From d79a7cdb9e1fa59df2498b7ecd08707c5c4ee8b3 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Wed, 25 Oct 2023 14:37:54 -0700 Subject: [PATCH] [native_toolchain_c] Setup Linux RISCV64 toolchain. (#163) --- .github/workflows/dart.yaml | 2 +- .github/workflows/native_toolchain_c.yaml | 2 +- .../lib/src/cbuilder/compiler_resolver.dart | 4 ++++ .../native_toolchain_c/lib/src/native_toolchain/gcc.dart | 9 +++++++++ .../test/cbuilder/cbuilder_cross_linux_host_test.dart | 4 +++- .../test/native_toolchain/gcc_test.dart | 6 ++++++ .../test/native_toolchain/recognizer_test.dart | 3 +++ 7 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dart.yaml b/.github/workflows/dart.yaml index c285821e2..77f8a6855 100644 --- a/.github/workflows/dart.yaml +++ b/.github/workflows/dart.yaml @@ -82,7 +82,7 @@ jobs: if: ${{ matrix.sdk == 'stable' }} - name: Install native toolchains - run: sudo apt-get update && sudo apt-get install clang-15 gcc-i686-linux-gnu gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf + run: sudo apt-get update && sudo apt-get install clang-15 gcc-i686-linux-gnu gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf gcc-riscv64-linux-gnu if: ${{ matrix.sdk == 'stable' && matrix.os == 'ubuntu' }} - run: dart test diff --git a/.github/workflows/native_toolchain_c.yaml b/.github/workflows/native_toolchain_c.yaml index 402a80efb..b7ed07641 100644 --- a/.github/workflows/native_toolchain_c.yaml +++ b/.github/workflows/native_toolchain_c.yaml @@ -44,7 +44,7 @@ jobs: - run: dart pub get - name: Install native toolchains - run: sudo apt-get update && sudo apt-get install gcc-i686-linux-gnu gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf + run: sudo apt-get update && sudo apt-get install gcc-i686-linux-gnu gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf gcc-riscv64-linux-gnu if: ${{ matrix.sdk == 'stable' && matrix.os == 'ubuntu' }} - run: git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart index 06209931b..cb4afb8a6 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart @@ -74,6 +74,8 @@ class CompilerResolver { return aarch64LinuxGnuGcc; case Architecture.ia32: return i686LinuxGnuGcc; + case Architecture.riscv64: + return riscv64LinuxGnuGcc; } } @@ -158,6 +160,8 @@ class CompilerResolver { return aarch64LinuxGnuGccAr; case Architecture.ia32: return i686LinuxGnuGccAr; + case Architecture.riscv64: + return riscv64LinuxGnuGccAr; } } if (host.os == OS.windows) { diff --git a/pkgs/native_toolchain_c/lib/src/native_toolchain/gcc.dart b/pkgs/native_toolchain_c/lib/src/native_toolchain/gcc.dart index 0f2477b15..3550f99ac 100644 --- a/pkgs/native_toolchain_c/lib/src/native_toolchain/gcc.dart +++ b/pkgs/native_toolchain_c/lib/src/native_toolchain/gcc.dart @@ -47,6 +47,15 @@ final aarch64LinuxGnuGccAr = _gnuArchiver('aarch64-linux-gnu'); /// [gnuLinker] with [Tool.defaultResolver] for [Architecture.arm64]. final aarch64LinuxGnuLd = _gnuLinker('aarch64-linux-gnu'); +/// [gcc] with [Tool.defaultResolver] for [Architecture.riscv64]. +final riscv64LinuxGnuGcc = _gcc('riscv64-linux-gnu'); + +/// [gnuArchiver] with [Tool.defaultResolver] for [Architecture.riscv64]. +final riscv64LinuxGnuGccAr = _gnuArchiver('riscv64-linux-gnu'); + +/// [gnuLinker] with [Tool.defaultResolver] for [Architecture.riscv64]. +final riscv64LinuxGnuLd = _gnuLinker('riscv64-linux-gnu'); + Tool _gcc(String prefix) => Tool( name: gcc.name, defaultResolver: CliVersionResolver( diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart index 0db2d1241..8abe7a492 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart @@ -24,7 +24,8 @@ void main() { Target.linuxArm, Target.linuxArm64, Target.linuxIA32, - Target.linuxX64 + Target.linuxX64, + Target.linuxRiscv64, ]; const readElfMachine = { @@ -32,6 +33,7 @@ void main() { Target.linuxArm64: 'AArch64', Target.linuxIA32: 'Intel 80386', Target.linuxX64: 'Advanced Micro Devices X86-64', + Target.linuxRiscv64: 'RISC-V', }; for (final linkMode in LinkMode.values) { diff --git a/pkgs/native_toolchain_c/test/native_toolchain/gcc_test.dart b/pkgs/native_toolchain_c/test/native_toolchain/gcc_test.dart index dad1ed4f7..570b08990 100644 --- a/pkgs/native_toolchain_c/test/native_toolchain/gcc_test.dart +++ b/pkgs/native_toolchain_c/test/native_toolchain/gcc_test.dart @@ -59,4 +59,10 @@ void main() { i686LinuxGnuGccAr, i686LinuxGnuLd, ]); + + testToolSet('riscv64LinuxGnuGcc', [ + riscv64LinuxGnuGcc, + riscv64LinuxGnuGccAr, + riscv64LinuxGnuLd, + ]); } diff --git a/pkgs/native_toolchain_c/test/native_toolchain/recognizer_test.dart b/pkgs/native_toolchain_c/test/native_toolchain/recognizer_test.dart index 40112d595..b26676ec7 100644 --- a/pkgs/native_toolchain_c/test/native_toolchain/recognizer_test.dart +++ b/pkgs/native_toolchain_c/test/native_toolchain/recognizer_test.dart @@ -39,6 +39,9 @@ void main() async { RecognizerTest(link, LinkerRecognizer.new), RecognizerTest(lld, LinkerRecognizer.new), RecognizerTest(llvmAr, ArchiverRecognizer.new), + RecognizerTest(riscv64LinuxGnuGcc, CompilerRecognizer.new), + RecognizerTest(riscv64LinuxGnuGccAr, ArchiverRecognizer.new), + RecognizerTest(riscv64LinuxGnuLd, LinkerRecognizer.new), ]; for (final test in tests) {