@@ -14,12 +14,20 @@ def run(arguments):
1414 print ("Running: " + " " .join (arguments ))
1515 subprocess .run (arguments , check = True )
1616
17+
18+ def is_elf (file_path ):
19+ """Check if the file is an ELF binary."""
20+ with open (file_path , 'rb' ) as f :
21+ header = f .read (4 )
22+ return header == b'\x7f ELF'
23+
24+
1725def main ():
1826 import argparse
1927 parser = argparse .ArgumentParser ()
2028 parser .add_argument ("-o" , "--output" , required = True )
2129 parser .add_argument ("extra_build_args" , nargs = "*" )
22-
30+
2331 args = parser .parse_args ()
2432
2533 build_args = ["swift" , "build" , "-c" , "release" , "--product" , "wasmkit-cli" , "--package-path" , SOURCE_ROOT ] + args .extra_build_args
@@ -33,13 +41,20 @@ def main():
3341 shutil .rmtree (archive_path , ignore_errors = True )
3442 os .makedirs (archive_path )
3543
44+ src_exe_path = os .path .join (bin_path , "wasmkit-cli" )
3645 dest_exe_path = os .path .join (archive_path , "wasmkit" )
37- shutil .copy (os .path .join (bin_path , "wasmkit-cli" ), dest_exe_path )
46+ if is_elf (src_exe_path ):
47+ # For ELF binaries, use strip to remove debug symbols because
48+ # most of static archives in static linux Swift SDK contains
49+ # debug sections.
50+ run (["strip" , src_exe_path , "--strip-debug" , "-o" , dest_exe_path ])
51+ else :
52+ shutil .copy (src_exe_path , dest_exe_path )
3853
3954 with tarfile .open (args .output , "w:gz" ) as tar :
4055 tar .add (archive_path , arcname = os .path .basename (archive_path ))
4156
4257 print (f"Release binary is available at { args .output } " )
4358
4459if __name__ == "__main__" :
45- main ()
60+ main ()
0 commit comments