Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build of toolchain/sysroot to not touch installation root #446

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions cmake/wasi-sdk-sysroot.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ find_program(MAKE make REQUIRED)
option(WASI_SDK_DEBUG_PREFIX_MAP "Pass `-fdebug-prefix-map` for built artifacts" ON)
option(WASI_SDK_INCLUDE_TESTS "Whether or not to build tests by default" OFF)

set(wasi_sysroot ${CMAKE_INSTALL_PREFIX}/share/wasi-sysroot)
set(wasi_tmp_install ${CMAKE_CURRENT_BINARY_DIR}/install)
set(wasi_sysroot ${wasi_tmp_install}/share/wasi-sysroot)

if(WASI_SDK_DEBUG_PREFIX_MAP)
add_compile_options(
Expand Down Expand Up @@ -44,7 +45,7 @@ endif()
# compiler-rt build logic
# =============================================================================

set(compiler_rt_dst ${CMAKE_INSTALL_PREFIX}/lib/clang/${clang_version})
set(compiler_rt_dst ${wasi_tmp_install}/lib/clang/${clang_version})
ExternalProject_Add(compiler-rt-build
SOURCE_DIR "${llvm_proj_dir}/compiler-rt"
CMAKE_ARGS
Expand Down Expand Up @@ -234,6 +235,10 @@ endforeach()
# misc build logic
# =============================================================================

install(DIRECTORY ${wasi_tmp_install}/lib ${wasi_tmp_install}/share
USE_SOURCE_PERMISSIONS
DESTINATION ${CMAKE_INSTALL_PREFIX})

# Add a top-level `build` target as well as `build-$target` targets.
add_custom_target(build ALL)
foreach(target IN LISTS WASI_SDK_TARGETS)
Expand All @@ -244,14 +249,13 @@ endforeach()

# Install a `VERSION` file in the output prefix with a dump of version
# information.
set(version_file_tmp ${CMAKE_CURRENT_BINARY_DIR}/VERSION)
set(version_file_tmp ${wasi_tmp_install}/VERSION)
execute_process(
COMMAND ${PYTHON} ${version_script} dump
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_FILE ${version_file_tmp})
install(
FILES ${version_file_tmp}
DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES ${wasi_tmp_install}/VERSION
DESTINATION ${CMAKE_INSTALL_PREFIX})

if(WASI_SDK_INCLUDE_TESTS)
add_subdirectory(tests)
Expand All @@ -264,13 +268,13 @@ set(dist_dir ${CMAKE_CURRENT_BINARY_DIR}/dist)
# Tarball with just `compiler-rt` builtins within it
wasi_sdk_add_tarball(dist-compiler-rt
${dist_dir}/libclang_rt.builtins-wasm32-wasi-${wasi_sdk_version}.tar.gz
${CMAKE_INSTALL_PREFIX}/lib/clang/${clang_version}/lib/wasi)
${wasi_tmp_install}/lib/clang/${clang_version}/lib/wasi)
add_dependencies(dist-compiler-rt compiler-rt)

# Tarball with the whole sysroot
wasi_sdk_add_tarball(dist-sysroot
${dist_dir}/wasi-sysroot-${wasi_sdk_version}.tar.gz
${CMAKE_INSTALL_PREFIX}/share/wasi-sysroot)
${wasi_tmp_install}/share/wasi-sysroot)
add_dependencies(dist-sysroot build install)

add_custom_target(dist DEPENDS dist-compiler-rt dist-sysroot)
56 changes: 38 additions & 18 deletions cmake/wasi-sdk-toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ set(WASI_SDK_ARTIFACT "" CACHE STRING "Name of the wasi-sdk artifact being produ

string(REGEX REPLACE "[ ]+" ";" llvm_cmake_flags_list "${LLVM_CMAKE_FLAGS}")

set(wasi_tmp_install ${CMAKE_CURRENT_BINARY_DIR}/install)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE MinSizeRel)
endif()
Expand All @@ -16,7 +18,7 @@ set(default_cmake_args
-DCMAKE_AR=${CMAKE_AR}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})
-DCMAKE_INSTALL_PREFIX=${wasi_tmp_install})

if(CMAKE_C_COMPILER_LAUNCHER)
list(APPEND default_cmake_args -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER})
Expand Down Expand Up @@ -106,6 +108,14 @@ ExternalProject_Add(llvm-build
USES_TERMINAL_INSTALL ON
)

add_custom_target(build ALL DEPENDS llvm-build)

# Installation target for this outer project for installing the toolchain to the
# system.
install(DIRECTORY ${wasi_tmp_install}/bin ${wasi_tmp_install}/lib ${wasi_tmp_install}/share
USE_SOURCE_PERMISSIONS
DESTINATION ${CMAKE_INSTALL_PREFIX})

# Build logic for `wasm-component-ld` installed from Rust code.
set(wasm_component_ld_root ${CMAKE_CURRENT_BINARY_DIR}/wasm-component-ld)
set(wasm_component_ld ${wasm_component_ld_root}/bin/wasm-component-ld${CMAKE_EXECUTABLE_SUFFIX})
Expand All @@ -118,24 +128,34 @@ add_custom_command(
COMMAND
cargo install --root ${wasm_component_ld_root} ${rust_target_flag}
wasm-component-ld@${wasm_component_ld_version}
COMMAND
cmake -E make_directory ${wasi_tmp_install}/bin
COMMAND
cmake -E copy ${wasm_component_ld} ${wasi_tmp_install}/bin
COMMENT "Building `wasm-component-ld` ...")

add_custom_target(wasm-component-ld ALL DEPENDS ${wasm_component_ld})

install(
PROGRAMS ${wasm_component_ld}
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
add_custom_target(wasm-component-ld DEPENDS ${wasm_component_ld})
add_dependencies(build wasm-component-ld)

# Setup installation logic for CMake support files.
install(
PROGRAMS src/config/config.sub src/config/config.guess
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/misc)
install(
FILES wasi-sdk.cmake wasi-sdk-pthread.cmake wasi-sdk-p2.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake)
install(
DIRECTORY cmake/Platform
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake)
add_custom_target(misc-files)
add_dependencies(build misc-files)

function(copy_misc_file src dst_folder)
cmake_path(GET src FILENAME src_filename)
set(dst ${wasi_tmp_install}/share/${dst_folder}/${src_filename})
add_custom_command(
OUTPUT ${dst}
COMMAND cmake -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${src} ${dst})
add_custom_target(copy-${src_filename} DEPENDS ${dst})
add_dependencies(misc-files copy-${src_filename})
endfunction()

copy_misc_file(src/config/config.sub misc)
copy_misc_file(src/config/config.guess misc)
copy_misc_file(wasi-sdk.cmake cmake)
copy_misc_file(wasi-sdk-pthread.cmake cmake)
copy_misc_file(wasi-sdk-p2.cmake cmake)
copy_misc_file(cmake/Platform/WASI.cmake cmake/Platform)

include(wasi-sdk-dist)

Expand All @@ -156,6 +176,6 @@ endif()
set(dist_dir ${CMAKE_CURRENT_BINARY_DIR}/dist)
wasi_sdk_add_tarball(dist-toolchain
${dist_dir}/wasi-toolchain-${wasi_sdk_version}-${wasi_sdk_artifact}.tar.gz
${CMAKE_INSTALL_PREFIX})
add_dependencies(dist-toolchain llvm-build install)
${wasi_tmp_install})
add_dependencies(dist-toolchain build)
add_custom_target(dist DEPENDS dist-toolchain)
Loading