Compare commits

...

11 Commits

Author SHA1 Message Date
openeuler-ci-bot
b685e4a0bc
!31 [sync] PR-29: riscv64: 修复rdcycle汇编指令导致的崩溃问题
From: @openeuler-sync-bot 
Reviewed-by: @sinever 
Signed-off-by: @sinever
2024-09-29 23:36:21 +00:00
laokz
7256f2d901 riscv64: fix rdcycle SIGILL of dependency abseil-cpp
(cherry picked from commit aff474883a745a4e8b153c6481e0ff9ae8d83f0b)
2024-07-30 18:30:24 +08:00
openeuler-ci-bot
ac689c25df
!26 修复bazel安装文件名
From: @wisespreading 
Reviewed-by: @zhunaipan 
Signed-off-by: @zhunaipan
2023-09-12 08:42:02 +00:00
Jincheng Miao
95f9785c43 add bazel-%{version}-%{_os}-%{_arch} to install root path 2023-09-12 16:31:16 +08:00
openeuler-ci-bot
5f9ea9b2c9
!24 升级bazel到5.3.0
From: @wisespreading 
Reviewed-by: @wx_4dd73e36e4, @zhunaipan 
Signed-off-by: @wx_4dd73e36e4, @zhunaipan
2023-09-08 14:29:17 +00:00
Jincheng Miao
97ebebf8e1 upgrade bazel to 5.3.0 for building TF-2.12.1 2023-09-08 12:16:34 +08:00
openeuler-ci-bot
184bb9c2f9
!22 修复 riscv 构建问题
From: @Jingwiw 
Reviewed-by: @sinever 
Signed-off-by: @sinever
2023-07-13 15:05:29 +00:00
Jingwiw
36a7dfade5 fix riscv64 build error and add qemu user support 2023-06-09 19:01:32 +08:00
openeuler-ci-bot
481f12d3cb
!20 升级bazel到5.1.1
From: @wisespreading 
Reviewed-by: @sinever 
Signed-off-by: @sinever
2022-11-09 16:11:50 +00:00
Jincheng Miao
af24ef0ba2 update to 5.1.1 for building TF-2.10.0
Signed-off-by: Jincheng Miao <jincheng.miao@intel.com>
2022-11-08 15:57:45 +00:00
openeuler-ci-bot
f7e6c26a48
!17 升级Bazel到5.0.0
From: @wisespreading 
Reviewed-by: @zhunaipan 
Signed-off-by: @sinever
2022-10-28 09:30:28 +00:00
8 changed files with 386 additions and 3 deletions

View File

@ -0,0 +1,15 @@
diff --git a/tools/jdk/BUILD.tools b/tools/jdk/BUILD.tools
index 85cb7b0..50d1b4e 100755
--- a/tools/jdk/BUILD.tools
+++ b/tools/jdk/BUILD.tools
@@ -106,8 +106,8 @@ cc_library(
"//src/conditions:linux_aarch64": ["include/linux"],
"//src/conditions:linux_ppc64le": ["include/linux"],
"//src/conditions:linux_s390x": ["include/linux"],
- "//src/conditions:linux_mips64": [":include/linux"],
- "//src/conditions:linux_riscv64": [":include/linux"],
+ "//src/conditions:linux_mips64": ["include/linux"],
+ "//src/conditions:linux_riscv64": ["include/linux"],
"//src/conditions:linux_x86_64": ["include/linux"],
"//src/conditions:darwin": ["include/darwin"],
"//src/conditions:freebsd": ["include/freebsd"],

64
02-use-riscv64-jdk.patch Normal file
View File

@ -0,0 +1,64 @@
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE
index a507f04..3be7b84 100755
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE
@@ -83,6 +83,21 @@ maybe(
version = "11",
)
+# This must be kept in sync with the top-level WORKSPACE file.
+maybe(
+ remote_java_repository,
+ name = "remotejdk11_linux_riscv64",
+ exec_compatible_with = [
+ "@platforms//os:linux",
+ "@platforms//cpu:riscv64",
+ ],
+ strip_prefix = "java-11-openjdk",
+ urls = [
+ "file:///build/bazel/src/remotejdk11_linux_riscv64.tar.gz",
+ ],
+ version = "11",
+)
+
# This must be kept in sync with the top-level WORKSPACE file.
maybe(
remote_java_repository,
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.tmpl b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.tmpl
index 7040eae..b783308 100755
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.tmpl
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.tmpl
@@ -66,6 +66,21 @@ maybe(
version = "11",
)
+# This must be kept in sync with the top-level WORKSPACE file.
+maybe(
+ remote_java_repository,
+ name = "remotejdk11_linux_riscv64",
+ exec_compatible_with = [
+ "@platforms//os:linux",
+ "@platforms//cpu:riscv64",
+ ],
+ strip_prefix = "java-11-openjdk",
+ urls = [
+ "file:///build/bazel/src/remotejdk11_linux_riscv64.tar.gz",
+ ],
+ version = "11",
+)
+
# This must be kept in sync with the top-level WORKSPACE file.
maybe(
remote_java_repository,
diff --git a/tools/jdk/BUILD.tools b/tools/jdk/BUILD.tools
index ecddfe0..85cb7b0 100755
--- a/tools/jdk/BUILD.tools
+++ b/tools/jdk/BUILD.tools
@@ -447,6 +447,7 @@ _JDKS = [
"remotejdk11_linux",
"remotejdk11_linux_ppc64le",
"remotejdk11_linux_s390x",
+ "remotejdk11_linux_riscv64",
"remotejdk15_macos",
"remotejdk15_macos_aarch64",
"remotejdk15_win",

View File

@ -0,0 +1,13 @@
diff --git a/src/BUILD b/src/BUILD
index 1873857..3983c08 100755
--- a/src/BUILD
+++ b/src/BUILD
@@ -376,7 +376,7 @@ genrule(
],
) for suffix, jdk in [
("-dev", "_jdk_allmodules"),
- ("", "_jdk_minimal"),
+ ("", "_nojdk"),
("_jdk_allmodules", "_jdk_allmodules"),
("_jdk_minimal", "_jdk_minimal"),
("_dev_jdk", "_dev_jdk"),

View File

@ -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",

76
abseil-cpp-riscv.patch Normal file
View File

@ -0,0 +1,76 @@
From 7335a36d0b5c1c597566f9aa3f458a5b6817c3b4 Mon Sep 17 00:00:00 2001
From: aurel32 <aurelien@aurel32.net>
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

View File

@ -1,13 +1,18 @@
%define _disable_source_fetch 0
Name: bazel
Version: 5.0.0
Release: 0
Version: 5.3.0
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
@ -26,6 +31,15 @@ Correct, reproducible, and fast builds for everyone.
%prep
%setup -q -c -n bazel-%{version}
%patch0 -p1
#%patch1 -p1
%patch2 -p1
%patch3 -p1
%ifarch riscv64
%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|' "{}" \;
@ -41,6 +55,10 @@ export EXTRA_BAZEL_ARGS="${EXTRA_BAZEL_ARGS} --nokeep_state_after_build --notrac
%else
%endif
%ifarch aarch64 %arm riscv64
export BAZEL_JAVAC_OPTS="-J-Xmx2g -J-Xms200m"
%endif
%ifarch s390x
# increase heap size to addess s390x build failures
export BAZEL_JAVAC_OPTS="-J-Xmx4g -J-Xms512m"
@ -66,6 +84,7 @@ env ./scripts/generate_bash_completion.sh --bazel=output/bazel --output=output/b
%{__mkdir_p} %{buildroot}/%{_bindir}
%{__mkdir_p} %{buildroot}/%{bashcompdir}
%{__cp} output/bazel %{buildroot}/%{_bindir}/bazel-real
%{__cp} output/bazel %{buildroot}/%{_bindir}/bazel-%{version}-%{_os}-%{_arch}
%{__cp} ./scripts/packages/bazel.sh %{buildroot}/%{_bindir}/bazel
%{__cp} output/bazel-complete.bash %{buildroot}/%{bashcompdir}/bazel
@ -76,9 +95,25 @@ env ./scripts/generate_bash_completion.sh --bazel=output/bazel --output=output/b
%defattr(-,root,root)
%attr(0755,root,root) %{_bindir}/bazel
%attr(0755,root,root) %{_bindir}/bazel-real
%attr(0755,root,root) %{_bindir}/bazel-%{version}-%{_os}-%{_arch}
%attr(0755,root,root) %{bashcompdir}/bazel
%changelog
* Tue Jul 09 2024 laokz <zhangkai@iscas.ac.cn> - 5.3.0-2
- riscv64: fix 'rdcycle' SIGILL of dependency abseil-cpp
* Tue Sep 12 2023 Jincheng Miao <jincheng.miao@intel.com> - 5.3.0-1
- add bazel-%{version}-%{_os}-%{_arch} to install root path
* Fri Sep 08 2023 Jincheng Miao <jincheng.miao@intel.com> - 5.3.0-0
- upgrade bazel to 5.3.0 for building TF-2.12.1
* Fri Jun 09 2023 Jingwiw <wangjingwei@iscas.ac.cn> - 5.1.1-1
- fix riscv64 build error and add qemu user support
* Tue Nov 8 2022 Jincheng Miao <jincheng.miao@intel.com> - 5.1.1-0
- Update version to 5.1.1 for TF-2.10.0 build
* Sat Oct 22 2022 Jincheng Miao <jincheng.miao@intel.com> - 5.0.0-0
- Update version to 5.0.0 for TF-2.9 build

View File

@ -0,0 +1,167 @@
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index a7cbde7..cf32dec 100755
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -1586,12 +1586,6 @@ int Main(int argc, const char *const *argv, WorkspaceLayout *workspace_layout,
new blaze_util::BazelLogHandler());
blaze_util::SetLogHandler(std::move(default_handler));
- const string self_path = GetSelfPath(argv[0]);
-
- if (argc == 2 && strcmp(argv[1], "--version") == 0) {
- PrintVersionInfo(self_path, option_processor->GetLowercaseProductName());
- return blaze_exit_code::SUCCESS;
- }
string cwd = GetCanonicalCwd();
LoggingInfo logging_info(CheckAndGetBinaryPath(cwd, argv[0]), start_time);
@@ -1622,6 +1616,12 @@ int Main(int argc, const char *const *argv, WorkspaceLayout *workspace_layout,
ParseOptionsOrDie(cwd, workspace, *option_processor, argc, argv);
StartupOptions *startup_options = option_processor->GetParsedStartupOptions();
startup_options->MaybeLogStartupOptionWarnings();
+ const string self_path = GetSelfPath(argv[0], *startup_options);
+
+ if (argc == 2 && strcmp(argv[1], "--version") == 0) {
+ PrintVersionInfo(self_path, option_processor->GetLowercaseProductName());
+ return blaze_exit_code::SUCCESS;
+ }
SetDebugLog(startup_options->client_debug);
// If client_debug was false, this is ignored, so it's accurate.
diff --git a/src/main/cpp/blaze_util_bsd.cc b/src/main/cpp/blaze_util_bsd.cc
index a9b81df..0aebf8f 100755
--- a/src/main/cpp/blaze_util_bsd.cc
+++ b/src/main/cpp/blaze_util_bsd.cc
@@ -46,6 +46,7 @@
#include "src/main/cpp/blaze_util.h"
#include "src/main/cpp/blaze_util_platform.h"
+#include "src/main/cpp/startup_options.h"
#include "src/main/cpp/util/errors.h"
#include "src/main/cpp/util/exit_code.h"
#include "src/main/cpp/util/file.h"
@@ -89,7 +90,7 @@ void WarnFilesystemType(const blaze_util::Path &output_base) {
}
}
-string GetSelfPath(const char* argv0) {
+string GetSelfPath(const char* argv0, const StartupOptions &options) {
#if defined(__FreeBSD__)
char buffer[PATH_MAX] = {};
auto pid = getpid();
diff --git a/src/main/cpp/blaze_util_darwin.cc b/src/main/cpp/blaze_util_darwin.cc
index c2e8e1f..33d1a96 100755
--- a/src/main/cpp/blaze_util_darwin.cc
+++ b/src/main/cpp/blaze_util_darwin.cc
@@ -124,7 +124,7 @@ void WarnFilesystemType(const blaze_util::Path &output_base) {
}
}
-string GetSelfPath(const char* argv0) {
+string GetSelfPath(const char* argv0, const StartupOptions &options) {
char pathbuf[PROC_PIDPATHINFO_MAXSIZE] = {};
int len = proc_pidpath(getpid(), pathbuf, sizeof(pathbuf));
if (len == 0) {
diff --git a/src/main/cpp/get_self_path_linux.cc b/src/main/cpp/get_self_path_linux.cc
index 2183d43..3e75ef0 100755
--- a/src/main/cpp/get_self_path_linux.cc 2023-09-07 09:45:41.310000000 +0000
+++ b/src/main/cpp/get_self_path_linux.cc 2023-09-07 09:47:28.512000000 +0000
@@ -14,8 +14,10 @@
#include <unistd.h>
#include <limits.h>
+#include <sys/auxv.h>
#include "src/main/cpp/blaze_util_platform.h"
+#include "src/main/cpp/startup_options.h"
#include "src/main/cpp/util/errors.h"
#include "src/main/cpp/util/exit_code.h"
#include "src/main/cpp/util/logging.h"
@@ -25,7 +27,14 @@ namespace blaze {
using blaze_util::GetLastErrorString;
using std::string;
-string GetSelfPath(const char* argv0) {
+string GetSelfPath(const char* argv0, const StartupOptions &options) {
+ // Sometimes /proc/self/exec isn't valid (binfmt_misc + qemu)
+ // so we provide an alternate API. e.g. Linux aarch64 running
+ // bazel-x86_64-linux
+ if (options.linux_bazel_path_from_getauxval) {
+ return reinterpret_cast<const char *>(getauxval(AT_EXECFN));
+ }
+
char buffer[PATH_MAX] = {};
ssize_t bytes = readlink("/proc/self/exe", buffer, sizeof(buffer));
if (bytes == sizeof(buffer)) {
diff --git a/src/main/cpp/blaze_util_platform.h b/src/main/cpp/blaze_util_platform.h
index 42075f1..54afa8e 100755
--- a/src/main/cpp/blaze_util_platform.h
+++ b/src/main/cpp/blaze_util_platform.h
@@ -22,6 +22,7 @@
#include <vector>
#include "src/main/cpp/blaze_util.h"
+#include "src/main/cpp/startup_options.h"
#include "src/main/cpp/server_process_info.h"
#include "src/main/cpp/util/path.h"
#include "src/main/cpp/util/port.h"
@@ -113,7 +114,7 @@ std::string Which(const std::string& executable);
// Gets an absolute path to the binary being executed that is guaranteed to be
// readable.
-std::string GetSelfPath(const char* argv0);
+std::string GetSelfPath(const char* argv0, const StartupOptions &options);
// Returns the directory Bazel can use to store output.
std::string GetOutputRoot();
diff --git a/src/main/cpp/blaze_util_windows.cc b/src/main/cpp/blaze_util_windows.cc
index 7cd1881..e84f92c 100755
--- a/src/main/cpp/blaze_util_windows.cc
+++ b/src/main/cpp/blaze_util_windows.cc
@@ -383,7 +383,7 @@ string GetProcessIdAsString() {
return blaze_util::ToString(GetCurrentProcessId());
}
-string GetSelfPath(const char* argv0) {
+string GetSelfPath(const char* argv0, const StartupOptions &options) {
WCHAR buffer[kWindowsPathBufferSize] = {0};
if (!GetModuleFileNameW(0, buffer, kWindowsPathBufferSize)) {
BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
diff --git a/src/main/cpp/startup_options.cc b/src/main/cpp/startup_options.cc
index d1e2f08..5112755 100755
--- a/src/main/cpp/startup_options.cc
+++ b/src/main/cpp/startup_options.cc
@@ -97,7 +97,8 @@ StartupOptions::StartupOptions(const string &product_name,
macos_qos_class(QOS_CLASS_UNSPECIFIED),
#endif
unlimit_coredumps(false),
- windows_enable_symlinks(false) {
+ windows_enable_symlinks(false),
+ linux_bazel_path_from_getauxval(false) {
if (blaze::IsRunningWithinTest()) {
output_root = blaze_util::MakeAbsolute(blaze::GetPathEnv("TEST_TMPDIR"));
max_idle_secs = 15;
@@ -148,6 +149,8 @@ StartupOptions::StartupOptions(const string &product_name,
RegisterNullaryStartupFlag("write_command_log", &write_command_log);
RegisterNullaryStartupFlag("windows_enable_symlinks",
&windows_enable_symlinks);
+ RegisterNullaryStartupFlag("linux_bazel_path_from_getauxval",
+ &linux_bazel_path_from_getauxval);
RegisterUnaryStartupFlag("command_port");
RegisterUnaryStartupFlag("connect_timeout_secs");
RegisterUnaryStartupFlag("local_startup_timeout_secs");
diff --git a/src/main/cpp/startup_options.h b/src/main/cpp/startup_options.h
index d6c8d02..2c60ffd 100755
--- a/src/main/cpp/startup_options.h
+++ b/src/main/cpp/startup_options.h
@@ -279,6 +279,10 @@ class StartupOptions {
// developer mode to be enabled.
bool windows_enable_symlinks;
+ // Accomodate bazel running via Linux's binfmt_misc which
+ // defeats /proc/self/exe path-finding
+ bool linux_bazel_path_from_getauxval;
+
protected:
// Constructor for subclasses only so that site-specific extensions of this
// class can override the product name. The product_name must be the