@@ -14,12 +14,20 @@ def run(arguments):
14
14
print ("Running: " + " " .join (arguments ))
15
15
subprocess .run (arguments , check = True )
16
16
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
+
17
25
def main ():
18
26
import argparse
19
27
parser = argparse .ArgumentParser ()
20
28
parser .add_argument ("-o" , "--output" , required = True )
21
29
parser .add_argument ("extra_build_args" , nargs = "*" )
22
-
30
+
23
31
args = parser .parse_args ()
24
32
25
33
build_args = ["swift" , "build" , "-c" , "release" , "--product" , "wasmkit-cli" , "--package-path" , SOURCE_ROOT ] + args .extra_build_args
@@ -33,13 +41,20 @@ def main():
33
41
shutil .rmtree (archive_path , ignore_errors = True )
34
42
os .makedirs (archive_path )
35
43
44
+ src_exe_path = os .path .join (bin_path , "wasmkit-cli" )
36
45
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 )
38
53
39
54
with tarfile .open (args .output , "w:gz" ) as tar :
40
55
tar .add (archive_path , arcname = os .path .basename (archive_path ))
41
56
42
57
print (f"Release binary is available at { args .output } " )
43
58
44
59
if __name__ == "__main__" :
45
- main ()
60
+ main ()
0 commit comments