Closed
Description
Description
.../bin/wasmkit
is built only for x86 in release/6.2
toolchain for macOS.
All other tools (except docc
) are built as universal binaries.
This causes swift run ...
to fail with a bad CPU on Apple silicon for wasm examples (recently described on the swift.org blog).
(fix proposed below)
Reproduction
- Download and install macOS toolchains from https://www.swift.org/install
- Pick any version starting with
swift-6.2-DEVELOPMENT-SNAPSHOT-2025-05-15-a.xctoolchain
- Pick any version starting with
- Check binary type:
file usr/bin/wasmkit
- RESULT:
Mach-O 64-bit executable x86_64
- Should be:
universal binary with 2 architectures...
Expected behavior
- Check binary type:
file usr/bin/wasmkit
- Expected result:
universal binary with 2 architectures: [x86_64: .. ] [arm64]
Environment
Impacts macOS arm64, not x86.
Additional information
Workaround
- directly build and run wasmkit-cli from https://github.com/swiftwasm/WasmKit
Rough fix: build with --arch x86_64 --arch arm64
in wasmkit.py
The Swiftpm build command for wasmkit-cli should include --arch x86_64 --arch arm64
when the target is macOS.
- In file:
/swift/utils/swift_build_support/swift_build_support/products/wasmkit.py
- See function:
def run_swift_build
- Currently constructing
rpath_args
per target, so inject arch at the same time.
The following injects the parameters at about the right place (but it should be corrected, see below):
build_os = host_target.split('-')[0]
if set_installation_rpath and not host_target.startswith('macos'):
# Library rpath for swift, dispatch, Foundation, etc. when installing
rpath_args = [
'--disable-local-rpath', '-Xswiftc', '-no-toolchain-stdlib-rpath',
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/' + build_os
]
else:
- rpath_args = [] // <-------------------------------------- fix here
+ rpath_args = ['--arch', 'x86_64', '--arch', 'arm64']
build_args = [
swift_build,
'--product', swiftpm_package_product_name,
'--package-path', os.path.join(product.source_dir),
'--build-path', product.build_dir,
'--configuration', 'release',
] + rpath_args
Issues with the proposed fix
- Untested
- This does not deal with other platforms and assumes macOS is the only multi-arch platform.
- The
if
logic should add flags for macOS even ifset_installation_rpath
is true - Probably should use another variable (
arches_args
) or renamerpath_args
for clarity.
Related: docc
binary
docc
similarly is not a universal binary- If/since all toolchain targets should be universal, consider a configuration-driven unified fix?