swiftlang/swift-corelibs-foundation
The Foundation framework defines a base layer of functionality that is required for almost all applications. It provides primitive classes and introduces several paradigms that define functionality not provided by either the Objective-C runtime and language or Swift standard libr
Using Foundation
Here is a simple main.swift file which uses Foundation. This guide assumes you have already installed a version of the latest Swift binary distribution.
import Foundation
// Make a URLComponents instance
let swifty = URLComponents(string: "https://swift.org")!
// Print something useful about the URL
print("\(swifty.host!)")
// Output: "swift.org"You will want to use the Swift Package Manager to build your Swift apps.
Working on Foundation
swift-corelibs-foundation builds as a standalone project using Swift Package Manager. Simply use swift build in the root of the checkout to build the project.
swift-corelibs-foundation also builds as part of the toolchain for non-Darwin platforms. Instructions on building the toolchain are available in the Swift project.
Building swift-corelibs-foundation on Windows
When building Foundation as a standalone project, it requires you to provide some dependencies that it will link during the build. SwiftPM already fetches most of these dependencies and on Linux the remaining dependencies (dispatch, zlib, curl, libxml) are found in the Swift toolchain or on the host OS. However, Windows does not ship with zlib/curl/libxml on the host OS. In order to build swift-corelibs-foundation as a package on Windows, you must first checkout and build these dependenies before running swift build as recommended above. To do this, you can build the provided CMake target which (instead of building Foundation via CMake) will checkout and build these 3 dependencies via CMake and provide environment variables that will connect the SwiftPM build to these dependencies. To build these targets, run the following commands:
cmake -G Ninja -B <build folder> -DFOUNDATION_SWIFTPM_DEPS=YES
cmake --build <build folder> --target --target WindowsSwiftPMDependenciesAfter running these commands, the output will include a list of environment variables to set. After setting these environment variables, you can run swift test/swift build just like on Linux in order to build swift-corelibs-foundation with an existing Swift toolchain.
Contributions
We welcome contributions to Foundation! Please see the known issues page if you are looking for an area where we need help. We are also standing by on the mailing lists to answer questions about what is most important to do and what we will accept into the project.
Package Metadata
Repository: swiftlang/swift-corelibs-foundation
Default branch: main
README: README.md