Skip to content

Add support for crt-static#45

Closed
Dirreke wants to merge 1 commit intorust-or:masterfrom
Dirreke:support-crt-static
Closed

Add support for crt-static#45
Dirreke wants to merge 1 commit intorust-or:masterfrom
Dirreke:support-crt-static

Conversation

@Dirreke
Copy link

@Dirreke Dirreke commented Mar 23, 2026

This pull request updates the build script to select the appropriate MSVC runtime library based on whether the crt-static target feature is enabled. This ensures that the correct runtime linkage is used for static or dynamic CRT builds.

@lovasoa
Copy link
Collaborator

lovasoa commented Mar 23, 2026

Hello and thank you for the pr ! Could you give me some context about what this does?

Is it meant to add support for building static executables on windows? If so, then could you also add this to the ci matrix, so that static windows binaries are tested and this does not regress in the future?

@Dirreke
Copy link
Author

Dirreke commented Mar 23, 2026

Hi, thank you for the review.

Rust exposes crt-static as a target feature, and on MSVC this affects whether native code should be built against the static or dynamic C runtime. In build scripts, this is available through CARGO_CFG_TARGET_FEATURE, which is what this patch checks. When crt-static is enabled, the native side should use MultiThreaded (/MT); otherwise it should use MultiThreadedDLL (/MD).

So this change is mainly about keeping the Rust side and the CMake-built native library consistent, and avoiding CRT mismatch during linking.

This patch simply makes that choice explicit:

  • with crt-static: CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
  • without it: CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL or I can remove it to keep default value.

As for CI, I’d prefer to keep this PR scoped to the runtime-selection fix itself for now. Since this change mainly aligns the native build with Rust’s existing target configuration, I’m not sure adding a dedicated CI entry is necessary at this stage. But if you insist, I'm good to add.

@lovasoa
Copy link
Collaborator

lovasoa commented Mar 23, 2026

Understood !

For reading the feature, is crt-static special in some way, or can we read it like all other features in the build script ?

Could we simplify this to

 .define("CMAKE_MSVC_RUNTIME_LIBRARY", if cfg!(feature = "crt-static") { "MultiThreaded" } else { "MultiThreadedDLL" })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants