0

I wrote a custom CROSSTOOL file that calls the arm-gcc compiler for my Cortex-M target. I specify my flags, including the sysroot via -isystem.

I see that Bazel augments my invocation of gcc with a bunch of extra -I flags. This seems ok, b/c Bazel is adding paths to files generated during the build, etc.

I see that Bazel is also adding a -isystem that I didn't specify:

-isystem external/bazel_tools/tools/cpp/gcc3

I can't figure out how to get Bazel to suppress this, since by looking at the only occurrence of "gcc3" in the code, it looks like it's trying to pull in a specific STL.

Can I tell Bazel not to add this? It's harmless at best, but possibly insidious.

1

1 Answer 1

1

Let me first answer a more general question: How to force Bazel to stop patching my crosstool? This can be done by defining no_legacy_features feature in your crosstool, simply by putting this into the all relevant toolchain messages:

feature { name: "no_legacy_features" } 

With that feature Bazel will not patch your crosstool, so it will not add the -isystem flag. But it will also stop adding all other flags such as -D defines, -l libs, etc. You can see everything that bazel is adding to your crosstool in CppActionConfigs. Another problem is that I introduce new features and new build variables every day now, so if you want to upgrade bazel in the future, you'll definitely need to update the crosstool. If you don't use action_configs and don't define no_legacy_features, your crosstool will keep working. Eventually my work on the crosstool will be finished and crosstool will be stable. It's not the case right now.

Now second question is why bazel adds that -isystem flag there, and I don't know. Therefore I filed an issue.

Sign up to request clarification or add additional context in comments.

5 Comments

Brilliant, thanks! Will "no_legacy_features" inhibit the dependency analysis flags like -MMD etc or is it just about feature flags? To be clear, I'm /only/ messing around in CROSSTOOL for firmware; I want full explicit control over every flag, and I'm statically linking single images together. No host-side complexity, no dll / so support, etc. For the host-side work I'm using vanilla Bazel and all of the defaults, no custom CROSSTOOL there.
no_legacy_features will prevent bazel from adding anything to your crosstool. For examples one of my last changes changed how copts are added, and it your crosstool doesn't expand 'copts' build variable, you will not get copts at all. So unless you don't add it, '-MMD' will not be added automatically. You can check CppActionConfigs.java to see most of what bazel patches into your crosstool normally.
Ah, that's not quite as helpful then. I want to take advantage of Bazel's dependency analysis for minimal rebuilds; I don't want Bazel (via CROSSTOOL) to mess with my explicitly-configured include paths.
You won't loose anything if you copy all the features that CppActionConfigs patch in (you're referring to the dependency_file feature, but you'd need more than just this one, especially for linking).
Got an idea, can you use nocopts? docs.bazel.build/versions/master/be/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.