Skip to content

Commit bfa8c3b

Browse files
brooksmtownsendricochet
authored andcommitted
feat(build): support additional build toolchain args
Signed-off-by: Brooks Townsend <brooks@cosmonic.com>
1 parent b2f00b2 commit bfa8c3b

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

crates/wash/src/cli/component_build.rs

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ pub struct ComponentBuildCommand {
4141
/// Skip fetching WIT dependencies, useful for offline builds
4242
#[clap(long = "skip-fetch")]
4343
skip_fetch: bool,
44+
45+
/// The arguments to pass to the native build tool (cargo, tinygo, npm, etc.)
46+
#[clap(name = "arg", trailing_var_arg = true, allow_hyphen_values = true)]
47+
pub args: Vec<String>,
4448
}
4549

4650
impl CliCommand for ComponentBuildCommand {
@@ -57,6 +61,16 @@ impl CliCommand for ComponentBuildCommand {
5761
..Default::default()
5862
})
5963
}
64+
if let Some(build) = config.build.as_mut() {
65+
if !self.args.is_empty() {
66+
build.additional_args = self.args.clone();
67+
}
68+
} else {
69+
config.build = Some(crate::component_build::BuildConfig {
70+
additional_args: self.args.clone(),
71+
..Default::default()
72+
});
73+
}
6074
let result = build_component(&self.project_path, ctx, &config).await?;
6175

6276
Ok(CommandOutput::ok(
@@ -542,8 +556,15 @@ impl ComponentBuilder {
542556
// Build cargo command arguments
543557
let mut cargo_args = vec!["build".to_string()];
544558

559+
let release_mode = rust_config.release
560+
|| config
561+
.build
562+
.as_ref()
563+
.map(|b| b.additional_args.contains(&"--release".to_string()))
564+
.unwrap_or(false);
565+
545566
// Apply release mode if configured
546-
if rust_config.release {
567+
if release_mode {
547568
cargo_args.push("--release".to_string());
548569
}
549570

@@ -576,6 +597,14 @@ impl ComponentBuilder {
576597
cargo_args.push(flag.clone());
577598
}
578599

600+
if let Some(build_config) = &config.build {
601+
for arg in &build_config.additional_args {
602+
if arg != "--release" {
603+
cargo_args.push(arg.clone());
604+
}
605+
}
606+
}
607+
579608
debug!(cargo_args = ?cargo_args, "running cargo with args");
580609

581610
// Change to project directory and run cargo build
@@ -619,11 +648,7 @@ impl ComponentBuilder {
619648
}
620649

621650
// Find the generated wasm file
622-
let build_type = if rust_config.release {
623-
"release"
624-
} else {
625-
"debug"
626-
};
651+
let build_type = if release_mode { "release" } else { "debug" };
627652
let target_dir = self
628653
.project_path
629654
.join(format!("target/{}/{}", rust_config.target, build_type));
@@ -791,6 +816,12 @@ impl ComponentBuilder {
791816
tinygo_args.push(flag.to_string());
792817
}
793818

819+
if let Some(build_config) = &config.build {
820+
for arg in &build_config.additional_args {
821+
tinygo_args.push(arg.clone());
822+
}
823+
}
824+
794825
// Add source directory
795826
tinygo_args.push(".".to_string());
796827

@@ -958,6 +989,12 @@ impl ComponentBuilder {
958989
build_args.push(flag.clone());
959990
}
960991

992+
if let Some(build_config) = &config.build {
993+
for arg in &build_config.additional_args {
994+
build_args.push(arg.clone());
995+
}
996+
}
997+
961998
debug!(package_manager = %package_manager, build_args = ?build_args, "running build command");
962999

9631000
// Run package manager build command

crates/wash/src/cli/plugin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub struct TestCommand {
196196
name = "arg",
197197
conflicts_with = "type",
198198
trailing_var_arg = true,
199-
// TODO: --help won't get collected into this args
199+
allow_hyphen_values = true
200200
)]
201201
pub args: Vec<String>,
202202
}
@@ -383,7 +383,7 @@ impl TestCommand {
383383
) =>
384384
{
385385
let _ = e.print();
386-
return Ok(CommandOutput::error(e.to_string(), None));
386+
return Ok(CommandOutput::error("", None));
387387
}
388388
Err(e) => anyhow::bail!("Failed to parse command arguments: {}", e),
389389
};
@@ -394,7 +394,7 @@ impl TestCommand {
394394
plugin_component: Some(plugin),
395395
};
396396

397-
output.push_str(component_plugin_command.handle(ctx).await?.message.as_str());
397+
output = component_plugin_command.handle(ctx).await?.message;
398398
}
399399

400400
Ok(CommandOutput::ok(

crates/wash/src/component_build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ pub struct BuildConfig {
2323
/// Expected path to the built Wasm component artifact
2424
#[serde(skip_serializing_if = "Option::is_none")]
2525
pub component_path: Option<PathBuf>,
26+
27+
#[serde(skip_serializing_if = "Vec::is_empty", default)]
28+
pub additional_args: Vec<String>,
2629
}
2730

2831
/// Types of projects that can be built

0 commit comments

Comments
 (0)