Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use get_cpu_value from rules_nixpkgs_core in other modules #617

Merged
merged 5 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions core/private/get_cpu_value.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

# 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"
40 changes: 1 addition & 39 deletions core/util.bzl
Original file line number Diff line number Diff line change
@@ -1,44 +1,6 @@
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"
load("//:private/get_cpu_value.bzl", "get_cpu_value")

def fail_on_err(return_value, prefix = None):
"""Fail if the given return value indicates an error.
Expand Down
2 changes: 1 addition & 1 deletion nixpkgs/nixpkgs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ nixpkgs_package(

load("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_autoconf_impl")
load(
"@bazel_tools//tools/cpp:lib_cc_configure.bzl",
"@rules_nixpkgs_core//:private/get_cpu_value.bzl",
"get_cpu_value",
)
load(
Expand Down
5 changes: 4 additions & 1 deletion toolchains/cc/cc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ using `nixpkgs_cc_configure(..., cc_lang = "cuda")` or similar.
load("@bazel_skylib//lib:sets.bzl", "sets")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load(
"@bazel_tools//tools/cpp:lib_cc_configure.bzl",
"@rules_nixpkgs_core//:private/get_cpu_value.bzl",
"get_cpu_value",
)
load(
"@bazel_tools//tools/cpp:lib_cc_configure.bzl",
"get_starlark_list",
"write_builtin_include_directory_paths",
)
Expand Down
2 changes: 1 addition & 1 deletion toolchains/java/java.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

load(
"@bazel_tools//tools/cpp:lib_cc_configure.bzl",
"@rules_nixpkgs_core//:private/get_cpu_value.bzl",
"get_cpu_value",
)
load(
Expand Down
2 changes: 1 addition & 1 deletion toolchains/posix/posix.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Rules for importing a POSIX toolchain from Nixpkgs.
"""

load(
"@bazel_tools//tools/cpp:lib_cc_configure.bzl",
"@rules_nixpkgs_core//:private/get_cpu_value.bzl",
"get_cpu_value",
)
load("@rules_nixpkgs_core//:nixpkgs.bzl", "nixpkgs_package")
Expand Down
Loading