@@ -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
4650impl 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
0 commit comments