@@ -49,10 +49,72 @@ Please refer to your OS documentation to install those packages.
49
49
50
50
## Build
51
51
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:
53
116
54
117
``` shell script
55
- cd wasi-sdk
56
118
./ci/build.sh
57
119
```
58
120
0 commit comments