rust-lang / cfg-if

A if/elif-like macro for Rust #[cfg] statements
Apache License 2.0
557 stars 40 forks source link

`%` anywhere in project path causes "error: could not compile `cfg-if`" #41

Closed Havegum closed 1 year ago

Havegum commented 3 years ago

I couldn't find this cause for this issue mentioned elsewhere, so I thought I'd post this to at least save some headaches.

Having the %-character anywhere in the project path causes cfg-if to fail compiling. In the example below I have the %-character as the name of the project folder, but the issue persist if there's a %-sign anywhere.

Reproducing

I can reproduce this issue by creating a new project, adding cfg-if as a dependency, and executing cargo run:

  1. Create a new project
    > cargo new test-%-cfg-if
  2. Add cfg-if as a dependency
    # --snip--
    [dependencies]
    cfg-if = "1.0.0"
  3. Run with cargo run
    > cargo run
    Compiling cfg-if v1.0.0
    error: failed to build archive: No such file or directory
    error: aborting due to previous error
    error: could not compile `cfg-if`

Running with --verbose yields:

Caused by:
  process didn't exit successfully: `rustc --crate-name cfg_if --edition=2018 /Users/havegum/.cargo/registry/src/github.com-1ecc6299db9ec823/cfg-if-1.0.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=33d5df19792096bf -C extra-filename=-33d5df19792096bf --out-dir '/Users/havegum/test-%-cfg-if/target/debug/deps' -L 'dependency=/Users/havegum/test-%-cfg-if/target/debug/deps' --cap-lints allow` (exit code: 1)

Expected outcome

The expected outcome – and what happens if you comment out the dependency – is that the project builds and runs as normal:

> cargo run
   Compiling test-cfg-if v0.1.0 (/Users/havegum/test-%-cfg-if)
    Finished dev [unoptimized + debuginfo] target(s) in 0.98s
     Running `target/debug/test-cfg-if`
Hello, world!

Removing % from the path fixes the error

> mv ../test-%-cfg-if ../test-cfg-if
> cd ../test-cfg-if
> cargo run
   Compiling cfg-if v1.0.0
   Compiling test-cfg-if v0.1.0 (/Users/havegum/test-cfg-if)
    Finished dev [unoptimized + debuginfo] target(s) in 0.93s
     Running `target/debug/test-cfg-if`
Hello, world!

System info

> sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.6
BuildVersion:   18G103
> rustup --version
rustup 1.23.1 (3df2264a9 2020-11-30)
> rustc --version 
rustc 1.50.0 (cb75ad5db 2021-02-10)
> cargo --version
cargo 1.50.0 (f04e7fab7 2021-02-04)
alexcrichton commented 3 years ago

Thanks for the report but do you have any reason to suspect that it's specific to this crate itself? This looks like a rustc bug.

Havegum commented 3 years ago

Ah, my bad. You're absolutely right! This happens whatever package I try, and it just happened to crash on this one

nospam3089 commented 3 years ago

This seems to be issue https://github.com/rust-lang/rust/issues/79567.

JohnTitor commented 1 year ago

Closing as it's not this crate's issue.