From 4d1979f7acc5d90a1fbe95ff1aee22c9166bf7c2 Mon Sep 17 00:00:00 2001 From: "Janne Kiviluoto (NVIDIA)" <235827468+jkiviluoto-nv@users.noreply.github.com> Date: Wed, 3 Jun 2026 21:15:00 +0300 Subject: [PATCH] Allow install of static slang library The install(EXPORT SlangTargets) step and the UNIX pkgconfig install were skipped whenever SLANG_LIB_TYPE was STATIC. The guard was added in #6158 to work around the export errors in #5821: slang's internal link dependencies (core, prelude, compiler-core, slang-capability-*, slang-lookup-tables, SPIRV-Headers, ...) leaked onto its public link interface and weren't in any export set, so install(EXPORT ...) failed. That guard is now obsolete. slang_add_target wraps private link deps in $ / $, so those targets no longer appear in the install/export interface and a static install exports cleanly. The guard also masked a second bug: configure_package_config_file runs unconditionally and the generated slangConfig.cmake unconditionally include()s slangTargets.cmake, so a static install used to ship a config that pointed at a Targets file that was never installed, making find_package(slang) fail with a confusing "file not found". Removing the guard fixes both: a static install now exports SlangTargets and find_package(slang) resolves the slang::slang target. Also add CI coverage: the CMake Options workflow already builds the SLANG_LIB_TYPE=STATIC entry, but only configured and built it and never ran cmake --install, so this regression would not have been caught. Add an install_test matrix flag and a 'cmake --install' step (in both the host and container build workflows) that runs for entries opting in via that flag. Fixes #11359 --- .github/cmake-options-matrix.json | 3 +- .../cmake-options-build-container.yml | 8 +++ .github/workflows/cmake-options-build.yml | 8 +++ CMakeLists.txt | 49 +++++++++++-------- 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/.github/cmake-options-matrix.json b/.github/cmake-options-matrix.json index 2ff8f6b1a9d..725ccbdebe6 100644 --- a/.github/cmake-options-matrix.json +++ b/.github/cmake-options-matrix.json @@ -53,7 +53,8 @@ }, { "option": "SLANG_LIB_TYPE", - "value": "STATIC" + "value": "STATIC", + "install_test": "true" }, { "option": "SLANG_ENABLE_ASAN", diff --git a/.github/workflows/cmake-options-build-container.yml b/.github/workflows/cmake-options-build-container.yml index f171b75f851..6213caa63ee 100644 --- a/.github/workflows/cmake-options-build-container.yml +++ b/.github/workflows/cmake-options-build-container.yml @@ -146,3 +146,11 @@ jobs: # don't abort the build when ASAN is enabled. No-op for other options. ASAN_OPTIONS: detect_leaks=0 run: cmake --build build --config "$cmake_config" + + # Exercise `cmake --install` for entries that opt in via install_test. + # The static-lib build (SLANG_LIB_TYPE=STATIC) used to skip the + # install(EXPORT ...) step entirely, so a broken export would not have + # been caught by a plain configure+build. See issue #11359. + - name: Install Slang (${{ matrix.option }}) + if: matrix.install_test == 'true' && matrix.windows_only != 'true' + run: cmake --install build --config "$cmake_config" --prefix install diff --git a/.github/workflows/cmake-options-build.yml b/.github/workflows/cmake-options-build.yml index df95f4d5442..c7e08243544 100644 --- a/.github/workflows/cmake-options-build.yml +++ b/.github/workflows/cmake-options-build.yml @@ -177,3 +177,11 @@ jobs: - name: Build Slang (${{ matrix.option }}) if: (matrix.linux_only != 'true' || inputs.os == 'linux') && (matrix.windows_only != 'true' || inputs.os == 'windows') && matrix.container_only != 'true' && (matrix.skip_linux_aarch64 != 'true' || inputs.os != 'linux' || inputs.platform != 'aarch64') run: cmake --build build --config "$cmake_config" + + # Exercise `cmake --install` for entries that opt in via install_test. + # The static-lib build (SLANG_LIB_TYPE=STATIC) used to skip the + # install(EXPORT ...) step entirely, so a broken export would not have + # been caught by a plain configure+build. See issue #11359. + - name: Install Slang (${{ matrix.option }}) + if: matrix.install_test == 'true' && (matrix.linux_only != 'true' || inputs.os == 'linux') && (matrix.windows_only != 'true' || inputs.os == 'windows') && matrix.container_only != 'true' && (matrix.skip_linux_aarch64 != 'true' || inputs.os != 'linux' || inputs.platform != 'aarch64') + run: cmake --install build --config "$cmake_config" --prefix install diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fed973bdba..994d4d7603a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -663,29 +663,38 @@ configure_package_config_file( # Conditionally handle the case for Emscripten where slang does not create # linkable targets. In this case do not export the targets. Otherwise, just # export the slang targets. +# +# A STATIC build used to be excluded here because slang's internal link +# dependencies (core, prelude, compiler-core, slang-capability-*, +# slang-lookup-tables, SPIRV-Headers, ...) leaked onto its public link +# interface and weren't in any export set, which made install(EXPORT ...) fail +# (see issue #5821 / PR #6158). slang_add_target now wraps private link deps in +# $ / $ (cmake/SlangTarget.cmake), +# so those targets no longer appear in the install/export interface and a static +# install exports cleanly. Exporting also for STATIC keeps SlangConfig.cmake's +# unconditional include() of slangTargets.cmake (cmake/SlangConfig.cmake.in) +# satisfied, so find_package(slang) works for static installs too. if(NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") - if(NOT ${SLANG_LIB_TYPE} STREQUAL "STATIC") - install( - EXPORT SlangTargets - FILE ${PROJECT_NAME}Targets.cmake - NAMESPACE ${PROJECT_NAME}:: - DESTINATION ${SLANG_CMAKE_CONFIG_DIR} - ) + install( + EXPORT SlangTargets + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${SLANG_CMAKE_CONFIG_DIR} + ) - if(UNIX) - configure_file( - "${PROJECT_SOURCE_DIR}/extras/pkgconfig/slang-compiler.pc.in" - "${PROJECT_BINARY_DIR}/slang-compiler.pc" - @ONLY - ) + if(UNIX) + configure_file( + "${PROJECT_SOURCE_DIR}/extras/pkgconfig/slang-compiler.pc.in" + "${PROJECT_BINARY_DIR}/slang-compiler.pc" + @ONLY + ) - # TODO: When build system is changed to respect CMAKE_INSTALL_LIBDIR, - # update this destination. - install( - FILES "${PROJECT_BINARY_DIR}/slang-compiler.pc" - DESTINATION "lib/pkgconfig" - ) - endif() + # TODO: When build system is changed to respect CMAKE_INSTALL_LIBDIR, + # update this destination. + install( + FILES "${PROJECT_BINARY_DIR}/slang-compiler.pc" + DESTINATION "lib/pkgconfig" + ) endif() endif()