summarylogtreecommitdiffstats
path: root/mujoco-py.patch
blob: ce4cd6c68a82198f3883c5401297ef2cf89f7f59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
diff '--color=auto' --unified --recursive --text mujoco-py-2.1.2.14.orig/mujoco_py/builder.py mujoco-py-2.1.2.14.new/mujoco_py/builder.py
--- mujoco-py-2.1.2.14.orig/mujoco_py/builder.py	2022-03-24 00:41:08.622171029 -0400
+++ mujoco-py-2.1.2.14.new/mujoco_py/builder.py	2022-03-24 00:42:23.291497507 -0400
@@ -71,9 +71,7 @@
     if sys.platform == 'darwin':
         Builder = MacExtensionBuilder
     elif sys.platform == 'linux':
-        _ensure_set_env_var("LD_LIBRARY_PATH", lib_path)
         if os.getenv('MUJOCO_PY_FORCE_CPU') is None and get_nvidia_lib_dir() is not None:
-            _ensure_set_env_var("LD_LIBRARY_PATH", get_nvidia_lib_dir())
             Builder = LinuxGPUExtensionBuilder
         else:
             Builder = LinuxCPUExtensionBuilder
@@ -89,6 +87,13 @@
     builder = Builder(mujoco_path)
     cext_so_path = builder.get_so_file_path()
 
+    # Check if we have write access to the cext_so_path.
+    # If not, it's probably because mujoco-py has been installed and everything is
+    # read-only. Returning here is necessary because the lock creation will fail.
+    # It might be better to try-catch the lock but this minimizes the diff complexity.
+    if not os.access(os.path.dirname(cext_so_path), os.W_OK):
+        return load_dynamic_ext('cymj', cext_so_path)
+
     lockpath = os.path.join(os.path.dirname(cext_so_path), 'mujocopy-buildlock')
 
     with fasteners.InterProcessLock(lockpath):
@@ -177,8 +182,8 @@
 
     # Fix the rpath of the generated library -- i lost the Stackoverflow
     # reference here
-    from_mujoco_path = '@executable_path/libmujoco210.dylib'
-    to_mujoco_path = '%s/libmujoco210.dylib' % mj_bin_path
+    from_mujoco_path = '@executable_path/libmujoco.dylib'
+    to_mujoco_path = '%s/libmujoco.dylib' % mj_bin_path
     subprocess.check_call(['install_name_tool',
                            '-change',
                            from_mujoco_path,
@@ -210,11 +215,10 @@
             sources=[join(self.CYMJ_DIR_PATH, "cymj.pyx")],
             include_dirs=[
                 self.CYMJ_DIR_PATH,
-                join(mujoco_path, 'include'),
+                "/usr/include/mujoco",
                 np.get_include(),
             ],
-            libraries=['mujoco210'],
-            library_dirs=[join(mujoco_path, 'bin')],
+            libraries=['mujoco'],
             extra_compile_args=[
                 '-fopenmp',  # needed for OpenMP
                 '-w',  # suppress numpy compilation warnings
@@ -271,14 +275,13 @@
 
         self.extension.sources.append(
             join(self.CYMJ_DIR_PATH, "gl", "osmesashim.c"))
-        self.extension.libraries.extend(['glewosmesa', 'OSMesa', 'GL'])
-        self.extension.runtime_library_dirs = [join(mujoco_path, 'bin')]
+        self.extension.libraries.extend(['GLEW', 'OSMesa', 'GL'])
 
     def _build_impl(self):
         so_file_path = super()._build_impl()
         # Removes absolute paths to libraries. Allows for dynamic loading.
-        fix_shared_library(so_file_path, 'libmujoco210.so', 'libmujoco210.so')
-        fix_shared_library(so_file_path, 'libglewosmesa.so', 'libglewosmesa.so')
+        fix_shared_library(so_file_path, 'libmujoco.so', 'libmujoco.so')
+        fix_shared_library(so_file_path, 'libGLEW.so', 'libGLEW.so')
         return so_file_path
 
 
@@ -289,15 +292,14 @@
 
         self.extension.sources.append(self.CYMJ_DIR_PATH + "/gl/eglshim.c")
         self.extension.include_dirs.append(self.CYMJ_DIR_PATH + '/vendor/egl')
-        self.extension.libraries.extend(['glewegl'])
-        self.extension.runtime_library_dirs = [join(mujoco_path, 'bin')]
+        self.extension.libraries.extend(['GLEW'])
 
     def _build_impl(self):
         so_file_path = super()._build_impl()
         fix_shared_library(so_file_path, 'libOpenGL.so', 'libOpenGL.so.0')
         fix_shared_library(so_file_path, 'libEGL.so', 'libEGL.so.1')
-        fix_shared_library(so_file_path, 'libmujoco210.so', 'libmujoco210.so')
-        fix_shared_library(so_file_path, 'libglewegl.so', 'libglewegl.so')
+        fix_shared_library(so_file_path, 'libmujoco.so', 'libmujoco.so')
+        fix_shared_library(so_file_path, 'libGLEW.so', 'libGLEW.so')
         return so_file_path
 
 
@@ -481,9 +483,8 @@
     source_string += '\nuintptr_t __fun = (uintptr_t) fun;'
     # Link against mujoco so we can call mujoco functions from within callback
     ffibuilder.set_source(name, source_string,
-                          include_dirs=[join(mujoco_path, 'include')],
-                          library_dirs=[join(mujoco_path, 'bin')],
-                          libraries=['mujoco210'])
+                          include_dirs=["/usr/include/mujoco"],
+                          libraries=['mujoco'])
     # Catch compilation exceptions so we can cleanup partial files in that case
     try:
         library_path = ffibuilder.compile(verbose=True)
diff '--color=auto' --unified --recursive --text mujoco-py-2.1.2.14.orig/mujoco_py/utils.py mujoco-py-2.1.2.14.new/mujoco_py/utils.py
--- mujoco-py-2.1.2.14.orig/mujoco_py/utils.py	2022-03-24 00:41:08.625504331 -0400
+++ mujoco-py-2.1.2.14.new/mujoco_py/utils.py	2022-03-24 00:42:48.474603679 -0400
@@ -61,14 +61,15 @@
 def discover_mujoco():
     """
     Discovers where MuJoCo is located in the file system.
-    Currently assumes path is in ~/.mujoco
 
     Returns:
     - mujoco_path (str): Path to MuJoCo 2.1 directory.
     """
     mujoco_path = os.getenv('MUJOCO_PY_MUJOCO_PATH')
     if not mujoco_path:
-        mujoco_path = join(expanduser('~'), '.mujoco', 'mujoco210')
+        mujoco_path = join(expanduser('~'), '.mujoco', 'mujoco')
+        if not exists(mujoco_path):
+            mujoco_path = "/usr/include/mujoco"
 
     # We get lots of github issues that seem to be missing these
     # so check that mujoco is really there and raise errors if not.