-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2080 from tweag/cg/support_macos_arm64
chore: support arm64 on MacOS
- Loading branch information
Showing
6 changed files
with
139 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Module for managing/deriving official Bazel platform values.""" | ||
|
||
# The expected values for os_cpu can be found by looking at the | ||
# implementation for get_cpu_value in lib_cc_configure.bzl. | ||
# https://github.com/bazelbuild/bazel/blob/e11506feaea7401c3d27f55b47183ef49bd1d5a8/tools/cpp/lib_cc_configure.bzl#L186 | ||
|
||
def _get_os(os_cpu): | ||
if os_cpu.find("darwin") >= 0: | ||
return "osx" | ||
if os_cpu.find("windows") >= 0: | ||
return "windows" | ||
return "linux" | ||
|
||
def _get_cpu(os_cpu): | ||
# This value could appear in older versions of Bazel. | ||
if os_cpu == "darwin": | ||
return "x86_64" | ||
|
||
# This handles modern os-cpu values like darwin_arm64 or darwin_x86_64. | ||
if os_cpu.startswith("darwin_"): | ||
return os_cpu.removeprefix("darwin_") | ||
if os_cpu == "arm64_windows": | ||
return "arm64" | ||
if os_cpu == "x64_windows": | ||
return "x86_64" | ||
|
||
return "x86_64" | ||
|
||
bazel_platforms = struct( | ||
get_os = _get_os, | ||
get_cpu = _get_cpu, | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
load(":bazel_platforms_tests.bzl", "bazel_platforms_test_suite") | ||
|
||
bazel_platforms_test_suite() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
"""Tests for `bazel_platforms` module.""" | ||
|
||
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") | ||
load("//haskell:private/bazel_platforms.bzl", "bazel_platforms") | ||
|
||
def _get_os_test(ctx): | ||
env = unittest.begin(ctx) | ||
|
||
tests = [ | ||
struct( | ||
msg = "darwin (legacy MacOS on x86_64)", | ||
os_cpu = "darwin", | ||
exp = "osx", | ||
), | ||
struct( | ||
os_cpu = "darwin_x86_64", | ||
exp = "osx", | ||
), | ||
struct( | ||
os_cpu = "darwin_arm64", | ||
exp = "osx", | ||
), | ||
struct( | ||
os_cpu = "arm64_windows", | ||
exp = "windows", | ||
), | ||
struct( | ||
os_cpu = "x64_windows", | ||
exp = "windows", | ||
), | ||
struct( | ||
os_cpu = "freebsd", | ||
exp = "linux", | ||
), | ||
struct( | ||
os_cpu = "openbsd", | ||
exp = "linux", | ||
), | ||
] | ||
for t in tests: | ||
actual = bazel_platforms.get_os(t.os_cpu) | ||
msg = getattr(t, "msg", t.os_cpu) | ||
asserts.equals(env, t.exp, actual, msg) | ||
|
||
return unittest.end(env) | ||
|
||
get_os_test = unittest.make(_get_os_test) | ||
|
||
def _get_cpu_test(ctx): | ||
env = unittest.begin(ctx) | ||
|
||
tests = [ | ||
struct( | ||
msg = "darwin (legacy MacOS on x86_64)", | ||
os_cpu = "darwin", | ||
exp = "x86_64", | ||
), | ||
struct( | ||
os_cpu = "darwin_x86_64", | ||
exp = "x86_64", | ||
), | ||
struct( | ||
os_cpu = "darwin_arm64", | ||
exp = "arm64", | ||
), | ||
struct( | ||
os_cpu = "arm64_windows", | ||
exp = "arm64", | ||
), | ||
struct( | ||
os_cpu = "x64_windows", | ||
exp = "x86_64", | ||
), | ||
struct( | ||
os_cpu = "freebsd", | ||
exp = "x86_64", | ||
), | ||
struct( | ||
os_cpu = "openbsd", | ||
exp = "x86_64", | ||
), | ||
] | ||
for t in tests: | ||
actual = bazel_platforms.get_cpu(t.os_cpu) | ||
msg = getattr(t, "msg", t.os_cpu) | ||
asserts.equals(env, t.exp, actual, msg) | ||
|
||
return unittest.end(env) | ||
|
||
get_cpu_test = unittest.make(_get_cpu_test) | ||
|
||
def bazel_platforms_test_suite(name = "bazel_platforms_tests"): | ||
return unittest.suite( | ||
name, | ||
get_os_test, | ||
get_cpu_test, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters