aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Imboden <adi@thingdust.com>2024-04-29 15:00:45 +0200
committerGitHub <noreply@github.com>2024-04-29 13:00:45 +0000
commit64920a015b27a934e4660ab8089968b3d50be781 (patch)
tree5bb4fbcaae8efe223b0d54da041a92373d320439
parentc43af7b886f0e185523fb7a280ed83615e643fae (diff)
downloadbazelbuild-rules_rust-64920a015b27a934e4660ab8089968b3d50be781.tar.gz
also rewrite -isystem in addition to -sysroot (#2631)
I build in a hermetic c++ toolchain and use `-isystem` args in addition to `-sysroot` which did not get rewritten before. this is one of the errors I get (indirect dependency when using `aspect_rules_py`): ``` cargo:warning=ToolExecError: Command "/tmp/bazel-working-directory/_main/external/local_config_cc/bin/clang" ... "-nostdinc" "-isystem" "external/local_config_cc/cxxlib/fastbuild/include/clang" "-isystem" "external/local_config_cc/cxxlib/fastbuild/include/x86_64-linux-gnu" "-isystem" "external/local_config_cc/cxxlib/fastbuild/include" "--sysroot=/tmp/bazel-working-directory/_main/external/local_config_cc/cxxlib/fastbuild" ... "-o" "/tmp/bazel-working-directory/_main/bazel-out/k8-fastbuild/bin/external/rules_rust~~crate~crate_index__bzip2-sys-0.1.11-1.0.8/bzip2-sys_bs.out_dir/lib/bzip2-1.0.8/decompress.o" "-c" "bzip2-1.0.8/decompress.c" cargo:warning=In file included from bzip2-1.0.8/decompress.c:22: cargo:warning=bzip2-1.0.8/bzlib_private.h:25:10: fatal error: 'stdlib.h' file not found cargo:warning=#include <stdlib.h> cargo:warning= ^~~~~~~~~~ cargo:warning=1 error generated. ``` I think it is unfortunate and probably brings more weird errors up in the future when the build command does not run in the same place where every other bazel rule runs the compiler.
-rw-r--r--cargo/private/cargo_build_script.bzl26
1 files changed, 25 insertions, 1 deletions
diff --git a/cargo/private/cargo_build_script.bzl b/cargo/private/cargo_build_script.bzl
index 675819d7..fb12c6f2 100644
--- a/cargo/private/cargo_build_script.bzl
+++ b/cargo/private/cargo_build_script.bzl
@@ -61,7 +61,7 @@ def get_cc_compile_args_and_env(cc_toolchain, feature_configuration):
)
return cc_c_args, cc_cxx_args, cc_env
-def _pwd_flags(args):
+def _pwd_flags_sysroot(args):
"""Prefix execroot-relative paths of known arguments with ${pwd}.
Args:
@@ -79,6 +79,30 @@ def _pwd_flags(args):
res.append(arg)
return res
+def _pwd_flags_isystem(args):
+ """Prefix execroot-relative paths of known arguments with ${pwd}.
+
+ Args:
+ args (list): List of tool arguments.
+
+ Returns:
+ list: The modified argument list.
+ """
+ res = []
+ fix_next_arg = False
+ for arg in args:
+ if fix_next_arg and not paths.is_absolute(arg):
+ res.append("${{pwd}}/{}".format(arg))
+ else:
+ res.append(arg)
+
+ fix_next_arg = arg == "-isystem"
+
+ return res
+
+def _pwd_flags(args):
+ return _pwd_flags_isystem(_pwd_flags_sysroot(args))
+
def _feature_enabled(ctx, feature_name, default = False):
"""Check if a feature is enabled.