-
Notifications
You must be signed in to change notification settings - Fork 29
Move Au code into code/au subfolder
#266
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
Conversation
This replaces the `project_symlinks` approach we had been using for CMake: it turns out that symlinks are fraught and error prone on Windows. To make this work, we had to satisfy a number of challenging constraints: 1. The include path had to be `"au/..."` (e.g., `"au/io.hh"`) for all files, on both bazel and CMake. 2. The `au` folder that contained the actual code needed to live inside of a true subdirectory --- not the git repository root folder (as it has been since time immemorial), and not a symlink (as we had been using to get CMake support). 3. The git repository root folder needed to also be the root of the bazel folder, because we use that for all of our bazel-backed tools, and because we want users to be able to run all `bazel` commands from the repo root. I previously tried a variety of approaches here, including: - Having CMake create the symlink, instead of having it checked in (bad idea: you can't create symlinks in Windows without developer mode, and even after I enabled dev mode it didn't work). - Making a `code` subfolder in the git repository root that had _its own separate `WORKSPACE` file_, and was included as a local bazel repo (terrible idea: we'd need two copies of all auxiliary bazel files, and making the single-file script work was nightmarishly complex --- I never even fully got there). In the end, the approach that works is to use the `includes` attribute of the `cc_library` rule. This is simple and direct: it's designed to solve this exact problem. The only real downside is that we need to prepend `code/au` to a lot of files in the `BUILD.bazel` for `//au`, and also in a couple of places in the single file script. Helps #215.
| @@ -0,0 +1,505 @@ | |||
| # Copyright 2024 Aurora Operations, Inc. | |||
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.
To review this file, "au/code/au/CMakeLists.txt", you can verify that it is identical to the contents of "au/CMakeLists.txt" on the parent branch. GitHub UI does not make it obvious, but we simply moved this file to this new location. (It doesn't show this because we had to retain a simpler version of the file at the old location.)
| name = "au", | ||
| hdrs = ["au.hh"], | ||
| hdrs = ["code/au/au.hh"], | ||
| includes = ["code"], |
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.
I thought about creating a bazel macro to handle this repetition, but I ended up deciding that direct representation might be easier to understand and maintain.
I realized I didn't need them before I added to them, but I forgot to remove them earlier.
Will revert before landing.
This reverts commit fdbaa0f.
geoffviola
left a comment
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.
The changes and rationale seem reasonable. I didn't get a chance to test it on Windows.
Code is a fine name. I've also seen src.
|
I think |
Reorganize the codebase such as the code is located at `//au/*` rather
than `//au/code/au/*`.
The primary motivation here is to conform more closely with the
canonical header path style that Bazel likes by avoiding
[`cc_library.includes`][includes]. Previously, we had Bazel targets
that looked like
```
cc_library(
hdrs = ["code/au/au.hh"],
includes = ["code"],
...
)
```
It is unusual and somewhat problematic to do this. The `hdrs` suggests
that code should `#include "PACKAGE_PATH/code/au/au.hh"`, but we
actually want people to just use the more typical
`#include "PACKAGE_PATH/au.hh"`. Using `includes` to permit this
essentially sidesteps Bazel's normal include path logic, and typically
causes the headers to be added to the system header include path
(`-isystem`) rather than the normal include path (`-I`). This can have
undesirable side effects such as suppressing warnings in these headers.
One alternative would be to use `strip_include_prefix = "code/au"`. This
brings the include path management back into Bazel's domain, but results
in a bunch of ugly and unnecessary virtual includes.
We should just simplify our include paths by dropping the extra
`code/au` directory entirely.
Note that we originally added this subdir in #266 to work around some
symlink concerns in our CMake build. Since then, our CMake handling has
matured considerably, to the point where I believe this subdir is no
longer required.
[includes]: https://bazel.build/reference/be/c-cpp#cc_library.includes
---
Note that doing this actually revealed a couple additional warnings that
were previously suppressed by the -isystem. These have been addressed
in #444 and #445.
This replaces the
project_symlinksapproach we had been using forCMake: it turns out that symlinks are fraught and error prone on
Windows. After this PR, CMake support on Windows is confirmed to work!
To make this work, we had to satisfy a number of challenging
constraints:
The include path had to be
"au/..."(e.g.,"au/io.hh") for allfiles, on both bazel and CMake.
The
aufolder that contained the actual code needed to live insideof a true subdirectory --- not the git repository root folder (as it
has been since time immemorial), and not a symlink (as we had been
using to get CMake support).
The git repository root folder needed to also be the root of the
bazel folder, because we use that for all of our bazel-backed tools,
and because we want users to be able to run all
bazelcommands fromthe repo root.
I previously tried a variety of approaches here, including:
Having CMake create the symlink, instead of having it checked in (bad
idea: you can't create symlinks in Windows without developer mode).
Making a
codesubfolder in the git repository root that had its ownseparate
WORKSPACEfile, and was included as a local bazel repo(terrible idea: we'd need two copies of all auxiliary bazel files, and
making the single-file script work was nightmarishly complex --- I
never even fully got there).
In the end, the approach that works is to use the
includesattributeof the
cc_libraryrule. This is simple and direct: it's designed tosolve this exact problem. The only real downside is that we need to
prepend
code/auto a lot of files in theBUILD.bazelfor//au, andalso in a couple of places in the single file script.
Helps #215.