Skip to content

Commit

Permalink
Support mips64 and riscv64
Browse files Browse the repository at this point in the history
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 #12683

Closes #13057.

PiperOrigin-RevId: 360130065
  • Loading branch information
meteorcloudy authored and copybara-github committed Mar 1, 2021
1 parent 9b30172 commit 1c29dff
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 10 deletions.
18 changes: 18 additions & 0 deletions src/conditions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
24 changes: 24 additions & 0 deletions src/conditions/BUILD.tools
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -97,16 +101,23 @@ public static Pair<CPU, OS> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/google/devtools/build/lib/util/CPU.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.<String>of());

private final String canonicalName;
Expand Down
58 changes: 58 additions & 0 deletions tools/cpp/BUILD.tools
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ 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",
"aarch64": ":cc-compiler-local",
"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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions tools/cpp/lib_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down
4 changes: 4 additions & 0 deletions tools/jdk/BUILD.tools
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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"],
Expand Down
14 changes: 14 additions & 0 deletions tools/platforms/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 = [
Expand All @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions tools/platforms/BUILD.tools
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 = [
Expand All @@ -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",
Expand Down

0 comments on commit 1c29dff

Please sign in to comment.