This repository has been archived by the owner on Feb 21, 2024. It is now read-only.
forked from paritytech/substrate
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request paritytech#300 from subspace/bundled-execution-run…
…time Bundled execution runtime
- Loading branch information
Showing
18 changed files
with
1,067 additions
and
934 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "subspace-wasm-tools" | ||
description = "Utilities for building WASM bundles" | ||
license = "Apache-2.0" | ||
version = "0.1.0" | ||
authors = ["Nazar Mokrynskyi <[email protected]>"] | ||
edition = "2021" | ||
include = [ | ||
"/src", | ||
"/Cargo.toml", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::{env, fs}; | ||
|
||
/// Creates a `target_file_name` in `OUT_DIR` that will contain constant `bundle_const_name` with | ||
/// runtime of `runtime_crate_name` stored in it. | ||
/// | ||
/// Must be called before Substrate's WASM builder. | ||
pub fn create_runtime_bundle_inclusion_file( | ||
target_dir: &str, | ||
runtime_crate_name: &str, | ||
bundle_const_name: &str, | ||
target_file_name: &str, | ||
) { | ||
// Make correct profile accessible in child processes. | ||
env::set_var( | ||
"WBUILD_PROFILE", | ||
env::var("WBUILD_PROFILE") | ||
.unwrap_or_else(|_| env::var("PROFILE").expect("Defined by cargo; qed")), | ||
); | ||
|
||
// Create a file that will include execution runtime into consensus runtime | ||
let profile = env::var("WBUILD_PROFILE").expect("Set above; qed"); | ||
let execution_wasm_bundle_path = format!( | ||
"{target_dir}/{profile}/wbuild/{runtime_crate_name}/{}.compact.wasm", | ||
runtime_crate_name.replace('-', "_") | ||
); | ||
|
||
let execution_wasm_bundle_rs_path = | ||
env::var("OUT_DIR").expect("Set by cargo; qed") + "/" + target_file_name; | ||
let execution_wasm_bundle_rs_contents = format!( | ||
r#" | ||
pub const {bundle_const_name}: &[u8] = include_bytes!("{}"); | ||
"#, | ||
execution_wasm_bundle_path.escape_default() | ||
); | ||
|
||
fs::write( | ||
execution_wasm_bundle_rs_path, | ||
execution_wasm_bundle_rs_contents, | ||
) | ||
.unwrap_or_else(|error| { | ||
panic!("Must be able to write to {target_file_name}: {error}"); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.