-
Notifications
You must be signed in to change notification settings - Fork 10.5k
utils/build-script: add--test-with-wasm-runtime
option
#83573
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,10 @@ | |
# ---------------------------------------------------------------------------- | ||
|
||
import os | ||
import shutil | ||
import sys | ||
|
||
from typing import NoReturn | ||
|
||
from . import cmake_product | ||
from . import llvm | ||
|
@@ -206,31 +210,52 @@ def _build_stdlib(self, host_target, target_triple, llvm_cmake_dir): | |
self.cmake_options.define('SWIFT_DRIVER_TEST_OPTIONS:STRING', | ||
' ' + ' '.join(test_driver_options)) | ||
|
||
self.cmake_options.define('SWIFT_TEST_WASM_RUNTIME', self.args.test_with_wasm_runtime) | ||
|
||
# Configure with WebAssembly target variant, and build with just-built toolchain | ||
self.build_with_cmake([], self._build_variant, [], | ||
prefer_native_toolchain=not self.args.build_runtime_with_host_compiler) | ||
|
||
def add_extra_cmake_options(self): | ||
self.cmake_options.define('SWIFT_THREADING_PACKAGE:STRING', 'none') | ||
|
||
def _wasm_runtime_lookup_failed(self) -> NoReturn: | ||
print("wasmstdlib testing: Wasm runtime not found") | ||
sys.exit(1) | ||
|
||
def infer_wasm_runtime(self, host_target) -> str: | ||
build_root = os.path.dirname(self.build_dir) | ||
if self.args.test_with_wasm_runtime == 'wasmkit': | ||
wasmkit_build_path = os.path.join( | ||
build_root, '%s-%s' % ('wasmkit', host_target)) | ||
return wasmkit.WasmKit.cli_file_path(wasmkit_build_path) | ||
elif self.args.test_with_wasm_runtime == 'nodejs': | ||
result = shutil.which('node') | ||
if result: | ||
return result | ||
Comment on lines
+232
to
+235
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to add it to |
||
else: | ||
self._wasm_runtime_lookup_failed() | ||
else: | ||
self._wasm_runtime_lookup_failed() | ||
|
||
|
||
def test(self, host_target): | ||
self._test(host_target, 'wasm32-wasip1') | ||
|
||
def _test(self, host_target, target_triple): | ||
build_root = os.path.dirname(self.build_dir) | ||
bin_paths = [ | ||
os.path.join(self._host_swift_build_dir(host_target), 'bin'), | ||
os.path.join(self._host_llvm_build_dir(host_target), 'bin'), | ||
os.environ['PATH'] | ||
] | ||
wasmkit_build_path = os.path.join( | ||
build_root, '%s-%s' % ('wasmkit', host_target)) | ||
wasmkit_bin_path = wasmkit.WasmKit.cli_file_path(wasmkit_build_path) | ||
if not os.path.exists(wasmkit_bin_path) or not self.should_test_executable(): | ||
|
||
wasm_runtime_bin_path = self.infer_wasm_runtime(host_target) | ||
print(f"wasm_runtime_bin_path is {wasm_runtime_bin_path}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. debug code? |
||
if not os.path.exists(wasm_runtime_bin_path) or not self.should_test_executable(): | ||
test_target = "check-swift-only_non_executable-wasi-wasm32-custom" | ||
else: | ||
test_target = "check-swift-wasi-wasm32-custom" | ||
bin_paths = [os.path.dirname(wasmkit_bin_path)] + bin_paths | ||
bin_paths = [os.path.dirname(wasm_runtime_bin_path)] + bin_paths | ||
|
||
env = { | ||
'PATH': os.path.pathsep.join(bin_paths), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,16 @@ def run(self, args): | |
subprocess.check_call(command) | ||
|
||
def invocation(self, args): | ||
command = ["wasmkit", "run"] | ||
envs = collect_wasm_env() | ||
for key in envs: | ||
command.append("--env") | ||
command.append(f"{key}={envs[key]}") | ||
command.append("--") | ||
if args.runtime == 'nodejs': | ||
command = [os.path.join(os.path.dirname(__file__), 'wasm', 'node-wasi-runner')] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to forward env vars from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't Node.js WASI inherit env vars by default? And args are passed below in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops, I missed the command args. We need to set env vars prefixed with |
||
else: | ||
command = ["wasmkit", "run"] | ||
envs = collect_wasm_env() | ||
for key in envs: | ||
command.append("--env") | ||
command.append(f"{key}={envs[key]}") | ||
command.append("--") | ||
|
||
command.extend(args.command) | ||
return command | ||
|
||
|
@@ -42,6 +46,11 @@ def main(): | |
parser.add_argument('-n', '--dry-run', action='store_true', dest='dry_run', | ||
help="print the commands that would have been run, but" | ||
" don't actually run them") | ||
parser.add_argument('-r', '--runtime', metavar='WASM_RUNTIME', | ||
choices=['wasmkit', 'nodejs'], default='wasmkit', | ||
help='Wasm runtime to use when running tests. Available choices: ' | ||
'`wasmkit` or `nodejs`') | ||
|
||
parser.add_argument('command', nargs=argparse.REMAINDER, | ||
help='the command to run', metavar='command...') | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent