Swift on RISC-V
Hi everybody,
I would like announce Swift on RISC-V, a new project I am currently working on.
The RISC-V ecosystem is growing at a phenomenal rate and 2023 will see the introduction of many new exciting and powerful devices. From small soc boards up to large 64 / 128 core workstations and servers.
Primarily the focus on this project will be on building the swift toolchain for riscv64 devices.
Most of the core programming languages and development tools are already available for the riscv64 architecture and I think it is very important for the future of Swift to be available for riscv64 as well.
Project Goals
The main goals for the project are:-
- Setup and maintain a
riscv64 CI build server for Swift development and testing.
- Provide feedback and
#PR's to the Swift project for bugs and fixes required for RISC-V
- Port the swift toolchain to
riscv64 on Debian / Ubuntu OS's
- Build and distribute Swift for
riscv64 Debian and Ubuntu packages via the Swift Community Apt Repository.
- Build and distribute Swift
riscv64 Libraries for hardware functionality such as GPIO on the VisionFive2 board.
Project Status June 2023
- The Github organization and repositories have been setup.
- A Dev environment has been created using docker
- riscv64 hardware - Visionfive 2 boards have been received
- A Debian build server has been added to Swift Community CI Server
- The first have been #PR's uploaded to Swift repository.
Help Needed
Help is needed in many areas and everybody is welcome to join the project.
You can use Github Discussions or the Swift Forums for any questions and support.
If someone can help getting the initial #PR's noticed and merged it would be very appreciated.
RISC-V International
For more information on RISC-V and the RISC-V community please go to
RISC-V International
37 Likes
this is is really cool!
i have a couple risc-v boards (visionfive2, hifive unmatched) so if there is any help needed with testing on real hardware etc i'd be willing to help out if possible ^_^
1 Like
@andrekandore, how does the performance of the visionfive2 compare with the hifive unmatched?
visionfive 2 seems a bit better than unmatched i must say
especially the graphical performance on unmatched was not great, even with a beefy gpu (games like tux racer or whatever was fine) ... but it was very hard to use for graphical development...
i suspect it has to do with what was explain in this thread: Memory access is too slow - #13 by davidlt - HiFive Unmatched - SiFive Forums
1 Like
Great, what is the current status of building the toolchain on one of those linux riscv64 boards? Can you run the Swift compiler validation suite on linux riscv64 yet? @ColemanCDA has been working on cross-compiling the Swift stdlib for riscv64, so that may be in good shape already.
You may want to set up a CI to cross-compile the Swift toolchain to linux riscv64, after which you could transfer it to the Visionfive2 board and run the Swift tests on it. That way, you don't have to build the Swift toolchain itself on the slower riscv64 board, but only use it for testing.
That is how I build the native Swift toolchain for Android that I distribute with the Termux app, I cross-compile that Swift toolchain package from linux x86_64 to Android AArch64, armv7, and x86_64.
I'd like to help out with this RISC-V port, but I have no idea how far along it is already. Also, will you be able to provide ssh access to a few contributors on this riscv64 board? That was a big problem with the prior armv7 CI, that such access was not available to debug build failures.
1 Like
@Finagolfin, providing ssh access to the VisionFive board at the moment is not practical as the OS and firmware are not stable and are being frequently updated.
The best option for development at the moment is to use docker on an arm64 or x86_64 machine and just use the riscv64 board for final verification of patches.
See here for more info Building a Developer Environment for Riscv64 With Docker.
Setting up a CI to cross-compile the Swift toolchain to linux riscv64 is a good idea and it would be great if somebody does this.
For myself one of the main purposes of this project is to assess to current state of the riscv64 ecosystem and its ability to build the swift toolchain natively.
The initial issues I have found have been posted here - swift-riscv64/issues
One of the first issues that will need to be fixed is implementing the swiftcall calling convention on riscv64. If you could help with this that would be great.
Why would that matter for ssh access, the board may need to be rebooted sometimes? Since we would only need to log in once in awhile, I don't think that would be a big deal.
Yep, that's best for most, but I've never used Docker and don't want to. I always use real hardware and never emulators, as there are inevitably differences. Anyway, I don't think I'll have much time for this port.
What is your assessment so far? Once you get the toolchain natively compiling, it should be pretty easy to cross-compile it after that, so I can help with that.
Thanks, will keep tabs on those.
No background with that, doubt I'd help much. Glad you set this repo and CI up, so the community can contribute in whatever areas they know best.
@Finagolfin the VisionFive board is not in a rack in a cloud server farm somewhere. It is on my desk at home next to my iMac. These are prototype dev boards and updating the firmware and OS system is a bit more involved than a reboot.
PR's #66530 and #66699 have been approved and merged

Big thank you to everyone who helped with these.
7 Likes
June 2024 - Special Announcement
Hi everyone,
I am excited to announce the first release from the Swift on RISC-V project.
Swift version 5.10.1 (swift-5.10.1-RELEASE)
Target: riscv64-unknown-linux-gnu
This a complete swift toolchain for installation and use on riscv64 hardware such as the visionfive2 board.
Please Note ~
This release is not production ready and may have unexpected bugs!
Known Issues ~
-
swift repl - not working
-
swift scripting - not working - e.g. swift hello.swift
-
macros are unavailable as the toolchain is build with bootstrapping off
-
swiftc requires extra flags -Xlinker -latomic - e.g. swiftc -Xlinker -latomic hello.swift
-
swift build requires extra flags -Xlinker -latomic - e.g. swift build -Xlinker -latomic
-
swift run requires extra flags -Xlinker -latomic - e.g. swift run -Xlinker -latomic
-
swift test requires extra flags -Xlinker -latomic - e.g. swift test -Xlinker -latomic
Installation ~
The release includes both .tar.gz and .deb package files.
The easiest way to install swift is to download the .deb package and use the system apt installer.
wget https://github.com/swift-riscv/swift-riscv64/releases/download/swift-5.10.1-RELEASE/swiftlang_5.10.1-1.0.0-debian-sid_riscv64.deb
sudo apt install ./swiftlang_5.10.1-1.0.0-debian-sid_riscv64.deb
Docker ~
If you don't have any riscv64 hardware but would still like to test out swift on riscv64 there is a docker image available.
docker pull swiftarm/swift:5.10.1-debian-unstable-riscv64
docker run --platform linux/riscv64 --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -it swiftarm/swift:5.10.1-debian-unstable-riscv64 /bin/bash
Project Update
-
All development has now moved to swift-5.10.1-RELEASE and the main-branch. Older swift versions have proved to be too difficult and not viable to continue.
-
Test release of swift-5.10.1-RELEASE for riscv64 is now available!
-
A new project, Patches to Upstream, has been set up to track upstream patches being submitted to swift and all the supporting projects.
-
New riscv64 hardware is coming soon! In the coming weeks we will be receiving a new Pioneer Box will hugely reduce build times and increase productivity.
Thats all for now, hope you enjoy using swift on riscv64.
Thanks.
One more thing ~
Included in the release there is a special riscv64 version of the Vapor Toolbox.
20 Likes
Exciting news!
The new Milk-V Pioneer riscv64 workstation has arrived!
Sophon SG2042 cpu - 64 cores at 2GHz
128GB RAM
1TB nvme ssd
Performance is looking very good in initial testing.
swift-5.10.1-RELEASE - V2 is now available.
This release fixes the -Xlinker -latomic requirement.
This also enables us to use this version to bootstrap future swift builds on riscv64.
Fully bootstrapped builds with macros support should be available soon.
The Swift Community Apt Repository has been upgraded to support the riscv64 architecture.
If you have a riscv64 device running Linux - Debian or Ubuntu, swift can now be installed using the apt package manager.
curl -s https://archive.swiftlang.xyz/install.sh | sudo bash
sudo apt install swiftlang
6 Likes
This is amazing! Excellent work, can’t wait to try it out in the future
Great to hear things are moving forward! Have you tried running the compiler validation test suite on RISC-V? It would be interesting to know how that does.
Up till now we have just been focussing on achieving a successful build so have been building with no tests activated.
This was mainly due to the very slow build times of 24+ hours on the VisionFive2 boards.
Now that we have the new Pioneer Workstation we can start running all the tests and posting the results.
I am expecting lots of interesting failures.
2 Likes