Commit Graph

867 Commits

Author SHA1 Message Date
Eric Miotto
f17d8909f0 [6.2] Do not require CMake to be in the path for build-script tests
(cherry picked from commit 4e854dea88)
2025-09-12 00:43:38 -07:00
Max Desiatov
2e9e12a8bd [6.2] Build CMake on macOS if one is not preinstalled
We build CMake on all platforms (except Darwin for an unknown reason) if CMake is not preinstalled. Since CMake 4.0 regresses certain build configurations, there's currently no way to build on Darwin without installing an older CMake version 3.x manually. This can be simplified if we build a pinned version of CMake consistently on all platforms.

Addresses rdar://159939866

(cherry picked from commit 7db6c5ddaa)
2025-09-05 07:19:46 -07:00
Finagolfin
1d8a95fab3 [build] Make the new --cross-compile-build-swift-tools flag public
This new flag makes it easy to build Swift cross-compilation toolchains, by
disabling cross-compilation of all host tools, like the Swift compiler and
various macros, building on prior pulls #38441 and #82163.

Also, add two class methods to the Testing macros product so it works with #83260.
2025-08-11 04:31:19 +05:30
finagolfin
2c9dcfe11f [build][android] Use a CMake toolchain file to cross-compile Testing (#83260)
Also, disable a recently failing test for Android armv7.
2025-08-11 04:31:19 +05:30
Finagolfin
9c7ae5025f Only bring over supporting change of generate_linux_toolchain_file() from fcc03898c,
specifically the change that makes the following possible on linux:

    "* under Linux, do not cross compile LLVM when building for the host
     architecture -- that will ensure that the compiler-rt build will use
    the just built compiler and not the system one (which may not be
    new enough for this purpose);"
2025-08-11 04:31:19 +05:30
Marc Prud'hommeaux
7f09af24cf Support 16 KB page sizes on Android (#81596)
Android 15+ requires that native libraries be compiled with a linker
flag to support 16 KB page sizes. See:
https://developer.android.com/guide/practices/page-sizes#compile-r26-lower
2025-08-11 04:31:19 +05:30
Yuta Saito
e25995ac5d [wasm] Fix installation paths for libxml2.a
Clang driver only passes arch-specific library paths as search paths
to the linker for WebAssembly targets but we were installing
libxml2.a under `<sysroot>/lib` without the multiarch triple. It led
to the linker not finding libxml2.a when importing FoundationXML
2025-07-27 23:07:42 +00:00
Max Desiatov
ab7cd238fd [6.2] test/CMakeLists.txt: run Embedded Swift for Wasm tests (#83287)
Cherry-pick of #83128, #82399, and #82878, merged as ea6ca2b5db, 0c4e56174b, and e34eb3331f respectively.

**Explanation**: Currently `test/CMakeLists.txt` can only set `SWIFT_LIT_ARGS` for all tests uniformly. This means that we can't have tests for Embedded Swift with a different set of `lit.py` arguments.

Also, create new `check-swift-embedded-wasi` target from `test/CMakeLists.txt`, tweak `lit.cfg` to support WASI Clang resource dir, exclude unsupported tests based on `CPU=wasm32` instead of `OS=wasi`.

**Scope**: Limited to Embedded Swift test suite.
**Risk**: Low, due to limited scope.
**Testing**: #82878 was incubated on `main` for 2 weeks, #82399 for 3 weeks with no disruption, #83128 merged this week, but enables all these tests on CI, which are consistently passing.
**Issue**: rdar://156585717
**Reviewer**: @bnbarham
2025-07-26 09:48:47 +01:00
Yuta Saito
a1a8d73ea2 [6.2][wasm] Build and install XCTest for Wasm Swift SDK (#83200)
- **Explanation**: Install static XCTest library and its Swift module files into Swift SDK for Wasm
- **Scope**: Narrow, only affects Wasm Swift SDK.
- **Original PRs**: https://github.com/swiftlang/swift/pull/83191
- **Risk**: Low, just a change to Wasm Swift SDK
- **Testing**: CI
- **Reviewers**: @MaxDesiatov
2025-07-22 23:06:50 +01:00
Yuta Saito
b7c3ceac0f [6.2][wasm] Rename wasm32-unknown-wasi to wasm32-unknown-wasip1 (#83199)
- **Explanation**: Renames the WebAssembly target triple from `wasm32-unknown-wasi` to `wasm32-unknown-wasip1` to align with the broader WebAssembly ecosystem's naming conventions. It's important to include this in 6.2, which is going to be the first stable release of Swift SDK for Wasm, so that we won't introduce a breaking triple change in the stable version series later.

  The WebAssembly ecosystem has been migrating from the generic wasi target name to more explicit version-specific names like `wasip1` and `wasip2`. This change has been adopted across multiple toolchains and language ecosystems:

  - Rust: Renamed `wasm32-wasi` to `wasm32-wasip1` (https://github.com/rust-lang/compiler-team/issues/607)
  - wasi-sdk: Renamed `wasm32-wasi` to `wasm32-wasip1` (https://github.com/WebAssembly/wasi-sdk/pull/386)
  - Go: Already uses `wasip1` naming convention (https://github.com/golang/go/issues/58141)

  The "p1" suffix explicitly indicates WASI Preview 1, which helps distinguish it from the newer WASI Preview 2 (wasip2) and provides clarity about which version of the WASI specification is being targeted.

  Also we already use `wasm32-unknown-wasip1` for Embedded WASI target, and having different names for Embedded and non-Embedded is confusing users.

- **Scope**: Narrow, only affects Wasm Swift SDK.
- **Original PRs**: https://github.com/swiftlang/swift/pull/83167
- **Risk**: Low, just a change to Wasm Swift SDK
- **Testing**: CI.
- **Reviewers**: @MaxDesiatov
2025-07-22 11:23:07 -07:00
Ben Barham
315de8dd74 Merge pull request #82516 from bnbarham/6.2-use-compiler-version
[6.2] Use SWIFT_COMPILER_VERSION before SWIFT_TOOLCHAIN_VERSION if it exists
2025-07-21 15:07:21 -07:00
finagolfin
d746436d94 Merge pull request #82986 from finagolfin/droid
[6.2][android] Small test and build tweaks
2025-07-18 15:22:47 +05:30
Max Desiatov
ba7944b743 6.2: Build and install Testing and Foundation for Wasm Swift SDK (#83059)
Cherry-pick of #82285, merged as 05204bdf63

**Explanation**: Include Swift Testing Foundation and libxml2 into the Swift SDK for WebAssembly
**Scope**: Limited to Swift SDK for Wasm
**Risk**: Low, due to limited scope. Changes were incubated on `main` for 2 weeks with no known issues. Swift Testing changes were incubated for more than a month.
**Testing**: Manual testing with Swift SDKs produced off `main`.
**Issue**: rdar://155865189
**Reviewer**: @MaxDesiatov

---------

Co-authored-by: Yuta Saito <kateinoigakukun@gmail.com>
2025-07-17 15:53:19 -07:00
Ben Barham
919bc88a31 Use SWIFT_COMPILER_VERSION before SWIFT_TOOLCHAIN_VERSION if it exists
We should eventually split these, but for now SWIFT_COMPILER_VERSION
matches SWIFT_TOOLCHAIN_VERSION when it's actually set. Just use it in
preference to SWIFT_TOOLCHAIN_VERSION.

(cherry picked from commit ec46a4f026)
2025-07-11 15:24:08 -07:00
Finagolfin
91360ab37b [build] Fix libcurl for typos and correct name of build target 2025-07-11 16:24:30 +05:30
finagolfin
43970ac2f0 [android] Fix an install path and the displayed NDK in the build log (#82620)
I just noticed the install issue when cross-compiling Testing with a
freshly-built compiler, which I'd never done before. Also, fix the NDK
path shown in the CMake output.
2025-07-11 16:21:18 +05:30
Ben Barham
3abc025579 Merge pull request #82018 from al45tair/fix-freestanding-deployment-version
[Build] Fix the minimal-stdlib build by setting a deployment version.
2025-07-08 11:25:17 +01:00
Alastair Houghton
0813e95569 Merge pull request #81440 from al45tair/currentos-availability
[Concurrency][Stdlib] Add SwiftStdlibCurrentOS availability, use it.
2025-07-07 12:04:00 +01:00
wti
ea734e2c22 [6.2] Update wasmkit toolchain build to emit universal on macOS to fix #82390 (#82406)
- **Explanation**: Build wasmkit, a new toolchain executable, as universal binary on macOS using SwiftPM --arch flags. (Cherry picked from commit 6530236)
- **Scope**: WasmKit is new, and users targeting Wasm (and preferring WasmKit over other Wasm runtimes) might be few. WasmKit can be invoked directly by users and indirectly via `swift run` when using the official Swift SDKs for Wasm.
- **Issues**: Resolves #82390
- **Original PRs**:  #82393
- **Risk**: The new configuration only affects macOS targets. The binary is output to a new location, but the code already introspects the location correctly. The bug and fix impacts users of WasmKit binary newly added to toolchain, directly and via `swift run`. Risk of no-fix: The Swift.org wasm "Getting Started" [1] refers explicitly to this (unreleased) 6.2 toolchain WasmKit binary. Without this fix, users on Apple Silicon following those instructions get an obscure "bad CPU" error because it is built only for the host x86_64 arch.
- **Testing**: @kateinoigakukun verified WasmKit is universal after change in `main`. To verify, run shell `file usr/bin/wasmkit` and verify outputs include x86_64 and arm64 arch. An outstanding question is whether to add a check that toolchain executables are universal binaries on macOS. Currently they are, except for `docc`.
- **Reviewers**: @kateinoigakukun 

[1] https://www.swift.org/documentation/articles/wasm-getting-started.html
2025-06-26 10:32:26 +01:00
Ben Barham
849cd8ee9a [Build] Pass the toolchain version through to Swift's compilation
Passes the value of the environment variable `TOOLCHAIN_VERSION` through
to Swift's `SWIFT_TOOLCHAIN_VERSION` for use in eg.
`-print-target-info` (and some day, `--version`).

(cherry picked from commit 3982ebbbb3)
2025-06-08 17:18:36 -07:00
Evan Wilde
91c92922fd Merge pull request #81788 from etcwilde/ewilde/6.2-wmo-swift-testing
Build Swift-Testing with WMO
2025-06-03 11:15:44 -07:00
Konrad `ktoso` Malawski
c8a8183d26 [6.2][Concurrency][SE-review update] Task names update (#81132)
**Description**: This adds "task name" parameter to all task creating
functions.

This is done in a few ways, e.g. we can backdeploy this to 5.1 in APIs
which do not accept the `TaskExecutor` but it they do we provide a
version for 6.0+ etc. This was requested in the SE acceptable of this
proposal [Acceptance post
SE-0469](https://forums.swift.org/t/accepted-with-modifications-se-0469-task-naming/79438).

This moves all these declarations to gyb since going through them one by
one has become unmaintainable otherwise.

**Scope/Impact**: All task creation APIs now gain a new task name
parameter.
**Risk:** Medium, changes existing APIs rather than adding "even more
overloads" though this risk was discussed in the team and accepted. This
has a potential to be source breaking it someone used Task.init and
friends as function.
**Testing**: CI testing, source compatibility suite testing
**Reviewed by**: 

**Original PR:** 
- https://github.com/swiftlang/swift/pull/81107 build changes required
for this
- https://github.com/swiftlang/swift/pull/80984


**Radar:**

---------

Co-authored-by: Kuba Mracek <mracek@apple.com>
2025-05-29 07:52:33 +09:00
Evan Wilde
379e445238 Build Swift-Testing with WMO
This tells build-script to build Swift-testing with WMO.
This results in a faster build products, but is also necessary for
configurations using the legacy swift driver, which would emit an
invalid swift interface in non-WMO builds.

Fixes: rdar://151357567
(cherry picked from commit 5f2b0022d1)
2025-05-27 14:37:03 -07:00
Max Desiatov
901885651e Set rpath correctly for installed wasmkit binary 2025-05-14 14:12:09 +01:00
Max Desiatov
25b60a5d25 Build WasmKit with the freshly-built SwiftPM 2025-05-14 14:12:09 +01:00
Max Desiatov
79e214f919 Rename wasmkit-cli to wasmkit when installing 2025-05-14 14:12:09 +01:00
Max Desiatov
2cd7de4810 Copy WasmKit to install_destdir
This enables `swift run` and `swift test` to use WasmKit when cross-compiling to Wasm with Swift SDKs that have toolsets pointing to WasmKit.
2025-05-14 14:12:08 +01:00
Max Desiatov
eb1a2960b6 Enable _Concurrency for Embedded Swift with WASI (#79292)
WASI with Embedded Swift provides WASI-libc and libc++ headers necessary to build the `_Concurrency` module for Wasm. We now add `wasm32-unknown-wasip1-wasm` triple to `EMBEDDED_STDLIB_TARGET_TRIPLES` when `SWIFT_WASI_SYSROOT_PATH` is set, which builds the necessary stdlib slice.

---------

Co-authored-by: Yuta Saito <kateinoigakukun@gmail.com>
2025-03-26 21:14:05 +00:00
Evan Wilde
321c8208f5 [build-script] Create time log dir
If the directory where the build time log is supposed to go doesn't
exist, create it. The append file mode will create files, but won't
create directories. When we start building ninja, we haven't necessary
created the build directory yet, so this results in an error about the
missing directory when writing the build time log.
2025-03-24 08:33:35 -07:00
Evan Wilde
bbd412b0dc Revert "[build-script] Remove ninja build time tracking"
This reverts commit fb4799f5d1.
2025-03-24 08:30:29 -07:00
Evan Wilde
fb4799f5d1 [build-script] Remove ninja build time tracking
Logging the build time is failing because the build log time file
doesn't always exist by the time Ninja is getting brought up.
2025-03-24 08:09:11 -07:00
Mishal Shah
deb1d9696d Merge pull request #80199 from etcwilde/ewilde/remove-ninja-host
[build-script] Remove ninja host
2025-03-21 09:43:50 -07:00
Evan Wilde
bafbfa2d46 [build-script] Remove ninja host
The ninja builder took a host argument that was unused by the function.
The ninja build failed to pass this argument, resulting in
an execution failure. Removing the argument.
2025-03-21 08:55:19 -07:00
Evan Wilde
9402a1689b Automatically choose a built ninja
Instead of using `--build-ninja` to decide to build ninja, build it
automatically if a sufficiently new enough version is not available.
Also record the build time taken to build the local Ninja so that we can
see how much time we would save by stashing a pre-built Ninja in CI.
2025-03-19 07:35:32 -07:00
Evan Wilde
d2d5925695 Disable building Ninja tests
Ninja builds its tests by default.
We don't run the Ninja test suite, we aren't doing development on Ninja,
and we are using a release tag that has been verified to work. There
isn't much point in building the tests if we're not going to use them.
Disabling building the Ninja tests. If it is desirable to build them,
one can set `BUILD_TESTING` to `YES` and re-run their build.
2025-03-18 09:32:40 -07:00
Evan Wilde
bac5232d18 Merge pull request #80034 from etcwilde/ewilde/ninja-build-fix
[build-script] Build Ninja with CMake
2025-03-16 23:15:35 -07:00
Evan Wilde
e46e3220b5 [build-script] Build Ninja with CMake
This patch switches the Ninja build from using the configure.py script
to building with the just-built CMake.
The configure.py in Ninja 1.11.1 still uses Python 2.7, importing the
`pipes` module. The pipes module was deprecated in Python 3.11 and
removed in 3.13, so folks using newer versions of Python are running
into issues with this.

The CMake build doesn't have this issue and is also perfectly valid, so
we can switch to that.
2025-03-15 08:53:38 -07:00
Evan Wilde
f7655ae393 Merge pull request #79973 from etcwilde/ewilde/build-script-cmake
[build-script] CMake bootstrapping updates
2025-03-14 18:48:15 -07:00
Evan Wilde
90bf96c104 [build-script] Don't rebuild CMake
This patch updates the CMake-building mechanism to avoid
re-bootstrapping CMake if we already bootstrapped one that is new
enough.

I've made it so that all paths through the function return the path to a
CMake so we can use the result of the function as the cmake path without
having to check.

The function will choose one of the following ways of getting CMake in
order of preference:
 - One we already built
 - The system CMake
 - Bootstrapping one from scratch

It prefers one we built over checking the system CMake because, if we
have already built a CMake previously, it's a good indication that
there either was no system CMake installed, or it wasn't new enough. We
shouldn't waste time checking it again if a previous run detected that
it wasn't good enough.

The system CMake is preferable to building one from scratch if we don't
need to though, so we determine if the system CMake is sufficient.

Finally, if one that we built either doesn't exist, or isn't new enough,
and the system either doesn't have a CMake, or a new enough CMake, build
one. It is built into the location that we are checking for caching, so
the next time we run build-script, it should hit the first case and
choose the already-built CMake instead of building it again.
2025-03-14 13:33:14 -07:00
Evan Wilde
71b7725d44 [build-script] Log CMake Bootstrap build time
Include the CMake bootstrap time in the build-script build times.
We're including everything else. Would be good to determine how much
time we can save by caching a new enough pre-built CMake in the builder
images.

Importing the log_time_in_scope exposes a cyclic dependency cycle
between the `swift_build_support` and `build_swift` python modules in
such a way that the tests fail due to re-importing parts of build_swift:

```
ImportError: Failed to import test module: tests.build_swift.test_migration
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/build-user/swift/utils/build_swift/tests/build_swift/test_migration.py", line 14, in <module>
    from build_swift import migration
  File "/home/build-user/swift/utils/build_swift/build_swift/migration.py", line 18, in <module>
    from swift_build_support.swift_build_support.targets import \
  File "/home/build-user/swift/utils/swift_build_support/swift_build_support/targets.py", line 15, in <module>
    from . import cmake
  File "/home/build-user/swift/utils/swift_build_support/swift_build_support/cmake.py", line 26, in <module>
    from swift_build_support.swift_build_support.utils import log_time_in_scope
  File "/home/build-user/swift/utils/swift_build_support/swift_build_support/utils.py", line 20, in <module>
    from build_swift.build_swift.constants import SWIFT_BUILD_ROOT
ModuleNotFoundError: No module named 'build_swift.build_swift'
```

I've put the import of log_time_in_scope into the function definition
to ensure that build_swift has been fully loaded by the time we need
log_time_in_scope, ensuring that there is order between the two pieces.

Python caches the imported module, so if we accidentally re-import the
log_time_in_scope, nothing actually changes.

This re-orders the instantiation of the BuildScriptInvocation object so
that it comes before the creation of the CMake path. This ensures that
BuildScriptInvocation() does not delete the build log after logging the
CMake bootstrap time. This is fine because the toolchain and arguments
are reference types, so updating the CMake path in both of those will be
reflected in the copy taken in the BuildScriptInvocation() object.
2025-03-14 13:33:12 -07:00
Michael Gottesman
243cfe0719 Merge pull request #79804 from gottesmm/pr-f26aec536f9d333150b49e0faf50a70a9a26ac53
Add a flag to enable-new-runtime-build that enables the new runtime build
2025-03-07 16:03:49 -08:00
Alex Hoppen
67f312cc2f Merge pull request #79834 from ahoppen/remove-syntax-lint
[build-script] Remove option to lint swift-syntax
2025-03-07 06:42:29 -08:00
Alex Hoppen
a4b8878787 Merge pull request #79827 from ahoppen/remove-swiftsyntax-verify-documentation
Remove the documentation verification step
2025-03-07 06:42:07 -08:00
Alex Hoppen
8ad0ca8c17 Remove the documentation verification step
This step is now performed by GitHub Actions.
2025-03-06 18:40:55 -08:00
Alex Hoppen
7256a92775 [build-script] Remove option to lint swift-syntax
This is being verified by GitHub Actions now as of https://github.com/swiftlang/swift-syntax/pull/2998.
2025-03-06 18:38:47 -08:00
Michael Gottesman
7418b42215 Add a flag to enable-new-runtime-build that enables the new runtime build.
What is nice about this is that by not using extra-cmake-args, we can avoid
passing this into LLVM as well when attempting to reproduce failures on the bots
(thus avoiding having to rebuild LLVM as well).
2025-03-05 14:10:26 -08:00
Michael Gottesman
f68e23aaf1 Merge pull request #79329 from gottesmm/pr-295dfc37ee8e5bf71b1249c2717a30c37de1aee2
[build-script] Add an option to force the linker used.
2025-02-14 21:09:09 -08:00
Bassam (Sam) Khouri
ac52024827 Merge pull request #79330 from bkhouri/t/main/support-swifttesting-in-swiftpm-for-toolchain-build
Add verbosity when building swiftpm
2025-02-14 12:39:09 -05:00
Sam Khouri
6e42092751 Add verbosity when building swiftpm 2025-02-12 15:37:03 -05:00
Michael Gottesman
3e2a6f6665 [build-script] Add an option to force the linker used.
I have been doing this using extra-cmake-args/etc... just feels better to have
an actual option to do this.

Just did this quickly while waiting for my Linux build to finish that uses
extra-cmake-args to set the linker.
2025-02-12 11:49:01 -08:00