From 7dfbb170263ef87ecb192ea6d73aef9c454c0bbb Mon Sep 17 00:00:00 2001 From: Alex Rain Date: Wed, 21 Sep 2022 20:31:59 +0800 Subject: [PATCH 1/2] Squashed commits, fix riscv64 patch with minimize changes to upstream - removed gcc10 patch - removed env_python.patch as upstream had provided workaround - keep old patches & changelogs --- add_cpu_riscv.patch | 10 + add_toolchain_support_for_riscv64.patch | 239 ++++++++++++++++++++++++ bazel.spec | 14 +- env_python3.patch | 149 +++++++++++++++ support-mips64el-and-riscv64.patch | 21 +++ 5 files changed, 432 insertions(+), 1 deletion(-) create mode 100644 add_cpu_riscv.patch create mode 100644 add_toolchain_support_for_riscv64.patch create mode 100644 env_python3.patch create mode 100644 support-mips64el-and-riscv64.patch diff --git a/add_cpu_riscv.patch b/add_cpu_riscv.patch new file mode 100644 index 0000000..a436f0a --- /dev/null +++ b/add_cpu_riscv.patch @@ -0,0 +1,10 @@ +--- a/src/test/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunctionTest.java 1980-01-01 00:00:00.000000000 +0800 ++++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunctionTest.java 2022-01-21 11:28:18.888515000 +0800 +@@ -52,6 +52,7 @@ + new Object[] {CPU.PPC, "@platforms//cpu:ppc"}, + new Object[] {CPU.ARM, "@platforms//cpu:arm"}, + new Object[] {CPU.AARCH64, "@platforms//cpu:aarch64"}, ++ new Object[] {CPU.RISCV64, "@platforms//cpu:riscv64"}, + new Object[] {CPU.S390X, "@platforms//cpu:s390x"}); + } + diff --git a/add_toolchain_support_for_riscv64.patch b/add_toolchain_support_for_riscv64.patch new file mode 100644 index 0000000..314b3d4 --- /dev/null +++ b/add_toolchain_support_for_riscv64.patch @@ -0,0 +1,239 @@ +Description: Add toolchain support for the riscv64 architecture + Based on the mips64el toolchain patch by Yun Peng +Author: Olek Wojnar +Forwarded: not-needed +Last-Update: 2021-01-22 + +--- a/src/conditions/BUILD ++++ b/src/conditions/BUILD +@@ -53,6 +53,12 @@ + ) + + config_setting( ++ name = "linux_riscv64", ++ values = {"cpu": "riscv64"}, ++ visibility = ["//visibility:public"], ++) ++ ++config_setting( + name = "darwin", + values = {"cpu": "darwin"}, + visibility = ["//visibility:public"], +--- a/src/conditions/BUILD.tools ++++ b/src/conditions/BUILD.tools +@@ -41,6 +41,12 @@ + ) + + config_setting( ++ name = "linux_riscv64", ++ values = {"cpu": "riscv64"}, ++ visibility = ["//visibility:public"], ++) ++ ++config_setting( + name = "linux_aarch64", + values = {"cpu": "aarch64"}, + visibility = ["//visibility:public"], +--- a/src/main/java/com/google/devtools/build/lib/analysis/config/AutoCpuConverter.java ++++ b/src/main/java/com/google/devtools/build/lib/analysis/config/AutoCpuConverter.java +@@ -61,6 +61,8 @@ + return "aarch64"; + case S390X: + return "s390x"; ++ case RISCV64: ++ return "riscv64"; + default: + return "unknown"; + } +@@ -102,4 +104,6 @@ + return Pair.of(CPU.S390X, OS.LINUX); ++ } else if (input.equals("riscv64")) { ++ return Pair.of(CPU.RISCV64, OS.LINUX); + } + + // Use the auto-detected values. +--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunction.java ++++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunction.java +@@ -118,4 +118,6 @@ + return "@platforms//cpu:s390x"; ++ case RISCV64: ++ return "@platforms//cpu:riscv64"; + default: + // Unknown, so skip it. + return null; +--- a/src/main/java/com/google/devtools/build/lib/util/CPU.java ++++ b/src/main/java/com/google/devtools/build/lib/util/CPU.java +@@ -28,5 +28,6 @@ + AARCH64("aarch64", ImmutableSet.of("aarch64")), + S390X("s390x", ImmutableSet.of("s390x", "s390")), ++ RISCV64("riscv64", ImmutableSet.of("riscv64")), + UNKNOWN("unknown", ImmutableSet.of()); + + private final String canonicalName; +--- a/third_party/BUILD ++++ b/third_party/BUILD +@@ -557,5 +557,6 @@ + "//src/conditions:linux_ppc": "*.so *.jnilib *.dll", + "//src/conditions:linux_s390x": "*.so *.jnilib *.dll", ++ "//src/conditions:linux_riscv64": "*.so *.jnilib *.dll", + "//src/conditions:freebsd": "*.so *.jnilib *.dll", + "//src/conditions:openbsd": "*.so *.jnilib *.dll", + # Default is to play it safe -- better have a big binary than a slow binary +@@ -748,6 +749,11 @@ + values = {"host_cpu": "s390x"}, + ) + ++config_setting( ++ name = "riscv64", ++ values = {"host_cpu": "riscv64"}, ++) ++ + config_setting( + name = "ppc", + values = {"host_cpu": "ppc"}, +--- a/tools/cpp/BUILD.tools ++++ b/tools/cpp/BUILD.tools +@@ -108,5 +108,6 @@ + "s390x|compiler": ":cc-compiler-s390x", + "ppc|compiler": ":cc-compiler-ppc", ++ "riscv64|compiler": ":cc-compiler-riscv64", + "k8": ":cc-compiler-local", + "piii": ":cc-compiler-local", + "arm": ":cc-compiler-local", +@@ -115,5 +116,6 @@ + "ppc": ":cc-compiler-local", + "ppc64": ":cc-compiler-local", ++ "riscv64": ":cc-compiler-local", + "darwin": ":cc-compiler-darwin", + "freebsd": ":cc-compiler-freebsd", + "armeabi-v7a": ":cc-compiler-armeabi-v7a", +@@ -238,6 +240,33 @@ + toolchain_type = ":toolchain_type", + ) + ++cc_toolchain( ++ name = "cc-compiler-riscv64", ++ all_files = ":empty", ++ ar_files = ":empty", ++ as_files = ":empty", ++ compiler_files = ":empty", ++ dwp_files = ":empty", ++ linker_files = ":empty", ++ objcopy_files = ":empty", ++ strip_files = ":empty", ++ supports_param_files = 1, ++ toolchain_config = ":local_linux", ++ toolchain_identifier = "local_linux", ++) ++ ++toolchain( ++ name = "cc-toolchain-riscv64", ++ exec_compatible_with = [ ++ "@platforms//cpu:riscv64", ++ ], ++ target_compatible_with = [ ++ "@platforms//cpu:riscv64", ++ ], ++ toolchain = ":cc-compiler-riscv64", ++ toolchain_type = ":toolchain_type", ++) ++ + cc_toolchain( + name = "cc-compiler-k8", + all_files = ":empty", +--- a/tools/cpp/lib_cc_configure.bzl ++++ b/tools/cpp/lib_cc_configure.bzl +@@ -197,4 +197,6 @@ + return "s390x" ++ if result.stdout.strip() in ["riscv64"]: ++ return "riscv64" + if result.stdout.strip() in ["arm", "armv7l"]: + return "arm" + if result.stdout.strip() in ["aarch64"]: +--- a/tools/jdk/BUILD ++++ b/tools/jdk/BUILD +@@ -137,6 +137,7 @@ + "//src/conditions:linux_aarch64": [":jni_md_header-linux"], + "//src/conditions:linux_ppc64le": [":jni_md_header-linux"], + "//src/conditions:linux_s390x": [":jni_md_header-linux"], ++ "//src/conditions:linux_riscv64": [":jni_md_header-linux"], + "//src/conditions:linux_x86_64": [":jni_md_header-linux"], + "//src/conditions:darwin": [":jni_md_header-darwin"], + "//src/conditions:freebsd": [":jni_md_header-freebsd"], +@@ -148,6 +149,7 @@ + "//src/conditions:linux_aarch64": ["include/linux"], + "//src/conditions:linux_ppc64le": ["include/linux"], + "//src/conditions:linux_s390x": ["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"], +--- a/tools/platforms/BUILD ++++ b/tools/platforms/BUILD +@@ -59,6 +59,11 @@ + ) + + alias( ++ name = "riscv64", ++ actual = "@platforms//cpu:riscv64", ++) ++ ++alias( + name = "osx", + actual = "@platforms//os:osx", + ) +@@ -110,5 +115,6 @@ + "@platforms//cpu:aarch64", + "@platforms//cpu:s390x", ++ "@platforms//cpu:riscv64", + ], + host_platform = True, + os_constraints = [ +@@ -132,5 +138,6 @@ + "@platforms//cpu:aarch64", + "@platforms//cpu:s390x", ++ "@platforms//cpu:riscv64", + ], + os_constraints = [ + "@platforms//os:osx", +--- a/tools/platforms/BUILD.tools ++++ b/tools/platforms/BUILD.tools +@@ -47,6 +47,11 @@ + ) + + alias( ++ name = "riscv64", ++ actual = "@platforms//cpu:riscv64", ++) ++ ++alias( + name = "osx", + actual = "@platforms//os:osx", + ) +@@ -98,5 +103,6 @@ + "@platforms//cpu:aarch64", + "@platforms//cpu:s390x", ++ "@platforms//cpu:riscv64", + ], + host_platform = True, + os_constraints = [ +@@ -120,5 +126,6 @@ + "@platforms//cpu:aarch64", + "@platforms//cpu:s390x", ++ "@platforms//cpu:riscv64", + ], + os_constraints = [ + "@platforms//os:osx", +--- bazel3.7-3.7.2.orig/src/test/java/com/google/devtools/build/lib/packages/util/MockPlatformSupport.java ++++ bazel3.7-3.7.2/src/test/java/com/google/devtools/build/lib/packages/util/MockPlatformSupport.java +@@ -55,6 +55,10 @@ public class MockPlatformSupport { + "constraint_value(", + " name = 's390x',", + " constraint_setting = ':cpu',", ++ ")", ++ "constraint_value(", ++ " name = 'riscv64',", ++ " constraint_setting = ':cpu',", + ")"); + mockToolsConfig.create( + TestConstants.CONSTRAINTS_PATH + "/os/BUILD", diff --git a/bazel.spec b/bazel.spec index e0a133a..0647a32 100644 --- a/bazel.spec +++ b/bazel.spec @@ -2,7 +2,7 @@ Name: bazel Version: 4.2.1 -Release: 0 +Release: 1 Summary: Correct, reproducible, and fast builds for everyone. License: Apache License 2.0 URL: http://bazel.io/ @@ -11,6 +11,10 @@ Source0: https://github.com/bazelbuild/bazel/releases/download/%{version} # FIXME: Java 11 log.warning generates backtrace Patch1: bazel-1.0.0-log-warning.patch Patch2: bazel-gcc.patch +Patch3: add_toolchain_support_for_riscv64.patch +Patch4: add_cpu_riscv.patch +Patch5: env_python3.patch +Patch6: support-mips64el-and-riscv64.patch # for folks with 'bazel' v1 package installed Conflicts: bazel @@ -23,6 +27,7 @@ Requires: java-11-openjdk-devel %define bashcompdir %(pkg-config --variable=completionsdir bash-completion 2>/dev/null) %global debug_package %{nil} +%global _default_patch_fuzz 2 %define __os_install_post %{nil} %description @@ -32,6 +37,10 @@ Correct, reproducible, and fast builds for everyone. %setup -q -c -n bazel-%{version} %patch1 -p0 %patch2 -p0 +%patch3 -p1 +%patch4 -p1 +%patch5 -p1 +%patch6 -p1 %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|' "{}" \; @@ -85,6 +94,9 @@ env ./scripts/generate_bash_completion.sh --bazel=output/bazel --output=output/b %attr(0755,root,root) %{bashcompdir}/bazel %changelog +* Sat Sep 10 2022 Alex Rain - 4.2.1-1 +- apply patch to build on riscv64, add patch to build on python3 + * Thu 23 Jun 2022 zhangshaoning - 4.2.1-0 - update version to 4.2.1 diff --git a/env_python3.patch b/env_python3.patch new file mode 100644 index 0000000..f38f54b --- /dev/null +++ b/env_python3.patch @@ -0,0 +1,149 @@ +Description: Update source code for Python 3 + Python 2 reached End-of-Life in January 2020. This patch completely + removes Python 2 support per release team guidance. +Author: Olek Wojnar +Forwarded: https://github.com/bazelbuild/bazel/pull/11201 +Last-Update: 2020-07-23 + +--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java ++++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java +@@ -217,7 +217,7 @@ + * logic will extract the zip's runfiles into a temporary directory. + * + * The stub script has a shebang pointing to a first-stage Python interpreter (as of this +- * writing "#!/usr/bin/env python"). When a zip file is built on unix, this shebang is also ++ * writing "#!/usr/bin/env python3"). When a zip file is built on unix, this shebang is also + * prepended to the final zip artifact. On Windows shebangs are ignored, and the launcher + * runs the first stage with an interpreter whose path is passed in as LaunchInfo. + */ +@@ -249,7 +249,7 @@ + PathFragment shExecutable = ShToolchain.getPathOrError(ruleContext); + // TODO(#8685): Remove this special-case handling as part of making the proper shebang a + // property of the Python toolchain configuration. +- String pythonExecutableName = OS.getCurrent() == OS.OPENBSD ? "python3" : "python"; ++ String pythonExecutableName = "python3"; + // NOTE: keep the following line intact to support nix builds + String pythonShebang = "#!/usr/bin/env " + pythonExecutableName; + ruleContext.registerAction( +--- a/src/test/py/bazel/launcher_test.py ++++ b/src/test/py/bazel/launcher_test.py +@@ -355,7 +355,7 @@ + 'helloworld(', ' name = "hello",', ' out = "hello.txt",', ')' + ]) + foo_py = self.ScratchFile('foo/foo.py', [ +- '#!/usr/bin/env python', ++ '#!/usr/bin/env python3', + 'import sys', + 'if len(sys.argv) == 2:', + ' with open(sys.argv[1], "w") as f:', +@@ -364,7 +364,7 @@ + ' print("Hello World!")', + ]) + test_py = self.ScratchFile('foo/test.py', [ +- '#!/usr/bin/env python', ++ '#!/usr/bin/env python3', + 'import unittest', + 'class MyTest(unittest.TestCase):', + ' def test_dummy(self):', +--- a/tools/j2objc/j2objc_header_map.py ++++ b/tools/j2objc/j2objc_header_map.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/python2.7 ++#!/usr/bin/python3 + + # Copyright 2017 The Bazel Authors. All rights reserved. + # +--- a/tools/j2objc/j2objc_wrapper.py ++++ b/tools/j2objc/j2objc_wrapper.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/python2.7 ++#!/usr/bin/python3 + + # Copyright 2015 The Bazel Authors. All rights reserved. + # +@@ -25,7 +25,7 @@ + import errno + import multiprocessing + import os +-import Queue ++import queue + import re + import shutil + import subprocess +@@ -68,7 +68,7 @@ + os.close(fd) + try: + j2objc_cmd = [java] +- j2objc_cmd.extend(filter(None, jvm_flags.split(','))) ++ j2objc_cmd.extend([_f for _f in jvm_flags.split(',') if _f]) + j2objc_cmd.extend(['-cp', j2objc, main_class]) + j2objc_cmd.extend(['@%s' % param_filename]) + subprocess.check_call(j2objc_cmd, stderr=subprocess.STDOUT) +@@ -100,13 +100,13 @@ + None. + """ + dep_mapping = dict() +- input_file_queue = Queue.Queue() +- output_dep_mapping_queue = Queue.Queue() +- error_message_queue = Queue.Queue() ++ input_file_queue = queue.Queue() ++ output_dep_mapping_queue = queue.Queue() ++ error_message_queue = queue.Queue() + for objc_file in objc_files: + input_file_queue.put(os.path.join(objc_file_root, objc_file)) + +- for _ in xrange(multiprocessing.cpu_count()): ++ for _ in range(multiprocessing.cpu_count()): + t = threading.Thread(target=_ReadDepMapping, args=(input_file_queue, + output_dep_mapping_queue, + error_message_queue, +@@ -136,7 +136,7 @@ + while True: + try: + input_file = input_file_queue.get_nowait() +- except Queue.Empty: ++ except queue.Empty: + # No more work left in the queue. + return + +--- a/tools/objc/j2objc_dead_code_pruner.py ++++ b/tools/objc/j2objc_dead_code_pruner.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/python2.7 ++#!/usr/bin/python3 + + # Copyright 2015 The Bazel Authors. All rights reserved. + # +@@ -162,12 +162,12 @@ + Returns: + None. + """ +- file_queue = Queue.Queue() ++ file_queue = queue.Queue() + for input_file, output_file in zip(input_files.split(','), + output_files.split(',')): + file_queue.put((input_file, output_file)) + +- for _ in xrange(multiprocessing.cpu_count()): ++ for _ in range(multiprocessing.cpu_count()): + t = threading.Thread(target=_PruneFile, args=(file_queue, + reachable_files, + objc_file_path, +@@ -183,7 +183,7 @@ + while True: + try: + input_file, output_file = file_queue.get_nowait() +- except Queue.Empty: ++ except queue.Empty: + return + file_name = os.path.relpath(os.path.splitext(input_file)[0], + objc_file_path) +@@ -209,7 +209,7 @@ + duplicated_files = [] + dict_with_duplicates = dict() + +- for source_files in archive_source_file_mapping.values(): ++ for source_files in list(archive_source_file_mapping.values()): + for source_file in source_files: + file_basename = os.path.basename(source_file) + file_without_ext = os.path.splitext(source_file)[0] diff --git a/support-mips64el-and-riscv64.patch b/support-mips64el-and-riscv64.patch new file mode 100644 index 0000000..47e7577 --- /dev/null +++ b/support-mips64el-and-riscv64.patch @@ -0,0 +1,21 @@ +Description: Support mips64el and riscv64 architectures +Author: Olek Wojnar +Forwarded: not-needed +Last-Update: 2021-01-09 + +--- a/platforms/cpu/BUILD ++++ b/platforms/cpu/BUILD +@@ -74,3 +74,13 @@ + name = "x86_64", + constraint_setting = ":cpu", + ) ++ ++constraint_value( ++ name = "mips64", ++ constraint_setting = ":cpu", ++) ++ ++constraint_value( ++ name = "riscv64", ++ constraint_setting = ":cpu", ++) -- Gitee From 8eb43c993553bd0dcf0049cf4fad99c132167c87 Mon Sep 17 00:00:00 2001 From: eval Nya <60149113+nexplorer-3e@users.noreply.github.com> Date: Mon, 14 Nov 2022 01:24:00 +0800 Subject: [PATCH 2/2] add bazel.yaml. --- bazel.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 bazel.yaml diff --git a/bazel.yaml b/bazel.yaml new file mode 100644 index 0000000..6796fb6 --- /dev/null +++ b/bazel.yaml @@ -0,0 +1,4 @@ +seperator: . +src_repo: bazelbuild/bazel +tag_prefix: ^ +version_control: github.com -- Gitee