diff --git a/getting-started/testing.html b/getting-started/testing.html index 9f01b69..bfb1d7d 100644 --- a/getting-started/testing.html +++ b/getting-started/testing.html @@ -220,6 +220,24 @@
PackageTests.wasm
. It is located in the .build/debug
subdirectory, or in the .build/release
subdirectory when you build in release mode.
+SwiftPM
++Note: Code coverage support is available only in nightly toolchains for now.
+
You can also generate code coverage reports for your test suite. To do this, you need to build your
+test suite with the --enable-code-coverage
and linker options -Xlinker -lwasi-emulated-getpid
:
$ swift build --build-tests --swift-sdk wasm32-unknown-wasi --enable-code-coverage -Xlinker -lwasi-emulated-getpid
+
+After building your test suite, you can run it with wasmtime
as described above. The raw coverage
+data will be stored in default.profraw
file in the current directory. You can use the llvm-profdata
+and llvm-cov
tools to generate a human-readable report:
$ wasmtime --dir . .build/wasm32-unknown-wasi/debug/ExamplePackageTests.wasm
+$ llvm-profdata merge default.profraw -o default.profdata
+$ llvm-cov show .build/wasm32-unknown-wasi/debug/ExamplePackageTests.wasm -instr-profile=default.profdata
+# or generate an HTML report
+$ llvm-cov show .build/wasm32-unknown-wasi/debug/ExamplePackageTests.wasm -instr-profile=default.profdata --format=html -o coverage
+$ open coverage/index.html
+
carton
If you use carton
to develop and build your app, as described in our guide
for browser apps, just run swift run carton test
in the
diff --git a/getting-started/troubleshooting.html b/getting-started/troubleshooting.html
index 76f2b5a..dafe024 100644
--- a/getting-started/troubleshooting.html
+++ b/getting-started/troubleshooting.html
@@ -202,7 +202,7 @@
error: missing external dependency '.../usr/lib/swift/wasi/static-executable-args.lnk'
You may encounter this error while building with Swift SDK for WebAssembly and swiftc
driver command. Unfortunately, Swift SDK does not support building with swiftc
command yet, so you need to use swift build
Swift Package Manager command instead.
e.g. swift build --swift-sdk <SDK name>
See also: Compile a SwiftPM package to WebAssembly
diff --git a/print.html b/print.html index ed92031..39879a8 100644 --- a/print.html +++ b/print.html @@ -652,6 +652,24 @@PackageTests.wasm
. It is located in the .build/debug
subdirectory, or in the .build/release
subdirectory when you build in release mode.
+SwiftPM
++Note: Code coverage support is available only in nightly toolchains for now.
+
You can also generate code coverage reports for your test suite. To do this, you need to build your
+test suite with the --enable-code-coverage
and linker options -Xlinker -lwasi-emulated-getpid
:
$ swift build --build-tests --swift-sdk wasm32-unknown-wasi --enable-code-coverage -Xlinker -lwasi-emulated-getpid
+
+After building your test suite, you can run it with wasmtime
as described above. The raw coverage
+data will be stored in default.profraw
file in the current directory. You can use the llvm-profdata
+and llvm-cov
tools to generate a human-readable report:
$ wasmtime --dir . .build/wasm32-unknown-wasi/debug/ExamplePackageTests.wasm
+$ llvm-profdata merge default.profraw -o default.profdata
+$ llvm-cov show .build/wasm32-unknown-wasi/debug/ExamplePackageTests.wasm -instr-profile=default.profdata
+# or generate an HTML report
+$ llvm-cov show .build/wasm32-unknown-wasi/debug/ExamplePackageTests.wasm -instr-profile=default.profdata --format=html -o coverage
+$ open coverage/index.html
+
carton
If you use carton
to develop and build your app, as described in our guide
for browser apps, just run swift run carton test
in the
@@ -776,7 +794,7 @@
error: missing external dependency '.../usr/lib/swift/wasi/static-executable-args.lnk'
You may encounter this error while building with Swift SDK for WebAssembly and swiftc
driver command. Unfortunately, Swift SDK does not support building with swiftc
command yet, so you need to use swift build
Swift Package Manager command instead.
e.g. swift build --swift-sdk <SDK name>
See also: Compile a SwiftPM package to WebAssembly
diff --git a/searchindex.js b/searchindex.js index 2f04ea3..7858fc9 100644 --- a/searchindex.js +++ b/searchindex.js @@ -1 +1 @@ -Object.assign(window.search, {"doc_urls":["index.html#introduction","index.html#project-status","getting-started/index.html#getting-started","getting-started/setup.html#installation---latest-release-swiftwasm-510","getting-started/setup.html#toolchain-installation","getting-started/setup.html#macos","getting-started/setup.html#linux","getting-started/setup.html#experimental-swift-sdk","getting-started/setup.html#docker","getting-started/setup.html#supported-platforms","getting-started/setup.html#using-docker-images","getting-started/setup-snapshot.html#installation---development-snapshot","getting-started/setup-snapshot.html#swift-sdk-for-webassembly---cross-compile-to-webassembly","getting-started/setup-snapshot.html#instructions","getting-started/setup-snapshot.html#how-to-use-the-swift-sdk","getting-started/setup-snapshot.html#faq","getting-started/setup-snapshot.html#what-is-the-difference-between-the-swift-toolchain-and-the-swift-sdk","getting-started/setup-snapshot.html#what-is-included-in-the-swift-sdk-for-webassembly","getting-started/hello-world.html#hello-world","getting-started/hello-world.html#1-create-a-swift-file","getting-started/hello-world.html#2-compile-swift-code-into-webassembly-with-wasi","getting-started/hello-world.html#3-run-the-produced-binary-on-webassembly-runtime","getting-started/swift-package.html#compile-a-swiftpm-package-to-webassembly","getting-started/swift-package.html#1-create-a-package-from-template","getting-started/swift-package.html#2-build-the-project-into-a-webassembly-binary","getting-started/swift-package.html#3-run-the-produced-binary","getting-started/porting.html#porting-code-from-other-platforms-to-webassembly","getting-started/porting.html#wasilibc-module","getting-started/porting.html#limitations","getting-started/porting.html#swift-foundation-and-dispatch","getting-started/browser-app.html#creating-a-browser-app","getting-started/browser-app.html#requirements","getting-started/browser-app.html#system-requirements","getting-started/browser-app.html#installation","getting-started/javascript-interop.html#javascript-interoperation","getting-started/concurrency.html#running-async-functions-in-webassembly","getting-started/concurrency.html#cooperative-task-executor","getting-started/concurrency.html#javascript-event-loop-based-task-executor","getting-started/testing.html#testing-your-app","getting-started/testing.html#a-simple-test-case","getting-started/testing.html#xctest-limitations-in-the-swiftwasm-toolchain","getting-started/testing.html#building-and-running-the-test-suite-with-swiftpm","getting-started/testing.html#building-and-running-the-test-suite-with-carton","getting-started/vscode.html#configuring-visual-studio-code-with-webassembly-sdk","getting-started/vscode.html#prerequisites","getting-started/vscode.html#configure-your-swiftpm-package","getting-started/debugging.html#debugging","getting-started/debugging.html#chrome-devtools","getting-started/debugging.html#wasminspect","getting-started/debugging.html#wasm-memprof","getting-started/troubleshooting.html#troubleshooting","getting-started/troubleshooting.html#runtimeerror-memory-access-out-of-bounds","getting-started/troubleshooting.html#1-you-are-trying-to-access-invalid-memory-in-your-code","getting-started/troubleshooting.html#2-you-missed-program-initialization-defined-in--wasi-application-abi-","getting-started/troubleshooting.html#3-stack-overflow-is-occurring","getting-started/troubleshooting.html#fatal-error-stdlibh-file-not-found","getting-started/troubleshooting.html#error-missing-external-dependency-usrlibswiftwasistatic-executable-argslnk","examples/index.html#examples","examples/importing-function.html#importing-a-function-from-host-environments","examples/importing-function.html#swift-510-or-earlier","examples/importing-function.html#swift-60-or-later","examples/exporting-function.html#exporting-function-for-host-environment","examples/exporting-function.html#swift-510-or-earlier","examples/exporting-function.html#swift-60-or-later","examples/example-projects.html#example-projects","contribution-guide/index.html#contribution-guide","contribution-guide/index.html#repositories","contribution-guide/index.html#swiftwasmswiftwasm-build","contribution-guide/index.html#swiftwasmicu4c-wasi","contribution-guide/how-to-build-toolchain.html#how-to-build-toolchain","contribution-guide/how-to-build-toolchain.html#1-checkout-the-project-source-code","contribution-guide/how-to-build-toolchain.html#2-install-required-dependencies","contribution-guide/how-to-build-toolchain.html#3-build-the-toolchain","contribution-guide/how-to-build-toolchain.html#build-on-docker"],"index":{"documentStore":{"docInfo":{"0":{"body":70,"breadcrumbs":1,"title":1},"1":{"body":22,"breadcrumbs":2,"title":2},"10":{"body":21,"breadcrumbs":5,"title":3},"11":{"body":0,"breadcrumbs":6,"title":3},"12":{"body":19,"breadcrumbs":9,"title":6},"13":{"body":167,"breadcrumbs":4,"title":1},"14":{"body":36,"breadcrumbs":6,"title":3},"15":{"body":0,"breadcrumbs":4,"title":1},"16":{"body":23,"breadcrumbs":9,"title":6},"17":{"body":17,"breadcrumbs":7,"title":4},"18":{"body":14,"breadcrumbs":4,"title":2},"19":{"body":4,"breadcrumbs":6,"title":4},"2":{"body":22,"breadcrumbs":2,"title":2},"20":{"body":8,"breadcrumbs":8,"title":6},"21":{"body":29,"breadcrumbs":8,"title":6},"22":{"body":7,"breadcrumbs":6,"title":4},"23":{"body":19,"breadcrumbs":6,"title":4},"24":{"body":29,"breadcrumbs":7,"title":5},"25":{"body":14,"breadcrumbs":6,"title":4},"26":{"body":60,"breadcrumbs":6,"title":4},"27":{"body":57,"breadcrumbs":4,"title":2},"28":{"body":26,"breadcrumbs":3,"title":1},"29":{"body":134,"breadcrumbs":5,"title":3},"3":{"body":58,"breadcrumbs":7,"title":5},"30":{"body":24,"breadcrumbs":5,"title":3},"31":{"body":19,"breadcrumbs":3,"title":1},"32":{"body":3,"breadcrumbs":4,"title":2},"33":{"body":129,"breadcrumbs":3,"title":1},"34":{"body":71,"breadcrumbs":4,"title":2},"35":{"body":21,"breadcrumbs":6,"title":4},"36":{"body":95,"breadcrumbs":5,"title":3},"37":{"body":152,"breadcrumbs":8,"title":6},"38":{"body":35,"breadcrumbs":4,"title":2},"39":{"body":82,"breadcrumbs":5,"title":3},"4":{"body":0,"breadcrumbs":4,"title":2},"40":{"body":40,"breadcrumbs":6,"title":4},"41":{"body":89,"breadcrumbs":7,"title":5},"42":{"body":24,"breadcrumbs":7,"title":5},"43":{"body":22,"breadcrumbs":8,"title":6},"44":{"body":20,"breadcrumbs":3,"title":1},"45":{"body":79,"breadcrumbs":5,"title":3},"46":{"body":37,"breadcrumbs":3,"title":1},"47":{"body":78,"breadcrumbs":4,"title":2},"48":{"body":22,"breadcrumbs":3,"title":1},"49":{"body":37,"breadcrumbs":4,"title":2},"5":{"body":73,"breadcrumbs":3,"title":1},"50":{"body":24,"breadcrumbs":3,"title":1},"51":{"body":5,"breadcrumbs":7,"title":5},"52":{"body":11,"breadcrumbs":8,"title":6},"53":{"body":16,"breadcrumbs":10,"title":8},"54":{"body":69,"breadcrumbs":6,"title":4},"55":{"body":40,"breadcrumbs":7,"title":5},"56":{"body":37,"breadcrumbs":9,"title":7},"57":{"body":5,"breadcrumbs":1,"title":1},"58":{"body":0,"breadcrumbs":5,"title":4},"59":{"body":201,"breadcrumbs":4,"title":3},"6":{"body":23,"breadcrumbs":3,"title":1},"60":{"body":54,"breadcrumbs":4,"title":3},"61":{"body":0,"breadcrumbs":5,"title":4},"62":{"body":163,"breadcrumbs":4,"title":3},"63":{"body":57,"breadcrumbs":4,"title":3},"64":{"body":7,"breadcrumbs":3,"title":2},"65":{"body":0,"breadcrumbs":2,"title":2},"66":{"body":0,"breadcrumbs":1,"title":1},"67":{"body":19,"breadcrumbs":2,"title":2},"68":{"body":13,"breadcrumbs":2,"title":2},"69":{"body":29,"breadcrumbs":4,"title":2},"7":{"body":89,"breadcrumbs":5,"title":3},"70":{"body":22,"breadcrumbs":7,"title":5},"71":{"body":20,"breadcrumbs":6,"title":4},"72":{"body":19,"breadcrumbs":5,"title":3},"73":{"body":69,"breadcrumbs":4,"title":2},"8":{"body":14,"breadcrumbs":3,"title":1},"9":{"body":10,"breadcrumbs":4,"title":2}},"docs":{"0":{"body":"Welcome to the SwiftWasm Documentation! SwiftWasm is an open source project to support the WebAssembly target for Swift. The goal of this project is to fully support the WebAssembly target for Swift and to be merged into the upstream repository . WebAssembly is described on its home page as: WebAssembly (abbreviated as Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications. We use LLVM as a compiler backend to produce WebAssembly binaries. Our resulting binaries also depend on WASI , which is a modular system interface for WebAssembly. WASI is mainly required to compile Swift Standard Library.","breadcrumbs":"Introduction","id":"0","title":"Introduction"},"1":{"body":"All compiler and standard library changes have been upstreamed to the official Swift repository, and the upstream CI is now testing WebAssembly targets. The remaining works are: Integrating the build system with the official Swift CI.","breadcrumbs":"Project Status","id":"1","title":"Project Status"},"10":{"body":"Pull the Docker image from GitHub Container Registry : docker pull ghcr.io/swiftwasm/swift:latest Create a container using tag latest and attach it to the container: docker run --rm -it ghcr.io/swiftwasm/swift:latest /bin/bash","breadcrumbs":"Getting Started » Using Docker Images","id":"10","title":"Using Docker Images"},"11":{"body":"","breadcrumbs":"Getting Started » Installation » Installation - Development Snapshot","id":"11","title":"Installation - Development Snapshot"},"12":{"body":"The upstream Open Source Swift toolchain does support WebAssembly as a target platform since Swift 6.0 . For those versions, you just need to install Swift SDK for cross-compilation .","breadcrumbs":"Getting Started » Installation » Swift SDK for WebAssembly - Cross compile to WebAssembly","id":"12","title":"Swift SDK for WebAssembly - Cross compile to WebAssembly"},"13":{"body":"Find a Development Snapshot Visit the SwiftWasm GitHub Releases page . Match the Swift Toolchain Version Refer to the release note's table to find the corresponding upstream Swift toolchain version. For example, swift-wasm-DEVELOPMENT-SNAPSHOT-2024-06-12-a corresponds to swift-DEVELOPMENT-SNAPSHOT-2024-06-11-a Download the Swift Toolchain Download the appropriate Swift toolchain version from swift.org/install . Get the Swift SDK artifactbundle URL Find the URL ending with .artifactbundle.zip from the release page you found in step 1. Currently we provide Swift SDKs for the following WebAssembly targets: wasm32-unknown-wasi (Recommended): for WASI Preview 1 wasm32-unknown-wasip1-threads: for WASI Preview 1 with wasi-threads extension Choose wasm32-unknown-wasi if you are not sure which target to use. Install the Swift SDK for WebAssembly Use the following command to install the Swift SDK: $ swift sdk install