1

speed first safety later

This commit is contained in:
Motiejus Jakštys 2021-08-04 19:46:21 +03:00
parent 144a87cd4c
commit 4d44d9ffd4
2 changed files with 21 additions and 4 deletions

View File

@ -53,4 +53,7 @@ load(
zig_register_toolchains = "register_toolchains", zig_register_toolchains = "register_toolchains",
) )
zig_register_toolchains(glibc_version = "2.19") zig_register_toolchains(
glibc_version = "2.19",
speed_first_safety_later = True,
)

View File

@ -111,13 +111,17 @@ def _target_linux_musl(gocpu, zigcpu):
def register_toolchains( def register_toolchains(
register_linux_libc = "gnu", register_linux_libc = "gnu",
glibc_version = _GLIBCS[-1]): glibc_version = _GLIBCS[-1],
speed_first_safety_later = False):
"""register_toolchains downloads and registers zig toolchains: """register_toolchains downloads and registers zig toolchains:
@param register_linux_libc: either "musl" or "gnu". Only one can be @param register_linux_libc: either "musl" or "gnu". Only one can be
registered at a time to avoid conflict. registered at a time to avoid conflict.
@param glibc_version: which glibc version to use when compiling via @param glibc_version: which glibc version to use when compiling via
glibc (either via registered toolchain, or via --extra_toolchains). glibc (either via registered toolchain, or via --extra_toolchains).
@param speed_first_safety_later: remove workaround of
github.com/ziglang/zig/issues/9431; dramatically increases compilation
speed
""" """
if register_linux_libc not in ("gnu", "musl"): if register_linux_libc not in ("gnu", "musl"):
@ -140,6 +144,7 @@ def register_toolchains(
"linux-x86_64": "lib/", "linux-x86_64": "lib/",
}, },
glibc_version = glibc_version, glibc_version = glibc_version,
speed_first_safety_later = speed_first_safety_later,
) )
for cfg in _target_structs(glibc_version): for cfg in _target_structs(glibc_version):
@ -165,7 +170,7 @@ export ZIG_LOCAL_CACHE_DIR="$cache_prefix/bazel-zig-cc"
export ZIG_GLOBAL_CACHE_DIR=$ZIG_LOCAL_CACHE_DIR export ZIG_GLOBAL_CACHE_DIR=$ZIG_LOCAL_CACHE_DIR
# https://github.com/ziglang/zig/issues/9431 # https://github.com/ziglang/zig/issues/9431
exec flock "{zig}" "{zig}" "{zig_tool}" "$@" exec {maybe_flock} "{zig}" "{zig_tool}" "$@"
""" """
_ZIG_TOOLS = [ _ZIG_TOOLS = [
@ -198,10 +203,18 @@ def _zig_repository_impl(repository_ctx):
sha256 = zig_sha256, sha256 = zig_sha256,
) )
maybe_flock = "flock"
if repository_ctx.attr.speed_first_safety_later:
maybe_flock = ""
for zig_tool in _ZIG_TOOLS: for zig_tool in _ZIG_TOOLS:
repository_ctx.file( repository_ctx.file(
ZIG_TOOL_PATH.format(zig_tool = zig_tool), ZIG_TOOL_PATH.format(zig_tool = zig_tool),
ZIG_TOOL_WRAPPER.format(zig = str(repository_ctx.path("zig")), zig_tool = zig_tool), ZIG_TOOL_WRAPPER.format(
zig = str(repository_ctx.path("zig")),
zig_tool = zig_tool,
maybe_flock = maybe_flock,
),
) )
repository_ctx.file( repository_ctx.file(
@ -231,6 +244,7 @@ zig_repository = repository_rule(
"url_format": attr.string(), "url_format": attr.string(),
"host_platform_include_root": attr.string_dict(), "host_platform_include_root": attr.string_dict(),
"glibc_version": attr.string(values = _GLIBCS), "glibc_version": attr.string(values = _GLIBCS),
"speed_first_safety_later": attr.bool(),
}, },
implementation = _zig_repository_impl, implementation = _zig_repository_impl,
) )