2

So I am trying to build a rust project using cargo build and receive:

error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names -C -Zshare-generics=y -Csplit-debuginfo=unpacked --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=cfg` (exit status: 1)
  --- stderr
  error: unknown codegen option: `-Zshare-generics`

I tried multiple projects, non of them worked. So tried creating a new one. Still didn't work. Removed the config file and still nothing.

My cargo version is cargo 1.66.1 (ad779e08b 2023-01-10) and rustc rustc 1.66.1 (90743e729 2023-01-10). Tried uninstalling rust (rustup self uninstall and rm -rf $HOME/.cargo) and reinstalling but still get the error.

$ rustup show
Default host: x86_64-apple-darwin
rustup home:  /Users/USER/.rustup

stable-x86_64-apple-darwin (default)
rustc 1.66.1 (90743e729 2023-01-10)

I tried creating a new project after the reinstall. Still nothing so any help is appreciated.

Brian61354270
  • 8,690
  • 4
  • 21
  • 43
BelMat
  • 93
  • 8
  • `stable` is pertinent; you won't get the latest, shiniest features that way. See [how to switch between rust toolchains](https://stackoverflow.com/questions/58226545/how-to-switch-between-rust-toolchains) re: switching to beta or nightly. – Charles Duffy Jan 24 '23 at 02:33
  • I don't really know why all these flags are being added. Can't find them on the config file or anything. If you know a way of removing them (Where they could be being added) It would help – BelMat Jan 24 '23 at 02:55
  • If you didn't add it manually then the flag probably is in one of the [`.cargo/config.toml`](https://doc.rust-lang.org/stable/cargo/reference/config.html) somewhere along the path to your project or in your home. – cafce25 Jan 24 '23 at 03:13
  • 1
    Yeah so I did not manually add the flag, but the issue is for all projects. Checked the config.toml at .cargo and it's the flag making issue is not in there. Any other place where the flag can be? Because just tried running the cmd as `RUSTFLAGS="" cargo build` and it did work – BelMat Jan 24 '23 at 03:27
  • What's in the `RUSTFLAGS` in your default environment, then? – Cerberus Jan 24 '23 at 04:08
  • I don't know or where they are being set. My .cargo/config.toml at the root of my user has an empty array for RUSTFLAGS config, so I am unsure why does are being passed – BelMat Jan 24 '23 at 07:48
  • 1
    I mean, what do you get, for example, with `echo "$RUSTFLAGS"` in the same shell you use to call `cargo build`? – Cerberus Jan 24 '23 at 09:45
  • Nope, which is the most weird. `echo "$RUSTFLAGS"` returns nothing ``` ``` is the actual returned character. `cargo build` adds all those flags IDK where they are coming from and if I override the RUSTFLAGS on cmd run they aren't added, so I am kinda lost on why that happens. (Sorry it took me long to reply) – BelMat Jan 25 '23 at 08:45

0 Answers0