@@ -34,7 +34,7 @@ def getoptions():
34
34
return opts
35
35
36
36
37
- Libs = namedtuple ("Libs" , ("archive" , " static" , "shared" , "linker_flags" ))
37
+ Libs = namedtuple ("Libs" , ("static" , "shared" , "linker_flags" ))
38
38
39
39
EXPORTED_LIB = "CodeQLSwiftFrontendTool"
40
40
@@ -74,11 +74,11 @@ def get_libs(configured):
74
74
print ("extracting linking information from dummy project" )
75
75
with open (configured / "CMakeFiles" / "codeql-swift-artifacts.dir" / "link.txt" ) as link :
76
76
libs = link .read ().split ()
77
- libs = libs [libs .index ('codeql-swift-artifacts' )+ 1 :] # skip up to -o dummy
78
- ret = Libs ([], [], [], [] )
77
+ libs = libs [libs .index ('codeql-swift-artifacts' ) + 1 :] # skip up to -o dummy
78
+ ret = Libs ([], [], [])
79
79
for l in libs :
80
80
if l .endswith (".a" ):
81
- ret .static .append (str (( configured / l ).resolve () ))
81
+ ret .static .append (( configured / l ).resolve ())
82
82
elif l .endswith (".so" ) or l .endswith (".tbd" ) or l .endswith (".dylib" ):
83
83
l = pathlib .Path (l ).stem
84
84
ret .shared .append (f"-l{ l [3 :]} " ) # drop 'lib' prefix and '.so' suffix
@@ -97,55 +97,6 @@ def get_tgt(tgt, filename):
97
97
return tgt .resolve ()
98
98
99
99
100
- def create_static_lib (tgt , libs ):
101
- tgt = get_tgt (tgt , f"lib{ EXPORTED_LIB } .a" )
102
- print (f"packaging { tgt .name } " )
103
- if sys .platform == 'linux' :
104
- includedlibs = "\n " .join (f"addlib { l } " for l in libs .archive + libs .static )
105
- mriscript = f"create { tgt } \n { includedlibs } \n save\n end"
106
- run (["ar" , "-M" ], cwd = tgt .parent , input = mriscript )
107
- else :
108
- libtool_args = ["libtool" , "-static" ]
109
- libtool_args .extend (libs .archive )
110
- libtool_args .extend (libs .static )
111
- libtool_args .append ("-o" )
112
- libtool_args .append (str (tgt ))
113
- run (libtool_args , cwd = tgt .parent )
114
- return tgt
115
-
116
-
117
- def create_shared_lib (tgt , libs ):
118
- ext = "so"
119
- if sys .platform != 'linux' :
120
- ext = "dylib"
121
- libname = f"lib{ EXPORTED_LIB } .{ ext } "
122
- tgt = get_tgt (tgt , libname )
123
- print (f"packaging { libname } " )
124
- compiler = os .environ .get ("CC" , "clang" )
125
- cmd = [compiler , "-shared" ]
126
- cmd .extend (libs .linker_flags )
127
-
128
- if sys .platform == 'linux' :
129
- cmd .append ("-Wl,--whole-archive" )
130
- else :
131
- cmd .append ("-Wl,-all_load" )
132
-
133
- cmd .append (f"-o{ tgt } " )
134
- cmd .extend (libs .archive )
135
-
136
- if sys .platform == 'linux' :
137
- cmd .append ("-Wl,--no-whole-archive" )
138
- else :
139
- cmd .append ("-lc++" )
140
-
141
- cmd .extend (libs .static )
142
- cmd .extend (libs .shared )
143
- run (cmd , cwd = tgt .parent )
144
- if sys .platform != "linux" :
145
- run (["install_name_tool" , "-id" , f"@executable_path/{ libname } " , libname ], cwd = tgt .parent )
146
- return tgt
147
-
148
-
149
100
def copy_includes (src , tgt ):
150
101
print ("copying includes" )
151
102
for dir , exts in (("include" , ("h" , "def" , "inc" )), ("stdlib" , ("h" ,))):
@@ -159,7 +110,7 @@ def copy_includes(src, tgt):
159
110
160
111
def export_sdk (tgt , swift_source_tree , swift_build_tree ):
161
112
print ("assembling sdk" )
162
- srcdir = swift_build_tree / "lib" / "swift"
113
+ srcdir = swift_build_tree / "lib" / "swift"
163
114
tgtdir = tgt / "usr" / "lib" / "swift"
164
115
if get_platform () == "linux" :
165
116
srcdir /= "linux"
@@ -181,11 +132,11 @@ def export_stdlibs(exported_dir, swift_build_tree):
181
132
ext = 'so'
182
133
lib_dir = swift_build_tree / 'lib/swift' / platform
183
134
stdlibs = [
184
- f'libswiftCore.{ ext } ' ,
185
- 'libswiftCompatibility50.a' ,
186
- 'libswiftCompatibility51.a' ,
187
- 'libswiftCompatibilityConcurrency.a' ,
188
- 'libswiftCompatibilityDynamicReplacements.a' ]
135
+ f'libswiftCore.{ ext } ' ,
136
+ 'libswiftCompatibility50.a' ,
137
+ 'libswiftCompatibility51.a' ,
138
+ 'libswiftCompatibilityConcurrency.a' ,
139
+ 'libswiftCompatibilityDynamicReplacements.a' ]
189
140
for stdlib in stdlibs :
190
141
lib_path = lib_dir / stdlib
191
142
if lib_path .exists ():
@@ -197,13 +148,8 @@ def export_stdlibs(exported_dir, swift_build_tree):
197
148
198
149
def export_libs (exported_dir , libs , swift_build_tree ):
199
150
print ("exporting libraries" )
200
- exportedlibs = [
201
- create_static_lib (exported_dir , libs ),
202
- create_shared_lib (exported_dir , libs )
203
- ]
204
-
205
- for l in exportedlibs :
206
- l .rename (exported_dir / l .name )
151
+ for i , l in enumerate (libs .static ):
152
+ shutil .copy (l , exported_dir / f"lib{ i :03} { l .name [3 :]} " )
207
153
export_stdlibs (exported_dir , swift_build_tree )
208
154
209
155
@@ -213,10 +159,14 @@ def export_headers(exported_dir, swift_source_tree, llvm_build_tree, swift_build
213
159
llvm_source_tree = swift_source_tree .parent / 'llvm-project/llvm'
214
160
clang_source_tree = swift_source_tree .parent / 'llvm-project/clang'
215
161
clang_tools_build_tree = llvm_build_tree / 'tools/clang'
216
- header_dirs = [ llvm_source_tree , clang_source_tree , swift_source_tree , llvm_build_tree , swift_build_tree , clang_tools_build_tree ]
162
+ header_dirs = [llvm_source_tree , clang_source_tree , swift_source_tree , llvm_build_tree , swift_build_tree ,
163
+ clang_tools_build_tree ]
217
164
for h in header_dirs :
218
165
copy_includes (h , exported_dir )
219
166
167
+ def export_frontend (exported_dir , swift_build_tree ):
168
+ print ("exporting swift-frontend" )
169
+ shutil .copy (swift_build_tree / 'bin' / 'swift-frontend' , exported_dir )
220
170
221
171
def zip_dir (src , tgt ):
222
172
tgt = get_tgt (tgt , f"swift-prebuilt-{ get_platform ()} .zip" )
@@ -238,10 +188,9 @@ def main(opts):
238
188
export_libs (exported , libs , opts .swift_build_tree )
239
189
export_headers (exported , opts .swift_source_tree , opts .llvm_build_tree , opts .swift_build_tree )
240
190
export_sdk (exported / "sdk" , opts .swift_source_tree , opts .swift_build_tree )
241
-
191
+ export_frontend ( exported , opts . swift_build_tree )
242
192
zip_dir (exported , opts .output )
243
193
244
194
245
195
if __name__ == "__main__" :
246
196
main (getoptions ())
247
-
0 commit comments