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 all commits
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
8 changes: 6 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,13 @@ jobs:
if: runner.os == 'Linux'

# 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)
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
if: runner.os == 'Windows'

Expand Down
24 changes: 12 additions & 12 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,39 @@ set -ex
# Optionally allow the first argument to this script to be the install
# location.
if [ "$1" = "" ]; then
install_dir=`pwd`/build/install
build_dir=`pwd`/build
else
install_dir="$1"
build_dir="$1"
fi

cmake -G Ninja -B build/toolchain -S . \
cmake -G Ninja -B $build_dir/toolchain -S . \
-DWASI_SDK_BUILD_TOOLCHAIN=ON \
"-DCMAKE_INSTALL_PREFIX=$install_dir" \
"-DCMAKE_INSTALL_PREFIX=$build_dir/install" \
$WASI_SDK_CI_TOOLCHAIN_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
exit 0
fi

# Use the just-built toolchain and its `CMAKE_TOOLCHAIN_FILE` to build a
# sysroot.
cmake -G Ninja -B build/sysroot -S . \
"-DCMAKE_TOOLCHAIN_FILE=$install_dir/share/cmake/wasi-sdk.cmake" \
cmake -G Ninja -B $build_dir/sysroot -S . \
"-DCMAKE_TOOLCHAIN_FILE=$build_dir/install/share/cmake/wasi-sdk.cmake" \
-DCMAKE_C_COMPILER_WORKS=ON \
-DCMAKE_CXX_COMPILER_WORKS=ON \
-DWASI_SDK_INCLUDE_TESTS=ON \
"-DCMAKE_INSTALL_PREFIX=$install_dir"
ninja -C build/sysroot install dist -v
"-DCMAKE_INSTALL_PREFIX=$build_dir/install"
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
exit 0
fi

# 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
27 changes: 17 additions & 10 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,16 @@ endforeach()

# Install a `VERSION` file in the output prefix with a dump of version
# information.
set(version_file_tmp ${CMAKE_CURRENT_BINARY_DIR}/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})
OUTPUT_VARIABLE version_dump)
set(version_file_tmp ${CMAKE_CURRENT_BINARY_DIR}/VERSION)
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})

if(WASI_SDK_INCLUDE_TESTS)
add_subdirectory(tests)
Expand All @@ -264,13 +271,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)
add_dependencies(dist-sysroot build install)
${wasi_tmp_install}/share/wasi-sysroot)
add_dependencies(dist-sysroot build)

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