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

Bazel build #2225

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Bazel build #2225

wants to merge 7 commits into from

Conversation

bd-jahn
Copy link

@bd-jahn bd-jahn commented Nov 12, 2024

Summary

This PR introduces a Bazel build system that compiles the C library, Python bindings, and mjx library. 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 //... and bazel test //....

Build and test using the GCC compiler:

Run bazel build --config=linux_gcc_x86_64 //... and bazel test --config=linux_gcc_x86_64 //....

Security

This build process fetches third-party dependencies through Bazel's http_archive rule, ensuring each dependency includes its license file.

Copy link

google-cla bot commented Nov 12, 2024

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.

Copy link
Member

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

Copy link
Member

@saran-t saran-t left a 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"
Copy link
Member

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...

Copy link
Author

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.

Copy link
Member

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?

Copy link
Author

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")
Copy link
Contributor

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.

Copy link
Author

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.

@bd-jahn
Copy link
Author

bd-jahn commented Nov 15, 2024

I see that some of my changes to the include paths broke the CMake build system. I'll fix this issue.

@bd-jahn
Copy link
Author

bd-jahn commented Nov 27, 2024

Any idea of why this is failing? I only touched generate_functions.py, generate_functions.py, and generate_structs.py, which shouldn't affect the test.

@bd-jahn
Copy link
Author

bd-jahn commented Dec 20, 2024

General comment: have you validated that you're passing the same compiler flags for the dependencies as we do for CMake builds?

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.

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