add cosmo
This commit is contained in:
parent
607346f52a
commit
f2e94144e1
2 changed files with 183 additions and 0 deletions
182
cosmo/Dockerfile
Normal file
182
cosmo/Dockerfile
Normal file
|
@ -0,0 +1,182 @@
|
|||
# MAIN: https://justine.lol/cosmopolitan/
|
||||
# REPO: https://github.com/jart/cosmopolitan
|
||||
ARG COSMO_FLAVOR=def
|
||||
# 1 commit after cosmopolitan 2.1.0:
|
||||
ARG COSMO_COMMIT=87708c5d6eef18dad5ca64f6da87fafbcb9a0132
|
||||
ARG COSMO_SHA256=103173004296b89471f586dcce56381ac5695c6f42f5aae75c620842685c6371
|
||||
|
||||
FROM localhost/notwa-util AS downloader
|
||||
ARG COSMO_COMMIT
|
||||
ARG COSMO_SHA256
|
||||
RUN --mount=type=cache,id=common,target=/media/common,sharing=locked \
|
||||
--mount=type=tmpfs,target=/tmp : \
|
||||
&& cd /media/common \
|
||||
&& name=cosmopolitan \
|
||||
&& export remote_fn="$COSMO_COMMIT.tar.gz" \
|
||||
&& export local_fn="$name-$remote_fn" \
|
||||
&& export remote_url="https://github.com/jart/$name/archive/$remote_fn" \
|
||||
&& export dest=/$name \
|
||||
&& export sha256="$COSMO_SHA256" \
|
||||
&& acquire \
|
||||
;
|
||||
|
||||
FROM alpine:3.16 AS builder
|
||||
ARG COSMO_FLAVOR
|
||||
ARG 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
|
||||
|
||||
RUN : \
|
||||
# allow optimized builds to be more portable, so the container is too. \
|
||||
&& sed -i 's/-march=native/-march=haswell -mno-pclmul -mtune=generic/' build/config.mk \
|
||||
# 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 \
|
||||
# include LoadZipArgs in cosmopolitan.a \
|
||||
&& sed -i '/COSMOPOLITAN_OBJECTS =/a\\tTOOL_ARGS\t\t\\' Makefile \
|
||||
# include nsync_cv_signal and nsync_cv_wait_with_deadline in cosmopolitan.a \
|
||||
&& sed -i '/THIRD_PARTY_NSYNC_MALLOC/i\\tTHIRD_PARTY_NSYNC_MEM\t\t\\' Makefile \
|
||||
# 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 \
|
||||
&& ./make -j2 MODE="$mode" \
|
||||
"o/$mode/ape/ape-copy-self.o" \
|
||||
"o/$mode/ape/ape-no-modify-self.o" \
|
||||
"o/$mode/ape/ape.elf" \
|
||||
"o/$mode/ape/ape.lds" \
|
||||
"o/$mode/ape/ape.macho" \
|
||||
"o/$mode/ape/ape.o" \
|
||||
"o/$mode/ape/public/ape.lds" \
|
||||
"o/$mode/cosmopolitan.a" \
|
||||
"o/$mode/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 \
|
||||
"o/$mode/third_party/make/make.com" \
|
||||
"o/$mode/tool/build/ar.com" \
|
||||
"o/$mode/tool/build/cocmd.com" \
|
||||
"o/$mode/tool/build/compile.com" \
|
||||
"o/$mode/tool/build/cp.com" \
|
||||
"o/$mode/tool/build/echo.com" \
|
||||
"o/$mode/tool/build/fixupobj.com" \
|
||||
"o/$mode/tool/build/gzip.com" \
|
||||
"o/$mode/tool/build/mkdeps.com" \
|
||||
"o/$mode/tool/build/mkdir.com" \
|
||||
"o/$mode/tool/build/package.com" \
|
||||
"o/$mode/tool/build/pwd.com" \
|
||||
"o/$mode/tool/build/rm.com" \
|
||||
"o/$mode/tool/build/touch.com" \
|
||||
"o/$mode/tool/build/unbundle.com" \
|
||||
"o/$mode/tool/build/zipobj.com" \
|
||||
# these are essential too! \
|
||||
&& ./make -j2 MODE="$mode" "$@" \
|
||||
"o/$mode/third_party/unzip/unzip.com" \
|
||||
"o/$mode/third_party/zip/zip.com" \
|
||||
"o/$mode/tool/build/assimilate.com" \
|
||||
;
|
||||
|
||||
RUN . ./env \
|
||||
&& mkdir dist "dist/$flavor" "dist/$flavor/public" \
|
||||
&& echo /dist >>.gitignore \
|
||||
&& cp -t "dist/$flavor" \
|
||||
"o/$mode/ape/ape-copy-self.o" \
|
||||
"o/$mode/ape/ape-no-modify-self.o" \
|
||||
"o/$mode/ape/ape.elf" \
|
||||
"o/$mode/ape/ape.lds" \
|
||||
"o/$mode/ape/ape.macho" \
|
||||
"o/$mode/ape/ape.o" \
|
||||
"o/$mode/cosmopolitan.a" \
|
||||
"o/$mode/libc/crt/crt.o" \
|
||||
"o/cosmopolitan.h" \
|
||||
&& cp -t "dist/$flavor/public" \
|
||||
"o/$mode/ape/public/ape.lds" \
|
||||
\
|
||||
&& install -m0755 "dist/$flavor/ape.elf" /usr/bin/ape \
|
||||
&& find libc -name '*.h' >headers.txt \
|
||||
&& tar zcf "dist/headers.tar.gz" \
|
||||
-T "headers.txt" \
|
||||
"ape/config.h" \
|
||||
"libc/integral" \
|
||||
"third_party/gdtoa/gdtoa.h" \
|
||||
"third_party/getopt/getopt.h" \
|
||||
"third_party/musl/crypt.h" \
|
||||
"third_party/musl/fnmatch.h" \
|
||||
"third_party/musl/passwd.h" \
|
||||
"third_party/regex/regex.h" \
|
||||
"third_party/zlib/zconf.h" \
|
||||
"third_party/zlib/zlib.h" \
|
||||
;
|
||||
|
||||
FROM builder AS distrib
|
||||
COPY dedupe.awk /
|
||||
RUN --mount=type=tmpfs,target=/tmp : \
|
||||
&& . ./env \
|
||||
&& dedupe() \
|
||||
(: \
|
||||
&& h=0 && { [ "$1" != --hard ] || shift && h=1 ;} \
|
||||
&& cd "$1" && shift && D="$1" && shift && t="$(mktemp)" \
|
||||
&& { [ $# -eq 0 ] || sha256sum >"$t" "$@" ;} \
|
||||
&& find ! -type d -exec sha256sum {} + >>"$t~" \
|
||||
&& sort -k2, <"$t~" >>"$t" \
|
||||
&& awk -v D="$D" -v h="$h" -F' ' -f /dedupe.awk <"$t" \
|
||||
) \
|
||||
&& 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 \
|
||||
"o/$mode/third_party/make/make.com" \
|
||||
"o/$mode/third_party/unzip/unzip.com" \
|
||||
"o/$mode/third_party/zip/zip.com" \
|
||||
"o/$mode/tool/build/ar.com" \
|
||||
"o/$mode/tool/build/assimilate.com" \
|
||||
"o/$mode/tool/build/cocmd.com" \
|
||||
"o/$mode/tool/build/compile.com" \
|
||||
"o/$mode/tool/build/cp.com" \
|
||||
"o/$mode/tool/build/echo.com" \
|
||||
"o/$mode/tool/build/fixupobj.com" \
|
||||
"o/$mode/tool/build/gzip.com" \
|
||||
"o/$mode/tool/build/mkdeps.com" \
|
||||
"o/$mode/tool/build/mkdir.com" \
|
||||
"o/$mode/tool/build/package.com" \
|
||||
"o/$mode/tool/build/pwd.com" \
|
||||
"o/$mode/tool/build/rm.com" \
|
||||
"o/$mode/tool/build/rollup.com" \
|
||||
"o/$mode/tool/build/symtab.com" \
|
||||
"o/$mode/tool/build/touch.com" \
|
||||
"o/$mode/tool/build/unbundle.com" \
|
||||
"o/$mode/tool/build/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"
|
1
cosmo/dedupe.awk
Normal file
1
cosmo/dedupe.awk
Normal file
|
@ -0,0 +1 @@
|
|||
BEGIN{if(!D){print U;exit 64}E=(Q="'")"\"'\""Q;H=(G=".")(F="/");I=" -- "Q;J="[^/]*/";sub(F"?$",F,D)gsub(Q,E,D)}function C(x){if(X=system(x))exit X}{if((p=$2)==B){print V;exit 65}for(r=z=i=d=B;d!=!i;i++){b=a=p;d=sub("/.*",B,a);sub(J,B,p);if(a==G G)e=!sub(J,B,z);else z=a==G?z:b!=a?z a F:z a;if(e||!i&&!a){print W;exit 65}}P=p=!z?H:z;if((o=O[$1])==p)next;gsub(Q,E,P);M=m=D P;gsub("/[^/]+$",B,M);if(!u[M]++)C("mkdir -p"I M Q);if(o){T=split(o,t,F);S=split(p,s,F);for(i=1;t[i]==s[i];i++);for(j=i;j<S;j++)r=r G H;for(j=i;j<T;j++)r=r t[j]F;r=h?o:r t[T];gsub(Q,E,r);C("ln"(h?I D:" -s"I)r"' '"m Q);next}O[$1]=p;C("cp -i"I P"' '"m Q)}
|
Loading…
Reference in a new issue