Request: cargo needs to help coordinate C compiler usage between `cc` and `rustc` on Windows-MSVC
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 15.5k
- Forks
- 3k
- Avg merge
- 23h 30m
- Merged PRs (30d)
- 51
Description
Describe the problem you are trying to solve
Currently on Window the Visual Studio linker is used. However, there's no absolute source of truth for what install of Visual Studio is being used. It's possible for cc to build a static C library with one toolchain, then rustc builds some Rust code and links with the static C library using another toolchain's linker. MSVC allows for static library ABI breakage between releases the same as Rust does, so if you mix two different releases it's potentially either a very weird linker error or silent runtime UB.
Plausible example situations that could trigger this problem:
- The latest
ccknows how to detect VS 2019 but is being built with an oldrustcthat doesn't know about VS 2019. The user has both versions of VS installed, and soccpicks 2019 whilerustcpicks 2017. - The user has several versions of Visual Studio installed but only one active in their path at once. They build their project once, then change their path to test the project with an alternate toolchain. They touch
lib.rswhich triggers a rebuild in the Rust crate, but the C dependency is left sitting there even though it's from the old toolchain.
Describe the solution you'd like
It seems like cargo should take over deciding what version of MSVC that both cc and rustc must both use during a particular build cycle by setting an environment variable or passing a command line flag or similar.
Also, I suppose the toolchain used to build a foo-sys dependency could be recorded as part of the crate's build data, and if the MSVC toolchain detected changes then that triggers the dependency to be rebuilt or throw an error or something like that.
Notes
@retep998 was the one who first brought this to my attention and is of course the full expert on this arcane Windows matter, I'm just reporting the soundness hole because I have a crate affected by this (an SDL2 wrapper).
It's possible this general issue can happen with static C libs on other systems I guess. You'd have to ask some C experts.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining how Cargo coordinates cc and rustc for Windows-MSVC builds; the issue names no files or tests. Done would require a single authoritative MSVC toolchain choice for both compilers and a defined response when the toolchain changes for an existing C dependency.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, rust
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100