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

On MacOS Monterey 12.4 with XCode 13.4, clang complains of no sysroot #68

Closed
jiawen opened this issue Jul 9, 2022 · 9 comments
Closed

Comments

@jiawen
Copy link

jiawen commented Jul 9, 2022

I'm using a vanilla MacOS with XCode environment - on a freshly installed Apple Studio (M1 Ultra) and Bazel 5.2.0-homebrew. I'm using option 3 (BUILD with refresh_compile_commands).

I tried a single cc_library target and it complains that:

>>> While locating the headers you use, we encountered a compiler warning or error.
    No need to worry; your code doesn't have to compile for this tool to work.
    However, we'll still print the errors and warnings in case they're helpful for you in fixing them.
    If the errors are about missing files that Bazel should generate:
        You might want to run a build of your code with --keep_going.
        That way, everything possible is generated, browsable and indexed for autocomplete.
    But, if you have *already* built your code successfully:
        Please make sure you're supplying this tool with the same flags you use to build.
        You can either use a refresh_compile_commands rule or the special -- syntax. Please see the README.
        [Supplying flags normally won't work. That just causes this tool to be built with those flags.]
    Continuing gracefully...
clang: warning: no such sysroot directory: '/Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk' [-Wmissing-sysroot]
clang: warning: no such sysroot directory: '/Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk' [-Wmissing-sysroot]
clang: warning: no such sysroot directory: '/Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk' [-Wmissing-sysroot]

(several more instances)

>>> Finished extracting commands for <redacted>

And indeed, the path /Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk does not exist. It looks like it moved and is now at /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk. This is a symlink to its siblings reflecting the latest version on the system.

I assume this isn't a bazel-compile-commands-extractor bug. But I don't know Bazel's toolchain resolution logic well enough to figure out where that path is baked in.

Any ideas?

@cpsauer
Copy link
Contributor

cpsauer commented Jul 10, 2022

Hey, @jiawen, fellow Xoogler! Thanks for using the tool and writing in. I smiled seeing you file these two and reply to the NDK issue back to back to back.

I think there's a good chance this is our issue, assuming the cc_library builds fine under Bazel normally. Which it does, right?

[In the background, we have to infer the SDKROOT, since Bazel has a bug where they omit many environment variables from the action information--and in working around that but, I bet we have things a bit more hardcoded than we should.]

Could I ask you to check that xcrun --show-sdk-path -sdk macosx gives you the correct path? And that xcode-select --print-path returns that CommandLineTools folder? (I'm asking because my machine is set up with Xcode, for which these other paths remain correct.)

I've got to crash for now, but I'll return to this tm.

Thanks for your help and patience!
Chris

@jiawen
Copy link
Author

jiawen commented Jul 10, 2022

Hi Chris,

Nice to finally meet you! I've been impressed at the open source work you've been doing.

Yes, the cc_library target works builds fine under Bazel normally :).

$ xcrun --show-sdk-path -sdk macosx
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
$ xcode-select --print-path
/Library/Developer/CommandLineTools
$ ls -la /Library/Developer/CommandLineTools
total 0
drwxr-xr-x 5 root wheel 160 Jun 29 11:31 ./
drwxr-xr-x 4 root admin 128 Jun 29 11:31 ../
drwxr-xr-x 5 root wheel 160 Apr 29 22:20 Library/
drwxr-xr-x 7 root wheel 224 Jun 29 11:31 SDKs/
drwxr-xr-x 7 root wheel 224 Apr 29 22:22 usr/
$ ls -la /Library/Developer/CommandLineTools/SDKs
total 0
drwxr-xr-x 7 root wheel 224 Jun 29 11:31 ./
drwxr-xr-x 5 root wheel 160 Jun 29 11:31 ../
lrwxr-xr-x 1 root wheel  14 Jun 29 11:31 MacOSX.sdk -> MacOSX12.3.sdk/
drwxr-xr-x 7 root wheel 224 Mar 31 07:00 MacOSX11.3.sdk/
lrwxr-xr-x 1 root wheel  14 Jun 29 11:31 MacOSX11.sdk -> MacOSX11.3.sdk/
drwxr-xr-x 7 root wheel 224 Mar 31 06:56 MacOSX12.3.sdk/
lrwxr-xr-x 1 root wheel  14 Jun 29 11:31 MacOSX12.sdk -> MacOSX12.3.sdk/

@cpsauer
Copy link
Contributor

cpsauer commented Jul 11, 2022

:) Thanks for being so kind--and thorough.

Definitely our problem, then--and a result of my hardcoding in _get_apple_SDKROOT. Sorry about that. Thanks for reporting!

@cpsauer
Copy link
Contributor

cpsauer commented Jul 11, 2022

I just pushed a commit that should fix this. Could you give the latest a try, and tell me if it fixes things for you?
[I've closed the issue (optimistically) but I'll open it right back up if that doesn't fix things.]

Separately, you've got me curious! What's this image_io you're working on? Could I ask you to run xcrun --find clang on your machine, just for the completeness of my comments? And I'm curious where else (if anywhere besides that NDK issue) you might have run into me on GitHub!

Cheers! Hope that works. And again, sorry it didn't just work out of the box.
Chris

@jiawen
Copy link
Author

jiawen commented Jul 12, 2022

Just gave it a try - it works!

@image_io: haha, that's just my wrapper around libpng. Nothing fancy - but I plan to open source it since it's way either with Bazel than anything else on the planet.

$ xcrun --find clang
/Library/Developer/CommandLineTools/usr/bin/clang

I think I've mostly run into your various comments in the Bazel / Objective C world. I must say, bazel-compile-commands-extractor's README is excellent - very refreshing.

@cpsauer
Copy link
Contributor

cpsauer commented Jul 13, 2022

Yay! Delighted to hear it, and again, thanks for being great to work with and for bearing with me.

Sounds great! Looking forward to using it someday :)

@cpsauer
Copy link
Contributor

cpsauer commented Jul 13, 2022

Btw, I clicked through to your site. Some very neat work you're doing!
[Graphics and computer vision are close to my heart, too!]

@joneshf
Copy link

joneshf commented Sep 4, 2023

👋 Just passed by this issue while trying to diagnose something that's unrelated to this project. It was a very wholesome conversation. I have nothing to contribute, but it was nice to read.

@cpsauer
Copy link
Contributor

cpsauer commented Sep 5, 2023

:) glad to hear it made you smile--i smiled back, reading. Thanks for reaching out!

tiponada4l added a commit to tiponada4l/bazel-compile-commands-extractor that referenced this issue Aug 10, 2024
Trabochuk added a commit to Trabochuk/bazel-compile-commands-extractor that referenced this issue Aug 10, 2024
ngiloq6 added a commit to ngiloq6/bazel-compile-commands-extractor that referenced this issue Aug 17, 2024
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

No branches or pull requests

3 participants