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

[PROF-6288] Enable -Werror to turn compiler warnings into errors in CI #2358

Merged
merged 1 commit into from
Nov 10, 2022

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Nov 9, 2022

What does this PR do?:

This PR enables the -Werror compiler flag, which turns any compiler warnings into errors, when compiling profiler C code in CI.

I also refreshed the extconf.rb for the ddtrace_profiling_loader to match the compiler flags from ddtrace_profiling_native_extension as well.

Motivation:

Most compiler warnings are quite useful at point out potential bugs, and we want to make sure our code is warning-free on all Ruby versions we support.

Additional Notes:

We don't enable -Werror always because we can't control what compiler our customers use. E.g. they may use a new compiler which introduces a new warning which we haven't seen and it doesn't make sense to "break" profiling for them just because of that.

This PR is on top of ivoanjo/prof-5942-ractor-support just out of convenience and does not really depend on anything on that PR.

How to test the change?:

Check that CI is still green.

**What does this PR do?**:

This PR enables the `-Werror` compiler flag, which turns any
compiler warnings into errors, when compiling profiler C code in CI.

I also refreshed the `extconf.rb` for the
`ddtrace_profiling_loader` to match the compiler flags from
`ddtrace_profiling_native_extension` as well.

**Motivation**:

Most compiler warnings are quite useful at point out potential bugs,
and we want to make sure our code is warning-free on all Ruby
versions we support.

**Additional Notes**:

We don't enable `-Werror` always because we can't control what
compiler our customers use. E.g. they may use a new compiler which
introduces a new warning which we haven't seen and it doesn't
make sense to "break" profiling for them just because of that.

**How to test the change?**:

Check that CI is still green.
@ivoanjo ivoanjo requested a review from a team November 9, 2022 10:21
@github-actions github-actions bot added the profiling Involves Datadog profiling label Nov 9, 2022
Comment on lines +31 to 38
# Older gcc releases may not default to C99 and we need to ask for this. This is also used:
# * by upstream Ruby -- search for gnu99 in the codebase
# * by msgpack, another ddtrace dependency
# (https://github.com/msgpack/msgpack-ruby/blob/18ce08f6d612fe973843c366ac9a0b74c4e50599/ext/msgpack/extconf.rb#L8)
add_compiler_flag '-std=gnu99'

# Gets really noisy when we include the MJIT header, let's omit it
add_compiler_flag '-Wno-unused-function'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag, as well as others below were already in ext/ddtrace_profiling_native_extension/extconf.rb but I had forgot to enable them for ext/ddtrace_profiling_loader/extconf.rb so I took the opportunity to copy them over as well.

Copy link
Contributor

@lloeki lloeki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't enable -Werror always because we can't control what compiler our customers use.

That was my fear upon jumping on this PR, but you addressed it immediately.

LGTM!

Base automatically changed from ivoanjo/prof-5942-ractor-support to master November 10, 2022 14:16
@ivoanjo ivoanjo merged commit 4a58009 into master Nov 10, 2022
@ivoanjo ivoanjo deleted the ivoanjo/prof-6288-ci-warnings-into-errors branch November 10, 2022 14:18
@github-actions github-actions bot added this to the 1.6.0 milestone Nov 10, 2022
ivoanjo added a commit that referenced this pull request Nov 17, 2022
**What does this PR do?**:

In #2358 we changed how the profiling native extension is built in CI
by adding the `-Werror` compiler option to turn warnings into errors.

We did this automatically by checking if the `CI` environment variable
was set to `true`.

Unfortunately, this broke at least one user, see
<DataDog/datadog-api-client-ruby#1137>.
The warning that was triggered in that case was actually not
relevant, see my investigation in
<#2377>.

The `CI=true` was never meant to trigger outside of our CI, but
clearly it's too generic of a name for us to rely on that.

To fix this, I've gone ahead and changed the configuration so that
`-Werror` only gets added when `DD_PROFILING_CI=true`. I also
changed our docker and CircleCI configurations to set this by
default.

**Motivation**:

This issue affected one Datadog internal customer --
<DataDog/datadog-api-client-ruby#1137>.

This should never happen -- we don't want any issues when
compiling the profiling bits to affect ddtrace installation.

**Additional Notes**:

(Nothing)

**How to test the change?**:

Validate that `-Werror` only gets added when
`DD_PROFILING_CI=true`.

To trigger a warning for testing, try removing
`DDTRACE_UNUSED` from function argument declarations, and you
should see that the compiler starts failing due to that.

---

Fixes #2377
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
profiling Involves Datadog profiling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants