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:
Bastian Köcher
2021-03-01 15:29:17 +01:00
committed by GitHub
parent f2d9bb9ea6
commit 68390d4085
65 changed files with 571 additions and 422 deletions
+24 -1
View File
@@ -43,6 +43,7 @@ impl WasmBuilderSelectProject {
rust_flags: Vec::new(),
file_name: None,
project_cargo_toml: get_manifest_dir().join("Cargo.toml"),
features_to_enable: Vec::new(),
}
}
@@ -60,6 +61,7 @@ impl WasmBuilderSelectProject {
rust_flags: Vec::new(),
file_name: None,
project_cargo_toml: path,
features_to_enable: Vec::new(),
})
} else {
Err("Project path must point to the `Cargo.toml` of the project")
@@ -88,6 +90,8 @@ pub struct WasmBuilder {
/// The path to the `Cargo.toml` of the project that should be built
/// for wasm.
project_cargo_toml: PathBuf,
/// Features that should be enabled when building the wasm binary.
features_to_enable: Vec<String>,
}
impl WasmBuilder {
@@ -132,10 +136,20 @@ impl WasmBuilder {
self
}
/// Enable the given feature when building the wasm binary.
///
/// `feature` needs to be a valid feature that is defined in the project `Cargo.toml`.
pub fn enable_feature(mut self, feature: impl Into<String>) -> Self {
self.features_to_enable.push(feature.into());
self
}
/// Build the WASM binary.
pub fn build(self) {
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("`OUT_DIR` is set by cargo!"));
let file_path = out_dir.join(self.file_name.unwrap_or_else(|| "wasm_binary.rs".into()));
let file_path = out_dir.join(
self.file_name.clone().unwrap_or_else(|| "wasm_binary.rs".into()),
);
if check_skip_build() {
// If we skip the build, we still want to make sure to be called when an env variable
@@ -151,6 +165,8 @@ impl WasmBuilder {
file_path,
self.project_cargo_toml,
self.rust_flags.into_iter().map(|f| format!("{} ", f)).collect(),
self.features_to_enable,
self.file_name,
);
// As last step we need to generate our `rerun-if-changed` stuff. If a build fails, we don't
@@ -200,10 +216,15 @@ fn generate_rerun_if_changed_instructions() {
/// constant `WASM_BINARY`, which contains the built WASM binary.
/// `project_cargo_toml` - The path to the `Cargo.toml` of the project that should be built.
/// `default_rustflags` - Default `RUSTFLAGS` that will always be set for the build.
/// `features_to_enable` - Features that should be enabled for the project.
/// `wasm_binary_name` - The optional wasm binary name that is extended with `.compact.wasm`.
/// If `None`, the project name will be used.
fn build_project(
file_name: PathBuf,
project_cargo_toml: PathBuf,
default_rustflags: String,
features_to_enable: Vec<String>,
wasm_binary_name: Option<String>,
) {
let cargo_cmd = match crate::prerequisites::check() {
Ok(cmd) => cmd,
@@ -217,6 +238,8 @@ fn build_project(
&project_cargo_toml,
&default_rustflags,
cargo_cmd,
features_to_enable,
wasm_binary_name,
);
let (wasm_binary, wasm_binary_bloaty) = if let Some(wasm_binary) = wasm_binary {