Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions substrate/utils/wasm-builder/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl WasmBuilderSelectProject {
/// is always set by `Cargo` in `build.rs` files.
pub fn with_current_project(self) -> WasmBuilder {
WasmBuilder {
cargo_flags: Vec::new(),
rust_flags: Vec::new(),
file_name: None,
project_cargo_toml: get_manifest_dir().join("Cargo.toml"),
Expand All @@ -73,6 +74,7 @@ impl WasmBuilderSelectProject {

if path.ends_with("Cargo.toml") && path.exists() {
Ok(WasmBuilder {
cargo_flags: Vec::new(),
rust_flags: Vec::new(),
file_name: None,
project_cargo_toml: path,
Expand Down Expand Up @@ -101,6 +103,8 @@ impl WasmBuilderSelectProject {
/// methods of [`WasmBuilder`].
/// 4. Build the WASM binary using [`Self::build`].
pub struct WasmBuilder {
/// Flags that should be appended to `cargo rustc` invocation.
cargo_flags: Vec<String>,
/// Flags that should be appended to `RUST_FLAGS` env variable.
rust_flags: Vec<String>,
/// The name of the file that is being generated in `OUT_DIR`.
Expand Down Expand Up @@ -190,6 +194,14 @@ impl WasmBuilder {
self
}

/// Append the given `flag` to `cargo rustc` invocation.
///
/// `flag` is appended as is, so it needs to be a valid flag.
pub fn append_to_cargo_flags(mut self, flag: impl Into<String>) -> Self {
self.cargo_flags.push(flag.into());
self
}

/// Append the given `flag` to `RUST_FLAGS`.
///
/// `flag` is appended as is, so it needs to be a valid flag.
Expand Down Expand Up @@ -264,6 +276,7 @@ impl WasmBuilder {
target,
file_path,
self.project_cargo_toml,
self.cargo_flags,
self.rust_flags.join(" "),
self.features_to_enable,
self.file_name,
Expand Down Expand Up @@ -340,6 +353,7 @@ fn build_project(
target: RuntimeTarget,
file_name: PathBuf,
project_cargo_toml: PathBuf,
default_cargo_flags: Vec<String>,
default_rustflags: String,
features_to_enable: Vec<String>,
wasm_binary_name: Option<String>,
Expand All @@ -359,6 +373,7 @@ fn build_project(
let (wasm_binary, bloaty) = crate::wasm_project::create_and_compile(
target,
&project_cargo_toml,
&default_cargo_flags,
&default_rustflags,
cargo_cmd,
features_to_enable,
Expand Down
7 changes: 7 additions & 0 deletions substrate/utils/wasm-builder/src/wasm_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ fn crate_metadata(cargo_manifest: &Path) -> Metadata {
pub(crate) fn create_and_compile(
target: RuntimeTarget,
orig_project_cargo_toml: &Path,
default_cargo_flags: &[String],
default_rustflags: &str,
cargo_cmd: CargoCommandVersioned,
features_to_enable: Vec<String>,
Expand Down Expand Up @@ -149,6 +150,7 @@ pub(crate) fn create_and_compile(
target,
&build_config.blob_build_profile,
&project,
default_cargo_flags,
default_rustflags,
cargo_cmd.clone(),
None,
Expand All @@ -160,6 +162,7 @@ pub(crate) fn create_and_compile(
target,
&build_config.blob_build_profile,
&project,
default_cargo_flags,
default_rustflags,
cargo_cmd,
Some(hash),
Expand All @@ -169,6 +172,7 @@ pub(crate) fn create_and_compile(
target,
&build_config.blob_build_profile,
&project,
default_cargo_flags,
default_rustflags,
cargo_cmd,
None,
Expand All @@ -182,6 +186,7 @@ pub(crate) fn create_and_compile(
target,
&build_config.blob_build_profile,
&project,
default_cargo_flags,
default_rustflags,
cargo_cmd,
)
Expand Down Expand Up @@ -827,6 +832,7 @@ fn build_bloaty_blob(
target: RuntimeTarget,
blob_build_profile: &Profile,
project: &Path,
default_cargo_flags: &[String],
default_rustflags: &str,
cargo_cmd: CargoCommandVersioned,
#[cfg(feature = "metadata-hash")] metadata_hash: Option<[u8; 32]>,
Expand Down Expand Up @@ -868,6 +874,7 @@ fn build_bloaty_blob(
.arg("rustc")
.arg(format!("--target={}", target.rustc_target(&cargo_cmd)))
.arg(format!("--manifest-path={}", manifest_path.display()))
.args(default_cargo_flags)
.env("RUSTFLAGS", rustflags)
// Manually set the `CARGO_TARGET_DIR` to prevent a cargo deadlock (cargo locks a target dir
// exclusive). The runner project is created in `CARGO_TARGET_DIR` and executing it will
Expand Down
Loading