diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 0000000000..c53f4e8d29 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,58 @@ +# don't use bzlmod yet. +common --enable_workspace=true +common --enable_bzlmod=false + +# use c++20 by default +build --cxxopt=-std=c++20 + +# remove this when https://github.com/abseil/abseil-cpp/issues/740 is resolved +build --copt=-Iexternal/abseil-cpp + +# Due to the repetitive directory names (e.g., `mujoco/mjx/mujoco/mjx`), `__init__.py` should not +# be automatically created. Otherwise, importing with `import mujoco.mjx` will reference +# `mujoco/mjx` instead of `mujoco/mjx/mujoco/mjx`. +build --incompatible_default_to_explicit_init_py + +# Compiler configuration. +# Note that the current configuration relies on system-installed toolchains, which may cause +# non-hermetic behavior in builds. This could be improved by defining a `cc_toolchain` with +# self-contained toolchains. +# See https://docs.bazel.build/versions/1.2.0/tutorial/cc-toolchain-config.html#configuring-the-c-toolchain + +# clang by default +build --platforms=@mujoco//tools:linux_clang_x86_64 +build --action_env=CC=clang + +# gcc +build:linux_gcc_x86_64 --platforms=@mujoco//tools:linux_gcc_x86_64 +build:linux_gcc_x86_64 --action_env=CC=gcc + +# ASan Build +build:asan --build_tests_only +build:asan --features=asan +# This flag effectively tells Bazel to avoid using certain hardware-dependent features that may +# cause ASan or TSan to fail unexpectedly or produce inaccurate results. +build:asan --incompatible_use_host_features + +# LSan is run with ASan by default +build:asan --test_tag_filters=-no_asan,-no_lsan +build:asan --test_lang_filters=-sh +# Typical slowdown introduced by AddressSanitizer is 2x. +# See https://clang.llvm.org/docs/AddressSanitizer.html +build:asan --test_timeout=150,750,2250,9000 + +# TSan Build +build:tsan --build_tests_only +build:tsan --features=tsan +# This flag effectively tells Bazel to avoid using certain hardware-dependent features that may +# cause ASan or TSan to fail unexpectedly or produce inaccurate results. +build:tsan --incompatible_use_host_features + +# We assume anything that didn't want asan doesn't want tsan +build:tsan --test_tag_filters=-no_asan,-no_tsan +build:tsan --test_lang_filters=-sh +# Typical slowdown introduced by ThreadSanitizer is about 5x-15x +# See https://clang.llvm.org/docs/ThreadSanitizer.html +build:tsan --test_timeout=150,750,2250,9000 + +try-import %workspace%/user.bazelrc diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 0000000000..815da58b7a --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +7.4.1 diff --git a/.gitignore b/.gitignore index ba97a7c9b2..733be8b757 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,6 @@ MUJOCO_LOG.TXT # Clang cache .cache/ + +# Bazel build artifacts (symlinks) +/bazel-* diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 0000000000..72c6b9386c --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,173 @@ +load("@mujoco//tools:symlink_files.bzl", "symlink_files") +load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier") +load("@mujoco//tools:def.bzl", "mj_cc_library") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +filegroup( + name = "license_filegroup", + srcs = [ + "LICENSE", + ], + tags = ["license_filegroup"], +) + +mj_cc_library( + name = "mujoco_hdrs", + hdrs = [":mujoco_headers"], + includes = [ + "include", + ], + target_compatible_with = ["@platforms//os:linux"], + visibility = ["//visibility:public"], +) + +mj_cc_library( + name = "_core", + target_compatible_with = ["@platforms//os:linux"], + deps = [ + "//src/engine", + "//src/thread:thread_pool", + "//src/xml:xml_api", + ], +) + +mj_cc_library( + name = "_graphics_native", + target_compatible_with = ["@platforms//os:linux"], + deps = [ + "//src/render", + "//src/ui:ui_main", + ], +) + +# The headers are needed to generate ctypes Python bindings. +filegroup( + name = "mujoco_headers", + srcs = [ + "include/mujoco/mjdata.h", + "include/mujoco/mjexport.h", + "include/mujoco/mjmacro.h", + "include/mujoco/mjmodel.h", + "include/mujoco/mjplugin.h", + "include/mujoco/mjrender.h", + "include/mujoco/mjsan.h", + "include/mujoco/mjspec.h", + "include/mujoco/mjthread.h", + "include/mujoco/mjtnum.h", + "include/mujoco/mjui.h", + "include/mujoco/mjvisualize.h", + "include/mujoco/mjxmacro.h", + "include/mujoco/mujoco.h", + ], +) + +mj_cc_library( + name = "mujoco", + hdrs = [":mujoco_headers"], + data = [ + ":license_filegroup", + ], + includes = [ + "include", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":_core", + ":_graphics_native", + ], +) + +cc_shared_library( + name = "mujoco_shared", + shared_lib_name = "libmujoco.so", + target_compatible_with = ["@platforms//os:linux"], + visibility = ["//visibility:public"], + deps = [ + ":mujoco", + ], +) + +alias( + name = "simulate", + actual = "//simulate:main", + visibility = ["//visibility:public"], +) + +alias( + name = "mujoco-py", + actual = "//python/mujoco:mujoco-py", + target_compatible_with = ["@platforms//os:linux"], + visibility = ["//visibility:public"], +) + +alias( + name = "mujoco-mjx", + actual = "//mjx/mujoco/mjx:mjx", + target_compatible_with = ["@platforms//os:linux"], + visibility = ["//visibility:public"], +) + +# Symlink data for the test. Note that Bazel tests look for data in the `TEST.runfiles/mujoco` +# directory, so we create proper symlinks for the files instead of altering paths within the test. +symlink_files( + name = "model_data", + srcs = ["//model"], +) + +# The reason we have `test_data` and `test_data_stripped` is that some tests (e.g., `spec_test.py`) +# reads `test/testdata/model.xml` while `pipeline_test.cc` reads `testdata/model.xml`. +symlink_files( + name = "test_data", + srcs = ["//test/testdata:model"], +) + +symlink_files( + name = "test_data_stripped", + srcs = ["//test/testdata:model"], + strip_prefix = "test/", +) + +symlink_files( + name = "test_engine_data", + srcs = ["//test/engine/testdata:model"], +) + +symlink_files( + name = "test_engine_data_stripped", + srcs = ["//test/engine/testdata:model"], + strip_prefix = "test/", +) + +symlink_files( + name = "test_plugin_data", + srcs = ["//test/plugin/sensor/testdata:model"], + strip_prefix = "test/", +) + +symlink_files( + name = "test_user_data", + srcs = ["//test/user/testdata:model"], + strip_prefix = "test/", +) + +symlink_files( + name = "test_xml_data", + srcs = ["//test/xml/testdata:model"], + strip_prefix = "test/", +) + +symlink_files( + name = "test_benchmark_data", + srcs = ["//test/benchmark/testdata:model"], +) + +symlink_files( + name = "test_benchmark_data_stripped", + srcs = ["//test/benchmark/testdata:model"], + strip_prefix = "test/", +) + +buildifier( + name = "buildifier", +) diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 0000000000..a953adbae3 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,94 @@ +workspace(name = "mujoco") + +""" +Download dependencies. Note that the functions below could potentially be called from a larger +Bazel project that fetches MuJoCo. +""" + +load("@mujoco//tools/workspace:default_repositories.bzl", "add_default_repositories") + +add_default_repositories() + +load("@mujoco//tools/workspace:default_dependencies.bzl", "add_default_dependencies") + +add_default_dependencies() + +""" +Configure a Python toolchain and Buildifier (a formatting tool for BUILD.bazel files). Note that the functions below are in a local scope and won’t be called from a larger Bazel project that fetches MuJoCo. +""" + +# Python +load("@rules_python//python:repositories.bzl", "python_register_toolchains") + +python_register_toolchains( + name = "python_3_11", + python_version = "3.11", +) + +load("@rules_python//python:pip.bzl", "pip_parse") +load("@python_3_11//:defs.bzl", "interpreter") + +pip_parse( + name = "pip_deps", + python_interpreter_target = interpreter, + requirements_lock = "@mujoco//python:pip_requirements.txt", +) + +load("@pip_deps//:requirements.bzl", install_pip_deps = "install_deps") + +install_pip_deps() + +# Buildifier to format BUILD.bazel files +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "io_bazel_rules_go", + sha256 = "6dc2da7ab4cf5d7bfc7c949776b1b7c733f05e56edc4bcd9022bb249d2e2a996", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.1/rules_go-v0.39.1.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.39.1/rules_go-v0.39.1.zip", + ], +) + +load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies") + +go_rules_dependencies() + +load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains") + +go_register_toolchains(version = "1.20.3") + +http_archive( + name = "bazel_gazelle", + sha256 = "727f3e4edd96ea20c29e8c2ca9e8d2af724d8c7778e7923a854b2c80952bc405", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.30.0/bazel-gazelle-v0.30.0.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.30.0/bazel-gazelle-v0.30.0.tar.gz", + ], +) + +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") + +gazelle_dependencies() + +http_archive( + name = "com_google_protobuf", + sha256 = "3bd7828aa5af4b13b99c191e8b1e884ebfa9ad371b0ce264605d347f135d2568", + strip_prefix = "protobuf-3.19.4", + urls = [ + "https://github.com/protocolbuffers/protobuf/archive/v3.19.4.tar.gz", + ], +) + +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") + +protobuf_deps() + +http_archive( + name = "com_github_bazelbuild_buildtools", + sha256 = "ae34c344514e08c23e90da0e2d6cb700fcd28e80c02e23e4d5715dddcb42f7b3", + strip_prefix = "buildtools-4.2.2", + urls = [ + "https://github.com/bazelbuild/buildtools/archive/refs/tags/4.2.2.tar.gz", + ], +) diff --git a/devtools/bbcp/builddefs/BUILD.bazel b/devtools/bbcp/builddefs/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/devtools/bbcp/builddefs/build_defs.bzl b/devtools/bbcp/builddefs/build_defs.bzl new file mode 100644 index 0000000000..450e03e137 --- /dev/null +++ b/devtools/bbcp/builddefs/build_defs.bzl @@ -0,0 +1,18 @@ +#Copied from https://github.com/taylor-bsg/xls/blob/7afd772753d95078cdd513566de438d8fcc2cfbd/xls/build_rules/xls_oss_config_rules.bzl#L25 + +def generated_file( + name = None, + wrapped_target = None, + tags = None, + testonly = None): + """The function is a placeholder for generated_file. + + The function is intended to be empty. + + Args: + name: Optional name of the marker rule created by this macro. + wrapped_target: The target to wrap. + tags: A list of tags to set on the artifacts. + testonly: Optional standard testonly attribute. + """ + pass diff --git a/devtools/python/blaze/BUILD.bazel b/devtools/python/blaze/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/devtools/python/blaze/pybind.bzl b/devtools/python/blaze/pybind.bzl new file mode 100644 index 0000000000..dba44162bf --- /dev/null +++ b/devtools/python/blaze/pybind.bzl @@ -0,0 +1,55 @@ +# Copied from https://github.com/pybind/pybind11_bazel/blob/v2.11.1.bzl.1/build_defs.bzl and +# modified. + +PYBIND_COPTS = ["-fexceptions"] + +PYBIND_FEATURES = [ + "-use_header_modules", # Required for pybind11. + "-parse_headers", +] + +PYBIND_DEPS = [ + "@pybind11", +] + +def pybind_extension( + name, + copts = [], + features = [], + linkopts = [], + tags = [], + deps = [], + **kwargs): + # Mark common dependencies as required for build_cleaner. + tags = tags + ["req_dep=%s" % dep for dep in PYBIND_DEPS] + + native.cc_binary( + name = name + ".so", + copts = copts + PYBIND_COPTS + ["-fvisibility=hidden"], + features = features + PYBIND_FEATURES, + linkopts = linkopts, + linkshared = 1, + tags = tags, + deps = deps + PYBIND_DEPS, + **kwargs + ) + +# Builds a pybind11 compatible library. This can be linked to a pybind_extension. +def pybind_library( + name, + copts = [], + features = [], + tags = [], + deps = [], + **kwargs): + # Mark common dependencies as required for build_cleaner. + tags = tags + ["req_dep=%s" % dep for dep in PYBIND_DEPS] + + native.cc_library( + name = name, + copts = copts + PYBIND_COPTS, + features = features + PYBIND_FEATURES, + tags = tags, + deps = deps + PYBIND_DEPS, + **kwargs + ) diff --git a/mjx/mujoco/mjx/BUILD.bazel b/mjx/mujoco/mjx/BUILD.bazel new file mode 100644 index 0000000000..7652fd8064 --- /dev/null +++ b/mjx/mujoco/mjx/BUILD.bazel @@ -0,0 +1,655 @@ +load("@pip_deps//:requirements.bzl", "requirement") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +py_library( + name = "collision_convex", + srcs = [ + "_src/collision_convex.py", + ], + imports = ["../.."], + deps = [ + ":collision_types", + ":math", + ":mesh", + ":types", + requirement("jax"), + ], +) + +py_library( + name = "collision_driver", + srcs = [ + "_src/collision_driver.py", + ], + imports = ["../.."], + deps = [ + ":collision_convex", + ":collision_primitive", + ":collision_sdf", + ":collision_types", + ":support", + ":types", + "//:mujoco-py", + requirement("jax"), + requirement("numpy"), + ], +) + +py_library( + name = "collision_sdf", + srcs = [ + "_src/collision_sdf.py", + ], + imports = ["../.."], + deps = [ + ":collision_types", + ":dataclasses", + ":math", + ":types", + requirement("jax"), + ], +) + +py_library( + name = "collision_primitive", + srcs = [ + "_src/collision_primitive.py", + ], + imports = ["../.."], + deps = [ + ":collision_types", + ":math", + ":types", + requirement("jax"), + ], +) + +py_library( + name = "collision_types", + srcs = [ + "_src/collision_types.py", + ], + imports = ["../.."], + deps = [ + ":dataclasses", + "//:mujoco-py", + requirement("jax"), + requirement("numpy"), + ], +) + +py_library( + name = "constraint", + srcs = [ + "_src/constraint.py", + ], + imports = ["../.."], + deps = [ + ":collision_driver", + ":dataclasses", + ":math", + ":support", + ":types", + "//:mujoco-py", + requirement("jax"), + requirement("numpy"), + ], +) + +py_library( + name = "dataclasses", + srcs = [ + "_src/dataclasses.py", + ], + imports = ["../.."], + deps = [ + requirement("jax"), + requirement("numpy"), + ], +) + +py_library( + name = "forward", + srcs = [ + "_src/forward.py", + ], + imports = ["../.."], + deps = [ + ":collision_driver", + ":constraint", + ":math", + ":passive", + ":scan", + ":sensor", + ":smooth", + ":solver", + ":support", + ":types", + "//:mujoco-py", + requirement("jax"), + requirement("numpy"), + ], +) + +py_library( + name = "io", + srcs = [ + "_src/io.py", + ], + imports = ["../.."], + deps = [ + ":collision_driver", + ":constraint", + ":mesh", + ":support", + ":types", + "//:mujoco-py", + requirement("jax"), + requirement("numpy"), + requirement("scipy"), + ], +) + +py_library( + name = "math", + srcs = [ + "_src/math.py", + ], + imports = ["../.."], + deps = [ + requirement("jax"), + ], +) + +py_library( + name = "mesh", + srcs = [ + "_src/mesh.py", + ], + imports = ["../.."], + deps = [ + ":collision_types", + ":math", + ":types", + "//:mujoco-py", + requirement("jax"), + requirement("numpy"), + requirement("scipy"), + requirement("trimesh"), + ], +) + +py_library( + name = "passive", + srcs = [ + "_src/passive.py", + ], + imports = ["../.."], + deps = [ + ":math", + ":scan", + ":support", + ":types", + requirement("jax"), + ], +) + +py_library( + name = "ray", + srcs = [ + "_src/ray.py", + ], + imports = ["../.."], + deps = [ + ":math", + ":types", + "//:mujoco-py", + requirement("jax"), + requirement("numpy"), + ], +) + +py_library( + name = "scan", + srcs = [ + "_src/scan.py", + ], + imports = ["../.."], + deps = [ + ":types", + requirement("jax"), + requirement("numpy"), + ], +) + +py_library( + name = "smooth", + srcs = [ + "_src/smooth.py", + ], + imports = ["../.."], + deps = [ + ":math", + ":scan", + ":support", + ":types", + "//:mujoco-py", + requirement("jax"), + requirement("numpy"), + ], +) + +py_library( + name = "solver", + srcs = [ + "_src/solver.py", + ], + imports = ["../.."], + deps = [ + ":dataclasses", + ":math", + ":smooth", + ":support", + ":types", + "//:mujoco-py", + requirement("jax"), + ], +) + +py_library( + name = "support", + srcs = [ + "_src/support.py", + ], + imports = ["../.."], + deps = [ + ":math", + ":scan", + ":types", + "//:mujoco-py", + "//python/mujoco/introspect:mjxmacro", + requirement("jax"), + requirement("numpy"), + ], +) + +py_library( + name = "types", + srcs = [ + "_src/types.py", + ], + imports = ["../.."], + deps = [ + ":dataclasses", + "//:mujoco-py", + requirement("jax"), + requirement("numpy"), + ], +) + +py_library( + name = "mjx", + srcs = [ + "__init__.py", + ], + data = [ + "//:license_filegroup", + ], + imports = ["../.."], + visibility = ["//visibility:public"], + deps = [ + ":collision_driver", + ":constraint", + ":forward", + ":io", + ":passive", + ":ray", + ":sensor", + ":smooth", + ":solver", + ":support", + ":test_util", + ":types", + ], +) + +py_library( + name = "test_util", + srcs = [ + "_src/test_util.py", + ], + deps = [ + ":forward", + ":io", + ":types", + "//:mujoco-py", + requirement("etils"), + requirement("jax"), + requirement("numpy"), + ], +) + +py_library( + name = "sensor", + srcs = [ + "_src/sensor.py", + ], + deps = [ + ":types", + requirement("jax"), + requirement("numpy"), + ], +) + +py_test( + name = "sensor_test", + size = "small", + srcs = [ + "_src/sensor_test.py", + ], + data = [ + "//mjx/mujoco/mjx/test_data:model", + ], + shard_count = 3, + deps = [ + ":mjx", + ":test_util", + "//:mujoco-py", + requirement("absl-py"), + requirement("jax"), + requirement("numpy"), + requirement("typing_extensions"), + requirement("importlib_resources"), + ], +) + +py_test( + name = "collision_driver_test", + size = "medium", + srcs = [ + "_src/collision_driver_test.py", + ], + data = [ + "//mjx/mujoco/mjx/test_data:model", + ], + deps = [ + ":collision_driver", + ":mjx", + ":test_util", + ":types", + "//:mujoco-py", + requirement("absl-py"), + requirement("etils"), + requirement("jax"), + requirement("numpy"), + requirement("typing_extensions"), + requirement("importlib_resources"), + ], +) + +py_test( + name = "constraint_test", + size = "small", + srcs = [ + "_src/constraint_test.py", + ], + data = [ + "//mjx/mujoco/mjx/test_data:model", + ], + shard_count = 5, + deps = [ + ":constraint", + ":mjx", + ":test_util", + requirement("absl-py"), + requirement("jax"), + requirement("numpy"), + requirement("typing_extensions"), + requirement("importlib_resources"), + ], +) + +py_test( + name = "io_test", + size = "small", + srcs = [ + "_src/io_test.py", + ], + data = [ + "//mjx/mujoco/mjx/test_data:model", + ], + shard_count = 5, + deps = [ + ":mjx", + requirement("absl-py"), + requirement("jax"), + requirement("numpy"), + requirement("typing_extensions"), + requirement("importlib_resources"), + ], +) + +py_test( + name = "forward_test", + size = "small", + srcs = [ + "_src/forward_test.py", + ], + data = [ + "//mjx/mujoco/mjx/test_data:model", + ], + shard_count = 4, + deps = [ + ":mjx", + ":test_util", + requirement("absl-py"), + requirement("jax"), + requirement("numpy"), + requirement("typing_extensions"), + requirement("importlib_resources"), + ], +) + +py_test( + name = "math_test", + size = "small", + srcs = [ + "_src/math_test.py", + ], + shard_count = 20, + deps = [ + ":math", + requirement("absl-py"), + requirement("jax"), + requirement("numpy"), + requirement("typing_extensions"), + requirement("importlib_resources"), + ], +) + +py_test( + name = "mesh_test", + size = "small", + srcs = [ + "_src/mesh_test.py", + ], + deps = [ + ":mesh", + requirement("absl-py"), + requirement("numpy"), + requirement("trimesh"), + requirement("typing_extensions"), + ], +) + +py_test( + name = "passive_test", + size = "small", + srcs = [ + "_src/passive_test.py", + ], + data = [ + "//mjx/mujoco/mjx/test_data:model", + ], + deps = [ + ":mjx", + ":test_util", + "//:mujoco-py", + requirement("absl-py"), + requirement("jax"), + requirement("numpy"), + requirement("typing_extensions"), + requirement("importlib_resources"), + ], +) + +py_test( + name = "ray_test", + size = "small", + srcs = [ + "_src/ray_test.py", + ], + data = [ + "//mjx/mujoco/mjx/test_data:model", + ], + deps = [ + ":mjx", + ":test_util", + "//:mujoco-py", + requirement("absl-py"), + requirement("jax"), + requirement("numpy"), + requirement("typing_extensions"), + requirement("importlib_resources"), + ], +) + +py_test( + name = "scan_test", + size = "small", + srcs = [ + "_src/scan_test.py", + ], + deps = [ + ":mjx", + ":scan", + ":types", + "//:mujoco-py", + requirement("absl-py"), + requirement("jax"), + requirement("numpy"), + requirement("typing_extensions"), + requirement("importlib_resources"), + ], +) + +py_test( + name = "smooth_test", + size = "small", + srcs = [ + "_src/smooth_test.py", + ], + data = [ + "//mjx/mujoco/mjx/test_data:model", + ], + shard_count = 3, + deps = [ + ":mjx", + ":test_util", + "//:mujoco-py", + requirement("absl-py"), + requirement("jax"), + requirement("numpy"), + requirement("typing_extensions"), + requirement("importlib_resources"), + ], +) + +py_test( + name = "solver_test", + size = "small", + srcs = [ + "_src/solver_test.py", + ], + data = [ + "//mjx/mujoco/mjx/test_data:model", + ], + deps = [ + ":mjx", + ":solver", + ":test_util", + "//:mujoco-py", + requirement("absl-py"), + requirement("jax"), + requirement("numpy"), + requirement("typing_extensions"), + requirement("importlib_resources"), + ], +) + +py_test( + name = "support_test", + size = "small", + srcs = [ + "_src/support_test.py", + ], + data = [ + "//mjx/mujoco/mjx/test_data:model", + ], + deps = [ + ":mjx", + ":support", + ":test_util", + "//:mujoco-py", + requirement("absl-py"), + requirement("jax"), + requirement("numpy"), + requirement("typing_extensions"), + requirement("importlib_resources"), + ], +) + +BENCHMARKS = ( + ("barkour", "barkour_v0/assets/barkour_v0_mjx.xml", "4", "cg", "4", "6"), + ("barkour", "barkour_v0/assets/barkour_v0_mjx.xml", "4", "newton", "1", "4"), +) + +[py_test( + name = "testspeed_%s_%s" % (model, solver), + size = "large", + srcs = [ + "testspeed.py", + ], + args = [ + "--mjcf=%s" % mjcf, + "--nstep=4", + "--batch_size=2", + "--unroll=%s" % unroll, + "--solver=%s" % solver, + "--iterations=%s" % iterations, + "--ls_iterations=%s" % ls_iterations, + "--output=tsv", + ], + data = [ + "//mjx/mujoco/mjx/test_data:model", + ], + main = "testspeed.py", + tags = ["manual"], + deps = [ + ":mjx", + "//:mujoco-py", + requirement("absl-py"), + requirement("jax"), + requirement("numpy"), + requirement("typing_extensions"), + requirement("importlib_resources"), + requirement("etils"), + ], +) for model, mjcf, unroll, solver, iterations, ls_iterations in BENCHMARKS] + +test_suite( + name = "benchmark_tests", + tags = ["manual"], + tests = ["testspeed_%s_%s" % (model, solver) for model, mjcf, unroll, solver, iterations, ls_iterations in BENCHMARKS], +) diff --git a/mjx/mujoco/mjx/test_data/BUILD.bazel b/mjx/mujoco/mjx/test_data/BUILD.bazel new file mode 100644 index 0000000000..04e22ff7d0 --- /dev/null +++ b/mjx/mujoco/mjx/test_data/BUILD.bazel @@ -0,0 +1,13 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +filegroup( + name = "model", + srcs = glob([ + "**/*.xml", + "**/*.msh", + "**/*.usda", + "**/*.stl", + "**/*.obj", + "**/*.png", + ]), +) diff --git a/model/BUILD.bazel b/model/BUILD.bazel new file mode 100644 index 0000000000..a36e17f143 --- /dev/null +++ b/model/BUILD.bazel @@ -0,0 +1,10 @@ +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "model", + srcs = glob([ + "**/*.xml", + "**/*.png", + "**/*.obj", + ]), +) diff --git a/plugin/actuator/BUILD.bazel b/plugin/actuator/BUILD.bazel new file mode 100644 index 0000000000..0d97af3117 --- /dev/null +++ b/plugin/actuator/BUILD.bazel @@ -0,0 +1,35 @@ +load("@mujoco//tools:def.bzl", "mj_cc_library") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +mj_cc_library( + name = "pid", + srcs = ["pid.cc"], + hdrs = ["pid.h"], + deps = [ + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "register", + srcs = [ + "register.cc", + ], + deps = [ + ":pid", + "//:mujoco_hdrs", + ], + alwayslink = True, +) + +cc_shared_library( + name = "actuator", + dynamic_deps = [ + "//:mujoco_shared", + ], + visibility = ["//visibility:public"], + deps = [ + "register", + ], +) diff --git a/plugin/elasticity/BUILD.bazel b/plugin/elasticity/BUILD.bazel new file mode 100644 index 0000000000..9eeed180d0 --- /dev/null +++ b/plugin/elasticity/BUILD.bazel @@ -0,0 +1,76 @@ +load("@mujoco//tools:def.bzl", "mj_cc_library") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +mj_cc_library( + name = "elasticity_impl", + srcs = [ + "elasticity.cc", + ], + hdrs = [ + "elasticity.h", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + "//:mujoco_hdrs", + ], + alwayslink = True, +) + +mj_cc_library( + name = "cable", + srcs = [ + "cable.cc", + ], + hdrs = [ + "cable.h", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":elasticity_impl", + "//:mujoco_hdrs", + ], + alwayslink = True, +) + +mj_cc_library( + name = "shell", + srcs = [ + "shell.cc", + ], + hdrs = [ + "shell.h", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":elasticity_impl", + "//:mujoco_hdrs", + ], + alwayslink = True, +) + +mj_cc_library( + name = "register", + srcs = [ + "register.cc", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":cable", + ":shell", + "//:mujoco_hdrs", + ], + alwayslink = True, +) + +cc_shared_library( + name = "elasticity", + dynamic_deps = [ + "//:mujoco_shared", + ], + target_compatible_with = ["@platforms//os:linux"], + visibility = ["//visibility:public"], + deps = [ + "register", + ], +) diff --git a/plugin/sdf/BUILD.bazel b/plugin/sdf/BUILD.bazel new file mode 100644 index 0000000000..df4248cdf1 --- /dev/null +++ b/plugin/sdf/BUILD.bazel @@ -0,0 +1,146 @@ +load("@mujoco//tools:def.bzl", "mj_cc_library") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +mj_cc_library( + name = "sdf_impl", + srcs = [ + "sdf.cc", + ], + hdrs = [ + "sdf.h", + ], + deps = [ + "//:mujoco_hdrs", + ], + alwayslink = True, +) + +mj_cc_library( + name = "torus", + srcs = [ + "torus.cc", + ], + hdrs = [ + "torus.h", + ], + deps = [ + ":sdf_impl", + "//:mujoco_hdrs", + ], + alwayslink = True, +) + +mj_cc_library( + name = "bolt", + srcs = [ + "bolt.cc", + ], + hdrs = [ + "bolt.h", + ], + deps = [ + ":sdf_impl", + "//:mujoco_hdrs", + ], + alwayslink = True, +) + +mj_cc_library( + name = "bowl", + srcs = [ + "bowl.cc", + ], + hdrs = [ + "bowl.h", + ], + deps = [ + ":sdf_impl", + "//:mujoco_hdrs", + ], + alwayslink = True, +) + +mj_cc_library( + name = "nut", + srcs = [ + "nut.cc", + ], + hdrs = [ + "nut.h", + ], + deps = [ + ":sdf_impl", + "//:mujoco_hdrs", + ], + alwayslink = True, +) + +mj_cc_library( + name = "gear", + srcs = [ + "gear.cc", + ], + hdrs = [ + "gear.h", + ], + deps = [ + ":sdf_impl", + "//:mujoco_hdrs", + ], + alwayslink = True, +) + +mj_cc_library( + name = "sdflib", + srcs = [ + "sdflib.cc", + ], + hdrs = [ + "sdflib.h", + ], + deps = [ + ":sdf_impl", + "//:mujoco_hdrs", + "@SdfLib", + ], + alwayslink = True, +) + +mj_cc_library( + name = "register", + srcs = [ + "register.cc", + ], + hdrs = [ + "bolt.h", + "bowl.h", + "gear.h", + "nut.h", + "sdf.h", + "sdflib.h", + "torus.h", + ], + deps = [ + ":bolt", + ":bowl", + ":gear", + ":nut", + ":sdflib", + ":torus", + "//:mujoco_hdrs", + "@SdfLib", + ], + alwayslink = True, +) + +cc_shared_library( + name = "sdf", + dynamic_deps = [ + "//:mujoco_shared", + ], + visibility = ["//visibility:public"], + deps = [ + "register", + ], +) diff --git a/plugin/sensor/BUILD.bazel b/plugin/sensor/BUILD.bazel new file mode 100644 index 0000000000..c679190dbb --- /dev/null +++ b/plugin/sensor/BUILD.bazel @@ -0,0 +1,29 @@ +load("@mujoco//tools:def.bzl", "mj_cc_library") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +mj_cc_library( + name = "touch_grid", + srcs = [ + "sensor.cc", + "touch_grid.cc", + ], + hdrs = [ + "touch_grid.h", + ], + deps = [ + "//:mujoco_hdrs", + ], + alwayslink = True, +) + +cc_shared_library( + name = "sensor", + dynamic_deps = [ + "//:mujoco_shared", + ], + visibility = ["//visibility:public"], + deps = [ + "touch_grid", + ], +) diff --git a/python/BUILD.bazel b/python/BUILD.bazel new file mode 100644 index 0000000000..0941e139bf --- /dev/null +++ b/python/BUILD.bazel @@ -0,0 +1,13 @@ +load("@rules_python//python:pip.bzl", "compile_pip_requirements") + +exports_files([ + "pip_requirements.in", + "pip_requirements.txt", +]) + +compile_pip_requirements( + name = "pip_requirements", + generate_hashes = False, + requirements_in = "pip_requirements.in", + requirements_txt = "pip_requirements.txt", +) diff --git a/python/mujoco/BUILD.bazel b/python/mujoco/BUILD.bazel new file mode 100644 index 0000000000..b8e5edab9a --- /dev/null +++ b/python/mujoco/BUILD.bazel @@ -0,0 +1,471 @@ +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") +load("//devtools/bbcp/builddefs:build_defs.bzl", "generated_file") +load("//devtools/python/blaze:pybind.bzl", "pybind_extension", "pybind_library") +load("@pip_deps//:requirements.bzl", "requirement") +load("@mujoco//tools:symlink_files.bzl", "symlink_files") +load("@mujoco//tools:def.bzl", "mj_cc_library") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +py_library( + name = "mujoco-py", + srcs = [ + "__init__.py", + "gl_context.py", + "minimize.py", + "renderer.py", + "rollout.py", + "viewer.py", + ], + data = [ + "//:license_filegroup", + "//:mujoco_shared", + ], + imports = [".."], + visibility = ["//visibility:public"], + deps = [ + ":_callbacks.so", + ":_constants.so", + ":_enums.so", + ":_errors.so", + ":_functions.so", + ":_render.so", + ":_rollout.so", + ":_simulate.so", + ":_specs.so", + ":_structs.so", + "//python/mujoco/glfw", + requirement("numpy"), + ], +) + +genrule( + name = "_genrule_enum_traits.h", + outs = ["enum_traits.h"], + cmd = "$(location //python/mujoco/codegen:generate_enum_traits) > $@", + tools = ["//python/mujoco/codegen:generate_enum_traits"], +) + +generated_file( + tags = ["mujoco_codegen"], + wrapped_target = ":_genrule_enum_traits.h", +) + +mj_cc_library( + name = "mujoco_private_api_header", + hdrs = ["private.h"], + deps = ["//:mujoco_hdrs"], +) + +pybind_extension( + name = "_callbacks", + srcs = ["callbacks.cc"], + dynamic_deps = [ + "//:mujoco_shared", + ], + deps = [ + ":errors_header", + ":raw", + ":structs_header", + "//:mujoco_hdrs", + ], +) + +pybind_extension( + name = "_constants", + srcs = ["constants.cc"], + copts = [ + "-Werror=redundant-move", + "-Wno-redundant-move", + ], + dynamic_deps = [ + "//:mujoco_shared", + ], + deps = [ + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "enum_traits", + hdrs = ["enum_traits.h"], + includes = ["."], + deps = ["//:mujoco_hdrs"], +) + +pybind_extension( + name = "_enums", + srcs = ["enums.cc"], + copts = [ + "-Wno-deprecated-enum-float-conversion", + ], + deps = [ + ":enum_traits", + "//:mujoco_hdrs", + "//python/mujoco/util:crossplatform", + "//python/mujoco/util:tuple_tools", + ], +) + +genrule( + name = "_genrule_function_traits.h", + outs = ["function_traits.h"], + cmd = "$(location //python/mujoco/codegen:generate_function_traits) > $@", + tools = ["//python/mujoco/codegen:generate_function_traits"], +) + +generated_file( + tags = ["mujoco_codegen"], + wrapped_target = ":_genrule_function_traits.h", +) + +mj_cc_library( + name = "function_traits", + hdrs = ["function_traits.h"], + includes = ["."], + deps = [ + "//:mujoco_hdrs", + "//python/mujoco/util:crossplatform", + ], +) + +pybind_library( + name = "errors_header", + hdrs = ["errors.h"], + deps = [ + ":mujoco_private_api_header", + "//:mujoco_hdrs", + "//python/mujoco/util:crossplatform", + "//python/mujoco/util:func_wrap", + ], +) + +pybind_extension( + name = "_errors", + srcs = ["errors.cc"], + deps = [":errors_header"], +) + +pybind_library( + name = "functions_header", + hdrs = ["functions.h"], + deps = [ + ":errors_header", + ":structs_header", + "//:mujoco_hdrs", + "//python/mujoco/util:array_traits", + "//python/mujoco/util:crossplatform", + "//python/mujoco/util:func_wrap", + "//python/mujoco/util:tuple_tools", + "@eigen", + ], +) + +pybind_extension( + name = "_functions", + srcs = ["functions.cc"], + dynamic_deps = [ + "//:mujoco_shared", + ], + deps = [ + ":errors_header", + ":function_traits", + ":functions_header", + ":mujoco_private_api_header", + ":raw", + ":structs_header", + "//:mujoco_hdrs", + "@eigen", + ], +) + +cc_library( + name = "raw", + hdrs = ["raw.h"], + deps = ["//:mujoco_hdrs"], +) + +pybind_extension( + name = "_render", + srcs = ["render.cc"], + dynamic_deps = [ + "//:mujoco_shared", + ], + deps = [ + ":errors_header", + ":function_traits", + ":functions_header", + ":raw", + ":structs_header", + "//:mujoco_hdrs", + "@eigen", + ], +) + +pybind_library( + name = "structs_header", + hdrs = [ + "indexer_xmacro.h", + "indexers.h", + "structs.h", + ], + copts = [ + "-Wno-sign-compare", + ], + deps = [ + ":raw", + "//:mujoco_hdrs", + "@abseil-cpp//absl/container:flat_hash_map", + "@abseil-cpp//absl/types:span", + ], +) + +pybind_extension( + name = "_structs", + srcs = [ + "indexers.cc", + "serialization.h", + "structs.cc", + ], + copts = [ + "-Wno-sign-compare", + "-Werror=redundant-move", + "-Wno-redundant-move", + "-Wno-type-limits", + "-Wno-error", + ], + dynamic_deps = [ + "//:mujoco_shared", + ], + deps = [ + ":errors_header", + ":function_traits", + ":mujoco_private_api_header", + ":raw", + ":structs_header", + "//:mujoco_hdrs", + "//python/mujoco/util:crossplatform", + "@abseil-cpp//absl/container:flat_hash_map", + ], +) + +pybind_extension( + name = "_rollout", + srcs = [ + "rollout.cc", + "threadpool.h", + "threadpool.cc" + ], + dynamic_deps = [ + "//:mujoco_shared", + ], + deps = [ + ":errors_header", + ":raw", + ":structs_header", + "//:mujoco_hdrs", + ], +) + +# This genrule is non-hermetic and uses the system-installed clang-format. +genrule( + name = "_genrule_specs.cc.inc", + outs = ["specs.cc.inc"], + cmd = """ + GENERATE_SPEC_BINDING=$(location //python/mujoco/codegen:generate_spec_bindings) + CLANG_FORMAT=$$(which clang-format) + $${GENERATE_SPEC_BINDING} | $${CLANG_FORMAT} - > $@ + """, + tools = [ + "//python/mujoco/codegen:generate_spec_bindings", + ], +) + +pybind_extension( + name = "_simulate", + srcs = [ + "simulate.cc", + ], + copts = [ + "-Werror=redundant-move", + "-Wno-redundant-move", + "-Wno-type-limits", + "-Wno-error", + "-Ipython/mujoco", + "-Isimulate", + ], + deps = [ + ":errors_header", + ":structs_header", + "//simulate:simulate_lib", + "@libglfw3//:lib", + ], +) + +pybind_extension( + name = "_specs", + srcs = [ + "specs.cc", + "specs.cc.inc", + ], + copts = [ + "-Wno-sign-compare", + ], + includes = ["."], + dynamic_deps = [ + "//:mujoco_shared", + ], + deps = [ + ":errors_header", + ":raw", + ":structs_header", + "//:mujoco_hdrs", + "@eigen", + ], +) + +exports_files( + srcs = [ + "mjpython/mjpython.mm", + "mjpython/mjpython.py", + ], +) + +# symlink plugins for test +symlink_files( + name = "symlinked_plugins", + srcs = [ + "//plugin/actuator", + "//plugin/elasticity", + "//plugin/sdf", + "//plugin/sensor", + ], +) + +# symlink plugins for test +symlink_files( + name = "symlinked_mujoco_so", + srcs = [ + "//:mujoco_shared", + ], +) + +py_test( + name = "bindings_test", + size = "small", + srcs = ["bindings_test.py"], + data = [ + ":symlinked_mujoco_so", + ":symlinked_plugins", + ], + deps = [ + ":mujoco-py", + requirement("absl-py"), + requirement("numpy"), + requirement("typing-extensions"), + ], +) + +# This test should be running with xvfb. (e.g., xvfb-run -s "-screen 0 1024x768x24" bazel run //python/mujoco:renderer_test) +py_binary( + name = "renderer_test", + srcs = ["renderer_test.py"], + deps = [ + ":mujoco-py", + requirement("absl-py"), + requirement("numpy"), + ], +) + +# This test should be running with xvfb. (e.g., xvfb-run -s "-screen 0 1024x768x24" bazel run //python/mujoco:render_test) +py_binary( + name = "render_test", + srcs = ["render_test.py"], + main = "render_test.py", + deps = [ + ":mujoco-py", + "//python/mujoco/glfw", + requirement("absl-py"), + requirement("numpy"), + ], +) + +py_test( + name = "rollout_test", + size = "small", + srcs = ["rollout_test.py"], + deps = [ + ":mujoco-py", + requirement("absl-py"), + requirement("numpy"), + requirement("typing-extensions"), + ], +) + +py_test( + name = "specs_test", + srcs = ["specs_test.py"], + data = [ + "//python/mujoco/testdata:model", + ":symlinked_plugins", + ], + deps = [ + ":mujoco-py", + requirement("absl-py"), + requirement("numpy"), + requirement("etils"), + requirement("typing-extensions"), + requirement("importlib-resources"), + ], +) + +py_test( + name = "minimize_test", + size = "small", + srcs = ["minimize_test.py"], + deps = [ + ":mujoco-py", + requirement("absl-py"), + requirement("numpy"), + requirement("typing-extensions"), + ], +) + +py_library( + name = "msh2obj", + srcs = [ + "msh2obj.py", + ], + deps = [ + requirement("numpy"), + ], +) + +py_test( + name = "msh2obj_test", + size = "small", + srcs = ["msh2obj_test.py"], + data = [ + "//python/mujoco/testdata:model", + ], + deps = [ + ":msh2obj", + ":mujoco-py", + requirement("absl-py"), + requirement("numpy"), + requirement("etils"), + requirement("typing-extensions"), + requirement("importlib-resources"), + ], +) + +py_test( + name = "memory_leak_test", + size = "small", + srcs = ["memory_leak_test.py"], + deps = [ + ":mujoco-py", + requirement("absl-py"), + requirement("typing-extensions"), + ], +) diff --git a/python/mujoco/cgl/BUILD.bazel b/python/mujoco/cgl/BUILD.bazel new file mode 100644 index 0000000000..956eb21c69 --- /dev/null +++ b/python/mujoco/cgl/BUILD.bazel @@ -0,0 +1,7 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +filegroup( + name = "cgl", + srcs = glob(["**"]), + tags = ["ignore_srcs"], +) diff --git a/python/mujoco/codegen/BUILD.bazel b/python/mujoco/codegen/BUILD.bazel new file mode 100644 index 0000000000..3e439310c4 --- /dev/null +++ b/python/mujoco/codegen/BUILD.bazel @@ -0,0 +1,33 @@ +load("@pip_deps//:requirements.bzl", "requirement") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +py_binary( + name = "generate_enum_traits", + srcs = ["generate_enum_traits.py"], + deps = [ + "//python/mujoco/introspect:ast_nodes", + "//python/mujoco/introspect:enums", + requirement("absl-py"), + ], +) + +py_binary( + name = "generate_function_traits", + srcs = ["generate_function_traits.py"], + deps = [ + "//python/mujoco/introspect:ast_nodes", + "//python/mujoco/introspect:functions", + requirement("absl-py"), + ], +) + +py_binary( + name = "generate_spec_bindings", + srcs = ["generate_spec_bindings.py"], + deps = [ + "//python/mujoco/introspect:ast_nodes", + "//python/mujoco/introspect:structs", + requirement("absl-py"), + ], +) diff --git a/python/mujoco/egl/BUILD.bazel b/python/mujoco/egl/BUILD.bazel new file mode 100644 index 0000000000..a5756a3785 --- /dev/null +++ b/python/mujoco/egl/BUILD.bazel @@ -0,0 +1,13 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +py_library( + name = "egl", + srcs = [ + "__init__.py", + "egl_ext.py", + ], + tags = ["keep_dep"], + deps = [ + "@libglfw3//:lib", + ], +) diff --git a/python/mujoco/glfw/BUILD.bazel b/python/mujoco/glfw/BUILD.bazel new file mode 100644 index 0000000000..46179f874e --- /dev/null +++ b/python/mujoco/glfw/BUILD.bazel @@ -0,0 +1,12 @@ +load("@pip_deps//:requirements.bzl", "requirement") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +py_library( + name = "glfw", + srcs = ["__init__.py"], + tags = ["keep_dep"], + deps = [ + requirement("glfw"), + ], +) diff --git a/python/mujoco/indexers.h b/python/mujoco/indexers.h index 2b9defadfe..6a249cafcd 100644 --- a/python/mujoco/indexers.h +++ b/python/mujoco/indexers.h @@ -22,7 +22,7 @@ #include #include -#include +#include "absl/container/flat_hash_map.h" #include #include "indexer_xmacro.h" #include "raw.h" diff --git a/python/mujoco/introspect/BUILD.bazel b/python/mujoco/introspect/BUILD.bazel new file mode 100644 index 0000000000..e80761a9ee --- /dev/null +++ b/python/mujoco/introspect/BUILD.bazel @@ -0,0 +1,37 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +py_library( + name = "ast_nodes", + srcs = ["ast_nodes.py"], + imports = [".."], +) + +py_library( + name = "type_parsing", + srcs = ["type_parsing.py"], + deps = [":ast_nodes"], +) + +py_library( + name = "enums", + srcs = ["enums.py"], + deps = [":ast_nodes"], +) + +py_library( + name = "functions", + srcs = ["functions.py"], + deps = [":ast_nodes"], +) + +py_library( + name = "structs", + srcs = ["structs.py"], + deps = [":ast_nodes"], +) + +py_library( + name = "mjxmacro", + srcs = ["mjxmacro.py"], + deps = [":structs"], +) diff --git a/python/mujoco/introspect/codegen/BUILD.bazel b/python/mujoco/introspect/codegen/BUILD.bazel new file mode 100644 index 0000000000..29e4dbf3e7 --- /dev/null +++ b/python/mujoco/introspect/codegen/BUILD.bazel @@ -0,0 +1,107 @@ +load("@pip_deps//:requirements.bzl", "requirement") + +# This genrule is non-hermetic and uses the system-installed clang. +genrule( + name = "_genrule_mujoco.h.json", + srcs = ["//:mujoco_headers"], + outs = ["mujoco.h.json"], + cmd = """ + CLANG=$$(which clang) + CLANG_INCLUDE=$$($${CLANG} --print-resource-dir)/include + MUJOCO_H=$$(find $(locations //:mujoco_headers) -name mujoco.h) + MUJOCO_INCLUDE=$$(dirname $$(dirname $${MUJOCO_H})) + $${CLANG} \ + -isystem$${CLANG_INCLUDE} \ + -I$${PWD} \ + -I$${MUJOCO_INCLUDE} \ + -Xclang -ast-dump=json -fsyntax-only -fparse-all-comments -x c \ + $${MUJOCO_H} > $@ + """, +) + +py_binary( + name = "generate_enums", + srcs = ["generate_enums.py"], + deps = [ + ":formatter", + "//python/mujoco/introspect:ast_nodes", + requirement("absl-py"), + "@abseil-cpp//absl/flags:flag", + ], +) + +genrule( + name = "_genrule_enums.py", + srcs = [ + "mujoco.h.json", + "//:mujoco_headers", + ], + outs = ["enums.py"], + cmd = """ + MUJOCO_H=$$(find $(locations //:mujoco_headers) -name mujoco.h) + $(location :generate_enums) \ + --json_path=$(location mujoco.h.json) > $@ + """, + tools = [":generate_enums"], +) + +py_binary( + name = "generate_functions", + srcs = ["generate_functions.py"], + deps = [ + ":formatter", + "//python/mujoco/introspect:ast_nodes", + "//python/mujoco/introspect:type_parsing", + requirement("absl-py"), + "@abseil-cpp//absl/flags:flag", + ], +) + +genrule( + name = "_genrule_functions.py", + srcs = [ + "mujoco.h.json", + "//:mujoco_headers", + ], + outs = ["functions.py"], + cmd = """ + MUJOCO_H=$$(find $(locations //:mujoco_headers) -name mujoco.h) + $(location :generate_functions) \ + --header_path=$${MUJOCO_H} \ + --json_path=$(location mujoco.h.json) > $@ + """, + tools = [":generate_functions"], +) + +py_binary( + name = "generate_structs", + srcs = ["generate_structs.py"], + deps = [ + ":formatter", + "//python/mujoco/introspect:ast_nodes", + "//python/mujoco/introspect:type_parsing", + requirement("absl-py"), + "@abseil-cpp//absl/flags:flag", + ], +) + +genrule( + name = "_genrule_structs.py", + srcs = [ + "mujoco.h.json", + "//:mujoco_headers", + ], + outs = ["structs.py"], + cmd = """ + MUJOCO_H=$$(find $(locations //:mujoco_headers) -name mujoco.h) + $(location :generate_structs) \ + --json_path=$(location mujoco.h.json) > $@ + """, + tools = [":generate_structs"], +) + +py_library( + name = "formatter", + srcs = ["formatter.py"], + imports = ["."], +) diff --git a/python/mujoco/introspect/codegen/generate_enums.py b/python/mujoco/introspect/codegen/generate_enums.py index 59d7ff3b60..ffaa8afee5 100644 --- a/python/mujoco/introspect/codegen/generate_enums.py +++ b/python/mujoco/introspect/codegen/generate_enums.py @@ -25,7 +25,7 @@ from absl import flags from introspect import ast_nodes -from . import formatter +from introspect.codegen import formatter _JSON_PATH = flags.DEFINE_string( 'json_path', None, diff --git a/python/mujoco/introspect/codegen/generate_functions.py b/python/mujoco/introspect/codegen/generate_functions.py index 1966e32895..94f660d6ee 100644 --- a/python/mujoco/introspect/codegen/generate_functions.py +++ b/python/mujoco/introspect/codegen/generate_functions.py @@ -26,7 +26,7 @@ from introspect import ast_nodes from introspect import type_parsing -from . import formatter +from introspect.codegen import formatter _HEADER_PATH = flags.DEFINE_string( 'header_path', None, 'Path to the original mujoco.h') diff --git a/python/mujoco/introspect/codegen/generate_structs.py b/python/mujoco/introspect/codegen/generate_structs.py index 1c50db22fd..2837ccf2b5 100644 --- a/python/mujoco/introspect/codegen/generate_structs.py +++ b/python/mujoco/introspect/codegen/generate_structs.py @@ -29,7 +29,7 @@ from introspect import ast_nodes from introspect import type_parsing -from . import formatter +from introspect.codegen import formatter _JSON_PATH = flags.DEFINE_string( 'json_path', None, diff --git a/python/mujoco/osmesa/BUILD.bazel b/python/mujoco/osmesa/BUILD.bazel new file mode 100644 index 0000000000..1e30def958 --- /dev/null +++ b/python/mujoco/osmesa/BUILD.bazel @@ -0,0 +1,12 @@ +load("@pip_deps//:requirements.bzl", "requirement") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +py_library( + name = "osmesa", + srcs = ["__init__.py"], + deps = [ + requirement("pyopengl"), + requirement("pyopengl_accelerate"), + ], +) diff --git a/python/mujoco/structs.cc b/python/mujoco/structs.cc index 90b73d2410..c52caa3c48 100644 --- a/python/mujoco/structs.cc +++ b/python/mujoco/structs.cc @@ -36,7 +36,7 @@ #include #include -#include +#include "absl/container/flat_hash_map.h" #include #include #include "errors.h" diff --git a/python/mujoco/structs.h b/python/mujoco/structs.h index da8c283a2f..2bc196fdc0 100644 --- a/python/mujoco/structs.h +++ b/python/mujoco/structs.h @@ -32,7 +32,7 @@ #include #include -#include +#include "absl/types/span.h" #include #include #include "indexers.h" diff --git a/python/mujoco/testdata/BUILD.bazel b/python/mujoco/testdata/BUILD.bazel new file mode 100644 index 0000000000..4f7bb5e091 --- /dev/null +++ b/python/mujoco/testdata/BUILD.bazel @@ -0,0 +1,10 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +filegroup( + name = "model", + srcs = glob([ + "**/*.xml", + "**/*.msh", + "**/*.usda", + ]), +) diff --git a/python/mujoco/util/BUILD.bazel b/python/mujoco/util/BUILD.bazel new file mode 100644 index 0000000000..f3269b5421 --- /dev/null +++ b/python/mujoco/util/BUILD.bazel @@ -0,0 +1,41 @@ +load("@mujoco//tools:def.bzl", "mj_cc_library") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +mj_cc_library( + name = "array_traits", + hdrs = ["array_traits.h"], + deps = [ + ":crossplatform", + "@eigen", + ], +) + +mj_cc_library( + name = "crossplatform", + hdrs = ["crossplatform.h"], +) + +mj_cc_library( + name = "func_traits", + hdrs = ["func_traits.h"], +) + +mj_cc_library( + name = "func_wrap", + hdrs = ["func_wrap.h"], + deps = [ + ":array_traits", + ":crossplatform", + ":func_traits", + "@eigen", + ], +) + +mj_cc_library( + name = "tuple_tools", + hdrs = ["tuple_tools.h"], + deps = [ + ":crossplatform", + ], +) diff --git a/python/pip_requirements.in b/python/pip_requirements.in new file mode 100644 index 0000000000..8ad859d4f5 --- /dev/null +++ b/python/pip_requirements.in @@ -0,0 +1,12 @@ +absl-py +numpy +jax +glfw +trimesh +scipy +pyopengl +pyopengl_accelerate +etils +typing-extensions +importlib-resources +trimesh diff --git a/python/pip_requirements.txt b/python/pip_requirements.txt new file mode 100644 index 0000000000..b34f00b24b --- /dev/null +++ b/python/pip_requirements.txt @@ -0,0 +1,45 @@ +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# bazel run //python:pip_requirements.update +# +absl-py==2.1.0 + # via -r python/pip_requirements.in +etils==1.10.0 + # via -r python/pip_requirements.in +glfw==2.7.0 + # via -r python/pip_requirements.in +importlib-resources==6.4.5 + # via -r python/pip_requirements.in +jax==0.4.34 + # via -r python/pip_requirements.in +jaxlib==0.4.34 + # via jax +ml-dtypes==0.5.0 + # via + # jax + # jaxlib +numpy==2.1.2 + # via + # -r python/pip_requirements.in + # jax + # jaxlib + # ml-dtypes + # scipy + # trimesh +opt-einsum==3.4.0 + # via jax +pyopengl==3.1.7 + # via -r python/pip_requirements.in +pyopengl-accelerate==3.1.7 + # via -r python/pip_requirements.in +scipy==1.14.1 + # via + # -r python/pip_requirements.in + # jax + # jaxlib +trimesh==4.5.0 + # via -r python/pip_requirements.in +typing-extensions==4.12.2 + # via -r python/pip_requirements.in diff --git a/sample/BUILD.bazel b/sample/BUILD.bazel new file mode 100644 index 0000000000..d5228439e3 --- /dev/null +++ b/sample/BUILD.bazel @@ -0,0 +1,7 @@ +cc_binary( + name = "testspeed", + srcs = ["testspeed.cc"], + deps = [ + "//:mujoco", + ], +) diff --git a/simulate/BUILD.bazel b/simulate/BUILD.bazel new file mode 100644 index 0000000000..6d9fd13e62 --- /dev/null +++ b/simulate/BUILD.bazel @@ -0,0 +1,63 @@ +load("@mujoco//tools:def.bzl", "mj_cc_library") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +mj_cc_library( + name = "platform_ui_adapter", + srcs = [ + "glfw_adapter.cc", + "glfw_dispatch.cc", + "platform_ui_adapter.cc", + ], + hdrs = [ + "glfw_adapter.h", + "glfw_dispatch.h", + "platform_ui_adapter.h", + ], + data = [ + "//:license_filegroup", + ], + linkstatic = True, + target_compatible_with = ["@platforms//os:linux"], + deps = [ + "//:mujoco", + "@libglfw3//:lib", + ], +) + +mj_cc_library( + name = "simulate_lib", + srcs = [ + "array_safety.h", + "simulate.cc", + ], + hdrs = [ + "simulate.h", + ], + data = [ + "//:license_filegroup", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":platform_ui_adapter", + "@lodepng", + ], +) + +cc_binary( + name = "main", + srcs = [ + "main.cc", + ], + data = [ + "//:license_filegroup", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":simulate_lib", + "//plugin/actuator:register", + "//plugin/elasticity:register", + "//plugin/sdf:register", + "//plugin/sensor:touch_grid", + ], +) diff --git a/src/cc/BUILD.bazel b/src/cc/BUILD.bazel new file mode 100644 index 0000000000..9b060caf43 --- /dev/null +++ b/src/cc/BUILD.bazel @@ -0,0 +1,9 @@ +load("@mujoco//tools:def.bzl", "mj_cc_library") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +mj_cc_library( + name = "array_safety", + hdrs = ["array_safety.h"], + target_compatible_with = ["@platforms//os:linux"], +) diff --git a/src/engine/BUILD.bazel b/src/engine/BUILD.bazel new file mode 100644 index 0000000000..a5aab9e1f1 --- /dev/null +++ b/src/engine/BUILD.bazel @@ -0,0 +1,558 @@ +load("//src/engine:helper.bzl", "THIN_LTO_FEATURE_IF_CLANG", "THIN_LTO_LINKOPTS_IF_CLANG") +load("@mujoco//tools:def.bzl", "mj_cc_library") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +mj_cc_library( + name = "engine", + srcs = [ + "engine_collision_driver.c", + "engine_collision_sdf.c", + "engine_core_constraint.c", + "engine_core_smooth.c", + "engine_derivative.c", + "engine_derivative_fd.c", + "engine_forward.c", + "engine_inverse.c", + "engine_island.c", + "engine_passive.c", + "engine_print.c", + "engine_sensor.c", + "engine_setconst.c", + "engine_solver.c", + "engine_support.c", + "engine_vis_interact.c", + "engine_vis_state.c", + "engine_vis_visualize.c", + ], + hdrs = [ + "engine_collision_driver.h", + "engine_collision_sdf.h", + "engine_core_constraint.h", + "engine_core_smooth.h", + "engine_derivative.h", + "engine_derivative_fd.h", + "engine_forward.h", + "engine_inverse.h", + "engine_island.h", + "engine_passive.h", + "engine_print.h", + "engine_sensor.h", + "engine_setconst.h", + "engine_solver.h", + "engine_support.h", + "engine_vis_interact.h", + "engine_vis_state.h", + "engine_vis_visualize.h", + ], + copts = [ + "-Wno-error=unknown-pragmas", + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//tools:gcc": [ + "-Wno-format-overflow", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + local_defines = [ + "_GNU_SOURCE", + "mjUSEPLATFORMSIMD", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_array_safety", + ":engine_callback", + ":engine_collision_box", + ":engine_collision_convex", + ":engine_collision_primitive", + ":engine_crossplatform", + ":engine_io", + ":engine_macro", + ":engine_name", + ":engine_plugin", + ":engine_ray", + ":engine_sort", + ":engine_util_blas", + ":engine_util_errmem", + ":engine_util_misc", + ":engine_util_solve", + ":engine_util_sparse", + ":engine_util_spatial", + ":engine_vis_init", + "//:mujoco_hdrs", + "//src/thread:thread_pool", + "//src/thread:thread_task", + "@libccd", + ], +) + +mj_cc_library( + name = "engine_array_safety", + copts = ["-Wshadow"], + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], + textual_hdrs = ["engine_array_safety.h"], +) + +mj_cc_library( + name = "engine_callback", + srcs = ["engine_callback.c"], + hdrs = ["engine_callback.h"], + copts = [ + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], + deps = [ + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "engine_collision_box", + srcs = [ + "engine_collision_box.c", + ], + copts = [ + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_collision_primitive", + ":engine_util_blas", + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "engine_collision_convex", + srcs = [ + "engine_collision_convex.c", + "engine_collision_gjk.c", + ], + hdrs = [ + "engine_collision_convex.h", + "engine_collision_gjk.h", + ], + copts = [ + "-Wno-error=unknown-pragmas", + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_collision_primitive", + ":engine_io", + ":engine_util_blas", + ":engine_util_errmem", + ":engine_util_misc", + ":engine_util_spatial", + "//:mujoco_hdrs", + "@libccd", + ], +) + +mj_cc_library( + name = "engine_collision_primitive", + srcs = ["engine_collision_primitive.c"], + hdrs = ["engine_collision_primitive.h"], + copts = [ + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_util_blas", + ":engine_util_misc", + ":engine_util_spatial", + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "engine_crossplatform", + srcs = ["engine_crossplatform.cc"], + hdrs = ["engine_crossplatform.h"], + copts = [ + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], +) + +mj_cc_library( + name = "engine_io", + srcs = ["engine_io.c"], + hdrs = ["engine_io.h"], + copts = [ + "-Wno-error=unknown-pragmas", + "-Wno-type-limits", + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_crossplatform", + ":engine_macro", + ":engine_plugin", + ":engine_util_blas", + ":engine_util_errmem", + ":engine_util_misc", + "//:mujoco_hdrs", + "//src/thread:thread_pool", + ], +) + +mj_cc_library( + name = "engine_macro", + hdrs = ["engine_macro.h"], + copts = ["-Wshadow"], + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_callback", + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "engine_name", + srcs = ["engine_name.c"], + hdrs = ["engine_name.h"], + copts = [ + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_crossplatform", + ":engine_io", + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "engine_plugin", + srcs = ["engine_plugin.cc"], + hdrs = [ + "engine_global_table.h", + "engine_plugin.h", + ], + copts = [ + "-Wno-error=unknown-pragmas", + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = ["-ldl"] + THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_util_errmem", + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "engine_ray", + srcs = ["engine_ray.c"], + hdrs = ["engine_ray.h"], + copts = [ + "-Wno-error=unknown-pragmas", + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_io", + ":engine_plugin", + ":engine_util_blas", + ":engine_util_errmem", + ":engine_util_misc", + ":engine_util_spatial", + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "engine_sort", + hdrs = ["engine_sort.h"], + copts = ["-Wshadow"], + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], +) + +mj_cc_library( + name = "engine_util_blas", + srcs = ["engine_util_blas.c"], + hdrs = ["engine_util_blas.h"], + copts = [ + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + local_defines = [ + "mjUSEPLATFORMSIMD", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "engine_util_container", + srcs = ["engine_util_container.c"], + hdrs = ["engine_util_container.h"], + copts = [ + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_crossplatform", + ":engine_io", + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "engine_util_errmem", + srcs = ["engine_util_errmem.c"], + hdrs = ["engine_util_errmem.h"], + copts = [ + "-Wno-error=unknown-pragmas", + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_array_safety", + ":engine_macro", + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "engine_util_misc", + srcs = ["engine_util_misc.c"], + hdrs = ["engine_util_misc.h"], + copts = [ + "-Wno-error=unknown-pragmas", + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_array_safety", + ":engine_macro", + ":engine_util_blas", + ":engine_util_errmem", + ":engine_util_spatial", + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "engine_util_sparse", + srcs = [ + "engine_util_sparse.c", + ], + hdrs = [ + "engine_util_sparse.h", + "engine_util_sparse_avx.h", + ], + copts = [ + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + local_defines = [ + "mjUSEPLATFORMSIMD", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_io", + ":engine_macro", + ":engine_util_blas", + ":engine_util_misc", + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "engine_util_spatial", + srcs = ["engine_util_spatial.c"], + hdrs = ["engine_util_spatial.h"], + copts = [ + "-Wno-error=unknown-pragmas", + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_util_blas", + ":engine_util_errmem", + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "engine_util_solve", + srcs = ["engine_util_solve.c"], + hdrs = ["engine_util_solve.h"], + copts = [ + "-Wno-error=unknown-pragmas", + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_io", + ":engine_util_blas", + ":engine_util_errmem", + ":engine_util_misc", + ":engine_util_sparse", + ":engine_util_spatial", + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "engine_vis_init", + srcs = ["engine_vis_init.c"], + hdrs = ["engine_vis_init.h"], + copts = [ + "-Wno-error=unknown-pragmas", + "-Wshadow", + "-Isrc", + ] + select({ + "//tools:clang": [ + "-Wno-unused-command-line-argument", + ], + "//conditions:default": [], + }), + features = THIN_LTO_FEATURE_IF_CLANG, + linkopts = THIN_LTO_LINKOPTS_IF_CLANG, + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":engine_array_safety", + ":engine_util_errmem", + ":engine_util_misc", + "//:mujoco_hdrs", + ], +) diff --git a/src/engine/engine_setconst.c b/src/engine/engine_setconst.c index 73f8919e75..95c3185158 100644 --- a/src/engine/engine_setconst.c +++ b/src/engine/engine_setconst.c @@ -96,10 +96,13 @@ static void set0(mjModel* m, mjData* d) { // compute dof_M0 for CRB algorithm mj_setM0(m, d); - // save flex_rigid, temporarily make all flexes non-rigid - mjtByte* rigid = mju_malloc(m->nflex); - memcpy(rigid, m->flex_rigid, m->nflex); - memset(m->flex_rigid, 0, m->nflex); + mjtByte* flex_rigid_cache = NULL; + if (m->nflex > 0) { + // save flex_rigid, temporarily make all flexes non-rigid + flex_rigid_cache = mju_malloc(m->nflex); + memcpy(flex_rigid_cache, m->flex_rigid, m->nflex); + memset(m->flex_rigid, 0, m->nflex); + } // run remaining computations mj_crb(m, d); @@ -108,9 +111,11 @@ static void set0(mjModel* m, mjData* d) { mj_tendon(m, d); mj_transmission(m, d); - // restore flex rigidity - memcpy(m->flex_rigid, rigid, m->nflex); - mju_free(rigid); + if (flex_rigid_cache) { + // restore flex rigidity + memcpy(m->flex_rigid, flex_rigid_cache, m->nflex); + mju_free(flex_rigid_cache); + } // restore camera and light mode for (int i=0; i < m->ncam; i++) { diff --git a/src/engine/helper.bzl b/src/engine/helper.bzl new file mode 100644 index 0000000000..5aff432b68 --- /dev/null +++ b/src/engine/helper.bzl @@ -0,0 +1,9 @@ +THIN_LTO_FEATURE_IF_CLANG = select({ + "//tools:clang": ["thin_lto"], + "//conditions:default": [], +}) + +THIN_LTO_LINKOPTS_IF_CLANG = select({ + "//tools:clang": ["-flto=thin"], + "//conditions:default": [], +}) diff --git a/src/render/BUILD.bazel b/src/render/BUILD.bazel new file mode 100644 index 0000000000..60f279648b --- /dev/null +++ b/src/render/BUILD.bazel @@ -0,0 +1,102 @@ +load("@mujoco//tools:def.bzl", "mj_cc_library") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +mj_cc_library( + name = "glad", + srcs = [ + "glad/glad.c", + "glad/loader.cc", + ], + hdrs = ["glad/glad.h"], + copts = [ + "-Wno-error=unknown-pragmas", + "-Isrc", + ], + linkopts = ["-ldl"], + target_compatible_with = ["@platforms//os:linux"], + deps = ["//src/engine:engine_util_errmem"], +) + +mj_cc_library( + name = "render", + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":render_context", + ":render_gl2", + ":render_gl3", + ":render_util", + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "render_context", + srcs = ["render_context.c"], + hdrs = ["render_context.h"], + copts = [ + "-Isrc", + ], + target_compatible_with = ["@platforms//os:linux"], + textual_hdrs = glob([ + "font/*.inc", + ]), + deps = [ + ":glad", + ":render_util", + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "render_gl2", + srcs = ["render_gl2.c"], + hdrs = ["render_gl2.h"], + copts = [ + "-Isrc", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + "//:mujoco_hdrs", + "//src/engine:engine_array_safety", + "//src/render:glad", + ], +) + +mj_cc_library( + name = "render_gl3", + srcs = ["render_gl3.c"], + hdrs = ["render_gl3.h"], + copts = [ + "-Isrc", + ], + local_defines = [ + "_GNU_SOURCE", + "mjUSEPLATFORMSIMD", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":glad", + ":render_context", + ":render_gl2", + ":render_util", + "//:mujoco_hdrs", + "//src/engine", + "//src/engine:engine_crossplatform", + "//src/engine:engine_vis_init", + ], +) + +mj_cc_library( + name = "render_util", + srcs = ["render_util.c"], + hdrs = ["render_util.h"], + copts = [ + "-Isrc", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + "//:mujoco_hdrs", + "//src/render:glad", + ], +) diff --git a/src/thread/BUILD.bazel b/src/thread/BUILD.bazel new file mode 100644 index 0000000000..fc073b4524 --- /dev/null +++ b/src/thread/BUILD.bazel @@ -0,0 +1,38 @@ +load("@mujoco//tools:def.bzl", "mj_cc_library") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +mj_cc_library( + name = "thread_queue", + hdrs = ["thread_queue.h"], + target_compatible_with = ["@platforms//os:linux"], +) + +mj_cc_library( + name = "thread_task", + srcs = ["thread_task.cc"], + hdrs = ["thread_task.h"], + copts = [ + "-Isrc", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = ["//:mujoco_hdrs"], +) + +mj_cc_library( + name = "thread_pool", + srcs = ["thread_pool.cc"], + hdrs = ["thread_pool.h"], + copts = [ + "-Wno-error=unknown-pragmas", + "-Isrc", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":thread_queue", + ":thread_task", + "//:mujoco_hdrs", + "//src/engine:engine_crossplatform", + "//src/engine:engine_util_errmem", + ], +) diff --git a/src/ui/BUILD.bazel b/src/ui/BUILD.bazel new file mode 100644 index 0000000000..ab9d9841e3 --- /dev/null +++ b/src/ui/BUILD.bazel @@ -0,0 +1,18 @@ +load("@mujoco//tools:def.bzl", "mj_cc_library") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +mj_cc_library( + name = "ui_main", + srcs = ["ui_main.c"], + hdrs = ["ui_main.h"], + copts = [ + "-Isrc", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + "//:mujoco_hdrs", + "//src/engine:engine_array_safety", + "//src/render:glad", + ], +) diff --git a/src/user/BUILD.bazel b/src/user/BUILD.bazel new file mode 100644 index 0000000000..9853cb2040 --- /dev/null +++ b/src/user/BUILD.bazel @@ -0,0 +1,156 @@ +load("@mujoco//tools:def.bzl", "mj_cc_library") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +mj_cc_library( + name = "user_flexcomp", + srcs = ["user_flexcomp.cc"], + hdrs = ["user_flexcomp.h"], + copts = [ + "-Wno-error=unknown-pragmas", + "-Wno-type-limits", + "-fexceptions", + "-Isrc", + ], + features = ["-use_header_modules"], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":user_model", + ":user_util", + "//:mujoco_hdrs", + "//src/cc:array_safety", + "//src/engine:engine_crossplatform", + "//src/engine:engine_util_errmem", + "//src/user:user_resource", + ], +) + +mj_cc_library( + name = "user_composite", + srcs = ["user_composite.cc"], + hdrs = ["user_composite.h"], + copts = [ + "-Wno-error=unknown-pragmas", + "-fexceptions", + "-Isrc", + ], + features = ["-use_header_modules"], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":user_model", + ":user_util", + "//:mujoco_hdrs", + "//src/cc:array_safety", + "//src/engine:engine_io", + "//src/engine:engine_util_errmem", + "//src/engine:engine_util_misc", + ], +) + +mj_cc_library( + name = "user_model", + srcs = [ + "user_api.cc", + "user_init.c", + "user_mesh.cc", + "user_model.cc", + "user_objects.cc", + ], + hdrs = [ + "user_api.h", + "user_model.h", + "user_objects.h", + ], + copts = [ + "-Wno-error=unknown-pragmas", + "-fexceptions", + "-Isrc", + "-Iexternal/qhull/src/libqhull_r", + ], + features = ["-use_header_modules"], + local_defines = [ + "_GNU_SOURCE", + "MUJOCO_TINYOBJLOADER_IMPL", + "MC_IMPLEM_ENABLE", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":user_cache", + ":user_resource", + ":user_util", + "//:mujoco_hdrs", + "//src/cc:array_safety", + "//src/engine", + "//src/engine:engine_crossplatform", + "//src/engine:engine_io", + "//src/engine:engine_name", + "//src/engine:engine_plugin", + "//src/engine:engine_util_errmem", + "//src/engine:engine_util_misc", + "@MarchingCubeCpp", + "@lodepng", + "@qhull//:libqhull_r", + "@tinyobjloader", + ], +) + +mj_cc_library( + name = "user_util", + srcs = ["user_util.cc"], + hdrs = ["user_util.h"], + copts = [ + "-Isrc", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + "//:mujoco_hdrs", + "//src/engine:engine_crossplatform", + ], +) + +mj_cc_library( + name = "user_cache", + srcs = ["user_cache.cc"], + hdrs = ["user_cache.h"], + copts = [ + "-Isrc", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":user_resource", + "//:mujoco_hdrs", + ], +) + +mj_cc_library( + name = "user_resource", + srcs = ["user_resource.cc"], + hdrs = ["user_resource.h"], + copts = [ + "-Wshadow", + "-Isrc", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":user_util", + ":user_vfs", + "//:mujoco_hdrs", + "//src/engine:engine_plugin", + "//src/engine:engine_util_misc", + ], +) + +mj_cc_library( + name = "user_vfs", + srcs = ["user_vfs.cc"], + hdrs = ["user_vfs.h"], + copts = [ + "-Isrc", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":user_util", + "//:mujoco_hdrs", + "//src/engine:engine_util_misc", + ], +) diff --git a/src/xml/BUILD.bazel b/src/xml/BUILD.bazel new file mode 100644 index 0000000000..0da269c3f8 --- /dev/null +++ b/src/xml/BUILD.bazel @@ -0,0 +1,175 @@ +load("@mujoco//tools:def.bzl", "mj_cc_library") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +exports_files(["xml_native_reader.cc"]) + +mj_cc_library( + name = "xml", + srcs = ["xml.cc"], + hdrs = ["xml.h"], + copts = [ + "-fexceptions", + "-Isrc", + ], + features = ["-use_header_modules"], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":xml_native_reader", + ":xml_native_writer", + ":xml_urdf", + ":xml_util", + "//:mujoco_hdrs", + "//src/cc:array_safety", + "//src/engine:engine_crossplatform", + "//src/user:user_resource", + "//src/user:user_util", + "//src/user:user_vfs", + "@tinyxml2", + ], +) + +mj_cc_library( + name = "xml_api", + srcs = ["xml_api.cc"], + hdrs = ["xml_api.h"], + copts = [ + "-Isrc", + ], + features = ["-use_header_modules"], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":xml", + ":xml_native_reader", + ":xml_util", + "//:mujoco_hdrs", + "//src/engine:engine_io", + "//src/user:user_resource", + "//src/user:user_vfs", + ], +) + +mj_cc_library( + name = "xml_base", + srcs = ["xml_base.cc"], + hdrs = ["xml_base.h"], + copts = [ + "-fexceptions", + "-Isrc", + ], + features = ["-use_header_modules"], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":xml_util", + "//:mujoco_hdrs", + "@tinyxml2", + ], +) + +mj_cc_library( + name = "xml_native_reader", + srcs = ["xml_native_reader.cc"], + hdrs = ["xml_native_reader.h"], + copts = [ + "-Wno-error=unknown-pragmas", + "-fexceptions", + "-Isrc", + ], + features = ["-use_header_modules"], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":xml_base", + ":xml_util", + "//:mujoco_hdrs", + "//src/engine:engine_plugin", + "//src/engine:engine_util_errmem", + "//src/engine:engine_util_misc", + "//src/user:user_composite", + "//src/user:user_flexcomp", + "//src/user:user_model", + "//src/user:user_util", + "@tinyxml2", + ], +) + +mj_cc_library( + name = "xml_native_writer", + srcs = ["xml_native_writer.cc"], + hdrs = ["xml_native_writer.h"], + copts = [ + "-Wno-error=unknown-pragmas", + "-fexceptions", + "-Isrc", + ], + features = ["-use_header_modules"], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":xml_base", + ":xml_util", + "//:mujoco_hdrs", + "//src/engine:engine_io", + "//src/engine:engine_plugin", + "//src/engine:engine_util_errmem", + "//src/engine:engine_util_misc", + "//src/user:user_model", + "//src/user:user_util", + "@tinyxml2", + ], +) + +mj_cc_library( + name = "xml_urdf", + srcs = ["xml_urdf.cc"], + hdrs = ["xml_urdf.h"], + copts = [ + "-fexceptions", + "-Isrc", + ], + features = ["-use_header_modules"], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":xml_base", + ":xml_native_reader", + ":xml_util", + "//:mujoco_hdrs", + "//src/user:user_model", + "//src/user:user_util", + "@tinyxml2", + ], +) + +mj_cc_library( + name = "xml_util", + srcs = ["xml_util.cc"], + hdrs = ["xml_util.h"], + copts = [ + "-Wno-error=unknown-pragmas", + "-fexceptions", + "-Isrc", + ], + features = ["-use_header_modules"], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + ":xml_numeric_format", + "//:mujoco_hdrs", + "//src/cc:array_safety", + "//src/engine:engine_util_errmem", + "//src/user:user_resource", + "//src/user:user_util", + "@tinyxml2", + ], +) + +mj_cc_library( + name = "xml_numeric_format", + srcs = ["xml_numeric_format.cc"], + hdrs = ["xml_numeric_format.h"], + copts = [ + "-Isrc", + ], + target_compatible_with = ["@platforms//os:linux"], + deps = [ + "//:mujoco_hdrs", + "@tinyxml2", + ], +) diff --git a/test/BUILD.bazel b/test/BUILD.bazel new file mode 100644 index 0000000000..aca9c970b0 --- /dev/null +++ b/test/BUILD.bazel @@ -0,0 +1,64 @@ +package(default_visibility = ["@mujoco//test:__subpackages__"]) + +cc_library( + name = "fixture", + testonly = True, + srcs = ["fixture.cc"], + hdrs = ["fixture.h"], + implementation_deps = [ + "//:mujoco", + ], + deps = [ + "//:mujoco_hdrs", + "//plugin/actuator:register", + "//plugin/elasticity:register", + "//plugin/sdf:register", + "//plugin/sensor:touch_grid", + "@abseil-cpp//absl/base:core_headers", + "@abseil-cpp//absl/container:flat_hash_map", + "@abseil-cpp//absl/container:flat_hash_set", + "@abseil-cpp//absl/strings", + "@abseil-cpp//absl/synchronization", + "@googletest//:gtest", + "@spdlog", + ], +) + +cc_test( + name = "fixture_test", + size = "small", + srcs = ["fixture_test.cc"], + deps = [ + ":fixture", + "//:mujoco", + "@googletest//:gtest_main", + ], + linkstatic=True, +) + +cc_test( + name = "header_test", + size = "small", + srcs = ["header_test.cc"], + deps = [ + ":fixture", + "//:mujoco", + "@googletest//:gtest_main", + ], + linkstatic=True, +) + +cc_test( + name = "pipeline_test", + size = "small", + srcs = ["pipeline_test.cc"], + data = [ + "//:test_data_stripped", + ], + deps = [ + ":fixture", + "//:mujoco", + "@googletest//:gtest_main", + ], + linkstatic=True, +) diff --git a/test/benchmark/BUILD.bazel b/test/benchmark/BUILD.bazel new file mode 100644 index 0000000000..a1d284445b --- /dev/null +++ b/test/benchmark/BUILD.bazel @@ -0,0 +1,39 @@ +names = [ + "step_benchmark_test", + "parse_benchmark_test", + "engine_util_spatial_benchmark_test", + "engine_core_smooth_benchmark_test", + "engine_util_sparse_benchmark_test", + "ccd_benchmark_test", + "factorI_benchmark_test", + "inertia_benchmark_test", + "solveLD_benchmark_test", + "thread_performance_test", +] + +[ + cc_test( + name = name, + srcs = ["{}.cc".format(name)], + data = [ + "//:model_data", + "//:test_benchmark_data", + "//:test_benchmark_data_stripped", + "//:test_plugin_data", + ], + tags = ["manual"], + deps = [ + "//plugin/elasticity:register", + "//test:fixture", + "@abseil-cpp//absl/base:core_headers", + "@google_benchmark//:benchmark_main", + ], + ) + for name in names +] + +test_suite( + name = "benchmark_tests", + tags = ["manual"], + tests = [name for name in names], +) diff --git a/test/benchmark/ccd_benchmark_test.cc b/test/benchmark/ccd_benchmark_test.cc index aaf093597b..5c46475741 100644 --- a/test/benchmark/ccd_benchmark_test.cc +++ b/test/benchmark/ccd_benchmark_test.cc @@ -19,7 +19,7 @@ #include #include -#include +#include "absl/base/attributes.h" #include #include #include "test/fixture.h" diff --git a/test/benchmark/testdata/BUILD.bazel b/test/benchmark/testdata/BUILD.bazel new file mode 100644 index 0000000000..dce14c2cf1 --- /dev/null +++ b/test/benchmark/testdata/BUILD.bazel @@ -0,0 +1,6 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +filegroup( + name = "model", + srcs = glob(["*.xml"]), +) diff --git a/test/engine/BUILD.bazel b/test/engine/BUILD.bazel new file mode 100644 index 0000000000..51d5a56937 --- /dev/null +++ b/test/engine/BUILD.bazel @@ -0,0 +1,64 @@ +load("//test:helper.bzl", "PLUGIN_DIR") + +cc_test( + name = "engine_test", + size = "small", + srcs = [ + "engine_collision_box_test.cc", + "engine_collision_convex_test.cc", + "engine_collision_driver_test.cc", + "engine_collision_gjk_test.cc", + "engine_collision_sdf_test.cc", + "engine_core_constraint_test.cc", + "engine_core_smooth_test.cc", + "engine_derivative_test.cc", + "engine_forward_test.cc", + "engine_inverse_test.cc", + "engine_io_test.cc", + "engine_island_test.cc", + "engine_passive_test.cc", + "engine_plugin_test.cc", + "engine_print_test.cc", + "engine_ray_test.cc", + "engine_sensor_test.cc", + "engine_solver_test.cc", + "engine_sort_test.cc", + "engine_support_test.cc", + "engine_thread_test.cc", + "engine_util_blas_test.cc", + "engine_util_container_test.cc", + "engine_util_errmem_test.cc", + "engine_util_misc_test.cc", + "engine_util_solve_test.cc", + "engine_util_sparse_test.cc", + "engine_util_spatial_test.cc", + "engine_vis_state_test.cc", + "engine_vis_visualize_test.cc", + ], + copts = [ + "-Wno-dangling-else", + "-Wno-unknown-pragmas", + "-Wno-unused-function", + "-Wno-sign-compare", + "-Isrc", + ] + select({ + "//tools:gcc": [ + "-Wno-maybe-uninitialized", + ], + "//conditions:default": [], + }), + data = [ + "//:model_data", + "//:test_data_stripped", + "//:test_engine_data_stripped", + ], + env = PLUGIN_DIR, + deps = [ + "//:mujoco", + "//src/engine:engine_util_container", + "//src/engine:engine_util_sparse", + "//test:fixture", + "@googletest//:gtest_main", + ], + linkstatic=True, +) diff --git a/test/engine/testdata/BUILD.bazel b/test/engine/testdata/BUILD.bazel new file mode 100644 index 0000000000..0da22a1f22 --- /dev/null +++ b/test/engine/testdata/BUILD.bazel @@ -0,0 +1,9 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +filegroup( + name = "model", + srcs = glob([ + "**/*.xml", + "**/*.obj", + ]), +) diff --git a/test/fixture.cc b/test/fixture.cc index 545691b495..82d8427002 100644 --- a/test/fixture.cc +++ b/test/fixture.cc @@ -80,7 +80,13 @@ const std::string GetTestDataFilePath(std::string_view path) { // NOLINT } const std::string GetModelPath(std::string_view path) { // NOLINT - return absl::StrCat("../model/", path); + // Bazel can only create symlinks for files under the `TEST_NAME.runfiles/mujoco` directory. + const char* bazel_env = std::getenv("BAZEL_TEST"); + if (bazel_env != nullptr) { + return absl::StrCat("model/", path); + } else { + return absl::StrCat("../model/", path); + } } mjModel* LoadModelFromString(std::string_view xml, char* error, diff --git a/test/helper.bzl b/test/helper.bzl new file mode 100644 index 0000000000..48e41cde74 --- /dev/null +++ b/test/helper.bzl @@ -0,0 +1,3 @@ +PLUGIN_DIR = { + "MUJOCO_PLUGIN_DIR": "mujoco_plugin", +} diff --git a/test/plugin/actuator/BUILD.bazel b/test/plugin/actuator/BUILD.bazel new file mode 100644 index 0000000000..b86ef60ba0 --- /dev/null +++ b/test/plugin/actuator/BUILD.bazel @@ -0,0 +1,16 @@ +load("//test:helper.bzl", "PLUGIN_DIR") + +cc_test( + name = "pid_test", + size = "small", + srcs = ["pid_test.cc"], + env = PLUGIN_DIR, + deps = [ + "//test:fixture", + "@abseil-cpp//absl/cleanup", + "@abseil-cpp//absl/strings", + "@abseil-cpp//absl/strings:string_view", + "@googletest//:gtest_main", + ], + linkstatic=True, +) diff --git a/test/plugin/elasticity/BUILD.bazel b/test/plugin/elasticity/BUILD.bazel new file mode 100644 index 0000000000..b38d0947d8 --- /dev/null +++ b/test/plugin/elasticity/BUILD.bazel @@ -0,0 +1,21 @@ +load("//test:helper.bzl", "PLUGIN_DIR") + +cc_test( + name = "elasticity_test", + size = "small", + srcs = ["elasticity_test.cc"], + copts = [ + "-Wno-sign-compare", + ], + env = PLUGIN_DIR, + deps = [ + "//plugin/elasticity:register", + "//plugin/elasticity:shell", + "//test:fixture", + "@abseil-cpp//absl/cleanup", + "@abseil-cpp//absl/strings", + "@abseil-cpp//absl/strings:string_view", + "@googletest//:gtest_main", + ], + linkstatic=True, +) diff --git a/test/plugin/sensor/BUILD.bazel b/test/plugin/sensor/BUILD.bazel new file mode 100644 index 0000000000..7e41fa43c9 --- /dev/null +++ b/test/plugin/sensor/BUILD.bazel @@ -0,0 +1,14 @@ +cc_test( + name = "sensor_test", + size = "small", + srcs = ["sensor_test.cc"], + data = [ + "//:test_plugin_data", + ], + deps = [ + "//plugin/sensor:touch_grid", + "//test:fixture", + "@googletest//:gtest_main", + ], + linkstatic=True, +) diff --git a/test/plugin/sensor/testdata/BUILD.bazel b/test/plugin/sensor/testdata/BUILD.bazel new file mode 100644 index 0000000000..dce14c2cf1 --- /dev/null +++ b/test/plugin/sensor/testdata/BUILD.bazel @@ -0,0 +1,6 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +filegroup( + name = "model", + srcs = glob(["*.xml"]), +) diff --git a/test/testdata/BUILD.bazel b/test/testdata/BUILD.bazel new file mode 100644 index 0000000000..dce14c2cf1 --- /dev/null +++ b/test/testdata/BUILD.bazel @@ -0,0 +1,6 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +filegroup( + name = "model", + srcs = glob(["*.xml"]), +) diff --git a/test/thread/BUILD.bazel b/test/thread/BUILD.bazel new file mode 100644 index 0000000000..2dbb6ab54e --- /dev/null +++ b/test/thread/BUILD.bazel @@ -0,0 +1,18 @@ +cc_test( + name = "thread_test", + size = "small", + srcs = [ + "thread_pool_test.cc", + "thread_queue_test.cc", + ], + copts = [ + "-Wno-sign-compare", + ], + deps = [ + "//:mujoco", + "//src/engine:engine_util_container", + "//test:fixture", + "@googletest//:gtest_main", + ], + linkstatic=True, +) diff --git a/test/user/BUILD.bazel b/test/user/BUILD.bazel new file mode 100644 index 0000000000..314bdb6186 --- /dev/null +++ b/test/user/BUILD.bazel @@ -0,0 +1,43 @@ +load("//test:helper.bzl", "PLUGIN_DIR") + +cc_test( + name = "user_test", + size = "large", # user_api_test.cc takes a long time + srcs = [ + "user_api_test.cc", + "user_cache_test.cc", + "user_composite_test.cc", + "user_flex_test.cc", + "user_model_test.cc", + "user_objects_test.cc", + "user_resource_test.cc", + "user_util_test.cc", + "user_vfs_test.cc", + ], + copts = [ + "-Wno-sign-compare", + "-Wno-write-strings", + ] + select({ + "//tools:gcc": [ + "-Wno-maybe-uninitialized", + ], + "//conditions:default": [], + }), + data = [ + "//:model_data", + "//:test_engine_data_stripped", + "//:test_user_data", + ], + env = PLUGIN_DIR, + deps = [ + "//:mujoco", + "//src/user:user_cache", + "//src/user:user_resource", + "//src/user:user_util", + "//src/user:user_vfs", + "//src/cc:array_safety", + "//test:fixture", + "@googletest//:gtest_main", + ], + linkstatic=True, +) diff --git a/test/user/testdata/BUILD.bazel b/test/user/testdata/BUILD.bazel new file mode 100644 index 0000000000..6ac1c13d43 --- /dev/null +++ b/test/user/testdata/BUILD.bazel @@ -0,0 +1,12 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +filegroup( + name = "model", + srcs = glob([ + "**/*.xml", + "**/*.obj", + "**/*.stl", + "**/*.msh", + "**/*.png", + ]), +) diff --git a/test/user/user_cache_test.cc b/test/user/user_cache_test.cc index f226827bd1..80727e128c 100644 --- a/test/user/user_cache_test.cc +++ b/test/user/user_cache_test.cc @@ -38,9 +38,9 @@ using CacheTest = MujocoTest; namespace { constexpr int kMaxSize = 100; // in bytes -constexpr std::string kText = "Hello World"; -constexpr std::string kModel = "myModel"; -constexpr std::string kFile = "hello.txt"; +const std::string kText = "Hello World"; +const std::string kModel = "myModel"; +const std::string kFile = "hello.txt"; void CacheText(mjCCache& cache, const std::string& model, const std::string& name, const std::string& text) { diff --git a/test/user/user_util_test.cc b/test/user/user_util_test.cc index 9873c74ba7..a5b92a64a8 100644 --- a/test/user/user_util_test.cc +++ b/test/user/user_util_test.cc @@ -147,7 +147,7 @@ TEST_F(UserUtilTest, StringToVectorInt) { } TEST_F(UserUtilTest, StringToVectorString) { - auto v = StringToVector(" abc def "); + auto v = StringToVector(std::string(" abc def ")); EXPECT_THAT(v, ElementsAre("abc", "def")); } diff --git a/test/xml/BUILD.bazel b/test/xml/BUILD.bazel new file mode 100644 index 0000000000..cd7a29076d --- /dev/null +++ b/test/xml/BUILD.bazel @@ -0,0 +1,38 @@ +load("//test:helper.bzl", "PLUGIN_DIR") + +cc_test( + name = "xml_test", + size = "medium", # xml_native_writer_test.cc takes a long time. + srcs = [ + "xml_api_test.cc", + "xml_native_reader_test.cc", + "xml_native_writer_test.cc", + "xml_schema_test.cc", + "xml_urdf_test.cc", + ], + copts = [ + "-Wno-unknown-pragmas", + "-Wno-sign-compare", + "-Isrc", + ] + select({ + "//tools:gcc": [ + "-Wno-maybe-uninitialized", + ], + "//conditions:default": [], + }), + data = [ + "//:model_data", + "//:test_xml_data", + ], + env = PLUGIN_DIR, + deps = [ + "//src/xml:xml_api", + "//src/xml:xml_native_reader", + "//src/xml:xml_util", + "//test:fixture", + "@abseil-cpp//absl/strings", + "@abseil-cpp//absl/strings:str_format", + "@googletest//:gtest_main", + ], + linkstatic=True, +) diff --git a/test/xml/testdata/BUILD.bazel b/test/xml/testdata/BUILD.bazel new file mode 100644 index 0000000000..8c53198ba5 --- /dev/null +++ b/test/xml/testdata/BUILD.bazel @@ -0,0 +1,6 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +filegroup( + name = "model", + srcs = glob(["**/*.xml"]), +) diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel new file mode 100644 index 0000000000..3680e805c2 --- /dev/null +++ b/tools/BUILD.bazel @@ -0,0 +1,34 @@ +constraint_setting( + name = "compiler", + default_constraint_value = "clang", +) + +constraint_value( + name = "clang", + constraint_setting = ":compiler", + visibility = ["//visibility:public"], +) + +constraint_value( + name = "gcc", + constraint_setting = ":compiler", + visibility = ["//visibility:public"], +) + +platform( + name = "linux_clang_x86_64", + constraint_values = [ + ":clang", + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], +) + +platform( + name = "linux_gcc_x86_64", + constraint_values = [ + ":gcc", + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], +) diff --git a/tools/def.bzl b/tools/def.bzl new file mode 100644 index 0000000000..ee18238bf7 --- /dev/null +++ b/tools/def.bzl @@ -0,0 +1,51 @@ +def _append(a, b): + if b == None: + return a + else: + return a + b + +def _get_default_copts(): + return [ + "-fvisibility=hidden", + "-Werror", + "-Wall", + "-Wpedantic", + "-Wimplicit-fallthrough", + "-Wunused", + "-Wvla", + "-Wno-int-in-bool-context", + "-Wno-sign-compare", + "-Wno-unknown-pragmas", + ] + select({ + "//tools:gcc": [ + "-Wno-maybe-uninitialized", + ], + "//tools:clang": [ + "-Wno-unused-but-set-variable", + ], + "//conditions:default": [], + }) + +def _get_default_defines(): + return [] + +def _get_default_deps(): + return [] + +def _get_default_linkopts(): + return [ + "-Wl,--gc-sections", + ] + + +def mj_cc_library(name, deps = None, srcs = None, hdrs = None, copts = None, defines = None, linkopts = None, **kwargs): + native.cc_library( + name = name, + deps = _append(_get_default_deps(), deps), + srcs = srcs, + hdrs = hdrs, + copts = _append(_get_default_copts(), copts), + defines = _append(_get_default_defines(), defines), + linkopts = _append(_get_default_linkopts(), linkopts), + **kwargs + ) diff --git a/tools/symlink_files.bzl b/tools/symlink_files.bzl new file mode 100644 index 0000000000..a4fc380764 --- /dev/null +++ b/tools/symlink_files.bzl @@ -0,0 +1,36 @@ +load("@aspect_bazel_lib//lib:paths.bzl", "to_repository_relative_path") + +_symlink_files_attrs = { + "srcs": attr.label_list( + allow_files = True, + doc = "A list of input files for which symbolic links will be created.", + ), + "strip_prefix": attr.string( + doc = """This pecifies a prefix that, if matched at the beginning of each file’s path, will + be stripped from the file path.""", + ), +} + +def _symlink_files_impl(ctx): + outputs = [] + for src in ctx.files.srcs: + workspace_relpath = to_repository_relative_path(src) + if workspace_relpath.startswith(ctx.attr.strip_prefix): + workspace_relpath = workspace_relpath[len(ctx.attr.strip_prefix):] + link = ctx.actions.declare_file(workspace_relpath) + ctx.actions.symlink(output = link, target_file = src) + outputs.append(link) + + return [ + DefaultInfo( + files = depset(outputs), + runfiles = ctx.runfiles(outputs), + ), + ] + +symlink_files = rule( + doc = "Symlink files to the output directory.", + implementation = _symlink_files_impl, + attrs = _symlink_files_attrs, + provides = [DefaultInfo], +) diff --git a/tools/workspace/BUILD.bazel b/tools/workspace/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/MarchingCubeCpp/BUILD.bazel b/tools/workspace/MarchingCubeCpp/BUILD.bazel new file mode 100644 index 0000000000..8ef196cd85 --- /dev/null +++ b/tools/workspace/MarchingCubeCpp/BUILD.bazel @@ -0,0 +1 @@ +exports_files(["LICENSE"]) diff --git a/tools/workspace/MarchingCubeCpp/LICENSE b/tools/workspace/MarchingCubeCpp/LICENSE new file mode 100644 index 0000000000..f957d8f6b2 --- /dev/null +++ b/tools/workspace/MarchingCubeCpp/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020 Axel Paris + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/tools/workspace/MarchingCubeCpp/package.BUILD.bazel b/tools/workspace/MarchingCubeCpp/package.BUILD.bazel new file mode 100644 index 0000000000..3d2bd3e50d --- /dev/null +++ b/tools/workspace/MarchingCubeCpp/package.BUILD.bazel @@ -0,0 +1,19 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +cc_library( + name = "MarchingCubeCpp", + hdrs = ["MC.h"], + includes = ["."], + data = [":license_filegroup"], +) + +filegroup( + name = "license_filegroup", + srcs = [ + # The MarchingCubeCpp repository is MIT-licensed but does not provide an official LICENSE + # file. Therefore, we include the `LICENSE` file here in the MuJoCo repository and + # reference it accordingly. See https://github.com/aparis69/MarchingCubeCpp#licence. + "@mujoco//tools/workspace/MarchingCubeCpp:LICENSE", + ], + tags = ["license_filegroup"], +) diff --git a/tools/workspace/MarchingCubeCpp/repository.bzl b/tools/workspace/MarchingCubeCpp/repository.bzl new file mode 100644 index 0000000000..e39720a65e --- /dev/null +++ b/tools/workspace/MarchingCubeCpp/repository.bzl @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def MarchingCubeCpp_repository(name = "MarchingCubeCpp"): + commit = "f03a1b3ec29b1d7d865691ca8aea4f1eb2c2873d" + http_archive( + name = name, + sha256 = "227c10b2cffe886454b92a0e9ef9f0c9e8e001d00ea156cc37c8fc43055c9ca6", + strip_prefix = "MarchingCubeCpp-{}".format(commit), + build_file = "@mujoco//tools/workspace/MarchingCubeCpp:package.BUILD.bazel", + url = "https://github.com/aparis69/MarchingCubeCpp/archive/{}.tar.gz".format(commit), + ) diff --git a/tools/workspace/SdfLib/BUILD.bazel b/tools/workspace/SdfLib/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/SdfLib/package.BUILD.bazel b/tools/workspace/SdfLib/package.BUILD.bazel new file mode 100644 index 0000000000..cb62b7b6bc --- /dev/null +++ b/tools/workspace/SdfLib/package.BUILD.bazel @@ -0,0 +1,42 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +cc_library( + name = "SdfLib", + srcs = glob([ + "src/sdf/*.cpp", + "src/utils/*.cpp", + ]), + hdrs = glob([ + "src/sdf/*.h", + "include/SdfLib/*.h", + "include/SdfLib/utils/*.h", + "libs/InteractiveComputerGraphics/InteractiveComputerGraphics/TriangleMeshDistance.h", + ]), + deps = [ + "@glm", + "@cereal", + "@spdlog", + ], + includes = [ + "include", + "libs/InteractiveComputerGraphics", + "src", + ], + copts = [ + "-Wno-error=switch", + "-Wno-switch", + "-Wno-sign-compare", + "-Wno-unused-variable", + "-Wno-unused-lambda-capture", + "-Wno-pessimizing-move", + ], + data = [":license_filegroup"], +) + +filegroup( + name = "license_filegroup", + srcs = [ + "LICENSE", + ], + tags = ["license_filegroup"], +) diff --git a/tools/workspace/SdfLib/repository.bzl b/tools/workspace/SdfLib/repository.bzl new file mode 100644 index 0000000000..aa244ad535 --- /dev/null +++ b/tools/workspace/SdfLib/repository.bzl @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def SdfLib_repository(name = "SdfLib"): + commit = "1927bee6bb8225258a39c8cbf14e18a4d50409ae" + http_archive( + name = name, + sha256 = "ff6081954d05041f5f583be69dfc9749a71030d8da64b4b9a7576350911b806a", + strip_prefix = "SdfLib-{}".format(commit), + build_file = "@mujoco//tools/workspace/SdfLib:package.BUILD.bazel", + url = "https://github.com/UPC-ViRVIG/SdfLib/archive/{}.tar.gz".format(commit), + ) diff --git a/tools/workspace/abseil-cpp/BUILD.bazel b/tools/workspace/abseil-cpp/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/abseil-cpp/repository.bzl b/tools/workspace/abseil-cpp/repository.bzl new file mode 100644 index 0000000000..25afc57e00 --- /dev/null +++ b/tools/workspace/abseil-cpp/repository.bzl @@ -0,0 +1,10 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def abseil_cpp_repository(name = "abseil-cpp"): + version = "20240722.0" + http_archive( + name = name, + sha256 = "f50e5ac311a81382da7fa75b97310e4b9006474f9560ac46f54a9967f07d4ae3", + strip_prefix = "abseil-cpp-{}".format(version), + url = "https://github.com/abseil/abseil-cpp/releases/download/{}/abseil-cpp-{}.tar.gz".format(version, version), + ) diff --git a/tools/workspace/aspect_bazel_lib/BUILD.bazel b/tools/workspace/aspect_bazel_lib/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/aspect_bazel_lib/repository.bzl b/tools/workspace/aspect_bazel_lib/repository.bzl new file mode 100644 index 0000000000..d46b8092f1 --- /dev/null +++ b/tools/workspace/aspect_bazel_lib/repository.bzl @@ -0,0 +1,10 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def aspect_bazel_lib_repository(name = "aspect_bazel_lib"): + version = "2.9.3" + http_archive( + name = name, + sha256 = "a272d79bb0ac6b6965aa199b1f84333413452e87f043b53eca7f347a23a478e8", + strip_prefix = "bazel-lib-{}".format(version), + url = "https://github.com/bazel-contrib/bazel-lib/releases/download/v{}/bazel-lib-v{}.tar.gz".format(version, version), + ) diff --git a/tools/workspace/cereal/BUILD.bazel b/tools/workspace/cereal/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/cereal/package.BUILD.bazel b/tools/workspace/cereal/package.BUILD.bazel new file mode 100644 index 0000000000..cce20c8ff6 --- /dev/null +++ b/tools/workspace/cereal/package.BUILD.bazel @@ -0,0 +1,23 @@ +package(default_visibility = [ + "@mujoco//:__subpackages__", + "@SdfLib//:__subpackages__", +]) + +cc_library( + name = "cereal", + hdrs = glob([ + "include/**/*.hpp", + ]), + includes = [ + "include", + ], + data = [":license_filegroup"], +) + +filegroup( + name = "license_filegroup", + srcs = [ + "LICENSE", + ], + tags = ["license_filegroup"], +) diff --git a/tools/workspace/cereal/repository.bzl b/tools/workspace/cereal/repository.bzl new file mode 100644 index 0000000000..e4f9643f62 --- /dev/null +++ b/tools/workspace/cereal/repository.bzl @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def cereal_repository(name = "cereal"): + commit = "ebef1e929807629befafbb2918ea1a08c7194554" + http_archive( + name = name, + sha256 = "ce52ae6abcdbda5fecd63abbaa7ab57e54b814b24d7cb6f5096f5753d1975d24", + strip_prefix = "cereal-{}".format(commit), + build_file = "@mujoco//tools/workspace/cereal:package.BUILD.bazel", + url = "https://github.com/USCiLab/cereal/archive/{}.tar.gz".format(commit), + ) diff --git a/tools/workspace/deb_archive.bzl b/tools/workspace/deb_archive.bzl new file mode 100644 index 0000000000..627eb2306b --- /dev/null +++ b/tools/workspace/deb_archive.bzl @@ -0,0 +1,71 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "workspace_and_buildfile") + +def _deb_archive_impl(ctx): + for src in ctx.attr.srcs: + ctx.extract(src) + workspace_and_buildfile(ctx) + +deb_archive = repository_rule( + doc = """The deb_archive repository rule extracts .deb archive files, allowing to incorporate + files from Debian packages into your Bazel workspace.""", + implementation = _deb_archive_impl, + attrs = { + "srcs": attr.label_list( + mandatory = True, + allow_empty = False, + doc = "A list of .deb package files to extract.", + ), + "build_file": attr.label( + allow_single_file = True, + doc = """ A file containing BUILD definitions. This BUILD file will be placed in the + root of the extracted repository and allows you to define Bazel targets based on + the extracted contents.""", + ), + "build_file_content": attr.string( + doc = "Optional inline BUILD.bazel file content", + ), + "workspace_file": attr.label( + allow_single_file = True, + doc = """A file containing WORKSPACE definitions, which will be added to the + repository’s root.""", + ), + "workspace_file_content": attr.string( + doc = "Optional inline WORKSPACE file content", + ), + }, +) + +def deb_package(name, urls, sha256s, data_archives = [], **kwargs): + """ + This function downloads `.deb` file from the URLs, extracts the specified data archives, and + invokes the `deb_archive` rule to handle extraction and setup within Bazel workspace. + + Args: + name (string): The name of the Bazel target created for this package. + urls (list of strings): A list of URLs pointing to the .deb packages you want to download + and extract. Each URL should point directly to a downloadable .deb file. + sha256s (list of strings): A list of SHA-256 hashes corresponding to each URL in `urls`. + data_archives (list of string): Specifies the names of the data archive files within each + `.deb` package that you want to extract. + **kwargs: Additional arguments passed to the underlying deb_archive rule. + """ + if not data_archives: + data_archives = ["data.tar.zst"] * len(urls) + srcs = [] + for (url, sha256, data_archive) in zip(urls, sha256s, data_archives): + _, sep, ext = url.rpartition(".") + src_name = name + "_" + sha256 + http_archive( + name = src_name, + url = url, + sha256 = sha256, + build_file_content = """exports_files(["{}"])""".format(data_archive), + ) + srcs.append("@{}//:{}".format(src_name, data_archive)) + + deb_archive( + name = name, + srcs = srcs, + **kwargs + ) diff --git a/tools/workspace/default_dependencies.bzl b/tools/workspace/default_dependencies.bzl new file mode 100644 index 0000000000..d8b7d522cf --- /dev/null +++ b/tools/workspace/default_dependencies.bzl @@ -0,0 +1,8 @@ +load("@rules_python//python:repositories.bzl", "py_repositories") +load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies") + +def add_default_dependencies(excludes = []): + if "rules_python" not in excludes: + py_repositories() + if "aspect_bazel_lib" not in excludes: + aspect_bazel_lib_dependencies() diff --git a/tools/workspace/default_repositories.bzl b/tools/workspace/default_repositories.bzl new file mode 100644 index 0000000000..3a4134f204 --- /dev/null +++ b/tools/workspace/default_repositories.bzl @@ -0,0 +1,62 @@ +load("@mujoco//tools/workspace/MarchingCubeCpp:repository.bzl", "MarchingCubeCpp_repository") +load("@mujoco//tools/workspace/cereal:repository.bzl", "cereal_repository") +load("@mujoco//tools/workspace/glm:repository.bzl", "glm_repository") +load("@mujoco//tools/workspace/libccd:repository.bzl", "libccd_repository") +load("@mujoco//tools/workspace/lodepng:repository.bzl", "lodepng_repository") +load("@mujoco//tools/workspace/SdfLib:repository.bzl", "SdfLib_repository") +load("@mujoco//tools/workspace/spdlog:repository.bzl", "spdlog_repository") +load("@mujoco//tools/workspace/tinyobjloader:repository.bzl", "tinyobjloader_repository") +load("@mujoco//tools/workspace/pybind11:repository.bzl", "pybind11_repository") +load("@mujoco//tools/workspace/rules_python:repository.bzl", "rules_python_repository") +load("@mujoco//tools/workspace/abseil-cpp:repository.bzl", "abseil_cpp_repository") +load("@mujoco//tools/workspace/qhull:repository.bzl", "qhull_repository") +load("@mujoco//tools/workspace/tinyxml2:repository.bzl", "tinyxml2_repository") +load("@mujoco//tools/workspace/libglvnd:repository.bzl", "libglvnd_repository") +load("@mujoco//tools/workspace/libglfw3:repository.bzl", "libglfw3_repository") +load("@mujoco//tools/workspace/googletest:repository.bzl", "googletest_repository") +load("@mujoco//tools/workspace/aspect_bazel_lib:repository.bzl", "aspect_bazel_lib_repository") +load("@mujoco//tools/workspace/google_benchmark:repository.bzl", "google_benchmark_repository") +load("@mujoco//tools/workspace/eigen:repository.bzl", "eigen_repository") +load("@mujoco//tools/workspace/fmt:repository.bzl", "fmt_repository") + +def add_default_repositories(excludes = []): + if "MarchingCubeCpp" not in excludes: + MarchingCubeCpp_repository(name = "MarchingCubeCpp") + if "cereal" not in excludes: + cereal_repository(name = "cereal") + if "glm" not in excludes: + glm_repository(name = "glm") + if "libccd" not in excludes: + libccd_repository(name = "libccd") + if "lodepng" not in excludes: + lodepng_repository(name = "lodepng") + if "SdfLib" not in excludes: + SdfLib_repository(name = "SdfLib") + if "spdlog" not in excludes: + spdlog_repository(name = "spdlog") + if "tinyobjloader" not in excludes: + tinyobjloader_repository(name = "tinyobjloader") + if "pybind11" not in excludes: + pybind11_repository(name = "pybind11") + if "rules_python" not in excludes: + rules_python_repository(name = "rules_python") + if "abseil-cpp" not in excludes: + abseil_cpp_repository(name = "abseil-cpp") + if "qhull" not in excludes: + qhull_repository(name = "qhull") + if "tinyxml2" not in excludes: + tinyxml2_repository(name = "tinyxml2") + if "libglvnd" not in excludes: + libglvnd_repository(name = "libglvnd") + if "libglfw3" not in excludes: + libglfw3_repository(name = "libglfw3") + if "googletest" not in excludes: + googletest_repository(name = "googletest") + if "aspect_bazel_lib" not in excludes: + aspect_bazel_lib_repository(name = "aspect_bazel_lib") + if "google_benchmark" not in excludes: + google_benchmark_repository(name = "google_benchmark") + if "eigen" not in excludes: + eigen_repository(name = "eigen") + if "fmt" not in excludes: + fmt_repository(name = "fmt") diff --git a/tools/workspace/eigen/BUILD.bazel b/tools/workspace/eigen/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/eigen/package.BUILD.bazel b/tools/workspace/eigen/package.BUILD.bazel new file mode 100644 index 0000000000..8261ecfc3d --- /dev/null +++ b/tools/workspace/eigen/package.BUILD.bazel @@ -0,0 +1,20 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "eigen", + hdrs = glob(["Eigen/**", "unsupported/Eigen/**"]), + includes = ["."], + data = [":license_filegroup"], +) + +filegroup( + name = "license_filegroup", + srcs = [ + "COPYING.APACHE", + "COPYING.BSD", + "COPYING.MINPACK", + "COPYING.MPL2", + "COPYING.README", + ], + tags = ["license_filegroup"], +) diff --git a/tools/workspace/eigen/repository.bzl b/tools/workspace/eigen/repository.bzl new file mode 100644 index 0000000000..e017caa528 --- /dev/null +++ b/tools/workspace/eigen/repository.bzl @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def eigen_repository(name = "eigen"): + commit = "33d0937c6bdf5ec999939fb17f2a553183d14a74" + http_archive( + name = name, + sha256 = "1a7c7d2e2052642acf78b32ef89dc5b6d12dcb8e552b66407c3e67d7f8e1d73e", + strip_prefix = "eigen-{}".format(commit), + build_file = "@mujoco//tools/workspace/eigen:package.BUILD.bazel", + url = "https://gitlab.com/libeigen/eigen/-/archive/{}/eigen-{}.tar.bz2".format(commit, commit), + ) diff --git a/tools/workspace/fmt/BUILD.bazel b/tools/workspace/fmt/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/fmt/package.BUILD b/tools/workspace/fmt/package.BUILD new file mode 100644 index 0000000000..5ea13b607c --- /dev/null +++ b/tools/workspace/fmt/package.BUILD @@ -0,0 +1,35 @@ +package(default_visibility = [ + "@mujoco//:__subpackages__", + "@spdlog//:__subpackages__", +]) + +cc_library( + name = "fmt", + srcs = [ + "src/format.cc", + "src/os.cc", + ], + hdrs = [ + "include/fmt/args.h", + "include/fmt/chrono.h", + "include/fmt/color.h", + "include/fmt/compile.h", + "include/fmt/core.h", + "include/fmt/format.h", + "include/fmt/format-inl.h", + "include/fmt/os.h", + "include/fmt/ostream.h", + "include/fmt/printf.h", + "include/fmt/ranges.h", + "include/fmt/std.h", + "include/fmt/xchar.h", + ], + data = [":license_filegroup"], + includes = ["include"], +) + +filegroup( + name = "license_filegroup", + srcs = ["LICENSE"], + tags = ["license_filegroup"], +) diff --git a/tools/workspace/fmt/repository.bzl b/tools/workspace/fmt/repository.bzl new file mode 100644 index 0000000000..67add95dc5 --- /dev/null +++ b/tools/workspace/fmt/repository.bzl @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def fmt_repository(name): + version = "10.2.1" + http_archive( + name = name, + strip_prefix = "fmt-{}".format(version), + sha256 = "1250e4cc58bf06ee631567523f48848dc4596133e163f02615c97f78bab6c811", + url = "https://github.com/fmtlib/fmt/archive/refs/tags/{}.tar.gz".format(version), + build_file = "@mujoco//tools/workspace/fmt:package.BUILD", + ) diff --git a/tools/workspace/glm/BUILD.bazel b/tools/workspace/glm/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/glm/package.BUILD.bazel b/tools/workspace/glm/package.BUILD.bazel new file mode 100644 index 0000000000..b60203cc23 --- /dev/null +++ b/tools/workspace/glm/package.BUILD.bazel @@ -0,0 +1,29 @@ +package(default_visibility = [ + "@mujoco//:__subpackages__", + "@SdfLib//:__subpackages__", +]) + +cc_library( + name = "glm", + hdrs = glob([ + "glm/*.hpp", + "glm/*.inl", + "glm/detail/*.hpp", + "glm/detail/*.inl", + "glm/gtc/*.hpp", + "glm/gtc/*.inl", + "glm/gtx/*.hpp", + "glm/gtx/*.inl", + "glm/simd/*.h", + ]), + data = [":license_filegroup"], + includes = ["."], +) + +filegroup( + name = "license_filegroup", + srcs = [ + "copying.txt", + ], + tags = ["license_filegroup"], +) diff --git a/tools/workspace/glm/repository.bzl b/tools/workspace/glm/repository.bzl new file mode 100644 index 0000000000..118cbaf8ee --- /dev/null +++ b/tools/workspace/glm/repository.bzl @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def glm_repository(name = "glm"): + commit = "454d480ceb4ac10ca76ac24b49836b7d5a35f786" + http_archive( + name = name, + sha256 = "ce6894e2bc38e5415a01827e23406776cd6d632c65e60fd2333b13621ab0ef43", + strip_prefix = "glm-{}".format(commit), + build_file = "@mujoco//tools/workspace/glm:package.BUILD.bazel", + url = "https://github.com/g-truc/glm/archive/{}.tar.gz".format(commit), + ) diff --git a/tools/workspace/google_benchmark/BUILD.bazel b/tools/workspace/google_benchmark/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/google_benchmark/repository.bzl b/tools/workspace/google_benchmark/repository.bzl new file mode 100644 index 0000000000..b131e8725d --- /dev/null +++ b/tools/workspace/google_benchmark/repository.bzl @@ -0,0 +1,10 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def google_benchmark_repository(name = "google_benchmark"): + version = "1.8.4" + http_archive( + name = name, + sha256 = "3e7059b6b11fb1bbe28e33e02519398ca94c1818874ebed18e504dc6f709be45", + strip_prefix = "benchmark-{}".format(version), + url = "https://github.com/google/benchmark/archive/refs/tags/v{}.tar.gz".format(version), + ) diff --git a/tools/workspace/googletest/BUILD.bazel b/tools/workspace/googletest/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/googletest/repository.bzl b/tools/workspace/googletest/repository.bzl new file mode 100644 index 0000000000..13af2c8ffc --- /dev/null +++ b/tools/workspace/googletest/repository.bzl @@ -0,0 +1,10 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def googletest_repository(name = "googletest"): + version = "1.15.2" + http_archive( + name = name, + sha256 = "7b42b4d6ed48810c5362c265a17faebe90dc2373c885e5216439d37927f02926", + strip_prefix = "googletest-{}".format(version), + url = "https://github.com/google/googletest/releases/download/v{}/googletest-{}.tar.gz".format(version, version), + ) diff --git a/tools/workspace/libccd/BUILD.bazel b/tools/workspace/libccd/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/libccd/package.BUILD.bazel b/tools/workspace/libccd/package.BUILD.bazel new file mode 100644 index 0000000000..5ff09b015f --- /dev/null +++ b/tools/workspace/libccd/package.BUILD.bazel @@ -0,0 +1,57 @@ +load("@bazel_skylib//rules:write_file.bzl", "write_file") + +package(default_visibility = ["@mujoco//:__subpackages__"]) + +write_file( + name = "config_h", + out = "src/ccd/config.h", + content = [""" +#ifndef __CCD_CONFIG_H__ +#define __CCD_CONFIG_H__ + +/* #undef CCD_SINGLE */ +#define CCD_DOUBLE + +#endif /* __CCD_CONFIG_H__ */ + """], +) + +cc_library( + name = "libccd", + srcs = [ + "src/alloc.h", + "src/ccd.c", + "src/dbg.h", + "src/list.h", + "src/mpr.c", + "src/polytope.c", + "src/polytope.h", + "src/simplex.h", + "src/support.c", + "src/support.h", + "src/vec3.c", + ], + hdrs = [ + "src/ccd/ccd.h", + "src/ccd/ccd_export.h", + "src/ccd/compiler.h", + "src/ccd/quat.h", + "src/ccd/vec3.h", + ":config_h", + ], + local_defines = [ + "CCD_STATIC_DEFINE", + ], + includes = [ + "src", + ], + data = [":license_filegroup"], +) + +filegroup( + name = "license_filegroup", + srcs = [ + "BSD-LICENSE", + ], + tags = ["license_filegroup"], +) diff --git a/tools/workspace/libccd/repository.bzl b/tools/workspace/libccd/repository.bzl new file mode 100644 index 0000000000..6833c63e7f --- /dev/null +++ b/tools/workspace/libccd/repository.bzl @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def libccd_repository(name = "libccd"): + commit = "7931e764a19ef6b21b443376c699bbc9c6d4fba8" + http_archive( + name = name, + sha256 = "479994a86d32e2effcaad64204142000ee6b6b291fd1859ac6710aee8d00a482", + strip_prefix = "libccd-{}".format(commit), + build_file = "@mujoco//tools/workspace/libccd:package.BUILD.bazel", + url = "https://github.com/danfis/libccd/archive/{}.tar.gz".format(commit), + ) diff --git a/tools/workspace/libglfw3/BUILD.bazel b/tools/workspace/libglfw3/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/libglfw3/package.BUILD.bazel b/tools/workspace/libglfw3/package.BUILD.bazel new file mode 100644 index 0000000000..474aa9356d --- /dev/null +++ b/tools/workspace/libglfw3/package.BUILD.bazel @@ -0,0 +1,24 @@ +cc_library( + name = "lib", + hdrs = glob(["usr/include/**/*.h*"]), + srcs = [], + includes = ["usr/include"], + deps = ["@libglvnd//:lib", ":libglfw.so-import", ":libglfw.so.3-import"], + data = [":license_filegroup"], + target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], + visibility = ["//visibility:public"], +) + +cc_import( + name = "libglfw.so-import", + shared_library = "usr/lib/x86_64-linux-gnu/libglfw.so", +) +cc_import( + name = "libglfw.so.3-import", + shared_library = "usr/lib/x86_64-linux-gnu/libglfw.so.3", +) +filegroup( + name = "license_filegroup", + tags = ["license_filegroup"], + srcs = glob(["usr/share/doc/*/copyright"]), +) diff --git a/tools/workspace/libglfw3/repository.bzl b/tools/workspace/libglfw3/repository.bzl new file mode 100644 index 0000000000..a5dbb83d31 --- /dev/null +++ b/tools/workspace/libglfw3/repository.bzl @@ -0,0 +1,19 @@ +load("@mujoco//tools/workspace:deb_archive.bzl", "deb_package") + +def libglfw3_repository(name = "libglfw3"): + deb_package( + name = name, + urls = [ + "http://mirrors.kernel.org/ubuntu/pool/universe/g/glfw3/libglfw3_3.3.6-1_amd64.deb", + "http://mirrors.kernel.org/ubuntu/pool/universe/g/glfw3/libglfw3-dev_3.3.6-1_amd64.deb", + ], + sha256s = [ + "a7fe08d4ded1c376e8b008fdeef220b8a0335258a05c542982424cdb43b61af3", + "2b2a68725a34dd69bcce045282806f1d1ffa6c43376aa1023058683f51a31b02", + ], + data_archives = [ + "data.tar.zst", + "data.tar.zst", + ], + build_file = "@mujoco//tools/workspace/libglfw3:package.BUILD.bazel", + ) diff --git a/tools/workspace/libglvnd/BUILD.bazel b/tools/workspace/libglvnd/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/libglvnd/package.BUILD.bazel b/tools/workspace/libglvnd/package.BUILD.bazel new file mode 100644 index 0000000000..25f6437ce8 --- /dev/null +++ b/tools/workspace/libglvnd/package.BUILD.bazel @@ -0,0 +1,16 @@ +cc_library( + name = "lib", + hdrs = glob(["usr/include/**/*.h*"]), + srcs = [], + includes = ["usr/include"], + deps = [], + data = [":license_filegroup"], + target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"], + visibility = ["//visibility:public"], +) + +filegroup( + name = "license_filegroup", + tags = ["license_filegroup"], + srcs = glob(["usr/share/doc/*/copyright"]), +) diff --git a/tools/workspace/libglvnd/repository.bzl b/tools/workspace/libglvnd/repository.bzl new file mode 100644 index 0000000000..ffa2aeb750 --- /dev/null +++ b/tools/workspace/libglvnd/repository.bzl @@ -0,0 +1,10 @@ +load("@mujoco//tools/workspace:deb_archive.bzl", "deb_package") + +def libglvnd_repository(name = "libglvnd"): + deb_package( + name = name, + urls = ["http://mirrors.kernel.org/ubuntu/pool/main/libg/libglvnd/libglvnd-dev_1.4.0-1_amd64.deb"], + sha256s = ["af38c9f0f7f65735d89094cb5bc32afa58012e4bd48bae995653c465dc110165"], + data_archives = ["data.tar.zst"], + build_file = "@mujoco//tools/workspace/libglvnd:package.BUILD.bazel", + ) diff --git a/tools/workspace/lodepng/BUILD.bazel b/tools/workspace/lodepng/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/lodepng/package.BUILD.bazel b/tools/workspace/lodepng/package.BUILD.bazel new file mode 100644 index 0000000000..4cc07356cf --- /dev/null +++ b/tools/workspace/lodepng/package.BUILD.bazel @@ -0,0 +1,19 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +filegroup( + name = "license_filegroup", + srcs = ["LICENSE"], + tags = ["license_filegroup"], +) + +cc_library( + name = "lodepng", + srcs = [ + "lodepng.cpp", + ], + hdrs = [ + "lodepng.h", + ], + data = [":license_filegroup"], + includes = ["."], +) diff --git a/tools/workspace/lodepng/repository.bzl b/tools/workspace/lodepng/repository.bzl new file mode 100644 index 0000000000..0e456c5e20 --- /dev/null +++ b/tools/workspace/lodepng/repository.bzl @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def lodepng_repository(name = "lodepng"): + commit = "b4ed2cd7ecf61d29076169b49199371456d4f90b" + http_archive( + name = name, + sha256 = "b67e466ba659c07ac775d07dbd97af319cde449ce14abed9ae596df29d888603", + strip_prefix = "lodepng-{}".format(commit), + build_file = "@mujoco//tools/workspace/lodepng:package.BUILD.bazel", + url = "https://github.com/lvandeve/lodepng/archive/{}.tar.gz".format(commit), + ) diff --git a/tools/workspace/pybind11/BUILD.bazel b/tools/workspace/pybind11/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/pybind11/package.BUILD.bazel b/tools/workspace/pybind11/package.BUILD.bazel new file mode 100644 index 0000000000..3f02423ad0 --- /dev/null +++ b/tools/workspace/pybind11/package.BUILD.bazel @@ -0,0 +1,15 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pybind11", + includes = ["include"], + hdrs = glob(["include/**/*.h"]), + data = [":license_filegroup"], + deps = ["@python_3_11//:python_headers"], +) + +filegroup( + name = "license_filegroup", + srcs = ["LICENSE"], + tags = ["license_filegroup"], +) diff --git a/tools/workspace/pybind11/repository.bzl b/tools/workspace/pybind11/repository.bzl new file mode 100644 index 0000000000..7a6f05bba1 --- /dev/null +++ b/tools/workspace/pybind11/repository.bzl @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def pybind11_repository(name = "pybind11"): + version = "2.13.5" + http_archive( + name = name, + build_file = "@mujoco//tools/workspace/pybind11:package.BUILD.bazel", + sha256 = "b1e209c42b3a9ed74da3e0b25a4f4cd478d89d5efbb48f04b277df427faf6252", + strip_prefix = "pybind11-{}".format(version), + url = "https://github.com/pybind/pybind11/archive/refs/tags/v{}.tar.gz".format(version), + ) diff --git a/tools/workspace/qhull/BUILD.bazel b/tools/workspace/qhull/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/qhull/package.BUILD.bazel b/tools/workspace/qhull/package.BUILD.bazel new file mode 100644 index 0000000000..5c7e8ced1e --- /dev/null +++ b/tools/workspace/qhull/package.BUILD.bazel @@ -0,0 +1,93 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +cc_library( + name = "libqhull", + srcs = [ + "src/libqhull/geom.c", + "src/libqhull/geom2.c", + "src/libqhull/global.c", + "src/libqhull/io.c", + "src/libqhull/libqhull.c", + "src/libqhull/mem.c", + "src/libqhull/merge.c", + "src/libqhull/poly.c", + "src/libqhull/poly2.c", + "src/libqhull/qset.c", + "src/libqhull/random.c", + "src/libqhull/rboxlib.c", + "src/libqhull/stat.c", + "src/libqhull/user.c", + "src/libqhull/usermem.c", + "src/libqhull/userprintf.c", + "src/libqhull/userprintf_rbox.c", + ], + hdrs = [ + "src/libqhull/geom.h", + "src/libqhull/io.h", + "src/libqhull/libqhull.h", + "src/libqhull/mem.h", + "src/libqhull/merge.h", + "src/libqhull/poly.h", + "src/libqhull/qhull_a.h", + "src/libqhull/qset.h", + "src/libqhull/random.h", + "src/libqhull/stat.h", + "src/libqhull/user.h", + ], + copts = select({ + "@mujoco//tools:clang": ["-Wno-unused-but-set-variable"], + "//conditions:default": [], + }), + data = [":license_filegroup"], + includes = ["src"], + linkopts = ["-lm"], +) + +cc_library( + name = "libqhull_r", + srcs = [ + "src/libqhull_r/geom2_r.c", + "src/libqhull_r/geom_r.c", + "src/libqhull_r/global_r.c", + "src/libqhull_r/io_r.c", + "src/libqhull_r/libqhull_r.c", + "src/libqhull_r/mem_r.c", + "src/libqhull_r/merge_r.c", + "src/libqhull_r/poly2_r.c", + "src/libqhull_r/poly_r.c", + "src/libqhull_r/qset_r.c", + "src/libqhull_r/random_r.c", + "src/libqhull_r/rboxlib_r.c", + "src/libqhull_r/stat_r.c", + "src/libqhull_r/user_r.c", + "src/libqhull_r/usermem_r.c", + "src/libqhull_r/userprintf_r.c", + "src/libqhull_r/userprintf_rbox_r.c", + ], + hdrs = [ + "src/libqhull_r/geom_r.h", + "src/libqhull_r/io_r.h", + "src/libqhull_r/libqhull_r.h", + "src/libqhull_r/mem_r.h", + "src/libqhull_r/merge_r.h", + "src/libqhull_r/poly_r.h", + "src/libqhull_r/qhull_ra.h", + "src/libqhull_r/qset_r.h", + "src/libqhull_r/random_r.h", + "src/libqhull_r/stat_r.h", + "src/libqhull_r/user_r.h", + ], + copts = select({ + "@mujoco//tools:clang": ["-Wno-unused-but-set-variable"], + "//conditions:default": [], + }), + data = [":license_filegroup"], + includes = ["src"], + linkopts = ["-lm"], +) + +filegroup( + name = "license_filegroup", + srcs = ["COPYING.txt"], + tags = ["license_filegroup"], +) diff --git a/tools/workspace/qhull/repository.bzl b/tools/workspace/qhull/repository.bzl new file mode 100644 index 0000000000..aa9a237cc4 --- /dev/null +++ b/tools/workspace/qhull/repository.bzl @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def qhull_repository(name = "qhull"): + commit = "0c8fc90d2037588024d9964515c1e684f6007ecc" + http_archive( + name = name, + sha256 = "227afadbfe4b934ef7da385dac0c7e7abf5d977fb3d4734b299e7b38a334a45a", + strip_prefix = "qhull-{}".format(commit), + build_file = "@mujoco//tools/workspace/qhull:package.BUILD.bazel", + url = "https://github.com/qhull/qhull/archive/{}.tar.gz".format(commit), + ) diff --git a/tools/workspace/rules_python/BUILD.bazel b/tools/workspace/rules_python/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/rules_python/repository.bzl b/tools/workspace/rules_python/repository.bzl new file mode 100644 index 0000000000..99d688210b --- /dev/null +++ b/tools/workspace/rules_python/repository.bzl @@ -0,0 +1,10 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def rules_python_repository(name = "rules_python"): + version = "0.37.0" + http_archive( + name = name, + sha256 = "0cc05ddb27614baecace068986931e2a6e9f69114e6115fc5dc58250faf56e0f", + strip_prefix = "rules_python-{}".format(version), + url = "https://github.com/bazelbuild/rules_python/releases/download/{}/rules_python-{}.tar.gz".format(version, version), + ) diff --git a/tools/workspace/spdlog/BUILD.bazel b/tools/workspace/spdlog/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/spdlog/package.BUILD.bazel b/tools/workspace/spdlog/package.BUILD.bazel new file mode 100644 index 0000000000..5bc2e40eac --- /dev/null +++ b/tools/workspace/spdlog/package.BUILD.bazel @@ -0,0 +1,32 @@ +package(default_visibility = [ + "@mujoco//:__subpackages__", + "@SdfLib//:__subpackages__", +]) + +cc_library( + name = "spdlog", + srcs = [ + "src/async.cpp", + "src/cfg.cpp", + "src/color_sinks.cpp", + "src/file_sinks.cpp", + "src/spdlog.cpp", + "src/stdout_sinks.cpp", + ], + hdrs = glob(["include/**/*.h"]), + data = [":license_filegroup"], + includes = ["include"], + deps = ["@fmt"], + local_defines = [ + "SPDLOG_COMPILED_LIB", + "SPDLOG_FMT_EXTERNAL", + ], +) + +filegroup( + name = "license_filegroup", + srcs = [ + "LICENSE", + ], + tags = ["license_filegroup"], +) diff --git a/tools/workspace/spdlog/repository.bzl b/tools/workspace/spdlog/repository.bzl new file mode 100644 index 0000000000..66d1e64ec7 --- /dev/null +++ b/tools/workspace/spdlog/repository.bzl @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def spdlog_repository(name = "spdlog"): + version = "1.14.1" + http_archive( + name = name, + sha256 = "1586508029a7d0670dfcb2d97575dcdc242d3868a259742b69f100801ab4e16b", + strip_prefix = "spdlog-{}".format(version), + build_file = "@mujoco//tools/workspace/spdlog:package.BUILD.bazel", + url = "https://github.com/gabime/spdlog/archive/refs/tags/v{}.tar.gz".format(version), + ) diff --git a/tools/workspace/tinyobjloader/BUILD.bazel b/tools/workspace/tinyobjloader/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/tinyobjloader/package.BUILD.bazel b/tools/workspace/tinyobjloader/package.BUILD.bazel new file mode 100644 index 0000000000..74197e584e --- /dev/null +++ b/tools/workspace/tinyobjloader/package.BUILD.bazel @@ -0,0 +1,14 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +cc_library( + name = "tinyobjloader", + hdrs = ["tiny_obj_loader.h"], + data = [":license_filegroup"], + includes = ["."], +) + +filegroup( + name = "license_filegroup", + srcs = ["LICENSE"], + tags = ["license_filegroup"], +) diff --git a/tools/workspace/tinyobjloader/repository.bzl b/tools/workspace/tinyobjloader/repository.bzl new file mode 100644 index 0000000000..25b9a87e08 --- /dev/null +++ b/tools/workspace/tinyobjloader/repository.bzl @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def tinyobjloader_repository(name = "tinyobjloader"): + commit = "1421a10d6ed9742f5b2c1766d22faa6cfbc56248" + http_archive( + name = name, + sha256 = "e334b2900380efdc19a0ea42e5e966a6a6a04831dd830dd42a80e28ce6d1e9be", + strip_prefix = "tinyobjloader-{}".format(commit), + build_file = "@mujoco//tools/workspace/tinyobjloader:package.BUILD.bazel", + url = "https://github.com/tinyobjloader/tinyobjloader/archive/{}.tar.gz".format(commit), + ) diff --git a/tools/workspace/tinyxml2/BUILD.bazel b/tools/workspace/tinyxml2/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/workspace/tinyxml2/package.BUILD.bazel b/tools/workspace/tinyxml2/package.BUILD.bazel new file mode 100644 index 0000000000..5412426215 --- /dev/null +++ b/tools/workspace/tinyxml2/package.BUILD.bazel @@ -0,0 +1,15 @@ +package(default_visibility = ["@mujoco//:__subpackages__"]) + +cc_library( + name = "tinyxml2", + srcs = ["tinyxml2.cpp"], + hdrs = ["tinyxml2.h"], + data = [":license_filegroup"], + includes = ["."] +) + +filegroup( + name = "license_filegroup", + srcs = ["LICENSE.txt"], + tags = ["license_filegroup"], +) diff --git a/tools/workspace/tinyxml2/repository.bzl b/tools/workspace/tinyxml2/repository.bzl new file mode 100644 index 0000000000..facf8ff47a --- /dev/null +++ b/tools/workspace/tinyxml2/repository.bzl @@ -0,0 +1,11 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def tinyxml2_repository(name = "tinyxml2"): + commit = "9a89766acc42ddfa9e7133c7d81a5bda108a0ade" + http_archive( + name = name, + sha256 = "562d77a5f3b1631c289e6856a440c2f459ba5e120a529ce70a08279c2d3d5667", + strip_prefix = "tinyxml2-{}".format(commit), + build_file = "@mujoco//tools/workspace/tinyxml2:package.BUILD.bazel", + url = "https://github.com/leethomason/tinyxml2/archive/{}.tar.gz".format(commit), + )