@@ -220,7 +220,6 @@ def processDeps(self, deps):
220
220
"_benchmarkSetupEach" ,
221
221
"_benchmarkTeardownEach" ,
222
222
"_benchmarkRun" ,
223
- "_main"
224
223
]
225
224
226
225
@@ -446,6 +445,17 @@ def __str__(self):
446
445
def benchmark_methods (self ):
447
446
return benchmark_methods
448
447
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
+
449
459
def build (self ):
450
460
source_dir = self .subject .getSourceDir ()
451
461
output_dir = self .subject .getOutputDir ()
@@ -469,9 +479,7 @@ def build(self):
469
479
include_flags = []
470
480
if hasattr (self .project , "includeset" ):
471
481
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
475
483
subdir_program_names = defaultdict (lambda : [])
476
484
for root , filename in self .subject .getProgramSources ():
477
485
if filename .startswith ("_" ):
@@ -489,12 +497,27 @@ def build(self):
489
497
timestampedOutput = mx .TimeStampFile (output_wasm_path )
490
498
mustRebuild = timestampedSource .isNewerThan (timestampedOutput ) or not timestampedOutput .exists ()
491
499
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
+
492
511
# Step 1: build the .wasm binary.
493
512
if mustRebuild :
494
513
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 ("'" , "\" " ) + "" ]
495
518
# This generates both a js file and a wasm file.
496
519
# 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
498
521
if mx .run (build_cmd_line , nonZeroIsFatal = False ) != 0 :
499
522
mx .abort ("Could not build the wasm-only output of " + filename + " with emcc." )
500
523
elif filename .endswith (".wat" ):
@@ -533,11 +556,11 @@ def build(self):
533
556
534
557
# Step 5: if this is a benchmark project, create native binaries too.
535
558
if mustRebuild :
536
- if filename .endswith (".c" ):
559
+ if filename .endswith (".c" ) and native_bench :
537
560
mx_util .ensure_dir_exists (os .path .join (output_dir , subdir , NATIVE_BENCH_DIR ))
538
561
output_path = os .path .join (output_dir , subdir , NATIVE_BENCH_DIR , mx .exe_suffix (basename ))
539
562
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
541
564
if mx .run (gcc_cmd_line , nonZeroIsFatal = False ) != 0 :
542
565
mx .abort ("Could not build the native binary of " + filename + "." )
543
566
os .chmod (output_path , stat .S_IRUSR | stat .S_IWUSR | stat .S_IXUSR )
@@ -642,10 +665,10 @@ def emscripten_init(args):
642
665
config_path = os .path .join (os .getcwd (), args .config_path )
643
666
emsdk_path = args .emsdk_path
644
667
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" )
649
672
650
673
def find_executable (exe_name ):
651
674
for root , _ , files in os .walk (args .emsdk_path ):
@@ -666,7 +689,7 @@ def find_executable(exe_name):
666
689
llvm_root = os .path .join (emsdk_path , "upstream" , "bin" )
667
690
binaryen_root = os .path .join (emsdk_path , "upstream" , "lib" )
668
691
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" )
670
693
671
694
mx .log ("Generating Emscripten configuration..." )
672
695
mx .log ("Config file path: " + str (config_path ))
0 commit comments