Skip to content

Repair build with latest main snapshot #616

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

Merged
merged 7 commits into from
Jul 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .github/workflows/build-toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,12 @@ jobs:
${{ matrix.container }}
docker exec swiftwasm-ci-buildbot /bin/bash -lc 'env; cp -r /source/* /home/build-user/; ./swiftwasm-build/tools/build/ci.sh ${{ matrix.scheme }}'

- name: Extract installable archive from Docker container (wasm32-unknown-wasip1)
if: ${{ matrix.container != null && matrix.scheme != 'release-6.0' && matrix.scheme != 'release-6.1' }}
run: |
docker cp swiftwasm-ci-buildbot:/home/build-user/swift-wasm-${{ matrix.toolchain_channel }}-SNAPSHOT-wasm32-unknown-wasip1.artifactbundle.zip .
- name: Extract installable archive from Docker container (wasm32-unknown-wasi)
if: ${{ matrix.container != null }}
if: ${{ matrix.container != null && !(matrix.scheme != 'release-6.0' && matrix.scheme != 'release-6.1') }}
run: |
docker cp swiftwasm-ci-buildbot:/home/build-user/swift-wasm-${{ matrix.toolchain_channel }}-SNAPSHOT-wasm32-unknown-wasi.artifactbundle.zip .
# release-6.0 doesn't have wasm32-unknown-wasip1-threads SDK support yet
Expand Down Expand Up @@ -214,6 +218,11 @@ jobs:
path: build-cache
key: ${{ steps.cache_key.outputs.SCCACHE_KEY }}

- name: Upload Swift SDK artifact bundle (wasm32-unknown-wasip1)
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.scheme }}-wasm32-unknown-wasip1-artifactbundle
path: swift-wasm-${{ matrix.toolchain_channel }}-SNAPSHOT-wasm32-unknown-wasip1.artifactbundle.zip
- name: Upload Swift SDK artifact bundle (wasm32-unknown-wasi)
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -265,10 +274,7 @@ jobs:
if: ${{ matrix.run_e2e_test }}
run: |
docker exec swiftwasm-ci-buildbot /bin/bash -lc \
"./llvm-project/llvm/utils/lit/lit.py \
--param swift-sdk=wasm32-unknown-wasi \
--param swift-sdks-path=./swift-sdk-generator/Bundles \
--param scheme=${{ matrix.scheme }} ./swiftwasm-build/test -vv"
"./swiftwasm-build/tools/build/run-e2e-test --scheme ${{ matrix.scheme }}"

- name: Cleanup docker volume
if: ${{ matrix.container != null }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $ ./tools/build/install-build-sdk.sh main
# Checkout the Swift repositories in the parent directory (swiftwasm-source) and apply patches
$ ./tools/git-swift-workspace --scheme main
# Build the toolchain (this will take a while)
$ ./tools/build/build-toolchain.sh main
$ ./tools/build/build-toolchain main
```

See [SwiftWasm book](https://book.swiftwasm.org/contribution-guide/how-to-build-toolchain.html) for more details about dependencies you need to install and how to build on Docker.
Expand Down
8 changes: 1 addition & 7 deletions docs/upstreaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ If it's first time to build or patch files are changed, you need to checkout the
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
./tools/build/build-toolchain --scheme main
```

### Edit
Expand Down
55 changes: 0 additions & 55 deletions schemes/main/build/build-foundation.sh

This file was deleted.

58 changes: 16 additions & 42 deletions schemes/main/build/build-target-toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,48 +40,22 @@ build_target_toolchain() {
env DESTDIR="$TRIPLE_DESTDIR" \
cmake --install "$TARGET_BUILD_ROOT/$STDLIB_PRODUCT-$HOST_SUFFIX" --prefix /usr

local swift_testing_build_dir="$TARGET_BUILD_ROOT/wasmswiftsdk-$HOST_SUFFIX/swift-testing/$TRIPLE"
# TODO: Remove this check once we build swift-testing for +threads target
if [[ -d "$swift_testing_build_dir" ]]; then
env DESTDIR="$TRIPLE_DESTDIR" \
cmake --install "$swift_testing_build_dir" --prefix /usr
fi
env DESTDIR="$TRIPLE_DESTDIR" \
cmake --install "$TARGET_BUILD_ROOT/wasmswiftsdk-$HOST_SUFFIX/swift-testing/$TRIPLE" --prefix /usr
env DESTDIR="$TRIPLE_DESTDIR" \
cmake --install "$TARGET_BUILD_ROOT/wasmswiftsdk-$HOST_SUFFIX/foundation/$TRIPLE" --prefix /usr
env DESTDIR="$TRIPLE_DESTDIR" \
cmake --install "$TARGET_BUILD_ROOT/wasmswiftsdk-$HOST_SUFFIX/xctest/$TRIPLE" --prefix /usr

rm -rf "$TRIPLE_DESTDIR/usr/lib/swift_static/clang/lib/$COMPILER_RT_OS_DIR"
# XXX: Is this the right way to install compiler-rt?
cp -R "$TARGET_BUILD_ROOT/wasi-sysroot/$CLANG_MULTIARCH_TRIPLE/lib/$COMPILER_RT_OS_DIR" "$TRIPLE_DESTDIR/usr/lib/swift_static/clang/lib/$COMPILER_RT_OS_DIR"

# FIXME: Clang resource directory installation is not the best way currently.
# We currently have two copies of compiler headers copied from the base toolchain in
# lib/swift/clang and lib/swift_static/clang. This is because the Swift CMake build
# system installs the compiler headers from the native tools path when not building
# tools including clang compiler. This is not ideal but then where should we bring
# the compiler headers from? If we use the headers beside the base toolchain, clang
# driver will not be able to find libclang_rt.builtins-wasm32.a because it is not
# a part of the base toolchain. We need to find a better way to handle this.
local CLANG_VERSION
CLANG_VERSION="$(basename "$($CLANG_BIN_DIR/clang -print-resource-dir)")"
mkdir -p "$TRIPLE_DESTDIR/usr/lib/clang/$CLANG_VERSION/lib"
ln -sf "../../../swift_static/clang/lib/$COMPILER_RT_OS_DIR" "$TRIPLE_DESTDIR/usr/lib/clang/$CLANG_VERSION/lib/$COMPILER_RT_OS_DIR"
}

build_target_corelibs() {
local LLVM_BIN_DIR="$1"
local CLANG_BIN_DIR="$2"
local SWIFT_BIN_DIR="$3"
local TRIPLE="$4"
local SHORT_TRIPLE="$5"

local TRIPLE_DESTDIR="$TARGET_TOOLCHAIN_DESTDIR/$TRIPLE"
local CORELIBS_ARGS=(
"$TRIPLE_DESTDIR"
"$LLVM_BIN_DIR"
"$CLANG_BIN_DIR"
"$SWIFT_BIN_DIR"
"$WASI_SYSROOT_PATH/$SHORT_TRIPLE"
)
"$SCHEMES_BUILD_PATH/build-foundation.sh" "${CORELIBS_ARGS[@]}" "$TRIPLE"
"$SCHEMES_BUILD_PATH/build-xctest.sh" "${CORELIBS_ARGS[@]}" "$TRIPLE"
# FIXME: The following is a workaround for the issue with wrong libxml2.a path
local LIBXML2_PATH_TO_FIX="$TARGET_BUILD_ROOT/wasi-sysroot/$CLANG_MULTIARCH_TRIPLE/lib/libxml2.a"
if [[ -f "$LIBXML2_PATH_TO_FIX" ]]; then
cp "$LIBXML2_PATH_TO_FIX" "$TRIPLE_DESTDIR/usr/lib/swift_static/wasi/libxml2.a"
fi
}

main() {
Expand Down Expand Up @@ -137,19 +111,22 @@ main() {

# NOTE: The llvm-cmake-options is a workaround for the issue on amazonlinux2
# See https://github.com/apple/swift/commit/40c7268e8f7d402b27e3ad16a84180e07c37f92c
"$SOURCE_PATH/swift/utils/build-script" \
# NOTE: Add llvm-bin directory to PATH so that wasmstdlib.py can find FileCheck during tests
env PATH="$OPTIONS_LLVM_BIN:$OPTIONS_SWIFT_BIN:$PATH" "$SOURCE_PATH/swift/utils/build-script" \
--build-subdir=WebAssembly \
--release \
--skip-build-llvm \
--skip-build-swift \
--skip-build-cmark \
--skip-build-benchmarks \
--skip-early-swift-driver \
--wasmkit \
--build-wasm-stdlib \
--skip-test-wasm-stdlib \
--native-swift-tools-path="$OPTIONS_SWIFT_BIN" \
--native-clang-tools-path="$OPTIONS_CLANG_BIN" \
--native-llvm-tools-path="$OPTIONS_LLVM_BIN" \
--build-runtime-with-host-compiler \
--extra-cmake-options="\
-DSWIFT_STDLIB_TRACING=NO \
-DSWIFT_STDLIB_HAS_ASL=NO \
Expand All @@ -168,13 +145,10 @@ main() {
"$OPTIONS_SWIFT_BIN"
)

build_target_toolchain "${BUILD_TOOLS_ARGS[@]}" "wasm32-unknown-wasi" "wasi-wasm32" "wasm32-wasi" "wasmstdlib" "wasi"
build_target_toolchain "${BUILD_TOOLS_ARGS[@]}" "wasm32-unknown-wasip1" "wasip1-wasm32" "wasm32-wasip1" "wasmstdlib" "wasip1"
build_target_toolchain "${BUILD_TOOLS_ARGS[@]}" "wasm32-unknown-wasip1-threads" "wasip1-threads-wasm32" "wasm32-wasip1-threads" "wasmthreadsstdlib" "wasip1"

rsync -av "$WASI_SYSROOT_PATH/" "$PACKAGING_DIR/wasi-sysroot/"

build_target_corelibs "${BUILD_TOOLS_ARGS[@]}" "wasm32-unknown-wasi" "wasm32-wasi"
build_target_corelibs "${BUILD_TOOLS_ARGS[@]}" "wasm32-unknown-wasip1-threads" "wasm32-wasip1-threads"
}

main "$@"
39 changes: 0 additions & 39 deletions schemes/main/build/build-xctest.sh

This file was deleted.

7 changes: 1 addition & 6 deletions schemes/main/build/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@

set -euxo pipefail

SOURCE_PATH="$(cd "$(dirname "$0")/../../../.." && pwd)"
BUILD_DIR="$SOURCE_PATH/build"
TARGET_BUILD_ROOT="$BUILD_DIR/WebAssembly"

HOST_SUFFIX=$(find "$TARGET_BUILD_ROOT" -name "wasmstdlib-*" -exec basename {} \; | sed 's/wasmstdlib-//')
env "PATH=$TARGET_BUILD_ROOT/llvm-$HOST_SUFFIX/bin:$BUILD_DIR/llvm-tools/bin:$PATH" "LIT_FILTER_OUT=(IRGen/|embedded/)" ninja check-swift-wasi-wasm32-custom -C "$TARGET_BUILD_ROOT/wasmstdlib-$HOST_SUFFIX"
echo "Skipping test because we now run tests in build-script"
7 changes: 2 additions & 5 deletions schemes/main/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"base-tag": "swift-DEVELOPMENT-SNAPSHOT-2025-07-18-a",
"base-tag": "swift-DEVELOPMENT-SNAPSHOT-2025-07-23-a",
"icu4c": [],
"libxml2": [
"https://github.com/swiftwasm/libxml2-wasm/releases/download/2.0.0/libxml2-wasm32-unknown-wasi.tar.gz",
"https://github.com/swiftwasm/libxml2-wasm/releases/download/2.0.0/libxml2-wasm32-unknown-wasip1-threads.tar.gz"
],
"libxml2": [],
"swift-org-download-channel": "development"
}
2 changes: 0 additions & 2 deletions test/swift-sdk/foundation/ProcessInfo.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// RUN: %{target_simple_swift_build}
// RUN: %{wasm_run} --dir %t.dir::/tmp %t.dir/.build/debug/Check.wasm | %{FileCheck} %s
// REQUIRES: FileCheck && scheme=main
// XFAIL: scheme=main
// https://github.com/swiftlang/swift-foundation/pull/1447

import Foundation

Expand Down
50 changes: 50 additions & 0 deletions tools/build/build-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3

import sys
import argparse
import pathlib
import subprocess
from build_support.actions import derive_options_from_args, REPO_ROOT, DownloadBaseSnapshotAction


def main():
parser = argparse.ArgumentParser(description='Build the Swift toolchain')
options = derive_options_from_args(sys.argv[1:], parser)

# Calculate paths
repo_path = pathlib.Path(REPO_ROOT)
source_path = repo_path.parent
tools_build_path = pathlib.Path(__file__).parent

build_dir = source_path / "build"
cross_compiler_destdir = pathlib.Path(DownloadBaseSnapshotAction.toolchain_path(options))

# Install base toolchain
print("=====> Installing base toolchain")
subprocess.check_call([
str(tools_build_path / "install-base-toolchain"),
"--scheme", options.scheme
])

# Build LLVM tools
print("=====> Building LLVM tools")
subprocess.check_call([
str(tools_build_path / "build-llvm-tools"),
"--toolchain", str(cross_compiler_destdir)
])

# Build target toolchain
print("=====> Building target toolchain")
scheme_build_script = repo_path / "schemes" / options.scheme / "build" / "build-target-toolchain.sh"

subprocess.check_call([
str(scheme_build_script),
"--llvm-bin", str(build_dir / "llvm-tools" / "bin"),
"--clang-bin", str(cross_compiler_destdir / "usr" / "bin"),
"--swift-bin", str(cross_compiler_destdir / "usr" / "bin"),
"--scheme", options.scheme
])


if __name__ == '__main__':
main()
23 changes: 0 additions & 23 deletions tools/build/build-toolchain.sh

This file was deleted.

Loading
Loading