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

Bzlmod #238

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft

Bzlmod #238

wants to merge 28 commits into from

Conversation

lalten
Copy link
Contributor

@lalten lalten commented Jan 8, 2024

Incomplete, work in progress 🚧

@lalten
Copy link
Contributor Author

lalten commented Jan 25, 2024

Current state is that things are complaining about boost. I think rather than trying to use the WORKSPACE-only rules_boost it would be best to switch over to bazelbuild/bazel-central-registry#1280 (comment) (once that's ready).

@mvukov
Copy link
Owner

mvukov commented Jan 25, 2024

Boost is used at a single place

(IMO, that package is outdated but still needed by the foxglove bridge). The receiver class is fairly small and contained last thing I remember. So, I'd suggest to patch it and use std::shared_ptr; then we can remove the boost dep. I can try to do this over the weekend or you can try to do it if you have some spare time. I'd target this change against the main branch to keep this PR as small as possible.

@lalten
Copy link
Contributor Author

lalten commented Jan 25, 2024

Here's the issues/todos as of now:

  • asio should probably depend on openssl like it does in WORKSPACE, but it doesn't in Bzlmod.
  • pybind_bazel is harder than necessary to integrate and causes issues about Python not being found in CI (works locally), might revert that and stick to the http_archive.
  • I don't understand why but Python3.10 causes issues. 3.11 works mostly, but py_loader complains about a compilation mismatch then.
  • Need to update bzlmod situation in examples. I have the feeling that users need to add a bunch of bazel_deps in their repo that are transitive dependencies of rules_ros2. That's kind of what bzlmod is supposed to avoid. Let's see how it works when we get there.

WORKSPACE Outdated Show resolved Hide resolved
Copy link
Owner

@mvukov mvukov left a comment

Choose a reason for hiding this comment

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

High level comments: let's leave version updates and reordering of deps for follow-up PRs to make the review easier.

Great job so far!

repositories/repositories.bzl Outdated Show resolved Hide resolved
repositories/repositories.bzl Outdated Show resolved Hide resolved
repositories/repositories.bzl Outdated Show resolved Hide resolved
@lalten
Copy link
Contributor Author

lalten commented Jan 28, 2024

Getting closer...
Still getting this from the WORKSPACE version of asio but not in the MODULE.bazel one.

external/asio/include/asio/ssl/detail/openssl_types.hpp:23:10: fatal error: 'openssl/conf.h' file not found
#include <openssl/conf.h>
         ^~~~~~~~~~~~~~~~
1 error generated.

The reason is that Bzlmod asio is configured as header-only: https://github.com/bazelbuild/bazel-central-registry/blob/main/modules/asio/1.28.2/patches/add_build_file.patch

But in WORKSPACE we use the checked-in asio.BUILD that has

defines = [
"ASIO_SEPARATE_COMPILATION",
],
to switch from header-only to lib compilation and (because of that) has to add
deps = ["@openssl//:ssl"],

CI is green with this change, but that may just mean that there are no tests that really need ssl :)

Not sure what's the better approach here. But IMO WORKSPACE and MODULE.bazel should both do the same thing.

We still need OpenSSL for libcurl, which is not on BCR yet.

@lalten lalten mentioned this pull request Jun 29, 2024
@mering
Copy link
Contributor

mering commented Jul 1, 2024

Things seem to work, the only drawback is that load("@rules_python//python:defs.bzl", "py_binary") must become load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary"), so there is a bunch of 3.10 hardcoded everywhere. While not pretty I think that would be acceptable

Why do you think this is necessary? AFAIK rules_python will use the default toolchain when using load("@rules_python//python:defs.bzl", "py_binary"), so load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary") should be equivalent to registering the 3.10 toolchain as default.

MODULE.bazel Outdated Show resolved Hide resolved
@lalten
Copy link
Contributor Author

lalten commented Jul 2, 2024

Things seem to work, the only drawback is that load("@rules_python//python:defs.bzl", "py_binary") must become load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary"), so there is a bunch of 3.10 hardcoded everywhere. While not pretty I think that would be acceptable

Why do you think this is necessary? AFAIK rules_python will use the default toolchain when using load("@rules_python//python:defs.bzl", "py_binary"), so load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary") should be equivalent to registering the 3.10 toolchain as default.

right, but my understanding is that if the root repo uses a default != 3.10, the rules_ros2_pip_deps are not guaranteed to be compatible

@mering
Copy link
Contributor

mering commented Jul 2, 2024

Things seem to work, the only drawback is that load("@rules_python//python:defs.bzl", "py_binary") must become load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary"), so there is a bunch of 3.10 hardcoded everywhere. While not pretty I think that would be acceptable

Why do you think this is necessary? AFAIK rules_python will use the default toolchain when using load("@rules_python//python:defs.bzl", "py_binary"), so load("@rules_ros2_pythons//3.10:defs.bzl", "py_binary") should be equivalent to registering the 3.10 toolchain as default.

right, but my understanding is that if the root repo uses a default != 3.10, the rules_ros2_pip_deps are not guaranteed to be compatible

Are you sure that they will chosen in the first place? My understanding is that it will only use pip deps with the correct version. This is why most projects specify the same pip deps for many Python versions. IIUC when it won't find pip deps in the correct version, it will throw an error.

@mering
Copy link
Contributor

mering commented Jul 2, 2024

@udaya2899
Copy link

udaya2899 commented Jul 18, 2024

@lalten were you able to make progress on this PR?

@lalten
Copy link
Contributor Author

lalten commented Jul 18, 2024

@lalten were you able to make progress on this PR?

I'm working on this on and off when I find time, which I didn't since the last commit 🙈

@udaya2899
Copy link

No worries, thank you for your contribution. As far as I understand, you got everything working already, right? Maybe time to merge 👀 ?

@lalten
Copy link
Contributor Author

lalten commented Aug 29, 2024

Tried to update this branch (still waiting on #344 and #340) but the new rust features require some work to be compatible with Bzlmod.

In particular it's not obvious how to get the bindgen stuff into Bzlmod. Looks like bazelbuild/rules_rust#2787

@ahans
Copy link
Contributor

ahans commented Sep 26, 2024

@lalten @mvukov Anything I can lend a hand with? Being able to move to bzlmod would be big!

@lalten
Copy link
Contributor Author

lalten commented Sep 26, 2024

My previous comment regarding the rust stuff is still the state of things. I'm thinking if we could add a custom build config flag or so to disable the rust support that might be a way around those issues.

@ahans
Copy link
Contributor

ahans commented Sep 27, 2024

My previous comment regarding the rust stuff is still the state of things. I'm thinking if we could add a custom build config flag or so to disable the rust support that might be a way around those issues.

Yeah, that sounds good. You could tag all Rust-related tests with no_bzlmod and then use --tag_test_filters to exclude them. Or simply exclude them in the CI config by doing something like bazel test -- //... -//ros2/test/rust/.... We'd need some documentation making clear that Rust support is only available in the WORKSPACE version, but that should be about it? The bindgen discussion sounds like it could be a while until this is fully supported with bzlmod... @mvukov What do you think?

@mvukov
Copy link
Owner

mvukov commented Sep 29, 2024

I have no objections merging bzlmod support. But, workspace-based workflow must work, no compromises on that one for the time being. I am not personally using bzlmod (yet) in any projects, so, no Rust support is fine.

Something to think about: https://github.com/mvukov/rules_ros is for instance migrated to bzlmod recently. Since no one is using the workspace workflow, it was decided to remove workspace support. Something I found along the way:

  • Python toolchain to be used is the one from the parent project, i.e. rules_ros.
  • In this repo we have rules_ros2_pip_deps, in the other rules_ros_pip_deps. Turns out one can not override this repo from his/her own repo. The issue is tracked in Thirdparty pip dependencies override root project's pip dependencies bazelbuild/rules_python#1791. Depending on what parts of and how you use rules_ros2, this might be a (big) problem. In workspace based workflow one can extend requirements.txt with their own deps and use that both with rules_ros2 in their own repo. (Of course, one needs to be careful not to break things.) This is a blocker IMO to remove workspace workflow from rules_ros2.

@mvukov
Copy link
Owner

mvukov commented Dec 2, 2024

bazelbuild/rules_python#2370 also very relevant and would solve issues with bzlmod and python packages coming from multiple places.

@mvukov
Copy link
Owner

mvukov commented Dec 21, 2024

rust bindgen is available in bzlmod iirc since rules_rust 0.55.0.

@kgreenek
Copy link
Contributor

Watching this eagerly! I'm going through the painful process now of getting my company's dependencies all up on BCR / working with bazel modules. Bazel 8 disabling the workspace option by default put a fire under us as motivation.

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.

8 participants