Skip to content

Commit 48ab22f

Browse files
Enable per-target runtime directory for compiler-rt
This change allows us to have per-target libclang_rt.* libraries instead of per-OS. This is particularly required for w/threads and wo/threads targets, whose rt libraries could be incompatible even with the same OS string. This change starts building `compiler-rt` for w/threads and wo/threads separately, so that we can enable thread-related features for p1-threads target for building upcoming ASan clang_rt libraries. Also `COMPILER_RT_OS_DIR` is not set anymore as it's unused when `LLVM_ENABLE_PER_TARGET_RUNTIME_DIR` is enabled.
1 parent 38c9744 commit 48ab22f

File tree

3 files changed

+45
-38
lines changed

3 files changed

+45
-38
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ convenience.
2424
One could also use a standard Clang installation, build a sysroot from the
2525
sources mentioned above, and compile with `--target=wasm32-wasi
2626
--sysroot=/path/to/sysroot`. In this scenario, one would also need the
27-
`libclang_rt.builtins-wasm32.a` objects available separately in the [release
27+
`libclang_rt.*.a` objects available separately in the [release
2828
downloads][releases] which must be extracted into
29-
`$CLANG_INSTALL_DIR/$CLANG_VERSION/lib/wasi/`.
29+
`$CLANG_INSTALL_DIR/$CLANG_VERSION/lib/`.
3030

3131
## Clone
3232

ci/merge-artifacts.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,9 @@ for build in dist-*; do
6262
tar xf $sysroot -C dist/$sdk_dir/share/wasi-sysroot --strip-components 1
6363
mv dist/$sdk_dir/share/wasi-sysroot/VERSION dist/$sdk_dir
6464

65-
# Setup the compiler-rt library for wasi,wasip1,wasip2
65+
# Setup the compiler-rt library for all targets.
6666
rtlibdir=$(dirname $(find dist/$sdk_dir/lib -name include))/lib
67-
mkdir -p $rtlibdir/wasi
68-
tar xf $compiler_rt -C $rtlibdir/wasi --strip-components 1
69-
cp -r $rtlibdir/wasi $rtlibdir/wasip1
70-
cp -r $rtlibdir/wasi $rtlibdir/wasip2
67+
tar xf $compiler_rt -C $rtlibdir --strip-components 1
7168

7269
tar czf dist/$sdk_dir.tar.gz -C dist $sdk_dir
7370

cmake/wasi-sdk-sysroot.cmake

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,38 @@ endif()
6666
# compiler-rt build logic
6767
# =============================================================================
6868

69-
ExternalProject_Add(compiler-rt-build
70-
SOURCE_DIR "${llvm_proj_dir}/compiler-rt"
71-
CMAKE_ARGS
72-
${default_cmake_args}
73-
-DCOMPILER_RT_BAREMETAL_BUILD=ON
74-
-DCOMPILER_RT_BUILD_XRAY=OFF
75-
-DCOMPILER_RT_INCLUDE_TESTS=OFF
76-
-DCOMPILER_RT_HAS_FPIC_FLAG=OFF
77-
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
78-
-DCOMPILER_RT_BUILD_SANITIZERS=OFF
79-
-DCOMPILER_RT_BUILD_XRAY=OFF
80-
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF
81-
-DCOMPILER_RT_BUILD_PROFILE=OFF
82-
-DCOMPILER_RT_BUILD_CTX_PROFILE=OFF
83-
-DCOMPILER_RT_BUILD_MEMPROF=OFF
84-
-DCOMPILER_RT_BUILD_ORC=OFF
85-
-DCOMPILER_RT_BUILD_GWP_ASAN=OFF
86-
-DCMAKE_C_COMPILER_TARGET=wasm32-wasi
87-
-DCOMPILER_RT_OS_DIR=wasi
88-
-DCMAKE_INSTALL_PREFIX=${wasi_resource_dir}
89-
EXCLUDE_FROM_ALL ON
90-
USES_TERMINAL_CONFIGURE ON
91-
USES_TERMINAL_BUILD ON
92-
USES_TERMINAL_INSTALL ON
93-
)
69+
add_custom_target(compiler-rt-build)
70+
function(define_compiler_rt target)
71+
ExternalProject_Add(compiler-rt-build-${target}
72+
SOURCE_DIR "${llvm_proj_dir}/compiler-rt"
73+
CMAKE_ARGS
74+
${default_cmake_args}
75+
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
76+
-DCOMPILER_RT_BAREMETAL_BUILD=ON
77+
-DCOMPILER_RT_BUILD_XRAY=OFF
78+
-DCOMPILER_RT_INCLUDE_TESTS=OFF
79+
-DCOMPILER_RT_HAS_FPIC_FLAG=OFF
80+
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
81+
-DCOMPILER_RT_BUILD_SANITIZERS=OFF
82+
-DCOMPILER_RT_BUILD_XRAY=OFF
83+
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF
84+
-DCOMPILER_RT_BUILD_PROFILE=OFF
85+
-DCOMPILER_RT_BUILD_CTX_PROFILE=OFF
86+
-DCOMPILER_RT_BUILD_MEMPROF=OFF
87+
-DCOMPILER_RT_BUILD_ORC=OFF
88+
-DCOMPILER_RT_BUILD_GWP_ASAN=OFF
89+
-DCMAKE_C_COMPILER_TARGET=${target}
90+
-DCMAKE_INSTALL_PREFIX=${wasi_resource_dir}
91+
EXCLUDE_FROM_ALL ON
92+
USES_TERMINAL_CONFIGURE ON
93+
USES_TERMINAL_BUILD ON
94+
USES_TERMINAL_INSTALL ON
95+
)
96+
add_dependencies(compiler-rt-build compiler-rt-build-${target})
97+
endfunction()
98+
99+
define_compiler_rt(wasm32-wasi)
100+
define_compiler_rt(wasm32-wasip1-threads)
94101

95102
# In addition to the default installation of `compiler-rt` itself also copy
96103
# around some headers and make copies of the `wasi` directory as `wasip1` and
@@ -106,12 +113,15 @@ add_custom_target(compiler-rt-post-build
106113
COMMAND ${CMAKE_COMMAND} -E copy_directory
107114
${clang_resource_dir}/include ${wasi_resource_dir}/include
108115

109-
# Copy the `lib/wasi` folder to `libc/wasi{p1,p2}` to ensure that those
116+
# Copy the `lib/wasm32-unknown-wasi` folder to `libc/wasm32-unknown-wasi{p1,p2}` to ensure that those
110117
# OS-strings also work for looking up the compiler-rt.a file.
111118
COMMAND ${CMAKE_COMMAND} -E copy_directory
112-
${wasi_resource_dir}/lib/wasi ${wasi_resource_dir}/lib/wasip1
119+
${wasi_resource_dir}/lib/wasm32-unknown-wasi ${wasi_resource_dir}/lib/wasm32-unknown-wasip1
120+
COMMAND ${CMAKE_COMMAND} -E copy_directory
121+
${wasi_resource_dir}/lib/wasm32-unknown-wasi ${wasi_resource_dir}/lib/wasm32-unknown-wasip2
122+
# Copy the `lib/wasm32-unknown-wasip1-threads` folder to `libc/wasm32-unknown-wasi-threads`
113123
COMMAND ${CMAKE_COMMAND} -E copy_directory
114-
${wasi_resource_dir}/lib/wasi ${wasi_resource_dir}/lib/wasip2
124+
${wasi_resource_dir}/lib/wasm32-unknown-wasip1-threads ${wasi_resource_dir}/lib/wasm32-unknown-wasi-threads
115125

116126
COMMENT "finalizing compiler-rt installation"
117127
)
@@ -357,10 +367,10 @@ include(wasi-sdk-dist)
357367

358368
set(dist_dir ${CMAKE_CURRENT_BINARY_DIR}/dist)
359369

360-
# Tarball with just `compiler-rt` builtins within it
370+
# Tarball with just `compiler-rt` libraries within it
361371
wasi_sdk_add_tarball(dist-compiler-rt
362-
${dist_dir}/libclang_rt.builtins-wasm32-wasi-${wasi_sdk_version}.tar.gz
363-
${wasi_resource_dir}/lib/wasi)
372+
${dist_dir}/libclang_rt-${wasi_sdk_version}.tar.gz
373+
${wasi_resource_dir}/lib)
364374
add_dependencies(dist-compiler-rt compiler-rt)
365375

366376
# Tarball with the whole sysroot

0 commit comments

Comments
 (0)