Skip to content

Commit

Permalink
Build more runtimes targeting PolkaVM (paritytech#3209)
Browse files Browse the repository at this point in the history
This PR improves compatibility with RISC-V and PolkaVM, allowing more
runtimes to successfully compile.

In particular, it makes the following changes:

- The `sp-mmr-primitives` and `sp-consensus-beefy` crates
unconditionally required an `std`-only dependency; now they only require
those dependencies when the `std` feature is actually enabled. (Our
RISC-V target is, unlike WASM, a true `no_std` target where you can't
accidentally use stuff from `std` anymore.)
- One of our dependencies (the `bitvec` trace) uses a crate called
`radium` which doesn't compile under RISC-V due to incomplete
autodetection logic in their `build.rs` file. The good news is that this
is already fixed in the newest upstream version of `radium`, and the
newest version of `bitvec` uses it. The bad news is that the newest
version of `bitvec` is not currently released on crates.io, so we can't
use it. I've [created an
issue](ferrilab/ferrilab#5) asking for a new
release, but in the meantime I forked the currently used `radium` 0.7,
[fixed the faulty
logic](paritytech/radium-0.7-fork@ed66c8a)
and used cargo's patching capabilities to use it for the RISC-V runtime
builds. This might be a little hacky, but it is the least intrusive way
to fix the problem, doesn't affect WASM builds at all, and we can
trivially remove it once a new `bitvec` is released.
- The new runtimes are added to the CI to make sure their compilation
doesn't break.
  • Loading branch information
koute authored Feb 6, 2024
1 parent a58f04e commit 1594aa2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion substrate/primitives/consensus/beefy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sp-mmr-primitives = { path = "../../merkle-mountain-range", default-features = f
sp-runtime = { path = "../../runtime", default-features = false }
sp-std = { path = "../../std", default-features = false }
strum = { version = "0.24.1", features = ["derive"], default-features = false }
lazy_static = "1.4.0"
lazy_static = { version = "1.4.0", optional = true }

[dev-dependencies]
array-bytes = "6.1"
Expand All @@ -37,6 +37,7 @@ w3f-bls = { version = "0.1.3", features = ["std"] }
default = ["std"]
std = [
"codec/std",
"dep:lazy_static",
"scale-info/std",
"serde/std",
"sp-api/std",
Expand Down
3 changes: 2 additions & 1 deletion substrate/primitives/merkle-mountain-range/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sp-core = { path = "../core", default-features = false }
sp-debug-derive = { path = "../debug-derive", default-features = false }
sp-runtime = { path = "../runtime", default-features = false }
sp-std = { path = "../std", default-features = false }
thiserror = "1.0"
thiserror = { version = "1.0", optional = true }

[dev-dependencies]
array-bytes = "6.1"
Expand All @@ -34,6 +34,7 @@ array-bytes = "6.1"
default = ["std"]
std = [
"codec/std",
"dep:thiserror",
"log/std",
"mmr-lib/std",
"scale-info/std",
Expand Down
12 changes: 12 additions & 0 deletions substrate/utils/wasm-builder/src/wasm_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,18 @@ fn create_project_cargo_toml(

wasm_workspace_toml.insert("workspace".into(), Table::new().into());

if target == RuntimeTarget::Riscv {
// This dependency currently doesn't compile under RISC-V, so patch it with our own fork.
//
// TODO: Remove this once a new version of `bitvec` (which uses a new version of `radium`
// which doesn't have this problem) is released on crates.io.
let patch = toml::toml! {
[crates-io]
radium = { git = "https://github.com/paritytech/radium-0.7-fork.git", rev = "a5da15a15c90fd169d661d206cf0db592487f52b" }
};
wasm_workspace_toml.insert("patch".into(), patch.into());
}

write_file_if_changed(
wasm_workspace.join("Cargo.toml"),
toml::to_string_pretty(&wasm_workspace_toml).expect("Wasm workspace toml is valid; qed"),
Expand Down

0 comments on commit 1594aa2

Please sign in to comment.