mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-10 01:47:58 +00:00
Build WASM binaries as part of cargo build (#2868)
* Introduce `wasm-builder` and `wasm-builder-runner` to retire `build.sh` Make use of `wasm-builder` in `test-runtime`. * Add build script and remove the wasm project * Port `node-runtime` to new wasm-builder * Make `substrate-executor` tests work with `wasm-builder` * Move `node-template` to `wasm-builder` * Remove `build.sh` :) * Remove the last include_bytes * Adds the missing build.rs files * Remove `build.sh` from CI * Debug CI * Make it work in CI * CI attempt 3 * Make `substrate-runtime-test` compile on stable * Ahhh, some missed `include_bytes!` * AHH * Add suggestions * Improve search for `Cargo.lock` and don't panic if it is not found * Searching from manifest path was no good idea * Make the `wasm-builder` source better configurable * Expose the bloaty wasm binary as well * Make sure to rerun WASM recompilation on changes in dependencies * Introduce new `WASM_BUILD_TYPE` env and make sure to call `build.rs` on changes to env variables * Remove `build.sh` from READMEs * Rename the projects * Fixes CI * Update lock file * Fixes merge-conflict * Apply suggestions from code review Co-Authored-By: TriplEight <denis.pisarev@parity.io> * Try to make windows happy * Replace all back slashes in paths with slashes * Apply suggestions from code review Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com> * Use cargo from `CARGO` env variable * Fix compilation * Use `rustup` for running the nightly build * Make individual projects skipable * Fix compilation * Fixes compilation * Build all WASM projects in one workspace * Replace more back slashes! * Remove `inlcude_bytes!` * Adds some documentation * Apply suggestions from code review Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com> * Apply suggestions from code review Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com> * More review comments * Update `Cargo.lock` * Set license * Apply suggestions from code review Co-Authored-By: joe petrowski <25483142+joepetrowski@users.noreply.github.com> * More review comments + adds `TRIGGER_WASM_BUILD` env * Fix doc tests * Increase version + update README * Switch crates.io version of `wasm-builder` * Update README * Switch to released version of `wasm-builder-runner`
This commit is contained in:
@@ -95,8 +95,7 @@ cargo-check-benches:
|
||||
stage: test
|
||||
<<: *docker-env
|
||||
script:
|
||||
- ./scripts/build.sh --locked
|
||||
- time cargo check --benches
|
||||
- BUILD_DUMMY_WASM_BINARY=1 time cargo check --benches
|
||||
- sccache -s
|
||||
|
||||
|
||||
@@ -107,7 +106,7 @@ cargo-check-subkey:
|
||||
- /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1
|
||||
script:
|
||||
- cd ./subkey
|
||||
- time cargo check --release # makes sense to save artifacts for building it
|
||||
- BUILD_DUMMY_WASM_BINARY=1 time cargo check --release # makes sense to save artifacts for building it
|
||||
- sccache -s
|
||||
|
||||
|
||||
@@ -122,7 +121,6 @@ test-linux-stable: &test-linux
|
||||
variables:
|
||||
- $DEPLOY_TAG
|
||||
script:
|
||||
- ./scripts/build.sh --locked
|
||||
- time cargo test --all --release --verbose --locked
|
||||
- sccache -s
|
||||
|
||||
@@ -160,7 +158,6 @@ test-linux-stable-int:
|
||||
variables:
|
||||
- $DEPLOY_TAG
|
||||
script:
|
||||
- ./scripts/build.sh --locked
|
||||
- time RUST_LOG=sync=trace,consensus=trace,client=trace,state-db=trace,db=trace,forks=trace,state_db=trace,storage_cache=trace
|
||||
cargo test -p node-cli --release --verbose --locked -- --ignored --test-threads=1
|
||||
- sccache -s
|
||||
@@ -215,7 +212,6 @@ build-linux-release:
|
||||
variables:
|
||||
- $DEPLOY_TAG
|
||||
script:
|
||||
- ./scripts/build.sh --locked
|
||||
- time cargo build --release --verbose
|
||||
- mkdir -p ./artifacts
|
||||
- mv ./target/release/substrate ./artifacts/.
|
||||
@@ -245,7 +241,6 @@ build-rust-doc-release:
|
||||
- ./crate-docs
|
||||
<<: *build-only
|
||||
script:
|
||||
- ./scripts/build.sh --locked
|
||||
- rm -f ./crate-docs/index.html # use it as an indicator if the job succeeds
|
||||
- time cargo +nightly doc --release --all --verbose
|
||||
- cp -R ./target/doc ./crate-docs
|
||||
|
||||
Generated
+94
-1
@@ -285,6 +285,14 @@ dependencies = [
|
||||
"serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "build-helper"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "build_const"
|
||||
version = "0.2.1"
|
||||
@@ -339,6 +347,18 @@ name = "c_linked_list"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "cargo_metadata"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cast"
|
||||
version = "0.2.2"
|
||||
@@ -690,6 +710,19 @@ dependencies = [
|
||||
"syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_more"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "difference"
|
||||
version = "2.0.0"
|
||||
@@ -901,6 +934,15 @@ dependencies = [
|
||||
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fs2"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fuchsia-cprng"
|
||||
version = "0.1.1"
|
||||
@@ -2283,6 +2325,7 @@ dependencies = [
|
||||
"substrate-keyring 2.0.0",
|
||||
"substrate-offchain-primitives 2.0.0",
|
||||
"substrate-primitives 2.0.0",
|
||||
"substrate-wasm-builder-runner 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2336,6 +2379,7 @@ dependencies = [
|
||||
"substrate-consensus-aura-primitives 2.0.0",
|
||||
"substrate-offchain-primitives 2.0.0",
|
||||
"substrate-primitives 2.0.0",
|
||||
"substrate-wasm-builder-runner 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3229,12 +3273,21 @@ dependencies = [
|
||||
"core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4281,7 +4334,7 @@ version = "2.0.0"
|
||||
dependencies = [
|
||||
"assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@@ -4294,6 +4347,7 @@ dependencies = [
|
||||
"substrate-offchain 2.0.0",
|
||||
"substrate-panic-handler 2.0.0",
|
||||
"substrate-primitives 2.0.0",
|
||||
"substrate-runtime-test 2.0.0",
|
||||
"substrate-serializer 2.0.0",
|
||||
"substrate-state-machine 2.0.0",
|
||||
"substrate-trie 2.0.0",
|
||||
@@ -4547,6 +4601,17 @@ dependencies = [
|
||||
"substrate-rpc 2.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-runtime-test"
|
||||
version = "2.0.0"
|
||||
dependencies = [
|
||||
"sr-io 2.0.0",
|
||||
"sr-sandbox 2.0.0",
|
||||
"sr-std 2.0.0",
|
||||
"substrate-primitives 2.0.0",
|
||||
"substrate-wasm-builder-runner 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-serializer"
|
||||
version = "2.0.0"
|
||||
@@ -4700,6 +4765,7 @@ dependencies = [
|
||||
"substrate-primitives 2.0.0",
|
||||
"substrate-test-runtime-client 2.0.0",
|
||||
"substrate-trie 2.0.0",
|
||||
"substrate-wasm-builder-runner 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"trie-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@@ -4765,6 +4831,27 @@ dependencies = [
|
||||
"trie-standardmap 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-wasm-builder"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"build-helper 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cargo_metadata 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"walkdir 2.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substrate-wasm-builder-runner"
|
||||
version = "1.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "substrate-wasm-builder-runner"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "1.0.0"
|
||||
@@ -5759,6 +5846,7 @@ dependencies = [
|
||||
"checksum block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6d4dc3af3ee2e12f3e5d224e5e1e3d73668abbeb69e566d361f7d5563a4fdf09"
|
||||
"checksum bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0de79cfb98e7aa9988188784d8664b4b5dad6eaaa0863b91d9a4ed871d4f7a42"
|
||||
"checksum bstr 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6cc0572e02f76cb335f309b19e0a0d585b4f62788f7d26de2a13a836a637385f"
|
||||
"checksum build-helper 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bdce191bf3fa4995ce948c8c83b4640a1745457a149e73c6db75b4ffe36aad5f"
|
||||
"checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39"
|
||||
"checksum bumpalo 2.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "84dca3afd8e01b9526818b7963e5b4916063b3cdf9f10cf6b73ef0bd0ec37aa5"
|
||||
"checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40"
|
||||
@@ -5768,6 +5856,7 @@ dependencies = [
|
||||
"checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c"
|
||||
"checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101"
|
||||
"checksum c_linked_list 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4964518bd3b4a8190e832886cdc0da9794f12e8e6c1613a9e90ff331c4c8724b"
|
||||
"checksum cargo_metadata 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "929766d993a2fde7a0ae962ee82429069cd7b68839cd9375b98efd719df65d3a"
|
||||
"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427"
|
||||
"checksum cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)" = "39f75544d7bbaf57560d2168f28fd649ff9c76153874db88bdbdfd839b1a7e7d"
|
||||
"checksum cexpr 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7fa24eb00d5ffab90eaeaf1092ac85c04c64aaf358ea6f84505b8116d24c6af"
|
||||
@@ -5805,6 +5894,7 @@ dependencies = [
|
||||
"checksum curve25519-dalek 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5d4b820e8711c211745880150f5fac78ab07d6e3851d8ce9f5a02cedc199174c"
|
||||
"checksum data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4f47ca1860a761136924ddd2422ba77b2ea54fe8cc75b9040804a0d9d32ad97"
|
||||
"checksum derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6d944ac6003ed268757ef1ee686753b57efc5fcf0ebe7b64c9fc81e7e32ff839"
|
||||
"checksum derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a141330240c921ec6d074a3e188a7c7ef95668bb95e7d44fa0e5778ec2a7afe"
|
||||
"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
|
||||
"checksum digest 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e5b29bf156f3f4b3c4f610a25ff69370616ae6e0657d416de22645483e72af0a"
|
||||
"checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
|
||||
@@ -5829,6 +5919,7 @@ dependencies = [
|
||||
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
||||
"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
||||
"checksum fs-swap 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "921d332c89b3b61a826de38c61ee5b6e02c56806cade1b0e5d81bd71f57a71bb"
|
||||
"checksum fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213"
|
||||
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
||||
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
|
||||
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
||||
@@ -6046,6 +6137,7 @@ dependencies = [
|
||||
"checksum sct 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f5adf8fbd58e1b1b52699dc8bed2630faecb6d8c7bee77d009d6bbe4af569b9"
|
||||
"checksum security-framework 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eee63d0f4a9ec776eeb30e220f0bc1e092c3ad744b2a379e3993070364d3adc2"
|
||||
"checksum security-framework-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9636f8989cbf61385ae4824b98c1aaa54c994d7d8b41f11c601ed799f0549a56"
|
||||
"checksum semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537"
|
||||
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
"checksum send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0eddf2e8f50ced781f288c19f18621fa72a3779e3cb58dbf23b07469b0abeb4"
|
||||
@@ -6079,6 +6171,7 @@ dependencies = [
|
||||
"checksum strum 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1810e25f576e7ffce1ff5243b37066da5ded0310b3274c20baaeccb1145b2806"
|
||||
"checksum strum_macros 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "572a2f4e53dd4c3483fd79e5cc10ddd773a3acb1169bbfe8762365e107110579"
|
||||
"checksum substrate-bip39 0.2.1 (git+https://github.com/paritytech/substrate-bip39)" = "<none>"
|
||||
"checksum substrate-wasm-builder-runner 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3533b62b476e5058947b9509038f9d5a72f7363a54a088821329fa76b990a485"
|
||||
"checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee"
|
||||
"checksum subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "01dca13cf6c3b179864ab3292bd794e757618d35a7766b7c46050c614ba00829"
|
||||
"checksum syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d960b829a55e56db167e861ddb43602c003c7be0bee1d345021703fac2fb7c"
|
||||
|
||||
@@ -28,6 +28,7 @@ members = [
|
||||
"core/consensus/rhd",
|
||||
"core/consensus/slots",
|
||||
"core/executor",
|
||||
"core/executor/runtime-test",
|
||||
"core/finality-grandpa",
|
||||
"core/finality-grandpa/primitives",
|
||||
"core/inherents",
|
||||
@@ -55,7 +56,9 @@ members = [
|
||||
"core/transaction-pool",
|
||||
"core/transaction-pool/graph",
|
||||
"core/trie",
|
||||
"core/util/fork-tree",
|
||||
"core/utils/fork-tree",
|
||||
"core/utils/wasm-builder",
|
||||
"core/utils/wasm-builder-runner",
|
||||
"srml/support",
|
||||
"srml/support/procedural",
|
||||
"srml/support/procedural/tools",
|
||||
@@ -89,11 +92,6 @@ members = [
|
||||
"subkey",
|
||||
"test-utils/chain-spec-builder",
|
||||
]
|
||||
exclude = [
|
||||
"node/runtime/wasm",
|
||||
"core/executor/wasm",
|
||||
"core/test-runtime/wasm",
|
||||
]
|
||||
|
||||
[badges]
|
||||
travis-ci = { repository = "paritytech/substrate", branch = "master" }
|
||||
|
||||
+18
-1
@@ -264,7 +264,6 @@ Then build the code:
|
||||
|
||||
[source, shell]
|
||||
----
|
||||
./scripts/build.sh # Builds the WebAssembly binaries
|
||||
cargo build # Builds all native code
|
||||
----
|
||||
|
||||
@@ -309,6 +308,24 @@ cargo run --release \-- \
|
||||
|
||||
Additional Substrate CLI usage options are available and may be shown by running `cargo run \-- --help`.
|
||||
|
||||
== WASM binaries
|
||||
|
||||
The WASM binaries are built during the normal `cargo build` process. To control the WASM binary building,
|
||||
we support multiple environment variables:
|
||||
|
||||
* `SKIP_WASM_BUILD` - Skips building any WASM binary. This is useful when only native should be recompiled.
|
||||
* `BUILD_DUMMY_WASM_BINARY` - Builds dummy WASM binaries. These dummy binaries are empty and useful
|
||||
for `cargo check` runs.
|
||||
* `WASM_BUILD_TYPE` - Sets the build type for building WASM binaries. Supported values are `release` or `debug`.
|
||||
By default the build type is equal to the build type used by the main build.
|
||||
* `TRIGGER_WASM_BUILD` - Can be set to trigger a WASM build. On subsequent calls the value of the variable
|
||||
needs to change. As WASM builder instructs `cargo` to watch for file changes
|
||||
this environment variable should only be required in certain circumstances.
|
||||
|
||||
Each project can be skipped individually by using the environment variable `SKIP_PROJECT_NAME_WASM_BUILD`.
|
||||
Where `PROJECT_NAME` needs to be replaced by the name of the cargo project, e.g. `node-runtime` will
|
||||
be `NODE_RUNTIME`.
|
||||
|
||||
[[flaming-fir]]
|
||||
=== Joining the Flaming Fir Testnet
|
||||
|
||||
|
||||
@@ -53,7 +53,12 @@ mod tests {
|
||||
use primitives::Blake2Hasher;
|
||||
use hex::*;
|
||||
|
||||
native_executor_instance!(Executor, test_client::runtime::api::dispatch, test_client::runtime::native_version, include_bytes!("../../test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm"));
|
||||
native_executor_instance!(
|
||||
Executor,
|
||||
test_client::runtime::api::dispatch,
|
||||
test_client::runtime::native_version,
|
||||
test_client::runtime::WASM_BINARY
|
||||
);
|
||||
|
||||
fn executor() -> executor::NativeExecutor<Executor> {
|
||||
NativeExecutionDispatch::new(None)
|
||||
|
||||
@@ -5,7 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
derive_more = "0.14.0"
|
||||
derive_more = "0.15.0"
|
||||
parity-codec = "4.1.1"
|
||||
runtime_io = { package = "sr-io", path = "../sr-io" }
|
||||
primitives = { package = "substrate-primitives", path = "../primitives" }
|
||||
@@ -15,8 +15,8 @@ state_machine = { package = "substrate-state-machine", path = "../state-machine"
|
||||
runtime_version = { package = "sr-version", path = "../sr-version" }
|
||||
panic-handler = { package = "substrate-panic-handler", path = "../panic-handler" }
|
||||
wasmi = { version = "0.4.3" }
|
||||
byteorder = "1.1"
|
||||
lazy_static = "1.0"
|
||||
byteorder = "1.3"
|
||||
lazy_static = "1.3"
|
||||
parking_lot = "0.8.0"
|
||||
log = "0.4"
|
||||
libsecp256k1 = "0.2.1"
|
||||
@@ -26,6 +26,7 @@ tiny-keccak = "1.4.2"
|
||||
assert_matches = "1.1"
|
||||
wabt = "~0.7.4"
|
||||
hex-literal = "0.2.0"
|
||||
runtime-test = { package = "substrate-runtime-test", path = "runtime-test" }
|
||||
substrate-client = { path = "../client" }
|
||||
substrate-offchain = { path = "../offchain/" }
|
||||
|
||||
|
||||
+8
-9
@@ -1,11 +1,9 @@
|
||||
[package]
|
||||
name = "runtime-test"
|
||||
name = "substrate-runtime-test"
|
||||
version = "2.0.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
rstd = { package = "sr-std", path = "../../sr-std", default-features = false }
|
||||
@@ -13,9 +11,10 @@ runtime_io = { package = "sr-io", path = "../../sr-io", default-features = false
|
||||
sandbox = { package = "sr-sandbox", path = "../../sr-sandbox", default-features = false }
|
||||
substrate-primitives = { path = "../../primitives", default-features = false }
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
lto = true
|
||||
[build-dependencies]
|
||||
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.0" }
|
||||
|
||||
[workspace]
|
||||
members = []
|
||||
[features]
|
||||
default = [ "std" ]
|
||||
std = []
|
||||
no_std = []
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 Parity Technologies (UK) Ltd.
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
@@ -14,8 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! The Substrate test runtime reexported for WebAssembly compile.
|
||||
use wasm_builder_runner::{build_current_project, WasmBuilderSource};
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
pub use substrate_test_runtime::*;
|
||||
fn main() {
|
||||
build_current_project("wasm_binary.rs", WasmBuilderSource::Crates("1.0.1"));
|
||||
}
|
||||
+7
-3
@@ -1,7 +1,11 @@
|
||||
#![no_std]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![cfg_attr(feature = "strict", deny(warnings))]
|
||||
|
||||
use rstd::{slice, vec::Vec, vec};
|
||||
// Make the WASM binary available.
|
||||
#[cfg(feature = "std")]
|
||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
|
||||
use rstd::{vec::Vec, slice, vec};
|
||||
|
||||
use runtime_io::{
|
||||
set_storage, storage, clear_prefix, print, blake2_128, blake2_256,
|
||||
@@ -31,7 +35,7 @@ macro_rules! impl_stubs {
|
||||
// Leak the output vector to avoid it being freed.
|
||||
// This is fine in a WASM context since the heap
|
||||
// will be discarded after the call.
|
||||
::core::mem::forget(output);
|
||||
rstd::mem::forget(output);
|
||||
res
|
||||
}
|
||||
};
|
||||
@@ -566,13 +566,14 @@ mod tests {
|
||||
use crate::wasm_executor::WasmExecutor;
|
||||
use state_machine::TestExternalities as CoreTestExternalities;
|
||||
use wabt;
|
||||
use runtime_test::WASM_BINARY;
|
||||
|
||||
type TestExternalities<H> = CoreTestExternalities<H, u64>;
|
||||
|
||||
#[test]
|
||||
fn sandbox_should_work() {
|
||||
let mut ext = TestExternalities::<Blake2Hasher>::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
|
||||
let code = wabt::wat2wasm(r#"
|
||||
(module
|
||||
@@ -604,7 +605,7 @@ mod tests {
|
||||
#[test]
|
||||
fn sandbox_trap() {
|
||||
let mut ext = TestExternalities::<Blake2Hasher>::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
|
||||
let code = wabt::wat2wasm(r#"
|
||||
(module
|
||||
@@ -625,7 +626,7 @@ mod tests {
|
||||
#[test]
|
||||
fn sandbox_should_trap_when_heap_exhausted() {
|
||||
let mut ext = TestExternalities::<Blake2Hasher>::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
|
||||
let code = wabt::wat2wasm(r#"
|
||||
(module
|
||||
@@ -650,7 +651,7 @@ mod tests {
|
||||
#[test]
|
||||
fn start_called() {
|
||||
let mut ext = TestExternalities::<Blake2Hasher>::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
|
||||
let code = wabt::wat2wasm(r#"
|
||||
(module
|
||||
@@ -688,7 +689,7 @@ mod tests {
|
||||
#[test]
|
||||
fn invoke_args() {
|
||||
let mut ext = TestExternalities::<Blake2Hasher>::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
|
||||
let code = wabt::wat2wasm(r#"
|
||||
(module
|
||||
@@ -722,7 +723,7 @@ mod tests {
|
||||
#[test]
|
||||
fn return_val() {
|
||||
let mut ext = TestExternalities::<Blake2Hasher>::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
|
||||
let code = wabt::wat2wasm(r#"
|
||||
(module
|
||||
@@ -744,7 +745,7 @@ mod tests {
|
||||
#[test]
|
||||
fn unlinkable_module() {
|
||||
let mut ext = TestExternalities::<Blake2Hasher>::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
|
||||
let code = wabt::wat2wasm(r#"
|
||||
(module
|
||||
@@ -764,7 +765,7 @@ mod tests {
|
||||
#[test]
|
||||
fn corrupted_module() {
|
||||
let mut ext = TestExternalities::<Blake2Hasher>::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
|
||||
// Corrupted wasm file
|
||||
let code = &[0, 0, 0, 0, 1, 0, 0, 0];
|
||||
@@ -778,7 +779,7 @@ mod tests {
|
||||
#[test]
|
||||
fn start_fn_ok() {
|
||||
let mut ext = TestExternalities::<Blake2Hasher>::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
|
||||
let code = wabt::wat2wasm(r#"
|
||||
(module
|
||||
@@ -801,7 +802,7 @@ mod tests {
|
||||
#[test]
|
||||
fn start_fn_traps() {
|
||||
let mut ext = TestExternalities::<Blake2Hasher>::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
|
||||
let code = wabt::wat2wasm(r#"
|
||||
(module
|
||||
|
||||
@@ -1394,6 +1394,7 @@ mod tests {
|
||||
use state_machine::TestExternalities as CoreTestExternalities;
|
||||
use hex_literal::hex;
|
||||
use primitives::map;
|
||||
use runtime_test::WASM_BINARY;
|
||||
use substrate_offchain::testing;
|
||||
|
||||
type TestExternalities<H> = CoreTestExternalities<H, u64>;
|
||||
@@ -1401,7 +1402,7 @@ mod tests {
|
||||
#[test]
|
||||
fn returning_should_work() {
|
||||
let mut ext = TestExternalities::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
|
||||
let output = WasmExecutor::new().call(&mut ext, 8, &test_code[..], "test_empty_return", &[]).unwrap();
|
||||
assert_eq!(output, vec![0u8; 0]);
|
||||
@@ -1410,7 +1411,7 @@ mod tests {
|
||||
#[test]
|
||||
fn panicking_should_work() {
|
||||
let mut ext = TestExternalities::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
|
||||
let output = WasmExecutor::new().call(&mut ext, 8, &test_code[..], "test_panic", &[]);
|
||||
assert!(output.is_err());
|
||||
@@ -1426,7 +1427,7 @@ mod tests {
|
||||
fn storage_should_work() {
|
||||
let mut ext = TestExternalities::default();
|
||||
ext.set_storage(b"foo".to_vec(), b"bar".to_vec());
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
|
||||
let output = WasmExecutor::new().call(&mut ext, 8, &test_code[..], "test_data_in", b"Hello world").unwrap();
|
||||
|
||||
@@ -1448,7 +1449,7 @@ mod tests {
|
||||
ext.set_storage(b"aba".to_vec(), b"3".to_vec());
|
||||
ext.set_storage(b"abb".to_vec(), b"4".to_vec());
|
||||
ext.set_storage(b"bbb".to_vec(), b"5".to_vec());
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
|
||||
// This will clear all entries which prefix is "ab".
|
||||
let output = WasmExecutor::new().call(&mut ext, 8, &test_code[..], "test_clear_prefix", b"ab").unwrap();
|
||||
@@ -1466,7 +1467,7 @@ mod tests {
|
||||
#[test]
|
||||
fn blake2_256_should_work() {
|
||||
let mut ext = TestExternalities::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
assert_eq!(
|
||||
WasmExecutor::new().call(&mut ext, 8, &test_code[..], "test_blake2_256", &[]).unwrap(),
|
||||
blake2_256(&b""[..]).encode()
|
||||
@@ -1480,7 +1481,7 @@ mod tests {
|
||||
#[test]
|
||||
fn blake2_128_should_work() {
|
||||
let mut ext = TestExternalities::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
assert_eq!(
|
||||
WasmExecutor::new().call(&mut ext, 8, &test_code[..], "test_blake2_128", &[]).unwrap(),
|
||||
blake2_128(&b""[..]).encode()
|
||||
@@ -1494,7 +1495,7 @@ mod tests {
|
||||
#[test]
|
||||
fn twox_256_should_work() {
|
||||
let mut ext = TestExternalities::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
assert_eq!(
|
||||
WasmExecutor::new().call(&mut ext, 8, &test_code[..], "test_twox_256", &[]).unwrap(),
|
||||
hex!("99e9d85137db46ef4bbea33613baafd56f963c64b1f3685a4eb4abd67ff6203a")
|
||||
@@ -1508,7 +1509,7 @@ mod tests {
|
||||
#[test]
|
||||
fn twox_128_should_work() {
|
||||
let mut ext = TestExternalities::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
assert_eq!(
|
||||
WasmExecutor::new().call(&mut ext, 8, &test_code[..], "test_twox_128", &[]).unwrap(),
|
||||
hex!("99e9d85137db46ef4bbea33613baafd5")
|
||||
@@ -1522,7 +1523,7 @@ mod tests {
|
||||
#[test]
|
||||
fn ed25519_verify_should_work() {
|
||||
let mut ext = TestExternalities::<Blake2Hasher>::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
let key = ed25519::Pair::from_seed(&blake2_256(b"test"));
|
||||
let sig = key.sign(b"all ok!");
|
||||
let mut calldata = vec![];
|
||||
@@ -1548,7 +1549,7 @@ mod tests {
|
||||
#[test]
|
||||
fn sr25519_verify_should_work() {
|
||||
let mut ext = TestExternalities::<Blake2Hasher>::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
let key = sr25519::Pair::from_seed(&blake2_256(b"test"));
|
||||
let sig = key.sign(b"all ok!");
|
||||
let mut calldata = vec![];
|
||||
@@ -1574,7 +1575,7 @@ mod tests {
|
||||
#[test]
|
||||
fn enumerated_trie_root_should_work() {
|
||||
let mut ext = TestExternalities::<Blake2Hasher>::default();
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
assert_eq!(
|
||||
WasmExecutor::new().call(&mut ext, 8, &test_code[..], "test_enumerated_trie_root", &[]).unwrap(),
|
||||
ordered_trie_root::<Blake2Hasher, _, _>(vec![b"zero".to_vec(), b"one".to_vec(), b"two".to_vec()].iter()).as_fixed_bytes().encode()
|
||||
@@ -1588,7 +1589,7 @@ mod tests {
|
||||
let mut ext = TestExternalities::<Blake2Hasher>::default();
|
||||
let (offchain, state) = testing::TestOffchainExt::new();
|
||||
ext.set_offchain_externalities(offchain);
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
assert_eq!(
|
||||
WasmExecutor::new().call(&mut ext, 8, &test_code[..], "test_offchain_local_storage", &[]).unwrap(),
|
||||
vec![0]
|
||||
@@ -1615,7 +1616,7 @@ mod tests {
|
||||
},
|
||||
);
|
||||
|
||||
let test_code = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm");
|
||||
let test_code = WASM_BINARY;
|
||||
assert_eq!(
|
||||
WasmExecutor::new().call(&mut ext, 8, &test_code[..], "test_offchain_http", &[]).unwrap(),
|
||||
vec![0]
|
||||
|
||||
Generated
-269
@@ -1,269 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.4.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "crunchy"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "fixed-hash"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hash-db"
|
||||
version = "0.12.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "hash256-std-hasher"
|
||||
version = "0.12.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "impl-codec"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"parity-codec 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nodrop"
|
||||
version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parity-codec"
|
||||
version = "4.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parity-codec-derive"
|
||||
version = "3.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "primitive-types"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"fixed-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"impl-codec 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"uint 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "0.4.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "0.6.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "runtime-test"
|
||||
version = "2.0.0"
|
||||
dependencies = [
|
||||
"sr-io 2.0.0",
|
||||
"sr-sandbox 2.0.0",
|
||||
"sr-std 2.0.0",
|
||||
"substrate-primitives 2.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hex"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver-parser"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "sr-io"
|
||||
version = "2.0.0"
|
||||
dependencies = [
|
||||
"hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-std 2.0.0",
|
||||
"substrate-primitives 2.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sr-sandbox"
|
||||
version = "2.0.0"
|
||||
dependencies = [
|
||||
"parity-codec 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-std 2.0.0",
|
||||
"substrate-primitives 2.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sr-std"
|
||||
version = "2.0.0"
|
||||
dependencies = [
|
||||
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "static_assertions"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "substrate-primitives"
|
||||
version = "2.0.0"
|
||||
dependencies = [
|
||||
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash256-std-hasher 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-codec 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"primitive-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sr-std 2.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.15.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uint"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71"
|
||||
"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf"
|
||||
"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
|
||||
"checksum crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
|
||||
"checksum fixed-hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "516877b7b9a1cc2d0293cbce23cd6203f0edbfd4090e6ca4489fecb5aa73050e"
|
||||
"checksum hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3c95a428c86ed4633d83e07ef9e0a147a906da01e931f07e74a85bedce5a43"
|
||||
"checksum hash256-std-hasher 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "663ce20dae36902c16d12c6aaae400ca40d922407a8cf2b4caf8cae9b39b4f03"
|
||||
"checksum impl-codec 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "62ed8ff267bc916dd848a800b96d3129aec73d5b23a5e3d018c83655d0c55371"
|
||||
"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945"
|
||||
"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32"
|
||||
"checksum parity-codec 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7902deb39d3b431897f211c1918789938251e67a740f55effd53201e79c0906c"
|
||||
"checksum parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "00a486fd383382ddcb2de928364b1f82571c1e48274fc43b7667a4738ee4056c"
|
||||
"checksum primitive-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "366ef730e56c11fd21ab3e518866cf7feb0fdf7f7c16ddc68485579e9d802787"
|
||||
"checksum proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e10d4b51f154c8a7fb96fd6dad097cb74b863943ec010ac94b9fd1be8861fe1e"
|
||||
"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
|
||||
"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db"
|
||||
"checksum rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "403bb3a286107a04825a5f82e1270acc1e14028d3d554d7a1e08914549575ab8"
|
||||
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
"checksum serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)" = "076a696fdea89c19d3baed462576b8f6d663064414b5c793642da8dfeb99475b"
|
||||
"checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5"
|
||||
"checksum syn 0.15.39 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d960b829a55e56db167e861ddb43602c003c7be0bee1d345021703fac2fb7c"
|
||||
"checksum toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b8c96d7873fa7ef8bdeb3a9cda3ac48389b4154f32b9803b4bc26220b677b039"
|
||||
"checksum uint 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f5375d2c574f89adad4108ad525c93e39669853a602560bf5ed4ca9943b10799"
|
||||
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||
@@ -1,13 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
if cargo --version | grep -q "nightly"; then
|
||||
CARGO_CMD="cargo"
|
||||
else
|
||||
CARGO_CMD="cargo +nightly"
|
||||
fi
|
||||
CARGO_INCREMENTAL=0 RUSTFLAGS="-C link-arg=--export-table" $CARGO_CMD build --target=wasm32-unknown-unknown --release "$@"
|
||||
for i in test
|
||||
do
|
||||
wasm-gc target/wasm32-unknown-unknown/release/runtime_$i.wasm target/wasm32-unknown-unknown/release/runtime_$i.compact.wasm
|
||||
done
|
||||
@@ -5,7 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
fork-tree = { path = "../../core/util/fork-tree" }
|
||||
fork-tree = { path = "../../core/utils/fork-tree" }
|
||||
futures = "0.1"
|
||||
log = "0.4"
|
||||
parking_lot = "0.8.0"
|
||||
|
||||
@@ -20,7 +20,7 @@ lru-cache = "0.1.1"
|
||||
rustc-hex = "2.0"
|
||||
rand = "0.6"
|
||||
libp2p = { version = "0.10.0", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
|
||||
fork-tree = { path = "../../core/util/fork-tree" }
|
||||
fork-tree = { path = "../../core/utils/fork-tree" }
|
||||
primitives = { package = "substrate-primitives", path = "../../core/primitives" }
|
||||
consensus = { package = "substrate-consensus-common", path = "../../core/consensus/common" }
|
||||
client = { package = "substrate-client", path = "../../core/client" }
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
use std::env;
|
||||
|
||||
#[test]
|
||||
fn ui() {
|
||||
// As trybuild is using `cargo check`, we don't need the real WASM binaries.
|
||||
env::set_var("BUILD_DUMMY_WASM_BINARY", "1");
|
||||
|
||||
let t = trybuild::TestCases::new();
|
||||
t.compile_fail("tests/ui/*.rs");
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ name = "substrate-test-runtime"
|
||||
version = "2.0.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
log = { version = "0.4", optional = true }
|
||||
@@ -29,11 +30,14 @@ cfg-if = "0.1.6"
|
||||
substrate-executor = { path = "../executor" }
|
||||
substrate-test-runtime-client = { path = "./client" }
|
||||
|
||||
[build-dependencies]
|
||||
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.0" }
|
||||
|
||||
[features]
|
||||
default = [
|
||||
"std",
|
||||
"include-wasm-blob"
|
||||
]
|
||||
no_std = []
|
||||
std = [
|
||||
"log",
|
||||
"serde",
|
||||
@@ -55,5 +59,3 @@ std = [
|
||||
"offchain-primitives/std",
|
||||
"executive/std",
|
||||
]
|
||||
# If enabled, the WASM blob is added to the `GenesisConfig`.
|
||||
include-wasm-blob = []
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
@@ -14,8 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! The Substrate runtime reexported for WebAssembly compile.
|
||||
use wasm_builder_runner::{build_current_project, WasmBuilderSource};
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
pub use node_runtime::*;
|
||||
fn main() {
|
||||
build_current_project("wasm_binary.rs", WasmBuilderSource::Crates("1.0.1"));
|
||||
}
|
||||
@@ -13,7 +13,6 @@ runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" }
|
||||
[features]
|
||||
default = [
|
||||
"std",
|
||||
"runtime/include-wasm-blob",
|
||||
]
|
||||
std = [
|
||||
"runtime/std",
|
||||
|
||||
@@ -51,7 +51,7 @@ mod local_executor {
|
||||
pub LocalExecutor,
|
||||
runtime::api::dispatch,
|
||||
runtime::native_version,
|
||||
include_bytes!("../../wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm")
|
||||
runtime::WASM_BINARY
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
use runtime_io::{blake2_256, twox_128};
|
||||
use super::{AuthorityId, AccountId};
|
||||
use super::{AuthorityId, AccountId, WASM_BINARY};
|
||||
use parity_codec::{Encode, KeyedVec, Joiner};
|
||||
use primitives::{ChangesTrieConfiguration, map, storage::well_known_keys};
|
||||
use runtime_primitives::traits::Block;
|
||||
@@ -48,13 +48,11 @@ impl GenesisConfig {
|
||||
}
|
||||
|
||||
pub fn genesis_map(&self) -> HashMap<Vec<u8>, Vec<u8>> {
|
||||
#[cfg(feature = "include-wasm-blob")]
|
||||
let wasm_runtime = include_bytes!("../wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm").to_vec();
|
||||
let wasm_runtime = WASM_BINARY.to_vec();
|
||||
let mut map: HashMap<Vec<u8>, Vec<u8>> = self.balances.iter()
|
||||
.map(|&(ref account, balance)| (account.to_keyed_vec(b"balance:"), vec![].and(&balance)))
|
||||
.map(|(k, v)| (blake2_256(&k[..])[..].to_vec(), v.to_vec()))
|
||||
.chain(vec![
|
||||
#[cfg(feature = "include-wasm-blob")]
|
||||
(well_known_keys::CODE.into(), wasm_runtime),
|
||||
(well_known_keys::HEAP_PAGES.into(), vec![].and(&(16 as u64))),
|
||||
].into_iter())
|
||||
|
||||
@@ -56,6 +56,10 @@ pub type AuraId = AuthorityId;
|
||||
// Ensure Babe and Aura use the same crypto to simplify things a bit.
|
||||
pub type BabeId = AuthorityId;
|
||||
|
||||
// Inlucde the WASM binary
|
||||
#[cfg(feature = "std")]
|
||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
|
||||
/// Test runtime version.
|
||||
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: create_runtime_str!("test"),
|
||||
|
||||
@@ -313,13 +313,10 @@ mod tests {
|
||||
|
||||
use runtime_io::{with_externalities, TestExternalities};
|
||||
use substrate_test_runtime_client::{AuthorityKeyring, AccountKeyring};
|
||||
use crate::{Header, Transfer};
|
||||
use crate::{Header, Transfer, WASM_BINARY};
|
||||
use primitives::{Blake2Hasher, map};
|
||||
use substrate_executor::WasmExecutor;
|
||||
|
||||
const WASM_CODE: &'static [u8] =
|
||||
include_bytes!("../wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm");
|
||||
|
||||
fn new_test_ext() -> TestExternalities<Blake2Hasher> {
|
||||
let authorities = vec![
|
||||
AuthorityKeyring::Alice.to_raw_public(),
|
||||
@@ -365,7 +362,7 @@ mod tests {
|
||||
#[test]
|
||||
fn block_import_works_wasm() {
|
||||
block_import_works(|b, ext| {
|
||||
WasmExecutor::new().call(ext, 8, &WASM_CODE, "Core_execute_block", &b.encode()).unwrap();
|
||||
WasmExecutor::new().call(ext, 8, &WASM_BINARY, "Core_execute_block", &b.encode()).unwrap();
|
||||
})
|
||||
}
|
||||
|
||||
@@ -453,7 +450,7 @@ mod tests {
|
||||
#[test]
|
||||
fn block_import_with_transaction_works_wasm() {
|
||||
block_import_with_transaction_works(|b, ext| {
|
||||
WasmExecutor::new().call(ext, 8, &WASM_CODE, "Core_execute_block", &b.encode()).unwrap();
|
||||
WasmExecutor::new().call(ext, 8, &WASM_BINARY, "Core_execute_block", &b.encode()).unwrap();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
-3645
File diff suppressed because it is too large
Load Diff
@@ -1,25 +0,0 @@
|
||||
[package]
|
||||
name = "substrate-test-runtime-wasm"
|
||||
version = "2.0.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
name = "substrate_test_runtime"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
substrate-test-runtime = { path = "..", default-features = false }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
std = [
|
||||
"substrate-test-runtime/std",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
lto = true
|
||||
|
||||
[workspace]
|
||||
members = []
|
||||
@@ -1,13 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
if cargo --version | grep -q "nightly"; then
|
||||
CARGO_CMD="cargo"
|
||||
else
|
||||
CARGO_CMD="cargo +nightly"
|
||||
fi
|
||||
CARGO_INCREMENTAL=0 RUSTFLAGS="-C link-arg=--export-table" $CARGO_CMD build --target=wasm32-unknown-unknown --release "$@"
|
||||
for i in substrate_test_runtime
|
||||
do
|
||||
wasm-gc "target/wasm32-unknown-unknown/release/$i.wasm" "target/wasm32-unknown-unknown/release/$i.compact.wasm"
|
||||
done
|
||||
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "substrate-wasm-builder-runner"
|
||||
version = "1.0.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
description = "Runner for substrate-wasm-builder"
|
||||
edition = "2018"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/paritytech/substrate"
|
||||
license = "GPL-3.0"
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,12 @@
|
||||
## WASM builder runner
|
||||
|
||||
Since cargo contains many bugs when it comes to correct dependency and feature
|
||||
resolution, we need this little tool. See <https://github.com/rust-lang/cargo/issues/5730> for
|
||||
more information.
|
||||
|
||||
It will create a project that will call `substrate-wasm-builder` to prevent any dependencies
|
||||
from `substrate-wasm-builder` influencing the main project's dependencies.
|
||||
|
||||
For more information see <https://crates.io/substrate-wasm-builder>
|
||||
|
||||
License: GPL-3.0
|
||||
@@ -0,0 +1,205 @@
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! # WASM builder runner
|
||||
//!
|
||||
//! Since cargo contains many bugs when it comes to correct dependency and feature
|
||||
//! resolution, we need this little tool. See <https://github.com/rust-lang/cargo/issues/5730> for
|
||||
//! more information.
|
||||
//!
|
||||
//! It will create a project that will call `substrate-wasm-builder` to prevent any dependencies
|
||||
//! from `substrate-wasm-builder` influencing the main project's dependencies.
|
||||
//!
|
||||
//! For more information see <https://crates.io/substrate-wasm-builder>
|
||||
|
||||
use std::{env, process::Command, fs, path::{PathBuf, Path}};
|
||||
|
||||
/// Environment variable that tells us to skip building the WASM binary.
|
||||
const SKIP_BUILD_ENV: &str = "SKIP_WASM_BUILD";
|
||||
|
||||
/// Environment variable that tells us to create a dummy WASM binary.
|
||||
///
|
||||
/// This is useful for `cargo check` to speed-up the compilation.
|
||||
///
|
||||
/// # Caution
|
||||
///
|
||||
/// Enabling this option will just provide `&[]` as WASM binary.
|
||||
const DUMMY_WASM_BINARY_ENV: &str = "BUILD_DUMMY_WASM_BINARY";
|
||||
|
||||
/// Environment variable that makes sure the WASM build is triggered.
|
||||
const TRIGGER_WASM_BUILD_ENV: &str = "TRIGGER_WASM_BUILD";
|
||||
|
||||
/// Replace all backslashes with slashes.
|
||||
fn replace_back_slashes<T: ToString>(path: T) -> String {
|
||||
path.to_string().replace("\\", "/")
|
||||
}
|
||||
|
||||
/// The `wasm-builder` dependency source.
|
||||
pub enum WasmBuilderSource {
|
||||
/// The relative path to the source code from the current manifest dir.
|
||||
Path(&'static str),
|
||||
/// The git repository that contains the source code.
|
||||
Git {
|
||||
repo: &'static str,
|
||||
rev: &'static str,
|
||||
},
|
||||
/// Use the given version released on crates.io
|
||||
Crates(&'static str),
|
||||
}
|
||||
|
||||
impl WasmBuilderSource {
|
||||
/// Convert to a valid cargo source declaration.
|
||||
///
|
||||
/// `absolute_path` - The manifest dir.
|
||||
fn to_cargo_source(&self, manifest_dir: &Path) -> String {
|
||||
match self {
|
||||
WasmBuilderSource::Path(path) => {
|
||||
replace_back_slashes(format!("path = \"{}\"", manifest_dir.join(path).display()))
|
||||
}
|
||||
WasmBuilderSource::Git { repo, rev } => {
|
||||
format!("git = \"{}\", rev=\"{}\"", repo, rev)
|
||||
}
|
||||
WasmBuilderSource::Crates(version) => {
|
||||
format!("version = \"{}\"", version)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Build the currently built project as WASM binary.
|
||||
///
|
||||
/// The current project is determined using the `CARGO_MANIFEST_DIR` environment variable.
|
||||
///
|
||||
/// `file_name` - The name of the file being generated in the `OUT_DIR`. The file contains the
|
||||
/// constant `WASM_BINARY` which contains the build wasm binary.
|
||||
/// `wasm_builder_path` - Path to the wasm-builder project, relative to `CARGO_MANIFEST_DIR`.
|
||||
pub fn build_current_project(file_name: &str, wasm_builder_source: WasmBuilderSource) {
|
||||
generate_rerun_if_changed_instructions();
|
||||
|
||||
if check_skip_build() {
|
||||
return;
|
||||
}
|
||||
|
||||
let manifest_dir = PathBuf::from(
|
||||
env::var("CARGO_MANIFEST_DIR").expect(
|
||||
"`CARGO_MANIFEST_DIR` is always set for `build.rs` files; qed"
|
||||
)
|
||||
);
|
||||
|
||||
let cargo_toml_path = manifest_dir.join("Cargo.toml");
|
||||
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("`OUT_DIR` is set by cargo!"));
|
||||
let file_path = out_dir.join(file_name);
|
||||
let project_folder = out_dir.join("wasm_build_runner");
|
||||
|
||||
if check_provide_dummy_wasm_binary() {
|
||||
provide_dummy_wasm_binary(&file_path);
|
||||
} else {
|
||||
create_project(&project_folder, &file_path, &manifest_dir, wasm_builder_source, &cargo_toml_path);
|
||||
run_project(&project_folder);
|
||||
}
|
||||
}
|
||||
|
||||
fn create_project(
|
||||
project_folder: &Path,
|
||||
file_path: &Path,
|
||||
manifest_dir: &Path,
|
||||
wasm_builder_source: WasmBuilderSource,
|
||||
cargo_toml_path: &Path,
|
||||
) {
|
||||
fs::create_dir_all(project_folder.join("src"))
|
||||
.expect("WASM build runner dir create can not fail; qed");
|
||||
|
||||
fs::write(
|
||||
project_folder.join("Cargo.toml"),
|
||||
format!(
|
||||
r#"
|
||||
[package]
|
||||
name = "wasm-build-runner-impl"
|
||||
version = "1.0.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
substrate-wasm-builder = {{ {wasm_builder_source} }}
|
||||
|
||||
[workspace]
|
||||
"#,
|
||||
wasm_builder_source = wasm_builder_source.to_cargo_source(manifest_dir),
|
||||
)
|
||||
).expect("WASM build runner `Cargo.toml` writing can not fail; qed");
|
||||
|
||||
fs::write(
|
||||
project_folder.join("src/main.rs"),
|
||||
format!(
|
||||
r#"
|
||||
fn main() {{
|
||||
substrate_wasm_builder::build_project("{file_path}", "{cargo_toml_path}")
|
||||
}}
|
||||
"#,
|
||||
file_path = replace_back_slashes(file_path.display()),
|
||||
cargo_toml_path = replace_back_slashes(cargo_toml_path.display()),
|
||||
)
|
||||
).expect("WASM build runner `main.rs` writing can not fail; qed");
|
||||
}
|
||||
|
||||
fn run_project(project_folder: &Path) {
|
||||
let cargo = env::var("CARGO").expect("`CARGO` env variable is always set when executing `build.rs`.");
|
||||
let mut cmd = Command::new(cargo);
|
||||
cmd.arg("run").arg(format!("--manifest-path={}", project_folder.join("Cargo.toml").display()));
|
||||
|
||||
if env::var("DEBUG") != Ok(String::from("true")) {
|
||||
cmd.arg("--release");
|
||||
}
|
||||
|
||||
if !cmd.status().map(|s| s.success()).unwrap_or(false) {
|
||||
panic!("Running WASM build runner failed!");
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate the name of the skip build environment variable for the current crate.
|
||||
fn generate_crate_skip_build_env_name() -> String {
|
||||
format!(
|
||||
"SKIP_{}_WASM_BUILD",
|
||||
env::var("CARGO_PKG_NAME").expect("Package name is set").to_uppercase().replace('-', "_"),
|
||||
)
|
||||
}
|
||||
|
||||
/// Checks if the build of the WASM binary should be skipped.
|
||||
fn check_skip_build() -> bool {
|
||||
env::var(SKIP_BUILD_ENV).is_ok() || env::var(generate_crate_skip_build_env_name()).is_ok()
|
||||
}
|
||||
|
||||
/// Check if we should provide a dummy WASM binary.
|
||||
fn check_provide_dummy_wasm_binary() -> bool {
|
||||
env::var(DUMMY_WASM_BINARY_ENV).is_ok()
|
||||
}
|
||||
|
||||
/// Provide the dummy WASM binary
|
||||
fn provide_dummy_wasm_binary(file_path: &Path) {
|
||||
fs::write(
|
||||
file_path,
|
||||
"pub const WASM_BINARY: &[u8] = &[]; pub const WASM_BINARY_BLOATY: &[u8] = &[];"
|
||||
).expect("Writing dummy WASM binary should not fail");
|
||||
}
|
||||
|
||||
/// Generate the `rerun-if-changed` instructions for cargo to make sure that the WASM binary is
|
||||
/// rebuilt when needed.
|
||||
fn generate_rerun_if_changed_instructions() {
|
||||
// Make sure that the `build.rs` is called again if one of the following env variables changes.
|
||||
println!("cargo:rerun-if-env-changed={}", SKIP_BUILD_ENV);
|
||||
println!("cargo:rerun-if-env-changed={}", DUMMY_WASM_BINARY_ENV);
|
||||
println!("cargo:rerun-if-env-changed={}", TRIGGER_WASM_BUILD_ENV);
|
||||
println!("cargo:rerun-if-env-changed={}", generate_crate_skip_build_env_name());
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "substrate-wasm-builder"
|
||||
version = "1.0.1"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
description = "Utility for building WASM binaries"
|
||||
edition = "2018"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/paritytech/substrate"
|
||||
license = "GPL-3.0"
|
||||
|
||||
[dependencies]
|
||||
build-helper = "0.1.1"
|
||||
cargo_metadata = "0.8"
|
||||
tempfile = "3.1.0"
|
||||
toml = "0.5.1"
|
||||
walkdir = "2.2.8"
|
||||
fs2 = "0.4.3"
|
||||
@@ -0,0 +1,65 @@
|
||||
## WASM builder is a utility for building a project as a WASM binary
|
||||
|
||||
The WASM builder is a tool that integrates the process of building the WASM binary of your project into the main
|
||||
`cargo` build process.
|
||||
|
||||
### Project setup
|
||||
|
||||
A project that should be compiled as a WASM binary needs to:
|
||||
|
||||
1. Add a `build.rs` file.
|
||||
2. Add `substrate-wasm-builder-runner` as dependency into `build-dependencies`.
|
||||
3. Add a feature called `no-std`.
|
||||
|
||||
The `build.rs` file needs to contain the following code:
|
||||
|
||||
```rust
|
||||
use wasm_builder_runner::{build_current_project, WasmBuilderSource};
|
||||
|
||||
fn main() {
|
||||
build_current_project(
|
||||
// The name of the file being generated in out-dir.
|
||||
"wasm_binary.rs",
|
||||
// How to include wasm-builder, in this case from crates.io.
|
||||
WasmBuilderSource::Crates("1.0.0"),
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
The `no-std` feature will be enabled by WASM builder while compiling your project to WASM.
|
||||
|
||||
As the final step, you need to add the following to your project:
|
||||
|
||||
```rust
|
||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
```
|
||||
|
||||
This will include the generated WASM binary as two constants `WASM_BINARY` and `WASM_BINARY_BLOATY`.
|
||||
The former is a compact WASM binary and the latter is not compacted.
|
||||
|
||||
### Environment variables
|
||||
|
||||
By using environment variables, you can configure which WASM binaries are built and how:
|
||||
|
||||
- `SKIP_WASM_BUILD` - Skips building any WASM binary. This is useful when only native should be recompiled.
|
||||
- `BUILD_DUMMY_WASM_BINARY` - Builds dummy WASM binaries. These dummy binaries are empty and useful
|
||||
for `cargo check` runs.
|
||||
- `WASM_BUILD_TYPE` - Sets the build type for building WASM binaries. Supported values are `release` or `debug`.
|
||||
By default the build type is equal to the build type used by the main build.
|
||||
- `TRIGGER_WASM_BUILD` - Can be set to trigger a WASM build. On subsequent calls the value of the variable
|
||||
needs to change. As WASM builder instructs `cargo` to watch for file changes
|
||||
this environment variable should only be required in certain circumstances.
|
||||
|
||||
Each project can be skipped individually by using the environment variable `SKIP_PROJECT_NAME_WASM_BUILD`.
|
||||
Where `PROJECT_NAME` needs to be replaced by the name of the cargo project, e.g. `node-runtime` will
|
||||
be `NODE_RUNTIME`.
|
||||
|
||||
### Prerequisites:
|
||||
|
||||
WASM builder requires the following prerequisities for building the WASM binary:
|
||||
|
||||
- rust nightly + `wasm32-unknown-unknown` toolchain
|
||||
- wasm-gc
|
||||
|
||||
|
||||
License: GPL-3.0
|
||||
@@ -0,0 +1,168 @@
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! # WASM builder is a utility for building a project as a WASM binary
|
||||
//!
|
||||
//! The WASM builder is a tool that integrates the process of building the WASM binary of your project into the main
|
||||
//! `cargo` build process.
|
||||
//!
|
||||
//! ## Project setup
|
||||
//!
|
||||
//! A project that should be compiled as a WASM binary needs to:
|
||||
//!
|
||||
//! 1. Add a `build.rs` file.
|
||||
//! 2. Add `substrate-wasm-builder-runner` as dependency into `build-dependencies`.
|
||||
//! 3. Add a feature called `no-std`.
|
||||
//!
|
||||
//! The `build.rs` file needs to contain the following code:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! use wasm_builder_runner::{build_current_project, WasmBuilderSource};
|
||||
//!
|
||||
//! fn main() {
|
||||
//! build_current_project(
|
||||
//! // The name of the file being generated in out-dir.
|
||||
//! "wasm_binary.rs",
|
||||
//! // How to include wasm-builder, in this case from crates.io.
|
||||
//! WasmBuilderSource::Crates("1.0.0"),
|
||||
//! );
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! The `no-std` feature will be enabled by WASM builder while compiling your project to WASM.
|
||||
//!
|
||||
//! As the final step, you need to add the following to your project:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
//! ```
|
||||
//!
|
||||
//! This will include the generated WASM binary as two constants `WASM_BINARY` and `WASM_BINARY_BLOATY`.
|
||||
//! The former is a compact WASM binary and the latter is not compacted.
|
||||
//!
|
||||
//! ## Environment variables
|
||||
//!
|
||||
//! By using environment variables, you can configure which WASM binaries are built and how:
|
||||
//!
|
||||
//! - `SKIP_WASM_BUILD` - Skips building any WASM binary. This is useful when only native should be recompiled.
|
||||
//! - `BUILD_DUMMY_WASM_BINARY` - Builds dummy WASM binaries. These dummy binaries are empty and useful
|
||||
//! for `cargo check` runs.
|
||||
//! - `WASM_BUILD_TYPE` - Sets the build type for building WASM binaries. Supported values are `release` or `debug`.
|
||||
//! By default the build type is equal to the build type used by the main build.
|
||||
//! - `TRIGGER_WASM_BUILD` - Can be set to trigger a WASM build. On subsequent calls the value of the variable
|
||||
//! needs to change. As WASM builder instructs `cargo` to watch for file changes
|
||||
//! this environment variable should only be required in certain circumstances.
|
||||
//!
|
||||
//! Each project can be skipped individually by using the environment variable `SKIP_PROJECT_NAME_WASM_BUILD`.
|
||||
//! Where `PROJECT_NAME` needs to be replaced by the name of the cargo project, e.g. `node-runtime` will
|
||||
//! be `NODE_RUNTIME`.
|
||||
//!
|
||||
//! ## Prerequisites:
|
||||
//!
|
||||
//! WASM builder requires the following prerequisities for building the WASM binary:
|
||||
//!
|
||||
//! - rust nightly + `wasm32-unknown-unknown` toolchain
|
||||
//! - wasm-gc
|
||||
//!
|
||||
|
||||
use std::{env, fs, path::PathBuf, process::Command};
|
||||
|
||||
mod prerequisites;
|
||||
mod wasm_project;
|
||||
|
||||
/// Environment variable that tells us to skip building the WASM binary.
|
||||
const SKIP_BUILD_ENV: &str = "SKIP_WASM_BUILD";
|
||||
|
||||
/// Environment variable to force a certain build type when building the WASM binary.
|
||||
/// Expects "debug" or "release" as value.
|
||||
///
|
||||
/// By default the WASM binary uses the same build type as the main cargo build.
|
||||
const WASM_BUILD_TYPE_ENV: &str = "WASM_BUILD_TYPE";
|
||||
|
||||
/// Build the currently built project as WASM binary.
|
||||
///
|
||||
/// The current project is determined by using the `CARGO_MANIFEST_DIR` environment variable.
|
||||
///
|
||||
/// `file_name` - The name + path of the file being generated. The file contains the
|
||||
/// constant `WASM_BINARY`, which contains the built WASM binary.
|
||||
/// `cargo_manifest` - The path to the `Cargo.toml` of the project that should be built.
|
||||
pub fn build_project(file_name: &str, cargo_manifest: &str) {
|
||||
if check_skip_build() {
|
||||
return;
|
||||
}
|
||||
|
||||
let cargo_manifest = PathBuf::from(cargo_manifest);
|
||||
|
||||
if !cargo_manifest.exists() {
|
||||
create_out_file(
|
||||
file_name,
|
||||
format!("compile_error!(\"'{}' does not exists!\")", cargo_manifest.display())
|
||||
);
|
||||
return
|
||||
}
|
||||
|
||||
if !cargo_manifest.ends_with("Cargo.toml") {
|
||||
create_out_file(
|
||||
file_name,
|
||||
format!("compile_error!(\"'{}' no valid path to a `Cargo.toml`!\")", cargo_manifest.display())
|
||||
);
|
||||
return
|
||||
}
|
||||
|
||||
if let Some(err_msg) = prerequisites::check() {
|
||||
create_out_file(file_name, format!("compile_error!(\"{}\");", err_msg));
|
||||
return
|
||||
}
|
||||
|
||||
let (wasm_binary, bloaty) = wasm_project::create_and_compile(&cargo_manifest);
|
||||
|
||||
create_out_file(
|
||||
file_name,
|
||||
format!(
|
||||
r#"
|
||||
pub const WASM_BINARY: &[u8] = include_bytes!("{wasm_binary}");
|
||||
pub const WASM_BINARY_BLOATY: &[u8] = include_bytes!("{wasm_binary_bloaty}");
|
||||
"#,
|
||||
wasm_binary = wasm_binary.wasm_binary_path(),
|
||||
wasm_binary_bloaty = bloaty.wasm_binary_bloaty_path(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Checks if the build of the WASM binary should be skipped.
|
||||
fn check_skip_build() -> bool {
|
||||
env::var(SKIP_BUILD_ENV).is_ok()
|
||||
}
|
||||
|
||||
fn create_out_file(file_name: &str, content: String) {
|
||||
fs::write(
|
||||
file_name,
|
||||
content
|
||||
).expect("Creating and writing can not fail; qed");
|
||||
}
|
||||
|
||||
/// Get a cargo command that compiles with nightly
|
||||
fn get_nightly_cargo() -> Command {
|
||||
if Command::new("rustup").args(&["run", "nightly", "cargo"])
|
||||
.status().map(|s| s.success()).unwrap_or(false)
|
||||
{
|
||||
let mut cmd = Command::new("rustup");
|
||||
cmd.args(&["run", "nightly", "cargo"]);
|
||||
cmd
|
||||
} else {
|
||||
Command::new("cargo")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::{process::{Command, Stdio}, fs};
|
||||
|
||||
use tempfile::tempdir;
|
||||
|
||||
/// Checks that all prerequisites are installed.
|
||||
///
|
||||
/// # Returns
|
||||
/// Returns `None` if everything was found and `Some(ERR_MSG)` if something could not be found.
|
||||
pub fn check() -> Option<&'static str> {
|
||||
if !check_nightly_installed() {
|
||||
return Some("Rust nightly not installed, please install it!")
|
||||
}
|
||||
|
||||
if Command::new("wasm-gc").stdout(Stdio::null()).status().map(|s| !s.success()).unwrap_or(true) {
|
||||
return Some("wasm-gc not installed, please install it!")
|
||||
}
|
||||
|
||||
if !check_wasm_toolchain_installed() {
|
||||
return Some("Rust WASM toolchain not installed, please install it!")
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn check_nightly_installed() -> bool {
|
||||
let version = Command::new("cargo")
|
||||
.arg("--version")
|
||||
.output()
|
||||
.map_err(|_| ())
|
||||
.and_then(|o| String::from_utf8(o.stdout).map_err(|_| ()))
|
||||
.unwrap_or_default();
|
||||
|
||||
let version2 = Command::new("rustup")
|
||||
.args(&["run", "nightly", "cargo", "--version"])
|
||||
.output()
|
||||
.map_err(|_| ())
|
||||
.and_then(|o| String::from_utf8(o.stdout).map_err(|_| ()))
|
||||
.unwrap_or_default();
|
||||
|
||||
version.contains("-nightly") || version2.contains("-nightly")
|
||||
}
|
||||
|
||||
fn check_wasm_toolchain_installed() -> bool {
|
||||
let temp = tempdir().expect("Creating temp dir does not fail; qed");
|
||||
fs::create_dir_all(temp.path().join("src")).expect("Creating src dir does not fail; qed");
|
||||
|
||||
let test_file = temp.path().join("src/lib.rs");
|
||||
let manifest_path = temp.path().join("Cargo.toml");
|
||||
|
||||
fs::write(&manifest_path,
|
||||
r#"
|
||||
[package]
|
||||
name = "wasm-test"
|
||||
version = "1.0.0"
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
name = "wasm_test"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[workspace]
|
||||
"#,
|
||||
).expect("Writing wasm-test manifest does not fail; qed");
|
||||
fs::write(&test_file, "pub fn test() {}")
|
||||
.expect("Writing to the test file does not fail; qed");
|
||||
|
||||
let manifest_path = manifest_path.display().to_string();
|
||||
crate::get_nightly_cargo()
|
||||
.args(&["build", "--target=wasm32-unknown-unknown", "--manifest-path", &manifest_path])
|
||||
.status()
|
||||
.map(|s| s.success())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
@@ -0,0 +1,336 @@
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::{fs, path::{Path, PathBuf}, borrow::ToOwned, process::Command, env};
|
||||
|
||||
use toml::value::Table;
|
||||
|
||||
use build_helper::rerun_if_changed;
|
||||
|
||||
use cargo_metadata::MetadataCommand;
|
||||
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use fs2::FileExt;
|
||||
|
||||
/// Holds the path to the bloaty WASM binary.
|
||||
pub struct WasmBinaryBloaty(PathBuf);
|
||||
|
||||
impl WasmBinaryBloaty {
|
||||
/// Returns the path to the bloaty wasm binary.
|
||||
pub fn wasm_binary_bloaty_path(&self) -> String {
|
||||
self.0.display().to_string().replace('\\', "/")
|
||||
}
|
||||
}
|
||||
|
||||
/// Holds the path to the WASM binary.
|
||||
pub struct WasmBinary(PathBuf);
|
||||
|
||||
impl WasmBinary {
|
||||
/// Returns the path to the wasm binary.
|
||||
pub fn wasm_binary_path(&self) -> String {
|
||||
self.0.display().to_string().replace('\\', "/")
|
||||
}
|
||||
}
|
||||
|
||||
/// A lock for the WASM workspace.
|
||||
struct WorkspaceLock(fs::File);
|
||||
|
||||
impl WorkspaceLock {
|
||||
/// Create a new lock
|
||||
fn new(wasm_workspace_root: &Path) -> Self {
|
||||
let lock = fs::OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(wasm_workspace_root.join("wasm_workspace.lock"))
|
||||
.expect("Opening the lock file does not fail");
|
||||
|
||||
lock.lock_exclusive().expect("Locking `wasm_workspace.lock` failed");
|
||||
|
||||
WorkspaceLock(lock)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for WorkspaceLock {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.0.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates the WASM project, compiles the WASM binary and compacts the WASM binary.
|
||||
///
|
||||
/// # Returns
|
||||
/// The path to the compact WASM binary and the bloaty WASM binary.
|
||||
pub fn create_and_compile(cargo_manifest: &Path) -> (WasmBinary, WasmBinaryBloaty) {
|
||||
let wasm_workspace_root = get_wasm_workspace_root();
|
||||
let wasm_workspace = wasm_workspace_root.join("wbuild");
|
||||
|
||||
// Lock the workspace exclusively for us
|
||||
let _lock = WorkspaceLock::new(&wasm_workspace_root);
|
||||
|
||||
let project = create_project(cargo_manifest, &wasm_workspace);
|
||||
create_wasm_workspace_project(&wasm_workspace);
|
||||
|
||||
build_project(&project);
|
||||
let (wasm_binary, bloaty) = compact_wasm_file(&project, cargo_manifest, &wasm_workspace);
|
||||
|
||||
generate_rerun_if_changed_instructions(cargo_manifest, &project, &wasm_workspace);
|
||||
|
||||
(wasm_binary, bloaty)
|
||||
}
|
||||
|
||||
/// Find the `Cargo.lock` relative to the `OUT_DIR` environment variable.
|
||||
///
|
||||
/// If the `Cargo.lock` cannot be found, we emit a warning and return `None`.
|
||||
fn find_cargo_lock(cargo_manifest: &Path) -> Option<PathBuf> {
|
||||
let mut path = build_helper::out_dir();
|
||||
|
||||
while path.pop() {
|
||||
if path.join("Cargo.lock").exists() {
|
||||
return Some(path.join("Cargo.lock"))
|
||||
}
|
||||
}
|
||||
|
||||
build_helper::warning!(
|
||||
"Could not find `Cargo.lock` for `{}`, while searching from `{}`.",
|
||||
cargo_manifest.display(),
|
||||
build_helper::out_dir().display()
|
||||
);
|
||||
None
|
||||
}
|
||||
|
||||
/// Extract the crate name from the given `Cargo.toml`.
|
||||
fn get_crate_name(cargo_manifest: &Path) -> String {
|
||||
let cargo_toml: Table = toml::from_str(
|
||||
&fs::read_to_string(cargo_manifest).expect("File exists as checked before; qed")
|
||||
).expect("Cargo manifest is a valid toml file; qed");
|
||||
|
||||
let package = cargo_toml
|
||||
.get("package")
|
||||
.and_then(|t| t.as_table())
|
||||
.expect("`package` key exists in valid `Cargo.toml`; qed");
|
||||
|
||||
package.get("name").and_then(|p| p.as_str()).map(ToOwned::to_owned).expect("Package name exists; qed")
|
||||
}
|
||||
|
||||
/// Returns the name for the wasm binary.
|
||||
fn get_wasm_binary_name(cargo_manifest: &Path) -> String {
|
||||
get_crate_name(cargo_manifest).replace('-', "_")
|
||||
}
|
||||
|
||||
/// Returns the root path of the wasm workspace.
|
||||
fn get_wasm_workspace_root() -> PathBuf {
|
||||
let mut out_dir = build_helper::out_dir();
|
||||
|
||||
while out_dir.parent().is_some() {
|
||||
if out_dir.parent().map(|p| p.ends_with("target")).unwrap_or(false) {
|
||||
return out_dir;
|
||||
}
|
||||
|
||||
out_dir.pop();
|
||||
}
|
||||
|
||||
panic!("Could not find target dir in: {}", build_helper::out_dir().display())
|
||||
}
|
||||
|
||||
fn create_wasm_workspace_project(wasm_workspace: &Path) {
|
||||
let members = WalkDir::new(wasm_workspace)
|
||||
.min_depth(1)
|
||||
.max_depth(1)
|
||||
.into_iter()
|
||||
.filter_map(|p| p.ok())
|
||||
.map(|d| d.into_path())
|
||||
.filter(|p| p.is_dir() && !p.ends_with("target"))
|
||||
.filter_map(|p| p.file_name().map(|f| f.to_owned()).and_then(|s| s.into_string().ok()))
|
||||
.map(|s| format!("\"{}\", ", s))
|
||||
.collect::<String>();
|
||||
|
||||
fs::write(
|
||||
wasm_workspace.join("Cargo.toml"),
|
||||
format!(
|
||||
r#"
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
lto = true
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
||||
[workspace]
|
||||
members = [ {members} ]
|
||||
"#,
|
||||
members = members,
|
||||
)
|
||||
).expect("WASM workspace `Cargo.toml` writing can not fail; qed");
|
||||
}
|
||||
|
||||
/// Create the project used to build the wasm binary.
|
||||
///
|
||||
/// # Returns
|
||||
/// The path to the created project.
|
||||
fn create_project(cargo_manifest: &Path, wasm_workspace: &Path) -> PathBuf {
|
||||
let crate_name = get_crate_name(cargo_manifest);
|
||||
let crate_path = cargo_manifest.parent().expect("Parent path exists; qed");
|
||||
let wasm_binary = get_wasm_binary_name(cargo_manifest);
|
||||
let project_folder = wasm_workspace.join(&crate_name);
|
||||
|
||||
fs::create_dir_all(project_folder.join("src")).expect("Wasm project dir create can not fail; qed");
|
||||
|
||||
fs::write(
|
||||
project_folder.join("Cargo.toml"),
|
||||
format!(
|
||||
r#"
|
||||
[package]
|
||||
name = "{crate_name}-wasm"
|
||||
version = "1.0.0"
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
name = "{wasm_binary}"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
wasm_project = {{ package = "{crate_name}", path = "{crate_path}", default-features = false, features = [ "no_std" ] }}
|
||||
"#,
|
||||
crate_name = crate_name,
|
||||
crate_path = crate_path.display(),
|
||||
wasm_binary = wasm_binary,
|
||||
)
|
||||
).expect("Project `Cargo.toml` writing can not fail; qed");
|
||||
|
||||
fs::write(
|
||||
project_folder.join("src/lib.rs"),
|
||||
format!(
|
||||
r#"
|
||||
#![no_std]
|
||||
pub use wasm_project::*;
|
||||
"#
|
||||
)
|
||||
).expect("Project `lib.rs` writing can not fail; qed");
|
||||
|
||||
if let Some(crate_lock_file) = find_cargo_lock(cargo_manifest) {
|
||||
// Use the `Cargo.lock` of the main project.
|
||||
fs::copy(crate_lock_file, wasm_workspace.join("Cargo.lock"))
|
||||
.expect("Copying the `Cargo.lock` can not fail; qed");
|
||||
}
|
||||
|
||||
project_folder
|
||||
}
|
||||
|
||||
/// Returns if the project should be built as a release.
|
||||
fn is_release_build() -> bool {
|
||||
if let Ok(var) = env::var(crate::WASM_BUILD_TYPE_ENV) {
|
||||
match var.as_str() {
|
||||
"release" => true,
|
||||
"debug" => false,
|
||||
var => panic!(
|
||||
"Unexpected value for `{}` env variable: {}\nOne of the following are expected: `debug` or `release`.",
|
||||
crate::WASM_BUILD_TYPE_ENV,
|
||||
var,
|
||||
),
|
||||
}
|
||||
} else {
|
||||
!build_helper::debug()
|
||||
}
|
||||
}
|
||||
|
||||
/// Build the project to create the WASM binary.
|
||||
fn build_project(project: &Path) {
|
||||
let manifest_path = project.join("Cargo.toml");
|
||||
let mut build_cmd = crate::get_nightly_cargo();
|
||||
build_cmd.args(&["build", "--target=wasm32-unknown-unknown"])
|
||||
.arg(format!("--manifest-path={}", manifest_path.display()))
|
||||
.env("RUSTFLAGS", "-C link-arg=--export-table")
|
||||
// We don't want to call ourselves recursively
|
||||
.env(crate::SKIP_BUILD_ENV, "");
|
||||
|
||||
if is_release_build() {
|
||||
build_cmd.arg("--release");
|
||||
};
|
||||
|
||||
println!("Executing build command: {:?}", build_cmd);
|
||||
|
||||
match build_cmd.status().map(|s| s.success()) {
|
||||
Ok(true) => {},
|
||||
_ => panic!("Failed to compile WASM binary"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Compact the WASM binary using `wasm-gc`. Returns the path to the bloaty WASM binary.
|
||||
fn compact_wasm_file(
|
||||
project: &Path,
|
||||
cargo_manifest: &Path,
|
||||
wasm_workspace: &Path,
|
||||
) -> (WasmBinary, WasmBinaryBloaty) {
|
||||
let target = if is_release_build() { "release" } else { "debug" };
|
||||
let wasm_binary = get_wasm_binary_name(cargo_manifest);
|
||||
let wasm_file = wasm_workspace.join("target/wasm32-unknown-unknown")
|
||||
.join(target)
|
||||
.join(format!("{}.wasm", wasm_binary));
|
||||
let wasm_compact_file = project.join(format!("{}.compact.wasm", wasm_binary));
|
||||
|
||||
let res = Command::new("wasm-gc")
|
||||
.arg(&wasm_file)
|
||||
.arg(&wasm_compact_file)
|
||||
.status()
|
||||
.map(|s| s.success());
|
||||
|
||||
if !res.unwrap_or(false) {
|
||||
panic!("Failed to compact generated WASM binary.");
|
||||
}
|
||||
|
||||
(WasmBinary(wasm_compact_file), WasmBinaryBloaty(wasm_file))
|
||||
}
|
||||
|
||||
/// Generate the `rerun-if-changed` instructions for cargo to make sure that the WASM binary is
|
||||
/// rebuilt when needed.
|
||||
fn generate_rerun_if_changed_instructions(
|
||||
cargo_manifest: &Path,
|
||||
project_folder: &Path,
|
||||
wasm_workspace: &Path,
|
||||
) {
|
||||
// Rerun `build.rs` if the `Cargo.lock` changes
|
||||
if let Some(cargo_lock) = find_cargo_lock(cargo_manifest) {
|
||||
rerun_if_changed(cargo_lock);
|
||||
}
|
||||
|
||||
let metadata = MetadataCommand::new()
|
||||
.manifest_path(project_folder.join("Cargo.toml"))
|
||||
.exec()
|
||||
.expect("`cargo metadata` can not fail!");
|
||||
|
||||
// Make sure that if any file/folder of a depedency change, we need to rerun the `build.rs`
|
||||
metadata.packages.into_iter()
|
||||
.filter(|package| !package.manifest_path.starts_with(wasm_workspace))
|
||||
.for_each(|package| {
|
||||
let mut manifest_path = package.manifest_path;
|
||||
if manifest_path.ends_with("Cargo.toml") {
|
||||
manifest_path.pop();
|
||||
}
|
||||
|
||||
rerun_if_changed(&manifest_path);
|
||||
|
||||
WalkDir::new(manifest_path)
|
||||
.into_iter()
|
||||
.filter_map(|p| p.ok())
|
||||
.for_each(|p| rerun_if_changed(p.path()));
|
||||
});
|
||||
|
||||
// Register our env variables
|
||||
println!("cargo:rerun-if-env-changed={}", crate::SKIP_BUILD_ENV);
|
||||
println!("cargo:rerun-if-env-changed={}", crate::WASM_BUILD_TYPE_ENV);
|
||||
}
|
||||
@@ -16,12 +16,6 @@ Install required tools:
|
||||
./scripts/init.sh
|
||||
```
|
||||
|
||||
Build the WebAssembly binary:
|
||||
|
||||
```bash
|
||||
./scripts/build.sh
|
||||
```
|
||||
|
||||
Build all native code:
|
||||
|
||||
```bash
|
||||
|
||||
@@ -25,6 +25,9 @@ client = { package = "substrate-client", path = "../../core/client", default_fea
|
||||
consensus-aura = { package = "substrate-consensus-aura-primitives", path = "../../core/consensus/aura/primitives", default_features = false }
|
||||
offchain-primitives = { package = "substrate-offchain-primitives", path = "../../core/offchain/primitives", default-features = false }
|
||||
|
||||
[build-dependencies]
|
||||
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.0" }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
@@ -48,3 +51,4 @@ std = [
|
||||
"consensus-aura/std",
|
||||
"offchain-primitives/std",
|
||||
]
|
||||
no_std = []
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use wasm_builder_runner::{build_current_project, WasmBuilderSource};
|
||||
|
||||
fn main() {
|
||||
build_current_project("wasm_binary.rs", WasmBuilderSource::Crates("1.0.1"));
|
||||
}
|
||||
@@ -4,6 +4,10 @@
|
||||
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
|
||||
#![recursion_limit="256"]
|
||||
|
||||
// Make the WASM binary available.
|
||||
#[cfg(feature = "std")]
|
||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use parity_codec::{Encode, Decode};
|
||||
|
||||
-3745
File diff suppressed because it is too large
Load Diff
@@ -1,24 +0,0 @@
|
||||
[package]
|
||||
name = "node-template-runtime-wasm"
|
||||
version = "2.0.0"
|
||||
authors = ["Anonymous"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
node-template-runtime = { path = "..", default-features = false }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
std = [
|
||||
"node-template-runtime/std",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
lto = true
|
||||
|
||||
[workspace]
|
||||
members = []
|
||||
@@ -1,13 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
if cargo --version | grep -q "nightly"; then
|
||||
CARGO_CMD="cargo"
|
||||
else
|
||||
CARGO_CMD="cargo +nightly"
|
||||
fi
|
||||
CARGO_INCREMENTAL=0 RUSTFLAGS="-C link-arg=--export-table" $CARGO_CMD build --target=wasm32-unknown-unknown --release "$@"
|
||||
for i in node_template_runtime_wasm
|
||||
do
|
||||
wasm-gc target/wasm32-unknown-unknown/release/$i.wasm target/wasm32-unknown-unknown/release/$i.compact.wasm
|
||||
done
|
||||
@@ -1,5 +0,0 @@
|
||||
//! The Substrate node template runtime reexported for WebAssembly compile.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
pub use node_template_runtime::*;
|
||||
@@ -1,26 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
PROJECT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null && pwd )"
|
||||
|
||||
export CARGO_INCREMENTAL=0
|
||||
|
||||
bold=$(tput bold)
|
||||
normal=$(tput sgr0)
|
||||
|
||||
# Save current directory.
|
||||
pushd . >/dev/null
|
||||
|
||||
for SRC in runtime/wasm
|
||||
do
|
||||
echo "${bold}Building webassembly binary in $SRC...${normal}"
|
||||
cd "$PROJECT_ROOT/$SRC"
|
||||
|
||||
./build.sh "$@"
|
||||
|
||||
cd - >> /dev/null
|
||||
done
|
||||
|
||||
# Restore initial directory.
|
||||
popd >/dev/null
|
||||
@@ -1,7 +1,7 @@
|
||||
use primitives::{ed25519, sr25519, Pair};
|
||||
use node_template_runtime::{
|
||||
AccountId, AuraId as AuthorityId, GenesisConfig, AuraConfig, TimestampConfig, BalancesConfig,
|
||||
SudoConfig, IndicesConfig, SystemConfig
|
||||
AccountId, GenesisConfig, AuraConfig, TimestampConfig, BalancesConfig,
|
||||
SudoConfig, IndicesConfig, SystemConfig, WASM_BINARY, AuraId
|
||||
};
|
||||
use substrate_service;
|
||||
|
||||
@@ -22,7 +22,7 @@ pub enum Alternative {
|
||||
LocalTestnet,
|
||||
}
|
||||
|
||||
fn authority_key(s: &str) -> AuthorityId {
|
||||
fn authority_key(s: &str) -> AuraId {
|
||||
ed25519::Pair::from_string(&format!("//{}", s), None)
|
||||
.expect("static values are valid; qed")
|
||||
.public()
|
||||
@@ -88,10 +88,10 @@ impl Alternative {
|
||||
}
|
||||
}
|
||||
|
||||
fn testnet_genesis(initial_authorities: Vec<AuthorityId>, endowed_accounts: Vec<AccountId>, root_key: AccountId) -> GenesisConfig {
|
||||
fn testnet_genesis(initial_authorities: Vec<AuraId>, endowed_accounts: Vec<AccountId>, root_key: AccountId) -> GenesisConfig {
|
||||
GenesisConfig {
|
||||
system: Some(SystemConfig {
|
||||
code: include_bytes!("../runtime/wasm/target/wasm32-unknown-unknown/release/node_template_runtime_wasm.compact.wasm").to_vec(),
|
||||
code: WASM_BINARY.to_vec(),
|
||||
changes_trie_config: Default::default(),
|
||||
}),
|
||||
aura: Some(AuraConfig {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use std::sync::Arc;
|
||||
use log::info;
|
||||
use transaction_pool::{self, txpool::{Pool as TransactionPool}};
|
||||
use node_template_runtime::{self, GenesisConfig, opaque::Block, RuntimeApi};
|
||||
use node_template_runtime::{self, GenesisConfig, opaque::Block, RuntimeApi, WASM_BINARY};
|
||||
use substrate_service::{
|
||||
FactoryFullConfiguration, LightComponents, FullComponents, FullBackend,
|
||||
FullClient, LightClient, LightBackend, FullExecutor, LightExecutor,
|
||||
@@ -27,7 +27,7 @@ native_executor_instance!(
|
||||
pub Executor,
|
||||
node_template_runtime::api::dispatch,
|
||||
node_template_runtime::native_version,
|
||||
include_bytes!("../runtime/wasm/target/wasm32-unknown-unknown/release/node_template_runtime_wasm.compact.wasm")
|
||||
WASM_BINARY
|
||||
);
|
||||
|
||||
#[derive(Default)]
|
||||
|
||||
@@ -21,9 +21,8 @@ use node_primitives::{AccountId, AuraId, Balance};
|
||||
use node_runtime::{
|
||||
AuraConfig, BalancesConfig, ContractsConfig, CouncilSeatsConfig, DemocracyConfig,
|
||||
GrandpaConfig, IndicesConfig, SessionConfig, StakingConfig, SudoConfig,
|
||||
SystemConfig, TimestampConfig,
|
||||
Perbill, SessionKeys, StakerStatus,
|
||||
DAYS, DOLLARS, MILLICENTS, SECS_PER_BLOCK,
|
||||
SystemConfig, TimestampConfig, WASM_BINARY, Perbill, SessionKeys, StakerStatus, DAYS, DOLLARS,
|
||||
MILLICENTS, SECS_PER_BLOCK,
|
||||
};
|
||||
pub use node_runtime::GenesisConfig;
|
||||
use substrate_service;
|
||||
@@ -97,7 +96,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
|
||||
GenesisConfig {
|
||||
system: Some(SystemConfig {
|
||||
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm").to_vec(), // FIXME change once we have #1252
|
||||
code: WASM_BINARY.to_vec(),
|
||||
changes_trie_config: Default::default(),
|
||||
}),
|
||||
balances: Some(BalancesConfig {
|
||||
@@ -230,7 +229,7 @@ pub fn testnet_genesis(
|
||||
|
||||
GenesisConfig {
|
||||
system: Some(SystemConfig {
|
||||
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm").to_vec(),
|
||||
code: WASM_BINARY.to_vec(),
|
||||
changes_trie_config: Default::default(),
|
||||
}),
|
||||
indices: Some(IndicesConfig {
|
||||
|
||||
@@ -30,9 +30,7 @@ native_executor_instance!(
|
||||
pub Executor,
|
||||
node_runtime::api::dispatch,
|
||||
node_runtime::native_version,
|
||||
include_bytes!(
|
||||
"../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm"
|
||||
)
|
||||
node_runtime::WASM_BINARY
|
||||
);
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -44,8 +42,10 @@ mod tests {
|
||||
use keyring::{AuthorityKeyring, AccountKeyring};
|
||||
use runtime_support::{Hashable, StorageValue, StorageMap, traits::Currency};
|
||||
use state_machine::{CodeExecutor, Externalities, TestExternalities as CoreTestExternalities};
|
||||
use primitives::{twox_128, blake2_256, Blake2Hasher, ChangesTrieConfiguration, NeverNativeValue,
|
||||
NativeOrEncoded};
|
||||
use primitives::{
|
||||
twox_128, blake2_256, Blake2Hasher, ChangesTrieConfiguration, NeverNativeValue,
|
||||
NativeOrEncoded
|
||||
};
|
||||
use node_primitives::{Hash, BlockNumber, AccountId};
|
||||
use runtime_primitives::traits::{Header as HeaderT, Hash as HashT};
|
||||
use runtime_primitives::{generic::Era, ApplyOutcome, ApplyError, ApplyResult, Perbill};
|
||||
@@ -53,10 +53,9 @@ mod tests {
|
||||
use contracts::ContractAddressFor;
|
||||
use system::{EventRecord, Phase};
|
||||
use node_runtime::{
|
||||
Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Call, Runtime, Balances,
|
||||
BuildStorage, GenesisConfig, BalancesConfig, SessionConfig, StakingConfig,
|
||||
System, SystemConfig, GrandpaConfig, IndicesConfig, ContractsConfig, Event,
|
||||
SessionKeys, Treasury, CENTS, DOLLARS, MILLICENTS
|
||||
Header, Block, UncheckedExtrinsic, CheckedExtrinsic, Call, Runtime, Balances, BuildStorage,
|
||||
GenesisConfig, BalancesConfig, SessionConfig, StakingConfig, System, SystemConfig,
|
||||
GrandpaConfig, IndicesConfig, ContractsConfig, Event, SessionKeys, CENTS, DOLLARS, MILLICENTS
|
||||
};
|
||||
use wabt;
|
||||
use primitives::map;
|
||||
@@ -67,16 +66,14 @@ mod tests {
|
||||
/// making the binary slimmer. There is a convention to use compact version of the runtime
|
||||
/// as canonical. This is why `native_executor_instance` also uses the compact version of the
|
||||
/// runtime.
|
||||
const COMPACT_CODE: &[u8] =
|
||||
include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm");
|
||||
const COMPACT_CODE: &[u8] = node_runtime::WASM_BINARY;
|
||||
|
||||
/// The wasm runtime binary which hasn't undergone the compacting process.
|
||||
///
|
||||
/// The idea here is to pass it as the current runtime code to the executor so the executor will
|
||||
/// have to execute provided wasm code instead of the native equivalent. This trick is used to
|
||||
/// test code paths that differ between native and wasm versions.
|
||||
const BLOATY_CODE: &[u8] =
|
||||
include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.wasm");
|
||||
const BLOATY_CODE: &[u8] = node_runtime::WASM_BINARY_BLOATY;
|
||||
|
||||
const GENESIS_HASH: [u8; 32] = [69u8; 32];
|
||||
|
||||
@@ -145,7 +142,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn executor() -> ::substrate_executor::NativeExecutor<Executor> {
|
||||
::substrate_executor::NativeExecutor::new(None)
|
||||
substrate_executor::NativeExecutor::new(None)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -3,6 +3,7 @@ name = "node-runtime"
|
||||
version = "2.0.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
integer-sqrt = { version = "0.1.2" }
|
||||
@@ -37,9 +38,12 @@ rustc-hex = { version = "2.0", optional = true }
|
||||
serde = { version = "1.0", optional = true }
|
||||
substrate-keyring = { path = "../../core/keyring", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.0" }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
core = [
|
||||
no_std = [
|
||||
"contracts/core",
|
||||
]
|
||||
std = [
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Substrate is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use wasm_builder_runner::{build_current_project, WasmBuilderSource};
|
||||
|
||||
fn main() {
|
||||
build_current_project(
|
||||
"wasm_binary.rs",
|
||||
WasmBuilderSource::Crates("1.0.1"),
|
||||
);
|
||||
}
|
||||
@@ -58,6 +58,10 @@ pub use runtime_primitives::{Permill, Perbill, impl_opaque_keys};
|
||||
pub use support::StorageValue;
|
||||
pub use staking::StakerStatus;
|
||||
|
||||
// Make the WASM binary available.
|
||||
#[cfg(feature = "std")]
|
||||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
|
||||
/// Runtime version.
|
||||
pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: create_runtime_str!("node"),
|
||||
|
||||
Generated
-3907
File diff suppressed because it is too large
Load Diff
@@ -1,28 +0,0 @@
|
||||
[package]
|
||||
name = "node-runtime-wasm"
|
||||
version = "2.0.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
name = "node_runtime"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
node-runtime = { path = "..", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["core"]
|
||||
core = [
|
||||
"node-runtime/core",
|
||||
]
|
||||
std = [
|
||||
"node-runtime/std",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
lto = true
|
||||
|
||||
[workspace]
|
||||
members = []
|
||||
@@ -1,13 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
if cargo --version | grep -q "nightly"; then
|
||||
CARGO_CMD="cargo"
|
||||
else
|
||||
CARGO_CMD="cargo +nightly"
|
||||
fi
|
||||
CARGO_INCREMENTAL=0 RUSTFLAGS="-C link-arg=--export-table" $CARGO_CMD build --target=wasm32-unknown-unknown --release "$@"
|
||||
for i in node_runtime
|
||||
do
|
||||
wasm-gc target/wasm32-unknown-unknown/release/$i.wasm target/wasm32-unknown-unknown/release/$i.compact.wasm
|
||||
done
|
||||
@@ -1,28 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script assumes that all pre-requisites are installed.
|
||||
|
||||
set -e
|
||||
|
||||
PROJECT_ROOT=`git rev-parse --show-toplevel`
|
||||
source "`dirname \"$0\"`/common.sh"
|
||||
|
||||
export CARGO_INCREMENTAL=0
|
||||
|
||||
# Save current directory.
|
||||
pushd .
|
||||
|
||||
cd -- "$ROOT"
|
||||
|
||||
for SRC in "${SRCS[@]}"
|
||||
do
|
||||
echo "*** Building wasm binaries in $SRC"
|
||||
cd "$PROJECT_ROOT/$SRC"
|
||||
|
||||
./build.sh "$@"
|
||||
|
||||
cd - >> /dev/null
|
||||
done
|
||||
|
||||
# Restore initial directory.
|
||||
popd
|
||||
@@ -395,7 +395,6 @@ mod tests {
|
||||
use balances::Call;
|
||||
use runtime_io::with_externalities;
|
||||
use substrate_primitives::{H256, Blake2Hasher};
|
||||
use primitives::BuildStorage;
|
||||
use primitives::traits::{Header as HeaderT, BlakeTwo256, IdentityLookup};
|
||||
use primitives::testing::{Digest, Header, Block};
|
||||
use srml_support::{impl_outer_event, impl_outer_origin, parameter_types};
|
||||
|
||||
Reference in New Issue
Block a user