Skip to content

Commit 2049bc5

Browse files
Add a CMake override path for fast_float (#11758)
## Motivation `fast_float` was bundled in v2026.12, but unlike the bundled dependencies already covered by this convention it shipped **without** a `SLANG_OVERRIDE_*_PATH` CMake option. Builds that pre-stage or mirror their dependencies (e.g. air-gapped / vendored-mirror CI) can point each of the 14 existing `SLANG_OVERRIDE_*_PATH` dependencies at an external copy via `-DSLANG_OVERRIDE_<DEP>_PATH=<dir>`, but for `fast_float` they have to patch the checkout. This adds the missing option so `fast_float` follows the same convention. (`metal-cpp` shares the same gap and is intentionally out of scope — see Scope.) Concrete example — before this change there is no way to do: ``` cmake --preset default -DSLANG_OVERRIDE_FAST_FLOAT_PATH=/mirror/deps # (where /mirror/deps/fast_float/include holds the headers) ``` ## Proposed solution Mirror the existing override-path shape: 1. Declare `advanced_option(SLANG_OVERRIDE_FAST_FLOAT_PATH ... OFF)` in the top-level `CMakeLists.txt` alongside the other 14 `SLANG_OVERRIDE_*_PATH` options. 2. In `external/CMakeLists.txt`, branch the `fast_float` INTERFACE target's include directory: use the override path when set, otherwise the bundled path — unchanged from today. `fast_float` is header-only, so (unlike the buildable deps that use `add_subdirectory`) the branch swaps the include-dir *string* rather than the subdirectory. The conditional `${system}` SYSTEM-include keyword is preserved, so the headers (bundled or override-supplied) still don't trip Slang's `-Werror`. The override resolves to `${SLANG_OVERRIDE_FAST_FLOAT_PATH}/fast_float/include`, matching the documented "directory-containing-a-subdirectory-named-after-the-dep" semantics noted at `CMakeLists.txt:242-245`. Because the header-only path is just a string (with no `add_subdirectory` to error on a missing source directory), a `message(FATAL_ERROR ...)` existence check is added **on the override branch only**, so a mistyped `SLANG_OVERRIDE_FAST_FLOAT_PATH` fails loudly at *configure* time instead of as an opaque "header not found" *compile* error — restoring the fail-fast behavior the `add_subdirectory` siblings get implicitly. The bundled branch keeps no such check (its submodule path is in-contract). This is the minimal change that satisfies the request and keeps `fast_float` consistent with its siblings. A `SLANG_USE_SYSTEM_FAST_FLOAT` / `find_package` toggle was rejected: the issue asks for the override-path convention, `fast_float` is rarely a system package, and `find_package` is far more surface for a header-only dep. ## Change summary | File | Change | | --- | --- | | `CMakeLists.txt` | Add `advanced_option(SLANG_OVERRIDE_FAST_FLOAT_PATH ...)` after the `SLANG_OVERRIDE_CMARK_PATH` declaration. | | `external/CMakeLists.txt` | Branch the `fast_float` INTERFACE include dir on `SLANG_OVERRIDE_FAST_FLOAT_PATH` (`${system}` preserved); add a configure-time `FATAL_ERROR` existence check on the override path. | ## Concepts and vocabulary - **`advanced_option`** (`cmake/AutoOption.cmake`): thin wrapper = `option()` + `mark_as_advanced()`. Using it makes the new option identical in kind to the other `SLANG_OVERRIDE_*_PATH` entries (hidden unless advanced view is on). When the value is supplied on the command line via `-D`, the cache entry exists before `option()` runs, so `option()` is a no-op and the path string is preserved — which is exactly why `if(NOT SLANG_OVERRIDE_*_PATH)` works as a "was an override given?" test across all of these options. - **`${system}`**: expands to `SYSTEM` on CMake ≥ 3.25 (else empty); marks the include as a system include so warnings from third-party headers are suppressed under `-Werror`. ## Process report Two edits, both required, both minimal: 1. `CMakeLists.txt` — without the `advanced_option` declaration the override variable would not be a recognized (advanced) cache option, breaking parity with the 14 sibling overrides. Placed after the CMARK block to keep the option list grouped as-is. 2. `external/CMakeLists.txt` — the `fast_float` target had a hard-coded include dir (`"${CMAKE_CURRENT_LIST_DIR}/fast_float/include"`) with no override branch. Added an `if(NOT SLANG_OVERRIDE_FAST_FLOAT_PATH)/else()` that sets `_fast_float_include` and feeds it to the single `target_include_directories` call, keeping `${system}` in place. On the override branch only, a `message(FATAL_ERROR ...)` fires if the resolved include dir does not exist, so a wrong override is caught at configure time. The block comment is widened from "the bundled headers" to "the bundled (or override-supplied) headers" so it still describes the code after the branch is added. **Input-shape check** (per the methodology): there is no malformed AST/IR here — this is a build-config feature, and the "shape" being handled is a user-supplied override directory. The branch follows the same documented producer convention as every other override option, so the fix sits at the right layer (the dependency-declaration site), not as a downstream workaround. The override path is the out-of-contract input, which is why the explicit existence check is on that branch (the siblings get the equivalent configure-time failure for free from `add_subdirectory`; this header-only override does not, hence the only deliberate exception — confined to user-supplied input). **Why no `.slang` regression test:** this is a CMake-only change; no compiler behavior is affected and the `SLANG_OVERRIDE_*_PATH` options are not exercised by per-PR CI (the options matrix runs on `workflow_dispatch` / weekly). Verified locally instead: - `gersemi` (the repo's CMake formatter, same invocation as `extras/formatting.sh`) — clean. - A configure-time probe over the **exact edited bytes** confirmed all three branches: - override **unset** → `<repo>/external/fast_float/include` (the same resolved path as today's bundled include; no check fires); - override **set** to an existing dir → `<dir>/fast_float/include`, configure succeeds; - override **set** to a missing dir → `FATAL_ERROR` naming the bad path, at configure time. ## Scope `fast_float` only. `metal-cpp` (`external/CMakeLists.txt:161-166`) has the same missing-override shape but is intentionally left out of scope. Closes #11756. <sub>🤖 Generated by an automated Slang coworker — may be inaccurate. A human maintainer should verify.</sub> --------- Co-authored-by: nv-slang-bot[bot] <274397474+nv-slang-bot[bot]@users.noreply.github.com>
1 parent 60d15fe commit 2049bc5

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ advanced_option(
314314
"Build using user defined path for cmark"
315315
OFF
316316
)
317+
advanced_option(
318+
SLANG_OVERRIDE_FAST_FLOAT_PATH
319+
"Build using user defined path for fast_float"
320+
OFF
321+
)
317322

318323
set(SLANG_EXCLUDE_DAWN_DEFAULT ON)
319324
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")

external/CMakeLists.txt

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,31 @@ target_include_directories(
165165
INTERFACE "${CMAKE_CURRENT_LIST_DIR}/metal-cpp"
166166
)
167167

168-
# fast_float headers (header-only). Mark as a system include so the
169-
# bundled headers don't trip Slang's extra warnings / -Werror.
168+
# fast_float headers (header-only). Mark as a system include so the bundled
169+
# (or override-supplied) headers don't trip Slang's extra warnings / -Werror.
170170
add_library(fast_float INTERFACE)
171+
if(NOT SLANG_OVERRIDE_FAST_FLOAT_PATH)
172+
set(_fast_float_include "${CMAKE_CURRENT_LIST_DIR}/fast_float/include")
173+
else()
174+
set(_fast_float_include
175+
"${SLANG_OVERRIDE_FAST_FLOAT_PATH}/fast_float/include"
176+
)
177+
# The add_subdirectory-based overrides fail at configure time on a bad path
178+
# because CMake errors on a missing source directory. A header-only override
179+
# is just an include-dir string, so validate the user-supplied path here to
180+
# fail loudly at configure time rather than as an opaque "header not found"
181+
# compile error later.
182+
if(NOT EXISTS "${_fast_float_include}")
183+
message(
184+
FATAL_ERROR
185+
"SLANG_OVERRIDE_FAST_FLOAT_PATH is set to '${SLANG_OVERRIDE_FAST_FLOAT_PATH}' but '${_fast_float_include}' does not exist"
186+
)
187+
endif()
188+
endif()
171189
target_include_directories(
172190
fast_float
173191
${system}
174-
INTERFACE "${CMAKE_CURRENT_LIST_DIR}/fast_float/include"
192+
INTERFACE "${_fast_float_include}"
175193
)
176194

177195
# SPIRV-Headers

0 commit comments

Comments
 (0)