@@ -28,6 +28,7 @@ pub fn build_bin(config: &Config, args: &BuildArgs) -> anyhow::Result<()> {
2828 Lang :: C => build_c ( config) ,
2929 Lang :: Cpp => build_cpp ( config) ,
3030 Lang :: Python => build_python ( config) ,
31+ Lang :: Moon => build_moon ( config) ,
3132 } ?;
3233 let bin_path = config. rom_path . join ( BIN ) ;
3334 if !bin_path. is_file ( ) {
@@ -65,6 +66,9 @@ fn detect_lang(root: &Path) -> anyhow::Result<Lang> {
6566 if root. join ( "pyproject.toml" ) . exists ( ) {
6667 return Ok ( Lang :: Python ) ;
6768 }
69+ if root. join ( "moon.pkg.json" ) . exists ( ) {
70+ return Ok ( Lang :: Moon ) ;
71+ }
6872 if root. join ( "main.c" ) . exists ( ) {
6973 return Ok ( Lang :: C ) ;
7074 }
@@ -308,6 +312,7 @@ fn find_wasi_sdk() -> anyhow::Result<PathBuf> {
308312 Ok ( path)
309313}
310314
315+ // Build Zig project.
311316fn build_zig ( config : & Config ) -> anyhow:: Result < ( ) > {
312317 check_installed ( "Zig" , "zig" , "version" ) ?;
313318 let mut cmd_args = vec ! [ "build" ] ;
@@ -331,6 +336,43 @@ fn build_zig(config: &Config) -> anyhow::Result<()> {
331336 Ok ( ( ) )
332337}
333338
339+ // Build Moon project.
340+ fn build_moon ( config : & Config ) -> anyhow:: Result < ( ) > {
341+ check_installed ( "Moon" , "moon" , "version" ) ?;
342+ let mut cmd_args = vec ! [ "build" , "--target" , "wasm" ] ;
343+ if let Some ( additional_args) = & config. compile_args {
344+ for arg in additional_args {
345+ cmd_args. push ( arg. as_str ( ) ) ;
346+ }
347+ }
348+ let output = Command :: new ( "moon" )
349+ . args ( cmd_args)
350+ . current_dir ( & config. root_path )
351+ . output ( )
352+ . context ( "run moon build" ) ?;
353+ check_output ( & output) ?;
354+
355+ let from_dir = config
356+ . root_path
357+ . join ( "target" )
358+ . join ( "wasm" )
359+ . join ( "release" )
360+ . join ( "build" ) ;
361+ let from_path = find_wasm ( & from_dir) ?;
362+ let out_path = config. rom_path . join ( BIN ) ;
363+ std:: fs:: copy ( & from_path, out_path) . context ( "copy wasm binary" ) ?;
364+ std:: fs:: remove_file ( from_path) . context ( "remove wasm file" ) ?;
365+ Ok ( ( ) )
366+ }
367+
368+ fn build_ts ( _config : & Config ) -> anyhow:: Result < ( ) > {
369+ todo ! ( "TypeScript is not supported yet" )
370+ }
371+
372+ fn build_python ( _config : & Config ) -> anyhow:: Result < ( ) > {
373+ todo ! ( "Python is not supported yet" )
374+ }
375+
334376/// Find a wasm binary in the given directory.
335377fn find_wasm ( from_dir : & Path ) -> anyhow:: Result < PathBuf > {
336378 let from_dir = std:: fs:: read_dir ( from_dir) ?;
@@ -353,14 +395,6 @@ fn find_wasm(from_dir: &Path) -> anyhow::Result<PathBuf> {
353395 }
354396}
355397
356- fn build_ts ( _config : & Config ) -> anyhow:: Result < ( ) > {
357- todo ! ( "TypeScript is not supported yet" )
358- }
359-
360- fn build_python ( _config : & Config ) -> anyhow:: Result < ( ) > {
361- todo ! ( "Python is not supported yet" )
362- }
363-
364398/// Convert a file system path to UTF-8 if possible.
365399pub fn path_to_utf8 ( path : & Path ) -> anyhow:: Result < & str > {
366400 match path. to_str ( ) {
0 commit comments