Upstreaming to apple/swift
One of the goals of SwiftWasm is to upstream our changes to apple/swift
as much as possible.
This document describes our upstreaming process and how we should keep our friendly fork.
We are maintaining several patches in swiftwasm/swiftwasm-build
.
We had been maintaining a fork of apple/swift
before, but we stopped it because we already have upstreamed most of our changes, and it is hard to maintain the fork for several reasons (See faq.md for details).
Most of our patches are ready to be upstreamed, but some of them marked as HACK
are not ready yet.
If you are new to Swift compiler development, please read Getting Started with Swift Development
-
Check if the patch is already upstreamed or not. Some patches are already upstreamed but nightly snapshot tag can be not updated yet.
-
If the patch is not upstreamed yet and ready to be upstreamed, create a PR to
apple/swift
. -
Test the PR in
ci.swift.org
. Use the following CI command:@swift-ci Please smoke test
@swift-ci Please test WebAssembly
-
If the CI is green and got approval from the upstream reviewers, merge the PR.
-
Ensure that the patch does not break the CI. If it breaks the CI, revert the commit or fix it ASAP.
- ci.swift.org: Jenkins CI hosted by Apple and used to test every PR and the latest
main
branch commit ofapple/swift
. - WebAssembly cross-compiler test in ci.swift.org: Jenkins CI hosted by SwiftWasm but joins the Apple's Swift CI system. Run tests for the latest
main
branch commit ofapple/swift
. The CI status is notified in SwiftWasm Discord server.
If our upstreaming commits break ci.swift.org, we should revert the commit or fix it ASAP.
-
✅ Upstream compiler patches
If we upstream all of our compiler patches, we can stop building our own compiler and use the official Swift compiler instead. After that, we can focus on building standard library and save much time.
-
✅ Upstream standard library patches
-
✅ Set up WebAssembly check in ci.swift.org and make it mandatory to pass the check to merge a PR like the Windows check
Building the Swift toolchain is a time-consuming process. We recommend to use powerful machine or cloud service to build the toolchain. (FYI: Yuta usually uses CPX51 by Hetzner)
Please basically follow the README process to set up the build environment.
If it's first time to build or patch files are changed, you need to checkout the source code:
./tools/git-swift-workspace --scheme main
If you want to build the whole toolchain, run the following command:
./tools/build/build-toolchain.sh
If you already built the compiler and want to build only the standard library for WebAssembly, run the following command:
./tools/build/build-toolchain.sh --skip-build-host-toolchain
If you want to add a new patch, edit the Swift source code and commit it on the current branch, which is created by git-swift-workspace
and includes our existing patches.
If you want to edit an existing patch (e.g. to resolve conflicts with upstream changes, or to improve the patch), please edit the commit history by git rebase -i
.
After editing the source code, you need to rebuild the toolchain, and if you are sure that the patch is OK, you can update our .patch
files by the follwoing command:
./tools/git-swift-update-patch --scheme main
The above build command does not run tests. If you want to run tests, run the following command:
ninja -C ../build/WebAssembly/swift-stdlib-wasi-wasm32 check-swift-wasi-wasm32-custom