Skip to content

Commit a80c32e

Browse files
committed
fix: mujoco not found in make commands
1 parent d85f584 commit a80c32e

3 files changed

Lines changed: 33 additions & 12 deletions

File tree

.github/workflows/cpp.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ jobs:
1919
- name: Check clang format
2020
run: make cppcheckformat
2121
- name: Set up Python 3.11
22+
id: setup-python
2223
uses: actions/setup-python@v5
2324
with:
2425
python-version: "3.11"
2526
cache: "pip"
2627
- name: Clang build
27-
run: make clangcompile
28+
run: make clangcompile PYTHON_EXECUTABLE=${{ steps.setup-python.outputs.python-path }}
2829
- name: Clang Tidy
2930
run: clang-tidy -p=build --warnings-as-errors='*' $(find src -name '*.cpp' -o -name '*.cc' -name '*.h')
3031

@@ -35,9 +36,10 @@ jobs:
3536
- name: Install dependencies
3637
run: sudo apt install $(cat debian_deps.txt)
3738
- name: Set up Python 3.11
39+
id: setup-python
3840
uses: actions/setup-python@v5
3941
with:
4042
python-version: "3.11"
4143
cache: "pip"
4244
- name: GCC build
43-
run: make gcccompile
45+
run: make gcccompile PYTHON_EXECUTABLE=${{ steps.setup-python.outputs.python-path }}

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ cpplint:
1919

2020
gcccompile:
2121
pip install --upgrade --requirement requirements_dev.txt
22-
cmake -DCMAKE_BUILD_TYPE=${COMPILE_MODE} -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -B build -G Ninja
22+
cmake -DCMAKE_BUILD_TYPE=${COMPILE_MODE} -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -B build -G Ninja $(if ${PYTHON_EXECUTABLE},-DPython3_EXECUTABLE=${PYTHON_EXECUTABLE})
2323
cmake --build build --target _core
2424

2525
clangcompile:
2626
pip install --upgrade --requirement requirements_dev.txt
27-
cmake -DCMAKE_BUILD_TYPE=${COMPILE_MODE} -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -B build -G Ninja
27+
cmake -DCMAKE_BUILD_TYPE=${COMPILE_MODE} -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -B build -G Ninja $(if ${PYTHON_EXECUTABLE},-DPython3_EXECUTABLE=${PYTHON_EXECUTABLE})
2828
cmake --build build --target _core
2929

3030
# Auto generation of CPP binding stub files

cmake/FindMuJoCo.cmake

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,47 @@ if (NOT MuJoCo_FOUND)
22
if (NOT Python3_FOUND)
33
set(MuJoCo_FOUND FALSE)
44
if (MuJoCo_FIND_REQUIRED)
5-
message(FATAL_ERROR "Could not find MuJoCo. Please install MuJoCo using pip.")
5+
message(FATAL_ERROR "Could not find MuJoCo. Please install MuJoCo using pip 1.")
66
endif()
77
return()
88
endif()
99

10-
# Check if the include directory exists
11-
cmake_path(APPEND Python3_SITELIB mujoco include OUTPUT_VARIABLE MuJoCo_INCLUDE_DIRS)
10+
# Get MuJoCo path from python
11+
execute_process(
12+
COMMAND ${Python3_EXECUTABLE} -c "import mujoco; print(mujoco.__path__[0])"
13+
OUTPUT_VARIABLE MUJOCO_PATH
14+
ERROR_VARIABLE MUJOCO_PYTHON_ERROR
15+
RESULT_VARIABLE MUJOCO_PYTHON_RESULT
16+
OUTPUT_STRIP_TRAILING_WHITESPACE
17+
)
18+
19+
if (MUJOCO_PYTHON_RESULT)
20+
message(STATUS "Python command failed with result: ${MUJOCO_PYTHON_RESULT}")
21+
message(STATUS "Python command stderr: ${MUJOCO_PYTHON_ERROR}")
22+
endif()
23+
24+
if (NOT MUJOCO_PATH)
25+
set(MuJoCo_FOUND FALSE)
26+
if (MuJoCo_FIND_REQUIRED)
27+
message(FATAL_ERROR "Could not find MuJoCo. MUJOCO_PATH is empty. Python command output: '${MUJOCO_PATH}'. Python command error: '${MUJOCO_PYTHON_ERROR}'. Please install MuJoCo using pip 2.")
28+
endif()
29+
return()
30+
endif()
31+
32+
set(MuJoCo_INCLUDE_DIRS "${MUJOCO_PATH}/include")
1233
if (NOT EXISTS ${MuJoCo_INCLUDE_DIRS})
1334
set(MuJoCo_FOUND FALSE)
1435
if (MuJoCo_FIND_REQUIRED)
15-
message(FATAL_ERROR "Could not find MuJoCo. Please install MuJoCo using pip.")
36+
message(FATAL_ERROR "Could not find MuJoCo. Please install MuJoCo using pip 3.")
1637
endif()
1738
return()
1839
endif()
1940

20-
# Check if the library file exists
21-
cmake_path(APPEND Python3_SITELIB mujoco OUTPUT_VARIABLE mujoco_library_path)
22-
file(GLOB mujoco_library_path "${mujoco_library_path}/libmujoco.so.*")
41+
file(GLOB mujoco_library_path "${MUJOCO_PATH}/libmujoco.so.*")
2342
if (NOT mujoco_library_path)
2443
set(MuJoCo_FOUND FALSE)
2544
if (MuJoCo_FIND_REQUIRED)
26-
message(FATAL_ERROR "Could not find MuJoCo. Please install MuJoCo using pip.")
45+
message(FATAL_ERROR "Could not find MuJoCo. Please install MuJoCo using pip 4.")
2746
endif()
2847
return()
2948
endif()

0 commit comments

Comments
 (0)