From 1c29dff364fd34d7e6158c812cfd6d96f66be747 Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Mon, 1 Mar 2021 01:28:01 -0800 Subject: [PATCH] Support mips64 and riscv64 Upstream some patches from the Bazel Debian package to make Bazel build on mips64 and riscv64 https://salsa.debian.org/bazel-team/bazel-bootstrap/-/tree/olek-mips-riscv-3/debian/patches Fixes https://github.com/bazelbuild/bazel/issues/12683 Closes #13057. PiperOrigin-RevId: 360130065 --- src/conditions/BUILD | 18 ++++++ src/conditions/BUILD.tools | 24 ++++++++ .../lib/analysis/config/AutoCpuConverter.java | 31 ++++++---- .../LocalConfigPlatformFunction.java | 4 ++ .../google/devtools/build/lib/util/CPU.java | 2 + tools/cpp/BUILD.tools | 58 +++++++++++++++++++ tools/cpp/lib_cc_configure.bzl | 4 ++ tools/jdk/BUILD.tools | 4 ++ tools/platforms/BUILD | 14 +++++ tools/platforms/BUILD.tools | 14 +++++ 10 files changed, 163 insertions(+), 10 deletions(-) diff --git a/src/conditions/BUILD b/src/conditions/BUILD index 5f8f6a7767ffc4..073f8475ab45db 100644 --- a/src/conditions/BUILD +++ b/src/conditions/BUILD @@ -66,6 +66,24 @@ config_setting( visibility = ["//visibility:public"], ) +config_setting( + name = "linux_mips64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:mips64", + ], + visibility = ["//visibility:public"], +) + +config_setting( + name = "linux_riscv64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:riscv64", + ], + visibility = ["//visibility:public"], +) + config_setting( name = "linux_x86_64", constraint_values = [ diff --git a/src/conditions/BUILD.tools b/src/conditions/BUILD.tools index ed90895b1a5750..e2b54e675d150a 100644 --- a/src/conditions/BUILD.tools +++ b/src/conditions/BUILD.tools @@ -16,6 +16,12 @@ config_setting( visibility = ["//visibility:public"], ) +config_setting( + name = "linux", + constraint_values = ["@platforms//os:linux"], + visibility = ["//visibility:public"], +) + config_setting( name = "linux_ppc", constraint_values = [ @@ -43,6 +49,24 @@ config_setting( visibility = ["//visibility:public"], ) +config_setting( + name = "linux_mips64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:mips64", + ], + visibility = ["//visibility:public"], +) + +config_setting( + name = "linux_riscv64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:riscv64", + ], + visibility = ["//visibility:public"], +) + config_setting( name = "linux_x86_64", constraint_values = [ diff --git 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 index 9f5fbca65fd003..d39620c50eb1d7 100644 --- 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 @@ -68,6 +68,10 @@ public String convert(String input) throws OptionsParsingException { return "aarch64"; case S390X: return "s390x"; + case MIPS64: + return "mips64"; + case RISCV64: + return "riscv64"; default: return "unknown"; } @@ -97,16 +101,23 @@ public static Pair reverse(String input) { } // Handle the Linux cases. - if (input.equals("piii")) { - return Pair.of(CPU.X86_32, OS.LINUX); - } else if (input.equals("k8")) { - return Pair.of(CPU.X86_64, OS.LINUX); - } else if (input.equals("ppc")) { - return Pair.of(CPU.PPC, OS.LINUX); - } else if (input.equals("arm")) { - return Pair.of(CPU.ARM, OS.LINUX); - } else if (input.equals("s390x")) { - return Pair.of(CPU.S390X, OS.LINUX); + switch (input) { + case "piii": + return Pair.of(CPU.X86_32, OS.LINUX); + case "k8": + return Pair.of(CPU.X86_64, OS.LINUX); + case "ppc": + return Pair.of(CPU.PPC, OS.LINUX); + case "arm": + return Pair.of(CPU.ARM, OS.LINUX); + case "s390x": + return Pair.of(CPU.S390X, OS.LINUX); + case "mips64": + return Pair.of(CPU.MIPS64, OS.LINUX); + case "riscv64": + return Pair.of(CPU.RISCV64, OS.LINUX); + default: + // fall through } // Use the auto-detected values. diff --git 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 index 1728028cb40c6b..c67b1092a7e361 100644 --- 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 @@ -116,6 +116,10 @@ static String cpuToConstraint(CPU cpu) { return "@platforms//cpu:aarch64"; case S390X: return "@platforms//cpu:s390x"; + case MIPS64: + return "@platforms//cpu:mips64"; + case RISCV64: + return "@platforms//cpu:riscv64"; default: // Unknown, so skip it. return null; diff --git a/src/main/java/com/google/devtools/build/lib/util/CPU.java b/src/main/java/com/google/devtools/build/lib/util/CPU.java index 075c94ac4fa5fa..88ae4a32f3de77 100644 --- a/src/main/java/com/google/devtools/build/lib/util/CPU.java +++ b/src/main/java/com/google/devtools/build/lib/util/CPU.java @@ -27,6 +27,8 @@ public enum CPU { ARM("arm", ImmutableSet.of("arm", "armv7l")), AARCH64("aarch64", ImmutableSet.of("aarch64")), S390X("s390x", ImmutableSet.of("s390x", "s390")), + MIPS64("mips64", ImmutableSet.of("mips64el", "mips64")), + RISCV64("riscv64", ImmutableSet.of("riscv64")), UNKNOWN("unknown", ImmutableSet.of()); private final String canonicalName; diff --git a/tools/cpp/BUILD.tools b/tools/cpp/BUILD.tools index d7b0d94e53bc91..d1234ac78c8462 100644 --- a/tools/cpp/BUILD.tools +++ b/tools/cpp/BUILD.tools @@ -106,6 +106,8 @@ cc_toolchain_suite( "x64_windows_msvc|compiler": ":cc-compiler-x64_windows_msvc", "s390x|compiler": ":cc-compiler-s390x", "ppc|compiler": ":cc-compiler-ppc", + "mips64|compiler": ":cc-compiler-mips64", + "riscv64|compiler": ":cc-compiler-riscv64", "k8": ":cc-compiler-local", "piii": ":cc-compiler-local", "arm": ":cc-compiler-local", @@ -113,6 +115,8 @@ cc_toolchain_suite( "s390x": ":cc-compiler-local", "ppc": ":cc-compiler-local", "ppc64": ":cc-compiler-local", + "mips64": ":cc-compiler-local", + "riscv64": ":cc-compiler-local", "darwin": ":cc-compiler-darwin", "freebsd": ":cc-compiler-freebsd", "armeabi-v7a": ":cc-compiler-armeabi-v7a", @@ -210,6 +214,60 @@ toolchain( toolchain_type = ":toolchain_type", ) +cc_toolchain( + name = "cc-compiler-mips64", + 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-mips64", + exec_compatible_with = [ + "@platforms//cpu:mips64", + ], + target_compatible_with = [ + "@platforms//cpu:mips64", + ], + toolchain = ":cc-compiler-mips64", + 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-armeabi-v7a", all_files = ":empty", diff --git a/tools/cpp/lib_cc_configure.bzl b/tools/cpp/lib_cc_configure.bzl index 1464d8ca6688e5..9508eb78f7e9e5 100644 --- a/tools/cpp/lib_cc_configure.bzl +++ b/tools/cpp/lib_cc_configure.bzl @@ -197,6 +197,10 @@ def get_cpu_value(repository_ctx): return "ppc" if result.stdout.strip() in ["s390x"]: return "s390x" + if result.stdout.strip() in ["mips64"]: + return "mips64" + if result.stdout.strip() in ["riscv64"]: + return "riscv64" if result.stdout.strip() in ["arm", "armv7l"]: return "arm" if result.stdout.strip() in ["aarch64"]: diff --git a/tools/jdk/BUILD.tools b/tools/jdk/BUILD.tools index 2b3909df7043e2..7e5fac5c402adf 100644 --- a/tools/jdk/BUILD.tools +++ b/tools/jdk/BUILD.tools @@ -98,6 +98,8 @@ cc_library( "//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_mips64": [":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"], @@ -109,6 +111,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_x86_64": ["include/linux"], "//src/conditions:darwin": ["include/darwin"], "//src/conditions:freebsd": ["include/freebsd"], diff --git a/tools/platforms/BUILD b/tools/platforms/BUILD index e372d62e425c83..18ff33eb0302dd 100644 --- a/tools/platforms/BUILD +++ b/tools/platforms/BUILD @@ -53,6 +53,16 @@ alias( actual = "@platforms//cpu:s390x", ) +alias( + name = "mips64", + actual = "@platforms//cpu:mips64", +) + +alias( + name = "riscv64", + actual = "@platforms//cpu:riscv64", +) + alias( name = "os", actual = "@platforms//os:os", @@ -109,6 +119,8 @@ platform( "@platforms//cpu:arm", "@platforms//cpu:aarch64", "@platforms//cpu:s390x", + "@platforms//cpu:mips64", + "@platforms//cpu:riscv64", ], host_platform = True, os_constraints = [ @@ -131,6 +143,8 @@ platform( "@platforms//cpu:arm", "@platforms//cpu:aarch64", "@platforms//cpu:s390x", + "@platforms//cpu:mips64", + "@platforms//cpu:riscv64", ], os_constraints = [ "@platforms//os:osx", diff --git a/tools/platforms/BUILD.tools b/tools/platforms/BUILD.tools index 73011dab678f48..03751861d71393 100644 --- a/tools/platforms/BUILD.tools +++ b/tools/platforms/BUILD.tools @@ -41,6 +41,16 @@ alias( actual = "@platforms//cpu:s390x", ) +alias( + name = "mips64", + actual = "@platforms//cpu:mips64", +) + +alias( + name = "riscv64", + actual = "@platforms//cpu:riscv64", +) + alias( name = "os", actual = "@platforms//os:os", @@ -97,6 +107,8 @@ platform( "@platforms//cpu:arm", "@platforms//cpu:aarch64", "@platforms//cpu:s390x", + "@platforms//cpu:mips64", + "@platforms//cpu:riscv64", ], host_platform = True, os_constraints = [ @@ -119,6 +131,8 @@ platform( "@platforms//cpu:arm", "@platforms//cpu:aarch64", "@platforms//cpu:s390x", + "@platforms//cpu:mips64", + "@platforms//cpu:riscv64", ], os_constraints = [ "@platforms//os:osx",