wip macos
motiejus@mtwork:/code/bazel-zig-cc$ bazel build --spawn_strategy=local --platforms @zig_sdk//libc_aware/platform:macos_aarch64_sdk.13.1 test/c:which_libc INFO: Analyzed target //test/c:which_libc (0 packages loaded, 0 targets configured). INFO: Found 1 target... Target //test/c:which_libc up-to-date: bazel-bin/test/c/which_libc INFO: Elapsed time: 0.071s, Critical Path: 0.00s INFO: 1 process: 1 internal. INFO: Build completed successfully, 1 total action motiejus@mtwork:/code/bazel-zig-cc$ file bazel-bin/test/c/which_libc bazel-bin/test/c/which_libc: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE> motiejus@mtwork:/code/bazel-zig-cc$
This commit is contained in:
parent
041d7f26ab
commit
27fe6c9ffb
18
WORKSPACE
18
WORKSPACE
@ -44,18 +44,27 @@ gazelle_dependencies(go_repository_default_config = "@//:WORKSPACE")
|
||||
|
||||
load(
|
||||
"//toolchain:defs.bzl",
|
||||
"macos_sdk",
|
||||
zig_toolchains = "toolchains",
|
||||
)
|
||||
|
||||
zig_toolchains()
|
||||
zig_toolchains(
|
||||
macos_sdks = [
|
||||
macos_sdk(
|
||||
version = "13.1",
|
||||
urls = [ "https://dl.jakstys.lt/ntpad/x/MacOSX13.1.sdk.tar.zst" ],
|
||||
sha256 = "9b65f80a142dfb0b7d295636ad8b8f9b9b3450957f6d101f1076836463e729a9",
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
register_toolchains(
|
||||
# if no `--platform` is specified, these toolchains will be used for
|
||||
# (linux,darwin,windows)x(amd64,arm64)
|
||||
"@zig_sdk//toolchain:linux_amd64_gnu.2.19",
|
||||
"@zig_sdk//toolchain:linux_arm64_gnu.2.28",
|
||||
"@zig_sdk//toolchain:darwin_amd64",
|
||||
"@zig_sdk//toolchain:darwin_arm64",
|
||||
"@zig_sdk//toolchain:darwin_amd64_sdk.13.1",
|
||||
"@zig_sdk//toolchain:darwin_arm64_sdk.13.1",
|
||||
"@zig_sdk//toolchain:windows_amd64",
|
||||
"@zig_sdk//toolchain:windows_arm64",
|
||||
|
||||
@ -67,6 +76,9 @@ register_toolchains(
|
||||
# arm64 toolchains for libc-aware platforms:
|
||||
"@zig_sdk//libc_aware/toolchain:linux_arm64_gnu.2.28",
|
||||
"@zig_sdk//libc_aware/toolchain:linux_arm64_musl",
|
||||
|
||||
"@zig_sdk//libc_aware/toolchain:darwin_amd64_sdk.13.1",
|
||||
"@zig_sdk//libc_aware/toolchain:darwin_arm64_sdk.13.1",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
|
@ -3,9 +3,6 @@ load("@bazel-zig-cc//rules:platform.bzl", "platform_binary")
|
||||
cc_binary(
|
||||
name = "which_libc",
|
||||
srcs = ["main.c"],
|
||||
target_compatible_with = [
|
||||
"@platforms//os:linux",
|
||||
],
|
||||
)
|
||||
|
||||
[
|
||||
|
@ -2,13 +2,8 @@
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
|
||||
#include <stdio.h>
|
||||
#include <features.h>
|
||||
|
||||
int main() {
|
||||
#ifdef __GLIBC__
|
||||
printf("glibc_%d.%d\n", __GLIBC__, __GLIBC_MINOR__);
|
||||
#else
|
||||
printf("non-glibc\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
10
toolchain/BUILD.macos.bazel
Normal file
10
toolchain/BUILD.macos.bazel
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright 2023 Uber Technologies, Inc.
|
||||
# Licensed under the Apache License, Version 2.0
|
||||
|
||||
load("@bazel-zig-cc//toolchain:defs.bzl", "declare_macos_sdk_files")
|
||||
|
||||
package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
declare_macos_sdk_files()
|
@ -10,6 +10,7 @@ package(
|
||||
|
||||
declare_files(
|
||||
os = {os},
|
||||
macos_sdk_versions = {macos_sdk_versions},
|
||||
)
|
||||
|
||||
exports_files([
|
||||
@ -22,4 +23,5 @@ exports_files([
|
||||
declare_cc_toolchains(
|
||||
os = {os},
|
||||
zig_sdk_path = {zig_sdk_path},
|
||||
macos_sdk_versions = {macos_sdk_versions},
|
||||
)
|
||||
|
@ -24,14 +24,14 @@ URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.{
|
||||
# generous enough to host the artifacts, which we use.
|
||||
URL_FORMAT_BAZELMIRROR = "https://mirror.bazel.build/" + URL_FORMAT_NIGHTLY.lstrip("https://")
|
||||
|
||||
_VERSION = "0.11.0-dev.1796+c9e02d3e6"
|
||||
_VERSION = "0.11.0-dev.2312+dd66e0add"
|
||||
|
||||
_HOST_PLATFORM_SHA256 = {
|
||||
"linux-aarch64": "5902b34b463635b25c11555650d095eb5030e2a05d8a4570c091313cd1a38b12",
|
||||
"linux-x86_64": "aa9da2305fad89f648db2fd1fade9f0f9daf01d06f3b07887ad3098402794778",
|
||||
"macos-aarch64": "51b4e88123d6cbb102f2a6665dd0d61467341f36b07bb0a8d46a37ea367b60d5",
|
||||
"macos-x86_64": "dd8eeae5249aa21f9e51ff4ff536a3e7bf2c0686ee78bf6032d18e74c8416c56",
|
||||
"windows-x86_64": "260f34d0d5312d2642097bb33c14ac552cd57c59a15383364df6764d01f0bfc9",
|
||||
"linux-aarch64": "adb62d5616e803d4174a818c6180ba34995f55f8d1d7e9282dc3e71cae3a3ee7",
|
||||
"linux-x86_64": "e3c05b0a820a137c199bbd06b705b578d9a91b6ce64caadb87b15a0d97f7c9aa",
|
||||
"macos-aarch64": "327e851c44efe870aefeddd94be181d5a942658e6e1ae74672ffa6fb5c06f96d",
|
||||
"macos-x86_64": "e21a3e5fa7368f5bafdd469702d0b12e3d7da09ee6338b3eb6688cbf91884c7a",
|
||||
"windows-x86_64": "371e3567b757061b4bbc27de09de98e631f15cf312b45d9e81398f68ed8c89ea",
|
||||
}
|
||||
|
||||
_HOST_PLATFORM_EXT = {
|
||||
@ -61,23 +61,68 @@ $ <... re-run your command ...>
|
||||
... and proceed with your life.
|
||||
"""
|
||||
|
||||
_want_format = """
|
||||
Unexpected MacOS SDK definition. Expected format:
|
||||
|
||||
zig_toolchain(
|
||||
macos_sdks = [
|
||||
struct(
|
||||
version = "13.1",
|
||||
urls = [ "https://<...>", ... ],
|
||||
sha256 = "<...>",
|
||||
),
|
||||
...
|
||||
],
|
||||
)
|
||||
|
||||
"""
|
||||
|
||||
def toolchains(
|
||||
version = _VERSION,
|
||||
url_formats = [URL_FORMAT_BAZELMIRROR, URL_FORMAT_NIGHTLY],
|
||||
host_platform_sha256 = _HOST_PLATFORM_SHA256,
|
||||
host_platform_ext = _HOST_PLATFORM_EXT):
|
||||
host_platform_ext = _HOST_PLATFORM_EXT,
|
||||
macos_sdks = []):
|
||||
"""
|
||||
Download zig toolchain and declare bazel toolchains.
|
||||
The platforms are not registered automatically, that should be done by
|
||||
the user with register_toolchains() in the WORKSPACE file. See README
|
||||
for possible choices.
|
||||
"""
|
||||
|
||||
macos_sdk_versions = []
|
||||
for sdk in macos_sdks:
|
||||
if not(bool(sdk.version) and bool(sdk.urls) and bool(sdk.sha256)):
|
||||
fail(_want_format)
|
||||
|
||||
macos_sdk_versions.append(sdk.version)
|
||||
|
||||
if not (len(sdk.version) == 4 and
|
||||
sdk.version[2] == "." and
|
||||
sdk.version[0:2].isdigit() and
|
||||
sdk.version[3].isdigit()):
|
||||
fail("unexpected macos SDK version {}, want DD.D".format(version))
|
||||
|
||||
macos_sdk_repository(
|
||||
name = "macos_sdk_{}".format(sdk.version),
|
||||
urls = sdk.urls,
|
||||
sha256 = sdk.sha256,
|
||||
)
|
||||
|
||||
zig_repository(
|
||||
name = "zig_sdk",
|
||||
version = version,
|
||||
url_formats = url_formats,
|
||||
host_platform_sha256 = host_platform_sha256,
|
||||
host_platform_ext = host_platform_ext,
|
||||
macos_sdk_versions = macos_sdk_versions,
|
||||
)
|
||||
|
||||
def macos_sdk(version, urls, sha256):
|
||||
return struct(
|
||||
version = version,
|
||||
urls = urls,
|
||||
sha256 = sha256,
|
||||
)
|
||||
|
||||
_ZIG_TOOLS = [
|
||||
@ -145,26 +190,31 @@ def _zig_repository_impl(repository_ctx):
|
||||
# https://bazel.build/extending/repo#when_is_the_implementation_function_executed
|
||||
# and a related rules_go PR:
|
||||
# https://github.com/bazelbuild/bazel-gazelle/pull/1206
|
||||
for dest, src in {
|
||||
"platform/BUILD": "//toolchain/platform:BUILD",
|
||||
"toolchain/BUILD": "//toolchain/toolchain:BUILD",
|
||||
"libc/BUILD": "//toolchain/libc:BUILD",
|
||||
"libc_aware/platform/BUILD": "//toolchain/libc_aware/platform:BUILD",
|
||||
"libc_aware/toolchain/BUILD": "//toolchain/libc_aware/toolchain:BUILD",
|
||||
}.items():
|
||||
repository_ctx.symlink(Label(src), dest)
|
||||
macos_sdk_versions_str = _macos_versions(repository_ctx.attr.macos_sdk_versions)
|
||||
repository_ctx.symlink(Label("//toolchain/platform:BUILD"), "platform/BUILD")
|
||||
repository_ctx.template(
|
||||
"BUILD",
|
||||
Label("//toolchain:BUILD.sdk.bazel"),
|
||||
executable = False,
|
||||
substitutions = {
|
||||
"{zig_sdk_path}": _quote("external/zig_sdk"),
|
||||
"{os}": _quote(os),
|
||||
"{macos_sdk_versions}": macos_sdk_versions_str,
|
||||
},
|
||||
)
|
||||
|
||||
for dest, src in {
|
||||
"BUILD": "//toolchain:BUILD.sdk.bazel",
|
||||
# "private/BUILD": "//toolchain/private:BUILD.sdk.bazel",
|
||||
"toolchain/BUILD": "//toolchain/toolchain:BUILD",
|
||||
"libc/BUILD": "//toolchain/libc:BUILD.sdk.bazel",
|
||||
"libc_aware/platform/BUILD": "//toolchain/libc_aware/platform:BUILD.sdk.bazel",
|
||||
"libc_aware/toolchain/BUILD": "//toolchain/libc_aware/toolchain:BUILD.sdk.bazel",
|
||||
}.items():
|
||||
repository_ctx.template(
|
||||
dest,
|
||||
Label(src),
|
||||
executable = False,
|
||||
substitutions = {
|
||||
"{zig_sdk_path}": _quote("external/zig_sdk"),
|
||||
"{os}": _quote(os),
|
||||
"{macos_sdk_versions}": macos_sdk_versions_str,
|
||||
},
|
||||
)
|
||||
|
||||
@ -219,7 +269,7 @@ def _zig_repository_impl(repository_ctx):
|
||||
))
|
||||
|
||||
exe = ".exe" if os == "windows" else ""
|
||||
for target_config in target_structs():
|
||||
for target_config in target_structs(repository_ctx.attr.macos_sdk_versions):
|
||||
for zig_tool in _ZIG_TOOLS + target_config.tool_paths.values():
|
||||
tool_path = zig_tool_path(os).format(
|
||||
zig_tool = zig_tool,
|
||||
@ -243,16 +293,40 @@ zig_repository = repository_rule(
|
||||
"host_platform_sha256": attr.string_dict(),
|
||||
"url_formats": attr.string_list(allow_empty = False),
|
||||
"host_platform_ext": attr.string_dict(),
|
||||
"macos_sdk_versions": attr.string_list(),
|
||||
},
|
||||
environ = ["BAZEL_ZIG_CC_CACHE_PREFIX"],
|
||||
implementation = _zig_repository_impl,
|
||||
)
|
||||
|
||||
def _macos_sdk_repository_impl(repository_ctx):
|
||||
urls = repository_ctx.attr.urls
|
||||
sha256 = repository_ctx.attr.sha256
|
||||
|
||||
repository_ctx.symlink(Label("//toolchain:BUILD.macos.bazel"), "BUILD.bazel")
|
||||
repository_ctx.download_and_extract(
|
||||
auth = use_netrc(read_user_netrc(repository_ctx), urls, {}),
|
||||
url = urls,
|
||||
sha256 = sha256,
|
||||
)
|
||||
|
||||
macos_sdk_repository = repository_rule(
|
||||
attrs = {
|
||||
"urls": attr.string_list(allow_empty = False, mandatory = True),
|
||||
"sha256": attr.string(mandatory = True),
|
||||
},
|
||||
implementation = _macos_sdk_repository_impl,
|
||||
)
|
||||
|
||||
def filegroup(name, **kwargs):
|
||||
native.filegroup(name = name, **kwargs)
|
||||
return ":" + name
|
||||
|
||||
def declare_files(os):
|
||||
def declare_macos_sdk_files():
|
||||
filegroup(name = "usr_include", srcs = native.glob(["usr/include/**"]))
|
||||
filegroup(name = "usr_lib", srcs = native.glob(["usr/lib/**"]))
|
||||
|
||||
def declare_files(os, macos_sdk_versions):
|
||||
filegroup(name = "all", srcs = native.glob(["**"]))
|
||||
filegroup(name = "empty")
|
||||
if os == "windows":
|
||||
@ -263,27 +337,28 @@ def declare_files(os):
|
||||
filegroup(name = "lib/std", srcs = native.glob(["lib/std/**"]))
|
||||
lazy_filegroups = {}
|
||||
|
||||
for target_config in target_structs():
|
||||
all_includes = [native.glob(["lib/{}/**".format(i)]) for i in target_config.includes]
|
||||
all_includes.append(getattr(target_config, "compiler_extra_includes", []))
|
||||
|
||||
for target_config in target_structs(macos_sdk_versions):
|
||||
cxx_tool_label = ":" + zig_tool_path(os).format(
|
||||
zig_tool = "c++",
|
||||
zigtarget = target_config.zigtarget,
|
||||
)
|
||||
|
||||
all_includes = [native.glob(["lib/{}/**".format(i)]) for i in target_config.includes]
|
||||
all_includes.append(getattr(target_config, "compiler_extra_includes", []))
|
||||
|
||||
filegroup(
|
||||
name = "{}_includes".format(target_config.zigtarget),
|
||||
srcs = _flatten(all_includes),
|
||||
srcs = _flatten(all_includes)
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "{}_compiler_files".format(target_config.zigtarget),
|
||||
srcs = [
|
||||
":zig",
|
||||
":lib/std",
|
||||
":{}_includes".format(target_config.zigtarget),
|
||||
cxx_tool_label,
|
||||
],
|
||||
] + getattr(target_config, "sdk_include_files", [])
|
||||
)
|
||||
|
||||
filegroup(
|
||||
@ -301,7 +376,7 @@ def declare_files(os):
|
||||
"lib/std/**",
|
||||
"lib/*.zig",
|
||||
"lib/*.h",
|
||||
]),
|
||||
]) + getattr(target_config, "sdk_lib_files", []),
|
||||
)
|
||||
|
||||
filegroup(
|
||||
@ -324,13 +399,18 @@ def declare_files(os):
|
||||
],
|
||||
)
|
||||
|
||||
for d in _DEFAULT_INCLUDE_DIRECTORIES + target_config.includes:
|
||||
for d in _DEFAULT_INCLUDE_DIRECTORIES + getattr(target_config, "includes", []):
|
||||
d = "lib/" + d
|
||||
if d not in lazy_filegroups:
|
||||
lazy_filegroups[d] = filegroup(name = d, srcs = native.glob([d + "/**"]))
|
||||
|
||||
|
||||
def _flatten(iterable):
|
||||
result = []
|
||||
for element in iterable:
|
||||
result += element
|
||||
return result
|
||||
|
||||
|
||||
def _macos_versions(versions):
|
||||
return "[{}]".format(", ".join([_quote(v) for v in versions]))
|
||||
|
@ -253,23 +253,34 @@ fn getTarget(self_exe: []const u8) error{BadParent}!?[]const u8 {
|
||||
// having fun.
|
||||
var it = mem.split(u8, triple, "-");
|
||||
|
||||
const arch = it.next() orelse return error.BadParent;
|
||||
if (mem.indexOf(u8, "aarch64,x86_64", arch) == null)
|
||||
const got_arch = it.next() orelse return error.BadParent;
|
||||
if (mem.indexOf(u8, "aarch64,x86_64", got_arch) == null)
|
||||
return error.BadParent;
|
||||
|
||||
const got_os = it.next() orelse return error.BadParent;
|
||||
if (mem.indexOf(u8, "linux,macos,windows", got_os) == null)
|
||||
return error.BadParent;
|
||||
|
||||
const got_abi = it.next();
|
||||
// ABI triple is too much of a moving target
|
||||
if (it.next() == null) return error.BadParent;
|
||||
if (got_abi == null) return error.BadParent;
|
||||
// but the target needs to have 3 dashes.
|
||||
if (it.next() != null) return error.BadParent;
|
||||
|
||||
if (mem.eql(u8, "c++" ++ EXE, fs.path.basename(self_exe)))
|
||||
return triple
|
||||
else
|
||||
if (!mem.eql(u8, "c++" ++ EXE, fs.path.basename(self_exe)))
|
||||
return null;
|
||||
|
||||
// HACK: if OS is macos, then force the ABI triple to "none".
|
||||
if (!mem.eql(u8, got_os, "macos"))
|
||||
return triple;
|
||||
|
||||
if (mem.eql(u8, got_arch, "aarch64"))
|
||||
return "aarch64-macos-none";
|
||||
|
||||
if (mem.eql(u8, got_arch, "x86_64"))
|
||||
return "x86_64-macos-none";
|
||||
|
||||
unreachable;
|
||||
}
|
||||
|
||||
const testing = std.testing;
|
||||
|
@ -1,20 +0,0 @@
|
||||
# Copyright 2023 Uber Technologies, Inc.
|
||||
# Licensed under the Apache License, Version 2.0
|
||||
|
||||
load("@bazel-zig-cc//toolchain/libc:defs.bzl", "declare_libcs")
|
||||
|
||||
package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
constraint_setting(
|
||||
name = "variant",
|
||||
default_constraint_value = "unconstrained",
|
||||
)
|
||||
|
||||
constraint_value(
|
||||
name = "unconstrained",
|
||||
constraint_setting = "variant",
|
||||
)
|
||||
|
||||
declare_libcs()
|
22
toolchain/libc/BUILD.sdk.bazel
Normal file
22
toolchain/libc/BUILD.sdk.bazel
Normal file
@ -0,0 +1,22 @@
|
||||
# Copyright 2023 Uber Technologies, Inc.
|
||||
# Licensed under the Apache License, Version 2.0
|
||||
|
||||
load("@bazel-zig-cc//toolchain/libc:defs.bzl", "declare_libcs")
|
||||
|
||||
package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
constraint_setting(
|
||||
name = "variant",
|
||||
default_constraint_value = "unconstrained",
|
||||
)
|
||||
|
||||
constraint_value(
|
||||
name = "unconstrained",
|
||||
constraint_setting = "variant",
|
||||
)
|
||||
|
||||
declare_libcs(
|
||||
macos_sdk_versions = {macos_sdk_versions}
|
||||
)
|
@ -3,8 +3,8 @@
|
||||
|
||||
load("@bazel-zig-cc//toolchain/private:defs.bzl", "LIBCS")
|
||||
|
||||
def declare_libcs():
|
||||
for libc in LIBCS:
|
||||
def declare_libcs(macos_sdk_versions):
|
||||
for libc in LIBCS + ["macos." + v for v in macos_sdk_versions]:
|
||||
native.constraint_value(
|
||||
name = libc,
|
||||
constraint_setting = "variant",
|
||||
|
@ -1,10 +0,0 @@
|
||||
# Copyright 2023 Uber Technologies, Inc.
|
||||
# Licensed under the Apache License, Version 2.0
|
||||
|
||||
load("@bazel-zig-cc//toolchain/platform:defs.bzl", "declare_libc_aware_platforms")
|
||||
|
||||
package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
declare_libc_aware_platforms()
|
12
toolchain/libc_aware/platform/BUILD.sdk.bazel
Normal file
12
toolchain/libc_aware/platform/BUILD.sdk.bazel
Normal file
@ -0,0 +1,12 @@
|
||||
# Copyright 2023 Uber Technologies, Inc.
|
||||
# Licensed under the Apache License, Version 2.0
|
||||
|
||||
load("@bazel-zig-cc//toolchain/platform:defs.bzl", "declare_libc_aware_platforms")
|
||||
|
||||
package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
declare_libc_aware_platforms(
|
||||
macos_sdk_versions = {macos_sdk_versions}
|
||||
)
|
@ -1,10 +0,0 @@
|
||||
# Copyright 2023 Uber Technologies, Inc.
|
||||
# Licensed under the Apache License, Version 2.0
|
||||
|
||||
load("@bazel-zig-cc//toolchain/toolchain:defs.bzl", "declare_libc_aware_toolchains")
|
||||
|
||||
package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
declare_libc_aware_toolchains()
|
12
toolchain/libc_aware/toolchain/BUILD.sdk.bazel
Normal file
12
toolchain/libc_aware/toolchain/BUILD.sdk.bazel
Normal file
@ -0,0 +1,12 @@
|
||||
# Copyright 2023 Uber Technologies, Inc.
|
||||
# Licensed under the Apache License, Version 2.0
|
||||
|
||||
load("@bazel-zig-cc//toolchain/toolchain:defs.bzl", "declare_libc_aware_toolchains")
|
||||
|
||||
package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
declare_libc_aware_toolchains(
|
||||
macos_sdk_versions = {macos_sdk_versions}
|
||||
)
|
@ -14,7 +14,7 @@ def declare_platforms():
|
||||
for os in oss:
|
||||
declare_platform(gocpu, zigcpu, bzlos, os)
|
||||
|
||||
def declare_libc_aware_platforms():
|
||||
def declare_libc_aware_platforms(macos_sdk_versions):
|
||||
# create @zig_sdk//{os}_{arch}_platform entries with zig and go conventions
|
||||
# with libc specified
|
||||
for zigcpu, gocpu in _CPUS:
|
||||
@ -27,6 +27,15 @@ def declare_libc_aware_platforms():
|
||||
suffix = "_{}".format(libc),
|
||||
extra_constraints = ["@zig_sdk//libc:{}".format(libc)],
|
||||
)
|
||||
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)],
|
||||
)
|
||||
|
||||
def declare_platform(gocpu, zigcpu, bzlos, os, suffix = "", extra_constraints = []):
|
||||
constraint_values = [
|
||||
|
@ -11,12 +11,11 @@ DEFAULT_TOOL_PATHS = {
|
||||
"strip": "/usr/bin/false",
|
||||
}.items()
|
||||
|
||||
def declare_cc_toolchains(os, zig_sdk_path):
|
||||
for target_config in target_structs():
|
||||
def declare_cc_toolchains(os, zig_sdk_path, macos_sdk_versions):
|
||||
for target_config in target_structs(macos_sdk_versions):
|
||||
gotarget = target_config.gotarget
|
||||
zigtarget = target_config.zigtarget
|
||||
|
||||
cxx_builtin_include_directories = []
|
||||
absolute_tool_paths = {}
|
||||
for name, path in target_config.tool_paths.items() + DEFAULT_TOOL_PATHS:
|
||||
if path[0] == "/":
|
||||
@ -30,9 +29,9 @@ def declare_cc_toolchains(os, zig_sdk_path):
|
||||
|
||||
dynamic_library_linkopts = target_config.dynamic_library_linkopts
|
||||
copts = target_config.copts
|
||||
linkopts = []
|
||||
linkopts = target_config.linkopts
|
||||
for s in getattr(target_config, "linker_version_scripts", []):
|
||||
linkopts = ["-Wl,--version-script,%s/%s" % (zig_sdk_path, s)]
|
||||
linkopts.append("-Wl,--version-script,%s/%s" % (zig_sdk_path, s))
|
||||
for incl in getattr(target_config, "compiler_extra_includes", []):
|
||||
copts = copts + ["-include", zig_sdk_path + "/" + incl]
|
||||
|
||||
@ -44,7 +43,11 @@ def declare_cc_toolchains(os, zig_sdk_path):
|
||||
name = zigtarget + "_cc_config",
|
||||
target = zigtarget,
|
||||
tool_paths = absolute_tool_paths,
|
||||
cxx_builtin_include_directories = cxx_builtin_include_directories,
|
||||
cxx_builtin_include_directories = getattr(
|
||||
target_config,
|
||||
"cxx_builtin_include_directories",
|
||||
[],
|
||||
),
|
||||
copts = copts,
|
||||
linkopts = linkopts,
|
||||
dynamic_library_linkopts = dynamic_library_linkopts,
|
||||
|
@ -36,36 +36,41 @@ def zig_tool_path(os):
|
||||
else:
|
||||
return _ZIG_TOOL_PATH
|
||||
|
||||
def target_structs():
|
||||
def target_structs(macos_sdk_versions):
|
||||
ret = []
|
||||
for zigcpu, gocpu in (("x86_64", "amd64"), ("aarch64", "arm64")):
|
||||
ret.append(_target_macos(gocpu, zigcpu))
|
||||
ret.append(_target_windows(gocpu, zigcpu))
|
||||
ret.append(_target_linux_musl(gocpu, zigcpu))
|
||||
for glibc in _GLIBCS:
|
||||
ret.append(_target_linux_gnu(gocpu, zigcpu, glibc))
|
||||
for macos_sdk_version in macos_sdk_versions:
|
||||
ret.append(_target_macos(gocpu, zigcpu, macos_sdk_version))
|
||||
return ret
|
||||
|
||||
def _target_macos(gocpu, zigcpu):
|
||||
min_os = "11"
|
||||
copts = []
|
||||
def _target_macos(gocpu, zigcpu, macos_sdk_version):
|
||||
macos_sdk_opts = [
|
||||
"--sysroot",
|
||||
"external/macos_sdk_{}".format(macos_sdk_version),
|
||||
"-F",
|
||||
"/System/Library/Frameworks",
|
||||
]
|
||||
|
||||
copts = macos_sdk_opts
|
||||
|
||||
if zigcpu == "aarch64":
|
||||
copts = ["-mcpu=apple_m1"]
|
||||
copts.append("-mcpu=apple_m1")
|
||||
|
||||
return struct(
|
||||
gotarget = "darwin_{}".format(gocpu),
|
||||
zigtarget = "{}-macos-none".format(zigcpu),
|
||||
includes = [
|
||||
"libunwind/include",
|
||||
# TODO: Define a toolchain for each minimum OS version
|
||||
"libc/include/{}-macos.{}-none".format(zigcpu, min_os),
|
||||
"libc/include/any-macos.{}-any".format(min_os),
|
||||
"libc/include/any-macos-any",
|
||||
] + _INCLUDE_TAIL,
|
||||
gotarget = "darwin_{}_sdk.{}".format(gocpu, macos_sdk_version),
|
||||
zigtarget = "{}-macos-sdk.{}".format(zigcpu, macos_sdk_version),
|
||||
includes = [],
|
||||
linkopts = macos_sdk_opts,
|
||||
dynamic_library_linkopts = ["-Wl,-undefined=dynamic_lookup"],
|
||||
cxx_builtin_include_directories = ["external/macos_sdk_{}/usr/include".format(macos_sdk_version)],
|
||||
sdk_include_files = ["@macos_sdk_{}//:usr_include".format(macos_sdk_version)],
|
||||
sdk_lib_files = ["@macos_sdk_{}//:usr_lib".format(macos_sdk_version)],
|
||||
copts = copts,
|
||||
libc = "darwin",
|
||||
libc = "macos",
|
||||
bazel_target_cpu = "darwin",
|
||||
constraint_values = [
|
||||
"@platforms//os:macos",
|
||||
@ -79,6 +84,7 @@ def _target_macos(gocpu, zigcpu):
|
||||
"extension": ".dylib",
|
||||
},
|
||||
],
|
||||
libc_constraint = "@zig_sdk//libc:macos.{}".format(macos_sdk_version),
|
||||
)
|
||||
|
||||
def _target_windows(gocpu, zigcpu):
|
||||
@ -90,6 +96,7 @@ def _target_windows(gocpu, zigcpu):
|
||||
"libunwind/include",
|
||||
"libc/include/any-windows-any",
|
||||
] + _INCLUDE_TAIL,
|
||||
linkopts = [],
|
||||
dynamic_library_linkopts = [],
|
||||
copts = [],
|
||||
libc = "mingw",
|
||||
@ -145,6 +152,7 @@ def _target_linux_gnu(gocpu, zigcpu, glibc_version):
|
||||
] + _INCLUDE_TAIL,
|
||||
compiler_extra_includes = compiler_extra_includes,
|
||||
linker_version_scripts = linker_version_scripts,
|
||||
linkopts = [],
|
||||
dynamic_library_linkopts = [],
|
||||
copts = [],
|
||||
libc = "glibc",
|
||||
@ -171,6 +179,7 @@ def _target_linux_musl(gocpu, zigcpu):
|
||||
(["libc/include/{}-linux-any".format(zigcpu)] if zigcpu != "x86_64" else []) + [
|
||||
"libc/include/any-linux-any",
|
||||
] + _INCLUDE_TAIL,
|
||||
linkopts = [],
|
||||
dynamic_library_linkopts = [],
|
||||
copts = ["-D_LIBCPP_HAS_MUSL_LIBC", "-D_LIBCPP_HAS_THREAD_API_PTHREAD"],
|
||||
libc = "musl",
|
||||
|
@ -4,4 +4,6 @@ package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
declare_toolchains()
|
||||
declare_toolchains(
|
||||
macos_sdk_versions = {macos_sdk_versions},
|
||||
)
|
||||
|
@ -1,7 +1,7 @@
|
||||
load("@bazel-zig-cc//toolchain/private:defs.bzl", "target_structs")
|
||||
|
||||
def declare_toolchains():
|
||||
for target_config in target_structs():
|
||||
def declare_toolchains(macos_sdk_versions):
|
||||
for target_config in target_structs(macos_sdk_versions):
|
||||
gotarget = target_config.gotarget
|
||||
zigtarget = target_config.zigtarget
|
||||
|
||||
@ -14,8 +14,8 @@ def declare_toolchains():
|
||||
|
||||
_declare_toolchain(gotarget, zigtarget, target_config.constraint_values + extra_constraints)
|
||||
|
||||
def declare_libc_aware_toolchains():
|
||||
for target_config in target_structs():
|
||||
def declare_libc_aware_toolchains(macos_sdk_versions):
|
||||
for target_config in target_structs(macos_sdk_versions):
|
||||
gotarget = target_config.gotarget
|
||||
zigtarget = target_config.zigtarget
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user