storypku / bazel_iwyu

IWYU Support for Bazel
Apache License 2.0
38 stars 11 forks source link

can't find headers from hermetic toolchain #5

Open luxe opened 1 year ago

luxe commented 1 year ago

I'm using a hermetic toolchain via bazel-toolchain and providing a custom sysroot.
Tragically, the iwyu aspect does not seem to find my system headers. Here is the error message:

./user_build -s --config=iwyu //code/programs/examples/abseil/...                                                                                                                                                                             1
2022/12/22 13:34:28 Using unreleased version at commit 01314ce0261e82e0be24c274a7726064f09a0962
INFO: Analyzed target //code/programs/examples/abseil/str_join:main (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
SUBCOMMAND: # //code/programs/examples/abseil/str_join:main [action 'Run include-what-you-use on code/programs/examples/abseil/str_join/main.cpp', configuration: cf38cdf241f5ec8932ceaf012c0fc70bb521ab2445ff295369cccc1901113f13, execution platform: @local_config_platform//:host]
(cd /home/luxe/.cache/bazel/_bazel_luxe/9b1d289b10540c9752c68b55618a2156/execroot/__main__ && \
  exec env - \
  bazel-out/k8-fastbuild/bin/external/com_github_storypku_bazel_iwyu/bazel/iwyu/run_iwyu bazel-out/k8-fastbuild/bin/code/programs/examples/abseil/str_join/main.main.cpp.iwyu.txt -Xiwyu --cxx17ns -Xiwyu '--error=1' -Xiwyu '--max_line_length=127' -Xiwyu --no_fwd_decls -Xiwyu --transitive_includes_only -Xiwyu '--mapping_file=external/com_github_storypku_bazel_iwyu/mappings/gtest.imp' -U_FORTIFY_SOURCE -fstack-protector -fno-omit-frame-pointer -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign '-std=c++17' '-stdlib=libc++' -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' '-fdebug-prefix-map=external/llvm_toolchain/=external/llvm_toolchain/' -x c++ '-DBAZEL_CURRENT_REPOSITORY=""' -iquote . -iquote bazel-out/k8-fastbuild/bin -iquote external/abseil -iquote bazel-out/k8-fastbuild/bin/external/abseil -iquote external/bazel_tools -iquote bazel-out/k8-fastbuild/bin/external/bazel_tools code/programs/examples/abseil/str_join/main.cpp)
# Configuration: cf38cdf241f5ec8932ceaf012c0fc70bb521ab2445ff295369cccc1901113f13
# Execution platform: @local_config_platform//:host
ERROR: /home/luxe/Desktop/unilang/source/code/programs/examples/abseil/str_join/BUILD:7:9: Run include-what-you-use on code/programs/examples/abseil/str_join/main.cpp failed: (Exit 1): run_iwyu failed: error executing command (from target //code/programs/examples/abseil/str_join:main) bazel-out/k8-fastbuild/bin/external/com_github_storypku_bazel_iwyu/bazel/iwyu/run_iwyu bazel-out/k8-fastbuild/bin/code/programs/examples/abseil/str_join/main.main.cpp.iwyu.txt -Xiwyu --cxx17ns -Xiwyu ... (remaining 40 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
[ERROR] IWYU violation found. Fixes have been written to bazel-out/k8-fastbuild/bin/code/programs/examples/abseil/str_join/main.main.cpp.iwyu.txt
code/programs/examples/abseil/str_join/main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
Aspect @com_github_storypku_bazel_iwyu//bazel/iwyu:iwyu.bzl%iwyu_aspect of //code/programs/examples/abseil/str_join:main failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.416s, Critical Path: 0.07s
INFO: 3 processes: 3 internal.
ERROR: Build did NOT complete successfully

I was looking at the aspect, and I had assumed the CompilationContext would have this path available (perhaps in system_includes), but I guess that's not the case.

In fact, I don't see -isystem in my subcommand at all. Hm, I wonder how to derive the appropriate sysroot paths for this aspect.

storypku commented 1 year ago

Maybe it's due to the removal of the --sysroot flag in https://github.com/storypku/bazel_iwyu/blob/039d78330125552d3ae3f14efbe97c6bedeb25b3/bazel/iwyu/iwyu.bzl#L132 ?

mrkkrp commented 1 month ago

We are facing the same issue with https://github.com/f0rmiga/gcc-toolchain. Is there a recommended solution?

mrkkrp commented 1 month ago

We seem to have made some progress by using the latest commit from current master. Maybe it's worth publishing a new version of bazel_iwyu based on that commit?