Skip to content

Commit 5070c44

Browse files
committed
Use pathed archives on Linux
Alpine Linux's `ar` program doesn't support having objects with the same name in the archive twice, so we have to use the GNU extension for including paths. This commit *should* honestly be split into multiple separate commits, but unfortunately pretty much all of these changes have to be applied as a unit or a build step fails.
1 parent ad67c44 commit 5070c44

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

libexec/build-monolith

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ case "${platform}" in
2727
/usr/bin/find . '(' '!' -path './icutools/deps/icu-small/source/stubdata/stubdata.o' ')' -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" | sort | uniq | xargs /usr/bin/ar -cq "${LIBV8_MONOLITH}"
2828
;;
2929
"Linux")
30-
find . '(' '!' -path './icutools/deps/icu-small/source/stubdata/stubdata.o' ')' -and '(' -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" ')' | sort | uniq | xargs ar -cqS "${LIBV8_MONOLITH}"
31-
ranlib "${LIBV8_MONOLITH}"
30+
find . '(' '!' -path './icutools/deps/icu-small/source/stubdata/stubdata.o' ')' -and '(' -path "./torque_*/**/*.o" -or -path "./v8*/**/*.o" -or -path "./icu*/**/*.o" ')' | sort | uniq | xargs ar -cqSP "${LIBV8_MONOLITH}"
31+
ar -sP "${LIBV8_MONOLITH}"
3232
;;
3333
*)
3434
echo "Unsupported platform: ${platform}"

libexec/inject-libv8

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,35 @@ for lib in libv8_monolith.a; do
3939
mkdir -p "${dir}"
4040
rm -f "${dir}/${lib}"
4141

42-
echo "${BASEDIR}/out/${BUILDTYPE}/${lib} -> ${dir}/${lib}"
43-
"${STRIP}" -S -x -o "${dir}/${lib}" "${lib}"
42+
if [ "$STRIP_NEEDS_EXTRACT" = "y" ]; then
43+
# manual extract/strip objects/build archive sequence
44+
# because `strip` can't deal with these
45+
# (presumably due to that folder issue mentioned below)
46+
(
47+
tmpdir="$(mktemp -d)"
48+
trap 'rm -r "$tmpdir"' EXIT
49+
mkdir "$tmpdir/stage"
50+
cd "$tmpdir/stage"
51+
52+
# create folders named in `ar` archive (`ar -x` fails to create these)
53+
"$AR" "$ARLISTFLAGS" "$BASEDIR/out/$BUILDTYPE/$lib" | while read -r path; do
54+
dirname "$path"
55+
done | uniq | xargs mkdir -p
56+
"$AR" "$AREXTRACTFLAGS" "$BASEDIR/out/${BUILDTYPE}/$lib"
57+
58+
# strip all objects
59+
"$FIND" -type f -exec "$STRIP" -Sx {} +
60+
61+
# rebuild the archive
62+
"$FIND" -type f -exec "$AR" "$ARCOLLECTFLAGS" "../$lib" {} +
63+
$ARBUILDSYMBOLS "../$lib"
64+
mv "../$lib" "$dir/$lib"
65+
)
66+
echo "${BASEDIR}/out/${BUILDTYPE}/${lib} -> ${dir}/${lib}"
67+
else
68+
echo "${BASEDIR}/out/${BUILDTYPE}/${lib} -> ${dir}/${lib}"
69+
"${STRIP}" -S -x -o "${dir}/${lib}" "${lib}"
70+
fi
4471
done
4572

4673
mkdir -p "${top}/ext/libv8-node"

libexec/platform

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ elif command -v cc >/dev/null 2>&1; then
1515
fi
1616

1717
STRIP="${STRIP:-strip}"
18+
AR="${AR:-ar}"
19+
AREXTRACTFLAGS="${AREXTRACTFLAGS:--x}"
20+
ARLISTFLAGS="${ARLISTFLAGS:--t}"
21+
ARCOLLECTFLAGS="${ARCOLLECTFLAGS:-cqS}"
22+
# this is the command to build the symbol table in an ar archive.
23+
ARBUILDSYMBOLS="${ARBUILDSYMBOLS:-ranlib}"
24+
FIND="${FIND:-find}"
25+
STRIP_NEEDS_EXTRACT="${STRIP_NEEDS_EXTRACT:-n}"
1826

1927
triple=$(${CC} -dumpmachine)
2028
host_platform="${triple}"
@@ -63,6 +71,11 @@ case "${host_platform}" in
6371
CXX="${CXX:-/opt/local/gcc7/bin/g++}"
6472
STRIP="gstrip"
6573
;;
74+
*linux*)
75+
STRIP_NEEDS_EXTRACT="y"
76+
ARCOLLECTFLAGS="-cqSP"
77+
ARBUILDSYMBOLS="${AR} -sP"
78+
;;
6679
esac
6780

6881
if [ "${host_platform}" != "${target_platform}" ]; then
@@ -146,6 +159,14 @@ export CC='${CC}'
146159
export CXX='${CXX}'
147160
host_platform='${host_platform}'
148161
target_platform='${target_platform}'
162+
STRIP='$STRIP'
163+
AR='$AR'
164+
AREXTRACTFLAGS='$AREXTRACTFLAGS'
165+
ARLISTFLAGS='$ARLISTFLAGS'
166+
ARCOLLECTFLAGS='$ARCOLLECTFLAGS'
167+
ARBUILDSYMBOLS='$ARBUILDSYMBOLS'
168+
FIND='$FIND'
169+
STRIP_NEEDS_EXTRACT='$STRIP_NEEDS_EXTRACT'
149170
EOF
150171

151172
if [ -n "${CC_host:-}" ]; then cat <<EOF; fi

0 commit comments

Comments
 (0)