mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 00:47:55 +00:00
Init RuntimeLogger automatically for each runtime api call (#8128)
* Init `RuntimeLogger` automatically for each runtime api call This pr change the runtime api in such a way to always and automatically enable the `RuntimeLogger`. This enables the user to use `log` or `tracing` from inside the runtime to create log messages. As logging introduces some extra code and especially increases the size of the wasm blob. It is advised to disable all logging completely with `sp-api/disable-logging` when doing the wasm builds for the on-chain wasm runtime. Besides these changes, the pr also brings most of the logging found in frame to the same format "runtime::*". * Update frame/im-online/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Update test-utils/runtime/Cargo.toml * Fix test * Don't use tracing in the runtime, as we don't support it :D * Fixes Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
@@ -97,6 +97,8 @@ pub(crate) fn create_and_compile(
|
||||
project_cargo_toml: &Path,
|
||||
default_rustflags: &str,
|
||||
cargo_cmd: CargoCommandVersioned,
|
||||
features_to_enable: Vec<String>,
|
||||
wasm_binary_name: Option<String>,
|
||||
) -> (Option<WasmBinary>, WasmBinaryBloaty) {
|
||||
let wasm_workspace_root = get_wasm_workspace_root();
|
||||
let wasm_workspace = wasm_workspace_root.join("wbuild");
|
||||
@@ -108,12 +110,14 @@ pub(crate) fn create_and_compile(
|
||||
&wasm_workspace,
|
||||
&crate_metadata,
|
||||
&crate_metadata.workspace_root,
|
||||
features_to_enable,
|
||||
);
|
||||
|
||||
build_project(&project, default_rustflags, cargo_cmd);
|
||||
let (wasm_binary, bloaty) = compact_wasm_file(
|
||||
&project,
|
||||
project_cargo_toml,
|
||||
wasm_binary_name,
|
||||
);
|
||||
|
||||
wasm_binary.as_ref().map(|wasm_binary|
|
||||
@@ -199,7 +203,7 @@ fn create_project_cargo_toml(
|
||||
crate_name: &str,
|
||||
crate_path: &Path,
|
||||
wasm_binary: &str,
|
||||
enabled_features: &[String],
|
||||
enabled_features: impl Iterator<Item = String>,
|
||||
) {
|
||||
let mut workspace_toml: Table = toml::from_str(
|
||||
&fs::read_to_string(
|
||||
@@ -265,7 +269,7 @@ fn create_project_cargo_toml(
|
||||
wasm_project.insert("package".into(), crate_name.into());
|
||||
wasm_project.insert("path".into(), crate_path.display().to_string().into());
|
||||
wasm_project.insert("default-features".into(), false.into());
|
||||
wasm_project.insert("features".into(), enabled_features.to_vec().into());
|
||||
wasm_project.insert("features".into(), enabled_features.collect::<Vec<_>>().into());
|
||||
|
||||
dependencies.insert("wasm-project".into(), wasm_project.into());
|
||||
|
||||
@@ -339,6 +343,7 @@ fn create_project(
|
||||
wasm_workspace: &Path,
|
||||
crate_metadata: &Metadata,
|
||||
workspace_root_path: &Path,
|
||||
features_to_enable: Vec<String>,
|
||||
) -> PathBuf {
|
||||
let crate_name = get_crate_name(project_cargo_toml);
|
||||
let crate_path = project_cargo_toml.parent().expect("Parent path exists; qed");
|
||||
@@ -354,13 +359,16 @@ fn create_project(
|
||||
enabled_features.push("runtime-wasm".into());
|
||||
}
|
||||
|
||||
let mut enabled_features = enabled_features.into_iter().collect::<HashSet<_>>();
|
||||
enabled_features.extend(features_to_enable.into_iter());
|
||||
|
||||
create_project_cargo_toml(
|
||||
&wasm_project_folder,
|
||||
workspace_root_path,
|
||||
&crate_name,
|
||||
&crate_path,
|
||||
&wasm_binary,
|
||||
&enabled_features,
|
||||
enabled_features.into_iter(),
|
||||
);
|
||||
|
||||
write_file_if_changed(
|
||||
@@ -437,16 +445,22 @@ fn build_project(project: &Path, default_rustflags: &str, cargo_cmd: CargoComman
|
||||
fn compact_wasm_file(
|
||||
project: &Path,
|
||||
cargo_manifest: &Path,
|
||||
wasm_binary_name: Option<String>,
|
||||
) -> (Option<WasmBinary>, WasmBinaryBloaty) {
|
||||
let is_release_build = is_release_build();
|
||||
let target = if is_release_build { "release" } else { "debug" };
|
||||
let wasm_binary = get_wasm_binary_name(cargo_manifest);
|
||||
let default_wasm_binary_name = get_wasm_binary_name(cargo_manifest);
|
||||
let wasm_file = project.join("target/wasm32-unknown-unknown")
|
||||
.join(target)
|
||||
.join(format!("{}.wasm", wasm_binary));
|
||||
.join(format!("{}.wasm", default_wasm_binary_name));
|
||||
|
||||
let wasm_compact_file = if is_release_build {
|
||||
let wasm_compact_file = project.join(format!("{}.compact.wasm", wasm_binary));
|
||||
let wasm_compact_file = project.join(
|
||||
format!(
|
||||
"{}.compact.wasm",
|
||||
wasm_binary_name.clone().unwrap_or_else(|| default_wasm_binary_name.clone()),
|
||||
)
|
||||
);
|
||||
wasm_gc::garbage_collect_file(&wasm_file, &wasm_compact_file)
|
||||
.expect("Failed to compact generated WASM binary.");
|
||||
Some(WasmBinary(wasm_compact_file))
|
||||
@@ -454,7 +468,16 @@ fn compact_wasm_file(
|
||||
None
|
||||
};
|
||||
|
||||
(wasm_compact_file, WasmBinaryBloaty(wasm_file))
|
||||
let bloaty_file_name = if let Some(name) = wasm_binary_name {
|
||||
format!("{}.wasm", name)
|
||||
} else {
|
||||
format!("{}.wasm", default_wasm_binary_name)
|
||||
};
|
||||
|
||||
let bloaty_file = project.join(bloaty_file_name);
|
||||
fs::copy(wasm_file, &bloaty_file).expect("Copying the bloaty file to the project dir.");
|
||||
|
||||
(wasm_compact_file, WasmBinaryBloaty(bloaty_file))
|
||||
}
|
||||
|
||||
/// Custom wrapper for a [`cargo_metadata::Package`] to store it in
|
||||
|
||||
Reference in New Issue
Block a user