-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Suppress all C++ warning when compiling generated protobuf code. #5467
Suppress all C++ warning when compiling generated protobuf code. #5467
Conversation
Context: I am C++ programmer on Windows and regularly deal with GCC, Clang and MSVC. Adding only the flags needed for each compiler (the problem is specific to compiler, not OS) is feasible, but adding them in
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review. Unfortunately, this can't be merged because it would make MSVC users sad.
I don't think Bazel has the concept of "disable all warnings" yet, does it, @mhlopko ? I'd define a feature that does that then add it to the default generated CROSSTOOL file. Unfortunately, that's not a single-line change.
@@ -256,6 +256,7 @@ private CcCompilationHelper initializeCompilationHelper( | |||
} | |||
|
|||
helper.addDeps(ruleContext.getPrerequisites("deps", TARGET)); | |||
helper.setCopts(ImmutableList.of("-w")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work: this assumes that the compiled is gcc/clang and leaves MSVC users out in the cold.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review! I'll try it on Windows just to be on the safe side.
The MSVC docs state Options are specified by either a forward slash (/) or a dash (–).
(see the option
entry). This in combination with the Warning levels page leads me to believe that it should work.
But then again, this is Windows we're talking about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MSVC can accept -w
to disable all warnings just fine, but if someone append -W3
/-W4
etc. after -w
, you will get D9025` warning that cannot be silenced at all, causing a waterfall of warnings.
Well, the review latency was embarrassing.... Even if it does work with MSVC, I'd like us to move away from hard-coded command line options not towards them. What do you think, @mhlopko ? |
@lberki I agree that having hard-coded command line options is non-optimal and that it would be far better to add a feature to the
|
/cc @mhlopko for CROSSTOOL wisdom |
+1 what @lberki said, let's not hardcode any flags if we can help it. I propose to add "disable_errors" feature to requested features here. Yes that means that we have to define the feature in all the crosstools. Well, we don't have to (bazel won't complain if the feature is not defined) but users will expect the feature to be there, so let's not let them down. Osx crosstool is indeed generated by a tool that we didn't get to open source (and we will not because Crosstool in Skylark solves the problem better). Just edit one toolchain in that file and I'll take care of the generator once I import the PR. |
357d63c
to
a4d7ae1
Compare
@mhlopko I just pushed a working example for macos and added the new feature to what I hope is the default Unix toolchain. I tested it on macos (sorry don't have a Linux machine handy right now). Could you let me know where else this feature should go? Finally, I'd propose to rename the feature "disable_warnings" or changing the flag from |
ping @mhlopko |
ping @lberki |
I like it, let me import it :) Thanks! |
(Asking protobuf team for approval internally, will take some time). |
@mhlopko Awesome, thanks for the update! |
@mhlopko Do you have a rough timeline for this to go in? |
Any update? |
What is this status of this PR? |
Wow, this was a while ago... I imported this change and asked @mhlopko to review it. What's the plan for Windows? |
Is this still import-able? |
Hi all, I'm very sorry for how long this PR took. So there were discussion with the protobuf team internally and the result is that protoc should not generate warning triggering code. I commented protocolbuffers/protobuf#4628 (comment) and I expect that protobuf team will reopen that issue and drive this effort further. @RNabel, @rongjiecomputer, can you check in on protocolbuffers/protobuf#4628 (comment) to help them understand the actual problems? Thank you! And again, I apologize for this taking this long. I'll now close this PR. But please shout if you disagree with what I wrote above and we'll continue the discussion here. |
This PR is a suggested fix for #5466.
As long as a) one cannot specify
copt
s for the compilation of generated C++ code, and b) protobuf generated code is warning-generating, we should suppress at least the errors protobuf code is known to generate (from my experience at leastunused-parameter
(as seen here: protocolbuffers/protobuf#4628) andinvalid-offset
andzero-as-null-pointer-constant
).a) is fixable, but has no timeline, b) will not be fixed.
Option 1: Suppress all warnings (currently chosen)
Since protobuf code is already assumed to be correct, suppressing all warnings both reduces log message spam and solves the
-Werror
problem.Advantages: Will compile with any CROSSTOOL copts.
Disadvantages: Could suppress warnings of a broken C++ protobuf
plugin
.Option 2: Suppress specific known errors
It is theoretically possible to suppress only the known errors, but I'm not a C++ expert so don't know how compatible these flags are between OSs.
Risks: Windows, different protobuf versions could have different errors.
Option 3: Pass
-Wno-error
Warnings would still be shown but at least the compilation would succeed.
Advantages: least intrusive, builds complete.
Disadvantages: many un-actionable log messages.
I hope this is the correct format for this kind of discussion. Many thanks in advance for any comments :)