Windows: the nvsdk_ngx_d / nvsdk_ngx_s choice uses the build script's own cfg, not the target's crt-static

Open Beginner friendly
#40 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
73/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
build-system

Research direction

Start in build.rs and inspect how it selects nvsdk_ngx_d or nvsdk_ngx_s, then check how the script already reads target settings for linking. Read Cargo's build script environment variables, especially CARGO_CFG_TARGET_FEATURE, and consider the related target_os selection for the Vulkan SDK include directory. Done means the library choice follows the target's crt-static setting and the Windows SDK include path works for Linux-hosted Windows cross builds.

Written by the indexing model from the issue text.

Description

build.rs picks the NGX library like this:

#[cfg(not(target_feature = "crt-static"))]
println!("cargo:rustc-link-lib=static=nvsdk_ngx_d");
#[cfg(target_feature = "crt-static")]
println!("cargo:rustc-link-lib=static=nvsdk_ngx_s");

Inside a build script, #[cfg(target_feature = …)] describes how the build script itself was compiled, not the crate being built. Cargo exposes the target's features to build scripts as CARGO_CFG_TARGET_FEATURE, a comma-separated list (Cargo book: environment variables Cargo sets for build scripts).

The two only agree when the same RUSTFLAGS reach both host and target, as with a plain RUSTFLAGS=-C target-feature=+crt-static cargo build without --target. Whenever crt-static is set for the target only, a static-CRT binary links nvsdk_ngx_d, the dynamic-CRT library. Examples:

  • cargo build --target x86_64-pc-windows-msvc with RUSTFLAGS
  • CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS
  • [target.x86_64-pc-windows-msvc] rustflags with --target

MSVC then rejects the mix:

error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease'

Getting the choice right matters in practice because other common dependencies ship static-CRT libraries. For example, nethost-sys (used by netcorehost) links libnethost.lib, so a dynamic-CRT build with dlss_wgpu fails with LNK2038 too. Such a project has to build with crt-static, and then needs dlss_wgpu to follow the target's setting.

Environment: dlss_wgpu 6.0.0, DLSS SDK 310.9.1, x86_64-pc-windows-msvc.

Suggested fix:

let crt_static = env::var("CARGO_CFG_TARGET_FEATURE")
    .map(|features| features.split(',').any(|feature| feature == "crt-static"))
    .unwrap_or(false);
println!(
    "cargo:rustc-link-lib=static={}",
    if crt_static { "nvsdk_ngx_s" } else { "nvsdk_ngx_d" }
);

Related, same pattern: vulkan_sdk_include is chosen with #[cfg(target_os = "windows")] on the build script. A Linux-hosted cross build to Windows therefore looks for include where the Windows Vulkan SDK has Include. Reading CARGO_CFG_TARGET_OS, which build.rs already does for linking, would keep the two consistent.

Workaround: apply -C target-feature=+crt-static through plain RUSTFLAGS without --target, so the build script is compiled with it too.

Dominant language
Rust
Stars
60
Forks
18
Avg merge
1d 4h
Merged PRs (30d)
1

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bevyengine/dlss_wgpu

All issues in bevyengine/dlss_wgpu

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.