storypku / bazel_iwyu

IWYU Support for Bazel
Apache License 2.0
42 stars 12 forks source link

Cross-compilation support: don't report IWYU issues on std headers #9

Open storypku opened 1 year ago

storypku commented 1 year ago

When running IWYU for X-Compilation on J5, it failed with error msg:

bazel build --config=iwyu --config=j5 experimental/users/jiaming/toolchain_exp:atomic_test
INFO: Invocation ID: 57c8ec4d-a7e5-4159-8148-a380fbf15538
INFO: Analyzed target //experimental/users/jiaming/toolchain_exp:atomic_test (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /qcraft/experimental/users/jiaming/toolchain_exp/BUILD:15:10: Run include-what-you-use on experimental/users/jiaming/toolchain_exp/atomic_test.cc failed: (Exit 1): run_iwyu failed: error executing command (from target //experimental/users/jiaming/toolchain_exp:atomic_test) bazel-out/k8-fastbuild-j5/bin/external/com_github_storypku_bazel_iwyu/bazel/iwyu/run_iwyu bazel-out/k8-fastbuild-j5/bin/experimental/users/jiaming/toolchain_exp/atomic_test.atomic_test.cc.iwyu.txt ... (remaining 99 arguments skipped)
[ERROR] IWYU violation found. Fixes have been written to bazel-out/k8-fastbuild-j5/bin/experimental/users/jiaming/toolchain_exp/atomic_test.atomic_test.cc.iwyu.txt

external/aarch64_j5_sysroot/usr/include/c++/9/atomic should add these lines:
#include <stdint.h>            // for int16_t, int32_t, int64_t, int8_t, int_fast16_t, int_fast32_t, int_fast64_t, int_fast8_t
#include <cstddef>             // for ptrdiff_t, _GLIBCXX_USE_C99_STDINT_TR1, _GLIBCXX_BEGIN_NAMESPACE_VERSION, _GLIBCXX_EN...
#include <type_traits>         // for is_object
#include <utility>             // for __addressof

external/aarch64_j5_sysroot/usr/include/c++/9/atomic should remove these lines:
- #include <bits/move.h>  // lines 42-42
- namespace std { struct atomic; }  // lines 147-148
- namespace std { template <typename _Tp> struct atomic; }  // lines 57-58

The full include-list for external/aarch64_j5_sysroot/usr/include/c++/9/atomic:
#include <bits/atomic_base.h>  // for memory_order, __atomic_base, __cmpexch_failure_order, atomic_flag, atomic
#include <stdint.h>            // for int16_t, int32_t, int64_t, int8_t, int_fast16_t, int_fast32_t, int_fast64_t, int_fast8_t
#include <cstddef>             // for ptrdiff_t, _GLIBCXX_USE_C99_STDINT_TR1, _GLIBCXX_BEGIN_NAMESPACE_VERSION, _GLIBCXX_EN...
#include <type_traits>         // for is_object
#include <utility>             // for __addressof
---

(experimental/users/jiaming/toolchain_exp/atomic_test.cc has correct #includes/fwd-decls)
Aspect @com_github_storypku_bazel_iwyu//bazel/iwyu:iwyu.bzl%iwyu_aspect of //experimental/users/jiaming/toolchain_exp:atomic_test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.508s, Critical Path: 0.36s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully

Where atomic_test.cc is something like:

#include <atomic>
#include <iostream>

int main() {
  struct Test {
    int val;
  };
  std::atomic<Test> s;
  std::cout << std::boolalpha << s.is_lock_free() << std::endl;
  std::atomic_int my_num;
  ++my_num;
  std::cout << "my_num: " << my_num << std::endl;
  return 0;
}

We need to address this issue.