centrifuge-chain
centrifuge-chain copied to clipboard
Enable wasm target in Rust toolchain in Nix Flake
This is an attempt at enabling wasm build when building with nix build
.
It enables wasm target in Rust toolchain using fenix.fromTemplateFile
to create the toolchain from rust-toolchain.toml
and add supported targets.
This fixes wasm32-unknown-unknown
target error when building without SKIP_WASM_BUILD
, but the build fails: with a different error: https://github.com/mpontus/centrifuge-chain/runs/8018805277?check_suite_focus=true
It fails because cargo can't vendor crates from a git source if they reference creates from a parent directory, such cargo can't vendor crates from a git source if they reference crates from a parent directory, which appears to be the intended behavior: https://github.com/rust-lang/cargo/issues/8885#issuecomment-735938754
Trying to build the package with naersk results in the following error:
$ nix log /nix/store/cly3xj8v6fhqw187fjasryyqyq9sibpv-centrifuge-chain-0.10.18.drv
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/4sndwxdvh1isz4m9mdp89grcd3w65faz-centrifuge-chain-source
source root is centrifuge-chain-source
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
[naersk] cargo_version (read): 1.62.0-nightly (a44758ac8 2022-05-04)
[naersk] cargo_message_format (set): json-diagnostic-rendered-ansi
[naersk] cargo_release: --release
[naersk] cargo_options:
[naersk] cargo_build_options: $cargo_release -j "$NIX_BUILD_CORES" --message-format=$cargo_message_format
[naersk] cargo_test_options: $cargo_release -j "$NIX_BUILD_CORES"
[naersk] RUST_TEST_THREADS: 8
[naersk] cargo_bins_jq_filter: select(.reason == "compiler-artifact" and .executable != null and .profile.test == false)
[naersk] cargo_build_output_json (created): /build/tmp.hSyY815sVz
[naersk] crate_sources: /nix/store/g34qfzbz1bycrs4dfski2n5ra9im22q4-crates-io
[naersk] RUSTFLAGS:
[naersk] CARGO_BUILD_RUSTFLAGS:
[naersk] CARGO_BUILD_RUSTFLAGS (updated): --remap-path-prefix /nix/store/g34qfzbz1bycrs4dfski2n5ra9im22q4-crates-io=/sources
@nix { "action": "setPhase", "phase": "buildPhase" }
building
cargo build $cargo_release -j "$NIX_BUILD_CORES" --message-format=$cargo_message_format
error: no matching package named `orml-tokens` found
location searched: https://github.com/open-web3-stack/open-runtime-module-library?branch=polkadot-v0.9.24#41dddc87
required by package `pallet-restricted-tokens v0.1.0 (/build/centrifuge-chain-source/pallets/restricted-tokens)`
[naersk] cargo returned with exit code 101, exiting
Looking in /nix/store/g34qfzbz1bycrs4dfski2n5ra9im22q4-crates-io
we can actually see orml-tokens
package present:
$ ls -d /nix/store/g34qfzbz1bycrs4dfski2n5ra9im22q4-crates-io/orml-tokens-*
/nix/store/g34qfzbz1bycrs4dfski2n5ra9im22q4-crates-io/orml-tokens-0.1.0-polkadot-v0.9.24
/nix/store/g34qfzbz1bycrs4dfski2n5ra9im22q4-crates-io/orml-tokens-0.4.1-dev-polkadot-v0.9.24
And apparently matching the version specified in pallet-restricted-tokens
's Cargo.toml:
## Benchmarkind dependencies
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.24" }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, optional = true, branch = "polkadot-v0.9.24" }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, optional = true, branch = "polkadot-v0.9.24" }
pallet-permissions = { path = "../permissions", default-features = false, optional = true }
runtime-common = { path = "../../runtime/common", default-features = false, optional = true }
[dev-dependencies]
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = true, branch = "polkadot-v0.9.24" }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = true, branch = "polkadot-v0.9.24" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = true, branch = "polkadot-v0.9.24" }
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = true, branch = "polkadot-v0.9.24" }
cargo vendor
is used by buildRustPackage
to vendor crates for offline access during thebuild step: https://github.com/NixOS/nixpkgs/blob/1066f0ef92a2f869709eb0515694a1139f23065c/pkgs/build-support/rust/fetch-cargo-tarball/default.nix#L72
Alternative rust buildsers: crane and naersk also use it to vendor dependencies and consider it to be an upstream (cargo) issue:
- https://github.com/ipetkov/crane/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc
- https://github.com/nix-community/naersk/issues/260#issuecomment-1236141950
And the current consensus is calling it the indented behavior: With the current consus calling this the intended behavior: https://github.com/rust-lang/cargo/issues/8885#issuecomment-735938754
I close this for now. Am cleaning up a bit. Feel free to re-open if still needed.