ladybird: Swift 6.0 Blockers
List of issues preventing moving forward on moving Swift 6.0 support out of an experimental state:
Swift issues:
-
https://github.com/swiftlang/llvm-project/issues/8998
Details: Swift’s version of LLVM is missing the fix for https://github.com/llvm/llvm-project/issues/53815. This means that any assertions build of llvm from the swift open source project cannot build our code. Snapshot builds are released with assertions on.
Workaround: Build swift from source on Linux without llvm assertions, or use macOS.
PR: https://github.com/swiftlang/llvm-project/pull/9038
Fixed in Swift 6.0.0 release
-
https://github.com/swiftlang/swift/issues/75593
Details: It is not currently possible to return a swift optional of a small C++ type back to C++. The compiler and the generated bridging header disagree on how that is supposed to be done.
Workaround: Don’t use Optional, use a return type that forces the C++ type to be heap allocated. Array is one alternative.
-
https://github.com/swiftlang/swift/issues/75661
Details: Swift’s clang module map for libstdc++ contains cycles when
<execution>is included. See https://forums.swift.org/t/swift-5-9-release-on-ubuntu-22-04-fails-to-build-std-module/67659Workaround: Edit
<prefix>/lib/swift/linux/libstdcxx.hto comment out the#include <execution>line.PR: https://github.com/swiftlang/swift/pull/75662 (Just a workaround, not a fix) 6.0 Backport: https://github.com/swiftlang/swift/pull/75971 Fixed in swiftlang/swift:main and release/6.0, but not in 6.0.0 or 6.0.1
-
https://github.com/swiftlang/swift/issues/76024
Details: Returning binding types
swift::Optional<T>orswift::Stringfrom a C++ function is not supportedWorkaround: Return std:: types?
-
https://github.com/swiftlang/swift/issues/76809
Details: Swift 6.0 cannot import libstdc+±13 or higher
<chrono>header.Workaround: Use libc++ or a lower libstdc++ version. libstdc+±13 is default on Ubuntu 24.04 LTS.
Fixed in swiftlang/swift:main as of Oct 18, 2024
-
https://github.com/swiftlang/swift/issues/80065
Details: SIL verifier crash when trying to compare unsafe reference types by pointer
Workaround: Disable SIL verification (!! yikes) Fixed in https://github.com/swiftlang/swift/pull/81614
-
https://github.com/swiftlang/swift/issues/80182
Details: SWIFT_UNSAFE_REFERENCE types with getters/setters for bitfields crash the frontend
Workaround: … don’t use SWIFT_UNSAFE_REFERENCE? unsure. Need guidance Fixed in https://github.com/swiftlang/swift/pull/80197
-
https://github.com/swiftlang/swift/issues/77607
Details:
Vector<u32, 2>is not recognized asCxxConvertibleToContainerWorkaround: Treat it as a sequence instead, and any transfer to a swift type requires manual copying of elements -
https://github.com/swiftlang/swift/issues/81774
Details: Swift fails to import clang modules with
#include <math.h>with libstdc+±15 installed.Workaround: None (!!)
CMake issues:
-
https://gitlab.kitware.com/cmake/cmake/-/issues/26174
Details: Swift + Ninja doesn’t respect CMAKE_OSX_DEPLOYMENT_TARGET. This results in a mismatched LC_BUILD_VERSION on swift and c++ object files, spamming the console with warnings.
-
https://gitlab.kitware.com/cmake/cmake/-/issues/26175
Details: With CMP0157 enabled, swiftc does not set install_name directory to “@rpath” per CMAKE_INSTALL_NAME_DIR
PR: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9692. Merged Aug 2, 2024 to be backported to CMake 3.29, 3.30.
-
https://gitlab.kitware.com/cmake/cmake/-/issues/26195
Details: Imported targets from dependencies can have INTERFACE_COMPILE_OPTIONS or INTERFACE_LINK_OPTIONS that swiftc doesn’t understand.
Workaround: Swizzle the flags just after import, for every single imported library.
Ladybird issues:
-
https://github.com/LadybirdBrowser/ladybird/pull/965
Details: Creating a modulemap for larger libraries can cause issues with libc headers. For example, creating an umbrella directory entry for LibGfx causes issues with
<math.h>, which is clearly included in every file that is complaining about it. Needs more module.modulemap massaging to get the clang frontend/swiftc to properly associate system headers with system modules and not our own modulesWorkaround: ¯\_(ツ)_/¯ Resolution: Generate module maps for each library
-
https://github.com/LadybirdBrowser/ladybird/issues/1101
Details: Building the CxxSequence protocol conformance test for AK containers crashes the swift frontend process in debug mode
Workaround: Build in release mode lmao Upstream bug: Not yet reduced
-
https://github.com/LadybirdBrowser/ladybird/issues/1102
Details: A function that takes an unnamespaced
Stringargument will crash the swift frontend ifAKis importedWorkaround: Qualify all references to String as AK.String or Swift.String Upstream bug: https://github.com/swiftlang/swift/issues/82108
-
https://github.com/LadybirdBrowser/ladybird/issues/1201
Details: Using swift-testing to test AK container conformance to swift interop protocols crashes the frontend
Workaround: Keep custom test runner code Upstream bug: Not yet reduced
-
https://github.com/LadybirdBrowser/ladybird/issues/2168
Details: AK::StringView fails to conform to CxxSequenceType on swift/main
Workaround: Reach into the bytesUnsafe() in order to iterate over the bytes of the view as a sequence Upstream bug: Not yet reduced
Nice-to-have:
-
https://github.com/swiftlang/swift/issues/79767
Details: Returning MyCxx.CxxType? from a swift function that is called from C++ crashes on call.
Workaround: Return as [MyCxx.CxxType] instead, with a 0 or 1-sized array
-
https://github.com/swiftlang/vscode-swift/issues/1449
Details: Top-level compile_commands.json is required for SourceKit-LSP and vscode-swift to grok the project
Workaround: Create a symlink
ln -s Build/release/compile_commands.json compile_commands.json -
https://github.com/swiftlang/swift/issues/80142
Details: An extra include path is required to include
<swift/bridging>on LinuxWorkaround: Grab the path from
swiftc -print-target-info
Open questions:
-
Unclear how to pass view types or byte slices to swift without creating a copy.
- We will want to be passing untrusted Strings, or c+±owned Spans of bytes to swift for it to crunch on and return some structured data. It’s not clear how to inform swift about this without copying the data (at least) once.
I was not able to massage swift into interpreting our String and StringView types as ‘CxxConvertibleToContainer’ or ‘CxxRandomAccessContainer’ types. Likely because they are actually immutable?
-
Unclear how to convince Swift that our types are just as good as std:: ones.
- AK::Optional
- AK::HashTable/HashMap
- AK::Time
- more?
-
How to integrate with our garbage collector? https://forums.swift.org/t/ladybird-browser-and-swift-garbage-collection/76084
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 17 (13 by maintainers)
Thanks for your feedback, but like I said, this issue is for technical issues with our specific implementation. If you want to debate the merits of using Swift for an open source project, please do it in the appropriate forum.
We have done our technical diligence regarding this experiment, and suggestions otherwise are not helpful for meeting the goals of the project
@ADKaster BSDs are not “downstream distros”. These are entirely separate and complete operating systems with their own kernels and userlands.
Today no swift compiler exists for these 3 operating systems and I don’t think there will ever be one. I urge you to reconsider the choice of swift. Literally any other language will have better cross-platform and cross-OS support.
Please reconsider the choice of the successor language. Swift is not really supported on Linux (and very little opensource software is written in Swift for Linux) and not even available on BSDs. This will make Ladybird browser a Windows/OSX only browser.
It will be very sad to loose new web browser to closed-source commercial OSes.
As Sam said, I meant to refer to any package or port that distributes the application for their operating system, not to classify the BSDs as Linux Distros.
There is documentation from 2022 for building Swift on OpenBSD. https://github.com/swiftlang/swift/blob/main/docs/OpenBSD.md. The technical challenges with the latest efforts of porting Swift to FreeBSD seem llvm related. The issues with updating Swift to work on more BSD platforms are technical problems, not political ones. Unless there’s BSD mailing list drama I’m not aware of. But that would still be out of scope for our project.
As you mentioned, there are no large and/or popular open source desktop applications using Swift (to my knowledge). I can’t think of a better way to energize Swift porting efforts than to prove that such a thing is possible on non-macOS Unix systems.
It appears as though the fix for the libstdcxx issue was merged into swift nightly and 6.0.3. https://github.com/swiftlang/swift/pull/75971#issuecomment-2690553245
This may be offtopic but why swift that isn’t there yet and not a language that is there already like the D programming language? D has good interop with C and C++ and is available on many platforms. I don’t see what Swift has that D doesn’t have except problems. I’d write it on YT not to bother anyone here but as everyone knows they are broken and half of them are never shown.
Indeed I misunderstood the meaning of downstream in this context.
I do not want to discourage the optimism and I hope that Ladybird will succeed. The opensource ecosystem desperately needs “new blood” in the browser section. But lets look at the facts:
Swift was first released in 2014 and Linux always was a second-class citizen (example - Swift’s stable ABI for dynamically loaded libraries only works on OSX). 10 years is plenty of time to “grow” support for various platforms but somehow Swift didn’t do it - comparing to literally any other LLVM based language. The hope that by 2026 the situation will somehow change is thin.
Swift’s C++ interop is still WIP. This means that you are inviting a whole new class of language interop bugs into the project that will be difficult to debug.
Introduction of any second language into the project inevitably slows the progress down, creates unnecessary context switch for humans and diverges a lot of energy into rewriting existing functionality. Needless to say that most rewrites never finish.
It does seem like you are subscribing yourselves to more work than you expect:
P.S. Have you looked at Herb Sutter’s cppfront? (https://hsutter.github.io/cppfront/) It is a lot less invasive way to get nice things in a C++ project
You’re misquoting/misunderstanding him. He said “downstreams like distros”. Anywhere that packages Ladybird, whether it’s a distro or a different OS like one of the BSDs or Haiku etc, is downstream of our repo.
Ladybird isn’t going into early alpha until 2026, and then a proper release will be years after that. There’s plenty of time for Swift support to develop on those other OSes. The Swift compiler is based on LLVM so the amount of porting required shouldn’t be too huge. (Though I haven’t looked into it.) Even on Linux the Swift situation is a little rough right now, but it’ll improve with time.
Unfortunately the fix for the c++23 std::chrono::time_zone w/gcc issue https://github.com/swiftlang/swift/issues/76809, https://github.com/swiftlang/swift/pull/77098 doesn’t exist in the 6.0.x branch. We’ll have to keep using main on linux until that’s in. I’ll need to get some useful swift changes in for linux to actually get a CI going to keep track of these sorts of things better