Skip to content
Open
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 44 additions & 6 deletions crates/wash/src/cli/component_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ pub struct ComponentBuildCommand {
/// Skip fetching WIT dependencies, useful for offline builds
#[clap(long = "skip-fetch")]
skip_fetch: bool,

/// Additional arguments to pass to the native build tool after '--'.
/// Example: wash build -- --release --features extra
#[clap(name = "arg", trailing_var_arg = true, allow_hyphen_values = true)]
pub args: Vec<String>,
}

impl CliCommand for ComponentBuildCommand {
Expand All @@ -57,6 +62,16 @@ impl CliCommand for ComponentBuildCommand {
..Default::default()
})
}
if !self.args.is_empty() {
if let Some(build) = config.build.as_mut() {
build.additional_args = self.args.clone();
} else {
config.build = Some(crate::component_build::BuildConfig {
additional_args: self.args.clone(),
..Default::default()
});
}
}
let result = build_component(&self.project_path, ctx, &config).await?;

Ok(CommandOutput::ok(
Expand Down Expand Up @@ -542,8 +557,15 @@ impl ComponentBuilder {
// Build cargo command arguments
let mut cargo_args = vec!["build".to_string()];

let release_mode = rust_config.release
|| config
.build
.as_ref()
.map(|b| b.additional_args.iter().any(|arg| arg == "--release"))
.unwrap_or(false);

// Apply release mode if configured
if rust_config.release {
if release_mode {
cargo_args.push("--release".to_string());
}

Expand Down Expand Up @@ -576,6 +598,14 @@ impl ComponentBuilder {
cargo_args.push(flag.clone());
}

if let Some(build_config) = &config.build {
for arg in &build_config.additional_args {
if arg != "--release" {
cargo_args.push(arg.clone());
}
}
}

debug!(cargo_args = ?cargo_args, "running cargo with args");

// Change to project directory and run cargo build
Expand Down Expand Up @@ -619,11 +649,7 @@ impl ComponentBuilder {
}

// Find the generated wasm file
let build_type = if rust_config.release {
"release"
} else {
"debug"
};
let build_type = if release_mode { "release" } else { "debug" };
let target_dir = self
.project_path
.join(format!("target/{}/{}", rust_config.target, build_type));
Expand Down Expand Up @@ -791,6 +817,12 @@ impl ComponentBuilder {
tinygo_args.push(flag.to_string());
}

if let Some(build_config) = &config.build {
for arg in &build_config.additional_args {
tinygo_args.push(arg.clone());
}
}

// Add source directory
tinygo_args.push(".".to_string());

Expand Down Expand Up @@ -958,6 +990,12 @@ impl ComponentBuilder {
build_args.push(flag.clone());
}

if let Some(build_config) = &config.build {
for arg in &build_config.additional_args {
build_args.push(arg.clone());
}
}

debug!(package_manager = %package_manager, build_args = ?build_args, "running build command");

// Run package manager build command
Expand Down
4 changes: 2 additions & 2 deletions crates/wash/src/cli/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub struct TestCommand {
name = "arg",
conflicts_with = "type",
trailing_var_arg = true,
// TODO: --help won't get collected into this args
allow_hyphen_values = true
)]
pub args: Vec<String>,
}
Expand Down Expand Up @@ -394,7 +394,7 @@ impl TestCommand {
plugin_component: Some(plugin),
};

output.push_str(component_plugin_command.handle(ctx).await?.message.as_str());
output = component_plugin_command.handle(ctx).await?.message;
}

Ok(CommandOutput::ok(
Expand Down
4 changes: 4 additions & 0 deletions crates/wash/src/component_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ pub struct BuildConfig {
/// Expected path to the built Wasm component artifact
#[serde(skip_serializing_if = "Option::is_none")]
pub component_path: Option<PathBuf>,

/// Additional arguments to pass to the build toolchain (cargo, tinygo, npm)
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub additional_args: Vec<String>,
}

/// Types of projects that can be built
Expand Down