@@ -220,7 +220,6 @@ def processDeps(self, deps):
220220 "_benchmarkSetupEach" ,
221221 "_benchmarkTeardownEach" ,
222222 "_benchmarkRun" ,
223- "_main"
224223]
225224
226225
@@ -446,6 +445,17 @@ def __str__(self):
446445 def benchmark_methods (self ):
447446 return benchmark_methods
448447
448+ def test_methods (self , opts_path ):
449+ if not os .path .isfile (opts_path ):
450+ return []
451+ with open (opts_path ) as opts_file :
452+ for line in opts_file :
453+ line = line .strip ()
454+ if line .startswith ("entry-point" ):
455+ _ , value = line .split ("=" , 1 )
456+ return ['_' + value .strip ()]
457+ return []
458+
449459 def build (self ):
450460 source_dir = self .subject .getSourceDir ()
451461 output_dir = self .subject .getOutputDir ()
@@ -469,9 +479,7 @@ def build(self):
469479 include_flags = []
470480 if hasattr (self .project , "includeset" ):
471481 include_flags = ["-I" , os .path .join (_suite .dir , "includes" , self .project .includeset )]
472- emcc_flags = ["-s" , "EXIT_RUNTIME=1" , "-s" , "STANDALONE_WASM" , "-s" , "WASM_BIGINT" ] + cc_flags
473- if self .project .isBenchmarkProject ():
474- emcc_flags = emcc_flags + ["-s" , "EXPORTED_FUNCTIONS=" + str (self .benchmark_methods ()).replace ("'" , "\" " ) + "" ]
482+ emcc_flags = ["-s" , "STANDALONE_WASM" , "-s" , "WASM_BIGINT" ] + cc_flags
475483 subdir_program_names = defaultdict (lambda : [])
476484 for root , filename in self .subject .getProgramSources ():
477485 if filename .startswith ("_" ):
@@ -489,12 +497,27 @@ def build(self):
489497 timestampedOutput = mx .TimeStampFile (output_wasm_path )
490498 mustRebuild = timestampedSource .isNewerThan (timestampedOutput ) or not timestampedOutput .exists ()
491499
500+ source_cc_flags = []
501+ native_bench = True
502+ if filename .endswith (".c" ):
503+ with open (source_path ) as f :
504+ source_file = f .read ()
505+ for flags in re .findall (r'//\s*CFLAGS\s*=\s*(.*)\n' , source_file ):
506+ source_cc_flags .extend (flags .split ())
507+ native_bench_option = re .search (r'//\s*NATIVE_BENCH\s*=\s*(.*)\n' , source_file )
508+ if native_bench_option :
509+ native_bench = native_bench_option .group (1 ).lower () == "true"
510+
492511 # Step 1: build the .wasm binary.
493512 if mustRebuild :
494513 if filename .endswith (".c" ):
514+ if self .project .isBenchmarkProject ():
515+ emcc_export_flags = ["-s" , "EXPORTED_FUNCTIONS=" + str (self .benchmark_methods ()).replace ("'" , "\" " ) + "" ]
516+ else :
517+ emcc_export_flags = ["-s" , "EXPORTED_FUNCTIONS=" + str (self .test_methods (os .path .join (root , basename + ".opts" ))).replace ("'" , "\" " ) + "" ]
495518 # This generates both a js file and a wasm file.
496519 # See https://github.com/emscripten-core/emscripten/wiki/WebAssembly-Standalone
497- build_cmd_line = [emcc_cmd ] + emcc_flags + [source_path , "-o" , output_js_path ] + include_flags
520+ build_cmd_line = [emcc_cmd ] + emcc_flags + emcc_export_flags + source_cc_flags + [source_path , "-o" , output_js_path ] + include_flags
498521 if mx .run (build_cmd_line , nonZeroIsFatal = False ) != 0 :
499522 mx .abort ("Could not build the wasm-only output of " + filename + " with emcc." )
500523 elif filename .endswith (".wat" ):
@@ -533,11 +556,11 @@ def build(self):
533556
534557 # Step 5: if this is a benchmark project, create native binaries too.
535558 if mustRebuild :
536- if filename .endswith (".c" ):
559+ if filename .endswith (".c" ) and native_bench :
537560 mx_util .ensure_dir_exists (os .path .join (output_dir , subdir , NATIVE_BENCH_DIR ))
538561 output_path = os .path .join (output_dir , subdir , NATIVE_BENCH_DIR , mx .exe_suffix (basename ))
539562 link_flags = ["-lm" ]
540- gcc_cmd_line = [gcc_cmd ] + cc_flags + [source_path , "-o" , output_path ] + include_flags + link_flags
563+ gcc_cmd_line = [gcc_cmd ] + cc_flags + source_cc_flags + [source_path , "-o" , output_path ] + include_flags + link_flags
541564 if mx .run (gcc_cmd_line , nonZeroIsFatal = False ) != 0 :
542565 mx .abort ("Could not build the native binary of " + filename + "." )
543566 os .chmod (output_path , stat .S_IRUSR | stat .S_IWUSR | stat .S_IXUSR )
@@ -642,10 +665,10 @@ def emscripten_init(args):
642665 config_path = os .path .join (os .getcwd (), args .config_path )
643666 emsdk_path = args .emsdk_path
644667
645- llvm_root = os .path .join (emsdk_path , "llvm" , "git" , "build_master_64 " , "bin" )
646- binaryen_root = os .path .join (emsdk_path , "binaryen" , "master_64bit_binaryen " )
647- emscripten_root = os .path .join (emsdk_path , "emscripten " , "master " )
648- node_js = os .path .join (emsdk_path , "node" , "12.9.1_64bit " , "bin" , "node" )
668+ llvm_root = os .path .join (emsdk_path , "upstream " , "bin" )
669+ binaryen_root = os .path .join (emsdk_path , "binaryen" , "main_64bit_binaryen " )
670+ emscripten_root = os .path .join (emsdk_path , "upstream " , "emscripten " )
671+ node_js = os .path .join (emsdk_path , "node" , "22.16.0_64bit " , "bin" , "node" )
649672
650673 def find_executable (exe_name ):
651674 for root , _ , files in os .walk (args .emsdk_path ):
@@ -666,7 +689,7 @@ def find_executable(exe_name):
666689 llvm_root = os .path .join (emsdk_path , "upstream" , "bin" )
667690 binaryen_root = os .path .join (emsdk_path , "upstream" , "lib" )
668691 emscripten_root = os .path .join (emsdk_path , "upstream" , "emscripten" )
669- node_js = os .path .join (emsdk_path , "node" , "14.15.5_64bit " , "bin" , "node" )
692+ node_js = os .path .join (emsdk_path , "node" , "22.16.0_64bit " , "bin" , "node" )
670693
671694 mx .log ("Generating Emscripten configuration..." )
672695 mx .log ("Config file path: " + str (config_path ))
0 commit comments