Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test iostream include #13

Merged
merged 14 commits into from
Nov 16, 2022
Merged

Test iostream include #13

merged 14 commits into from
Nov 16, 2022

Conversation

renefritze
Copy link
Collaborator

This is a merge of @tristan0x's #12 and #11 so we can run tests on the result.

The test from the sdist tarball build went through. The mac one didn't

@tristan0x
Copy link
Contributor

I have already encountered the issue:

error: 'iostream' file not found [clang-diagnostic-error]
  #include <iostream>
           ^~~~~~~~~~`

It means clang-tidy is not able to find the libstdc++ on the host. Installing a C++ compiler may fix the issue.

@renefritze
Copy link
Collaborator Author

Right, but isn't that what should be solved by #11, which is included in this PR?

@tristan0x
Copy link
Contributor

Right, but isn't that what should be solved by #11, which is included in this PR?

#11 provides builtin includes, which is different than the stdlibc++. The link suggests using -v to get the search paths. I will try to reproduce the issue on Mac OS on Monday.

@tristan0x
Copy link
Contributor

tristan0x commented Jul 18, 2022

Right, but isn't that what should be solved by #11, which is included in this PR?

#11 provides builtin includes, which is different than the stdlibc++. The link suggests using -v to get the search paths. I will try to reproduce the issue on Mac OS on Monday.

I confirm it is the absence of XCode on the MacOS builder (or the tunability to find it) that makes clang-tidy fails.

Working version on Apple M1 with XCode installed:

$ clang-tidy --extra-arg=-v include-iostream.cpp

Error while trying to load a compilation database:
Could not auto-detect compilation database for file "include-iostream.cpp"
No compilation database found in /Users/me/src/github.com/me/clang-tidy-wheel or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
clang version 14.0.6
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Users/me/src/github.com/me/clang-tidy-wheel/.env/lib/python3.9/site-packages/clang_tidy/data/bin
ignoring nonexistent directory "/Users/me/src/github.com/me/clang-tidy-wheel/.env/lib/python3.9/site-packages/clang_tidy/data/bin/../include/c++/v1"
clang Invocation:
 "/Users/me/src/github.com/me/clang-tidy-wheel/.env/lib/python3.9/site-packages/clang_tidy/data/bin/clang-tool" "-cc1" "-triple" "arm64-apple-macosx12.0.0" "-Wundef-prefix=TARGET_OS_" "-Werror=undef-prefix" "-Wdeprecated-objc-isa-usage" "-Werror=deprecated-objc-isa-usage" "-fsyntax-only" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "include-iostream.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=non-leaf" "-ffp-contract=on" "-fno-rounding-math" "-funwind-tables=2" "-target-sdk-version=12.3" "-fcompatibility-qualified-id-block-type-checking" "-fvisibility-inlines-hidden-static-local-var" "-target-cpu" "apple-m1" "-target-feature" "+v8.5a" "-target-feature" "+fp-armv8" "-target-feature" "+neon" "-target-feature" "+crc" "-target-feature" "+crypto" "-target-feature" "+dotprod" "-target-feature" "+fp16fml" "-target-feature" "+ras" "-target-feature" "+lse" "-target-feature" "+rdm" "-target-feature" "+rcpc" "-target-feature" "+zcm" "-target-feature" "+zcz" "-target-feature" "+fullfp16" "-target-feature" "+sha2" "-target-feature" "+aes" "-target-abi" "darwinpcs" "-fallow-half-arguments-and-returns" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=lldb" "-target-linker-version" "764" "-v" "-fcoverage-compilation-dir=/Users/me/src/github.com/me/clang-tidy-wheel" "-resource-dir" "/Users/me/src/github.com/me/clang-tidy-wheel/.env/lib/python3.9/site-packages/clang_tidy/data/lib/clang/14.0.6" "-isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk" "-stdlib=libc++" "-internal-isystem" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/c++/v1" "-internal-isystem" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/local/include" "-internal-isystem" "/Users/me/src/github.com/me/clang-tidy-wheel/.env/lib/python3.9/site-packages/clang_tidy/data/lib/clang/14.0.6/include" "-internal-externc-isystem" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include" "-fdeprecated-macro" "-fdebug-compilation-dir=/Users/me/src/github.com/me/clang-tidy-wheel" "-ferror-limit" "19" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-fmax-type-align=16" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c++" "/Users/me/src/github.com/me/clang-tidy-wheel/include-iostream.cpp"

clang -cc1 version 14.0.6 based upon LLVM 14.0.6 default target arm64-apple-darwin21.4.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/c++/v1
 /Users/me/src/github.com/me/clang-tidy-wheel/.env/lib/python3.9/site-packages/clang_tidy/data/lib/clang/14.0.6/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks (framework directory)
End of search list.

Issue without XCode:

$ unset SDKROOT
$ clang-tidy --extra-arg=-v include-iostream.cpp


Error while trying to load a compilation database:
Could not auto-detect compilation database for file "include-iostream.cpp"
No compilation database found in /Users/me/src/github.com/me/clang-tidy-wheel or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
clang version 14.0.6
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Users/me/src/github.com/me/clang-tidy-wheel/.env/lib/python3.9/site-packages/clang_tidy/data/bin
ignoring nonexistent directory "/Users/me/src/github.com/me/clang-tidy-wheel/.env/lib/python3.9/site-packages/clang_tidy/data/bin/../include/c++/v1"
ignoring nonexistent directory "/usr/include/c++/v1"
clang Invocation:
 "/Users/me/src/github.com/me/clang-tidy-wheel/.env/lib/python3.9/site-packages/clang_tidy/data/bin/clang-tool" "-cc1" "-triple" "arm64-apple-macosx12.0.0" "-Wundef-prefix=TARGET_OS_" "-Werror=undef-prefix" "-Wdeprecated-objc-isa-usage" "-Werror=deprecated-objc-isa-usage" "-fsyntax-only" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "include-iostream.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=non-leaf" "-ffp-contract=on" "-fno-rounding-math" "-funwind-tables=2" "-fcompatibility-qualified-id-block-type-checking" "-fvisibility-inlines-hidden-static-local-var" "-target-cpu" "apple-m1" "-target-feature" "+v8.5a" "-target-feature" "+fp-armv8" "-target-feature" "+neon" "-target-feature" "+crc" "-target-feature" "+crypto" "-target-feature" "+dotprod" "-target-feature" "+fp16fml" "-target-feature" "+ras" "-target-feature" "+lse" "-target-feature" "+rdm" "-target-feature" "+rcpc" "-target-feature" "+zcm" "-target-feature" "+zcz" "-target-feature" "+fullfp16" "-target-feature" "+sha2" "-target-feature" "+aes" "-target-abi" "darwinpcs" "-fallow-half-arguments-and-returns" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=lldb" "-target-linker-version" "764" "-v" "-fcoverage-compilation-dir=/Users/me/src/github.com/me/clang-tidy-wheel" "-resource-dir" "/Users/me/src/github.com/me/clang-tidy-wheel/.env/lib/python3.9/site-packages/clang_tidy/data/lib/clang/14.0.6" "-stdlib=libc++" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/Users/me/src/github.com/me/clang-tidy-wheel/.env/lib/python3.9/site-packages/clang_tidy/data/lib/clang/14.0.6/include" "-internal-externc-isystem" "/usr/include" "-fdeprecated-macro" "-fdebug-compilation-dir=/Users/me/src/github.com/me/clang-tidy-wheel" "-ferror-limit" "19" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-fmax-type-align=16" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c++" "/Users/me/src/github.com/me/clang-tidy-wheel/include-iostream.cpp"

clang -cc1 version 14.0.6 based upon LLVM 14.0.6 default target arm64-apple-darwin21.4.0
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /Users/me/src/github.com/me/clang-tidy-wheel/.env/lib/python3.9/site-packages/clang_tidy/data/lib/clang/14.0.6/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
1 error generated.
Error while processing /Users/me/src/github.com/me/clang-tidy-wheel/include-iostream.cpp.
/Users/me/src/github.com/me/clang-tidy-wheel/include-iostream.cpp:1:10: error: 'iostream' file not found [clang-diagnostic-error]
#include <iostream>
         ^~~~~~~~~~
Found compiler error(s).

I tried to include the libcxx shipped with llvm in the clang_tidy package

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d0fa8ac..a6b4e78 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,3 +47,9 @@ install(
     ${CMAKE_BINARY_DIR}/llvm/lib/clang/${CLANG_TIDY_VERSION}/include
   DESTINATION clang_tidy/data/lib/clang/${CLANG_TIDY_VERSION}
 )
+
+install(
+  DIRECTORY
+    ${CMAKE_BINARY_DIR}/llvm-project/libcxx/include/
+  DESTINATION clang_tidy/data/include/c++/v1
+)

but then I have the following issue with clang-tidy:

/Users/tcarel/src/github.com/tristan0x/clang-tidy-wheel/.env/lib/python3.9/site-packages/clang_tidy/data/bin/../include/c++/v1/__config:13:10: error: '__config_site' file not found [clang-diagnostic-error]
#include <__config_site>
         ^~~~~~~~~~~~~~~

__config_site is a file generated by CMake during the build of llvm-project. I think this workaround solution isn't going anywhere. IMO the host where clang-tidy is used should have a C++ compiler installed.

WDYT @renefritze ?

@renefritze
Copy link
Collaborator Author

My use case for the tidy wheel actually is a (linux) container with no compiler setup, so generally I'd say that no compiler should be necessary. But practically I'd be happy to just install xcode in the tests for now and maybe add a note to the readme.

@renefritze
Copy link
Collaborator Author

@renefritze
Copy link
Collaborator Author

I confirm it is the absence of XCode on the MacOS builder (or the tunability to find it) that makes clang-tidy fails.

I've had a look at the list of installed versions for the macos runners. So while there's a default, it does not seem to get picked up, right? OTOH there's also brew-installed gccs and llvms in the machine.

@tristan0x
Copy link
Contributor

Triggered build with verbose output

Thank you for merging the debug code. We can now clearly see that XCode is not found. xcode-select should maybe be called somewhere, or the PATH updated to make brew installation visible?

@renefritze
Copy link
Collaborator Author

I'm trying a github action to setup xcode here

@tristan0x
Copy link
Contributor

CI: set SDKROOT on macOS builder

pipeline running here 🤞

@tristan0x
Copy link
Contributor

CI: set SDKROOT on macOS builder

pipeline running here 🤞

The build is still failing but we can see that clang-tidy is trying to exploit SDKROOT compared to the previous pipelines:

"/Applications/Xcode_12.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/usr/local/include"
  ignoring nonexistent directory "/Applications/Xcode_12.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/Library/Frameworks"
  #include "..." search starts here:
  #include <...> search starts here:
   /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/cibw-run-fs8tudme/cp38-macosx_universal2/venv-test/lib/python3.8/site-packages/clang_tidy/data/lib/clang/14.0.6/include
   /Applications/Xcode_12.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/usr/include
   /Applications/Xcode_12.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks (framework directory)

But for some reason, the path is invalid.
On my computer, the corresponding path is: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/

Maybe it is worth trying without the step maxim-lobanov/setup-xcode@v1. I am sorry to bother you with this @renefritze , I am clearly walking in the dark here.

@renefritze
Copy link
Collaborator Author

Yeah, no worries. I'm happy to try that, since I also have no insight. Not even a MacOS user.

@renefritze
Copy link
Collaborator Author

I dropped 38c6ee3 from the branch and new pipeline is running

@renefritze
Copy link
Collaborator Author

The new pipeline failed again. If you don't have a new idea/insight into what's wrong @tristan0x, I propose we should just ignore the failure for now:

  1. make the pytest xfail if runner.os is Macos
  2. add a new issue that refers to that so we don't forget
  3. maybe emit a Warning from the python entrypoint script if it's running on Mac (which could also refer to the issue)?
  4. hope none of the other platforms fail too
  5. merge this PR
  6. release version 13 to close Typo in the clang-tidy Pypi project page #17 and Publish clang-tidy 13.0.0 #16

@tristan0x
Copy link
Contributor

I have no idea at the moment. I am good with your plan, I am not even sure (3) is necessary as it works on my 2 macOS environments but no strong opinion about that.
Thank you

@renefritze renefritze mentioned this pull request Jul 22, 2022
Tristan Carel and others added 5 commits July 22, 2022 13:16
This change fixes the issue referenced in Clang FAQ
https://clang.llvm.org/docs/FAQ.html#i-get-errors-about-some-headers-being-missing-stddef-h-stdarg-h

To reproduce the issue with 14.0.6:
```
$ docker run --rm -ti python bash
$ pip install clang-tidy==14.0.6
$ echo "include <iostream>" > foo.cpp
$ clang-tidy foo.cpp
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "foo.cpp"
No compilation database found in / or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
1 error generated.
Error while processing /foo.cpp.
/usr/include/wchar.h:35:10: error: 'stddef.h' file not found [clang-diagnostic-error]
         ^~~~~~~~~~
Found compiler error(s).
```
* ensure that clang-tidy binary file exists and is executable
* run clang-tidy on a very simple C++ file

Fixes #1
@renefritze renefritze marked this pull request as ready for review July 23, 2022 08:06
@renefritze
Copy link
Collaborator Author

The other platforms' tests worked out. Via the actions summary I learned that the macOS image we're using is being discontinued. So I'm going to try the tests on the newest macOS 12 image, without the xfailing before merging this PR.
@tristan0x are your working mac environments also macOS 12 already?

@tristan0x
Copy link
Contributor

tristan0x commented Jul 23, 2022 via email

@renefritze
Copy link
Collaborator Author

Pipeline with all-newest base images and xfailing dropped is now running

@renefritze
Copy link
Collaborator Author

That failed early since I also add the qemu build in the branch, new pipeline

@renefritze
Copy link
Collaborator Author

Good news, updating the MacOS image did indeed get rid of the environment problem.
I'm now running a full test build with all QEMU archs too.

This was referenced Jul 26, 2022
@renefritze
Copy link
Collaborator Author

renefritze commented Aug 5, 2022

I wanted to release tidy 13 for you @tristan0x since this whole setup will take longer still to properly fix and I do not have many cycles to spare atm.

However the upload job did not upload wheels and also did not fail 😞
https://github.com/ssciwr/clang-tidy-wheel/runs/7690709574?check_suite_focus=true

@renefritze
Copy link
Collaborator Author

Did the upload manually now
https://pypi.org/project/clang-tidy/13.0.1.1/

@tristan0x
Copy link
Contributor

Thank you very much @renefritze

@renefritze renefritze force-pushed the test_iostream_include branch 3 times, most recently from 1b2c09a to 82fe96a Compare September 22, 2022 07:20
@renefritze renefritze force-pushed the test_iostream_include branch 4 times, most recently from e510ae4 to 2ba8679 Compare October 28, 2022 07:13
@renefritze renefritze force-pushed the test_iostream_include branch 2 times, most recently from c6906a4 to 2a6db68 Compare November 4, 2022 10:16
@renefritze renefritze force-pushed the test_iostream_include branch 3 times, most recently from f433775 to 1523ba9 Compare November 15, 2022 18:14
@renefritze renefritze merged commit 74d344d into main Nov 16, 2022
@renefritze renefritze deleted the test_iostream_include branch November 16, 2022 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants