Skip to content

Commit ea734e2

Browse files
authored
[6.2] Update wasmkit toolchain build to emit universal on macOS to fix #82390 (#82406)
- **Explanation**: Build wasmkit, a new toolchain executable, as universal binary on macOS using SwiftPM --arch flags. (Cherry picked from commit 6530236) - **Scope**: WasmKit is new, and users targeting Wasm (and preferring WasmKit over other Wasm runtimes) might be few. WasmKit can be invoked directly by users and indirectly via `swift run` when using the official Swift SDKs for Wasm. - **Issues**: Resolves #82390 - **Original PRs**: #82393 - **Risk**: The new configuration only affects macOS targets. The binary is output to a new location, but the code already introspects the location correctly. The bug and fix impacts users of WasmKit binary newly added to toolchain, directly and via `swift run`. Risk of no-fix: The Swift.org wasm "Getting Started" [1] refers explicitly to this (unreleased) 6.2 toolchain WasmKit binary. Without this fix, users on Apple Silicon following those instructions get an obscure "bad CPU" error because it is built only for the host x86_64 arch. - **Testing**: @kateinoigakukun verified WasmKit is universal after change in `main`. To verify, run shell `file usr/bin/wasmkit` and verify outputs include x86_64 and arm64 arch. An outstanding question is whether to add a check that toolchain executables are universal binaries on macOS. Currently they are, except for `docc`. - **Reviewers**: @kateinoigakukun [1] https://www.swift.org/documentation/articles/wasm-getting-started.html
1 parent 8e0749e commit ea734e2

File tree

1 file changed

+8
-5
lines changed
  • utils/swift_build_support/swift_build_support/products

1 file changed

+8
-5
lines changed

utils/swift_build_support/swift_build_support/products/wasmkit.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,26 @@ def run_swift_build(host_target, product, swiftpm_package_product_name, set_inst
7777
# Building with the freshly-built SwiftPM
7878
swift_build = os.path.join(product.install_toolchain_path(host_target), "bin", "swift-build")
7979

80-
build_os = host_target.split('-')[0]
81-
if set_installation_rpath and not host_target.startswith('macos'):
80+
if host_target.startswith('macos'):
81+
# Universal binary on macOS
82+
platform_args = ['--arch', 'x86_64', '--arch', 'arm64']
83+
elif set_installation_rpath:
8284
# Library rpath for swift, dispatch, Foundation, etc. when installing
83-
rpath_args = [
85+
build_os = host_target.split('-')[0]
86+
platform_args = [
8487
'--disable-local-rpath', '-Xswiftc', '-no-toolchain-stdlib-rpath',
8588
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/' + build_os
8689
]
8790
else:
88-
rpath_args = []
91+
platform_args = []
8992

9093
build_args = [
9194
swift_build,
9295
'--product', swiftpm_package_product_name,
9396
'--package-path', os.path.join(product.source_dir),
9497
'--build-path', product.build_dir,
9598
'--configuration', 'release',
96-
] + rpath_args
99+
] + platform_args
97100

98101
if product.args.verbose_build:
99102
build_args.append('--verbose')

0 commit comments

Comments
 (0)