Skip to content

Commit 9b06293

Browse files
authored
Merge pull request #71309 from kateinoigakukun/yt/runtime-tests-with-wasmkit
build: Run executable tests with WasmKit
2 parents 1d73afb + 8e0a79d commit 9b06293

File tree

9 files changed

+129
-5
lines changed

9 files changed

+129
-5
lines changed

utils/build-presets.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ mixin-preset=
896896
mixin-preset=buildbot_linux
897897

898898
llvm-targets-to-build=X86;ARM;AArch64;WebAssembly
899+
wasmkit
899900
build-wasm-stdlib
900901
# FIXME(katei): Test fails on a specific CI node.
901902
# https://github.com/apple/swift/issues/70980

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ def create_argument_parser():
750750
option(['--build-wasm-stdlib'], toggle_true('build_wasmstdlib'),
751751
help='build the stdlib for WebAssembly target into a'
752752
'separate build directory ')
753+
option(['--wasmkit'], toggle_true('build_wasmkit'),
754+
help='build WasmKit')
753755

754756
option('--xctest', toggle_true('build_xctest'),
755757
help='build xctest')

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
'build_watchos_simulator': False,
130130
'build_xctest': False,
131131
'build_wasmstdlib': False,
132+
'build_wasmkit': False,
132133
'cmake_c_launcher': None,
133134
'cmake_cxx_launcher': None,
134135
'clang_compiler_version': None,
@@ -547,6 +548,7 @@ class BuildScriptImplOption(_BaseOption):
547548
SetTrueOption('--swiftdocc', dest='build_swiftdocc'),
548549
SetTrueOption('--build-minimal-stdlib', dest='build_minimalstdlib'),
549550
SetTrueOption('--build-wasm-stdlib', dest='build_wasmstdlib'),
551+
SetTrueOption('--wasmkit', dest='build_wasmkit'),
550552
SetTrueOption('-B', dest='benchmark'),
551553
SetTrueOption('-S', dest='skip_build'),
552554
SetTrueOption('-b', dest='build_llbuild'),

utils/swift_build_support/swift_build_support/build_script_invocation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,8 @@ def compute_product_pipelines(self):
670670
is_enabled=self.args.build_wasmstdlib)
671671
builder.add_product(products.WasmLLVMRuntimeLibs,
672672
is_enabled=self.args.build_wasmstdlib)
673+
builder.add_product(products.WasmKit,
674+
is_enabled=self.args.build_wasmkit)
673675
builder.add_product(products.WasmStdlib,
674676
is_enabled=self.args.build_wasmstdlib)
675677

utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from .swiftsyntax import SwiftSyntax
3939
from .tsan_libdispatch import TSanLibDispatch
4040
from .wasisysroot import WASILibc, WasmLLVMRuntimeLibs
41+
from .wasmkit import WasmKit
4142
from .wasmstdlib import WasmStdlib
4243
from .xctest import XCTest
4344
from .zlib import Zlib
@@ -74,5 +75,6 @@
7475
'SwiftDocCRender',
7576
'WASILibc',
7677
'WasmLLVMRuntimeLibs',
78+
'WasmKit',
7779
'WasmStdlib'
7880
]
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# swift_build_support/products/wasmkit.py ------------------------------------
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
import os
14+
import shutil
15+
16+
from . import product
17+
from .. import shell
18+
19+
20+
class WasmKit(product.Product):
21+
"""
22+
A product for WasmKit, which is a WebAssembly runtime implementation
23+
written in Swift.
24+
"""
25+
26+
@classmethod
27+
def product_source_name(cls):
28+
return "wasmkit"
29+
30+
@classmethod
31+
def is_build_script_impl_product(cls):
32+
return False
33+
34+
@classmethod
35+
def is_before_build_script_impl_product(cls):
36+
return True
37+
38+
@classmethod
39+
def get_dependencies(cls):
40+
return []
41+
42+
def should_build(self, host_target):
43+
return self.args.build_wasmkit
44+
45+
def should_test(self, host_target):
46+
return False
47+
48+
def should_install(self, host_target):
49+
# Currently, it's only used for testing stdlib.
50+
return False
51+
52+
def install(self, host_target):
53+
pass
54+
55+
def build(self, host_target):
56+
bin_path = run_swift_build(host_target, self, 'wasmkit-cli')
57+
print("Built wasmkit-cli at: " + bin_path)
58+
# Copy the built binary to ./bin
59+
dest_bin_path = self.__class__.cli_file_path(self.build_dir)
60+
print("Copying wasmkit-cli to: " + dest_bin_path)
61+
os.makedirs(os.path.dirname(dest_bin_path), exist_ok=True)
62+
shutil.copy(bin_path, dest_bin_path)
63+
64+
@classmethod
65+
def cli_file_path(cls, build_dir):
66+
return os.path.join(build_dir, 'bin', 'wasmkit-cli')
67+
68+
69+
def run_swift_build(host_target, product, swpft_package_product_name):
70+
# Building with the host toolchain's SwiftPM
71+
swiftc_path = os.path.abspath(product.toolchain.swiftc)
72+
toolchain_path = os.path.dirname(os.path.dirname(swiftc_path))
73+
swift_build = os.path.join(toolchain_path, 'bin', 'swift-build')
74+
75+
build_args = [
76+
swift_build,
77+
'--product', swpft_package_product_name,
78+
'--package-path', os.path.join(product.source_dir),
79+
'--build-path', product.build_dir,
80+
'--configuration', 'release',
81+
]
82+
83+
if product.args.verbose_build:
84+
build_args.append('--verbose')
85+
86+
env = dict(os.environ)
87+
env['SWIFTCI_USE_LOCAL_DEPS'] = '1'
88+
89+
shell.call(build_args, env=env)
90+
91+
bin_dir_path = shell.capture(
92+
build_args + ['--show-bin-path'], dry_run=False, echo=False).rstrip()
93+
return os.path.join(bin_dir_path, swpft_package_product_name)

utils/swift_build_support/swift_build_support/products/wasmstdlib.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from . import llvm
1717
from . import swift
1818
from . import wasisysroot
19+
from . import wasmkit
1920

2021

2122
class WasmStdlib(cmake_product.CMakeProduct):
@@ -100,7 +101,7 @@ def build(self, host_target):
100101
# Test configuration
101102
self.cmake_options.define('SWIFT_INCLUDE_TESTS:BOOL', 'TRUE')
102103
self.cmake_options.define('SWIFT_ENABLE_SOURCEKIT_TESTS:BOOL', 'FALSE')
103-
lit_test_paths = ['IRGen']
104+
lit_test_paths = ['IRGen', 'stdlib', 'Concurrency/Runtime']
104105
lit_test_paths = [os.path.join(
105106
self.build_dir, 'test-wasi-wasm32', path) for path in lit_test_paths]
106107
self.cmake_options.define('SWIFT_LIT_TEST_PATHS:STRING',
@@ -119,13 +120,27 @@ def build(self, host_target):
119120
prefer_just_built_toolchain=True)
120121

121122
def test(self, host_target):
123+
build_root = os.path.dirname(self.build_dir)
122124
bin_paths = [
123125
os.path.join(self._host_swift_build_dir(host_target), 'bin'),
124126
os.path.join(self._host_llvm_build_dir(host_target), 'bin'),
125127
os.environ['PATH']
126128
]
127-
env = {'PATH': os.path.pathsep.join(bin_paths)}
128-
test_target = "check-swift-only_non_executable-wasi-wasm32-custom"
129+
wasmkit_build_path = os.path.join(
130+
build_root, '%s-%s' % ('wasmkit', host_target))
131+
wasmkit_bin_path = wasmkit.WasmKit.cli_file_path(wasmkit_build_path)
132+
if not os.path.exists(wasmkit_bin_path):
133+
test_target = "check-swift-only_non_executable-wasi-wasm32-custom"
134+
else:
135+
test_target = "check-swift-wasi-wasm32-custom"
136+
bin_paths = [os.path.dirname(wasmkit_bin_path)] + bin_paths
137+
138+
env = {
139+
'PATH': os.path.pathsep.join(bin_paths),
140+
# FIXME: WasmKit takes too long to run these exhaustive tests for now
141+
'LIT_FILTER_OUT':
142+
'(Concurrency/Runtime/clock.swift|stdlib/StringIndex.swift)',
143+
}
129144
self.test_with_cmake(None, [test_target], self._build_variant, [], test_env=env)
130145

131146
@property
@@ -153,4 +168,5 @@ def get_dependencies(cls):
153168
return [llvm.LLVM,
154169
wasisysroot.WASILibc,
155170
wasisysroot.WasmLLVMRuntimeLibs,
171+
wasmkit.WasmKit,
156172
swift.Swift]

utils/update_checkout/update-checkout-config.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@
8585
"remote": { "id": "apple/llvm-project" } },
8686
"wasi-libc": {
8787
"remote": { "id": "WebAssembly/wasi-libc" } },
88+
"wasmkit": {
89+
"remote": { "id": "swiftwasm/WasmKit" }
90+
},
8891
"curl": {
8992
"remote": { "id": "curl/curl" }
9093
},
@@ -142,6 +145,7 @@
142145
"swift-nio-ssl": "2.15.0",
143146
"swift-experimental-string-processing": "swift/main",
144147
"wasi-libc": "wasi-sdk-20",
148+
"wasmkit": "0.0.3",
145149
"curl": "curl-8_4_0",
146150
"icu": "maint/maint-69",
147151
"libxml2": "v2.11.5",
@@ -237,7 +241,8 @@
237241
"swift-nio": "2.31.2",
238242
"swift-nio-ssl": "2.15.0",
239243
"swift-experimental-string-processing": "swift/main",
240-
"wasi-libc": "wasi-sdk-20"
244+
"wasi-libc": "wasi-sdk-20",
245+
"wasmkit": "0.0.3"
241246
}
242247
},
243248
"release/5.9": {
@@ -606,6 +611,7 @@
606611
"swift-installer-scripts": "main",
607612
"swift-experimental-string-processing": "swift/main",
608613
"wasi-libc": "wasi-sdk-20",
614+
"wasmkit": "0.0.3",
609615
"curl": "curl-8_4_0",
610616
"icu": "maint/maint-69",
611617
"libxml2": "v2.11.5",

utils/wasm-run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def run(self, args):
2424
subprocess.check_call(command)
2525

2626
def invocation(self, args):
27-
command = ["wasmtime", "run"]
27+
command = ["wasmkit-cli", "run"]
2828
envs = collect_wasm_env()
2929
for key in envs:
3030
command.append("--env")

0 commit comments

Comments
 (0)