Skip to content

Enable -Werror in CMake (CI only)#9037

Merged
alexreinking merged 9 commits intomainfrom
alexreinking/cmake-werror
Mar 16, 2026
Merged

Enable -Werror in CMake (CI only)#9037
alexreinking merged 9 commits intomainfrom
alexreinking/cmake-werror

Conversation

@alexreinking
Copy link
Copy Markdown
Member

@alexreinking alexreinking commented Mar 15, 2026

Let's see what breaks!

@mcourteaux
Copy link
Copy Markdown
Contributor

Actually... why CI only? I wanna know it will fail before I push.

@alexreinking
Copy link
Copy Markdown
Member Author

Actually... why CI only? I wanna know it will fail before I push.

Well, to do that you'd have to start by installing one of the exact same versions of GCC/Clang/MSVC as the buildbots have and then test on all of them 😉

The key issue is that -Werror doesn't mean "the same warnings as CI." It means "whatever your compiler thinks is a warning, right now, on your machine." You could get a passing local build and still get a failing pipeline. Or worse, you could waste time fixing a warning that CI ignores.

The only way to know it'll pass CI is to run CI.

If you want to build more like CI, we have ci-* presets that should work locally, assuming you have VCPKG_INSTALLATION_ROOT pointing to a suitable location.

On Windows, raw string literals and binary2cpp-generated arrays can
contain \r\n line endings (from git checkout with core.autocrlf).
Normalize to \n so that generated source files have consistent,
platform-independent line endings.
@alexreinking alexreinking requested a review from abadams March 16, 2026 04:11
@alexreinking
Copy link
Copy Markdown
Member Author

Error is an intermittent timeout failure in the onnx app on win-worker-3

@alexreinking alexreinking requested a review from mcourteaux March 16, 2026 04:11
Comment thread src/CodeGen_C.cpp
// On Windows, raw string literals and binary2cpp-generated arrays can
// contain \r\n line endings (from git checkout with core.autocrlf).
// Normalize to \n so that generated source files have consistent,
// platform-independent line endings.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wauw this sucks. We couldn't just normalize those source files?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think that's brittle. People's editors might change things locally and ephemerally before git renormalizes them. When we upgrade to C++20, this can be consteval

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No chance for a pre-commit check?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It wouldn't help during local development. The scenario I'm envisioning is that someone edits CodeGen_C.cpp on Windows when it's checked out by git as LF. Upon save, their editor changes it silently to CRLF. I would hope most editors are smart about this, but who knows? Maybe someone is doing something weird like running VSCode in a WSL container yet compiling on Windows. Now there's a mix of line endings in the generated sources that will be very hard to track down.

I thought of a few alternative approaches but this seemed like the lowest-friction option:

  1. We could switch the output to binary mode. But then everywhere we write a '\n' character today would need to be replaced with Halide::Endl or something that expands to \n on Unix and \r\n on Windows.
  2. We could add a -text flag to binary2cpp that normalizes newlines in the template files. Doesn't fix the problem with raw string literals, though
  3. I did think of changing the line endings of the relevant files with .gitattributes (which I think is what you were suggesting?)---but that's brittle for the reasons I just described. I don't like that it's outside the code. For example, what happens if someone downloads a ZIP of our sources from GitHub? Maybe it works, but I don't want to have to think about it or rely on it.

It is incredibly vexing that the standard did not define the bytes of a newline in a raw string literal.

@alexreinking alexreinking merged commit 11f6bb7 into main Mar 16, 2026
22 of 23 checks passed
@alexreinking alexreinking deleted the alexreinking/cmake-werror branch March 16, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants