toolchain wrapper: zig_exe path is relative
Just like we know the path to zig_lib_dir, we do know the path to zig_exe. Lets use that. This was surfaced by experimenting with `--experimental_use_hermetic_linux_sandbox`. `repository_ctx.path("zig")` would return the real file system path to zig (outside of the sandbox), which is not good when the sandbox is hermetic. Co-developed-by: Fabian Hahn <fabian@hahn.graphics>
This commit is contained in:
parent
43b6e1c0c1
commit
1fb93e089c
|
@ -92,21 +92,25 @@ _ZIG_TOOLS = [
|
||||||
_ZIG_TOOL_WRAPPER_WINDOWS_CACHE_KNOWN = """@echo off
|
_ZIG_TOOL_WRAPPER_WINDOWS_CACHE_KNOWN = """@echo off
|
||||||
if exist "external\\zig_sdk\\lib\\*" goto :have_external_zig_sdk_lib
|
if exist "external\\zig_sdk\\lib\\*" goto :have_external_zig_sdk_lib
|
||||||
set ZIG_LIB_DIR=%~dp0\\..\\..\\lib
|
set ZIG_LIB_DIR=%~dp0\\..\\..\\lib
|
||||||
|
set ZIG_EXE=%~dp0\\..\\..\\zig.exe
|
||||||
goto :set_zig_lib_dir
|
goto :set_zig_lib_dir
|
||||||
:have_external_zig_sdk_lib
|
:have_external_zig_sdk_lib
|
||||||
set ZIG_LIB_DIR=external\\zig_sdk\\lib
|
set ZIG_LIB_DIR=external\\zig_sdk\\lib
|
||||||
|
set ZIG_EXE=external\\zig_sdk\\zig.exe
|
||||||
:set_zig_lib_dir
|
:set_zig_lib_dir
|
||||||
set ZIG_LOCAL_CACHE_DIR={cache_prefix}\\bazel-zig-cc
|
set ZIG_LOCAL_CACHE_DIR={cache_prefix}\\bazel-zig-cc
|
||||||
set ZIG_GLOBAL_CACHE_DIR=%ZIG_LOCAL_CACHE_DIR%
|
set ZIG_GLOBAL_CACHE_DIR=%ZIG_LOCAL_CACHE_DIR%
|
||||||
"{zig}" "{zig_tool}" {maybe_target} %*
|
"%ZIG_EXE%" "{zig_tool}" {maybe_target} %*
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_ZIG_TOOL_WRAPPER_WINDOWS_CACHE_GUESS = """@echo off
|
_ZIG_TOOL_WRAPPER_WINDOWS_CACHE_GUESS = """@echo off
|
||||||
if exist "external\\zig_sdk\\lib\\*" goto :have_external_zig_sdk_lib
|
if exist "external\\zig_sdk\\lib\\*" goto :have_external_zig_sdk_lib
|
||||||
set ZIG_LIB_DIR=%~dp0\\..\\..\\lib
|
set ZIG_LIB_DIR=%~dp0\\..\\..\\lib
|
||||||
|
set ZIG_EXE=%~dp0\\..\\..\\zig.exe
|
||||||
goto :set_zig_lib_dir
|
goto :set_zig_lib_dir
|
||||||
:have_external_zig_sdk_lib
|
:have_external_zig_sdk_lib
|
||||||
set ZIG_LIB_DIR=external\\zig_sdk\\lib
|
set ZIG_LIB_DIR=external\\zig_sdk\\lib
|
||||||
|
set ZIG_EXE=external\\zig_sdk\\zig.exe
|
||||||
:set_zig_lib_dir
|
:set_zig_lib_dir
|
||||||
if exist "%TMP%\\*" goto :usertmp
|
if exist "%TMP%\\*" goto :usertmp
|
||||||
set ZIG_LOCAL_CACHE_DIR=C:\\Temp\\bazel-zig-cc
|
set ZIG_LOCAL_CACHE_DIR=C:\\Temp\\bazel-zig-cc
|
||||||
|
@ -115,29 +119,33 @@ goto zig
|
||||||
set ZIG_LOCAL_CACHE_DIR=%TMP%\\bazel-zig-cc
|
set ZIG_LOCAL_CACHE_DIR=%TMP%\\bazel-zig-cc
|
||||||
:zig
|
:zig
|
||||||
set ZIG_GLOBAL_CACHE_DIR=%ZIG_LOCAL_CACHE_DIR%
|
set ZIG_GLOBAL_CACHE_DIR=%ZIG_LOCAL_CACHE_DIR%
|
||||||
"{zig}" "{zig_tool}" {maybe_target} %*
|
"%ZIG_EXE%" "{zig_tool}" {maybe_target} %*
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_ZIG_TOOL_WRAPPER_CACHE_KNOWN = """#!/bin/sh
|
_ZIG_TOOL_WRAPPER_CACHE_KNOWN = """#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
if [ -d external/zig_sdk/lib ]; then
|
if [ -d external/zig_sdk/lib ]; then
|
||||||
ZIG_LIB_DIR=external/zig_sdk/lib
|
ZIG_LIB_DIR=external/zig_sdk/lib
|
||||||
|
ZIG_EXE=external/zig_sdk/zig
|
||||||
else
|
else
|
||||||
ZIG_LIB_DIR="$(dirname "$0")/../../lib"
|
ZIG_LIB_DIR="$(dirname "$0")/../../lib"
|
||||||
|
ZIG_EXE="$(dirname "$0")/../../zig"
|
||||||
fi
|
fi
|
||||||
export ZIG_LIB_DIR
|
export ZIG_LIB_DIR
|
||||||
export ZIG_LOCAL_CACHE_DIR="{cache_prefix}/bazel-zig-cc"
|
export ZIG_LOCAL_CACHE_DIR="{cache_prefix}/bazel-zig-cc"
|
||||||
export ZIG_GLOBAL_CACHE_DIR="{cache_prefix}/bazel-zig-cc"
|
export ZIG_GLOBAL_CACHE_DIR="{cache_prefix}/bazel-zig-cc"
|
||||||
{maybe_gohack}
|
{maybe_gohack}
|
||||||
exec "{zig}" "{zig_tool}" {maybe_target} "$@"
|
exec "$ZIG_EXE" "{zig_tool}" {maybe_target} "$@"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_ZIG_TOOL_WRAPPER_CACHE_GUESS = """#!/bin/sh
|
_ZIG_TOOL_WRAPPER_CACHE_GUESS = """#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
if [ -d external/zig_sdk/lib ]; then
|
if [ -d external/zig_sdk/lib ]; then
|
||||||
ZIG_LIB_DIR=external/zig_sdk/lib
|
ZIG_LIB_DIR=external/zig_sdk/lib
|
||||||
|
ZIG_EXE=external/zig_sdk/zig
|
||||||
else
|
else
|
||||||
ZIG_LIB_DIR="$(dirname "$0")/../../lib"
|
ZIG_LIB_DIR="$(dirname "$0")/../../lib"
|
||||||
|
ZIG_EXE="$(dirname "$0")/../../zig"
|
||||||
fi
|
fi
|
||||||
if [ -n "$TMPDIR" ]; then
|
if [ -n "$TMPDIR" ]; then
|
||||||
_cache_prefix=$TMPDIR
|
_cache_prefix=$TMPDIR
|
||||||
|
@ -154,7 +162,7 @@ export ZIG_LIB_DIR
|
||||||
export ZIG_LOCAL_CACHE_DIR="$_cache_prefix/bazel-zig-cc"
|
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
|
||||||
{maybe_gohack}
|
{maybe_gohack}
|
||||||
exec "{zig}" "{zig_tool}" {maybe_target} "$@"
|
exec "$ZIG_EXE" "{zig_tool}" {maybe_target} "$@"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# The abomination below adds "-O2" to Go's link-prober command. Saves around
|
# The abomination below adds "-O2" to Go's link-prober command. Saves around
|
||||||
|
@ -176,14 +184,13 @@ fi
|
||||||
eval set -- "$saved"
|
eval set -- "$saved"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _zig_tool_wrapper(zig_tool, zig, is_windows, cache_prefix, zigtarget):
|
def _zig_tool_wrapper(zig_tool, is_windows, cache_prefix, zigtarget):
|
||||||
if zig_tool in ["c++", "build-exe", "build-lib", "build-obj"]:
|
if zig_tool in ["c++", "build-exe", "build-lib", "build-obj"]:
|
||||||
maybe_target = "-target {}".format(zigtarget)
|
maybe_target = "-target {}".format(zigtarget)
|
||||||
else:
|
else:
|
||||||
maybe_target = ""
|
maybe_target = ""
|
||||||
|
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
zig = str(zig).replace("/", "\\") + ".exe" if is_windows else zig,
|
|
||||||
zig_tool = zig_tool,
|
zig_tool = zig_tool,
|
||||||
cache_prefix = cache_prefix,
|
cache_prefix = cache_prefix,
|
||||||
maybe_gohack = _ZIG_TOOL_GOHACK if (zig_tool == "c++" and not is_windows) else "",
|
maybe_gohack = _ZIG_TOOL_GOHACK if (zig_tool == "c++" and not is_windows) else "",
|
||||||
|
@ -266,7 +273,6 @@ def _zig_repository_impl(repository_ctx):
|
||||||
for target_config in target_structs():
|
for target_config in target_structs():
|
||||||
zig_tool_wrapper = _zig_tool_wrapper(
|
zig_tool_wrapper = _zig_tool_wrapper(
|
||||||
zig_tool,
|
zig_tool,
|
||||||
str(repository_ctx.path("zig")),
|
|
||||||
os == "windows",
|
os == "windows",
|
||||||
repository_ctx.os.environ.get("BAZEL_ZIG_CC_CACHE_PREFIX", ""),
|
repository_ctx.os.environ.get("BAZEL_ZIG_CC_CACHE_PREFIX", ""),
|
||||||
zigtarget = target_config.zigtarget,
|
zigtarget = target_config.zigtarget,
|
||||||
|
|
Loading…
Reference in New Issue