stargazing/cosmo-perl/Dockerfile

135 lines
3.8 KiB
Docker

# 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=bebc393fb7412bb39314f8a8bad76ffe7522574d
ARG PERL_SHA256=274f749bd447f00b93537616b77950c1981034ada80568c052344eb017649ddc
ARG PERLTIDY_VERSION=20220613
ARG PERLTIDY_SHA256=50496a6952904ef28f495919fc0a67801a63c87779c61308ce1ca5b32467c5d4
RUN --mount=type=cache,id=common,target=/media/common,sharing=locked \
--mount=type=tmpfs,target=/tmp : \
&& acquire from=github repo=Perl/perl5 dest=/perl \
commit="$PERL_COMMIT" checksum="$PERL_SHA256" \
\
&& name=perltidy \
&& remote_fn="Perl-Tidy-$PERLTIDY_VERSION.tar.gz" \
&& export local_fn="$name-$PERLTIDY_VERSION.tar.gz" \
&& export remote_url="https://cpan.metacpan.org/authors/id/S/SH/SHANCOCK/$remote_fn" \
&& export dest=/$name \
&& export sha256="$PERLTIDY_SHA256" \
&& acquire \
;
FROM localhost/cosmo AS builder
# TODO: this shouldn't be necessary!
RUN apk add --no-cache make
COPY --from=downloader /perl /perl
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 \
;
WORKDIR perl
COPY --chmod=0755 --from=localhost/notwa-util /nu/shed /usr/bin/
RUN : \
&& shed hints/cosmo.sh '/x86_64-linux-musl/d' \
&& shed Makefile.SH 's/.*-musl-objcopy/\tobjcopy/g' \
\
&& COSMO_MODE= COSMO_REPO=/cosmopolitan sh Configure -d -e \
-Dprefix=/zip \
-Dusedevel \
-Uversiononly \
-Doptimize=-Os \
-Dmyhostname=cosmo \
-Dmydomain=invalid \
-Dcf_by=cosmo \
;
RUN make -j2
RUN make -j2 minitest devtty=/dev/zero | tee minitest_results.txt
RUN : \
&& mkdir /perl/cosmo \
&& mkdir /perl/cosmo/o \
&& mkdir /perl/cosmo/o/tmp \
&& cp /perl/perl.com /perl/cosmo/o/tmp/perl.com \
&& make DESTDIR=/perl/cosmo/o/tmp install.perl \
;
RUN : \
&& cd /perl/cosmo/o/tmp/zip \
&& rm bin/perl bin/perl5.36.0 \
&& find lib -name '*.a' -delete \
&& find lib -name '*.h' -delete \
&& find -name '*.pod' -delete \
&& cp ../perl.com ../perl.com.bak \
&& chmod u+w ../perl.com \
&& zip -qr ../perl.com lib \
&& mv ../perl.com ../../perl.com \
;
COPY --from=downloader /perltidy /perltidy
RUN : \
&& cd /perltidy \
&& /perl/cosmo/o/perl.com pm2pl \
&& mv perltidy-*.pl /perl/perltidy.pl \
&& cd /perl/cosmo/o/tmp/zip \
&& find -type f -name '*.pm' -exec \
/cosmopolitan/o/ape/ape.elf ../../perl.com /perl/perltidy.pl \
--mangle --delete-all-comments --backup-and-modify-in-place --backup-file-extension=/ {} \
+ \
;
RUN : \
&& cd /perl/cosmo/o/tmp/zip \
&& cp ../perl.com.bak ../perl.com \
&& chmod u+w ../perl.com \
&& zip -qr ../perl.com bin \
&& zip -qr ../perl.com lib \
&& mv ../perl.com ../../perl.com \
;
FROM scratch AS runner
COPY --chmod=0755 --from=localhost/notwa-util /nu/busybox /bin/busybox
COPY --chmod=0755 --from=builder /cosmopolitan/bin/ape /bin/ape
COPY --chmod=0755 --from=builder /perl/cosmo/o/perl.com /bin/perl.com
COPY --chmod=0755 --from=builder /perl/perl.elf /bin/perl.com.dbg
COPY --from=builder /perl/minitest_results.txt /minitest_results.txt
ENTRYPOINT ["/bin/ape", "/bin/perl.com"]