From 71c356a07fbbf1530cfc87960e975f93bc9007e8 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Tue, 22 Jul 2025 09:46:03 -0700
Subject: [PATCH] Use getrandom syscall on riscv32/riscv64 linux

Minimum kernel needed on RISCV is fairly new (4.15+) so we are sure
to have getrandom syscall, on glibc there is mimimal ABI kernel to denote
it but musl does not have any other way to indicate it, so add it
as a condition here to choose getrandom backend for rv32/rv64 on linux
when using musl.

Upstream-Status: Backport [https://github.com/rust-random/getrandom/pull/699]
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 src/backends/use_file.rs | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

--- a/src/backends.rs
+++ b/src/backends.rs
@@ -93,7 +93,15 @@ cfg_if! {
                 // Minimum supported Linux kernel version for MUSL targets
                 // is not specified explicitly (as of Rust 1.77) and they
                 // are used in practice to target pre-3.17 kernels.
-                target_env = "musl",
+                all(
+                    target_env = "musl",
+                    not(
+                        any(
+                            target_arch = "riscv64",
+                            target_arch = "riscv32",
+                        ),
+                    ),
+                ),
             ),
         )
     ))] {
