dhuseby / cargo-bootstrap

Bootstrapping script for Rust Cargo when cross-compilation is difficult or impossible.
BSD 2-Clause "Simplified" License
37 stars 9 forks source link

Requiring a dependency with a non-default feature enabled doesn't seem to work #16

Open zofrex opened 8 years ago

zofrex commented 8 years ago

Building url-0.5.9 fails:

cargo:curl:url: Building url-0.5.9 (needed by: curl-0.2.18)
cargo:curl:url:  PROFILE="release" TARGET="x86_64-unknown-openbsd" CARGO_MANIFEST_DIR="/home/zofrex/cargo-out/url-0.5.9" OUT_DIR="/home/zofrex/cargo-out" CARGO_PKG_VERSION_MAJOR="0" CARGO_PKG_VERSION="0.5.9" CARGO_PKG_VERSION_PATCH="9" HOST="x86_64-unknown-openbsd" PATH="/home/zofrex/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games:." DEBUG="0" OPT_LEVEL="0" CARGO_PKG_VERSION_MINOR="5" NUM_JOBS="1" CARGO_PKG_VERSION_PRE="" /usr/local/bin/rustc /home/zofrex/cargo-out/url-0.5.9/src/lib.rs --crate-name url --crate-type lib -C extra-filename=-0_5_9 --out-dir /home/zofrex/cargo-out --emit=dep-info,link --target x86_64-unknown-openbsd -L /home/zofrex/cargo-out -L /home/zofrex/cargo-out/lib --extern unicode_bidi=/home/zofrex/cargo-out/libunicode_bidi-0_2_3.rlib --extern rustc_serialize=/home/zofrex/cargo-out/librustc_serialize-0_3_19.rlib --extern unicode_normalization=/home/zofrex/cargo-out/libunicode_normalization-0_1_2.rlib --extern matches=/home/zofrex/cargo-out/libmatches-0_1_2.rlib --extern uuid=/home/zofrex/cargo-out/libuuid-0_2_0.rlib
cargo:curl:url: /home/zofrex/cargo-out/url-0.5.9/src/lib.rs:219:22: 219:34 error: no associated item named `new_v4` found for type `uuid::Uuid` in the current scope
cargo:curl:url: /home/zofrex/cargo-out/url-0.5.9/src/lib.rs:219         OpaqueOrigin(Uuid::new_v4())
cargo:curl:url:                                                                      ^~~~~~~~~~~~
cargo:curl:url: error: aborting due to previous error

Exception:
 from ./bootstrap.py, line 974:
 build command failed: 101

The error message given is because the uuid library was not compiled with the v4 feature, which is optional - the uuid Cargo.toml is:

[features]
use_std = []
v4 = ["rand"]

So the v4 feature is not enabled by default. But it should have been enabled, because the url crate requires it:

[dependencies]
uuid = { version = "0.2", features = ["v4"] }

Looking at the feature handling code it kind of looks like only features from the RHS of declarations will be picked up (values, not keys)? Working on that theory I managed to get a little bit further with this patch:

diff --git a/bootstrap.py b/bootstrap.py
index 031a249..3d713ea 100755
--- a/bootstrap.py
+++ b/bootstrap.py
@@ -821,6 +821,8 @@ class Crate(object):
                     # and any features they depend on recursively
                     def add_features(f):
                         if ftrs.has_key(f):
+                            if not f in features:
+                                features.append(f)
                             for k in ftrs[f]:
                                 # guard against infinite recursion
                                 if not k in features:

With this patch in place, compilation of uuid itself fails, but I can see that the v4 feature gets enabled, which is possibly progress:

cargo:curl:url:uuid: Building uuid-0.2.0 (needed by: url-0.5.9)
cargo:curl:url:uuid:  CARGO_FEATURE_V4="1" CARGO_PKG_VERSION_PRE="" CARGO_MANIFEST_DIR="/home/zofrex/cargo-out/uuid-0.2.0" OUT_DIR="/home/zofrex/cargo-out" HOST="x86_64-unknown-openbsd" PATH="/home/zofrex/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games:." DEBUG="0" OPT_LEVEL="0" CARGO_PKG_VERSION_MINOR="2" PROFILE="release" TARGET="x86_64-unknown-openbsd" CARGO_PKG_VERSION_MAJOR="0" CARGO_PKG_VERSION="0.2.0" CARGO_PKG_VERSION_PATCH="0" CARGO_FEATURE_RAND="1" NUM_JOBS="1" /usr/local/bin/rustc /home/zofrex/cargo-out/uuid-0.2.0/src/lib.rs --crate-name uuid --crate-type lib --cfg feature="v4" --cfg feature="rand" -C extra-filename=-0_2_0 --out-dir /home/zofrex/cargo-out --emit=dep-info,link --target x86_64-unknown-openbsd -L /home/zofrex/cargo-out -L /home/zofrex/cargo-out/lib
cargo:curl:url:uuid: /home/zofrex/cargo-out/uuid-0.2.0/src/lib.rs:253:9: 253:25 error: unresolved name `rand::thread_rng` [E0425]
cargo:curl:url:uuid: /home/zofrex/cargo-out/uuid-0.2.0/src/lib.rs:253         rand::thread_rng().gen()
cargo:curl:url:uuid:                                                          ^~~~~~~~~~~~~~~~
cargo:curl:url:uuid: /home/zofrex/cargo-out/uuid-0.2.0/src/lib.rs:253:9: 253:25 help: run `rustc --explain E0425` to see a detailed explanation
cargo:curl:url:uuid: error: aborting due to previous error

Exception:
 from ./bootstrap.py, line 974:
 build command failed: 101

It picks up rand as a feature but doesn't seem to add it as a library requirement.

For others finding this issue, for the time being I am getting past this point by changing the rand dependency in uuid to be non-optional:

sed -i"" -e 's/^rand.*version\([ ]*=[ ]*"[0-9.]*"\).*/rand\1/' /path/to/output/dir/uuid-0.2.0/Cargo.toml