-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Bazel build #2225
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
base: main
Are you sure you want to change the base?
Bazel build #2225
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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 file shouldn't be here
saran-t
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.
General comment: have you validated that you're passing the same compiler flags for the dependencies as we do for CMake builds?
| load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
|
||
| def abseil_cpp_repository(name = "abseil-cpp"): | ||
| version = "20240722.0" |
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.
We really should have a mechanism to ensure that this is kept in sync with CMakeFiles...
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 is a good idea. Let me add that mechanism.
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.
There are several libraries that aren't being pulled in for our CMake builds (cereal, spdlog, libglvnd, ...) -- why are these needed for Bazel?
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.
These are transitive dependencies:
For instance, SdfLib depends on cereal and spdlog, while libglfw3 depends on libglvnd.
The goal is to avoid using system-installed libraries and instead fetch them with a fixed SHA to ensure hermeticity.
| @@ -0,0 +1,94 @@ | |||
| workspace(name = "mujoco") | |||
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 is using the soon-to-be deprecated WORKSPACE system. It might be worth migrating this to use the new Bzlmod setup. I'll take a look at this if I have some extra time in the upcoming days. No guarantees though.
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.
Good point. I noticed that some dependencies are already in Bazel Central Registry. Let me know how it goes - I’m happy to explore this as well.
|
I see that some of my changes to the include paths broke the CMake build system. I'll fix this issue. |
|
This was due to the change in |
Thanks for the comment, and sorry for the delayed response. I've added some default copts to match the options in CMake. I know the CMake system has more options to configure GL backends and precision, but I hope this PR serves as a starting point toward that. |
|
Hey @saran-t Re: Compiler flags: I think the two big discussion points are:
What is your opinion, on merging this PR without these changes? And extending the scope of the bazel build incrementally afterwards? CC: @yuvaltassa, @hartikainen, @bd-jahn @bd-sarikatla @bd-adaniele |
|
I'm so sorry about forgetting about this PR and thanks for prodding. I'm going to try and see how far I can get with importing this into our internal repo and setting up continuous builds for Bazel. In the meantime, could you please validate if everything is still working correctly at HEAD? As an alternative to merging this into our own repo, would you consider maintaining a separate BD-owned repo for Bazel building infrastructure for MuJoCo? Given that you guys will be the de factor owner of this stuff, it is likely going to be less overhead and annoyance if you can avoid having to wait for us to merge PRs all the time. I'd suggest having something like a |
|
@saran-t Thanks for your response. I'll update the PR and make sure everything works with the latest master. Looking forward to catching up in person for the next step! |
|
I took a stab at porting this into bzlmod setup earlier this year. I intended to finish it but, as often happens, haven't had found time to do that. I'll see if I can get back to it sometime in the upcoming weekends. For me, it would also be important to get the macos build working as most of my development happens on a macbook. |
|
Did this go anywhere? I'm another bazel user who would love to not have to write my own build files. |
|
Same here! :) |
|
@bd-jahn, I tried running the the bazel build from the latest main (v3.3.3) and had to make some changes on my way. Feel free to pick those changes here. They're available at main...hartikainen:mujoco:bazel-build-v3.3.3. I haven't verified that things fully work but |
Summary
This PR introduces a Bazel build system that compiles the C library, Python bindings, and
mjxlibrary. While the original CMake build system supports multiple architectures and configurations, this Bazel build is currently configured only for Ubuntu 22.04 on x86_64.This setup is not yet fully comprehensive. Some functionalities are still lacking, such as a hermetic toolchain, support for multiple OS and architecture builds, and compatibility with various rendering backends. However, this PR aims to initiate a discussion on the best direction for further improvements.
Testing
Build and test using the default Clang compiler:
Run
bazel build //...andbazel test //....Build and test using the GCC compiler:
Run
bazel build --config=linux_gcc_x86_64 //...andbazel test --config=linux_gcc_x86_64 //....Security
This build process fetches third-party dependencies through Bazel's
http_archiverule, ensuring each dependency includes its license file.