From 2e7bb65533b2a8d038a41bd1caca5d2212396492 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 12 Jul 2024 10:38:50 -0500 Subject: [PATCH] Expand README build instructions (#438) Updating for the rewrite in #429 --- README.md | 66 +++++++++++++++++++++++++++++++++++++++++-- ci/merge-artifacts.sh | 13 ++++++--- 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 72e01f9..9632be9 100644 --- a/README.md +++ b/README.md @@ -49,10 +49,72 @@ Please refer to your OS documentation to install those packages. ## Build -To build the full package: +Building `wasi-sdk` uses CMake and is split into two halves. First you can build +the toolchain itself: + +```shell script +cmake -G Ninja -B build/toolchain -S . -DWASI_SDK_BUILD_TOOLCHAIN=ON -DCMAKE_INSTALL_PREFIX=build/install +cmake --build build/toolchain --target install +``` + +When you're developing locally you may also wish to pass +`-DCMAKE_CXX_COMPILER_LAUNCHER=ccache` to assist with rebuilds. Other supported +CMake flags are: + +* `-DLLVM_CMAKE_FLAGS` - extra flags to pass to `cmake` when building + LLVM/Clang. +* `-DRUST_TARGET` - the specific Rust target triple to build `wasm-component-ld` + for, useful for cross-compiles. + +The `clang` compiler should now be located at `build/install/bin/clang` but it's +just a compiler, the sysroot isn't built yet. Next the second step of the build +is to build the sysroot: + +```shell script +cmake -G Ninja -B build/sysroot -S . \ + -DCMAKE_INSTALL_PREFIX=build/install \ + -DCMAKE_TOOLCHAIN_FILE=build/install/share/cmake/wasi-sdk.cmake \ + -DCMAKE_C_COMPILER_WORKS=ON \ + -DCMAKE_CXX_COMPILER_WORKS=ON +cmake --build build/sysroot --target install +``` + +A full toolchain should now be present at `build/install` and is ready for use +in compiling WebAssembly code. Supported CMake flags are: + +* `-DWASI_SDK_DEBUG_PREFIX_MAKE=OFF` - disable `-fdebug-prefix-map` when + building C/C++ code to use full host paths instead. +* `-DWASI_SDK_INCLUDE_TESTS=ON` - used for building tests. +* `-DWASI_SDK_TARGETS=..` - a list of targets to build, by default all WASI + targets are compiled. + +If you'd like to build distribution artifacts you can use the `dist` target like +so: + +```shell script +cmake --build build/toolchain --target dist +cmake --build build/sysroot --target dist +``` + +Tarballs will be created under `build/toolchain/dist` and `build/sysroot/dist`. +Note that these are separate tarballs for the toolchain and sysroot. To create a +single tarball for the entire SDK you'll first want to copy all tarballs into a +new folder and then run the `./ci/merge-artifacts.sh` script: + +```shell script +mkdir dist-my-platform +cp build/toolchain/dist/* build/sysroot/dist/* dist-my-platform +./ci/merge-artifacts.sh +``` + +This will produce `dist/wasi-sdk-*.tar.gz` which is the same as the release +artifacts for this repository. + +Finally you can additionally bundle many of the above steps, minus +`merge-artifact.sh` by using the CI script to perform both the toolchain and +sysroot build: ```shell script -cd wasi-sdk ./ci/build.sh ``` diff --git a/ci/merge-artifacts.sh b/ci/merge-artifacts.sh index 0ef7e71..e55db2d 100755 --- a/ci/merge-artifacts.sh +++ b/ci/merge-artifacts.sh @@ -39,8 +39,6 @@ make_deb() { rm -rf dist/pkg } -compiler_rt=`ls dist-x86_64-linux/libclang_rt*` - for build in dist-*; do toolchain=`ls $build/wasi-toolchain-*` if [ -f $build/wasi-sysroot-* ]; then @@ -48,6 +46,11 @@ for build in dist-*; do else sysroot=`ls dist-x86_64-linux/wasi-sysroot-*` fi + if [ -f $build/libclang_rt* ]; then + compiler_rt=`ls $build/libclang_rt*` + else + compiler_rt=`ls dist-x86_64-linux/libclang_rt*` + fi sdk_dir=`basename $toolchain | sed 's/.tar.gz//' | sed s/toolchain/sdk/` mkdir dist/$sdk_dir @@ -75,5 +78,7 @@ done # In addition to `wasi-sdk-*` also preserve artifacts for just the sysroot # and just compiler-rt. -cp dist-x86_64-linux/wasi-sysroot-* dist -cp dist-x86_64-linux/libclang_rt* dist +if [ -d dist-x86_64-linux ]; then + cp dist-x86_64-linux/wasi-sysroot-* dist + cp dist-x86_64-linux/libclang_rt* dist +fi