diff --git a/04-riscv-distdir_deps.patch b/04-riscv-distdir_deps.patch
new file mode 100644
index 0000000000000000000000000000000000000000..e3799e62211a7b57e50fbc06cf94f355b1268ce6
--- /dev/null
+++ b/04-riscv-distdir_deps.patch
@@ -0,0 +1,13 @@
+--- a/distdir_deps.bzl 2024-07-09 14:42:34.465863400 +0800
++++ b/distdir_deps.bzl 2024-07-09 15:18:31.432886425 +0800
+@@ -163,6 +163,10 @@
+ },
+ "com_google_absl": {
+ "archive": "20211102.0.tar.gz",
++ "patch_args": ["-p1"],
++ "patches": [
++ "//third_party:abseil-cpp/abseil-cpp-riscv.patch",
++ ],
+ "sha256": "dcf71b9cba8dc0ca9940c4b316a0c796be8fab42b070bb6b7cab62b48f0e66c4",
+ "urls": [
+ "https://mirror.bazel.build/github.com/abseil/abseil-cpp/archive/refs/tags/20211102.0.tar.gz",
diff --git a/_constraints b/_constraints
new file mode 100644
index 0000000000000000000000000000000000000000..b2c280145154b5b3e4069a4344588947a93b8cca
--- /dev/null
+++ b/_constraints
@@ -0,0 +1,3 @@
+
+ chroot
+
diff --git a/abseil-cpp-riscv.patch b/abseil-cpp-riscv.patch
new file mode 100644
index 0000000000000000000000000000000000000000..26b0510d2bc64293d24d92f098578d1c199967eb
--- /dev/null
+++ b/abseil-cpp-riscv.patch
@@ -0,0 +1,76 @@
+From 7335a36d0b5c1c597566f9aa3f458a5b6817c3b4 Mon Sep 17 00:00:00 2001
+From: aurel32
+Date: Fri, 22 Mar 2024 14:21:13 -0700
+Subject: [PATCH] PR #1644: unscaledcycleclock: remove RISC-V support
+
+Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1644
+
+Starting with Linux 6.6 [1], RDCYCLE is a privileged instruction on RISC-V and can't be used directly from userland. There is a sysctl option to change that as a transition period, but it will eventually disappear.
+
+The RDTIME instruction is another less accurate alternative, however its frequency varies from board to board, and there is currently now way to get its frequency from userland [2].
+
+Therefore this patch just removes the code for unscaledcycleclock on RISC-V. Without processor specific implementation, abseil relies on std::chrono::steady_clock::now().time_since_epoch() which is basically a wrapper around clock_gettime (CLOCK_MONOTONIC), which in turns use __vdso_clock_gettime(). On RISC-V this VDSO is just a wrapper around RDTIME correctly scaled to use nanoseconds units.
+
+This fixes the testsuite on riscv64, tested on a VisionFive 2 board.
+
+[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cc4c07c89aada16229084eeb93895c95b7eabaa3
+[2] https://github.com/abseil/abseil-cpp/pull/1631
+Merge 43356a2548cfde76e164d446cb69004b488c6a71 into 76f8011beabdaee872b5fde7546e02407b220cb1
+
+Merging this change closes #1644
+
+COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1644 from aurel32:rv64-no-unscaledcycleclock 43356a2548cfde76e164d446cb69004b488c6a71
+PiperOrigin-RevId: 618286262
+Change-Id: Ie4120a727e7d0bb185df6e06ea145c780ebe6652
+---
+ absl/base/internal/unscaledcycleclock.cc | 12 ------------
+ absl/base/internal/unscaledcycleclock.h | 8 ++++----
+ 2 files changed, 4 insertions(+), 16 deletions(-)
+
+diff --git a/absl/base/internal/unscaledcycleclock.cc b/absl/base/internal/unscaledcycleclock.cc
+index 05e0e7ba..a0bf3a65 100644
+--- a/absl/base/internal/unscaledcycleclock.cc
++++ b/absl/base/internal/unscaledcycleclock.cc
+@@ -121,18 +121,6 @@ double UnscaledCycleClock::Frequency() {
+ return aarch64_timer_frequency;
+ }
+
+-#elif defined(__riscv)
+-
+-int64_t UnscaledCycleClock::Now() {
+- int64_t virtual_timer_value;
+- asm volatile("rdcycle %0" : "=r"(virtual_timer_value));
+- return virtual_timer_value;
+-}
+-
+-double UnscaledCycleClock::Frequency() {
+- return base_internal::NominalCPUFrequency();
+-}
+-
+ #elif defined(_M_IX86) || defined(_M_X64)
+
+ #pragma intrinsic(__rdtsc)
+diff --git a/absl/base/internal/unscaledcycleclock.h b/absl/base/internal/unscaledcycleclock.h
+index 24b324ac..43a3dabe 100644
+--- a/absl/base/internal/unscaledcycleclock.h
++++ b/absl/base/internal/unscaledcycleclock.h
+@@ -46,7 +46,7 @@
+
+ // The following platforms have an implementation of a hardware counter.
+ #if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || \
+- defined(__powerpc__) || defined(__ppc__) || defined(__riscv) || \
++ defined(__powerpc__) || defined(__ppc__) || \
+ defined(_M_IX86) || defined(_M_X64)
+ #define ABSL_HAVE_UNSCALED_CYCLECLOCK_IMPLEMENTATION 1
+ #else
+@@ -80,7 +80,7 @@
+
+ // This macro can be used to test if UnscaledCycleClock::Frequency()
+ // is NominalCPUFrequency() on a particular platform.
+-#if (defined(__i386__) || defined(__x86_64__) || defined(__riscv) || \
++#if (defined(__i386__) || defined(__x86_64__) || \
+ defined(_M_IX86) || defined(_M_X64))
+ #define ABSL_INTERNAL_UNSCALED_CYCLECLOCK_FREQUENCY_IS_CPU_FREQUENCY
+ #endif
+--
+2.39.2
diff --git a/bazel.spec b/bazel.spec
index 45af5abca6a8f56e59957cc901e145fc16c912e0..f0839119f56e99b54b1f265bb7216f37ded258af 100644
--- a/bazel.spec
+++ b/bazel.spec
@@ -2,15 +2,17 @@
Name: bazel
Version: 5.3.0
-Release: 1
+Release: 2
Summary: Correct, reproducible, and fast builds for everyone.
License: Apache License 2.0
URL: http://bazel.io/
Source0: https://github.com/bazelbuild/bazel/releases/download/%{version}/bazel-%{version}-dist.zip
+Source1: abseil-cpp-riscv.patch
Patch0: 01-fix-invalid-jni_md-select.patch
Patch1: 02-use-riscv64-jdk.patch
Patch2: 03-set-default-nojdk.patch
Patch3: linux-bazel-path-from-getauxval.patch
+Patch4: 04-riscv-distdir_deps.patch
# for folks with 'bazel' v1 package installed
Conflicts: bazel
Conflicts: bazel2
@@ -30,9 +32,14 @@ Correct, reproducible, and fast builds for everyone.
%prep
%setup -q -c -n bazel-%{version}
%patch0 -p1
-#%patch1 -p1
%patch2 -p1
%patch3 -p1
+%ifarch riscv64
+%patch1 -p1
+%patch4 -p1
+mkdir third_party/abseil-cpp
+cp %{SOURCE1} third_party/abseil-cpp
+%endif
%build
find . -type f -regextype posix-extended -iregex '.*(sh|txt|py|_stub|stub_.*|bazel|get_workspace_status|protobuf_support|_so)' -exec %{__sed} -i -e '1s|^#!/usr/bin/env python$|#!/usr/bin/env python3|' "{}" \;
@@ -92,6 +99,9 @@ env ./scripts/generate_bash_completion.sh --bazel=output/bazel --output=output/b
%attr(0755,root,root) %{bashcompdir}/bazel
%changelog
+* Tue Jul 09 2024 laokz - 5.3.0-2
+- riscv64: fix 'rdcycle' SIGILL of dependency abseil-cpp
+
* Tue Sep 12 2023 Jincheng Miao - 5.3.0-1
- add bazel-%{version}-%{_os}-%{_arch} to install root path