From 87ad08f03bab1b13b45f69490ff502874ee75c25 Mon Sep 17 00:00:00 2001 From: Shahzad Malik Muzaffar Date: Thu, 25 Jul 2024 12:29:43 +0200 Subject: [PATCH 1/3] Bazel: Use Java 17 for el8 and above --- bazel.spec | 5 ++++- java-env.spec | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bazel.spec b/bazel.spec index 6b072a29565..f7020aaff1c 100644 --- a/bazel.spec +++ b/bazel.spec @@ -28,8 +28,11 @@ Patch1: bazel-absl %build -export EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//:jdk --jobs %{compiling_processes}" +export EXTRA_BAZEL_ARGS="--define=ABSOLUTE_JAVABASE=${JAVA_HOME} --jobs %{compiling_processes}" export BAZEL_CXXOPTS="-std=c++%{cms_cxx_standard}" +if [ $(${JAVA_HOME}/bin/java -version 2>&1 | head -1 | sed -E 's|.* "([0-9]+)[.].*|\1|') -ge 17 ] ; then + export JNI_FLAGS="--add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED" +fi bash ./compile.sh %install diff --git a/java-env.spec b/java-env.spec index 2a18620a49d..75e3f1ee949 100644 --- a/java-env.spec +++ b/java-env.spec @@ -1,15 +1,19 @@ -### RPM external java-env 11.0 +### RPM external java-env 11_17 ## INITENV SET JAVA_HOME %{java_home} ## INITENV +PATH PATH %{java_home}/bin ## INITENV +PATH LD_LIBRARY_PATH %{java_home}/lib ## NOCOMPILER +#For RHEL: Use java 11 for el7 and java 17 for el8 and above +#Nor non RHEL e.g FC: use default system java %define java_home /usr/lib/jvm/java %if 0%{?rhel:1} -%if 0%{?rhel} < 9 -# /usr/lib/jvm/java on EL8 contains java 1.8, and Bazel requires java 11 +%if %{?rhel} < 8 %define java_home /usr/lib/jvm/java-11 %endif +%if %{?rhel} > 7 +%define java_home /usr/lib/jvm/java-17 +%endif %endif Source: none From c9a9ca26215e11396ff747178a27fbc32332e4db Mon Sep 17 00:00:00 2001 From: Malik Shahzad Muzaffar Date: Thu, 25 Jul 2024 12:34:36 +0200 Subject: [PATCH 2/3] Update bazel.spec --- bazel.spec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bazel.spec b/bazel.spec index f7020aaff1c..fc30cde0050 100644 --- a/bazel.spec +++ b/bazel.spec @@ -30,7 +30,8 @@ Patch1: bazel-absl export EXTRA_BAZEL_ARGS="--define=ABSOLUTE_JAVABASE=${JAVA_HOME} --jobs %{compiling_processes}" export BAZEL_CXXOPTS="-std=c++%{cms_cxx_standard}" -if [ $(${JAVA_HOME}/bin/java -version 2>&1 | head -1 | sed -E 's|.* "([0-9]+)[.].*|\1|') -ge 17 ] ; then +${JAVA_HOME}/bin/java -version 2>&1 | grep -E -i 'openjdk version "[1-9]' +if [ $(${JAVA_HOME}/bin/java -version 2>&1 | grep -E -i 'openjdk version "[1-9]' | sed -E 's|.* "([0-9]+)[.].*|\1|') -ge 17 ] ; then export JNI_FLAGS="--add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED" fi bash ./compile.sh From 47744e6b062a1ad8467c4b8237107fd75916bb8d Mon Sep 17 00:00:00 2001 From: Ivan Razumov Date: Thu, 25 Jul 2024 13:56:48 +0200 Subject: [PATCH 3/3] Pass additional flags to bazel for Java 17+ --- tensorflow-sources.file | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tensorflow-sources.file b/tensorflow-sources.file index 6e0f891b017..ac87f1e98cc 100644 --- a/tensorflow-sources.file +++ b/tensorflow-sources.file @@ -42,7 +42,15 @@ export USE_DEFAULT_PYTHON_LIB_PATH=1 export GCC_HOST_COMPILER_PATH="$(which gcc)" export CC_OPT_FLAGS="-Wno-sign-compare" -BAZEL_OPTS="--batch --output_user_root ../build build -s --verbose_failures --distinct_host_configuration=false" +BAZEL_OPTS="--batch --output_user_root ../build" +# For Java17+ +if [ $(${JAVA_HOME}/bin/java -version 2>&1 | grep -E -i 'openjdk version "[1-9]' | sed -E 's|.* "([0-9]+)[.].*|\1|') -ge 17 ] ; then +BAZEL_OPTS="$BAZEL_OPTS --host_jvm_args=--add-opens=java.base/java.nio=ALL-UNNAMED" +BAZEL_OPTS="$BAZEL_OPTS --host_jvm_args=--add-opens=java.base/java.lang=ALL-UNNAMED" +fi + +BAZEL_OPTS="$BAZEL_OPTS build -s --verbose_failures --distinct_host_configuration=false" + %if "%{selected_microarch}" BAZEL_OPTS="$BAZEL_OPTS --copt=%{selected_microarch}" %if "%{selected_microarch}" != "%{default_microarch}"