2022-04-13 17:52:25 +03:00
|
|
|
load("@bazel-zig-cc//toolchain/private:defs.bzl", "LIBCS")
|
|
|
|
|
|
|
|
_CPUS = (("x86_64", "amd64"), ("aarch64", "arm64"))
|
2022-05-29 19:35:17 +03:00
|
|
|
_OS = {
|
|
|
|
"linux": ["linux"],
|
|
|
|
"macos": ["macos", "darwin"],
|
|
|
|
"windows": ["windows"],
|
|
|
|
}
|
2022-04-13 17:52:25 +03:00
|
|
|
|
2022-04-06 22:19:44 +03:00
|
|
|
def declare_platforms():
|
|
|
|
# create @zig_sdk//{os}_{arch}_platform entries with zig and go conventions
|
2022-04-13 17:52:25 +03:00
|
|
|
for zigcpu, gocpu in _CPUS:
|
2022-05-29 19:35:17 +03:00
|
|
|
for bzlos, oss in _OS.items():
|
2022-04-06 22:19:44 +03:00
|
|
|
for os in oss:
|
2022-04-13 17:52:25 +03:00
|
|
|
declare_platform(gocpu, zigcpu, bzlos, os)
|
|
|
|
|
2023-03-28 08:52:20 +03:00
|
|
|
def declare_libc_aware_platforms(macos_sdk_versions):
|
2022-04-13 17:52:25 +03:00
|
|
|
# create @zig_sdk//{os}_{arch}_platform entries with zig and go conventions
|
|
|
|
# with libc specified
|
|
|
|
for zigcpu, gocpu in _CPUS:
|
|
|
|
for libc in LIBCS:
|
|
|
|
declare_platform(
|
|
|
|
gocpu,
|
|
|
|
zigcpu,
|
|
|
|
"linux",
|
|
|
|
"linux",
|
|
|
|
suffix = "_{}".format(libc),
|
|
|
|
extra_constraints = ["@zig_sdk//libc:{}".format(libc)],
|
|
|
|
)
|
2023-03-28 08:52:20 +03:00
|
|
|
for macos_sdk_version in macos_sdk_versions:
|
|
|
|
declare_platform(
|
|
|
|
gocpu,
|
|
|
|
zigcpu,
|
|
|
|
"macos",
|
|
|
|
"macos",
|
|
|
|
suffix = "_sdk.{}".format(macos_sdk_version),
|
|
|
|
extra_constraints = ["@zig_sdk//libc:macos.{}".format(macos_sdk_version)],
|
|
|
|
)
|
2022-04-13 17:52:25 +03:00
|
|
|
|
|
|
|
def declare_platform(gocpu, zigcpu, bzlos, os, suffix = "", extra_constraints = []):
|
|
|
|
constraint_values = [
|
|
|
|
"@platforms//os:{}".format(bzlos),
|
|
|
|
"@platforms//cpu:{}".format(zigcpu),
|
|
|
|
] + extra_constraints
|
|
|
|
|
|
|
|
native.platform(
|
|
|
|
name = "{os}_{zigcpu}{suffix}".format(os = os, zigcpu = zigcpu, suffix = suffix),
|
|
|
|
constraint_values = constraint_values,
|
|
|
|
)
|
|
|
|
|
|
|
|
native.platform(
|
|
|
|
name = "{os}_{gocpu}{suffix}".format(os = os, gocpu = gocpu, suffix = suffix),
|
|
|
|
constraint_values = constraint_values,
|
|
|
|
)
|