This reimplements the underlying support for `Float16(_:StringSlice)`, `Float32(_:StringSlice)`, and `Float64(_:StringSlice)` in pure Swift, using the same core algorithm currently used by Apple's libc. Those `StringSlice` initializers are in turn used by `Float16(_:String)`, `Float32(_:String)`, and `Float64(_:String)`. **Supports Embedded**: This fully supports Embedded Swift and insulates us from variations in libc implementations. **Corrects bugs in Float16 parsing**: The previous version of `Float16` parsing called libc `strtof()` to parse to a 32-bit float, then rounded to `Float16`. (This was necessary because float16 parsing functions are not widely supported in C implementations.) This double-rounding systematically corrupted NaN payloads and resulted in 1 ULP errors for certain decimal and hexadecimal inputs. The new version parses `Float16` directly, avoiding these errors. **Modest perforamnce improvement**: The old version had to copy the Swift string to construct a C string. For inputs longer than 15 characters, this typically required a heap allocation, which added up to 20% to the runtime. The new version parses directly from a Swift string, avoiding this copy and heap allocation.
SwiftCore
SwiftCore contains core libraries that sit below the platform overlays. These include the standard library and associated runtimes, SwiftOnoneSupport, and the concurrency runtimes.
Build Instructions
Important
The standard library requires that it is built with a Swift compiler that is at least as new as the standard library sources. You will likely need to build the compiler as you would normally. In these instructions,
<swiftc>is the path to your just-built Swift compiler.
Run these commands from the Runtimes/Core directory.
Build a standard library with the default configuration. This builds for the system that the command was run on, usually resulting in a static archive without optimizations applied.
cmake -B build -S . -G Ninja -DCMAKE_Swift_COMPILER=<swiftc>
cmake --build build
DESTDIR=/tmp/staging-dir cmake --install build --prefix /usr
The DESTDIR environment variable sets the staging location so that the result
of the build isn't installed directly to /usr on the system performing the
build.
Note
The
DESTDIRenvironment variable is not portable to Windows. UseCMAKE_INSTALL_PREFIXor the--prefixflag to set the staging location.
To build the runtimes as dynamic libraries, pass -DBUILD_SHARED_LIBS=YES to
CMake.
cmake -B build -S . -G Ninja -DBUILD_SHARED_LIBS=YES -DCMAKE_Swift_COMPILER=<swiftc>
cmake --build build
To enable semantic editing, ensure you're running CMake 3.29 or newer and enable
CMAKE_EXPORT_COMPILE_COMMANDS.
cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=YES
Some editors will look under <source-root>/build for the generated
compile_commands.json while others do not.
On UNIX-like systems, run ln -s build/compile_commands.json.
On Windows, creating symlinks requires administrator privileges, but can be done
with CMake cmake -E create_symlink build\compile_commands.json compile_commands.json. If you do not have administrator privileges, you can
copy the file from your build directory into the root directory of your sources.
Note that the copied file won't be updated so you will need to copy the file
each time you re-run CMake.
The compile-commands are specific to the current build configuration, so the semantic results shown in the editor match what you are currently building.
There are many more knobs for configuration. From the build directory, run
ccmake to edit the build configuration to your liking.
Reproducing a Build
The knobs make it easy to build the standard library to your needs, but can make it challenging to reproduce a specific build configuration. CMake has cache files to specify how to position the knobs for a given configuration.
These caches live under cmake/caches, but can live anywhere.
The following command uses the x86_64-MacOSX.cmake cache file to reproduce the
Apple Intel macOS standard library build.
cmake -B build -S . -G Ninja \
-DCMAKE_OSX_DEPLOYMENT_TARGET=15.3 \
-DCMAKE_OSX_SYSROOT=macosx \
-DCMAKE_Swift_COMPILER=<swiftc> \
--toolchain cmake/caches/Vendors/Apple/Darwin.toolchain.cmake \
-C cmake/caches/Vendors/Apple/x86_64-MacOSX.cmake
cmake --build build
Note
Variables are evaluated in order of appearance on the command line. The
x86_64-MacOSX.cmakecache requires thatCMAKE_OSX_DEPLOYMENT_TARGETis set before usage. Therefore, settingCMAKE_OSX_DEPLOYMENT_TARGETmust come before specifying the cache or you will get an error message.