Expand description
Shared build-script support for the workspace.
Besides the Metal shader precompilation in metal_shaders and the source
hashing in source_hash, two responsibilities, both previously copy-pasted
between the runtime crate’s build script and the editor crate’s build script
(and missing entirely from the example binaries, which is why they failed to
link against the runtime’s DLSS code on Windows):
-
Resolve the rendering backend once and emit it as a single cfg (
backend_metal/backend_dx/backend_vk) the source gates on. -
Detect the optional graphics SDKs and emit the cfgs the renderer gates on (
agility_sdk_configured,ffx_sdk_bundled,xess_sdk_bundled,ngx_sdk_bundled,dxc_bundled). For a package that produces final binaries this also copies the runtime DLLs next to the .exe and links the NGX import lib; for a package that produces only an rlib and its own test binaries just the NGX link is needed. Which of the two, and where the binaries land, is read off the calling package bytargets– a build script declares nothing about its own target list.
The public entry points emit cargo:: directives on stdout, which Cargo
attributes to the build script of whichever package called in. That is what
lets an example binary’s build script pick up the same NGX link and DLL
bundling the CLI’s does, without duplicating any of this logic.
This file is the thin environment-reading layer: it snapshots everything the
setup needs from the process environment into an SdkEnv and prints the
directives. The probe/copy/directive logic itself lives in the sdks
module, which never touches the environment or stdout.
Structs§
- Slang
Artifact - One program to precompile: the name the renderer looks it up by, the assembled source text, the entry point, and what slangc should emit.
- Slang
LibSpec - One single-source shader library to precompile to a metallib: the
.slangfile under the slang shader directory, the entry points linked into the library, and the#defines that select its variant.nameis the key the renderer’s lookup uses (distinct fromfilewhen one source yields several variant libraries). - Slang
Shaders - The single-source half of the precompile: where the
.slangfiles live, the shared declarations spliced into the ones carrying a marker, and one spec per metallib variant. Grouped because they always travel together, and because the splice table has to match the renderer’sslang_source::assembleexactly – the two produce the same text or the content-addressed cache serves one path’s bytes to the other.
Enums§
- Backend
- The graphics backend a build targets.
Functions§
- backend_
from_ cargo - Resolve the backend from the Cargo-provided environment, emitting nothing. For a package that needs the backend only to pick its SDK setup and never gates its own source on one, so has no reason to carry the cfg.
- emit_
backend_ cfg - Resolve the backend from the Cargo-provided environment and emit the
rustc-cfgfor it, returning the choice so the caller can branch. - emit_
check_ cfgs - Declare every cfg the renderer source gates on so
--check-cfgdoes not warn. A package only needs this if its own source references one of these cfgs. - hash_
sources - Hash the Rust sources under
roots, and emit the rerun directives that re-run the calling build script when any of them change. Each root is either a directory tree (every.rsunder it participates) or a single file. - precompile_
metal_ shaders - Precompile every eligible
.metalundershaders_dir, plus every.slangspec inslang, into OUT_DIR and generateengine_metallibs.rsthere.fragmentspairs a source marker with the file undershaders_dirthat replaces it, matching the substitution the renderer applies when it compiles the same shader from source. Panics if the Metal toolchain is present but a shader fails to compile: a broken shader must fail the build, not surface at renderer init. - precompile_
slang_ artifacts - Compile every artifact into
OUT_DIRand generategeneratedbeside it: afn <lookup>(name: &str) -> Option<(u64, &'static [u8])>mapping each name to the digest of the source it was built from and its embedded bytes. - setup_
graphics_ sdks - Set up the optional graphics SDKs for the given backend. On a non-Windows target (or the Metal backend) this is a no-op: none of these SDKs apply.
- watch_
shader_ dir - Emit a rerun directive per shader file, so an edit to any of them recompiles the artifacts rather than replaying stale bytes.