Skip to content

Commit

Permalink
wasm-builder: Support latest nightly (paritytech#10837)
Browse files Browse the repository at this point in the history
* wasm-builder: Support latest nightly

With latest nightly, aka rust version 1.60+ namespaced features are added. This changes the handling
of optional dependencies. We currently have features that enable optional dependencies when `std` is
enabled. This was before no problem, but now the wasm-builder detects them as enabled. To support
the transition period until 1.60 is released as stable, this pr adds an heuristic to not enable these
optional crates in the wasm build when they are enabled in the `std` feature. This heuristic fails
when someones enables these optional dependencies from the outside as well as via the `std` feature,
however we hope that no one is doing this at the moment. When namespaced features are enabled, these
dependencies needs to be enabled using `dep:dependency-name` to solve this properly.

https://doc.rust-lang.org/cargo/reference/unstable.html#namespaced-features

* Remove accidentally added features
  • Loading branch information
bkchr authored and bernardo-xxnet committed May 26, 2022
1 parent ba78567 commit adc6e7b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ sp-std = { version = "4.0.0-dev", default-features = false, path = "../../../pri
sp-api = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/api" }
sp-runtime = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/runtime" }
sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/staking" }
<<<<<<< HEAD
sp-keyring = { version = "4.0.0-dev", optional = true, path = "../../../primitives/keyring" }
=======
>>>>>>> 4bc2af13c (wasm-builder: Support latest nightly (#10837))
sp-session = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/session" }
sp-transaction-pool = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/transaction-pool" }
sp-version = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/version" }
Expand Down Expand Up @@ -147,7 +150,6 @@ std = [
"sp-runtime/std",
"sp-staking/std",
"pallet-staking/std",
"sp-keyring",
"sp-session/std",
"pallet-sudo/std",
"frame-support/std",
Expand All @@ -171,7 +173,12 @@ std = [
"log/std",
"frame-try-runtime/std",
"sp-npos-elections/std",
<<<<<<< HEAD
"sp-io/std"
=======
"sp-io/std",
"pallet-child-bounties/std",
>>>>>>> 4bc2af13c (wasm-builder: Support latest nightly (#10837))
]
runtime-benchmarks = [
"frame-benchmarking",
Expand Down
1 change: 0 additions & 1 deletion primitives/keyring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ readme = "README.md"
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]


[dependencies]
sp-core = { version = "4.0.0-dev", path = "../core" }
sp-runtime = { version = "4.0.0-dev", path = "../runtime" }
Expand Down
23 changes: 20 additions & 3 deletions utils/wasm-builder/src/wasm_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,21 +338,38 @@ fn project_enabled_features(
) -> Vec<String> {
let package = find_package_by_manifest_path(cargo_manifest, crate_metadata);

let std_enabled = package.features.get("std");

let mut enabled_features = package
.features
.keys()
.filter(|f| {
.iter()
.filter(|(f, v)| {
let mut feature_env = f.replace("-", "_");
feature_env.make_ascii_uppercase();

// If this is a feature that corresponds only to an optional dependency
// and this feature is enabled by the `std` feature, we assume that this
// is only done through the `std` feature. This is a bad heuristic and should
// be removed after namespaced features are landed:
// https://doc.rust-lang.org/cargo/reference/unstable.html#namespaced-features
// Then we can just express this directly in the `Cargo.toml` and do not require
// this heuristic anymore. However, for the transition phase between now and namespaced
// features already being present in nightly, we need this code to make
// runtimes compile with all the possible rustc versions.
if v.len() == 1 && v.get(0).map_or(false, |v| *v == format!("dep:{}", f)) {
if std_enabled.as_ref().map(|e| e.iter().any(|ef| ef == *f)).unwrap_or(false) {
return false
}
}

// We don't want to enable the `std`/`default` feature for the wasm build and
// we need to check if the feature is enabled by checking the env variable.
*f != "std" &&
*f != "default" && env::var(format!("CARGO_FEATURE_{}", feature_env))
.map(|v| v == "1")
.unwrap_or_default()
})
.cloned()
.map(|d| d.0.clone())
.collect::<Vec<_>>();

enabled_features.sort();
Expand Down

0 comments on commit adc6e7b

Please sign in to comment.