Skip to content

Commit 6562df3

Browse files
committed
Fix packaging and remove assertions
1 parent f88c271 commit 6562df3

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

pkg_swift_llvm.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def getoptions():
3434

3535
REQUIRED_CMAKE_PACKAGES = ["LLVM", "Clang", "Swift", "SwiftSyntax"]
3636

37+
EXPORTED_LIB = "CodeQLSwiftFrontendTool"
38+
3739
Libs = namedtuple("Libs", ("static", "shared", "linker_flags"))
3840

3941

@@ -87,13 +89,10 @@ def get_libs(configured):
8789
ret = Libs([], [], [])
8890
for l in libs:
8991
if l.endswith(".a"):
90-
ret.static.append((configured / l).resolve())
92+
ret.static.append((configured / l).absolute())
9193
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")):
9796
ret.linker_flags.append(l)
9897
else:
9998
raise ValueError(f"cannot understand link.txt: " + l)
@@ -103,11 +102,26 @@ def get_libs(configured):
103102
def get_tgt(tgt, filename):
104103
if tgt.is_dir():
105104
tgt /= filename
106-
return tgt.resolve()
105+
return tgt.absolute()
106+
107107

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}\nsave\nend"
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
108122

109123
def copy_includes(src, tgt):
110-
print("copying includes")
124+
print(f"copying includes from {src}")
111125
for dir, exts in (("include", ("h", "def", "inc")), ("stdlib", ("h",))):
112126
srcdir = src / dir
113127
for ext in exts:
@@ -128,8 +142,8 @@ def export_sdk(tgt, swift_source_tree, swift_build_tree):
128142
srcdir /= "macosx"
129143
for mod in srcdir.glob("*.swiftmodule"):
130144
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",
133147
ignore=shutil.ignore_patterns('CMakeLists.txt'))
134148

135149

@@ -157,10 +171,11 @@ def export_stdlibs(exported_dir, swift_build_tree):
157171

158172
def export_libs(exported_dir, libs, swift_build_tree):
159173
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)
164179
export_stdlibs(exported_dir, swift_build_tree)
165180

166181

swift-build-presets

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ skip-build-android
2828
enable-experimental-string-processing
2929
swift-enable-experimental-string-processing=1
3030

31+
no-assertions
32+
33+
reconfigure
34+
3135
[preset: codeql]
3236
mixin-preset=codeql-baseline
3337
release
@@ -37,4 +41,3 @@ build-subdir=codeql
3741
mixin-preset=codeql-baseline
3842
debug
3943
build-subdir=codeql-debug
40-

0 commit comments

Comments
 (0)