question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SDKROOT, DEVELOPER_DIR, INCLUDE, LIB missing from Environment Variables in Aquery and Extra Actions

See original GitHub issue

Description of the problem:

When listening to CppCompile and ObjcCompile (mnemonic) actions with an action_listener on macOS and Windows, the key environment variables DEVELOPER_DIR and SDKROOT (Apple Platforms) and INCLUDE and LIB and other essentials (Windows) are missing from the environment variables in aquery and extra actions output, despite being needed to run the action successfully.

For Apple platforms, the bazel-supplied, wrapped Xcode compiler is dependent on these environment variables, and crashes if they aren’t provided. For Windows, MSVC is dependent on these variables for system headers and libraries. Those environment variables provide key information about the compilation command.

On Apple platforms, some other, less-standard variables are supplied: XCODE_VERSION_OVERRIDE, APPLE_SDK_VERSION_OVERRIDE, and APPLE_SDK_PLATFORM. On Windows…not so much.

What underlying problem are you trying to solve?

The lack of these variables significantly complicates building C++ developer tooling around Bazel.

In my case, I’m integrating Bazel with clangd autocomplete in a wide variety of editors, to make development using Bazel more fun. We’re linked to from the bazel docs 😃

But I’d imagine this would also be useful for Kythe–the complication databases it generates would be incomplete without this, and they use action_listeners/extra_action, while we use aquery. As above, the problem exists in both.

The workaround I’m currently using on macOS using is to go direct to the system, re-inferring SDKROOT and DEVELOPER_DIR from the system Xcode commands. On Windows, I inspect the top level cc_toolchain. While these generally work, they’ll miss any configuration the user does in the build graph.

More generally, it seems odd that those key variables are missing for the core cc rules. It feels like they’d be the primary purpose of being able to query the environment of C++ actions. It feels like there might be something even more general broken here.

Bugs: what’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Just run bazel aquery "mnemonic('(Objc|Cpp)Compile',//...)" on a cc_library on macOS or Windows and look at the (lack of) those environment variables.

Reproing the extra action issue is more involved, and probably is just another manifestation of the same underlying problem. But I think the fastest way to do that would be to grab Kythe’s implementation of an extractor (https://github.com/kythe/kythe/blob/master/kythe/cxx/extractor/README.md) and examine the extra_actions_base_proto.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
gregestrencommented, Apr 6, 2022

I don’t have expertise on this part of the code base (aquery, extra actions, environment variable consumption). I’m going to defer to @oquenchil .

0reactions
cpsauercommented, Nov 16, 2022

I’m pretty sure it also affects Objective-C, at least, but I’m not sure whether it affects other language toolchains/Java. [It’s been a problem everywhere I’ve looked, but I haven’t needed to dive into the Bazel toolchains for other languages just yet.]

Read more comments on GitHub >

github_iconTop Results From Across the Web

DYLD_LIBRARY_PATH and make | Apple Developer Forums
I have several build steps (Qt/clang/make/etc) that rely on DYLD_LIBRARY_PATH being set so that the proper libraries can be found. If I do...
Read more >
How to set ANDROID_SDK_ROOT in mac? - Stack Overflow
vim ~/.bash_profile. Then add the following environment variables: export ANDROID_HOME=~/Library/Android/sdk export ...
Read more >
Environment Variables - Forms - Oracle Help Center
This chapter describes Forms environment variables associated with ... Specifies whether or not the full file system path should be included in the...
Read more >
Environment variables - Android Developers
Learn how to set environment variables for Android Studio and the command-line tools that specify things like where the SDK is installed and ......
Read more >
Android SDK and Emulator
The process consists of these tasks: Download and install Android Studio, ... To set the Android SDK home environment variable, do the following:....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found