Skip to content
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

rustc uses wrong build tools when compiling from MSVC #133794

Closed
dlon opened this issue Dec 3, 2024 · 2 comments · Fixed by #134505
Closed

rustc uses wrong build tools when compiling from MSVC #133794

dlon opened this issue Dec 3, 2024 · 2 comments · Fixed by #134505
Labels
A-cross Area: Cross compilation C-bug Category: This is a bug. O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dlon
Copy link
Contributor

dlon commented Dec 3, 2024

This is due to an issue in cc-rs, rust-lang/cc-rs#1308, which is a dependency in rustc_llvm/rustc_codegen_ssa. There is a fix in progress (not yet released/merged): rust-lang/cc-rs#1310. This is a problem as of Rust 1.83.

The issue can be reproduced by creating a cargo workspace with an empty build.rs, creating a new MSVC project within that workspace and running cargo build from within the Pre-Build Event of that MSVC project. When targeting something other than the native arch, cargo/rustc will use the wrong build tools for linking or compilation.

I can provide more details/examples if necessary.

EDIT: This should be fixed on its own once cc is updated.

@dlon dlon added the C-bug Category: This is a bug. label Dec 3, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 3, 2024
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. O-windows-msvc Toolchain: MSVC, Operating system: Windows A-cross Area: Cross compilation and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 3, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Dec 3, 2024

Thinking about it some more, part of the problem here is that cc is both a dependency of rustc (for finding link.exe + libraries) and a tool to use in build scripts. So another option would be to have some way for rustc to disable this behaviour for rustc only. Though I've not thought through the implications of that.

EDIT: Ideally there would be a way to know if Cargo is building a build script.

rust-lang/cc-rs#1201 (comment)

@ChrisDenton
Copy link
Member

Note this is specifically when cross-compiling with MSBuild. It shouldn't affect anything else.

jieyouxu added a commit to jieyouxu/rust that referenced this issue Dec 19, 2024
- `cc` 1.2.4 contains a fix to address [rustc uses wrong build tools
  when compiling from MSVC
  rust-lang#133794](rust-lang#133794). See
  <https://github.com/rust-lang/cc-rs/releases/tag/cc-v1.2.4>.
- `cc` 1.2.5 contains a fix to also check linking when testing if
  certain compiler flags are supported, which fixed an issue that was
  causing previous compiler `cc` bumps to fail. See
  <https://github.com/rust-lang/cc-rs/releases/tag/cc-v1.2.5>.
jieyouxu added a commit to jieyouxu/rust that referenced this issue Dec 19, 2024
- `cc` 1.2.4 contains a fix to address [rustc uses wrong build tools
  when compiling from MSVC
  rust-lang#133794](rust-lang#133794). See
  <https://github.com/rust-lang/cc-rs/releases/tag/cc-v1.2.4>.
- `cc` 1.2.5 contains a fix to also check linking when testing if
  certain compiler flags are supported, which fixed an issue that was
  causing previous compiler `cc` bumps to fail. See
  <https://github.com/rust-lang/cc-rs/releases/tag/cc-v1.2.5>.

Co-authored-by: David Lönnhager <[email protected]>
jieyouxu added a commit to jieyouxu/rust that referenced this issue Dec 19, 2024
- `cc` 1.2.4 contains a fix to address [rustc uses wrong build tools
  when compiling from MSVC
  rust-lang#133794](rust-lang#133794). See
  <https://github.com/rust-lang/cc-rs/releases/tag/cc-v1.2.4>.
- `cc` 1.2.5 contains a fix to also check linking when testing if
  certain compiler flags are supported, which fixed an issue that was
  causing previous compiler `cc` bumps to fail. See
  <https://github.com/rust-lang/cc-rs/releases/tag/cc-v1.2.5>.

Co-authored-by: David Lönnhager <[email protected]>
@bors bors closed this as completed in 4c40c89 Dec 21, 2024
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Dec 23, 2024
Bump compiler `cc` to 1.2.5

- `cc` 1.2.4 contains a fix to address [rustc uses wrong build tools when compiling from MSVC #133794](rust-lang/rust#133794). See <https://github.com/rust-lang/cc-rs/releases/tag/cc-v1.2.4>.
- `cc` 1.2.5 contains a fix to also check linking when testing if certain compiler flags are supported, which fixed an issue that was causing previous compiler `cc` bumps to fail. See <https://github.com/rust-lang/cc-rs/releases/tag/cc-v1.2.5>.

Supersedes #134419.
Fixes #133794.

r? `@clubby789`
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Dec 27, 2024
Bump compiler `cc` to 1.2.5

- `cc` 1.2.4 contains a fix to address [rustc uses wrong build tools when compiling from MSVC #133794](rust-lang/rust#133794). See <https://github.com/rust-lang/cc-rs/releases/tag/cc-v1.2.4>.
- `cc` 1.2.5 contains a fix to also check linking when testing if certain compiler flags are supported, which fixed an issue that was causing previous compiler `cc` bumps to fail. See <https://github.com/rust-lang/cc-rs/releases/tag/cc-v1.2.5>.

Supersedes #134419.
Fixes #133794.

r? `@clubby789`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cross Area: Cross compilation C-bug Category: This is a bug. O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants