Skip to content

Commit 2e6ecc7

Browse files
package-toolchain: Remove toolchain packaging code
1 parent 0522099 commit 2e6ecc7

File tree

1 file changed

+27
-215
lines changed

1 file changed

+27
-215
lines changed

tools/build/package-toolchain

Lines changed: 27 additions & 215 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import re
99
from typing import Optional
1010
from build_support.actions import Action, ActionRunner, DownloadBaseSnapshotAction, derive_options_from_args
1111
from build_support.platform import PlatformInfo
12-
from build_support.llvm_tools import WASM_SPECIFIC_TOOLS_TO_INSTALL
1312

1413

1514
class SnapshotInfo:
@@ -77,127 +76,6 @@ def copy_libxml2_libs(build_sdk_path, dist_toolchain_path, target_triple):
7776
shutil.copy(os.path.join(lib_dir, lib), dest_path)
7877

7978

80-
class PackageAction(Action):
81-
def __init__(self, options, snapshot_info: SnapshotInfo):
82-
super().__init__(options)
83-
self.snapshot_info = snapshot_info
84-
self.target_triple = "wasm32-unknown-wasi"
85-
86-
def run(self):
87-
import shutil
88-
print('=====> Packaging toolchain {}'.format(self.snapshot_info.toolchain_name))
89-
packaging_dir = os.path.join('..', 'build', 'Packaging')
90-
base_toolchain_path = os.path.join(packaging_dir, 'base-snapshot')
91-
target_toolchain_path = os.path.join(
92-
packaging_dir, 'target-toolchain', self.target_triple)
93-
dist_toolchain_path = os.path.join(packaging_dir, 'dist-toolchain', self.snapshot_info.toolchain_name)
94-
llvm_toolchain_path = os.path.join(packaging_dir, 'llvm-toolchain')
95-
llvm_tools_path = os.path.join('..', 'build', 'llvm-tools')
96-
build_sdk_path = os.path.join('..', 'build-sdk')
97-
98-
shutil.rmtree(os.path.dirname(dist_toolchain_path), ignore_errors=True)
99-
os.makedirs(dist_toolchain_path, exist_ok=True)
100-
print(f"=====> Copying base snapshot {base_toolchain_path} to {dist_toolchain_path}")
101-
self.rsync("-a", base_toolchain_path + "/", dist_toolchain_path)
102-
103-
copy_icu_libs(self.options.scheme, build_sdk_path, target_toolchain_path, self.target_triple)
104-
copy_libxml2_libs(build_sdk_path, target_toolchain_path, self.target_triple)
105-
# Copying target stdlib to dist toolchain, and cross compiler if
106-
# host compiler is built with patches by ourselves.
107-
print(f"=====> Copying target toolchain {target_toolchain_path} to {dist_toolchain_path}")
108-
self.rsync("-a", target_toolchain_path + "/", dist_toolchain_path)
109-
110-
self.install_extra_llvm_tools(llvm_tools_path, base_toolchain_path, dist_toolchain_path)
111-
112-
# FIXME: We now support only legacy driver because the new swift-driver doesn't have hacks for default
113-
# -sdk and forcing -use-static-resource-dir (-static-executable).
114-
# e.g.
115-
# The canonical way to build a static executable is to use -static-executable and specify -sdk because
116-
# we don't have good concensus for the wasi-sysroot layout and the driver should not assume the SDK path.
117-
# $ echo | ./usr/bin/swiftc -target wasm32-unknown-wasi -o /dev/null - -static-executable -sdk ./usr/share/wasi-sysroot
118-
# But we don't want to force users to specify -sdk, so we have a hack in the legacy driver to assume
119-
# the SDK path and pass -static-executable (effectively -use-static-resource-dir).
120-
# $ echo | ./usr/bin/swiftc -target wasm32-unknown-wasi -o /dev/null -
121-
# The new swift-driver doesn't have this hack, so we remove swift-driver from the toolchain for now.
122-
swift_driver_path = os.path.join(dist_toolchain_path, 'usr', 'bin', 'swift-driver')
123-
if os.path.exists(swift_driver_path) and \
124-
(self.options.scheme == 'release-5.9' or \
125-
self.options.scheme == 'release-5.10'):
126-
os.remove(swift_driver_path)
127-
128-
# Select wasi-sysroot
129-
wasi_sysroot_path = derive_wasi_sysroot(self.options, packaging_dir, 'wasm32-wasi')
130-
print("=====> Using wasi-sysroot from {}".format(wasi_sysroot_path))
131-
132-
# Now dist toolchain always has cross compiler regardless of whether
133-
# host compiler is built by ourselves or just downloaded from swift.org
134-
if self.options.scheme in ['release-5.9', 'release-5.10']:
135-
# We still need to distribute custom built cross compiler tools
136-
# for 5.9 and 5.10.
137-
self.make_swift_sdk(
138-
base_toolchain_path,
139-
dist_toolchain_path,
140-
target_toolchain_path,
141-
wasi_sysroot_path,
142-
self.snapshot_info.swift_sdk_name)
143-
144-
shutil.copytree(wasi_sysroot_path, os.path.join(dist_toolchain_path, 'usr', 'share', 'wasi-sysroot'))
145-
146-
def rsync(self, *args):
147-
import subprocess
148-
args = ['rsync'] + list(args)
149-
if self.options.dry_run:
150-
print(' '.join(args))
151-
return
152-
subprocess.check_call(args)
153-
154-
def install_extra_llvm_tools(self, llvm_tools_path, base_toolchain_path, dist_toolchain_path):
155-
import shutil
156-
print(f"=====> Installing extra LLVM tools")
157-
llvm_tools_bin_dir = os.path.join(llvm_tools_path, 'bin')
158-
install_bin_dir = os.path.join(dist_toolchain_path, 'usr', 'bin')
159-
os.makedirs(install_bin_dir, exist_ok=True)
160-
for tool_name in WASM_SPECIFIC_TOOLS_TO_INSTALL:
161-
# Skip installing if the tool already exists
162-
if os.path.exists(os.path.join(base_toolchain_path, 'usr', 'bin', tool_name)):
163-
continue
164-
165-
tool_path = os.path.join(llvm_tools_bin_dir, tool_name)
166-
if os.path.islink(tool_path) and \
167-
os.path.dirname(os.readlink(tool_path)) != "":
168-
# Copy the tool with following the symlink if it points to a file
169-
# that does not beside the symlink
170-
print(f"Copying {tool_path} to {install_bin_dir} (following symlink)")
171-
shutil.copy(tool_path, install_bin_dir, follow_symlinks=True)
172-
else:
173-
# Copy the tool while preserving the symlink
174-
print(f"Copying {tool_path} to {install_bin_dir}")
175-
shutil.copy(tool_path, install_bin_dir, follow_symlinks=False)
176-
177-
# If it's a symlink, copy the direct symlink target too
178-
if os.path.islink(tool_path):
179-
target = os.readlink(tool_path)
180-
if os.path.exists(os.path.join(install_bin_dir, target)):
181-
continue
182-
target_path = os.path.join(llvm_tools_bin_dir, target)
183-
print(f"Copying {target_path} to {install_bin_dir} (target of {tool_path})")
184-
shutil.copy(target_path, install_bin_dir, follow_symlinks=False)
185-
186-
def make_swift_sdk(
187-
self,
188-
base_toolchain_path: str,
189-
host_toolchain_path: Optional[str],
190-
target_toolchain_path: str,
191-
wasi_sysroot_path: str,
192-
swift_sdk_name: str,
193-
):
194-
underlying = PackageSwiftSDKAction(
195-
self.options, self.snapshot_info, base_toolchain_path,
196-
host_toolchain_path, target_toolchain_path, wasi_sysroot_path,
197-
swift_sdk_name, self.target_triple)
198-
underlying.run()
199-
200-
20179
class PackageSwiftSDKAction(Action):
20280
def __init__(
20381
self, options, snapshot_info: SnapshotInfo,
@@ -316,64 +194,6 @@ class PackageSwiftSDKAction(Action):
316194
return info["target"]["triple"]
317195

318196

319-
class DarwinInfoPlistAction(Action):
320-
321-
def __init__(self, options, snapshot_info: SnapshotInfo):
322-
super().__init__(options)
323-
self.snapshot_info = snapshot_info
324-
325-
def run(self):
326-
print('=====> Creating Info.plist')
327-
328-
bundle_prefix="org.swiftwasm"
329-
swift_version = self.swift_version()
330-
darwin_toolchain_display_name_short="Swift for WebAssembly Snapshot"
331-
332-
year, month, day = self.snapshot_info.year, self.snapshot_info.month, self.snapshot_info.day
333-
if self.snapshot_info.daily_snapshot:
334-
darwin_toolchain_version=f"{swift_version}.{year}{month}{day}"
335-
darwin_toolchain_bundle_identifier=f"{bundle_prefix}.{year}{month}{day}"
336-
darwin_toolchain_display_name=f"{darwin_toolchain_display_name_short} {year}-{month}-{day} (a)"
337-
else:
338-
darwin_toolchain_version=f"{swift_version}.9999"
339-
darwin_toolchain_bundle_identifier=f"{bundle_prefix}.dev"
340-
darwin_toolchain_display_name=f"{darwin_toolchain_display_name_short} Development"
341-
342-
darwin_toolchain_alias="swiftwasm"
343-
darwin_toolchain_report_url="https://github.com/swiftwasm/swift/issues"
344-
345-
plist_path = f"../build/Packaging/dist-toolchain/{self.snapshot_info.toolchain_name}/Info.plist"
346-
self.plistbuddy("-c", f"Set DisplayName {darwin_toolchain_display_name}", plist_path)
347-
self.plistbuddy("-c", f"Set ShortDisplayName {darwin_toolchain_display_name_short}", plist_path)
348-
self.plistbuddy("-c", f"Set Version {darwin_toolchain_version}", plist_path)
349-
self.plistbuddy("-c", f"Set CFBundleIdentifier {darwin_toolchain_bundle_identifier}", plist_path)
350-
self.plistbuddy("-c", f"Set ReportProblemURL {darwin_toolchain_report_url}", plist_path)
351-
self.plistbuddy("-c", f"Set Aliases:0 {darwin_toolchain_alias}", plist_path)
352-
353-
def plistbuddy(self, *args):
354-
import subprocess
355-
return subprocess.check_output(['/usr/libexec/PlistBuddy'] + list(args))
356-
357-
def swift_version(self):
358-
version = self.plistbuddy("-c", "Print Version", os.path.join("..", "build", "Packaging", "base-snapshot", "Info.plist"))
359-
version = version.decode("utf-8").strip()
360-
# Get only the major and minor version
361-
return ".".join(version.split(".")[:2])
362-
363-
class ArchiveTarballAction(Action):
364-
365-
def __init__(self, options, snapshot_info: SnapshotInfo):
366-
super().__init__(options)
367-
self.snapshot_info = snapshot_info
368-
369-
def run(self):
370-
tarball_path = os.path.join("..", self.snapshot_info.tarball_name)
371-
print(f"=====> Creating tarball at {tarball_path}")
372-
373-
dist_toolchain_dir = os.path.join("..", "build", "Packaging", "dist-toolchain")
374-
self.system("tar", "-C", dist_toolchain_dir, "-czf", tarball_path, self.snapshot_info.toolchain_name)
375-
376-
377197
class CleanBuildArtifactAction(Action):
378198
def run(self):
379199
import shutil
@@ -444,7 +264,6 @@ def derive_date_suffix_from_base_tag(tag: str) -> datetime.datetime:
444264
def main():
445265
parser = argparse.ArgumentParser(description='A script to create a workspace for a Swift project applying patches')
446266
parser.add_argument("--daily-snapshot", action="store_true", help="Create a daily snapshot")
447-
parser.add_argument("--only-swift-sdk", action="store_true", help="Create only Swift SDK")
448267
options = derive_options_from_args(sys.argv[1:], parser)
449268
now = derive_date_suffix_from_base_tag(options.tag)
450269
actions = []
@@ -453,44 +272,37 @@ def main():
453272

454273
actions.append(DownloadBaseSnapshotAction(options))
455274

456-
if not options.only_swift_sdk:
457-
snapshot_info = derive_snapshot_info(options.daily_snapshot, options.scheme, now)
458-
actions.append(PackageAction(options, snapshot_info))
275+
packaging_dir = os.path.join(
276+
os.path.dirname(__file__), '..', '..', '..', 'build', 'Packaging')
459277

460-
if os.uname().sysname == "Darwin":
461-
actions.append(DarwinInfoPlistAction(options, snapshot_info))
462-
actions.append(ArchiveTarballAction(options, snapshot_info))
463-
else:
464-
packaging_dir = os.path.join(
465-
os.path.dirname(__file__), '..', '..', '..', 'build', 'Packaging')
466-
467-
toolchain_channel = derive_toolchain_channel(options.scheme)
468-
triples = [
469-
["wasm32-unknown-wasi", "wasm32-wasi"],
278+
toolchain_channel = derive_toolchain_channel(options.scheme)
279+
triples = [
280+
["wasm32-unknown-wasi", "wasm32-wasi"],
281+
]
282+
if options.scheme not in ["release-6.0"]:
283+
triples += [
284+
["wasm32-unknown-wasip1-threads", "wasm32-wasip1-threads"]
470285
]
471-
if options.scheme not in ["release-6.0"]:
472-
triples += [
473-
["wasm32-unknown-wasip1-threads", "wasm32-wasip1-threads"]
474-
]
475-
for target_triple, short_triple in triples:
476-
snapshot_info = SnapshotInfo(
477-
now.year, now.month, now.day,
478-
swift_version=derive_swift_version(
479-
options.daily_snapshot, toolchain_channel, now),
480-
artifact_name=f"swift-wasm-{toolchain_channel}-SNAPSHOT-{target_triple}",
481-
daily_snapshot=options.daily_snapshot
482-
)
483-
actions.append(PackageSwiftSDKAction(
484-
options, snapshot_info,
485-
base_toolchain_path=os.path.join(packaging_dir, 'base-snapshot'),
486-
host_toolchain_path=None,
487-
target_toolchain_path=os.path.join(packaging_dir, 'target-toolchain', target_triple),
488-
wasi_sysroot_path=derive_wasi_sysroot(options, packaging_dir, short_triple),
489-
swift_sdk_name=f"{snapshot_info.swift_version}-{target_triple}",
490-
target_triple=target_triple,
491-
))
286+
for target_triple, short_triple in triples:
287+
snapshot_info = SnapshotInfo(
288+
now.year, now.month, now.day,
289+
swift_version=derive_swift_version(
290+
options.daily_snapshot, toolchain_channel, now),
291+
artifact_name=f"swift-wasm-{toolchain_channel}-SNAPSHOT-{target_triple}",
292+
daily_snapshot=options.daily_snapshot
293+
)
294+
actions.append(PackageSwiftSDKAction(
295+
options, snapshot_info,
296+
base_toolchain_path=os.path.join(packaging_dir, 'base-snapshot'),
297+
host_toolchain_path=None,
298+
target_toolchain_path=os.path.join(packaging_dir, 'target-toolchain', target_triple),
299+
wasi_sysroot_path=derive_wasi_sysroot(options, packaging_dir, short_triple),
300+
swift_sdk_name=f"{snapshot_info.swift_version}-{target_triple}",
301+
target_triple=target_triple,
302+
))
492303

493304
ActionRunner(actions).run()
494305

306+
495307
if __name__ == '__main__':
496308
main()

0 commit comments

Comments
 (0)