error-chain icon indicating copy to clipboard operation
error-chain copied to clipboard

backtrace-sys still compiled when the backtrace feature is turned off

Open Michael-F-Bryan opened this issue 8 years ago • 4 comments
trafficstars

Apparently the backtrace-sys dependency is always compiled, regardless of whether the backtrace feature is present. This bit me because when compiling for the x86_64-unknown-linux-musl target and the musl C library isn't installed, backtrace-sys can't be compiled.

My question is, why is error-chain depending on backtrace-sys even when the backtrace feature isn't activated?


This is roughly what I was doing to replicate a failed travis build for my mdbook PR, azerupi/mdbook#361.

$ rustup target add x86_64-unknown-linux-musl
$ cargo build --target x86_64-unknown-linux-musl
   Compiling rustc-demangle v0.1.4
   Compiling backtrace-sys v0.1.11
error: failed to run custom build command for `backtrace-sys v0.1.11`
...
--- stderr
configure: error: in `/home/michael/Documents/forks/mdBook/target/x86_64-unknown-linux-musl/debug/build/backtrace-sys-9b035f64636a9441/out':
configure: error: C compiler cannot create executables

I then thought I could work around this by telling error-chain to not use the backtrace feature. With the backtrace feature removed this shouldn't try to compile anything related to backtraces.

// Cargo.toml
- error-chain = "0.10.0"
+ error-chain = { version = "0.10.0", features = [] }

Recompiling then gives you the same error.

The build succeeds if you install musl gcc wrapper (pacman -S musl), but that means you are still building the backtrace-sys crate even when the backtrace feature isn't enabled.

Michael-F-Bryan avatar Jun 25 '17 06:06 Michael-F-Bryan

I think you have to add default-features = false.

Yamakaky avatar Jun 25 '17 10:06 Yamakaky

I tried that too and it still compiles backtrace-sys regardless of whether I specify default-features = false and/or features = [].

error-chain declares backtrace as an optional dependency which is only meant to be compiled when the backtrace feature is enabled, do you know why cargo would still be compiling an optional dependency even when it is told not to?

Michael-F-Bryan avatar Jun 25 '17 11:06 Michael-F-Bryan

Hum, did you try the dependency syntax from http://doc.crates.io/manifest.html (search dependencies.awesome)?

Yamakaky avatar Jun 25 '17 12:06 Yamakaky

I ran into the same issue but as @Yamakaky suggested this fixed it:

[dependencies.error-chain]
version = "0.10.0"
default-features = false

Paspartout avatar Jul 07 '17 15:07 Paspartout