Skip to content

Commit 2b11604

Browse files
build: Add WasmKit (a Wasm runtime) product
This patch adds a new product, WasmKit, which is a Wasm runtime that is going to be used to run executable tests targeting Wasm. Note that the product is not shipped as a part of the toolchain, but is used only for testing purposes.
1 parent 6cca6e5 commit 2b11604

File tree

6 files changed

+108
-1
lines changed

6 files changed

+108
-1
lines changed

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/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",

0 commit comments

Comments
 (0)