Skip to content

Commit

Permalink
Map riscv64 to riscv64gc to match Rust naming (#43)
Browse files Browse the repository at this point in the history
For 64-bit RISC-V platforms, Nerves passes `riscv64` for the
architecture since that matched the tools (gcc and zig) used when Nerves
was ported to RISC-V. Rust uses `riscv64gc`. The `g` and `c` refer to
instruction sets available on the RISC-V processor, so this is a more
specific name. The `g` says that the processor supports atomics, integer
and floating point math. The `c` shows support for compressed
instructions. To my knowledge, all available 64-bit RISC-V processors
support `gc`, so this is a safe mapping.
  • Loading branch information
fhunleth authored Dec 10, 2022
1 parent 672a985 commit 700679f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rustler_precompiled.ex
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ defmodule RustlerPrecompiled do
%{target_system | arch: arch, os: "darwin"}

target_system.os =~ "linux" ->
arch = with "amd64" <- target_system.arch, do: "x86_64"
arch = normalize_linux_arch(target_system.arch)

vendor =
with vendor when vendor in ~w(pc redhat suse) <- target_system.vendor, do: "unknown"
Expand All @@ -402,6 +402,10 @@ defmodule RustlerPrecompiled do
end
end

defp normalize_linux_arch("amd64"), do: "x86_64"
defp normalize_linux_arch("riscv64"), do: "riscv64gc"
defp normalize_linux_arch(arch), do: arch

defp system_arch_to_string(system_arch) do
values =
for key <- [:arch, :vendor, :os, :abi],
Expand Down
28 changes: 28 additions & 0 deletions test/rustler_precompiled_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,34 @@ defmodule RustlerPrecompiledTest do
RustlerPrecompiled.target(config, @available_targets)
end

test "riscv64 running a Linux OS" do
config = %{
target_system: %{arch: "riscv64", vendor: "unknown", os: "linux", abi: "gnu"},
nif_version: "2.16",
os_type: {:unix, :linux}
}

assert {:ok, "nif-2.16-riscv64gc-unknown-linux-gnu"} =
RustlerPrecompiled.target(
config,
@available_targets ++ ["riscv64gc-unknown-linux-gnu"]
)
end

test "riscv64 running a Linux OS with MUSL" do
config = %{
target_system: %{arch: "riscv64", vendor: "unknown", os: "linux", abi: "musl"},
nif_version: "2.16",
os_type: {:unix, :linux}
}

assert {:ok, "nif-2.16-riscv64gc-unknown-linux-musl"} =
RustlerPrecompiled.target(
config,
@available_targets ++ ["riscv64gc-unknown-linux-musl"]
)
end

test "target not available" do
config = %{
target_system: %{arch: "i686", vendor: "unknown", os: "linux", abi: "gnu"},
Expand Down

0 comments on commit 700679f

Please sign in to comment.