2022-10-01 14:26:45 +03:00
|
|
|
_ZIG_TOOL_PATH = "tools/{zigtarget}/{zig_tool}"
|
2022-04-06 23:10:45 +03:00
|
|
|
|
|
|
|
# Zig supports even older glibcs than defined below, but we have tested only
|
|
|
|
# down to 2.17.
|
|
|
|
# $ zig targets | jq -r '.glibc[]' | sort -V
|
|
|
|
_GLIBCS = [
|
|
|
|
"2.17",
|
|
|
|
"2.18",
|
|
|
|
"2.19",
|
|
|
|
"2.22",
|
|
|
|
"2.23",
|
|
|
|
"2.24",
|
|
|
|
"2.25",
|
|
|
|
"2.26",
|
|
|
|
"2.27",
|
|
|
|
"2.28",
|
|
|
|
"2.29",
|
|
|
|
"2.30",
|
|
|
|
"2.31",
|
|
|
|
"2.32",
|
|
|
|
"2.33",
|
|
|
|
"2.34",
|
|
|
|
]
|
|
|
|
|
2022-04-15 15:20:42 +03:00
|
|
|
LIBCS = ["musl"] + ["gnu.{}".format(glibc) for glibc in _GLIBCS]
|
2022-04-13 17:52:25 +03:00
|
|
|
|
2022-05-29 19:35:16 +03:00
|
|
|
def zig_tool_path(os):
|
|
|
|
if os == "windows":
|
|
|
|
return _ZIG_TOOL_PATH + ".bat"
|
|
|
|
else:
|
|
|
|
return _ZIG_TOOL_PATH
|
|
|
|
|
2022-04-06 23:10:45 +03:00
|
|
|
def target_structs():
|
|
|
|
ret = []
|
|
|
|
for zigcpu, gocpu in (("x86_64", "amd64"), ("aarch64", "arm64")):
|
|
|
|
ret.append(_target_darwin(gocpu, zigcpu))
|
2022-05-29 19:35:17 +03:00
|
|
|
ret.append(_target_windows(gocpu, zigcpu))
|
2022-04-06 23:10:45 +03:00
|
|
|
ret.append(_target_linux_musl(gocpu, zigcpu))
|
2022-04-18 11:44:51 +03:00
|
|
|
for glibc in _GLIBCS:
|
2022-04-06 23:10:45 +03:00
|
|
|
ret.append(_target_linux_gnu(gocpu, zigcpu, glibc))
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def _target_darwin(gocpu, zigcpu):
|
|
|
|
min_os = "10"
|
|
|
|
if zigcpu == "aarch64":
|
|
|
|
min_os = "11"
|
|
|
|
return struct(
|
|
|
|
gotarget = "darwin_{}".format(gocpu),
|
2022-06-28 12:47:23 +03:00
|
|
|
zigtarget = "{}-macos-none".format(zigcpu),
|
2022-04-06 23:10:45 +03:00
|
|
|
includes = [
|
|
|
|
"libunwind/include",
|
|
|
|
# TODO: Define a toolchain for each minimum OS version
|
2022-07-27 22:13:06 +03:00
|
|
|
"libc/include/{}-macos.{}-none".format(zigcpu, min_os),
|
2022-04-06 23:10:45 +03:00
|
|
|
"libc/include/any-macos.{}-any".format(min_os),
|
|
|
|
"libc/include/any-macos-any",
|
|
|
|
],
|
|
|
|
linkopts = [],
|
2022-05-25 03:17:33 +03:00
|
|
|
dynamic_library_linkopts = ["-Wl,-undefined=dynamic_lookup"],
|
2022-04-06 23:10:45 +03:00
|
|
|
copts = [],
|
|
|
|
bazel_target_cpu = "darwin",
|
|
|
|
constraint_values = [
|
|
|
|
"@platforms//os:macos",
|
|
|
|
"@platforms//cpu:{}".format(zigcpu),
|
|
|
|
],
|
|
|
|
tool_paths = {"ld": "ld64.lld"},
|
|
|
|
)
|
|
|
|
|
2022-05-29 19:35:17 +03:00
|
|
|
def _target_windows(gocpu, zigcpu):
|
|
|
|
return struct(
|
|
|
|
gotarget = "windows_{}".format(gocpu),
|
|
|
|
zigtarget = "{}-windows-gnu".format(zigcpu),
|
|
|
|
includes = [
|
|
|
|
"libunwind/include",
|
|
|
|
"libc/include/any-windows-any",
|
|
|
|
],
|
|
|
|
linkopts = [],
|
2022-06-02 05:47:51 +03:00
|
|
|
dynamic_library_linkopts = [],
|
2022-05-29 19:35:17 +03:00
|
|
|
copts = [],
|
|
|
|
bazel_target_cpu = "x64_windows",
|
|
|
|
constraint_values = [
|
|
|
|
"@platforms//os:windows",
|
|
|
|
"@platforms//cpu:{}".format(zigcpu),
|
|
|
|
],
|
|
|
|
tool_paths = {"ld": "ld64.lld"},
|
|
|
|
)
|
|
|
|
|
2022-04-18 11:44:51 +03:00
|
|
|
def _target_linux_gnu(gocpu, zigcpu, glibc_version):
|
|
|
|
glibc_suffix = "gnu.{}".format(glibc_version)
|
2022-04-06 23:10:45 +03:00
|
|
|
|
|
|
|
# https://github.com/ziglang/zig/issues/5882#issuecomment-888250676
|
2022-04-18 11:44:51 +03:00
|
|
|
# fcntl_hack is only required for glibc 2.27 or less.
|
|
|
|
fcntl_hack = glibc_version < "2.28"
|
2022-04-06 23:10:45 +03:00
|
|
|
|
|
|
|
return struct(
|
|
|
|
gotarget = "linux_{}_{}".format(gocpu, glibc_suffix),
|
|
|
|
zigtarget = "{}-linux-{}".format(zigcpu, glibc_suffix),
|
|
|
|
includes = [
|
2022-09-26 10:14:08 +03:00
|
|
|
"libc/include/{}-linux-gnu".format(zigcpu),
|
|
|
|
"libc/include/generic-glibc",
|
|
|
|
] +
|
|
|
|
# x86_64-linux-any is x86_64-linux and x86-linux combined.
|
|
|
|
(["libc/include/x86-linux-any"] if zigcpu == "x86_64" else []) +
|
|
|
|
(["libc/include/{}-linux-any".format(zigcpu)] if zigcpu != "x86_64" else []) + [
|
2022-04-06 23:10:45 +03:00
|
|
|
"libc/include/any-linux-any",
|
2022-09-26 10:14:08 +03:00
|
|
|
],
|
2022-04-06 23:10:45 +03:00
|
|
|
toplevel_include = ["glibc-hacks"] if fcntl_hack else [],
|
|
|
|
compiler_extra_includes = ["glibc-hacks/glibchack-fcntl.h"] if fcntl_hack else [],
|
|
|
|
linker_version_scripts = ["glibc-hacks/fcntl.map"] if fcntl_hack else [],
|
|
|
|
linkopts = ["-lc++", "-lc++abi"],
|
2022-05-25 03:14:35 +03:00
|
|
|
dynamic_library_linkopts = [],
|
2022-04-06 23:10:45 +03:00
|
|
|
copts = [],
|
|
|
|
bazel_target_cpu = "k8",
|
|
|
|
constraint_values = [
|
|
|
|
"@platforms//os:linux",
|
|
|
|
"@platforms//cpu:{}".format(zigcpu),
|
|
|
|
],
|
2022-04-13 17:52:25 +03:00
|
|
|
libc_constraint = "@zig_sdk//libc:{}".format(glibc_suffix),
|
2022-04-06 23:10:45 +03:00
|
|
|
tool_paths = {"ld": "ld.lld"},
|
|
|
|
)
|
|
|
|
|
|
|
|
def _target_linux_musl(gocpu, zigcpu):
|
|
|
|
return struct(
|
|
|
|
gotarget = "linux_{}_musl".format(gocpu),
|
|
|
|
zigtarget = "{}-linux-musl".format(zigcpu),
|
|
|
|
includes = [
|
2022-09-26 10:14:08 +03:00
|
|
|
"libc/include/{}-linux-musl".format(zigcpu),
|
|
|
|
"libc/include/generic-musl",
|
|
|
|
] +
|
|
|
|
# x86_64-linux-any is x86_64-linux and x86-linux combined.
|
|
|
|
(["libc/include/x86-linux-any"] if zigcpu == "x86_64" else []) +
|
|
|
|
(["libc/include/{}-linux-any".format(zigcpu)] if zigcpu != "x86_64" else []) + [
|
2022-04-06 23:10:45 +03:00
|
|
|
"libc/include/any-linux-any",
|
2022-09-26 10:14:08 +03:00
|
|
|
],
|
2022-09-02 13:21:39 +03:00
|
|
|
linkopts = [],
|
2022-05-25 03:14:35 +03:00
|
|
|
dynamic_library_linkopts = [],
|
2022-04-06 23:10:45 +03:00
|
|
|
copts = ["-D_LIBCPP_HAS_MUSL_LIBC", "-D_LIBCPP_HAS_THREAD_API_PTHREAD"],
|
|
|
|
bazel_target_cpu = "k8",
|
|
|
|
constraint_values = [
|
|
|
|
"@platforms//os:linux",
|
|
|
|
"@platforms//cpu:{}".format(zigcpu),
|
|
|
|
],
|
2022-04-13 17:52:25 +03:00
|
|
|
libc_constraint = "@zig_sdk//libc:musl",
|
2022-04-06 23:10:45 +03:00
|
|
|
tool_paths = {"ld": "ld.lld"},
|
|
|
|
)
|