From 440a6e22a5d606b143dd5fb33b7b2a4ca279734d Mon Sep 17 00:00:00 2001 From: Ilias Kasoumis Date: Fri, 17 Dec 2021 16:09:19 +0000 Subject: [PATCH] Bring in sync with deepmind/mujoco commit a499b381: Version 2.1.1: Binaries for ARM64, proper macOS bundles Add Xcode (clang) support with libomp and framework linkage: - Need to put MuJoCo.framework under mujoco_path (eg ~/.mujoco/mujoco210) - Approve the new framework under System Preferences -> Security & Privacy - Install libomp under [/usr/local/lib or /opt/homebrew/lib] --- mujoco_py/builder.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/mujoco_py/builder.py b/mujoco_py/builder.py index 5280b2c3..d98a3650 100644 --- a/mujoco_py/builder.py +++ b/mujoco_py/builder.py @@ -310,6 +310,7 @@ def __init__(self, mujoco_path): self.extension.libraries.extend(['glfw.3']) self.extension.define_macros = [('ONMAC', None)] self.extension.runtime_library_dirs = [join(mujoco_path, 'bin')] + self.extension.include_dirs.extend([join(self.mujoco_path, 'MuJoCo.framework/Headers')]) def _build_impl(self): if not os.environ.get('CC'): @@ -323,6 +324,7 @@ def _build_impl(self): '/opt/local/bin/gcc-mp-8', '/opt/local/bin/gcc-mp-7', '/opt/local/bin/gcc-mp-6', + '/usr/bin/clang', ] available_c_compiler = None for c_compiler in c_compilers: @@ -332,10 +334,31 @@ def _build_impl(self): if available_c_compiler is None: raise RuntimeError( 'Could not find supported GCC executable.\n\n' - 'HINT: On OS X, install GCC 9.x with ' + 'HINT: On OS X, install Xcode and libomp (brew install libomp), or\n' + 'GCC 9.x with: ' '`brew install gcc@9`. or ' '`port install gcc9`.') os.environ['CC'] = available_c_compiler + if available_c_compiler == '/usr/bin/clang': + # Use standard Apple Xcode (with libomp for OpenMP): clang -Xpreprocessor -fopenmp -lomp + # Need to ensure libomp is in LIBRARY_PATH somewhere (e.g. /usr/local/lib or /opt/homebrew/lib) + self.extension.extra_compile_args=[ + '-Xpreprocessor', + '-fopenmp', + '-w' + ] + self.extension.extra_link_args=[ + '-lomp', + '-framework', + 'MuJoCo', + '-F', + self.mujoco_path, + '-rpath', + self.mujoco_path + ] + self.extension.libraries=['omp', 'glfw.3'] + self.extension.library_dirs.extend(['/usr/local/lib', '/opt/homebrew/lib']) + self.extension.include_dirs.extend(['/usr/local/include', '/opt/homebrew/include']) so_file_path = super()._build_impl() del os.environ['CC']