-
Notifications
You must be signed in to change notification settings - Fork 349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add crt-static feature for msvc #927
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make more sense for the cc crate to handle this by defaulting builds to static_crt(true)
when target_feature = "crt-static"
is detected?
Yes, I think you're right. As far as I know, there shouldn't be any cases where |
Sounds good — that was my guess. The cc crate is already responsible for communicating with Cargo to instruct rustc to link the result of the cc build. As you said, there is no reason it should run a static_crt=false build and then attempt to get that linked with static_crt=true Rust code. I'll go ahead and close this while you follow up in the cc repo. Feel free to comment back here if that gets shot down, and we can reevaluate. |
It looks like the target-features don't flow from the top crate down to the crates it consumes, at least not if it's scoped to the package's own It turns out |
@dtolnay apparently I can't re-activate it myself, all I can do is start another PR for the same branch. I can see how not getting to permanently close a PR would get annoying for maintainers, but tagging you here in case you want to re-open this PR with its discussion intact. |
I have some static C++ libraries I'd like to link against on Windows with MSVC, and they are built with the
/MT
flag for the static CRT. If there's a mismatch with any statically linked libraries, the link fails. I can tweak thecc::Build
for my own files built withcxx
by addingstatic_crt(true)
, but there's currently no way to configure the flags forcxx.cc
which is built fromcxx
as part of its ownbuild.rs
script.In my project, I also have a .cargo/config.toml file with this option, which makes the Rust object files link against the static CRT as well:
I added that to this change in
cxx
, but gated oncfg(feature = "crt-static")
instead of the triplet, so it can still link the Rust objects with the C++ objects anytime this feature is enabled. Consumers may still need to enable that in their own crates separately, I don't think they'll automatically pick this setting up from thecxx
config.toml
. But that should only impact consumers who are opting into this feature already.