114 lines
5.1 KiB
Docker
114 lines
5.1 KiB
Docker
# MAIN: https://justine.lol/cosmopolitan/
|
|
# REPO: https://github.com/jart/cosmopolitan
|
|
ARG COSMO_FLAVOR=def
|
|
ARG COSMO_COMMIT=f52f65b2e351085250b743a5319dab418f2d48be
|
|
ARG COSMO_SHA256=8a13f4be3d689b8895af6e1178d455db2f82a69e33ce5848e2f2f14f96760d4c
|
|
ARG COSMO_REBUILD=0
|
|
|
|
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 env=COSMO \
|
|
;
|
|
|
|
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 make.com build/bootstrap/make.com
|
|
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\\' \
|
|
# 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!) \
|
|
&& printf '%s\n' >makeit '#!/usr/bin/env sh' \
|
|
"build/bootstrap/make.com -j2 MODE='$mode'"' "$@"' \
|
|
# make accessing some common paths a littler shorter (don't put this in distrib!) \
|
|
&& printf '%s\n' >expand '#!/usr/bin/env sh' \
|
|
"o='o/$mode' once=false" \
|
|
'for f; do g="${f#?//}"; case "$f" in' \
|
|
'(a//*) f="$o/ape/$g";;' \
|
|
'(b//*) f="$o/tool/build/$g";;' \
|
|
'(e//*) f="$o/examples/$g";;' \
|
|
'(o//*) f="$o/$g";;' \
|
|
'(t//*) f="$o/third_party/$g";;' \
|
|
'(T//*) f="third_party/$g";;' \
|
|
'esac; $once && set -- "$@" "$f" || set -- "$f"; once=true; done' \
|
|
'"$@"' \
|
|
# i always forget to do this \
|
|
&& chmod +x makeit expand \
|
|
;
|
|
|
|
# finally start building
|
|
RUN --mount=type=tmpfs,target=/tmp : \
|
|
&& ./expand ./makeit \
|
|
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() { ./expand ./makeit "$@" && ./expand 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 \
|
|
# install the newly-built ape loader, just in case it has changed: \
|
|
&& ./expand install -m0755 a//ape.elf /usr/bin/ape \
|
|
;
|
|
|
|
# optionally use the newly-built bootstrapped binaries to build themselves again.
|
|
ARG COSMO_REBUILD
|
|
RUN --mount=type=tmpfs,target=/tmp : \
|
|
&& { [ "$COSMO_REBUILD" = 1 ] || exit 0 ;} \
|
|
&& rm -r o \
|
|
\
|
|
&& ./expand ./makeit \
|
|
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() { ./expand ./makeit "$@" && ./expand 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! \
|
|
RUN --mount=type=tmpfs,target=/tmp : \
|
|
&& ./expand ./makeit \
|
|
t//unzip/unzip.com t//zip/zip.com \
|
|
;
|