diff --git a/.github/workflows/flutter-engine-riscv64.yaml b/.github/workflows/flutter-engine-riscv64.yaml new file mode 100644 index 0000000..e71c4a7 --- /dev/null +++ b/.github/workflows/flutter-engine-riscv64.yaml @@ -0,0 +1,148 @@ +name: Linux riscv64 + +on: + pull_request: + types: [ opened, synchronize, reopened, closed ] + release: + types: [ published, created, edited ] + workflow_dispatch: + +jobs: + linux-riscv64: + + env: + # TODO - hard coded for now + SRCREV: "c9b9d5780da342eb3f0f5e439a7db06f7d112575" + + runs-on: [self-hosted, linux, x64] + + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Install packages + run: | + git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git + + - name: Get Flutter Source + run: | + rm -rf out/linux_debug_riscv64|true + rm -rf out/linux_release_riscv64|true + rm -rf out/linux_profile_riscv64|true + + export PATH=$PATH:$PWD/depot_tools + export VPYTHON_VIRTUALENV_ROOT=$PWD/vpython + gclient config --spec 'solutions=[{"name":"src/flutter","url":"https://github.com/flutter/engine.git","deps_file":"DEPS","managed":False,"custom_deps":{},"custom_vars":{"download_android_deps":False,"download_windows_deps":False,"download_linux_deps":True}}]' + gclient sync --force --shallow --no-history -R -D --revision $SRCREV -j$(nproc) -v + + PATCH_DIR=$PWD/patches + + # fetch arm64 sysroot + cd src + + # setting system_libdir in args.gn does not work + git apply $PATCH_DIR/riscv64/0001-system-libdir.patch + + git apply $PATCH_DIR/0001-clang-toolchain.patch + cd flutter + git apply $PATCH_DIR/0001-export-GPU-symbols.patch + + git apply $PATCH_DIR/riscv64/0001-gn-riscv32-and-riscv64.patch + git apply $PATCH_DIR/riscv64/0002-fml-build-config-add-riscv.patch + git apply $PATCH_DIR/riscv64/0003-swiftshader-riscv-support.patch + git apply $PATCH_DIR/riscv64/0004-tonic-riscv-support.patch + + - name: Fetch sysroot & toolchain + working-directory: src/build/linux + run: | + rm -rf debian_sid_riscv64-sysroot |true + curl -L "https://drive.usercontent.google.com/download?id=1YM1OR7d_Z7KibqcUHVWuufqhsQlmH3qg&confirm=xxx" -o debian_sid_riscv64-sysroot.tar.gz + mkdir -p debian_sid_riscv64-sysroot + tar -xvzf debian_sid_riscv64-sysroot.tar.gz -C debian_sid_riscv64-sysroot + rm debian_sid_riscv64-sysroot.tar.gz + + cd ../../flutter/buildtools/linux-x64 + + rm -rf recipe-sysroot-native |true + curl -L "https://drive.usercontent.google.com/download?id=1gdV-1dJ4HD-EMWdFGAXKJwi8sFWnM1Qq&confirm=xxx" -o recipe-sysroot-native.tar.gz + tar -xvzf recipe-sysroot-native.tar.gz -C . + rm recipe-sysroot-native.tar.gz + + - name: Build Debug + working-directory: src + run: | + export PATH=$PATH:$PWD/../depot_tools + export VPYTHON_VIRTUALENV_ROOT=$PWD/vpython + ./flutter/tools/gn --runtime-mode=debug \ + --embedder-for-target \ + --no-build-embedder-examples \ + --enable-impeller-3d \ + --no-goma --no-rbe \ + --no-stripped --no-enable-unittests \ + --no-prebuilt-dart-sdk \ + --linux-cpu riscv64 \ + --target-os linux \ + --target-sysroot $PWD/build/linux/debian_sid_riscv64-sysroot \ + --target-toolchain $PWD/flutter/buildtools/linux-x64/recipe-sysroot-native/usr \ + --target-triple riscv64-unknown-linux-gnu + + ninja -C out/linux_debug_riscv64 + + - name: Publish Debug + working-directory: src/out/linux_debug_riscv64 + run: | + ls -laR exe.unstripped + ls -la *.so + + - name: Build Release + working-directory: src + run: | + export PATH=$PATH:$PWD/../depot_tools + export VPYTHON_VIRTUALENV_ROOT=$PWD/vpython + ./flutter/tools/gn --runtime-mode=release \ + --embedder-for-target \ + --no-build-embedder-examples \ + --enable-impeller-3d \ + --no-goma --no-rbe \ + --no-stripped --no-enable-unittests \ + --no-prebuilt-dart-sdk \ + --linux-cpu riscv64 \ + --target-os linux \ + --target-sysroot $PWD/build/linux/debian_sid_riscv64-sysroot \ + --target-toolchain $PWD/flutter/buildtools/linux-x64/recipe-sysroot-native/usr \ + --target-triple riscv64-unknown-linux-gnu + + ninja -C out/linux_release_riscv64 + + - name: Publish Release + working-directory: src/out/linux_release_riscv64 + run: | + ls -laR exe.unstripped + ls -la *.so + + - name: Build Profile + working-directory: src + run: | + export PATH=$PATH:$PWD/../depot_tools + export VPYTHON_VIRTUALENV_ROOT=$PWD/vpython + ./flutter/tools/gn --runtime-mode=profile \ + --embedder-for-target \ + --no-build-embedder-examples \ + --enable-impeller-3d \ + --no-goma --no-rbe \ + --no-stripped --no-enable-unittests \ + --no-prebuilt-dart-sdk \ + --linux-cpu riscv64 \ + --target-os linux \ + --target-sysroot $PWD/build/linux/debian_sid_riscv64-sysroot \ + --target-toolchain $PWD/flutter/buildtools/linux-x64/recipe-sysroot-native/usr \ + --target-triple riscv64-unknown-linux-gnu + + ninja -C out/linux_profile_riscv64 + + - name: Publish Profile + working-directory: src/out/linux_profile_riscv64 + run: | + ls -laR exe.unstripped + ls -la *.so diff --git a/patches/riscv64/0001-gn-riscv32-and-riscv64.patch b/patches/riscv64/0001-gn-riscv32-and-riscv64.patch new file mode 100644 index 0000000..007b063 --- /dev/null +++ b/patches/riscv64/0001-gn-riscv32-and-riscv64.patch @@ -0,0 +1,26 @@ +From 748e416e394552cac6e4be30112c3ef45d1c0ec3 Mon Sep 17 00:00:00 2001 +From: Joel Winarske +Date: Tue, 6 Aug 2024 08:03:59 -0700 +Subject: [PATCH] gn riscv32 and riscv64 + +Signed-off-by: Joel Winarske +--- + tools/gn | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/tools/gn b/tools/gn +index 0be76e5477..8fee233aed 100755 +--- a/tools/gn ++++ b/tools/gn +@@ -1015,7 +1015,7 @@ def parse_args(args): + parser.add_argument('--web', action='store_true', default=False) + parser.add_argument('--windows', dest='target_os', action='store_const', const='win') + +- parser.add_argument('--linux-cpu', type=str, choices=['x64', 'x86', 'arm64', 'arm']) ++ parser.add_argument('--linux-cpu', type=str, choices=['x64', 'x86', 'arm64', 'arm', 'riscv32', 'riscv64']) + parser.add_argument('--fuchsia-cpu', type=str, choices=['x64', 'arm64'], default='x64') + parser.add_argument('--windows-cpu', type=str, choices=['x64', 'arm64', 'x86'], default='x64') + parser.add_argument('--simulator-cpu', type=str, choices=['x64', 'arm64'], default='x64') +-- +2.45.2 + diff --git a/patches/riscv64/0001-system-libdir.patch b/patches/riscv64/0001-system-libdir.patch new file mode 100644 index 0000000..48f45db --- /dev/null +++ b/patches/riscv64/0001-system-libdir.patch @@ -0,0 +1,26 @@ +From 2dea579a9473d42a99fafbe79e893d49ed4475bb Mon Sep 17 00:00:00 2001 +From: Joel Winarske +Date: Tue, 27 Aug 2024 14:17:06 -0700 +Subject: [PATCH] system libdir + +Signed-off-by: Joel Winarske +--- + build/config/linux/pkg_config.gni | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/build/config/linux/pkg_config.gni b/build/config/linux/pkg_config.gni +index 3deef2b..82d0f97 100644 +--- a/build/config/linux/pkg_config.gni ++++ b/build/config/linux/pkg_config.gni +@@ -44,7 +44,7 @@ declare_args() { + # chrome build scheme. This variable permits controlling this for GN builds + # in similar fashion by setting the `system_libdir` variable in the build's + # args.gn file to 'lib' or 'lib64' as appropriate for the target architecture. +- system_libdir = "lib" ++ system_libdir = "lib/riscv64-linux-gnu" + } + + pkg_config_script = "//build/config/linux/pkg-config.py" +-- +2.25.1 + diff --git a/patches/riscv64/0002-fml-build-config-add-riscv.patch b/patches/riscv64/0002-fml-build-config-add-riscv.patch new file mode 100644 index 0000000..c830600 --- /dev/null +++ b/patches/riscv64/0002-fml-build-config-add-riscv.patch @@ -0,0 +1,34 @@ +From 8b34fbdace418dcf338492ac63ce1048ecc20bf5 Mon Sep 17 00:00:00 2001 +From: Joel Winarske +Date: Wed, 13 Mar 2024 21:28:43 +0000 +Subject: [PATCH] fml build config add riscv + +Signed-off-by: Joel Winarske +--- + fml/build_config.h | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/fml/build_config.h b/fml/build_config.h +index d42a88e..9ee6e04 100644 +--- a/fml/build_config.h ++++ b/fml/build_config.h +@@ -93,6 +93,16 @@ + #define FML_ARCH_CPU_ARM64 1 + #define FML_ARCH_CPU_64_BITS 1 + #define FML_ARCH_CPU_LITTLE_ENDIAN 1 ++#elif defined(__riscv) ++#define FML_ARCH_CPU_RISC_FAMILY 1 ++#if (__riscv_xlen == 32) ++#define FML_ARCH_CPU_RISCV32 1 ++#define FML_ARCH_CPU_32_BITS 1 ++#elif (__riscv_xlen == 64) ++#define FML_ARCH_CPU_RISCV64 1 ++#define FML_ARCH_CPU_64_BITS 1 ++#endif ++#define FML_ARCH_CPU_LITTLE_ENDIAN 1 + #elif defined(__pnacl__) + #define FML_ARCH_CPU_32_BITS 1 + #define FML_ARCH_CPU_LITTLE_ENDIAN 1 +-- +2.44.0 + diff --git a/patches/riscv64/0003-swiftshader-riscv-support.patch b/patches/riscv64/0003-swiftshader-riscv-support.patch new file mode 100644 index 0000000..cf76b4a --- /dev/null +++ b/patches/riscv64/0003-swiftshader-riscv-support.patch @@ -0,0 +1,26 @@ +From 9d3788480dba3dcc27cd00d4852c968b0e5de502 Mon Sep 17 00:00:00 2001 +From: Joel Winarske +Date: Sun, 4 Aug 2024 20:41:17 +0000 +Subject: [PATCH] swiftshader-riscv + +Signed-off-by: Joel Winarske +--- + third_party/swiftshader/src/Reactor/BUILD.gn | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/third_party/swiftshader/src/Reactor/BUILD.gn b/third_party/swiftshader/src/Reactor/BUILD.gn +index 67dfeb0..dcb1361 100644 +--- a/third_party/swiftshader/src/Reactor/BUILD.gn ++++ b/third_party/swiftshader/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", +-- +2.45.2 + diff --git a/patches/riscv64/0004-tonic-riscv-support.patch b/patches/riscv64/0004-tonic-riscv-support.patch new file mode 100644 index 0000000..babb3fc --- /dev/null +++ b/patches/riscv64/0004-tonic-riscv-support.patch @@ -0,0 +1,34 @@ +From 9be5e09115a693ab7fc8cee2122d0a4318fc6e71 Mon Sep 17 00:00:00 2001 +From: Joel Winarske +Date: Sun, 4 Aug 2024 20:53:56 +0000 +Subject: [PATCH] tonic riscv support + +Signed-off-by: Joel Winarske +--- + third_party/tonic/common/build_config.h | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/third_party/tonic/common/build_config.h b/third_party/tonic/common/build_config.h +index 365808a1a7..f3edb471be 100644 +--- a/third_party/tonic/common/build_config.h ++++ b/third_party/tonic/common/build_config.h +@@ -88,6 +88,16 @@ + #define ARCH_CPU_ARM64 1 + #define ARCH_CPU_64_BITS 1 + #define ARCH_CPU_LITTLE_ENDIAN 1 ++#elif defined(__riscv) ++#define FML_ARCH_CPU_RISC_FAMILY 1 ++#if (__riscv_xlen == 32) ++#define ARCH_CPU_RISCV32 1 ++#define ARCH_CPU_32_BITS 1 ++#elif (__riscv_xlen == 64) ++#define ARCH_CPU_RISCV64 1 ++#define ARCH_CPU_64_BITS 1 ++#endif ++#define ARCH_CPU_LITTLE_ENDIAN 1 + #elif defined(__pnacl__) + #define ARCH_CPU_32_BITS 1 + #define ARCH_CPU_LITTLE_ENDIAN 1 +-- +2.45.2 +