Skip to content

Commit 20c6e70

Browse files
authored
add build script and Dockerfile for perl (#124)
1 parent 232285e commit 20c6e70

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
- misc
2020
- nasm
2121
- ncc-ng
22+
- perl
2223
- python
2324
- pythran
2425
- rocm

Dockerfile.perl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM ubuntu:22.04
2+
3+
# Enable source repositories so we can use `apt build-dep` to get all the
4+
# build dependencies for Perl
5+
RUN sed -i -- 's/#deb-src/deb-src/g' /etc/apt/sources.list && \
6+
sed -i -- 's/# deb-src/deb-src/g' /etc/apt/sources.list
7+
8+
ARG DEBIAN_FRONTEND=noninteractive
9+
RUN apt update -y -q && apt upgrade -y -q && apt update -y -q && \
10+
apt -q build-dep -y perl && \
11+
apt -q install -y \
12+
curl \
13+
git \
14+
perl \
15+
xz-utils \
16+
&& \
17+
cpan Devel::PatchPerl \
18+
&& \
19+
# clean up CPAN cache/build \
20+
rm -rf ~/.cpan \
21+
&& \
22+
# Remove apt's lists to make the image smaller.
23+
rm -rf /var/lib/apt/lists/*
24+
25+
RUN mkdir -p /root
26+
COPY perl /root/
27+
COPY common.sh /root/
28+
29+
WORKDIR /root

perl/build.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/bin/bash
2+
# perl/build.sh $VERSION /outdir $OPTREVISION
3+
# $VERSION can be a released version or one of the perl development
4+
# branches, including "blead" (aka trunk), maint-5.xx
5+
6+
set -ex
7+
source common.sh
8+
9+
ROOT=$(pwd)
10+
VERSION=$1
11+
# determine build revision
12+
LAST_REVISION="${3:-}"
13+
14+
SRCURL=https://www.cpan.org/src/5.0/
15+
GITURL=https://github.com/Perl/perl5.git
16+
17+
SRCDIR="${ROOT}/perl"
18+
[ -e "${SRCDIR}" ] && rm -rf "${SRCDIR}"
19+
20+
# use git for blead (aka trunk) or maint and CPAN for releases
21+
# I doubt maint will be used
22+
case $VERSION in
23+
blead|maint-*)
24+
BRANCH=${VERSION}
25+
VERSION=${VERSION}-$(date +%Y%m%d)
26+
27+
# Setup perl checkout
28+
git clone --depth 1 --single-branch -b "${BRANCH}" "${GITURL}" "${SRCDIR}"
29+
30+
REF="heads/${BRANCH}"
31+
REVISION=$(get_remote_revision "${GITURL}" "${REF}")
32+
;;
33+
*)
34+
BASENAME="perl-$VERSION"
35+
FILE="${BASENAME}.tar.gz"
36+
ARCHIVEURL="${SRCURL}${FILE}"
37+
cd "${ROOT}"
38+
39+
[ -e "${FILE}" ] && rm "${FILE}"
40+
curl -o "${FILE}" "${ARCHIVEURL}"
41+
42+
# creates perl-X.XX.X aka $BASENAME
43+
[ -e "${BASENAME}" ] && rm -rf "${BASENAME}"
44+
tar xzf "${FILE}"
45+
mv "${BASENAME}" "${SRCDIR}"
46+
47+
# patches older perls to build on modern systems
48+
perl -MDevel::PatchPerl -e 'Devel::PatchPerl->patch_source(@ARGV)' \
49+
"${VERSION}" "${SRCDIR}"
50+
REVISION="${VERSION}"
51+
;;
52+
esac
53+
54+
FULLNAME=perl-${VERSION}
55+
if [[ -d "${2}" ]]; then
56+
OUTPUT=$2/${FULLNAME}.tar.xz
57+
else
58+
OUTPUT=${2-$OUTPUT}
59+
fi
60+
initialise "${REVISION}" "${OUTPUT}" "${LAST_REVISION}"
61+
62+
STAGING_DIR=/opt/compiler-explorer/${FULLNAME}
63+
rm -rf "${STAGING_DIR}"
64+
mkdir -p "${STAGING_DIR}"
65+
66+
# Configure build
67+
# modern perls can use -Dmksymlinks to do an out of
68+
# tree build, but I don't trust it for older perls
69+
#
70+
# -de - -d use defaults, -e don't prompt to build Makefile etc
71+
# -s (silent) is also common here but may make diagnosis harder
72+
# -Dusedevel - required to build blead, harmless for other builds except
73+
# it sets -Dversiononly
74+
# -Uversiononly - installs a "perl" binary, not just perl$VERSION
75+
# -Dusethreads - enable threads, commonly set by vendors
76+
# -Dman1dir=none -Dman3dir=none - don't install man pages
77+
# -Duseshrplib - build libperl as a shared library
78+
# -Dlibperl - name of libperl shared object (otherwise just libperl.so)
79+
cd "${SRCDIR}"
80+
./Configure \
81+
-de \
82+
-Dusedevel \
83+
-Uversiononly \
84+
-Dprefix="${STAGING_DIR}" \
85+
-Dusethreads \
86+
-Dman1dir=none \
87+
-Dman3dir=none \
88+
-Duseshrplib \
89+
-Dlibperl=libperl-${VERSION}.so
90+
91+
# Build and install artifacts
92+
make -j $(nproc)
93+
make install
94+
95+
# delete installed pod, perldiag.pod is used by diagnostics.pm
96+
find "${STAGING_DIR}" -name '*.pod' ! -name perldiag.pod -print0 | xargs -0 rm --
97+
98+
# make sure it works
99+
"${STAGING_DIR}/bin/perl" -V
100+
101+
complete "${STAGING_DIR}" "${FULLNAME}" "${OUTPUT}"

0 commit comments

Comments
 (0)