From 4d8e12cb467a23b105c2250b732b340060486a5b Mon Sep 17 00:00:00 2001 From: kanarus Date: Sat, 8 Nov 2025 15:40:25 +0900 Subject: [PATCH 01/11] feat: MUJOCO_LIB --- Cargo.toml | 4 ++ README.md | 16 ++++---- build.rs | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++--- probe.c | 6 +++ 4 files changed, 120 insertions(+), 12 deletions(-) create mode 100644 probe.c diff --git a/Cargo.toml b/Cargo.toml index 9576b2c..63d19bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,9 +14,13 @@ categories = ["api-bindings", "science::robotics", "simulation"] [build-dependencies] bindgen = { optional = true, version = "=0.72.1" } +cc = "1.2.45" [dev-dependencies] glfw = "0.60" [features] bindgen = ["dep:bindgen"] # run bindgen at build time, instead of using pre-generated bindgen.rs + +# internal +DEBUG = [] diff --git a/README.md b/README.md index 0a182b8..a48675a 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,9 @@ - [MuJoCo 3.3.2](https://github.com/google-deepmind/mujoco/releases/tag/3.3.2) downloaded and expanded **as it is** (don't move or rename the files within it) -- `MUJOCO_DIR` environment variable set to the path of the MuJoCo directory (e.g. `$HOME/.mujoco/mujoco-3.3.2`) +- `MUJOCO_LIB` environment variable set to the path of a directory containing + `libmujoco.so` or `mujoco.lib` of MuJoCo 3.3.2 + (e.g. `$HOME/.mujoco/mujoco-3.3.2/lib` when you placed the official release above in `~/.mujoco`) ### Note / Tips @@ -51,23 +53,23 @@ and insert to your shell config file: ```sh # example on Linux with /usr/local/lib/ - export MUJOCO_DIR="/usr/local/lib/mujoco-3.3.2" + export MUJOCO_LIB="/usr/local/lib/mujoco-3.3.2/lib" ``` Or if you'd like to avoid to install MuJoCo to such a system directory: ```sh # example on Linux with $HOME/.mujoco/ - export MUJOCO_DIR="$HOME/.mujoco/mujoco-3.3.2" - export LD_LIBRARY_PATH="$MUJOCO_DIR/lib:$LD_LIBRARY_PATH" + export MUJOCO_LIB="$HOME/.mujoco/mujoco-3.3.2/lib" + export LD_LIBRARY_PATH="$MUJOCO_LIB:$LD_LIBRARY_PATH" ``` -- Depending on your setting, be sure to specify `$MUJOCO_DIR/lib` as shared library path - when executing your app (for example `LD_LIBRARY_PATH=$MUJOCO_DIR/lib cargo run` on Linux) +- Depending on your setting, be sure to specify `$MUJOCO_LIB` as shared library path + when executing your app (for example `LD_LIBRARY_PATH=$MUJOCO_LIB cargo run` on Linux) ## Example ```toml [dependencies] -rusty_mujoco = "0.1" +rusty_mujoco = "0.2" glfw = "0.60" ``` diff --git a/build.rs b/build.rs index 40929f7..f1d6e3a 100644 --- a/build.rs +++ b/build.rs @@ -1,17 +1,113 @@ fn main() { if option_env!("DOCS_RS").is_some() { return } - let mujoco_dir = std::env::var("MUJOCO_DIR").expect("MUJOCO_DIR environment variable is not set"); - let mujoco_dir = std::path::Path::new(&mujoco_dir).canonicalize().expect("MUJOCO_DIR is not a valid path"); - let mujoco_lib = mujoco_dir.join("lib").to_str().unwrap().to_owned(); - - println!("cargo:rustc-link-search={mujoco_lib}"); + if dbg!(!probe_mujoco_lib_with_libdir(None)) { + if let Some(mujoco_lib_dir) = mujoco_lib_directory_from_env("MUJOCO_LIB") { + assert!( + dbg!(probe_mujoco_lib_with_libdir(Some(&mujoco_lib_dir))), + "Failed to link with mujoco library even after setting `MUJOCO_LIB` environment variable!" + ); + println!("cargo:rustc-link-search=native={}", mujoco_lib_dir.display()); + } else { + panic!("\ + MuJoCo library not found. Make sure that the mujoco library is installed and, \ + if its location is non-standard, set the path via the `MUJOCO_LIB` environment variable.\ + "); + } + } println!("cargo:rustc-link-lib=dylib=mujoco"); #[cfg(feature = "bindgen")] bindgen(); } +fn probe_mujoco_lib_with_libdir(libdir: Option<&std::path::Path>) -> bool { + let crate_root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")); + let vendor_dir = crate_root.join("vendor"); + + let probe_c = crate_root.join("probe.c"); + let vendor_include = vendor_dir.join("include"); + let vendor_include_mujoco = vendor_include.join("mujoco"); + + /* + * `cc` crate is designed as: + * + * > A library for Cargo build scripts to compile a set of C/C++/assembly/CUDA files + * into a static archive for Cargo to link into the crate being built. + * + * However, here we need to probe whether linking with `mujoco` library to an executable + * succeeds or not, so we manually invoke the compiler with appropriate arguments + * using `cc` crate to get the compiler path and kind. + */ + + let cc = cc::Build::new().cargo_metadata(false).get_compiler(); + let cc_path = cc.path(); + let cc_args = if cc.is_like_gnu() || cc.is_like_clang() { + let mut args = vec![ + probe_c.to_str().unwrap(), + "-I", vendor_include.to_str().unwrap(), + "-I", vendor_include_mujoco.to_str().unwrap(), + "-o", "/dev/null", + ]; + if let Some(libdir) = libdir { + args.extend(["-L", libdir.to_str().unwrap()]); + } + args.extend(["-l", "mujoco"]); + args + } else if cc.is_like_msvc() || cc.is_like_clang_cl() { + let mut args = vec![ + probe_c.to_str().unwrap(), + "/I", vendor_include.to_str().unwrap(), + "/I", vendor_include_mujoco.to_str().unwrap(), + "/Fe:NUL", + ]; + if let Some(libdir) = libdir { + let libpath_arg = format!("/LIBPATH:{}", libdir.display()); + args.extend([libpath_arg.leak() as &_]); // will be released soon when build script ends + } + args.extend(["mujoco.lib"]); + args + } else { + panic!("Unsupported compiler: {}", cc_path.display()); + }; + + let stdio_strategy = || if cfg!(feature = "DEBUG") { + std::process::Stdio::inherit() + } else { + std::process::Stdio::null() + }; + std::process::Command::new(dbg!(cc_path)) + .args(dbg!(cc_args)) + .stdout(stdio_strategy()) + .stderr(stdio_strategy()) + .status() + .unwrap_or_else(|err| panic!("Failed to invoke compiler to probe mujoco library: {err}")) + .success() +} + +/// Adds the given path to the library search path for linking, +/// with resolving the directory path from an environment variable `env` +/// that may be either the directory path or path of the library file itself. +fn mujoco_lib_directory_from_env(env: &'static str) -> Option { + let mujoco_lib = match std::env::var(env) { + Ok(value) => value, + Err(std::env::VarError::NotPresent) => return None, + Err(std::env::VarError::NotUnicode(os_str)) => panic!("{env} contains invalid unicode: `{}`", os_str.to_string_lossy()), + }; + let mujoco_lib = std::path::Path::new(&mujoco_lib) + .canonicalize() + .unwrap_or_else(|err| panic!("{env} is not a valid path: {err}")); + + Some(if mujoco_lib.is_dir() { + mujoco_lib + } else { + mujoco_lib + .parent() + .unwrap_or_else(|| panic!("{env} must be a valid path to mujoco library file or directory containing it")) + .to_owned() + }) +} + #[cfg(feature = "bindgen")] fn bindgen() { #[derive(Debug)] diff --git a/probe.c b/probe.c new file mode 100644 index 0000000..30cc1e0 --- /dev/null +++ b/probe.c @@ -0,0 +1,6 @@ +#include "mujoco/mujoco.h" + +int main(void) { + mj_version(); + return 0; +} From 5c4001195b9ca2786e29bf9cf01043be78a2a3c3 Mon Sep 17 00:00:00 2001 From: kanarus Date: Sat, 8 Nov 2025 16:00:56 +0900 Subject: [PATCH 02/11] revise build.rs --- build.rs | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/build.rs b/build.rs index f1d6e3a..f3d8723 100644 --- a/build.rs +++ b/build.rs @@ -15,7 +15,7 @@ fn main() { "); } } - println!("cargo:rustc-link-lib=dylib=mujoco"); + println!("cargo:rustc-link-lib=mujoco"); #[cfg(feature = "bindgen")] bindgen(); @@ -36,7 +36,7 @@ fn probe_mujoco_lib_with_libdir(libdir: Option<&std::path::Path>) -> bool { * into a static archive for Cargo to link into the crate being built. * * However, here we need to probe whether linking with `mujoco` library to an executable - * succeeds or not, so we manually invoke the compiler with appropriate arguments + * succeeds or not, so we manually invoke the compiler with appropriate arguments, * using `cc` crate to get the compiler path and kind. */ @@ -44,42 +44,36 @@ fn probe_mujoco_lib_with_libdir(libdir: Option<&std::path::Path>) -> bool { let cc_path = cc.path(); let cc_args = if cc.is_like_gnu() || cc.is_like_clang() { let mut args = vec![ - probe_c.to_str().unwrap(), - "-I", vendor_include.to_str().unwrap(), - "-I", vendor_include_mujoco.to_str().unwrap(), - "-o", "/dev/null", + probe_c.to_str().unwrap().to_string(), + format!("-I{}", vendor_include.display()), + format!("-I{}", vendor_include_mujoco.display()), + "-o".to_string(), "/dev/null".to_string(), ]; if let Some(libdir) = libdir { - args.extend(["-L", libdir.to_str().unwrap()]); + args.push(format!("-L{}", libdir.display())); } - args.extend(["-l", "mujoco"]); + args.push("-lmujoco".to_string()); args } else if cc.is_like_msvc() || cc.is_like_clang_cl() { let mut args = vec![ - probe_c.to_str().unwrap(), - "/I", vendor_include.to_str().unwrap(), - "/I", vendor_include_mujoco.to_str().unwrap(), - "/Fe:NUL", + probe_c.to_str().unwrap().to_string(), + format!("/I{}", vendor_include.display()), + format!("/I{}", vendor_include_mujoco.display()), + "/Fe:NUL".to_string(), ]; if let Some(libdir) = libdir { - let libpath_arg = format!("/LIBPATH:{}", libdir.display()); - args.extend([libpath_arg.leak() as &_]); // will be released soon when build script ends + args.push(format!("/LIBPATH:{}", libdir.display())); } - args.extend(["mujoco.lib"]); + args.push("mujoco.lib".to_string()); args } else { panic!("Unsupported compiler: {}", cc_path.display()); }; - let stdio_strategy = || if cfg!(feature = "DEBUG") { - std::process::Stdio::inherit() - } else { - std::process::Stdio::null() - }; std::process::Command::new(dbg!(cc_path)) .args(dbg!(cc_args)) - .stdout(stdio_strategy()) - .stderr(stdio_strategy()) + .stdout(std::process::Stdio::inherit()) + .stderr(std::process::Stdio::inherit()) .status() .unwrap_or_else(|err| panic!("Failed to invoke compiler to probe mujoco library: {err}")) .success() @@ -94,17 +88,17 @@ fn mujoco_lib_directory_from_env(env: &'static str) -> Option return None, Err(std::env::VarError::NotUnicode(os_str)) => panic!("{env} contains invalid unicode: `{}`", os_str.to_string_lossy()), }; - let mujoco_lib = std::path::Path::new(&mujoco_lib) - .canonicalize() - .unwrap_or_else(|err| panic!("{env} is not a valid path: {err}")); + let mujoco_lib = std::path::Path::new(&mujoco_lib); Some(if mujoco_lib.is_dir() { - mujoco_lib - } else { + mujoco_lib.to_owned() + } else if mujoco_lib.is_file() { mujoco_lib .parent() .unwrap_or_else(|| panic!("{env} must be a valid path to mujoco library file or directory containing it")) .to_owned() + } else { + panic!("{env} must be a valid path to mujoco library file or directory containing it") }) } From 50180da18c15e60c7a1a1df661833da79844022b Mon Sep 17 00:00:00 2001 From: kanarus Date: Sat, 8 Nov 2025 16:02:43 +0900 Subject: [PATCH 03/11] lock `cc` version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 63d19bd..d7319cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ categories = ["api-bindings", "science::robotics", "simulation"] [build-dependencies] bindgen = { optional = true, version = "=0.72.1" } -cc = "1.2.45" +cc = { version = "=1.2.45" } [dev-dependencies] glfw = "0.60" From b9bb14261d488142073a804904e60fffdcc4c592 Mon Sep 17 00:00:00 2001 From: kanarus Date: Sat, 8 Nov 2025 16:20:19 +0900 Subject: [PATCH 04/11] update CI --- .github/workflows/CI.yml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index dc21793..76c3342 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -26,30 +26,39 @@ jobs: rustup component add rustfmt ### required for the build script to work ### [ "${{ matrix.arch }}" = 'aarch64' ] && sudo apt update && sudo apt install -y g++-aarch64-linux-gnu || : - - name: build fails without MUJOCO_DIR + - name: build fails without mujoco env: CARGO_BUILD_TARGET: ${{ matrix.arch }}-unknown-linux-gnu run: | if cargo build; then - echo 'cargo build succeeded without MUJOCO_DIR, which is unexpected.' + echo 'cargo build **unexpectedly** succeeded without mujoco.' exit 1 else echo 'cargo build failed as expected without mujoco.' fi - - name: install mujoco and set MUJOCO_DIR + - name: install mujoco run: | mkdir -p $HOME/.mujoco cd $HOME/.mujoco wget https://github.com/google-deepmind/mujoco/releases/download/3.3.2/mujoco-3.3.2-linux-${{ matrix.arch }}.tar.gz tar -xzf mujoco-3.3.2-linux-${{ matrix.arch }}.tar.gz - echo "MUJOCO_DIR=$HOME/.mujoco/mujoco-3.3.2" >> $GITHUB_ENV - echo "LD_LIBRARY_PATH=$HOME/.mujoco/mujoco-3.3.2/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV - - name: build succeeds with MUJOCO_DIR + - name: build succeeds with MUJOCO_LIB + env: + MUJOCO_LIB: $HOME/.mujoco/mujoco-3.3.2/lib + CARGO_BUILD_TARGET: ${{ matrix.arch }}-unknown-linux-gnu + run: | + cargo build + cargo build --features bindgen + git diff --exit-code ./src/bindgen.rs || (echo "bindgen.rs changed after build with bindgen feature."; exit 1) + + - name: build succeeds using system mujoco without MUJOCO_LIB env: CARGO_BUILD_TARGET: ${{ matrix.arch }}-unknown-linux-gnu run: | + sudo cp $HOME/.mujoco/mujoco-3.3.2/lib/libmujoco.so /usr/local/lib/ + sudo ldconfig cargo build cargo build --features bindgen git diff --exit-code ./src/bindgen.rs || (echo "bindgen.rs changed after build with bindgen feature."; exit 1) From 2299a59b3f81084bd11e03d19e1de0ead6e8c6b5 Mon Sep 17 00:00:00 2001 From: kanarus Date: Sat, 8 Nov 2025 16:27:22 +0900 Subject: [PATCH 05/11] update examples' README --- examples/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/README.md b/examples/README.md index f7f2759..0b37d38 100644 --- a/examples/README.md +++ b/examples/README.md @@ -24,10 +24,10 @@ Options: If not provided, the default camera will be used. - example: `--camera side` for the humanoid model -Depending on your system, you may need to give: +Depending on your system, you may need to specify: -- `MUJOCO_DIR` environment variable, to the MuJoCo directory path (e.g. `$HOME/.mujoco/mujoco-3.3.2`) +- `MUJOCO_LIB` environment variable, to the MuJoCo directory path (e.g. `$HOME/.mujoco/mujoco-3.3.2/lib`) - `LD_LIBRARY_PATH` (Linux), `DYLD_LIBRARY_PATH` (macOS), or `PATH` (Windows) configuration for searching the MuJoCo library path -like `LD_LIBRARY_PATH="$MUJOCO_DIR/lib" cargo run --example visualize_left_object -- $MUJOCO_DIR/model/humanoid.xml` +like `LD_LIBRARY_PATH="$MUJOCO_LIB" cargo run --example visualize_left_object -- $MUJOCO_LIB/../model/humanoid.xml` From 7a94847fece04a9df1e9e47bf8f7396d51da317d Mon Sep 17 00:00:00 2001 From: kanarus Date: Sat, 8 Nov 2025 16:47:25 +0900 Subject: [PATCH 06/11] debug CI --- .github/workflows/CI.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 76c3342..5b91898 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -49,6 +49,7 @@ jobs: MUJOCO_LIB: $HOME/.mujoco/mujoco-3.3.2/lib CARGO_BUILD_TARGET: ${{ matrix.arch }}-unknown-linux-gnu run: | + echo "[DEBUG] MUJOCO_LIB='$MUJOCO_LIB'" cargo build cargo build --features bindgen git diff --exit-code ./src/bindgen.rs || (echo "bindgen.rs changed after build with bindgen feature."; exit 1) From f0401fe42e3f90c3236b17ef2f7bebe58ea85e5b Mon Sep 17 00:00:00 2001 From: kanarus Date: Sat, 8 Nov 2025 16:55:23 +0900 Subject: [PATCH 07/11] fix CI::build to run cargo clean as needed --- .github/workflows/CI.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 5b91898..1fe9c1c 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -49,7 +49,7 @@ jobs: MUJOCO_LIB: $HOME/.mujoco/mujoco-3.3.2/lib CARGO_BUILD_TARGET: ${{ matrix.arch }}-unknown-linux-gnu run: | - echo "[DEBUG] MUJOCO_LIB='$MUJOCO_LIB'" + cargo clean ### clean up the build cache to assure the build script is re-run ### cargo build cargo build --features bindgen git diff --exit-code ./src/bindgen.rs || (echo "bindgen.rs changed after build with bindgen feature."; exit 1) @@ -58,6 +58,7 @@ jobs: env: CARGO_BUILD_TARGET: ${{ matrix.arch }}-unknown-linux-gnu run: | + cargo clean ### clean up the build cache to assure the build script is re-run ### sudo cp $HOME/.mujoco/mujoco-3.3.2/lib/libmujoco.so /usr/local/lib/ sudo ldconfig cargo build From 3da40101882619fe63364947c89e9e8f0c4eabcb Mon Sep 17 00:00:00 2001 From: kanarus Date: Sat, 8 Nov 2025 17:05:03 +0900 Subject: [PATCH 08/11] fix CI::build: environment variable handling --- .github/workflows/CI.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 1fe9c1c..d79bcc2 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -46,11 +46,10 @@ jobs: - name: build succeeds with MUJOCO_LIB env: - MUJOCO_LIB: $HOME/.mujoco/mujoco-3.3.2/lib CARGO_BUILD_TARGET: ${{ matrix.arch }}-unknown-linux-gnu run: | cargo clean ### clean up the build cache to assure the build script is re-run ### - cargo build + MUJOCO_LIB="$HOME/.mujoco/mujoco-3.3.2/lib" cargo build cargo build --features bindgen git diff --exit-code ./src/bindgen.rs || (echo "bindgen.rs changed after build with bindgen feature."; exit 1) From ed527ff6e5218ed08362adb51965f27b2f923940 Mon Sep 17 00:00:00 2001 From: kanarus Date: Sat, 8 Nov 2025 17:07:45 +0900 Subject: [PATCH 09/11] fix CI::build: environment variable handling --- .github/workflows/CI.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d79bcc2..2511f96 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -48,8 +48,9 @@ jobs: env: CARGO_BUILD_TARGET: ${{ matrix.arch }}-unknown-linux-gnu run: | + export MUJOCO_LIB="$HOME/.mujoco/mujoco-3.3.2/lib" cargo clean ### clean up the build cache to assure the build script is re-run ### - MUJOCO_LIB="$HOME/.mujoco/mujoco-3.3.2/lib" cargo build + cargo build cargo build --features bindgen git diff --exit-code ./src/bindgen.rs || (echo "bindgen.rs changed after build with bindgen feature."; exit 1) @@ -57,9 +58,9 @@ jobs: env: CARGO_BUILD_TARGET: ${{ matrix.arch }}-unknown-linux-gnu run: | - cargo clean ### clean up the build cache to assure the build script is re-run ### sudo cp $HOME/.mujoco/mujoco-3.3.2/lib/libmujoco.so /usr/local/lib/ sudo ldconfig + cargo clean ### clean up the build cache to assure the build script is re-run ### cargo build cargo build --features bindgen git diff --exit-code ./src/bindgen.rs || (echo "bindgen.rs changed after build with bindgen feature."; exit 1) From 6b8fec33cbab43258def9223c785858a7a54bb1b Mon Sep 17 00:00:00 2001 From: kanarus Date: Sat, 8 Nov 2025 17:12:22 +0900 Subject: [PATCH 10/11] fix CI::test: update MUJOCO_DIR -> MUJOCO_LIB --- .github/workflows/CI.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2511f96..b2912d7 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -92,7 +92,8 @@ jobs: mkdir -p $HOME/.mujoco && cd $HOME/.mujoco wget https://github.com/google-deepmind/mujoco/releases/download/3.3.2/$MUJOCO_FILENAME tar -xzf $MUJOCO_FILENAME - echo "MUJOCO_DIR=$HOME/.mujoco/mujoco-3.3.2" >> $GITHUB_ENV + ### Set `MUJOCO_LIB` and `LD_LIBRARY_PATH` for the test jobs ### + echo "MUJOCO_LIB=$HOME/.mujoco/mujoco-3.3.2/lib" >> $GITHUB_ENV echo "LD_LIBRARY_PATH=$HOME/.mujoco/mujoco-3.3.2/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV - name: setup additional dependencies for examples From a77e301007fe53c99c4a48dcfa1ff773894c01b5 Mon Sep 17 00:00:00 2001 From: kanarus Date: Sat, 8 Nov 2025 17:34:15 +0900 Subject: [PATCH 11/11] update docs --- README.md | 15 ++++++++------- examples/README.md | 12 +++++++++--- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a48675a..157a745 100644 --- a/README.md +++ b/README.md @@ -32,11 +32,10 @@ ## Requirements -- [MuJoCo 3.3.2](https://github.com/google-deepmind/mujoco/releases/tag/3.3.2) downloaded - and expanded **as it is** (don't move or rename the files within it) -- `MUJOCO_LIB` environment variable set to the path of a directory containing - `libmujoco.so` or `mujoco.lib` of MuJoCo 3.3.2 - (e.g. `$HOME/.mujoco/mujoco-3.3.2/lib` when you placed the official release above in `~/.mujoco`) +- [MuJoCo 3.3.2](https://github.com/google-deepmind/mujoco/releases/tag/3.3.2) downloaded and installed +- Additionally, if you place mujoco library in a non-standard directory of the platform, + you need `MUJOCO_LIB` environment variable set to the path of the directory containing + `libmujoco.so` or `mujoco.lib` (e.g. `$HOME/.mujoco/mujoco-3.3.2/lib` when you placed the official release above in `~/.mujoco`) ### Note / Tips @@ -47,7 +46,7 @@ ``` to download & expand MuJoCo 3.3.2.\ On other platforms, do the same with the appropriate archive file for your system. - + - One way to setup is to install MuJoCo to _a default standard path_ like `/usr/local/lib/` (or a folder in _PATH_ on Windows), then if needed create symlink to `mujoco-3.3.2/lib/libmujoco.so` there, and insert to your shell config file: @@ -61,7 +60,9 @@ export MUJOCO_LIB="$HOME/.mujoco/mujoco-3.3.2/lib" export LD_LIBRARY_PATH="$MUJOCO_LIB:$LD_LIBRARY_PATH" ``` - + +- Or, you can get MuJoCo library through Python toolchain like `uv` or `pip`. + - Depending on your setting, be sure to specify `$MUJOCO_LIB` as shared library path when executing your app (for example `LD_LIBRARY_PATH=$MUJOCO_LIB cargo run` on Linux) diff --git a/examples/README.md b/examples/README.md index 0b37d38..34d63cd 100644 --- a/examples/README.md +++ b/examples/README.md @@ -15,19 +15,25 @@ Pass the path to a MuJoCo model XML file as an argument. For example, you can use the `humanoid.xml` model provided by MuJoCo: ```sh -cargo run --example visualize_left_object -- $MUJOCO_DIR/model/humanoid/humanoid.xml +cargo run --example visualize_left_object -- $MUJOCO_LIB/../model/humanoid/humanoid.xml ``` +*(replace the path to humanoid.xml with yours)* + Options: - `--camera `: Specify the name of camera to use for visualization (optional). If not provided, the default camera will be used. - example: `--camera side` for the humanoid model -Depending on your system, you may need to specify: +Depending on your setting, you may need to specify: - `MUJOCO_LIB` environment variable, to the MuJoCo directory path (e.g. `$HOME/.mujoco/mujoco-3.3.2/lib`) - `LD_LIBRARY_PATH` (Linux), `DYLD_LIBRARY_PATH` (macOS), or `PATH` (Windows) configuration for searching the MuJoCo library path -like `LD_LIBRARY_PATH="$MUJOCO_LIB" cargo run --example visualize_left_object -- $MUJOCO_LIB/../model/humanoid.xml` +like: + +```sh +LD_LIBRARY_PATH="$MUJOCO_LIB" cargo run --example visualize_left_object -- $MUJOCO_LIB/../model/humanoid.xml +```