Skip to content

6.2: Copy WasmKit to host_install_destdir #81504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,7 @@ playgroundsupport
indexstore-db
sourcekit-lsp
swiftdocc
wasmkit

# Build with debug info, this allows us to symbolicate crashes from
# production builds.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,14 @@ def compute_product_pipelines(self):
is_enabled=self.args.build_wasmstdlib)
builder.add_product(products.WasmThreadsLLVMRuntimeLibs,
is_enabled=self.args.build_wasmstdlib)

builder.add_product(products.SwiftTestingMacros,
is_enabled=self.args.build_swift_testing_macros)
builder.add_product(products.SwiftTesting,
is_enabled=self.args.build_swift_testing)
builder.add_product(products.SwiftPM,
is_enabled=self.args.build_swiftpm)

builder.add_product(products.WasmKit,
is_enabled=self.args.build_wasmkit)
builder.add_product(products.WasmStdlib,
Expand All @@ -681,12 +689,6 @@ def compute_product_pipelines(self):
builder.add_product(products.WasmSwiftSDK,
is_enabled=self.args.build_wasmstdlib)

builder.add_product(products.SwiftTestingMacros,
is_enabled=self.args.build_swift_testing_macros)
builder.add_product(products.SwiftTesting,
is_enabled=self.args.build_swift_testing)
builder.add_product(products.SwiftPM,
is_enabled=self.args.build_swiftpm)
builder.add_product(products.SwiftFoundationTests,
is_enabled=self.args.build_foundation)
builder.add_product(products.FoundationTests,
Expand Down
37 changes: 26 additions & 11 deletions utils/swift_build_support/swift_build_support/products/wasmkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import shutil

from . import product
from . import swiftpm
from .. import shell


Expand All @@ -37,7 +38,7 @@ def is_before_build_script_impl_product(cls):

@classmethod
def get_dependencies(cls):
return []
return [swiftpm.SwiftPM]

def should_build(self, host_target):
return self.args.build_wasmkit
Expand All @@ -47,10 +48,16 @@ def should_test(self, host_target):

def should_install(self, host_target):
# Currently, it's only used for testing stdlib.
return False
return True

def install(self, host_target):
pass
"""
Install WasmKit to the target location
"""
install_destdir = self.host_install_destdir(host_target)
build_toolchain_path = install_destdir + self.args.install_prefix + '/bin'
bin_path = run_swift_build(host_target, self, 'wasmkit-cli', set_installation_rpath=True)
shutil.copy(bin_path, build_toolchain_path + '/wasmkit')

def build(self, host_target):
bin_path = run_swift_build(host_target, self, 'wasmkit-cli')
Expand All @@ -66,19 +73,27 @@ def cli_file_path(cls, build_dir):
return os.path.join(build_dir, 'bin', 'wasmkit-cli')


def run_swift_build(host_target, product, swpft_package_product_name):
# Building with the host toolchain's SwiftPM
swiftc_path = os.path.abspath(product.toolchain.swiftc)
toolchain_path = os.path.dirname(os.path.dirname(swiftc_path))
swift_build = os.path.join(toolchain_path, 'bin', 'swift-build')
def run_swift_build(host_target, product, swiftpm_package_product_name, set_installation_rpath=False):
# Building with the freshly-built SwiftPM
swift_build = os.path.join(product.install_toolchain_path(host_target), "bin", "swift-build")

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 = []

build_args = [
swift_build,
'--product', swpft_package_product_name,
'--product', swiftpm_package_product_name,
'--package-path', os.path.join(product.source_dir),
'--build-path', product.build_dir,
'--configuration', 'release',
]
] + rpath_args

if product.args.verbose_build:
build_args.append('--verbose')
Expand All @@ -90,4 +105,4 @@ def run_swift_build(host_target, product, swpft_package_product_name):

bin_dir_path = shell.capture(
build_args + ['--show-bin-path'], dry_run=False, echo=False).rstrip()
return os.path.join(bin_dir_path, swpft_package_product_name)
return os.path.join(bin_dir_path, swiftpm_package_product_name)