Repository navigation
Add support for riscv64 desktop linux engine - #178712
vhaudiquet wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for cross-compiling the Flutter engine for riscv64 desktop Linux. The changes span across build configurations, CI definitions, and engine tooling to recognize and build for the new target. My review identified a couple of areas for improvement: a redundant build flag definition in the GN configuration and a potential typo in a path within the new CI build definition file for riscv64. Addressing these will improve the correctness and maintainability of the build configuration.
There was a problem hiding this comment.
Do you only want to support this for local builds right now?
There was a problem hiding this comment.
I would love to be able to build that engine in CI. It would help the RISC-V community. But I don't think you want to officially build and serve that, right? So in the mean time, if it could be built by third-party CI pipelines, and unofficially distributed by the RISC-V community, I would be happy. Building locally was for testing, but that seems to be automatically buildable, right?
There was a problem hiding this comment.
We could build this in post submit rather than blocking in the merge queue. The question is do we need to support this on release builds or only at master? I'll start a chat to follow up
There was a problem hiding this comment.
If I understand correctly, you would be ready to build this in CI but without that build being required to push/merge a commit. That is wonderful news. Release builds would be better as it would almost be first-class support for RISC-V.
The main issue for me is that patch to swiftshader, which will be missing for the RISC-V build, but it seemed that patch was previously applied and reverted because it caused failure in Chromium/Chrome CI builds. I'm not sure if that is still the case though.
Please let me know about your decision!
There was a problem hiding this comment.
I missed the github notifications. Until there's a .ci.yaml update that has something like name: Linux linux_host_engine, the artifacts are not built for master or release. We do not have a riscv machine in our pools - can this be built on arm or x64?
There was a problem hiding this comment.
This can be built on x64 - but with the patch I mentioned in the PR description to third_party/swiftshader. I'm not sure how that part works, or how to send a patch there. Plus, this patch had already been sent but rolled back AFAIK (for something related to failing chromium builds).
There was a problem hiding this comment.
There's a way to do patches in engine/src/flutter/third_party - @jason-simmons might be better able to help there.
So right now, lets look at landing this; then get a patch in; then consider a x64 builder that can make artifacts at head.
There was a problem hiding this comment.
So.. took a while, but this did just land. Required more than your patch since llvm 16 and swiftshader were not happy with windows arm64.
6309083 to
7effe97
Compare
|
@vhaudiquet Also found here: They’ve been around since August of last year. Two key issues:
committing flutter changes without the above two is a bit of a hack. |
|
I've only had to apply a patch to third_party swiftshader (as explained above). Other patches seem to have already been applied, or to not be necessary anymore? I did not need anything except the swiftshader patch and this PR to build the engine. |
|
Did the llvm cipd get updated recently? If so in what version. Patches referenced are for stable (3.57.7) + llvm 21. |
|
I would think so, as effectively I tried applying my PR to the latest stable and it failed to build, so that one needed more patches. |
robert-ancell
left a comment
There was a problem hiding this comment.
Change looks generally good to me. If this is still experimental then perhaps some comments noting that or a message when building. On the other hand, this only runs if you have a RISCV builder right? So you probably know the limitations if you've done that.
|
@robert-ancell This allows cross-compiling the engine on an x86_64 host for a riscv64 target, so you don't technically need a riscv64 builder to do that. But to run that engine, you are right that you need a riscv64 host; for which I think all of the community understands that the support is experimental. But maybe we can still add a message somewhere? I see now that the "Google testing" failed. The test page says
Can somebody help with that? 😃 |
|
Ping @jtmcdole on landing and testing this. |
jtmcdole
left a comment
There was a problem hiding this comment.
This only builds locally for now. If we identify what machines we would need to build this at master, we could produce artifacts at a later time.
|
Hello @jtmcdole, happy new year! 😃 |
|
Back from holidays, let me take a look |
There was a problem hiding this comment.
There's a way to do patches in engine/src/flutter/third_party - @jason-simmons might be better able to help there.
So right now, lets look at landing this; then get a patch in; then consider a x64 builder that can make artifacts at head.
This adds support for buildind desktop linux applications for riscv64 on the flutter tool, as well as basic riscv64 support for the tool. This is a first move towards fixing #99963. Along with #178712 that allows building an engine for `riscv64`, this PR allows me to build and run the flutter 'hello world' app on RISC-V hardware: <img width="1920" height="1080" alt="Screenshot from 2025-11-18 08-58-03" src="https://github.com/user-attachments/assets/5e90bc7f-49a7-41a8-82b7-5a5d3247938a" /> This allows someone who built a flutter engine and exposed it on a webserver to run commands like: ``` export FLUTTER_STORAGE_BASE_URL=http://your-server-url flutter flutter doctor cd example/hello_world && flutter build linux ``` This means that even if Google does not want to support Flutter on RISC-V officially (hosting the artifacts), community-managed servers could host the RISC-V flutter engines/artifacts. It also means that internally, companies using Flutter on RISC-V would just have to build their engine and setup such a server, and it allows them to use the upstream Flutter tool. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: John "codefu" McDole <[email protected]>
|
Now that the tool PR has landed, is there a timeline for this one?
If I can help getting the patch in for |
The PR description says "For now, building the engine on RISC-V still requires another patch:" - since we'd be building this on x86, are we blocked waiting on this patch? @jason-simmons - can you help with how we would maintain a flutter-specific patch for: diff --git a/src/Reactor/BUILD.gn b/src/Reactor/BUILD.gn
index 67dfeb0ec..dcb13614a 100644
--- a/src/Reactor/BUILD.gn
+++ b/src/Reactor/BUILD.gn
@@ -307,7 +307,7 @@ if (supports_subzero) {
if (supports_llvm) {
swiftshader_source_set("swiftshader_llvm_reactor") {
- llvm_dir = "../../third_party/llvm-10.0"
+ llvm_dir = "../../third_party/llvm-16.0"
deps = [
":swiftshader_reactor_base", |
|
The SwiftShader upstream tried to land that patch 2 years ago. But apparently it was reverted due to an incompatibility with Chromium. If we want to use that patch in Flutter, then that would involve creating a mirror of SwiftShader on https://flutter.googlesource.com/ and adding the patch to a branch. |
Sorry, I meant for RISC-V. We will need that patch if we want to merge and build at the same time. |
|
i've created a mirror. I'll see about landing the patch there and then updating DEPs. |
|
Hey @jtmcdole this hasn't been updated in a while but is approved, are we still sitting on this? |
The idea was to merge that and also start to build the engine for riscv64 at the same time. The issue is that #181225 causes another problem, as it breaks builds on different cases, I'm not sure where (multiple tests are failing in CI, I think there are real failures on Windows and maybe others). I tried to reproduce locally but even with the swiftshader patch of #181225 the builds I tried did work 😃 I think there was a lack of time to debug that further, which is why the PR is still in this dangling state. |
|
still waiting on the patch from @jtmcdole, I've pinged him on that pr |
|
@jtmcdole friendly ping |
|
third_party/swiftshader doesn't build for me on infra. I've not had time to look into what is missing to get that building from the mirror. I can try an update the mirror / patch set sometime this week. |
Updates SwiftShader to our own mirror and applied patches for llvm16: New head commit: 1be9f83618f8ba258431c0c13d7a083eb193df11 https://flutter.googlesource.com/third_party/swiftshader/+/refs/heads/flutter-a7c547b55 ``` llvm16 + riscv on flutter Reapply "Default to use llvm16" + --- LLVM: Fix missing MCExternalSymbolizer on ARM64 This adds MCExternalSymbolizer.cpp and MCSymbolizer.cpp back to the build files by removing them from the ignore list in generate_build_files.py. It also fixes two Windows-specific bugs in generate_build_files.py that caused it to output thousands of extra files and CRLF line endings on Windows. This reverts commit 5b0479bd2d15058aaa9eb490e364f920ff824a8c. --- LLVM: Fix MSVC 14.44 build error in CFG.h Add default constructor to SuccIterator to satisfy std::default_initializable required by MSVC's C++20/C++23 std::reverse_iterator. ``` Must land before flutter#178712
it does now. |
|
Hi @jtmcdole, thank you for your work on this! |
|
I think a rebase and we should be able to review it, @vhaudiquet |
This allows to cross-compile a Flutter engine for riscv64 desktop linux from an x64 linux host
7effe97 to
16bf6f0
Compare
|
I have rebased on top of master. I have retested a build, which works, but only after others small patches.
After those two changes: I am not sure how to proceed here. I believe the second issue should be patched here, and I will add a commit on the PR for that patch (unless you advise me not to). It seems to me that it makes sense to disable that feature for every "from-source" builds, as it will break every from-source build otherwise, AFAIU. For the first issue, it gets a bit more tricky. The right solution would be to send the fix to Debian so that it gets into Trixie. Current Trixie version for that package is Another issue that we would have, though, is that Bullseye might be too old to patch (it is The only other way IMO would be a script here that applies this patch directly. Thoughts? Does everything makes sense? Do we want to take in the PR without the Debian fix, so that then we can build by manually patching, or do we want to wait until everything is ready first? Or maybe add another trixie-specific workaround that applies the patch, while hoping that Debian takes it? |
When the Dart SDK is built from source (i.e. no usable prebuilt is available for the target, such as for riscv64 Linux cross builds), exclude the wasm-opt target. Binaryen's wasm-opt is built with exceptions enabled and links the toolchain libc++, whose bundled libcxxabi exception symbols collide with the no-exceptions stubs in the engine's libcxxabi. The prebuilt Dart SDK already ships a wasm-opt binary for platforms that have one, so this only affects from-source builds.
a681ad3
The atkversion.h header in at-spi2-core (Debian Bullseye 2.38 and Trixie 2.56.2) lacks G_BEGIN_DECLS/G_END_DECLS, causing link failures when included from C++ code. This was fixed upstream in https://gitlab.gnome.org/GNOME/at-spi2-core/-/merge_requests/219 but the fix has not yet propagated to all Debian stable releases. Previously, fl_view_accessible.cc and fl_accessibility_handler_test.cc worked around this by wrapping #include <atk/atk.h> in extern "C" { }. This breaks on Trixie sysroots where atk.h pulls in headers with C++ features that cannot be inside an extern "C" block. This commit: - Adds PatchAtkVersionHeader() to install-sysroot.py, which patches atkversion.h after sysroot extraction to add G_BEGIN_DECLS/ G_END_DECLS (the same fix as upstream MR 219). Idempotent. - Removes the extern "C" workaround from fl_view_accessible.cc and fl_accessibility_handler_test.cc, relying on the patched header for proper C linkage.
|
The Debian route seems convoluted, and I have confirmed that there will be no way to fix bullseye. I have added a patch function in the sysroot setup, I believe that this is the cleaner fix, and it will also allow updating sysroots to Trixie for other arches desktop builds, so I believe this is a win-win? With this patch, the engine build succeeds 😃 |
This adds support for buildind desktop linux applications for riscv64 on the flutter tool, as well as basic riscv64 support for the tool. This is a first move towards fixing #99963. Along with flutter/flutter#178712 that allows building an engine for `riscv64`, this PR allows me to build and run the flutter 'hello world' app on RISC-V hardware: <img width="1920" height="1080" alt="Screenshot from 2025-11-18 08-58-03" src="https://github.com/user-attachments/assets/5e90bc7f-49a7-41a8-82b7-5a5d3247938a" /> This allows someone who built a flutter engine and exposed it on a webserver to run commands like: ``` export FLUTTER_STORAGE_BASE_URL=http://your-server-url flutter flutter doctor cd example/hello_world && flutter build linux ``` This means that even if Google does not want to support Flutter on RISC-V officially (hosting the artifacts), community-managed servers could host the RISC-V flutter engines/artifacts. It also means that internally, companies using Flutter on RISC-V would just have to build their engine and setup such a server, and it allows them to use the upstream Flutter tool. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: John "codefu" McDole <[email protected]>
Pin Flutter’s bootstrap engine.version to the bundled meta-flutter RISC-V engine revision before invoking Flutter. Flutter 3.47.6 otherwise regenerates engine.stamp from 692136cb6582dbfc5af3fb33c2515a069f2f66d0 rather than the seeded 5d531788691ec3404cac0cee66ead4007b177363 Dart stamp, discards the supplied SDK and fetches an unavailable riscv64 archive; prepare() fails with "End-of-central-directory signature not found". Keep the matching Dart 3.13.1 and local engine SDK. No applicable upstream bootstrap fix or meta-flutter release for the newer pinned revision was found. https://archriscv.felixc.at/.status/logs/plezy/plezy-2.22.0-1.log https://github.com/flutter/flutter/blob/3.47.6/bin/internal/update_engine_version.sh https://github.com/flutter/flutter/blob/3.47.6/bin/internal/update_dart_sdk.sh flutter/flutter#178712
This allows to cross-compile a Flutter engine for riscv64 desktop linux from an x64 linux host.
This is a first move towards fixing #99963. Along with #178711 that allows using the flutter tool on riscv64, this PR allows me to build and run the flutter 'hello world' app on RISC-V hardware:
This allows to build a Flutter engine on x64 host, and then expose the artifacts with a webserver to the flutter tool of #178711:
This means that even if Google does not want to support Flutter on RISC-V officially (hosting the artifacts), community-managed servers could host the RISC-V flutter engines/artifacts. It also means that internally, companies using Flutter on RISC-V would just have to build their engine with upstream flutter instead of relying on third-party patches.
For now, building the engine on RISC-V still requires another patch:
However once that dependency is upgraded, everything builds without issues.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.