Skip to content

Commit 0bb0494

Browse files
authored
build(libzip): use Docker (#5056)
* build(libzip): use docker * ci: validate libzip build * build: make build directory on the host * chore: update artifacts * chore: versions
1 parent 847657c commit 0bb0494

File tree

6 files changed

+82
-43
lines changed

6 files changed

+82
-43
lines changed

.github/workflows/integration-workflow.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ jobs:
6060
env:
6161
TARGET_BRANCH: ${{github.event.pull_request.base.ref}}
6262

63+
- name: 'Check that libzip artifacts are consistent with a fresh build (fix w/ "git merge master && bash packages/yarnpkg-libzip/artifacts/build.sh")'
64+
run: |
65+
if [[ $(git diff --name-only "$(git merge-base origin/"$TARGET_BRANCH" HEAD)" HEAD -- 'packages/yarnpkg-libzip/artifacts' 'packages/yarnpkg-libzip/sources/*.js' | wc -l) -gt 0 ]]; then
66+
bash packages/yarnpkg-libzip/artifacts/build.sh
67+
[[ $(git diff --name-only 'packages/yarnpkg-libzip/artifacts' 'packages/yarnpkg-libzip/sources/*.js' | wc -l) -eq 0 ]]
68+
fi
69+
shell: bash
70+
if: |
71+
(success() || failure()) && github.event.pull_request != ''
72+
env:
73+
TARGET_BRANCH: ${{github.event.pull_request.base.ref}}
74+
6375
- name: 'Check that the PnP hooks are consistent with a fresh build (fix w/ "git merge master && yarn update:pnp:hook")'
6476
run: |
6577
if [[ $(git diff --name-only "$(git merge-base origin/"$TARGET_BRANCH" HEAD)" HEAD -- 'packages/yarnpkg-{fslib,libzip,pnp}/sources/**/*' | wc -l) -gt 0 ]]; then

.yarn/versions/95d9f16a.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declined:
2+
- "@yarnpkg/core"
3+
- "@yarnpkg/libzip"

packages/yarnpkg-core/sources/worker-zip/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/yarnpkg-libzip/artifacts/build.sh

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
set -e
44

5-
EMSDK_ENV=~/emsdk/emsdk_env.sh
65
EMSDK_VERSION=2.0.22
76

8-
~/emsdk/emsdk install $EMSDK_VERSION
9-
~/emsdk/emsdk activate $EMSDK_VERSION
10-
117
THIS_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
128
cd "$THIS_DIR"
139

@@ -17,35 +13,46 @@ LIBZIP_VERSION=1.5.2 # Ignored at the moment; we use a fork, cf next params
1713
LIBZIP_REPO=arcanis/libzip
1814
LIBZIP_COMMIT=664462465d2730d51f04437c90ed7ebcbe19a36f
1915

20-
[[ -f ./zlib-"$ZLIB_VERSION"/libz.a ]] || (
16+
ZLIB_ROOT="$THIS_DIR/zlib-ng-$ZLIB_VERSION"
17+
LIBZIP_ROOT="$THIS_DIR/libzip-$LIBZIP_VERSION"
18+
19+
[[ -f "$ZLIB_ROOT/build/libz.a" ]] || (
2120
if ! [[ -e zlib-"$ZLIB_VERSION".zip ]]; then
2221
wget -O ./zlib-"$ZLIB_VERSION".zip "https://github.com/zlib-ng/zlib-ng/archive/refs/tags/$ZLIB_VERSION.zip"
2322
fi
2423

25-
if ! [[ -e zlib-"$ZLIB_VERSION" ]]; then
24+
if ! [[ -e "$ZLIB_ROOT" ]]; then
2625
unzip ./zlib-"$ZLIB_VERSION".zip
27-
mv ./zlib-ng-"$ZLIB_VERSION" ./zlib-"$ZLIB_VERSION"
2826
fi
2927

30-
cd "$THIS_DIR"/zlib-"$ZLIB_VERSION"
31-
32-
source "$EMSDK_ENV"
33-
34-
mkdir -p build
35-
cd build
36-
37-
CHOST="wasm32" CFLAGS="-static" LDFLAGS="-static" emconfigure ../configure --warn --zlib-compat --static
38-
39-
emmake make -j2
40-
28+
mkdir -p "$ZLIB_ROOT/build"
29+
30+
docker run --rm \
31+
-v "$ZLIB_ROOT:/zlib" \
32+
-u $(id -u):$(id -g) \
33+
--env CHOST="wasm32" \
34+
--env CFLAGS="-static" \
35+
--env LDFLAGS="-static" \
36+
-w "/zlib/build" \
37+
emscripten/emsdk:$EMSDK_VERSION \
38+
emconfigure ../configure --warn --zlib-compat --static
39+
40+
docker run --rm \
41+
-v "$ZLIB_ROOT:/zlib" \
42+
-u $(id -u):$(id -g) \
43+
-w "/zlib/build" \
44+
emscripten/emsdk:$EMSDK_VERSION \
45+
emmake make -j2
46+
47+
cd "$ZLIB_ROOT/build"
4148
mkdir -p local/lib local/include
4249
cp libz.a local/lib/
4350
cp zconf.h ../zlib.h local/include/
4451

4552
echo Built zlib
4653
)
4754

48-
[[ -f ./libzip-"$LIBZIP_VERSION"/build/lib/libzip.a ]] || (
55+
[[ -f "$LIBZIP_ROOT/build/lib/libzip.a" ]] || (
4956
if [[ -n "$LIBZIP_REPO" ]]; then
5057
if ! [[ -e libzip-"$LIBZIP_VERSION" ]]; then
5158
git clone https://github.com/"$LIBZIP_REPO" libzip-"$LIBZIP_VERSION"
@@ -64,27 +71,35 @@ LIBZIP_COMMIT=664462465d2730d51f04437c90ed7ebcbe19a36f
6471
fi
6572
fi
6673

67-
cd "$THIS_DIR"/libzip-"$LIBZIP_VERSION"
68-
69-
source "$EMSDK_ENV"
70-
71-
mkdir -p build
72-
cd build
74+
mkdir -p "$LIBZIP_ROOT/build"
7375

74-
emcmake cmake -Wno-dev \
76+
docker run --rm \
77+
-v "$LIBZIP_ROOT:/libzip" \
78+
-v "$ZLIB_ROOT:/zlib" \
79+
-u $(id -u):$(id -g) \
80+
-w "/libzip/build" \
81+
emscripten/emsdk:$EMSDK_VERSION \
82+
emcmake cmake -Wno-dev \
7583
-DBUILD_SHARED_LIBS=OFF \
7684
-DENABLE_LOCALTIME=OFF \
7785
-DENABLE_COMMONCRYPTO=OFF \
7886
-DENABLE_GNUTLS=OFF \
7987
-DENABLE_MBEDTLS=OFF \
8088
-DENABLE_OPENSSL=OFF \
8189
-DENABLE_WINDOWS_CRYPTO=OFF \
82-
-DZLIB_LIBRARY="$THIS_DIR"/zlib-"$ZLIB_VERSION"/build/local/lib/libz.a \
83-
-DZLIB_INCLUDE_DIR="$THIS_DIR"/zlib-"$ZLIB_VERSION"/build/local/include \
90+
-DZLIB_LIBRARY=/zlib/build/local/lib/libz.a \
91+
-DZLIB_INCLUDE_DIR=/zlib/build/local/include \
8492
..
8593

86-
emmake make zip
94+
docker run --rm \
95+
-v "$LIBZIP_ROOT:/libzip" \
96+
-v "$ZLIB_ROOT:/zlib" \
97+
-u $(id -u):$(id -g) \
98+
-w "/libzip/build" \
99+
emscripten/emsdk:$EMSDK_VERSION \
100+
emmake make zip
87101

102+
cd "$LIBZIP_ROOT/build"
88103
mkdir -p local/lib local/include
89104
cp lib/libzip.a local/lib/
90105
cp config.h zipconf.h ../lib/zip.h ../lib/compat.h ../lib/zipint.h local/include/
@@ -96,11 +111,16 @@ build() {
96111
local name=$1
97112
shift
98113

99-
source "$EMSDK_ENV"
100-
101114
# Options are documented at https://github.com/emscripten-core/emscripten/blob/86131037aa4f1c7bf6021081dd28fae12bdedba1/src/settings.js
102-
emcc \
103-
-o ./build.js \
115+
docker run --rm \
116+
-v "$THIS_DIR:/src" \
117+
-v "$LIBZIP_ROOT:/libzip" \
118+
-v "$ZLIB_ROOT:/zlib" \
119+
-u $(id -u):$(id -g) \
120+
-w "/src" \
121+
emscripten/emsdk:$EMSDK_VERSION \
122+
emcc \
123+
-o ./$name.js \
104124
-s WASM=1 \
105125
-s EXPORTED_FUNCTIONS="$(cat ./exported.json)" \
106126
-s EXPORTED_RUNTIME_METHODS='["cwrap", "getValue"]' \
@@ -111,26 +131,28 @@ build() {
111131
-s NODERAWFS=1 \
112132
-s SINGLE_FILE=1 \
113133
-s MODULARIZE=1 \
134+
-s STRICT=1 \
114135
-s EXPORT_NAME="createModule" \
115136
-s NODEJS_CATCH_EXIT=0 \
116137
-s NODEJS_CATCH_REJECTION=0 \
117138
"$@" \
118-
-I./libzip-"$LIBZIP_VERSION"/build/local/include \
119-
-I./zlib-"$ZLIB_VERSION"/build/local/include \
139+
-I/libzip/build/local/include \
140+
-I/zlib/build/local/include \
120141
-O3 \
121142
./lib/*.c \
122-
./libzip-"$LIBZIP_VERSION"/build/local/lib/libzip.a \
123-
./zlib-"$ZLIB_VERSION"/build/local/lib/libz.a
143+
/libzip/build/local/lib/libzip.a \
144+
/zlib/build/local/lib/libz.a
124145

125146
cat >../sources/"$name".js \
126147
<(echo "var frozenFs = Object.assign({}, require('fs'));") \
127-
<(sed 's/require("fs")/frozenFs/g' ./build.js |
148+
<(sed 's/require("fs")/frozenFs/g' ./$name.js |
128149
sed 's/process\["binding"\]("constants")/({"fs":fs.constants})/g')
129150

130-
yarn prettier --write ../sources/"$name".js
131-
132151
echo "Built wasm ($name)"
133152
}
134153

135-
build libzipSync -s BINARYEN_ASYNC_COMPILATION=0
136-
build libzipAsync -s BINARYEN_ASYNC_COMPILATION=1
154+
build libzipSync -s WASM_ASYNC_COMPILATION=0 &
155+
build libzipAsync -s WASM_ASYNC_COMPILATION=1 &
156+
wait
157+
158+
yarn prettier --write ../sources/*.js

packages/yarnpkg-libzip/sources/libzipAsync.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/yarnpkg-libzip/sources/libzipSync.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)