How can I add Foundation(swift-corelib-foundation) support in a local build toolchain on Linux? I try to pass --foundation to the build-script but it still does not work.
The full command is utils/build-script --release-debuginfo --foundation --skip-early-swift-driver --skip-early-swiftsyntax --sccache (Build against release/5.10 on Ubuntu 22)
And then I use SWIFT_EXEC to build the demo package.
SWIFT_EXEC=xx/Ninja-RelWithDebInfoAssert/swift-linux-aarch64/bin/swiftc swift build
Building for debugging...
DemoKit/Sources/DemoKit.swift:2:8: error: no such module 'Foundation'
import Foundation
You most probably need to pass --install-foundation and also corresponding flags to install dependencies of Foundation.
In general, you should only call build-script with a given preset that's known to work (which are the CI presets). Trying to build passing flags manually one-by-one will only lead to frustration most of the time, as some flags are incompatible and some have implicit dependencies on each other.
I did not see such information in GettingStarted documentation. Do I miss something here?
And which preset is recommended? My requirement is debug Swift compiler for a crash on Linux. The CI presets may not fit my needs.
Cannot look up associated type for imported conformance:
(struct_type decl=CDemoKit.(file).CAttribute)
(associated_type_decl "_ObjectiveCType" access=public overridden=)
There are no generally recommended presets as everyone's needs are different. I personally recommend presets used on CI as those more often than not lead to successful builds and you can get the test suite passing with them.
With toolchain presets you can also replicate what's published on Swift.org - Download Swift, which is important if you're trying to reproduce a bug seen in one of those toolchains.
Tried the above presets here, they both failed for the following error message
+ /home/kyle/swift-project/build/cmake-linux-aarch64/bin/cmake --build /home/kyle/swift-project/build/buildbot_linux/swift-linux-aarch64 -- -j10 all swift-stdlib-linux-aarch64 swift-libexec-linux-aarch64
ninja: error: '/home/kyle/.local/lib/swift/linux/aarch64/swiftrt.o', needed by 'bin/swift-frontend', missing and no known rule to make it
ERROR: command terminated with a non-zero exit status 1, aborting
Does it because I'm passing a wrong install_destdir/installable_package here?
build-script currently doesn't support swiftly as the latter puts the compiler and its libraries in locations that build-script doesn't expect. You need to use the same filesystem layout that upstream Swift Docker images use, or ideally and most straightforwardly just use those Docker images directly, as that replicates Swift CI setup almost exactly.
But I can't find the Docker image you are talking. The Docker images / Dockerfile linked by swift.org seems just downloading the prebuilt toolchain products instead of building them from bottom up.
That is expected. You need a preinstalled Swift toolchain to build a new toolchain with how bootstrapping works. git clone, update-checkout, and build-script invocations are not included in these Dockerfiles, you're supposed to run it yourself in a container spawned from these images.
The main point is that these images have Swift toolchains preinstalled in correct locations that build-script can handle, which is not the case with swiftly.
There's no documentation on this file that I know of. But it's relatively simple, being a collection of flags passed to build-script. One of the mixed-in presets seems to contain a release flag that you have to remove for release-debuginfo to be allowed. If this is a one-off, you can just run textual search on build-presets.ini and remove all mentions of release. Hopefully this helps.