@@ -24,6 +24,7 @@ pub fn build_bin(config: &Config, args: &BuildArgs) -> anyhow::Result<()> {
2424 Lang :: Go => build_go ( config) ,
2525 Lang :: Rust => build_rust ( config) ,
2626 Lang :: Zig => build_zig ( config) ,
27+ Lang :: AS => build_as ( config) ,
2728 Lang :: TS => build_ts ( config) ,
2829 Lang :: C => build_c ( config) ,
2930 Lang :: Cpp => build_cpp ( config) ,
@@ -63,6 +64,15 @@ fn detect_lang(root: &Path) -> anyhow::Result<Lang> {
6364 if root. join ( "build.zig.zon" ) . exists ( ) {
6465 return Ok ( Lang :: Zig ) ;
6566 }
67+ if root. join ( "asconfig.json" ) . exists ( ) {
68+ return Ok ( Lang :: AS ) ;
69+ }
70+ if root. join ( "assembly" ) . join ( "index.ts" ) . exists ( ) {
71+ return Ok ( Lang :: AS ) ;
72+ }
73+ if root. join ( "assembly" ) . join ( "tsconfig.json" ) . exists ( ) {
74+ return Ok ( Lang :: AS ) ;
75+ }
6676 if root. join ( "package.json" ) . exists ( ) {
6777 return Ok ( Lang :: TS ) ;
6878 }
@@ -390,6 +400,38 @@ fn build_lua(config: &Config) -> anyhow::Result<()> {
390400 Ok ( ( ) )
391401}
392402
403+ fn build_as ( config : & Config ) -> anyhow:: Result < ( ) > {
404+ check_installed ( "AssemblyScript" , "npx" , "--version" ) ?;
405+ let mut cmd_args = vec ! [
406+ "asc" ,
407+ "assembly" ,
408+ "--use" ,
409+ "abort=~lib/firefly-as/assembly/stubs/handleAbort" ,
410+ "--outFile" ,
411+ "main.wasm" ,
412+ ] ;
413+ if let Some ( additional_args) = & config. compile_args {
414+ for arg in additional_args {
415+ cmd_args. push ( arg. as_str ( ) ) ;
416+ }
417+ } else {
418+ cmd_args. push ( "--optimize" ) ;
419+ cmd_args. push ( "--noAssert" ) ;
420+ }
421+ let output = Command :: new ( "npx" )
422+ . args ( cmd_args)
423+ . current_dir ( & config. root_path )
424+ . output ( )
425+ . context ( "run asc assembly" ) ?;
426+ check_output ( & output) ?;
427+
428+ let from_path = config. root_path . join ( "main.wasm" ) ;
429+ let out_path = config. rom_path . join ( BIN ) ;
430+ std:: fs:: copy ( & from_path, out_path) . context ( "copy wasm binary" ) ?;
431+ std:: fs:: remove_file ( from_path) . context ( "remove wasm file" ) ?;
432+ Ok ( ( ) )
433+ }
434+
393435fn build_ts ( _config : & Config ) -> anyhow:: Result < ( ) > {
394436 todo ! ( "TypeScript is not supported yet" )
395437}
0 commit comments