mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 04:41:02 +00:00
Make RUSTFLAGS configurable in wasm-builder (#3057)
* Make `RUSTFLAGS` configurable in `wasm-builder` * Version ups * Update `Cargo.lock`
This commit is contained in:
committed by
Gavin Wood
parent
3a002a9100
commit
29311e98b4
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "substrate-wasm-builder-runner"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
description = "Runner for substrate-wasm-builder"
|
||||
edition = "2018"
|
||||
|
||||
@@ -30,6 +30,9 @@ use std::{env, process::{Command, self}, 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 to extend the `RUSTFLAGS` variable given to the WASM build.
|
||||
const WASM_BUILD_RUSTFLAGS_ENV: &str = "WASM_BUILD_RUSTFLAGS";
|
||||
|
||||
/// Environment variable that tells us to create a dummy WASM binary.
|
||||
///
|
||||
/// This is useful for `cargo check` to speed-up the compilation.
|
||||
@@ -93,6 +96,20 @@ impl WasmBuilderSource {
|
||||
}
|
||||
}
|
||||
|
||||
/// Build the currently built project as WASM binary and extend `RUSTFLAGS` with the given rustflags.
|
||||
///
|
||||
/// For more information, see [`build_current_project`].
|
||||
pub fn build_current_project_with_rustflags(
|
||||
file_name: &str,
|
||||
wasm_builder_source: WasmBuilderSource,
|
||||
rustflags: &str,
|
||||
) {
|
||||
let given_rustflags = env::var(WASM_BUILD_RUSTFLAGS_ENV).unwrap_or_default();
|
||||
env::set_var(WASM_BUILD_RUSTFLAGS_ENV, format!("{} {}", given_rustflags, rustflags));
|
||||
|
||||
build_current_project(file_name, wasm_builder_source)
|
||||
}
|
||||
|
||||
/// Build the currently built project as WASM binary.
|
||||
///
|
||||
/// The current project is determined using the `CARGO_MANIFEST_DIR` environment variable.
|
||||
|
||||
@@ -49,6 +49,7 @@ By using environment variables, you can configure which WASM binaries are built
|
||||
- `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.
|
||||
- `WASM_BUILD_RUSTFLAGS` - Extend `RUSTFLAGS` given to `cargo build` while building the WASM binary.
|
||||
|
||||
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
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
//! - `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.
|
||||
//! - `WASM_BUILD_RUSTFLAGS` - Extend `RUSTFLAGS` given to `cargo build` while building the WASM binary.
|
||||
//!
|
||||
//! 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
|
||||
@@ -92,6 +93,9 @@ const SKIP_BUILD_ENV: &str = "SKIP_WASM_BUILD";
|
||||
/// By default the WASM binary uses the same build type as the main cargo build.
|
||||
const WASM_BUILD_TYPE_ENV: &str = "WASM_BUILD_TYPE";
|
||||
|
||||
/// Environment variable to extend the `RUSTFLAGS` variable given to the WASM build.
|
||||
const WASM_BUILD_RUSTFLAGS_ENV: &str = "WASM_BUILD_RUSTFLAGS";
|
||||
|
||||
/// Build the currently built project as WASM binary.
|
||||
///
|
||||
/// The current project is determined by using the `CARGO_MANIFEST_DIR` environment variable.
|
||||
|
||||
@@ -227,12 +227,7 @@ fn create_project(cargo_manifest: &Path, wasm_workspace: &Path) -> PathBuf {
|
||||
|
||||
fs::write(
|
||||
project_folder.join("src/lib.rs"),
|
||||
format!(
|
||||
r#"
|
||||
#![no_std]
|
||||
pub use wasm_project::*;
|
||||
"#
|
||||
)
|
||||
"#![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) {
|
||||
@@ -265,9 +260,15 @@ fn is_release_build() -> bool {
|
||||
fn build_project(project: &Path) {
|
||||
let manifest_path = project.join("Cargo.toml");
|
||||
let mut build_cmd = crate::get_nightly_cargo();
|
||||
|
||||
let rustflags = format!(
|
||||
"-C link-arg=--export-table {}",
|
||||
env::var(crate::WASM_BUILD_RUSTFLAGS_ENV).unwrap_or_default(),
|
||||
);
|
||||
|
||||
build_cmd.args(&["build", "--target=wasm32-unknown-unknown"])
|
||||
.arg(format!("--manifest-path={}", manifest_path.display()))
|
||||
.env("RUSTFLAGS", "-C link-arg=--export-table")
|
||||
.env("RUSTFLAGS", rustflags)
|
||||
// We don't want to call ourselves recursively
|
||||
.env(crate::SKIP_BUILD_ENV, "");
|
||||
|
||||
@@ -347,4 +348,5 @@ fn generate_rerun_if_changed_instructions(
|
||||
// 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);
|
||||
println!("cargo:rerun-if-env-changed={}", crate::WASM_BUILD_RUSTFLAGS_ENV);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user