stargazing/cosmo-perl/Dockerfile

140 lines
4.4 KiB
Text
Raw Normal View History

2022-09-23 16:15:26 -07:00
# MAIN: https://www.perl.org/
# REPO: https://github.com/Perl/perl5
# FORK: https://github.com/G4Vi/perl5/tree/cosmo
FROM localhost/notwa-util AS downloader
ARG PERL_COMMIT=75e54093a8376c4b2196510e88201e8d793f5424
ARG PERL_SHA256=b28ccbb96f9dfb96a4216215dafc2db8ba3b998e5ead6357b2614f5334c3a6f7
RUN --mount=type=cache,id=common,target=/media/common,sharing=locked \
--mount=type=tmpfs,target=/tmp : \
&& cd /media/common \
&& name=perl5 \
&& export remote_fn="$PERL_COMMIT.tar.gz" \
&& export local_fn="$name-$remote_fn" \
&& export remote_url="https://github.com/G4Vi/$name/archive/$remote_fn" \
&& export dest=/$name \
&& export sha256="$PERL_SHA256" \
&& acquire \
;
FROM localhost/cosmo AS builder
COPY --from=downloader /perl5 /perl5
# TODO: this shouldn't be necessary!
RUN apk add --no-cache make
RUN : \
&& cd cosmopolitan \
&& . ./env \
&& a="dist/$flavor" \
&& mkdir o o/ape o/ape/public o/libc o/libc/crt \
&& cp -t o/ape \
"$a/ape-copy-self.o" \
"$a/ape-no-modify-self.o" \
"$a/ape.elf" \
"$a/ape.lds" \
"$a/ape.o" \
&& cp -t o/ape/public \
"$a/public/ape.lds" \
&& cp -t o/libc/crt \
"$a/crt.o" \
&& cp -t o \
"$a/cosmopolitan.a" \
"$a/cosmopolitan.h" \
\
&& tar zxf dist/headers.tar.gz \
\
&& for f in \
bin/unzip.com \
bin/zip.com \
;do : \
&& cp -- "$f" /a.out \
&& /cosmopolitan/bin/ape bin/assimilate.com /a.out \
&& install -m0755 /a.out "/usr/bin/$(basename "${f%.com}")" \
;done \
\
&& rm /usr/bin/strings \
&& for f in gcc/bin/* \
;do : \
&& g="$(basename "$f")" \
&& ln -s "$(realpath "$f")" "/usr/bin/${g#x86_64-linux-musl-}" \
;done \
;
# TODO: use -D__W__ at compile-time instead?
RUN : \
&& sed -i '/-Wuninitialized/d' cosmopolitan/o/cosmopolitan.h \
&& sed -i '/-Wmaybe-uninitialized/d' cosmopolitan/o/cosmopolitan.h \
&& sed -i '/-Wuninitialized/d' cosmopolitan/libc/integral/c.inc \
&& sed -i '/-Wmaybe-uninitialized/d' cosmopolitan/libc/integral/c.inc \
&& sed -i '/sock\/sock.h/a\\#include "libc/sock/struct/pollfd.h"' cosmopolitan/libc/isystem/poll.h \
&& sed -i '/sock\/sock.h/a\\#include "libc/sock/struct/pollfd.h"' cosmopolitan/libc/isystem/sys/poll.h \
&& sed -i '/calls\/weirdtypes.h/a\\#include "libc/runtime/sysconf.h"' cosmopolitan/libc/isystem/unistd.h \
&& sed -i '/x86_64-linux-musl/d' perl5/hints/cosmo.sh \
&& sed -i '/Which of these apply/c\\dflt=cosmo' perl5/Configure \
&& sed -i 's/.*-musl-objcopy/\tobjcopy/g' perl5/Makefile.SH \
&& sed -i 's/cp \([^ ]\+\)/chmod +x \1 \&\& cp \1/g' perl5/Makefile.SH \
;
WORKDIR perl5
RUN : \
&& COSMO_MODE="" COSMO_REPO="/cosmopolitan" sh Configure -d -e \
-Dprefix="/zip" \
-Dusedevel \
-Doptimize="-Os" \
-Dmyhostname="cosmo" \
-Dmydomain="invalid" \
-Dcf_by="cosmo" \
-DDEBUGGING \
;
RUN make -j2
RUN make -j2 minitest devtty=/dev/zero | tee minitest_results.txt
RUN : \
&& mkdir "/perl5/cosmo/o" \
&& mkdir "/perl5/cosmo/o/tmp" \
&& cp "/perl5/perl.com" "/perl5/cosmo/o/tmp/perl.com" \
&& make "DESTDIR=/perl5/cosmo/o/tmp" install.perl \
;
RUN : \
&& cd "/perl5/cosmo/o/tmp/zip" \
&& find lib -name '*.a' -delete \
&& find lib -name '*.h' -delete \
&& find -name '*.pod' -delete \
&& cp "../perl.com" "../perl.com.bak" \
&& zip -qr "../perl.com" "lib" \
&& mv "../perl.com" "../../perl.com" \
;
RUN : \
&& version=20220613 \
&& wget -q "https://cpan.metacpan.org/authors/id/S/SH/SHANCOCK/Perl-Tidy-$version.tar.gz" -O "Perl-Tidy-$version.tar.gz" \
&& tar zxf "Perl-Tidy-$version.tar.gz" \
&& cd "Perl-Tidy-$version" \
&& ../cosmo/o/perl.com pm2pl \
&& mv "perltidy-$version.pl" ../perltidy.pl \
&& cd .. \
&& rm -r Perl-Tidy-$version \
;
RUN : \
&& cd "/perl5/cosmo/o/tmp/zip" \
&& find -type f -name '*.pm' -exec \
/cosmopolitan/o/ape/ape.elf ../../perl.com /perl5/perltidy.pl \
--mangle --delete-all-comments --backup-and-modify-in-place --backup-file-extension=/ {} \
+ \
&& cp "../perl.com.bak" "../perl.com" \
&& zip -qr "../perl.com" "lib" \
&& mv "../perl.com" "../../perl.com" \
;
FROM scratch AS runner
COPY --chmod=0755 --from=localhost/notwa-util /usr/local/bin/busybox /bin/busybox
COPY --chmod=0755 --from=builder /cosmopolitan/bin/ape /bin/ape
COPY --chmod=0755 --from=builder /perl5/cosmo/o/perl.com /bin/perl.com
# TODO: include .dbg file too!
COPY --from=builder /perl5/minitest_results.txt /minitest_results.txt
ENTRYPOINT ["/bin/ape", "/bin/perl.com"]