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

cargo install uses my project's .cargo/config target triple and it shouldn't? #5441

Closed
slimsag opened this issue Apr 30, 2018 · 2 comments · Fixed by #5606
Closed

cargo install uses my project's .cargo/config target triple and it shouldn't? #5441

slimsag opened this issue Apr 30, 2018 · 2 comments · Fixed by #5606
Labels

Comments

@slimsag
Copy link

slimsag commented Apr 30, 2018

TL;DR: I spent multiple hours trying to figure out why I couldn't cargo install some tools. It turned out that the reason I couldn't was because, unbeknownst to me, cargo install was trying to build the tools for the wrong target due to .cargo/config in my project directory!

Full explanation

  1. My project has a .cargo/config file to build for a wasm target triple since my project is wasm only:
[build]
target = "wasm32-unknown-emscripten"
  1. I ran cargo install cargo-web from my project's working directory. It failed due to a bunch of obscure errors about dependencies being unable to compile. This made me think the dependencies had been really broken, which gave me a really sour taste in my mouth for Rust.

  2. After cloning the dependencies and trying to fix them, I finally realized: cargo install cargo-web is for some reason building for wasm32-unknown-emscripten on my system! 😢

As it turned out, cargo install is respecting my project's .cargo/config target triple.

What I expected

I think that cargo install should ignore the target triple specified in a project directory.

I imagine that at some point or another, most users developing projects primarily targeting wasm/asmjs will run into this issue, and it is incredibly annoying to debug.

I'm using:

$ cargo --version
cargo 1.27.0-nightly (0a1add2d8 2018-04-20)
@vramana
Copy link
Contributor

vramana commented Jun 2, 2018

Hi,

I will work on this bug. I have explored the relevant code a bit. https://github.com/rust-lang/cargo/blob/master/src/bin/cargo/commands/install.rs#L75 Setting the BuildConfig.target to host triplet fixes the bug if I understand it correctly.

https://github.com/rust-lang/cargo/blob/master/src/cargo/util/rustc.rs#L43-L56 host triplet is calculated here. It can be extracted into a seperate function and used in commands/install.rs

How should I add test for this bug?

@rambip
Copy link

rambip commented Jun 28, 2023

Is it really solved ?
I'm on rust 1.70.0 and it seems I get the same bug:

# in .cargo/config.toml
[build]
target = "wasm32-unknown-unknown"

And when I use cargo install, I have to specify --target x86_64-unwnown-linux=gnu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants