Skip to content

Commit

Permalink
[native_toolchain_c] Setup Linux RISCV64 toolchain. (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmacnak-google authored Oct 25, 2023
1 parent ce26f75 commit d79a7cd
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/native_toolchain_c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class CompilerResolver {
return aarch64LinuxGnuGcc;
case Architecture.ia32:
return i686LinuxGnuGcc;
case Architecture.riscv64:
return riscv64LinuxGnuGcc;
}
}

Expand Down Expand Up @@ -158,6 +160,8 @@ class CompilerResolver {
return aarch64LinuxGnuGccAr;
case Architecture.ia32:
return i686LinuxGnuGccAr;
case Architecture.riscv64:
return riscv64LinuxGnuGccAr;
}
}
if (host.os == OS.windows) {
Expand Down
9 changes: 9 additions & 0 deletions pkgs/native_toolchain_c/lib/src/native_toolchain/gcc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ void main() {
Target.linuxArm,
Target.linuxArm64,
Target.linuxIA32,
Target.linuxX64
Target.linuxX64,
Target.linuxRiscv64,
];

const readElfMachine = {
Target.linuxArm: 'ARM',
Target.linuxArm64: 'AArch64',
Target.linuxIA32: 'Intel 80386',
Target.linuxX64: 'Advanced Micro Devices X86-64',
Target.linuxRiscv64: 'RISC-V',
};

for (final linkMode in LinkMode.values) {
Expand Down
6 changes: 6 additions & 0 deletions pkgs/native_toolchain_c/test/native_toolchain/gcc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ void main() {
i686LinuxGnuGccAr,
i686LinuxGnuLd,
]);

testToolSet('riscv64LinuxGnuGcc', [
riscv64LinuxGnuGcc,
riscv64LinuxGnuGccAr,
riscv64LinuxGnuLd,
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d79a7cd

Please sign in to comment.