Skip to content

Commit 3a413c4

Browse files
[ci] build on container for reproducible build
1 parent 82a18f6 commit 3a413c4

File tree

4 files changed

+81
-64
lines changed

4 files changed

+81
-64
lines changed

.github/workflows/build-toolchain.yml

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ jobs:
101101
"build_os": "ubuntu-18.04",
102102
"agent_query": "ubuntu-18.04",
103103
"target": "ubuntu18.04_x86_64",
104+
"container": "ghcr.io/swiftwasm/swift-ci:main-ubuntu-18.04",
104105
"run_stdlib_test": true,
105106
"run_full_test": false,
106107
"run_e2e_test": true,
@@ -112,6 +113,7 @@ jobs:
112113
"build_os": "ubuntu-20.04",
113114
"agent_query": "ubuntu-20.04",
114115
"target": "ubuntu20.04_x86_64",
116+
"container": "ghcr.io/swiftwasm/swift-ci:main-ubuntu-20.04",
115117
"run_stdlib_test": true,
116118
"run_full_test": false,
117119
"run_e2e_test": true,
@@ -123,6 +125,7 @@ jobs:
123125
"build_os": "ubuntu-22.04",
124126
"agent_query": "ubuntu-22.04",
125127
"target": "ubuntu22.04_x86_64",
128+
"container": "ghcr.io/swiftwasm/swift-ci:main-ubuntu-22.04",
126129
"run_stdlib_test": true,
127130
"run_full_test": false,
128131
"run_e2e_test": true,
@@ -260,23 +263,32 @@ jobs:
260263
${{ github.workspace }}/host-toolchain-sdk \
261264
${{ github.workspace }}/dist-toolchain-sdk
262265
266+
- name: Build ${{ matrix.target }} installable archive on Docker container
267+
if: ${{ matrix.container != null }}
268+
run: |
269+
chmod 777 -R ${{ github.workspace }}/build-cache
270+
docker volume create oss-swift-package
271+
docker run --name swiftwasm-ci-buildbot \
272+
--security-opt=no-new-privileges \
273+
--cap-add=SYS_PTRACE \
274+
--security-opt seccomp=unconfined \
275+
-dit \
276+
-w /home/build-user/ \
277+
-v ${{ github.workspace }}:/source \
278+
-v oss-swift-package:/home/build-user \
279+
${{ matrix.container }}
280+
docker exec swiftwasm-ci-buildbot /bin/bash -lc 'env; cp -r /source/* /home/build-user/; ./swift/utils/webassembly/ci.sh'
281+
rm -rf ${{ github.workspace }}/build-cache
282+
docker cp swiftwasm-ci-buildbot:/home/build-user/build-cache ${{ github.workspace }}/build-cache
283+
docker cp swiftwasm-ci-buildbot:/home/build-user/swift-wasm-${{ env.TOOLCHAIN_CHANNEL }}-SNAPSHOT-${{ matrix.target }}.tar.gz .
284+
263285
- name: Build ${{ matrix.target }} installable archive
286+
if: ${{ matrix.container == null }}
264287
env:
265288
SKIP_XCODE_VERSION_CHECK: 1
266289
run: |
290+
./swift/utils/webassembly/ci.sh
267291
268-
case "${{ matrix.target }}" in
269-
"amazonlinux2_x86_64" | "ubuntu22.04_x86_64" | "ubuntu20.04_x86_64" | "ubuntu18.04_x86_64" | "ubuntu20.04_aarch64" | "macos_x86_64" | "macos_arm64")
270-
./swift/utils/webassembly/ci.sh
271-
;;
272-
*)
273-
echo "Unrecognised target: ${{ matrix.target }}"
274-
exit 1
275-
;;
276-
esac
277-
278-
- name: Check cache hit rate
279-
run: sccache --show-stats
280292
- uses: actions/cache/save@v3
281293
if: ${{ always() }}
282294
with:
@@ -293,7 +305,11 @@ jobs:
293305
run: echo "$HOME/.wasmer/bin" >> $GITHUB_PATH
294306

295307
- name: Run stdlib tests for wasi-wasm32
296-
if: ${{ matrix.run_stdlib_test }}
308+
if: ${{ matrix.run_stdlib_test && matrix.container != null }}
309+
run: |
310+
docker exec swiftwasm-ci-buildbot /bin/bash -lc "cd target-build/swift-stdlib-wasi-wasm32 && ninja check-swift-wasi-wasm32-custom"
311+
- name: Run stdlib tests for wasi-wasm32
312+
if: ${{ matrix.run_stdlib_test && matrix.container == null }}
297313
run: |
298314
TARGET_STDLIB_BUILD_DIR=${{ github.workspace }}/target-build/swift-stdlib-wasi-wasm32
299315
ninja check-swift-wasi-wasm32-custom -C "$TARGET_STDLIB_BUILD_DIR"

utils/webassembly/build-toolchain.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,35 @@ create_darwin_info_plist() {
217217
chmod a+r "${DARWIN_TOOLCHAIN_INFO_PLIST}"
218218
}
219219

220+
show_sccache_stats() {
221+
# If sccache is installed in PATH
222+
if command -v sccache &> /dev/null; then
223+
sccache --show-stats
224+
else
225+
echo "sccache is not installed in PATH"
226+
fi
227+
}
228+
220229
if [ ${BUILD_HOST_TOOLCHAIN} -eq 1 ]; then
221230
build_host_toolchain
231+
echo "=================================="
232+
echo "Host toolchain built successfully!"
233+
echo "=================================="
234+
echo ""
235+
echo "sccache stats:"
236+
show_sccache_stats
222237
rm -rf "$DIST_TOOLCHAIN_DESTDIR"
223238
mkdir -p "$DIST_TOOLCHAIN_SDK"
224239
rsync -a "$HOST_TOOLCHAIN_DESTDIR/" "$DIST_TOOLCHAIN_SDK"
225240
fi
226241

227242
build_target_toolchain
243+
echo "===================================="
244+
echo "Target toolchain built successfully!"
245+
echo "===================================="
246+
echo ""
247+
echo "sccache stats:"
248+
show_sccache_stats
228249

229250
embed_wasi_sysroot
230251

utils/webassembly/ci.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ esac
2424
BUILD_SCRIPT=$UTILS_PATH/build-toolchain.sh
2525
RUN_TEST_BIN=$SWIFT_PATH/utils/run-test
2626
TARGET_STDLIB_BUILD_DIR=$SOURCE_PATH/target-build/swift-stdlib-wasi-wasm32
27+
BUILD_SDK_PATH="$SOURCE_PATH/build-sdk"
2728

28-
$DEPENDENCIES_SCRIPT
29+
export WASMER_DIR="$BUILD_SDK_PATH/wasmer"
30+
31+
$DEPENDENCIES_SCRIPT "$BUILD_SDK_PATH"
2932
$UTILS_PATH/install-build-sdk.sh
3033

34+
export PATH="$BUILD_SDK_PATH/bin:$PATH"
3135
export SCCACHE_CACHE_SIZE="50G"
3236
export SCCACHE_DIR="$SOURCE_PATH/build-cache"
3337

utils/webassembly/linux/install-dependencies.sh

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
set -ex
44

5+
DESTDIR="$1"
6+
mkdir -p "$DESTDIR"
7+
58
if [[ "$(cat /etc/system-release)" == *"Amazon Linux release 2"* ]]; then
69
sudo yum -y install \
710
clang \
@@ -37,73 +40,46 @@ if [[ "$(cat /etc/system-release)" == *"Amazon Linux release 2"* ]]; then
3740
sudo ln -s /usr/bin/ninja-build /usr/local/bin/ninja
3841
fi
3942
else
40-
sudo apt update
41-
42-
if [ $(grep RELEASE /etc/lsb-release) == "DISTRIB_RELEASE=18.04" ]; then
43-
sudo apt install -y \
44-
git ninja-build clang-10 python python-six \
45-
uuid-dev libicu-dev icu-devtools libbsd-dev \
46-
libedit-dev libxml2-dev libsqlite3-dev swig \
47-
libpython-dev libncurses5 libncurses5-dev pkg-config \
48-
libblocksruntime-dev libcurl4-openssl-dev \
49-
make systemtap-sdt-dev tzdata rsync wget llvm-10 zip unzip
50-
sudo ln -s -f /usr/bin/clang-10 /usr/bin/clang
51-
sudo ln -s -f /usr/bin/clang++-10 /usr/bin/clang++
52-
elif [ $(grep RELEASE /etc/lsb-release) == "DISTRIB_RELEASE=20.04" ]; then
53-
sudo apt install -y \
54-
git ninja-build clang python python-six \
55-
uuid-dev libicu-dev icu-devtools libbsd-dev \
56-
libedit-dev libxml2-dev libsqlite3-dev swig \
57-
libpython2-dev libncurses5 libncurses5-dev pkg-config \
58-
libblocksruntime-dev libcurl4-openssl-dev \
59-
make systemtap-sdt-dev tzdata rsync wget llvm zip unzip
60-
elif [ $(grep RELEASE /etc/lsb-release) == "DISTRIB_RELEASE=22.04" ]; then
61-
sudo apt install -y \
62-
git ninja-build clang python3 python-six \
63-
uuid-dev libicu-dev icu-devtools libbsd-dev \
64-
libedit-dev libxml2-dev libsqlite3-dev swig \
65-
libpython2-dev libncurses5 libncurses5-dev pkg-config \
66-
libblocksruntime-dev libcurl4-openssl-dev \
67-
make systemtap-sdt-dev tzdata rsync wget llvm zip unzip
68-
else
69-
echo "Unknown Ubuntu version"
70-
exit 1
71-
fi
72-
sudo apt clean
43+
echo "skip"
7344
fi
7445

7546
SOURCE_PATH="$( cd "$(dirname $0)/../../../.." && pwd )"
7647
SWIFT_PATH=$SOURCE_PATH/swift
77-
cd $SWIFT_PATH
7848

79-
./utils/update-checkout --clone --scheme wasm --skip-repository swift
49+
mkdir -p "$DESTDIR/bin"
8050

8151
# Install wasmer
8252
# FIXME: Wasmer doesn't support linux-aarch64, consider using a different WASI-compatible runtime.
8353
if [ "$(uname -m)" != "aarch64" ]; then
84-
if [ ! -e ~/.wasmer/bin/wasmer ]; then
54+
export WASMER_DIR="${WASMER_DIR:-$HOME/.wasmer}"
55+
if [ ! -e "$WASMER_DIR" ]; then
8556
curl https://get.wasmer.io -sSfL | sh -s "2.1.1"
57+
ln -sf "$WASMER_DIR/bin/wasmer" "$DESTDIR/bin/wasmer"
8658
fi
8759
fi
8860

89-
cd $SOURCE_PATH
61+
install_cmake() {
62+
local workdir="$(mktemp -d)"
63+
curl -L -o "$workdir/install_cmake.sh" "https://github.com/Kitware/CMake/releases/download/v3.22.1/cmake-3.22.1-linux-$(uname -m).sh"
64+
chmod +x "$workdir/install_cmake.sh"
65+
mkdir -p "$DESTDIR/cmake"
66+
"$workdir/install_cmake.sh" --skip-license --prefix="$DESTDIR/cmake"
67+
ln -sf "$DESTDIR/cmake/bin"/* "$DESTDIR/bin"
68+
}
9069

91-
if [ -z $(which cmake) ]; then
92-
wget -O install_cmake.sh "https://github.com/Kitware/CMake/releases/download/v3.22.1/cmake-3.22.1-linux-$(uname -m).sh"
93-
chmod +x install_cmake.sh
94-
sudo mkdir -p /opt/cmake
95-
sudo ./install_cmake.sh --skip-license --prefix=/opt/cmake
96-
sudo ln -sf /opt/cmake/bin/* /usr/local/bin
70+
if [ ! -e "$DESTDIR/cmake/bin/cmake" ]; then
71+
install_cmake
9772
fi
9873

99-
cmake --version
100-
10174
# Install sccache
10275

10376
if [ -z $(which sccache) ]; then
104-
sudo mkdir /opt/sccache && cd /opt/sccache
105-
wget -O - "https://github.com/mozilla/sccache/releases/download/v0.3.0/sccache-v0.3.0-$(uname -m)-unknown-linux-musl.tar.gz" | \
106-
sudo tar xz --strip-components 1
107-
sudo chmod +x /opt/sccache/sccache
108-
sudo ln -sf /opt/sccache/sccache /usr/local/bin
77+
mkdir "$DESTDIR/sccache" && cd "$DESTDIR/sccache"
78+
curl -L "https://github.com/mozilla/sccache/releases/download/v0.3.0/sccache-v0.3.0-$(uname -m)-unknown-linux-musl.tar.gz" | \
79+
tar xz --strip-components 1
80+
chmod +x "$DESTDIR/sccache/sccache"
81+
ln -sf "$DESTDIR/sccache/sccache" "$DESTDIR/bin/sccache"
10982
fi
83+
84+
cd $SWIFT_PATH
85+
./utils/update-checkout --clone --scheme wasm --skip-repository swift

0 commit comments

Comments
 (0)