Skip to content

Commit 2e7bb65

Browse files
authored
Expand README build instructions (#438)
Updating for the rewrite in #429
1 parent 3adc86a commit 2e7bb65

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed

README.md

+64-2
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,72 @@ Please refer to your OS documentation to install those packages.
4949

5050
## Build
5151

52-
To build the full package:
52+
Building `wasi-sdk` uses CMake and is split into two halves. First you can build
53+
the toolchain itself:
54+
55+
```shell script
56+
cmake -G Ninja -B build/toolchain -S . -DWASI_SDK_BUILD_TOOLCHAIN=ON -DCMAKE_INSTALL_PREFIX=build/install
57+
cmake --build build/toolchain --target install
58+
```
59+
60+
When you're developing locally you may also wish to pass
61+
`-DCMAKE_CXX_COMPILER_LAUNCHER=ccache` to assist with rebuilds. Other supported
62+
CMake flags are:
63+
64+
* `-DLLVM_CMAKE_FLAGS` - extra flags to pass to `cmake` when building
65+
LLVM/Clang.
66+
* `-DRUST_TARGET` - the specific Rust target triple to build `wasm-component-ld`
67+
for, useful for cross-compiles.
68+
69+
The `clang` compiler should now be located at `build/install/bin/clang` but it's
70+
just a compiler, the sysroot isn't built yet. Next the second step of the build
71+
is to build the sysroot:
72+
73+
```shell script
74+
cmake -G Ninja -B build/sysroot -S . \
75+
-DCMAKE_INSTALL_PREFIX=build/install \
76+
-DCMAKE_TOOLCHAIN_FILE=build/install/share/cmake/wasi-sdk.cmake \
77+
-DCMAKE_C_COMPILER_WORKS=ON \
78+
-DCMAKE_CXX_COMPILER_WORKS=ON
79+
cmake --build build/sysroot --target install
80+
```
81+
82+
A full toolchain should now be present at `build/install` and is ready for use
83+
in compiling WebAssembly code. Supported CMake flags are:
84+
85+
* `-DWASI_SDK_DEBUG_PREFIX_MAKE=OFF` - disable `-fdebug-prefix-map` when
86+
building C/C++ code to use full host paths instead.
87+
* `-DWASI_SDK_INCLUDE_TESTS=ON` - used for building tests.
88+
* `-DWASI_SDK_TARGETS=..` - a list of targets to build, by default all WASI
89+
targets are compiled.
90+
91+
If you'd like to build distribution artifacts you can use the `dist` target like
92+
so:
93+
94+
```shell script
95+
cmake --build build/toolchain --target dist
96+
cmake --build build/sysroot --target dist
97+
```
98+
99+
Tarballs will be created under `build/toolchain/dist` and `build/sysroot/dist`.
100+
Note that these are separate tarballs for the toolchain and sysroot. To create a
101+
single tarball for the entire SDK you'll first want to copy all tarballs into a
102+
new folder and then run the `./ci/merge-artifacts.sh` script:
103+
104+
```shell script
105+
mkdir dist-my-platform
106+
cp build/toolchain/dist/* build/sysroot/dist/* dist-my-platform
107+
./ci/merge-artifacts.sh
108+
```
109+
110+
This will produce `dist/wasi-sdk-*.tar.gz` which is the same as the release
111+
artifacts for this repository.
112+
113+
Finally you can additionally bundle many of the above steps, minus
114+
`merge-artifact.sh` by using the CI script to perform both the toolchain and
115+
sysroot build:
53116

54117
```shell script
55-
cd wasi-sdk
56118
./ci/build.sh
57119
```
58120

ci/merge-artifacts.sh

+9-4
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ make_deb() {
3939
rm -rf dist/pkg
4040
}
4141

42-
compiler_rt=`ls dist-x86_64-linux/libclang_rt*`
43-
4442
for build in dist-*; do
4543
toolchain=`ls $build/wasi-toolchain-*`
4644
if [ -f $build/wasi-sysroot-* ]; then
4745
sysroot=`ls $build/wasi-sysroot-*`
4846
else
4947
sysroot=`ls dist-x86_64-linux/wasi-sysroot-*`
5048
fi
49+
if [ -f $build/libclang_rt* ]; then
50+
compiler_rt=`ls $build/libclang_rt*`
51+
else
52+
compiler_rt=`ls dist-x86_64-linux/libclang_rt*`
53+
fi
5154

5255
sdk_dir=`basename $toolchain | sed 's/.tar.gz//' | sed s/toolchain/sdk/`
5356
mkdir dist/$sdk_dir
@@ -75,5 +78,7 @@ done
7578

7679
# In addition to `wasi-sdk-*` also preserve artifacts for just the sysroot
7780
# and just compiler-rt.
78-
cp dist-x86_64-linux/wasi-sysroot-* dist
79-
cp dist-x86_64-linux/libclang_rt* dist
81+
if [ -d dist-x86_64-linux ]; then
82+
cp dist-x86_64-linux/wasi-sysroot-* dist
83+
cp dist-x86_64-linux/libclang_rt* dist
84+
fi

0 commit comments

Comments
 (0)