This is an archive of the discontinued LLVM Phabricator instance.

Do not build with Werror by default (Bazel build)
ClosedPublic

Authored by mehdi_amini on Apr 10 2022, 9:57 PM.

Details

Summary

This seems like an anti-pattern to have -Werror on by default:
it is hostile to user as we can't ensure that all of the supported
platforms are warning-free, and any newer compiler could break the build
for a user who does not have a clear actionable way around it.

Diff Detail

Event Timeline

mehdi_amini created this revision.Apr 10 2022, 9:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2022, 9:57 PM
mehdi_amini requested review of this revision.Apr 10 2022, 9:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2022, 9:57 PM
mehdi_amini edited the summary of this revision. (Show Details)

Descriptin

kuhar accepted this revision.Apr 11 2022, 7:04 AM
kuhar added a subscriber: kuhar.

+1, I had to patch this locally in my project for exactly the reasons you mentioned

This revision is now accepted and ready to land.Apr 11 2022, 7:04 AM

+1, I had to patch this locally in my project for exactly the reasons you mentioned

I don't understand what you mean about having to patch it locally in a different project. bazelrc files are only applicable to the project itself, not anything that uses it as a dependency.

utils/bazel/.bazelrc
51

[Here for threading]

I'm pretty strongly against warnings in default build configurations. In my experience, it inevitably leads to an ever-growing pile of warning spam. If we turn it off here, I'm going to turn it on explicitly on the CI. The issue with that is that then users have things that only fail on the CI (Bazel will hide warnings from cached actions, irritatingly). I take your point about users on different platforms and compiler versions. Notably they can override bazelrc options themselves and pass --copt=-Wno-error --host_copt=-Wno-error. Have you actually run into issues or is this theoretical right now? The better workflow IMO would be for someone to switch to building locally with these options and send a patch to fix things for the new compiler/platform. Opting in to ignoring warnings seems better to me, but it depends on the frequency of this issue.

91

Why would things be different for gcc than for clang?

kuhar added a comment.May 10 2022, 7:10 PM

+1, I had to patch this locally in my project for exactly the reasons you mentioned

I don't understand what you mean about having to patch it locally in a different project. bazelrc files are only applicable to the project itself, not anything that uses it as a dependency.

We build and test llvm before importing because we have a small number of local patches . I don't remember what our issue was exactly, but I think it was something caused by not fully hermetic builds and picking up system headers that caused deprecation warnings in code that used mallinfo or something similar.

mehdi_amini added inline comments.May 11 2022, 3:15 PM
utils/bazel/.bazelrc
51

I'm pretty strongly against warnings in default build configurations.

You mean you want to remove -Wall? Disable warnings entirely by default?
I don't have a definitive opinion on this actually, why would you want this?
(it seems secondary to Werror anyway)

If we turn it off here, I'm going to turn it on explicitly on the CI. The issue with that is that then users have things that only fail on the CI

I am not sure if you're still talking about warnings in general or just the Werror option?
If it Werror then again: I don't have a definitive opinion but as long as this is a CI that isn't community maintained, you do whatever you want :)

Notably they can override bazelrc options themselves and pass --copt=-Wno-error --host_copt=-Wno-error.

That does not seem like a solution to me in any way to "what we ship to users": having the build failed in a weird way (pedantically) and have the user figure out how to manage this.

Have you actually run into issues or is this theoretical right now?

This was because of a bug report from @kuhar ; in any case this isn't theoretical: this is a quite well known aspect of shipping C++. (for example: https://embeddedartistry.com/blog/2017/05/22/werror-is-not-your-friend/ )

The better workflow IMO would be for someone to switch to building locally with these options and send a patch to fix things for the new compiler/platform.

No it isn't a better workflow: first users are not developers, being able to clone and build by default seems like the basic to me for our users. But also there are code pattern that will trigger a warning on some version of GCC and "fixing" the code will necessarily trigger a warning on some version of clang.

More fundamentally, in the context of LLVM it's not clear to me why the Bazel build would default to this when the CMake build does not?

91

I removed -Werror equally for gcc and clang, can you clarify what you mean?

GMNGeoffrey added inline comments.May 12 2022, 12:01 PM
utils/bazel/.bazelrc
51

I mean that in my experience not enforcing 0-warnings means that you end up with warnings. That blog post (plus the comments) have convinced me though. I think my experience comes from a place where toolchains were more tightly controlled. It seems to me that the right thing to do is not have Werror in the default build configuration, but to enforce it in some other way. The simplest is to do so in the CI build where you do have control over the toolchain, so I'll do that for now. Need to separately enable it for pre-merge tests so give me a bit to do so

91

Uh... somehow I read the wrong side of the diff

https://github.com/google/llvm-premerge-checks/pull/400 turns this on for the pre-merge checks and I've updated the continuous build. I want to make sure the pre-merge checks are doing what we expect. Mehdi, perhaps you could push an update to this change? That should re-run the pre-merge checks and we can confirm they're using -Werror. Alternatively, any patch that touches the bazel files or is by someone in the Bazel project would do it. I just didn't want to send draft patches because people have griped about email traffic in the past.

I rebased, can you check the premerge to see if it does what you expect? (I'm not sure what you want to look at)

I just remembered about this. I think you can land it. -Werror is turned on explicitly on the CI. @aeubanks to confirm

This revision was automatically updated to reflect the committed changes.

I just remembered about this. I think you can land it. -Werror is turned on explicitly on the CI. @aeubanks to confirm

it should be added at the bottom of this file under build:ci