stargazing/cosmo-perl/Dockerfile

141 lines
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
2022-09-26 20:07:20 -07:00
ARG PERL_COMMIT=7ed252b7da0fa1fce0d3f3c87f83f67bd3d33bca
ARG PERL_SHA256=459d1d48dc9c6f36b2289e7f229aea488eb2f7e8e680dbe37925e311015350ad
2022-09-23 16:15:26 -07:00
ARG PERLTIDY_VERSION=20220613
ARG PERLTIDY_SHA256=50496a6952904ef28f495919fc0a67801a63c87779c61308ce1ca5b32467c5d4
2022-09-23 16:15:26 -07:00
RUN --mount=type=cache,id=common,target=/media/common,sharing=locked \
--mount=type=tmpfs,target=/tmp : \
&& cd /media/common \
&& name=perl \
2022-09-23 16:15:26 -07:00
&& export remote_fn="$PERL_COMMIT.tar.gz" \
&& export local_fn="$name-$remote_fn" \
&& export remote_url="https://github.com/G4Vi/perl5/archive/$remote_fn" \
2022-09-23 16:15:26 -07:00
&& export dest=/$name \
&& export sha256="$PERL_SHA256" \
&& acquire \
\
&& name=perltidy \
&& export 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 \
2022-09-23 16:15:26 -07:00
;
FROM localhost/cosmo AS builder
# TODO: this shouldn't be necessary!
RUN apk add --no-cache make
COPY --from=downloader /perl /perl
2022-09-23 16:15:26 -07:00
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
2022-09-23 16:15:26 -07:00
RUN : \
&& sed -i '/x86_64-linux-musl/d' hints/cosmo.sh \
&& sed -i 's/.*-musl-objcopy/\tobjcopy/g' Makefile.SH \
\
2022-09-23 16:15:26 -07:00
&& COSMO_MODE="" COSMO_REPO="/cosmopolitan" sh Configure -d -e \
-Dprefix="/zip" \
-Dusedevel \
2022-09-23 17:08:10 -07:00
-Uversiononly \
2022-09-23 16:15:26 -07:00
-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 "/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 \
2022-09-23 16:15:26 -07:00
;
RUN : \
&& cd "/perl/cosmo/o/tmp/zip" \
2022-09-23 17:08:10 -07:00
&& rm "bin/perl" "bin/perl5.36.0" \
2022-09-23 16:15:26 -07:00
&& find lib -name '*.a' -delete \
&& find lib -name '*.h' -delete \
&& find -name '*.pod' -delete \
&& cp "../perl.com" "../perl.com.bak" \
2022-09-23 17:08:10 -07:00
&& chmod u+w "../perl.com" \
2022-09-23 16:15:26 -07:00
&& zip -qr "../perl.com" "lib" \
&& mv "../perl.com" "../../perl.com" \
;
COPY --from=downloader /perltidy /perltidy
2022-09-23 16:15:26 -07:00
RUN : \
&& cd "/perltidy" \
&& /perl/cosmo/o/perl.com pm2pl \
2022-09-23 17:36:48 -07:00
&& mv "perltidy-"*".pl" /perl/perltidy.pl \
&& cd "/perl/cosmo/o/tmp/zip" \
2022-09-23 16:15:26 -07:00
&& find -type f -name '*.pm' -exec \
/cosmopolitan/o/ape/ape.elf ../../perl.com /perl/perltidy.pl \
2022-09-23 16:15:26 -07:00
--mangle --delete-all-comments --backup-and-modify-in-place --backup-file-extension=/ {} \
+ \
2022-09-23 17:08:10 -07:00
;
RUN : \
&& cd "/perl/cosmo/o/tmp/zip" \
2022-09-23 16:15:26 -07:00
&& cp "../perl.com.bak" "../perl.com" \
2022-09-23 17:08:10 -07:00
&& chmod u+w "../perl.com" \
&& zip -qr "../perl.com" "bin" \
2022-09-23 16:15:26 -07:00
&& 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 /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
2022-09-23 16:15:26 -07:00
ENTRYPOINT ["/bin/ape", "/bin/perl.com"]