Always build wasm32-wasip2 with `-fPIC`

This commit updates the build of the `wasm32-wasip2` target to always
pass `-fPIC` to compilation of wasi-libc. This notably enables using
`libc.a` in dynamic linking situations instead of being forced to use
`libc.so`. While many applications likely want to use `libc.so` I've
found it more flexible if objects are compatible with as many builds as
possible. This will enable, for example, building shared libraries in
Rust by default since Rust only ships `libc.a`, not `libc.so`, in the
pre-built sysroot. This behavior additionally matches the Rust
`wasm32-wasip2` target where `-fPIC` is enabled by default there.
pull/564/head
Alex Crichton 5 days ago
parent d90d7de10e
commit b7d75701aa

@ -139,31 +139,31 @@ add_custom_target(compiler-rt DEPENDS compiler-rt-build compiler-rt-post-build)
function(define_wasi_libc_sub target target_suffix lto)
set(build_dir ${CMAKE_CURRENT_BINARY_DIR}/wasi-libc-${target}${target_suffix})
if(${target} MATCHES threads)
if(lto)
set(extra_make_flags LTO=full THREAD_MODEL=posix)
else()
set(extra_make_flags THREAD_MODEL=posix)
endif()
elseif(${target} MATCHES p2)
if(lto)
set(extra_make_flags LTO=full WASI_SNAPSHOT=p2 default)
else()
set(extra_make_flags WASI_SNAPSHOT=p2 default libc_so)
endif()
else()
if(lto)
set(extra_make_flags LTO=full default)
else()
set(extra_make_flags default libc_so)
endif()
endif()
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
get_property(directory_cflags DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_OPTIONS)
list(APPEND directory_cflags -resource-dir ${wasi_resource_dir})
set(extra_cflags_list
"${WASI_SDK_CPU_CFLAGS} ${CMAKE_C_FLAGS} ${directory_cflags} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
set(extra_make_flags default)
# If LTO is enabled then pass that on to wasi-libc, and otherwise make sure to
# build a `libc.so` dynamic library.
if(lto)
list(APPEND extra_make_flags LTO=full)
else()
list(APPEND extra_make_flags libc_so)
endif()
if(${target} MATCHES threads)
list(APPEND extra_make_flags THREAD_MODEL=posix)
elseif(${target} MATCHES p2)
list(APPEND extra_make_flags WASI_SNAPSHOT=p2)
# Always enable `-fPIC` for the `wasm32-wasip2` target. This makes `libc.a`
# more flexible and usable in dynamic linking situations.
list(APPEND extra_cflags_list -fPIC)
endif()
list(JOIN extra_cflags_list " " extra_cflags)
if(${target} MATCHES threads)

@ -1 +1 @@
Subproject commit bbb0c01b112f8c3aaa1974407c5302a26b88babb
Subproject commit 008d705c9d16dc9057bb6efc220fb539f1fb7fb5
Loading…
Cancel
Save