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

* Update build of toolchain/sysroot to not touch installation root

This changes everything to ensure that only the `install` step actually
tries to install things. Everything is staged into temporary `./install`
folders inside of the build directory and then running the build
system's `install` target will actually copy out everything using CMake
builtins.

Closes #442

* Better integrate generating a version file
pull/448/head
Alex Crichton 6 months ago committed by GitHub
parent de6328701c
commit 489ce6eb41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -119,9 +119,13 @@ jobs:
if: runner.os == 'Linux' if: runner.os == 'Linux'
# Use a shorter build directory than the default on Windows to avoid # Use a shorter build directory than the default on Windows to avoid
# hitting path length and command line length limits. # hitting path length and command line length limits. See
# WebAssembly/wasi-libc#514
- name: Build and test (Windows) - name: Build and test (Windows)
run: ./ci/build.sh C:/wasi-sdk run: |
./ci/build.sh C:/wasi-sdk
mkdir build
cp -r C:/wasi-sdk/dist build
shell: bash shell: bash
if: runner.os == 'Windows' if: runner.os == 'Windows'

@ -11,19 +11,19 @@ set -ex
# Optionally allow the first argument to this script to be the install # Optionally allow the first argument to this script to be the install
# location. # location.
if [ "$1" = "" ]; then if [ "$1" = "" ]; then
install_dir=`pwd`/build/install build_dir=`pwd`/build
else else
install_dir="$1" build_dir="$1"
fi fi
cmake -G Ninja -B build/toolchain -S . \ cmake -G Ninja -B $build_dir/toolchain -S . \
-DWASI_SDK_BUILD_TOOLCHAIN=ON \ -DWASI_SDK_BUILD_TOOLCHAIN=ON \
"-DCMAKE_INSTALL_PREFIX=$install_dir" \ "-DCMAKE_INSTALL_PREFIX=$build_dir/install" \
$WASI_SDK_CI_TOOLCHAIN_CMAKE_ARGS \ $WASI_SDK_CI_TOOLCHAIN_CMAKE_ARGS \
"-DLLVM_CMAKE_FLAGS=$WASI_SDK_CI_TOOLCHAIN_LLVM_CMAKE_ARGS" "-DLLVM_CMAKE_FLAGS=$WASI_SDK_CI_TOOLCHAIN_LLVM_CMAKE_ARGS"
ninja -C build/toolchain install dist -v ninja -C $build_dir/toolchain install dist -v
mv build/toolchain/dist build/dist mv $build_dir/toolchain/dist $build_dir/dist
if [ "$WASI_SDK_CI_SKIP_SYSROOT" = "1" ]; then if [ "$WASI_SDK_CI_SKIP_SYSROOT" = "1" ]; then
exit 0 exit 0
@ -31,19 +31,19 @@ fi
# Use the just-built toolchain and its `CMAKE_TOOLCHAIN_FILE` to build a # Use the just-built toolchain and its `CMAKE_TOOLCHAIN_FILE` to build a
# sysroot. # sysroot.
cmake -G Ninja -B build/sysroot -S . \ cmake -G Ninja -B $build_dir/sysroot -S . \
"-DCMAKE_TOOLCHAIN_FILE=$install_dir/share/cmake/wasi-sdk.cmake" \ "-DCMAKE_TOOLCHAIN_FILE=$build_dir/install/share/cmake/wasi-sdk.cmake" \
-DCMAKE_C_COMPILER_WORKS=ON \ -DCMAKE_C_COMPILER_WORKS=ON \
-DCMAKE_CXX_COMPILER_WORKS=ON \ -DCMAKE_CXX_COMPILER_WORKS=ON \
-DWASI_SDK_INCLUDE_TESTS=ON \ -DWASI_SDK_INCLUDE_TESTS=ON \
"-DCMAKE_INSTALL_PREFIX=$install_dir" "-DCMAKE_INSTALL_PREFIX=$build_dir/install"
ninja -C build/sysroot install dist -v ninja -C $build_dir/sysroot install dist -v
mv build/sysroot/dist/* build/dist mv $build_dir/sysroot/dist/* $build_dir/dist
if [ "$WASI_SDK_CI_SKIP_TESTS" = "1" ]; then if [ "$WASI_SDK_CI_SKIP_TESTS" = "1" ]; then
exit 0 exit 0
fi fi
# Run tests to ensure that the sysroot works. # Run tests to ensure that the sysroot works.
ctest --output-on-failure --parallel 10 --test-dir build/sysroot/tests ctest --output-on-failure --parallel 10 --test-dir $build_dir/sysroot/tests

@ -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_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) 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) if(WASI_SDK_DEBUG_PREFIX_MAP)
add_compile_options( add_compile_options(
@ -44,7 +45,7 @@ endif()
# compiler-rt build logic # 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 ExternalProject_Add(compiler-rt-build
SOURCE_DIR "${llvm_proj_dir}/compiler-rt" SOURCE_DIR "${llvm_proj_dir}/compiler-rt"
CMAKE_ARGS CMAKE_ARGS
@ -234,6 +235,10 @@ endforeach()
# misc build logic # 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 a top-level `build` target as well as `build-$target` targets.
add_custom_target(build ALL) add_custom_target(build ALL)
foreach(target IN LISTS WASI_SDK_TARGETS) foreach(target IN LISTS WASI_SDK_TARGETS)
@ -244,13 +249,15 @@ endforeach()
# Install a `VERSION` file in the output prefix with a dump of version # Install a `VERSION` file in the output prefix with a dump of version
# information. # information.
set(version_file_tmp ${CMAKE_CURRENT_BINARY_DIR}/VERSION)
execute_process( execute_process(
COMMAND ${PYTHON} ${version_script} dump COMMAND ${PYTHON} ${version_script} dump
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_FILE ${version_file_tmp}) OUTPUT_VARIABLE version_dump)
install( set(version_file_tmp ${CMAKE_CURRENT_BINARY_DIR}/VERSION)
FILES ${version_file_tmp} file(GENERATE OUTPUT ${version_file_tmp} CONTENT ${version_dump})
add_custom_target(version-file DEPENDS ${version_file_tmp})
add_dependencies(build version-file)
install(FILES ${version_file_tmp}
DESTINATION ${CMAKE_INSTALL_PREFIX}) DESTINATION ${CMAKE_INSTALL_PREFIX})
if(WASI_SDK_INCLUDE_TESTS) if(WASI_SDK_INCLUDE_TESTS)
@ -264,13 +271,13 @@ set(dist_dir ${CMAKE_CURRENT_BINARY_DIR}/dist)
# Tarball with just `compiler-rt` builtins within it # Tarball with just `compiler-rt` builtins within it
wasi_sdk_add_tarball(dist-compiler-rt wasi_sdk_add_tarball(dist-compiler-rt
${dist_dir}/libclang_rt.builtins-wasm32-wasi-${wasi_sdk_version}.tar.gz ${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) add_dependencies(dist-compiler-rt compiler-rt)
# Tarball with the whole sysroot # Tarball with the whole sysroot
wasi_sdk_add_tarball(dist-sysroot wasi_sdk_add_tarball(dist-sysroot
${dist_dir}/wasi-sysroot-${wasi_sdk_version}.tar.gz ${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_dependencies(dist-sysroot build)
add_custom_target(dist DEPENDS dist-compiler-rt dist-sysroot) add_custom_target(dist DEPENDS dist-compiler-rt dist-sysroot)

@ -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}") string(REGEX REPLACE "[ ]+" ";" llvm_cmake_flags_list "${LLVM_CMAKE_FLAGS}")
set(wasi_tmp_install ${CMAKE_CURRENT_BINARY_DIR}/install)
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE MinSizeRel) set(CMAKE_BUILD_TYPE MinSizeRel)
endif() endif()
@ -16,7 +18,7 @@ set(default_cmake_args
-DCMAKE_AR=${CMAKE_AR} -DCMAKE_AR=${CMAKE_AR}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}) -DCMAKE_INSTALL_PREFIX=${wasi_tmp_install})
if(CMAKE_C_COMPILER_LAUNCHER) if(CMAKE_C_COMPILER_LAUNCHER)
list(APPEND default_cmake_args -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}) list(APPEND default_cmake_args -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER})
@ -106,6 +108,14 @@ ExternalProject_Add(llvm-build
USES_TERMINAL_INSTALL ON 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. # 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_root ${CMAKE_CURRENT_BINARY_DIR}/wasm-component-ld)
set(wasm_component_ld ${wasm_component_ld_root}/bin/wasm-component-ld${CMAKE_EXECUTABLE_SUFFIX}) set(wasm_component_ld ${wasm_component_ld_root}/bin/wasm-component-ld${CMAKE_EXECUTABLE_SUFFIX})
@ -118,24 +128,34 @@ add_custom_command(
COMMAND COMMAND
cargo install --root ${wasm_component_ld_root} ${rust_target_flag} cargo install --root ${wasm_component_ld_root} ${rust_target_flag}
wasm-component-ld@${wasm_component_ld_version} 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` ...") COMMENT "Building `wasm-component-ld` ...")
add_custom_target(wasm-component-ld DEPENDS ${wasm_component_ld})
add_custom_target(wasm-component-ld ALL DEPENDS ${wasm_component_ld}) add_dependencies(build wasm-component-ld)
install(
PROGRAMS ${wasm_component_ld}
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
# Setup installation logic for CMake support files. # Setup installation logic for CMake support files.
install( add_custom_target(misc-files)
PROGRAMS src/config/config.sub src/config/config.guess add_dependencies(build misc-files)
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/misc)
install( function(copy_misc_file src dst_folder)
FILES wasi-sdk.cmake wasi-sdk-pthread.cmake wasi-sdk-p2.cmake cmake_path(GET src FILENAME src_filename)
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake) set(dst ${wasi_tmp_install}/share/${dst_folder}/${src_filename})
install( add_custom_command(
DIRECTORY cmake/Platform OUTPUT ${dst}
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake) 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) include(wasi-sdk-dist)
@ -156,6 +176,6 @@ endif()
set(dist_dir ${CMAKE_CURRENT_BINARY_DIR}/dist) set(dist_dir ${CMAKE_CURRENT_BINARY_DIR}/dist)
wasi_sdk_add_tarball(dist-toolchain wasi_sdk_add_tarball(dist-toolchain
${dist_dir}/wasi-toolchain-${wasi_sdk_version}-${wasi_sdk_artifact}.tar.gz ${dist_dir}/wasi-toolchain-${wasi_sdk_version}-${wasi_sdk_artifact}.tar.gz
${CMAKE_INSTALL_PREFIX}) ${wasi_tmp_install})
add_dependencies(dist-toolchain llvm-build install) add_dependencies(dist-toolchain build)
add_custom_target(dist DEPENDS dist-toolchain) add_custom_target(dist DEPENDS dist-toolchain)

Loading…
Cancel
Save