Initial open sourcing of MuJoCo.

PiperOrigin-RevId: 450374687
Change-Id: Ie3225a46ce095fc28ae8e63c326a640261f562bb
This commit is contained in:
Saran Tunyasuvunakool
2022-05-23 01:08:10 -07:00
committed by Copybara-Service
parent 0e5d062302
commit 1913a02b40
275 changed files with 99607 additions and 935 deletions
+45 -26
View File
@@ -31,44 +31,63 @@ need to be downloaded or installed separately.
### Source
**Note.** Building from source is only necessary if you are modifying the Python bindings (or are trying to run on exceptionally old Linux systems). If that's not the case, then we recommend installing the prebuilt binaries from PyPI.
**IMPORTANT:** Building from source is only necessary if you are modifying the
Python bindings (or are trying to run on exceptionally old Linux systems).
If that's not the case, then we recommend installing the prebuilt binaries from
PyPI.
Before proceeding, make sure you have CMake and a C++17 compiler installed.
1. Make sure you have CMake and a C++17 compiler installed.
1. Download the latest release of the [binary archives](https://github.com/deepmind/mujoco/releases) from GitHub. On macOS, the download corresponds to a DMG file from which you can drag the `MuJoCo` app into your Applications folder.
1. Download the [latest binary release](https://github.com/deepmind/mujoco/releases)
from GitHub. On macOS, the download corresponds to a DMG file from which you
can drag `MuJoCo.app` into your `/Applications` folder.
2. Clone the entire `mujoco` repository from GitHub and `cd` into the python directory.
1. Clone the entire `mujoco` repository from GitHub and `cd` into the python
directory.
```bash
git clone https://github.com/deepmind/mujoco.git
cd mujoco/python
```
```bash
git clone https://github.com/deepmind/mujoco.git
cd mujoco/python
```
3. Create a virtual environment:
1. Create a virtual environment:
```bash
python3 -m venv /tmp/mujoco
source /tmp/mujoco/bin/activate
```
```bash
python3 -m venv /tmp/mujoco
source /tmp/mujoco/bin/activate
```
4. Generate a [source distribution](https://packaging.python.org/en/latest/glossary/#term-Source-Distribution-or-sdist)
tarball with the `make_sdist.sh` script.
1. Generate a [source distribution](https://packaging.python.org/en/latest/glossary/#term-Source-Distribution-or-sdist)
tarball with the `make_sdist.sh` script.
```bash
cd python
bash make_sdist.sh
```
```bash
cd python
bash make_sdist.sh
```
The `make_sdist.sh` script generates additional C++ header files that are needed to build the bindings, and also pulls in required files from elsewhere in the repository outside the `python` directory into the sdist. Upon completion, the script will create a `dist` directory with a `mujoco-2.1.X.tar.gz` file (where X is the version number of the release).
The `make_sdist.sh` script generates additional C++ header files that are
needed to build the bindings, and also pulls in required files from elsewhere
in the repository outside the `python` directory into the sdist. Upon
completion, the script will create a `dist` directory with a
`mujoco-x.y.z.tar.gz` file (where `x.y.z` is the version number).
5. Install the generated tarball. You'll need to specify the path to the MuJoCo library you downloaded earlier. For example, on macOS, this will be `/Applications/MuJoCo.app/Contents/Frameworks/MuJoCo.framework` if you dragged it to your Applications folder.
1. Use the generated source distribution to build and install the bindings.
You'll need to specify the path to the MuJoCo library you downloaded earlier
in the `MUJOCO_PATH` environment variable.
```bash
cd dist
MUJOCO_PATH=/PATH/TO/MUJOCO pip install mujoco-2.1.X.tar.gz
```
**Note**: For macOS, this can be the path to a directory that contains the
`mujoco.framework`. In particular, you can set
`MUJOCO_PATH=/Applications/MuJoCo.app` if you installed MuJoCo as suggested
in step 1.
The Python bindings should now be installed! To check that they've been successfully installed, `cd` outside of the `mujoco` directory and run `python -c "import mujoco"`.
```bash
cd dist
MUJOCO_PATH=/PATH/TO/MUJOCO pip install mujoco-x.y.z.tar.gz
```
The Python bindings should now be installed! To check that they've been
successfully installed, `cd` outside of the `mujoco` directory and run
`python -c "import mujoco"`.
## Usage
+84 -45
View File
@@ -40,32 +40,60 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
separate_arguments(CMDLINE_LINK_OPTIONS UNIX_COMMAND ${CMAKE_SHARED_LINKER_FLAGS})
add_link_options(${CMDLINE_LINK_OPTIONS})
if(MSVC)
add_compile_options(/Gy /Gw /Oi)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-fdata-sections -ffunction-sections)
endif()
include(MujocoLinkOptions)
get_mujoco_extra_link_options(EXTRA_LINK_OPTIONS)
add_link_options(${EXTRA_LINK_OPTIONS})
if(APPLE)
add_compile_options(-Werror=partial-availability -Werror=unguarded-availability)
add_link_options(-Wl,-no_weak_imports)
include(MujocoMacOS)
enforce_mujoco_macosx_min_version()
if(WIN32)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif()
include(MujocoHarden)
add_compile_options("${MUJOCO_HARDEN_COMPILE_OPTIONS}")
add_link_options("${MUJOCO_HARDEN_LINK_OPTIONS}")
find_package(Python3 COMPONENTS Interpreter Development)
include(FindOrFetch)
# ==================== MUJOCO LIBRARY ==========================================
if(NOT TARGET mujoco)
find_library(MUJOCO_LIBRARY mujoco mujoco.2.1.5 HINTS ${MUJOCO_LIBRARY_DIR} REQUIRED)
find_path(MUJOCO_INCLUDE mujoco.h HINTS ${MUJOCO_INCLUDE_DIR} REQUIRED)
message("MuJoCo is at ${MUJOCO_LIBRARY}")
message("MuJoCo headers are at ${MUJOCO_INCLUDE}")
add_library(mujoco SHARED IMPORTED)
if(APPLE)
# On macOS, check if we are using mujoco.framework first.
# Framework headers are searched differently from normal headers.
# We need to use -F instead of the usual target_include_directories.
find_path(MUJOCO_FRAMEWORK mujoco.Framework HINTS ${MUJOCO_FRAMEWORK_DIR})
if(MUJOCO_FRAMEWORK)
message("MuJoCo framework is at ${MUJOCO_FRAMEWORK}/mujoco.framework")
set(MUJOCO_LIBRARY ${MUJOCO_FRAMEWORK}/mujoco.framework/Versions/A/libmujoco.2.2.0.dylib)
target_compile_options(mujoco INTERFACE -F${MUJOCO_FRAMEWORK})
endif()
endif()
if(NOT MUJOCO_FRAMEWORK)
find_library(MUJOCO_LIBRARY mujoco mujoco.2.2.0 HINTS ${MUJOCO_LIBRARY_DIR} REQUIRED)
find_path(MUJOCO_INCLUDE mujoco/mujoco.h HINTS ${MUJOCO_INCLUDE_DIR} REQUIRED)
message("MuJoCo is at ${MUJOCO_LIBRARY}")
message("MuJoCo headers are at ${MUJOCO_INCLUDE}")
target_include_directories(mujoco INTERFACE "${MUJOCO_INCLUDE}")
endif()
if(WIN32)
set_target_properties(mujoco PROPERTIES IMPORTED_IMPLIB "${MUJOCO_LIBRARY}")
else()
set_target_properties(mujoco PROPERTIES IMPORTED_LOCATION "${MUJOCO_LIBRARY}")
endif()
target_include_directories(mujoco INTERFACE "${MUJOCO_INCLUDE}")
if(APPLE)
execute_process(
COMMAND otool -XD ${MUJOCO_LIBRARY}
@@ -88,18 +116,7 @@ if(NOT TARGET mujoco)
endif()
# ==================== ABSEIL ==================================================
if(APPLE)
set(ABSL_EXTRA_FETCH_ARGS
PATCH_COMMAND
"sed"
"-i"
" "
"s/-march=armv8-a+crypto/-mcpu=apple-m1+crypto/g"
"${CMAKE_BINARY_DIR}/_deps/abseil-cpp-src/absl/copts/GENERATED_AbseilCopts.cmake"
)
else()
set(ABSL_EXTRA_FETCH_ARGS "")
endif()
set(MUJOCO_PYTHON_ABSL_TARGETS absl::core_headers absl::flat_hash_map absl::span)
findorfetch(
USE_SYSTEM_PACKAGE
OFF
@@ -110,14 +127,26 @@ findorfetch(
GIT_REPO
https://github.com/abseil/abseil-cpp
GIT_TAG
215105818dfde3174fe799600bb0f3cae233d0bf # 20211102.0
78f9680225b9792c26dfdd99d0bd26c96de53dd4 # # Fixes universal builds for macOS
TARGETS
absl::core_headers
absl::flat_hash_map
absl::span
${ABSL_EXTRA_FETCH_ARGS}
${MUJOCO_PYTHON_ABSL_TARGETS}
EXCLUDE_FROM_ALL
)
foreach(absl_target IN ITEMS ${MUJOCO_PYTHON_ABSL_TARGETS})
get_target_property(absl_target_aliased ${absl_target} ALIASED_TARGET)
if(absl_target_aliased)
set(absl_target ${absl_target_aliased})
endif()
get_target_property(absl_target_type ${absl_target} TYPE)
if(NOT
${absl_target_type}
STREQUAL
"INTERFACE_LIBRARY"
)
target_compile_options(${absl_target} PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS})
target_link_options(${absl_target} PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS})
endif()
endforeach()
# ==================== EIGEN ===================================================
add_compile_definitions(EIGEN_MPL2_ONLY)
@@ -138,26 +167,21 @@ findorfetch(
)
# ==================== PYBIND11 ================================================
if(MUJOCO_PYBIND11_DIR)
FetchContent_Declare(pybind11 SOURCE_DIR ${MUJOCO_PYBIND11_DIR} EXCLUDE_FROM_ALL)
FetchContent_MakeAvailable(pybind11)
else()
findorfetch(
USE_SYSTEM_PACKAGE
OFF
PACKAGE_NAME
pybind11
LIBRARY_NAME
pybind11
GIT_REPO
https://github.com/pybind/pybind11
GIT_TAG
a8f1a5567608f346bdba293b3d062a288ee16cd4
TARGETS
pybind11::pybind11_headers
EXCLUDE_FROM_ALL
)
endif()
findorfetch(
USE_SYSTEM_PACKAGE
OFF
PACKAGE_NAME
pybind11
LIBRARY_NAME
pybind11
GIT_REPO
https://github.com/pybind/pybind11
GIT_TAG
a8f1a5567608f346bdba293b3d062a288ee16cd4
TARGETS
pybind11::pybind11_headers
EXCLUDE_FROM_ALL
)
# ==================== MUJOCO PYTHON BINDINGS ==================================
@@ -222,6 +246,7 @@ target_link_libraries(
structs_header
INTERFACE absl::flat_hash_map
absl::span
crossplatform
mujoco
raw
)
@@ -246,6 +271,19 @@ get_avx_compile_options(AVX_COMPILE_OPTIONS)
macro(mujoco_pybind11_module name)
pybind11_add_module(${name} ${ARGN})
target_compile_options(${name} PRIVATE ${AVX_COMPILE_OPTIONS})
if(NOT MSVC)
target_compile_options(${name} PRIVATE -Wall -Werror)
if(CMAKE_C_COMPILER_ID STREQUAL GNU)
target_compile_options(
${name}
PRIVATE -Wno-int-in-bool-context
-Wno-maybe-uninitialized
-Wno-sign-compare
-Wno-stringop-overflow
-Wno-stringop-truncation
)
endif()
endif()
set_target_properties(${name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
if(APPLE)
add_custom_command(
@@ -323,6 +361,7 @@ mujoco_pybind11_module(
target_link_libraries(
_structs
PRIVATE absl::flat_hash_map
crossplatform
mujoco
raw
errors_header
+1 -1
View File
@@ -53,6 +53,6 @@ if _MUJOCO_GL not in ('disable', 'disabled', 'off', 'false', '0'):
else:
from mujoco.glfw import GLContext
HEADERS_DIR = os.path.join(os.path.dirname(__file__), 'include')
HEADERS_DIR = os.path.join(os.path.dirname(__file__), 'include/mujoco')
__version__ = mj_versionString() # pylint: disable=undefined-variable
+1 -1
View File
@@ -19,7 +19,7 @@
#include <sstream>
#include <type_traits>
#include <mujoco.h>
#include <mujoco/mujoco.h>
#include "errors.h"
#include "structs.h"
#include "raw.h"
@@ -71,7 +71,7 @@ struct {enum.name} {{
#include <tuple>
#include <utility>
#include <mujoco.h>
#include <mujoco/mujoco.h>
namespace mujoco::python_traits {{
@@ -91,7 +91,7 @@ struct {func.name} {{
#include <tuple>
#include <mujoco.h>
#include <mujoco/mujoco.h>
#include "util/crossplatform.h"
namespace mujoco::python_traits {{
+6 -6
View File
@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <utility>
#include <vector>
#include <mjmodel.h>
#include <mjvisualize.h>
#include <mujoco.h>
#include <mujoco/mjmodel.h>
#include <mujoco/mjvisualize.h>
#include <mujoco/mujoco.h>
#include <pybind11/cast.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
namespace mujoco::python {
namespace {
@@ -32,7 +32,7 @@ py::tuple MakeTuple(
for (int i = 0; i < N; i++) {
result.append(py::str(strings[i]));
}
return result;
return std::move(result);
}
template <auto N>
@@ -44,7 +44,7 @@ py::tuple MakeTuple(const char* (&strings)[N][3]) {
py::str(strings[i][1]),
py::str(strings[i][2])));
}
return result;
return std::move(result);
}
PYBIND11_MODULE(_constants, pymodule) {
+2 -2
View File
@@ -20,7 +20,7 @@
#include <string>
#include <type_traits>
#include <mjexport.h>
#include <mujoco/mjexport.h>
#include "util/crossplatform.h"
#include "util/func_wrap.h"
#include <pybind11/pybind11.h>
@@ -109,7 +109,7 @@ class ErrorBase : public pybind11::builtin_exception {
static thread_local std::jmp_buf mju_error_jmp_buf;
static thread_local std::array<char, 1024> mju_error_msg{0};
static void MjErrorHandler(const char* msg) {
static inline void MjErrorHandler(const char* msg) {
std::strncpy(mju_error_msg.data(), msg, mju_error_msg.size());
std::longjmp(mju_error_jmp_buf, 1);
}
+1 -1
View File
@@ -23,7 +23,7 @@
#include <type_traits>
#include <Eigen/Core>
#include <mujoco.h>
#include <mujoco/mujoco.h>
#include "errors.h"
#include "structs.h"
#include "util/array_traits.h"
+5 -3
View File
@@ -15,7 +15,7 @@
#ifndef MUJOCO_PYTHON_INDEXER_XMACRO_H_
#define MUJOCO_PYTHON_INDEXER_XMACRO_H_
#include <mjxmacro.h>
#include <mujoco/mjxmacro.h>
#define MJMODEL_ACTUATOR \
X( int, actuator_, trntype, nu, 1 ) \
@@ -26,11 +26,13 @@
X( int, actuator_, group, nu, 1 ) \
X( mjtByte, actuator_, ctrllimited, nu, 1 ) \
X( mjtByte, actuator_, forcelimited, nu, 1 ) \
X( mjtByte, actuator_, actlimited, nu, 1 ) \
X( mjtNum, actuator_, dynprm, nu, mjNDYN ) \
X( mjtNum, actuator_, gainprm, nu, mjNGAIN ) \
X( mjtNum, actuator_, biasprm, nu, mjNBIAS ) \
X( mjtNum, actuator_, ctrlrange, nu, 2 ) \
X( mjtNum, actuator_, forcerange, nu, 2 ) \
X( mjtNum, actuator_, actrange, nu, 2 ) \
X( mjtNum, actuator_, gear, nu, 6 ) \
X( mjtNum, actuator_, cranklength, nu, 1 ) \
X( mjtNum, actuator_, acc0, nu, 1 ) \
@@ -361,8 +363,8 @@
X( mjtNum, , qfrc_bias, nv, 1 ) \
X( mjtNum, , qfrc_passive, nv, 1 ) \
X( mjtNum, , qfrc_actuator, nv, 1 ) \
X( mjtNum, , qfrc_unc, nv, 1 ) \
X( mjtNum, , qacc_unc, nv, 1 ) \
X( mjtNum, , qfrc_smooth, nv, 1 ) \
X( mjtNum, , qacc_smooth, nv, 1 ) \
X( mjtNum, , qfrc_constraint, nv, 1 ) \
X( mjtNum, , qfrc_inverse, nv, 1 )
+5 -4
View File
@@ -20,11 +20,10 @@
#include <variant>
#include <vector>
#include "errors.h"
#include "indexers.h"
#include "mjdata_meta.h"
#include "raw.h"
#include <pybind11/pybind11.h>
#include "util/crossplatform.h"
namespace mujoco::python {
@@ -218,13 +217,15 @@ MJDATA_VIEW_GROUPS
#undef XGROUP
#define MAKE_SHAPE(dim) \
[n = (dim)]() -> std::vector<int> { \
MUJOCO_DIAG_IGNORE_UNUSED_LAMBDA_CAPTURE \
[n = (dim)]() -> std::vector<int> { \
if constexpr (std::string_view(#dim) == std::string_view("1")) { \
return {}; \
} else { \
return {n}; \
} \
}()
}() \
MUJOCO_DIAG_UNIGNORE_UNUSED_LAMBDA_CAPTURE
#undef MJ_M
#define MJ_M(n) m_->n
+1 -1
View File
@@ -23,7 +23,7 @@
#include <vector>
#include <absl/container/flat_hash_map.h>
#include <mjxmacro.h>
#include <mujoco/mjxmacro.h>
#include "indexer_xmacro.h"
#include "mjdata_meta.h"
#include "raw.h"
+4 -2
View File
@@ -15,8 +15,9 @@
#ifndef MUJOCO_PYTHON_MJDATA_META_H_
#define MUJOCO_PYTHON_MJDATA_META_H_
#include <mjxmacro.h>
#include <mujoco/mjxmacro.h>
#include "raw.h"
#include "util/crossplatform.h"
namespace mujoco::python {
namespace _impl {
@@ -95,7 +96,8 @@ struct MjDataMetadata {
#undef X
dummy_() {}
bool dummy_; // Dummy variable to terminate X macro sequences.
// Dummy variable to terminate X macro sequences.
MUJOCO_MAYBE_UNUSED bool dummy_;
};
} // namespace mujoco::python
+4 -4
View File
@@ -15,10 +15,10 @@
#ifndef MUJOCO_PYTHON_RAW_H_
#define MUJOCO_PYTHON_RAW_H_
#include <mjdata.h>
#include <mjmodel.h>
#include <mjrender.h>
#include <mjvisualize.h>
#include <mujoco/mjdata.h>
#include <mujoco/mjmodel.h>
#include <mujoco/mjrender.h>
#include <mujoco/mjvisualize.h>
// Type aliases for MuJoCo C structs to allow us refer to consistently refer
// to them under the "raw" namespace.
+2 -2
View File
@@ -16,8 +16,8 @@
#include <cstdint>
#include <Eigen/Core>
#include <mjrender.h>
#include <mujoco.h>
#include <mujoco/mjrender.h>
#include <mujoco/mujoco.h>
#include "errors.h"
#include "function_traits.h"
#include "functions.h"
+1 -1
View File
@@ -17,7 +17,7 @@
#include <iostream>
#include <mjtnum.h>
#include <mujoco/mjtnum.h>
namespace mujoco::python::_impl {
+2 -2
View File
@@ -34,8 +34,8 @@
#include <vector>
#include <absl/container/flat_hash_map.h>
#include <mjxmacro.h>
#include <mujoco.h>
#include <mujoco/mjxmacro.h>
#include <mujoco/mujoco.h>
#include "errors.h"
#include "function_traits.h"
#include "indexers.h"
+3 -3
View File
@@ -25,8 +25,8 @@
#include <vector>
#include <absl/types/span.h>
#include <mujoco.h>
#include <mjxmacro.h>
#include <mujoco/mujoco.h>
#include <mujoco/mjxmacro.h>
#include "indexers.h"
#include "mjdata_meta.h"
#include "raw.h"
@@ -894,7 +894,7 @@ static InitPyArray(Shape&& shape, T* buf, pybind11::handle owner) {
out.append(InitPyArray(block_shape, &buf[i * block_size], owner));
}
}
return out;
return std::move(out);
}
// Same as above, but where we can determine array dimensions through the
+2 -6
View File
@@ -23,11 +23,6 @@ set(CMAKE_CXX_EXTENSIONS OFF)
# INTERPROCEDURAL_OPTIMIZATION is enforced when enabled.
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
if(APPLE)
add_compile_options(-Werror=partial-availability -Werror=unguarded-availability)
add_link_options(-Wl,-no_weak_imports)
endif()
add_library(crossplatform INTERFACE)
target_sources(crossplatform INTERFACE crossplatform.h)
set_target_properties(crossplatform PROPERTIES PUBLIC_HEADER crossplatform.h)
@@ -62,7 +57,8 @@ target_link_libraries(
func_traits
)
if(MUJOCO_TEST_PYTHON_UTIL)
if(BUILD_TESTING)
enable_testing()
add_executable(array_traits_test array_traits_test.cc)
target_link_libraries(
array_traits_test
+25
View File
@@ -48,4 +48,29 @@
#define MUJOCO_ALWAYS_INLINE_LAMBDA_MUTABLE
#endif
#ifndef MUJOCO_DIAG_IGNORE_UNUSED_LAMBDA_CAPTURE
#if defined(__clang__)
#define MUJOCO_DIAG_IGNORE_UNUSED_LAMBDA_CAPTURE \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wunused-lambda-capture\"")
#define MUJOCO_DIAG_UNIGNORE_UNUSED_LAMBDA_CAPTURE \
_Pragma("clang diagnostic pop")
#elif defined(__GNUC__)
#define MUJOCO_DIAG_IGNORE_UNUSED_LAMBDA_CAPTURE \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wunused-lambda-capture\"")
#define MUJOCO_DIAG_UNIGNORE_UNUSED_LAMBDA_CAPTURE _Pragma("GCC diagnostic pop")
#else
#define MUJOCO_DIAG_IGNORE_UNUSED_LAMBDA_CAPTURE
#define MUJOCO_DIAG_UNIGNORE_UNUSED_LAMBDA_CAPTURE
#endif
#endif
// GCC ignores [[maybe_unused]] and emits a -Wattributes
#if defined(__GNUC__) && !defined(__clang__)
#define MUJOCO_MAYBE_UNUSED
#else
#define MUJOCO_MAYBE_UNUSED [[maybe_unused]]
#endif
#endif // MUJOCO_PYTHON_UTIL_CROSSPLATFORM_H_
+34 -18
View File
@@ -30,7 +30,7 @@ from setuptools import find_packages
from setuptools import setup
from setuptools.command import build_ext
__version__ = '2.1.5'
__version__ = '2.2.0'
MUJOCO_CMAKE = 'MUJOCO_CMAKE'
MUJOCO_CMAKE_ARGS = 'MUJOCO_CMAKE_ARGS'
@@ -137,7 +137,10 @@ class BuildCMakeExtension(build_ext.build_ext):
"""Uses CMake to build extensions."""
def run(self):
self._mujoco_library_path, self._mujoco_include_path = self._find_mujoco()
self._is_apple = (platform.system() == 'Darwin')
(self._mujoco_library_path,
self._mujoco_include_path,
self._mujoco_framework_path) = self._find_mujoco()
self._configure_cmake()
for ext in self.extensions:
assert ext.name.startswith(EXT_PREFIX)
@@ -151,13 +154,17 @@ class BuildCMakeExtension(build_ext.build_ext):
raise RuntimeError(f'{MUJOCO_PATH} environment variable is not set')
library_path = None
include_path = None
for directory, _, filenames in os.walk(os.environ['MUJOCO_PATH']):
for directory, subdirs, filenames in os.walk(os.environ['MUJOCO_PATH']):
if self._is_apple and 'mujoco.framework' in subdirs:
return (os.path.join(directory, 'mujoco.framework/Versions/A'),
os.path.join(directory, 'mujoco.framework/Headers'),
directory)
if fnmatch.filter(filenames, get_mujoco_lib_pattern()):
library_path = directory
if fnmatch.filter(filenames, 'mujoco.h'):
if os.path.exists(os.path.join(directory, 'mujoco/mujoco.h')):
include_path = directory
if library_path and include_path:
return library_path, include_path
return library_path, include_path, None
raise RuntimeError('Cannot find MuJoCo library and/or include paths')
def _copy_external_libraries(self):
@@ -171,8 +178,8 @@ class BuildCMakeExtension(build_ext.build_ext):
def _copy_mujoco_headers(self):
dst = os.path.join(
os.path.dirname(self.get_ext_fullpath(self.extensions[0].name)),
'include')
os.mkdir(dst)
'include/mujoco')
os.makedirs(dst)
for directory, _, filenames in os.walk(self._mujoco_include_path):
for filename in fnmatch.filter(filenames, '*.h'):
shutil.copyfile(os.path.join(directory, filename),
@@ -184,18 +191,27 @@ class BuildCMakeExtension(build_ext.build_ext):
build_cfg = 'Debug' if self.debug else 'Release'
cmake_module_path = os.path.join(os.path.dirname(__file__), 'cmake')
cmake_args = [
f'-DPython3_ROOT_DIR={sys.prefix}',
f'-DPython3_EXECUTABLE={sys.executable}',
f'-DMUJOCO_LIBRARY_DIR={self._mujoco_library_path}',
f'-DMUJOCO_INCLUDE_DIR={self._mujoco_include_path}',
f'-DCMAKE_MODULE_PATH={cmake_module_path}',
f'-DCMAKE_BUILD_TYPE={build_cfg}',
f'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={self.build_temp}',
f'-DCMAKE_INTERPROCEDURAL_OPTIMIZATION={"OFF" if self.debug else "ON"}',
f'-DPython3_ROOT_DIR:PATH={sys.prefix}',
f'-DPython3_EXECUTABLE:STRING={sys.executable}',
f'-DCMAKE_MODULE_PATH:PATH={cmake_module_path}',
f'-DCMAKE_BUILD_TYPE:STRING={build_cfg}',
f'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY:PATH={self.build_temp}',
f'-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=:BOOL{"OFF" if self.debug else "ON"}',
'-DCMAKE_Fortran_COMPILER:STRING=',
'-DCMAKE_VERBOSE_MAKEFILE=ON',
'-DBUILD_TESTING=OFF',
'-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON',
'-DBUILD_TESTING:BOOL=OFF',
]
if self._mujoco_framework_path is not None:
cmake_args.extend([
f'-DMUJOCO_FRAMEWORK_DIR:PATH={self._mujoco_framework_path}',
])
else:
cmake_args.extend([
f'-DMUJOCO_LIBRARY_DIR:PATH={self._mujoco_library_path}',
f'-DMUJOCO_INCLUDE_DIR:PATH={self._mujoco_include_path}',
])
if platform.system() != 'Windows':
cmake_args.extend([
f'-DPython3_LIBRARY={sysconfig.get_paths()["stdlib"]}',
@@ -293,7 +309,7 @@ setup(
'libmujoco.*.dylib',
'libmujoco*.so.*',
'mujoco.dll',
'include/*.h',
'include/mujoco/*.h',
]),
},
)