129 lines
6.1 KiB
Docker
129 lines
6.1 KiB
Docker
# MAIN: https://justine.lol/cosmopolitan/
|
|
# REPO: https://github.com/jart/cosmopolitan
|
|
ARG COSMO_FLAVOR=def
|
|
ARG COSMO_COMMIT=7822917fc2374a5e85c3bf535ce14e1dd3446d8f
|
|
ARG COSMO_SHA256=d2cb9d79ac578347e7430062f831bb303eb415735d552414d55aa6582e70b4c6
|
|
|
|
FROM localhost/notwa-util AS downloader
|
|
ARG COSMO_COMMIT COSMO_SHA256
|
|
RUN --mount=type=cache,id=common,target=/media/common,sharing=locked \
|
|
--mount=type=tmpfs,target=/tmp : \
|
|
&& acquire from=github repo=jart/cosmopolitan dest=/cosmopolitan \
|
|
commit="$COSMO_COMMIT" checksum="$COSMO_SHA256" \
|
|
;
|
|
|
|
FROM alpine:3.16 AS builder
|
|
ARG COSMO_FLAVOR COSMO_COMMIT
|
|
COPY --from=downloader /cosmopolitan /cosmopolitan
|
|
WORKDIR /cosmopolitan
|
|
|
|
# tell makefiles to be less noisy, also use /tmp:
|
|
ENV V=0 COLUMNS=80 TMPDIR=/tmp
|
|
|
|
COPY --chmod=0755 --from=localhost/notwa-util /nu/shed /usr/bin/
|
|
RUN : \
|
|
# allow optimized builds to be more portable, so the container is too. \
|
|
&& shed build/config.mk 's/-march=native/-march=haswell -mno-pclmul -mtune=generic/' \
|
|
# fix execution on alpine (although installing the loader mitigates this) \
|
|
&& sed -i 's/skip=" 76" count=" 128"/skip=76 count=128 /' build/bootstrap/*.com \
|
|
&& install -m0755 build/bootstrap/ape.elf /usr/bin/ape \
|
|
&& shed Makefile \
|
|
# TODO: apply changes to COSMOPOLITAN_HEADERS as to include them in cosmopolitan.h \
|
|
# NOTE: the order here is important! look at the generated o/depend file for hints. \
|
|
# include cosmopolitan linenoise (formerly known as bestline) \
|
|
'/\bNET_HTTP\b/i\\tTHIRD_PARTY_LINENOISE\t\t\\' \
|
|
# include LoadZipArgs in cosmopolitan.a \
|
|
'/\bNET_HTTP\b/i\\tTOOL_ARGS\t\t\\' \
|
|
# include nsync_cv_signal and nsync_cv_wait_with_deadline in cosmopolitan.a \
|
|
'/\bTHIRD_PARTY_NSYNC_MALLOC\b/i\\tTHIRD_PARTY_NSYNC_MEM\t\t\\' \
|
|
# add missing includes \
|
|
&& shed libc/elf/elf.h '/"libc\/elf\/struct\/ehdr.h"/i\\#include "libc/elf/struct/dyn.h"' \
|
|
# awk's pledge isn't working for me for whatever reason \
|
|
&& shed third_party/awk/main.c '/pledge.*{/,/}/d' \
|
|
# create a mapping from flavor to mode (possibly an empty string) \
|
|
&& { [ "$COSMO_FLAVOR" != def ] && mode="$COSMO_FLAVOR" || mode=; } \
|
|
&& printf '%s="%s"\n' >env \
|
|
commit "$COSMO_COMMIT" \
|
|
flavor "$COSMO_FLAVOR" \
|
|
mode "$mode" \
|
|
# make calling make a little shorter (don't put this in distrib!) \
|
|
&& ln -s build/bootstrap/make.com make \
|
|
;
|
|
|
|
# finally start building
|
|
|
|
RUN --mount=type=tmpfs,target=/tmp : \
|
|
&& . ./env && o="o/$mode" a="$o/ape" b="$o/tool/build" t="$o/third_party" \
|
|
&& ./make -j2 MODE="$mode" \
|
|
"$a/ape-copy-self.o" "$a/ape-no-modify-self.o" "$a/ape.elf" \
|
|
"$a/ape.lds" "$a/ape.macho" "$a/ape.o" \
|
|
"$a/public/ape.lds" "$o/cosmopolitan.a" "$o/libc/crt/crt.o" \
|
|
"o/cosmopolitan.h" \
|
|
# build some extra tools for other containers to stem off of: \
|
|
&& rebuild() { ./make -j2 MODE="$mode" "$@" && cp -t build/bootstrap "$@" ;} \
|
|
&& rebuild \
|
|
"$t/make/make.com" "$b/ar.com" "$b/cocmd.com" \
|
|
"$b/compile.com" "$b/cp.com" "$b/echo.com" \
|
|
"$b/fixupobj.com" "$b/gzip.com" "$b/mkdeps.com" \
|
|
"$b/mkdir.com" "$b/package.com" "$b/pwd.com" \
|
|
"$b/rm.com" "$b/touch.com" "$b/unbundle.com" \
|
|
"$b/zipobj.com" \
|
|
# these are essential too! \
|
|
&& ./make -j2 MODE="$mode" "$@" \
|
|
"$t/awk/awk.com" "$t/sed/sed.com" "$t/unzip/unzip.com" \
|
|
"$t/zip/zip.com" "$b/assimilate.com" \
|
|
;
|
|
|
|
RUN : \
|
|
&& . ./env && o="o/$mode" a="$o/ape" b="$o/tool/build" t="$o/third_party" \
|
|
&& mkdir dist "dist/$flavor" "dist/$flavor/public" \
|
|
&& echo /dist >>.gitignore \
|
|
&& cp -t "dist/$flavor" \
|
|
"$a/ape-copy-self.o" "$a/ape-no-modify-self.o" "$a/ape.elf" \
|
|
"$a/ape.lds" "$a/ape.macho" "$a/ape.o" \
|
|
"$o/cosmopolitan.a" "$o/libc/crt/crt.o" "o/cosmopolitan.h" \
|
|
&& cp -t "dist/$flavor/public" "$a/public/ape.lds" \
|
|
\
|
|
&& install -m0755 "dist/$flavor/ape.elf" /usr/bin/ape \
|
|
&& find libc -name '*.h' >headers.txt \
|
|
&& t=third_party ln=linenoise \
|
|
&& tar zcf "dist/headers.tar.gz" -T "headers.txt" \
|
|
"ape/config.h" "libc/integral" "$t/gdtoa/gdtoa.h" \
|
|
"$t/getopt/getopt.h" "$t/$ln/$ln.h" "$t/musl/crypt.h" \
|
|
"$t/musl/fnmatch.h" "$t/musl/passwd.h" "$t/regex/regex.h" \
|
|
"$t/zlib/zconf.h" "$t/zlib/zlib.h" \
|
|
;
|
|
|
|
FROM builder AS distrib
|
|
COPY --chmod=0755 --from=localhost/notwa-util /nu/dedupe /usr/bin/
|
|
RUN --mount=type=tmpfs,target=/tmp : \
|
|
&& . ./env && o="o/$mode" a="$o/ape" b="$o/tool/build" t="$o/third_party" \
|
|
&& find o -name '*.sym' -delete \
|
|
&& dedupe o/third_party/gcc /distrib/gcc/ \
|
|
bin/x86_64-linux-musl-gcc \
|
|
bin/x86_64-linux-musl-g++ \
|
|
bin/x86_64-linux-musl-ld.bfd \
|
|
&& dedupe dist /distrib/dist/ "$flavor/cosmopolitan.h" \
|
|
&& mkdir /tmp/bin \
|
|
# discover .com files by uncommenting this command: \
|
|
#&& find o -name '*.com' ! -type d -exec printf '%s\n' cp -t /tmp/bin {} + | sort && exit 1 \
|
|
&& cp -t /tmp/bin \
|
|
"$t/awk/awk.com" "$t/make/make.com" "$t/sed/sed.com" \
|
|
"$t/unzip/unzip.com" "$t/zip/zip.com" "$b/ar.com" \
|
|
"$b/assimilate.com" "$b/cocmd.com" "$b/compile.com" \
|
|
"$b/cp.com" "$b/echo.com" "$b/fixupobj.com" \
|
|
"$b/gzip.com" "$b/mkdeps.com" "$b/mkdir.com" \
|
|
"$b/package.com" "$b/pwd.com" "$b/rm.com" \
|
|
"$b/rollup.com" "$b/symtab.com" "$b/touch.com" \
|
|
"$b/unbundle.com" "$b/zipobj.com" \
|
|
&& dedupe /tmp/bin /distrib/bin/ \
|
|
#&& ln -s "../dist/$flavor/ape.elf" /distrib/bin/ape \
|
|
&& cp "dist/$flavor/ape.elf" /distrib/bin/ape \
|
|
&& cp /cosmopolitan/env /distrib/env \
|
|
;
|
|
|
|
FROM alpine:3.16 AS runner
|
|
COPY --from=distrib /distrib /cosmopolitan
|
|
ENV PATH="/cosmopolitan/bin:/cosmopolitan/gcc/bin/:/cosmopolitan/gcc/x86_64-linux-musl/bin/:$PATH"
|
|
ARG COSMO_FLAVOR
|
|
ENV COSMO_DIST="/cosmopolitan/dist/$COSMO_FLAVOR"
|