Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions toolchain/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,14 @@ def _zig_repository_impl(repository_ctx):
"_ext": zig_ext,
"version": repository_ctx.attr.version,
"host_platform": host_platform,
# Zig >=0.14.1 tarballs are named zig-{arch}-{os}-{version}.
"zig_platform": "{}-{}".format(host_arch, host_os),
}
format_vars_exec = {
"_ext": repository_ctx.attr.host_platform_ext[exec_platform],
"version": repository_ctx.attr.version,
"host_platform": exec_platform,
"zig_platform": "{}-{}".format(exec_arch, exec_os),
}

for dest, src in {
Expand All @@ -179,7 +182,7 @@ def _zig_repository_impl(repository_ctx):
repository_ctx.download_and_extract(
auth = use_netrc(read_user_netrc(repository_ctx), urls, {}),
url = urls,
stripPrefix = "zig-{host_platform}-{version}/".format(**format_vars),
stripPrefix = "zig-{zig_platform}-{version}/".format(**format_vars),
sha256 = zig_sha256,
)

Expand Down Expand Up @@ -267,7 +270,7 @@ def _zig_repository_impl(repository_ctx):
repository_ctx.download_and_extract(
auth = use_netrc(read_user_netrc(repository_ctx), urls, {}),
url = urls,
stripPrefix = "zig-{host_platform}-{version}/".format(**format_vars_exec),
stripPrefix = "zig-{zig_platform}-{version}/".format(**format_vars_exec),
sha256 = repository_ctx.attr.host_platform_sha256[exec_platform],
)

Expand Down Expand Up @@ -345,7 +348,11 @@ def declare_files(os):
"lib/libunwind/**",
"lib/compiler_rt/**",
"lib/std/**",
"lib/tsan/**",
# Zig 0.15 renamed lib/tsan to lib/libtsan.
"lib/libtsan/**",
# Zig 0.15's lib/c.zig (the libzigc shim built during linking)
# imports lib/c/*.zig, which must be staged into the sandbox.
"lib/c/**",
"lib/*.zig",
"lib/*.h",
]),
Expand Down
11 changes: 7 additions & 4 deletions toolchain/private/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,15 @@ def _target_linux_gnu(gocpu, zigcpu, glibc_version):
gotarget = "linux_{}_{}".format(gocpu, glibc_suffix),
zigtarget = "{}-linux-{}".format(zigcpu, glibc_suffix),
includes = [
"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 []) + [
# Zig 0.15 folded x86_64-linux-gnu into the shared
# x86-linux-gnu dir. x86_64-linux-any never existed and is
# likewise covered by x86-linux-any.
(["libc/include/x86-linux-gnu", "libc/include/x86-linux-any"] if zigcpu == "x86_64" else [
"libc/include/{}-linux-gnu".format(zigcpu),
"libc/include/{}-linux-any".format(zigcpu),
]) + [
"libc/include/any-linux-any",
] + _INCLUDE_TAIL,
linkopts = [],
Expand Down
24 changes: 15 additions & 9 deletions toolchain/private/zig_sdk.bzl
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
VERSION = "0.14.0"
VERSION = "0.15.2"

HOST_PLATFORM_SHA256 = {
"linux-aarch64": "ab64e3ea277f6fc5f3d723dcd95d9ce1ab282c8ed0f431b4de880d30df891e4f",
"linux-x86_64": "473ec26806133cf4d1918caf1a410f8403a13d979726a9045b421b685031a982",
"macos-aarch64": "b71e4b7c4b4be9953657877f7f9e6f7ee89114c716da7c070f4a238220e95d7e",
"macos-x86_64": "685816166f21f0b8d6fc7aa6a36e91396dcd82ca6556dfbe3e329deffc01fec3",
"windows-aarch64": "03e984383ebb8f85293557cfa9f48ee8698e7c400239570c9ff1aef3bffaf046",
"windows-x86_64": "f53e5f9011ba20bbc3e0e6d0a9441b31eb227a97bac0e7d24172f1b8b27b4371",
"linux-aarch64": "958ed7d1e00d0ea76590d27666efbf7a932281b3d7ba0c6b01b0ff26498f667f",
"linux-x86_64": "02aa270f183da276e5b5920b1dac44a63f1a49e55050ebde3aecc9eb82f93239",
"macos-aarch64": "3cc2bab367e185cdfb27501c4b30b1b0653c28d9f73df8dc91488e66ece5fa6b",
"macos-x86_64": "375b6909fc1495d16fc2c7db9538f707456bfc3373b14ee83fdd3e22b3d43f7f",
"windows-aarch64": "b926465f8872bf983422257cd9ec248bb2b270996fbe8d57872cca13b56fc370",
"windows-x86_64": "3a0ed1e8799a2f8ce2a6e6290a9ff22e6906f8227865911fb7ddedc3cc14cb0c",
}

# Zig >=0.14.1 names its release tarballs zig-{arch}-{os}-{version} (arch
# first), whereas older releases used zig-{os}-{arch}-{version}. The download
# URL and archive strip-prefix therefore use the {zig_platform} format var
# (arch-os), while the dicts above stay keyed by {os}-{arch} for the public
# host_platform_sha256 / host_platform_ext override API.

# Official recommended version. Should use this when we have a usable release.
URL_FORMAT_RELEASE = "https://ziglang.org/download/{version}/zig-{host_platform}-{version}.{_ext}"
URL_FORMAT_RELEASE = "https://ziglang.org/download/{version}/zig-{zig_platform}-{version}.{_ext}"

# Caution: nightly releases are purged from ziglang.org after ~90 days. Use the
# Bazel mirror or your own.
URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.{_ext}"
URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{zig_platform}-{version}.{_ext}"
10 changes: 10 additions & 0 deletions toolchain/zig-wrapper.zig
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ fn parseArgs(
.arg1, .cc => try args.appendSlice(arena, &[_][]const u8{arg0_noexe}),
}

// Zig 0.15 compiles C/C++ with UBSan instrumentation by default, which
// surfaces as `ld.lld: error: undefined symbol: __ubsan_handle_*` when
// the instrumented objects are linked. Disable it by default; the flag
// is added before the caller's args, so an explicit -fsanitize=undefined
// from the caller still takes precedence.
if (run_mode == RunMode.cc)
try args.appendSlice(arena, &[_][]const u8{"-fno-sanitize=undefined"});

// Process arguments, transforming -u SYMBOL into -Wl,-u,SYMBOL
// This is needed because zig c++ doesn't handle the -u flag correctly
// (it tries to open the symbol name as a file instead of passing it to the linker)
Expand Down Expand Up @@ -454,6 +462,7 @@ test "zig-wrapper:parseArgs" {
"tools" ++ sep ++ "x86_64-linux-musl" ++ sep ++
".." ++ sep ++ ".." ++ sep ++ "zig" ++ EXE,
"c++",
"-fno-sanitize=undefined",
"main.c",
"-o",
"/dev/null",
Expand Down Expand Up @@ -498,6 +507,7 @@ test "zig-wrapper:parseArgs" {
.args = &[_][:0]const u8{
"external" ++ sep ++ "zig_sdk" ++ sep ++ "zig" ++ EXE,
"c++",
"-fno-sanitize=undefined",
"main.c",
"-o",
"/dev/null",
Expand Down
10 changes: 8 additions & 2 deletions toolchain/zig_cc_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ def _compilation_mode_features(ctx):
actions = actions,
flag_groups = [
flag_group(
flags = ["-g", "-fsanitize-undefined-strip-path-components=-1"],
# -fno-sanitize=undefined: Zig 0.15 enables UBSan for
# C/C++ by default, which leads to `undefined symbol:
# __ubsan_handle_*` link errors. The wrapper also
# passes this flag; it is repeated here so the intent
# is visible in the toolchain config.
flags = ["-g", "-fsanitize-undefined-strip-path-components=-1", "-fno-sanitize=undefined"],
),
],
),
Expand Down Expand Up @@ -79,7 +84,8 @@ def _compilation_mode_features(ctx):
actions = actions,
flag_groups = [
flag_group(
flags = ["-fno-lto", "-fsanitize-undefined-strip-path-components=-1"],
# -fno-sanitize=undefined: see the dbg feature above.
flags = ["-fno-lto", "-fsanitize-undefined-strip-path-components=-1", "-fno-sanitize=undefined"],
),
],
),
Expand Down
Loading