From fe5112b7406de514cbfb77b9708ae5b738eec439 Mon Sep 17 00:00:00 2001 From: kczulko Date: Wed, 27 Nov 2024 13:35:57 +0100 Subject: [PATCH 1/3] fix: get_cpu_value for bazel 8.0.0rc4 --- core/MODULE.bazel | 1 + core/util.bzl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/MODULE.bazel b/core/MODULE.bazel index 1c8819d4..bff000db 100644 --- a/core/MODULE.bazel +++ b/core/MODULE.bazel @@ -3,6 +3,7 @@ module( version = "0.12.0", ) +bazel_dep(name = "rules_cc", version = "0.1.0") bazel_dep(name = "platforms", version = "0.0.4") bazel_dep(name = "bazel_skylib", version = "1.0.3") diff --git a/core/util.bzl b/core/util.bzl index f352f170..bee71150 100644 --- a/core/util.bzl +++ b/core/util.bzl @@ -1,4 +1,4 @@ -load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value") +load("@rules_cc//cc/private/toolchain:lib_cc_configure.bzl", "get_cpu_value") load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_skylib//lib:versions.bzl", "versions") From a66bbeed9172958351885b036326cc0813236d95 Mon Sep 17 00:00:00 2001 From: kczulko Date: Wed, 27 Nov 2024 17:19:05 +0100 Subject: [PATCH 2/3] Revert "fix: get_cpu_value for bazel 8.0.0rc4" This reverts commit fe5112b7406de514cbfb77b9708ae5b738eec439. --- core/MODULE.bazel | 1 - core/util.bzl | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/core/MODULE.bazel b/core/MODULE.bazel index bff000db..1c8819d4 100644 --- a/core/MODULE.bazel +++ b/core/MODULE.bazel @@ -3,7 +3,6 @@ module( version = "0.12.0", ) -bazel_dep(name = "rules_cc", version = "0.1.0") bazel_dep(name = "platforms", version = "0.0.4") bazel_dep(name = "bazel_skylib", version = "1.0.3") diff --git a/core/util.bzl b/core/util.bzl index bee71150..f352f170 100644 --- a/core/util.bzl +++ b/core/util.bzl @@ -1,4 +1,4 @@ -load("@rules_cc//cc/private/toolchain:lib_cc_configure.bzl", "get_cpu_value") +load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value") load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_skylib//lib:versions.bzl", "versions") From 1aa2aeaac8e43b60d4cdbc41cc47154d55ae628a Mon Sep 17 00:00:00 2001 From: kczulko Date: Wed, 27 Nov 2024 17:20:22 +0100 Subject: [PATCH 3/3] fix: inline get_cpu_value from rules_cc --- core/util.bzl | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/core/util.bzl b/core/util.bzl index f352f170..b7940627 100644 --- a/core/util.bzl +++ b/core/util.bzl @@ -1,7 +1,45 @@ -load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value") load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_skylib//lib:versions.bzl", "versions") +# see https://github.com/tweag/rules_nixpkgs/pull/613 +# taken from https://github.com/bazelbuild/rules_cc/blob/8395ec0172270f3bf92cd7b06c9b5b3f1f679e88/cc/private/toolchain/lib_cc_configure.bzl#L225 +def get_cpu_value(repository_ctx): + """Compute the cpu_value based on the OS name. Doesn't %-escape the result! + + Args: + repository_ctx: The repository context. + Returns: + One of (darwin, freebsd, x64_windows, ppc, s390x, arm, aarch64, k8, piii) + """ + os_name = repository_ctx.os.name + arch = repository_ctx.os.arch + if os_name.startswith("mac os"): + # Check if we are on x86_64 or arm64 and return the corresponding cpu value. + return "darwin_" + ("arm64" if arch == "aarch64" else "x86_64") + if os_name.find("freebsd") != -1: + return "freebsd" + if os_name.find("openbsd") != -1: + return "openbsd" + if os_name.find("windows") != -1: + if arch == "aarch64": + return "arm64_windows" + else: + return "x64_windows" + + if arch in ["power", "ppc64le", "ppc", "ppc64"]: + return "ppc" + if arch in ["s390x"]: + return "s390x" + if arch in ["mips64"]: + return "mips64" + if arch in ["riscv64"]: + return "riscv64" + if arch in ["arm", "armv7l"]: + return "arm" + if arch in ["aarch64"]: + return "aarch64" + return "k8" if arch in ["amd64", "x86_64", "x64"] else "piii" + def fail_on_err(return_value, prefix = None): """Fail if the given return value indicates an error.