@@ -34,6 +34,8 @@ def getoptions():
34
34
35
35
REQUIRED_CMAKE_PACKAGES = ["LLVM" , "Clang" , "Swift" , "SwiftSyntax" ]
36
36
37
+ EXPORTED_LIB = "CodeQLSwiftFrontendTool"
38
+
37
39
Libs = namedtuple ("Libs" , ("static" , "shared" , "linker_flags" ))
38
40
39
41
@@ -87,13 +89,10 @@ def get_libs(configured):
87
89
ret = Libs ([], [], [])
88
90
for l in libs :
89
91
if l .endswith (".a" ):
90
- ret .static .append ((configured / l ).resolve ())
92
+ ret .static .append ((configured / l ).absolute ())
91
93
elif l .endswith (".so" ) or l .endswith (".tbd" ) or l .endswith (".dylib" ):
92
- l = pathlib .Path (l ).stem
93
- ret .shared .append (f"-l{ l [3 :]} " ) # drop 'lib' prefix and '.so' suffix
94
- elif l .startswith ("-l" ):
95
- ret .shared .append (l )
96
- elif l .startswith ("-L" ) or l .startswith ("-Wl" ):
94
+ ret .shared .append ((configured / l ).absolute ())
95
+ elif l .startswith (("-L" , "-Wl" , "-l" )):
97
96
ret .linker_flags .append (l )
98
97
else :
99
98
raise ValueError (f"cannot understand link.txt: " + l )
@@ -103,11 +102,26 @@ def get_libs(configured):
103
102
def get_tgt (tgt , filename ):
104
103
if tgt .is_dir ():
105
104
tgt /= filename
106
- return tgt .resolve ()
105
+ return tgt .absolute ()
106
+
107
107
108
+ def create_static_lib (tgt , libs ):
109
+ tgt = get_tgt (tgt , f"lib{ EXPORTED_LIB } .a" )
110
+ print (f"packaging { tgt .name } " )
111
+ if sys .platform == 'linux' :
112
+ includedlibs = "\n " .join (f"addlib { l } " for l in libs .static )
113
+ mriscript = f"create { tgt } \n { includedlibs } \n save\n end"
114
+ run (["ar" , "-M" ], cwd = tgt .parent , input = mriscript )
115
+ else :
116
+ libtool_args = ["libtool" , "-static" ]
117
+ libtool_args .extend (libs .static )
118
+ libtool_args .append ("-o" )
119
+ libtool_args .append (str (tgt ))
120
+ run (libtool_args , cwd = tgt .parent )
121
+ return tgt
108
122
109
123
def copy_includes (src , tgt ):
110
- print ("copying includes" )
124
+ print (f "copying includes from { src } " )
111
125
for dir , exts in (("include" , ("h" , "def" , "inc" )), ("stdlib" , ("h" ,))):
112
126
srcdir = src / dir
113
127
for ext in exts :
@@ -128,8 +142,8 @@ def export_sdk(tgt, swift_source_tree, swift_build_tree):
128
142
srcdir /= "macosx"
129
143
for mod in srcdir .glob ("*.swiftmodule" ):
130
144
shutil .copytree (mod , tgtdir / mod .name )
131
- shutil .copytree (swift_source_tree / "stdlib" / "public" / "SwiftShims" ,
132
- tgt / "usr" / "include " / "SwiftShims " ,
145
+ shutil .copytree (swift_source_tree / "stdlib" / "public" / "SwiftShims" / "swift" / "shims" ,
146
+ tgt / "usr" / "lib " / "swift" / "shims " ,
133
147
ignore = shutil .ignore_patterns ('CMakeLists.txt' ))
134
148
135
149
@@ -157,10 +171,11 @@ def export_stdlibs(exported_dir, swift_build_tree):
157
171
158
172
def export_libs (exported_dir , libs , swift_build_tree ):
159
173
print ("exporting libraries" )
160
- # index libraries to preserve linking order
161
- for i , lib in enumerate (libs .static ):
162
- assert lib .name .startswith ("lib" )
163
- shutil .copy (lib , exported_dir / f'lib{ i :03} { lib .name [3 :]} ' )
174
+ create_static_lib (exported_dir , libs )
175
+ for lib in libs .shared :
176
+ # export libraries under the build tree (e.g. libSwiftSyntax.so)
177
+ if lib .is_relative_to (swift_build_tree .parent ):
178
+ shutil .copy (lib , exported_dir )
164
179
export_stdlibs (exported_dir , swift_build_tree )
165
180
166
181
0 commit comments