rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.79k stars 2.42k forks source link

Panic on curious [patch] combination #8745

Open bjorn3 opened 4 years ago

bjorn3 commented 4 years ago

Problem

$ cargo build
thread 'main' panicked at 'not currently active!?', src/tools/cargo/src/cargo/core/resolver/mod.rs:825:36
stack backtrace:
   0: rust_begin_unwind
             at /rustc/fc2daaae610b5515438b551a2f3706196a997f35/library/std/src/panicking.rs:483
   1: core::panicking::panic_fmt
             at /rustc/fc2daaae610b5515438b551a2f3706196a997f35/library/core/src/panicking.rs:85
   2: core::option::expect_failed
             at /rustc/fc2daaae610b5515438b551a2f3706196a997f35/library/core/src/option.rs:1226
   3: cargo::core::resolver::activate_deps_loop
   4: cargo::core::resolver::resolve
   5: cargo::ops::resolve::resolve_with_previous
   6: cargo::ops::resolve::resolve_with_registry
   7: cargo::ops::resolve::resolve_ws_with_opts
   8: cargo::ops::cargo_compile::create_bcx
   9: cargo::ops::cargo_compile::compile_ws
  10: cargo::ops::cargo_compile::compile
  11: cargo::commands::build::exec
  12: cargo::cli::main
  13: cargo::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Steps

Try to build the following crate structure using Cargo.toml where ../wasmtime is a checkout of https://github.com/bytecodealliance/wasmtime.

# Cargo.toml
[package]
name = "headcrab"
version = "0.2.0"

[target.'cfg(target_os = "linux")'.dev-dependencies]
headcrab_inject = { path = "./headcrab_inject" }

[dev-dependencies]
rustc_codegen_cranelift = { path = "./cg_clif" }

[workspace]
exclude = ["./cg_clif"]

[patch.crates-io]
"cranelift-codegen" = { git = 'https://github.com/bytecodealliance/wasmtime/', branch = "main" }

[patch."https://github.com/bytecodealliance/wasmtime/"]
cranelift-codegen = { path = "../wasmtime/cranelift/codegen" }
# headcrab_inject/Cargo.toml
[package]
name = "headcrab_inject"
version = "0.2.0"

[dependencies]
headcrab = { version = "0.2.0", path = "../" }
cranelift-codegen = "0.67.0"
# cg_clif/Cargo.toml
[package]
name = "rustc_codegen_cranelift"
version = "0.1.0"

[dependencies]
# These have to be in sync with each other
cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main", features = ["unwind"] }

Notes

Output of cargo version: cargo 1.48.0-nightly (05c611ae3 2020-09-23)

Eh2406 commented 4 years ago

Same odd problem as #7463. As I recall this is do to to [patch] being implemented as "just lie to the resolver". In this case the resolver notices that thinks don't make sense and panics. The relevant optimization could just get skipped, but it involves threading the error path through several closures.

kdy1 commented 3 years ago

Found the cause.

I depended on swc_common = 0.10.7 by mistake where other crates depends on swc_common = "0.10.6" and it is patched to point https://github.com/kdy1/swc/tree/tsc of which version is 0.10.6

Seems like resolve wants 0.10.7, but failed to find matching package because of patch.