1- use crate :: componentize;
1+ use crate :: { bindings :: generate_bindings , componentize} ;
22use anyhow:: Result ;
33use clap:: { Parser , Subcommand } ;
44use std:: { ffi:: OsString , path:: PathBuf } ;
@@ -48,6 +48,9 @@ pub struct Common {
4848pub enum Command {
4949 /// Build a Go WebAssembly component.
5050 Componentize ( Componentize ) ,
51+
52+ /// Generate Go bindings for the world.
53+ Bindings ( Bindings ) ,
5154}
5255
5356#[ derive( Parser ) ]
@@ -69,9 +72,19 @@ pub fn run<T: Into<OsString> + Clone, I: IntoIterator<Item = T>>(args: I) -> Res
6972 let options = Options :: parse_from ( args) ;
7073 match options. command {
7174 Command :: Componentize ( opts) => componentize ( options. common , opts) ,
75+ Command :: Bindings ( opts) => bindings ( options. common , opts) ,
7276 }
7377}
7478
79+ #[ derive( Parser ) ]
80+ pub struct Bindings {
81+ /// Output directory for bindings (or current directory if `None`).
82+ ///
83+ /// This will be created if it does not already exist.
84+ #[ arg( long, short = 'o' ) ]
85+ pub output : Option < PathBuf > ,
86+ }
87+
7588fn componentize ( common : Common , componentize : Componentize ) -> Result < ( ) > {
7689 // Step 1: Build a WebAssembly core module using Go.
7790 let core_module = componentize:: build_wasm_core_module (
@@ -93,3 +106,13 @@ fn componentize(common: Common, componentize: Componentize) -> Result<()> {
93106 componentize:: core_module_to_component ( & core_module) ?;
94107 Ok ( ( ) )
95108}
109+
110+ fn bindings ( common : Common , bindings : Bindings ) -> Result < ( ) > {
111+ generate_bindings (
112+ common. wit_path . as_ref ( ) ,
113+ common. world . as_deref ( ) ,
114+ & common. features ,
115+ common. all_features ,
116+ bindings. output . as_deref ( ) ,
117+ )
118+ }
0 commit comments