Skip to content

Commit

Permalink
Recognize darwin_arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
aherrmann committed Apr 14, 2022
1 parent e487aa0 commit 0563ddf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions core/util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def find_children(repository_ctx, target_dir):
def ensure_constraints(repository_ctx):
"""Build exec and target constraints for repository rules.
If these are user-provided, then they are passed through. Otherwise we build for x86_64 on the current OS.
If these are user-provided, then they are passed through.
Otherwise we build for the current CPU on the current OS, one of darwin-x86_64, darwin-arm64, or the default linux-x86_64.
In either case, exec_constraints always contain the support_nix constraint, so the toolchain can be rejected on non-Nix environments.
Args:
Expand All @@ -110,10 +111,16 @@ def ensure_constraints(repository_ctx):
target_constraints, The generated list of target constraints
"""
cpu = get_cpu_value(repository_ctx)
os = {"darwin": "osx"}.get(cpu, "linux")
cpu = {
"darwin": "@platforms//cpu:x86_64",
"darwin_arm64": "@platforms//cpu:arm64",
}.get(cpu, "@platforms//cpu:x86_64")
os = {
"darwin": "@platforms//os:osx",
"darwin_arm64": "@platforms//os:osx",
}.get(cpu, "@platforms//os:linux")
if not repository_ctx.attr.target_constraints and not repository_ctx.attr.exec_constraints:
target_constraints = ["@platforms//cpu:x86_64"]
target_constraints.append("@platforms//os:{}".format(os))
target_constraints = [cpu, os]
exec_constraints = target_constraints
else:
target_constraints = list(repository_ctx.attr.target_constraints)
Expand Down
2 changes: 1 addition & 1 deletion toolchains/cc/cc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _parse_cc_toolchain_info(content, filename):

def _nixpkgs_cc_toolchain_config_impl(repository_ctx):
cpu_value = get_cpu_value(repository_ctx)
darwin = cpu_value == "darwin"
darwin = cpu_value == "darwin" or cpu_value == "darwin_arm64"

cc_toolchain_info_file = repository_ctx.path(repository_ctx.attr.cc_toolchain_info)
if not cc_toolchain_info_file.exists and not repository_ctx.attr.fail_not_supported:
Expand Down

0 comments on commit 0563ddf

Please sign in to comment.