Skip to content

Commit

Permalink
Merge pull request #20 from skaji/static-libcrypt
Browse files Browse the repository at this point in the history
link libcrypt statically
  • Loading branch information
skaji authored Oct 7, 2024
2 parents 4b499fd + 4a523fd commit 136d24e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ Copyright 2010- Tatsuhiko Miyagawa, licensed under the same terms as Perl.

* [App::ChangeShebang](https://github.com/skaji/change-shebang)
Copyright Shoichi Kaji, licensed under the same terms as Perl.

* [libcrypt.a](https://sourceware.org/glibc/)
Copyright (C) 1991-2015 Free Software Foundation, Inc. GNU Lesser General Public License version 2.1 or later.
25 changes: 25 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
FROM buildpack-deps:bookworm AS static-libcrypt

RUN set -eux; \
mkdir /libc6-dev; \
cd /tmp; \
if [ $(uname -m) = x86_64 ]; then \
curl -fsSL -O http://security.ubuntu.com/ubuntu/pool/main/g/glibc/libc6-dev_2.23-0ubuntu3_amd64.deb; \
dpkg-deb -x libc6-dev_2.23-0ubuntu3_amd64.deb /libc6-dev; \
cp /libc6-dev/usr/lib/x86_64-linux-gnu/libcrypt.a /libcrypt.a; \
else \
curl -fsSL -O http://ports.ubuntu.com/pool/main/g/glibc/libc6-dev_2.23-0ubuntu3_arm64.deb; \
dpkg-deb -x libc6-dev_2.23-0ubuntu3_arm64.deb /libc6-dev; \
cp /libc6-dev/usr/lib/aarch64-linux-gnu/libcrypt.a /libcrypt.a; \
fi; \
:

FROM centos:centos7 AS builder

# see https://gist.github.com/skaji/76203327b517cb44da88a4301de118d3
Expand Down Expand Up @@ -26,7 +42,16 @@ RUN mkdir -p \
RUN curl -fsSL https://raw.githubusercontent.com/skaji/relocatable-perl/main/perl-install | bash -s /perl
RUN curl -fsSL --compressed -o /cpm https://raw.githubusercontent.com/skaji/cpm/main/cpm
RUN --mount=type=bind,target=src /perl/bin/perl /cpm install -g --cpmfile src/build/cpm.yml

# RUN rm -f /usr/lib64/libcrypt.so /usr/lib64/libcrypt.so.1
COPY --from=static-libcrypt /libcrypt.a /usr/lib64/libcrypt.a
RUN --mount=type=bind,target=src /perl/bin/perl src/build/relocatable-perl-build --perl_version $(cat src/BUILD_VERSION) --prefix /opt/perl
RUN cd /usr/lib64; \
rm -f libcrypt.a; \
ln -sf libcrypt-2.17.so libcrypt.so; \
ln -sf libcrypt-2.17.so libcrypt.so.1; \
:

RUN /opt/perl/bin/perl /cpm install -g App::cpanminus App::ChangeShebang
RUN /opt/perl/bin/change-shebang -f /opt/perl/bin/*
RUN set -eux; \
Expand Down
10 changes: 8 additions & 2 deletions build/relocatable-perl-build
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,13 @@ sub perl_build {
# see https://github.com/agracio/electron-edge-js/issues/16
push @Configure, "-Ui_xlocale";

# RHEL8, Fedora28, CentOS8 does not have libnsl.so.1 by default;
# remove -lnsl
# RHEL8, Fedora28, CentOS8 does not have libnsl.so.1 by default; remove -lnsl
push @Configure, "-Dlibs=-lpthread -ldl -lm -lcrypt -lutil -lc";

# RHEL9 removes libcrypt.so.1 by default; so we will link libcrypt.a statically
# manually define d_crypt here
push @Configure, "-Dd_crypt";

my $arch = (uname)[4];
my @libpth = (
"/lib",
Expand Down Expand Up @@ -172,6 +175,9 @@ sub perl_build {
}
}
say "---> building perl $perl_version, see $log for progress";
if ($^O eq "linux") {
system "rm -f /usr/lib64/libcrypt.so /usr/lib64/libcrypt.so.1"; # XXX
}
run \@Configure, $log;
my @option = $jobs ? ("--jobs=$jobs") : ();
run ["make", @option, "install"], $log;
Expand Down

0 comments on commit 136d24e

Please sign in to comment.