Build Python bindings in build.yml.

We currently skip building the Python bindings on Windows since MSVC takes an hour+ on them. Internally, we use Clang for our Windows build, so are not affected by this issue.

PiperOrigin-RevId: 450914163
Change-Id: I329aab28f3a2aeb1896242a8712f89d8ecff2f92
This commit is contained in:
Saran Tunyasuvunakool
2022-05-25 07:01:19 -07:00
committed by Copybara-Service
parent 223874c4ca
commit aefab0e9dc
5 changed files with 110 additions and 41 deletions
+105 -26
View File
@@ -2,6 +2,9 @@
# It is not the same configuration that is used by DeepMind to create release binaries.
# The "official" binaries are built with Clang 13 on all platforms, and are linked against libc++
# on Linux.
#
# We set CMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF here to reduce build time.
# It is highly recommended that this is set to ON for production builds.
name: build
@@ -16,46 +19,122 @@ jobs:
strategy:
matrix:
include:
- os: ubuntu-20.04
additional_label: "with GCC 10"
cmake_args: "-G Ninja -DCMAKE_C_COMPILER:STRING=gcc-10 -DCMAKE_CXX_COMPILER:STRING=g++-10"
- os: ubuntu-20.04
- os: ubuntu-22.04
additional_label: "with GCC 11"
cmake_args: >-
-G Ninja
-DCMAKE_C_COMPILER:STRING=gcc-11
-DCMAKE_CXX_COMPILER:STRING=g++-11
tmpdir: "/tmp"
- os: ubuntu-22.04
additional_label: "with Clang 12"
cmake_args: "-G Ninja -DCMAKE_C_COMPILER:STRING=clang-12 -DCMAKE_CXX_COMPILER:STRING=clang++-12 -DMUJOCO_HARDEN:BOOL=ON"
cmake_args: >-
-G Ninja
-DCMAKE_C_COMPILER:STRING=clang-12
-DCMAKE_CXX_COMPILER:STRING=clang++-12
-DMUJOCO_HARDEN:BOOL=ON
tmpdir: "/tmp"
- os: macos-12
cmake_args: "-G Ninja -DMUJOCO_HARDEN:BOOL=ON"
cmake_args: >-
-G Ninja
-DMUJOCO_HARDEN:BOOL=ON
tmpdir: "/tmp"
- os: windows-2022
cmake_build_args: "-- /MP"
cmake_build_args: "-- -m"
tmpdir: "C:/Temp"
name: "MuJoCo on ${{ matrix.os }} ${{ matrix.additional_label }}"
runs-on: ${{ matrix.os }}
env:
CMAKE_ARGS: ${{ matrix.cmake_args }}
CMAKE_BUILD_ARGS: ${{ matrix.cmake_build_args }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Prepare Linux
if: ${{ runner.os == 'Linux' }}
run: |
sudo apt-get install \
libgl1-mesa-dev \
libxinerama-dev \
libxcursor-dev \
libxrandr-dev \
libxi-dev \
ninja-build
run: >
sudo apt-get install
libgl1-mesa-dev
libxinerama-dev
libxcursor-dev
libxrandr-dev
libxi-dev
ninja-build
- name: Prepare macOS
if: ${{ runner.os == 'macOS' }}
run: brew install ninja
- name: Configure
- uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Prepare Python
shell: bash
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE:STRING=Release $CMAKE_ARGS
- name: Build
cd ${{ matrix.tmpdir }}
python -m venv venv
if [[ $RUNNER_OS == "Windows" ]]; then
mkdir venv/bin
fixpath="$(s="$(cat venv/Scripts/activate | grep VIRTUAL_ENV=)"; echo "${s:13:-1}")"
sed -i "s#$(printf "%q" "${fixpath}")#$(cygpath "${fixpath}")#g" venv/Scripts/activate
ln -s ../Scripts/activate venv/bin/activate
fi
source venv/bin/activate
python -m pip install --upgrade pip
pip install pytest wheel
- name: Configure MuJoCo
run: >
mkdir build &&
cd build &&
cmake ..
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_INSTALL_PREFIX:STRING=${{ matrix.tmpdir }}/mujoco_install
-DMUJOCO_BUILD_EXAMPLES:BOOL=OFF
${{ matrix.cmake_args }}
- name: Build MuJoCo
working-directory: build
run: cmake --build . --config=Release $CMAKE_BUILD_ARGS
- name: Test
run: cmake --build . --config=Release ${{ matrix.cmake_build_args }}
- name: Test MuJoCo
working-directory: build
run: ctest -C Release .
- name: Install MuJoCo
working-directory: build
run: cmake --install .
- name: Configure samples
working-directory: sample
run: >
mkdir build &&
cd build &&
cmake ..
-DCMAKE_BUILD_TYPE:STRING=Release
-Dmujoco_ROOT:STRING=${{ matrix.tmpdir }}/mujoco_install
${{ matrix.cmake_args }}
- name: Build samples
working-directory: sample/build
run: cmake --build . --config=Release ${{ matrix.cmake_build_args }}
- name: Make Python sdist
shell: bash
working-directory: python
run: >
source ${{ matrix.tmpdir }}/venv/bin/activate &&
./make_sdist.sh
- name: Build Python bindings
if: ${{ runner.os != 'Windows' }}
shell: bash
working-directory: python/dist
run: >
source ${{ matrix.tmpdir }}/venv/bin/activate &&
MUJOCO_PATH="${{ matrix.tmpdir }}/mujoco_install"
MUJOCO_CMAKE_ARGS="-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=OFF ${{ matrix.cmake_args }}"
pip wheel -v --no-deps mujoco-*.tar.gz
- name: Install Python bindings
if: ${{ runner.os != 'Windows' }}
shell: bash
working-directory: python/dist
run: >
source ${{ matrix.tmpdir }}/venv/bin/activate &&
pip install mujoco-*.whl
- name: Test Python bindings
if: ${{ runner.os != 'Windows' }}
shell: bash
env:
MUJOCO_GL: disable
run: >
source ${{ matrix.tmpdir }}/venv/bin/activate &&
pytest -v --pyargs mujoco
+2 -2
View File
@@ -21,7 +21,7 @@ fi
# Figure out the path to this script (https://stackoverflow.com/a/246128).
package_dir="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
if [[ "$(uname)" == CYGWIN* ]]; then
if [[ "$(uname)" == CYGWIN* || "$(uname)" == MINGW* ]]; then
package_dir="$(cygpath -m ${package_dir})"
readonly tmp_dir="$(TMPDIR="${LOCALAPPDATA//\\/$'/'}/Temp" mktemp -d)"
else
@@ -35,7 +35,7 @@ cp -r "${package_dir}"/* .
# Generate header files.
old_pythonpath="${PYTHONPATH}"
if [[ "$(uname)" == CYGWIN* ]]; then
if [[ "$(uname)" == CYGWIN* || "$(uname)" == MINGW* ]]; then
export PYTHONPATH="${old_pythonpath};${package_dir}/.."
else
export PYTHONPATH="${old_pythonpath}:${package_dir}/.."
+2 -6
View File
@@ -28,8 +28,7 @@ namespace mujoco::python {
namespace {
namespace py = ::pybind11;
MUJOCO_ALWAYS_INLINE
void ZeroDenominatorCheck(double b) {
inline void ZeroDenominatorCheck(double b) {
if (b == 0) {
PyErr_SetString(PyExc_ZeroDivisionError, "division by zero");
throw py::error_already_set();
@@ -37,14 +36,12 @@ void ZeroDenominatorCheck(double b) {
}
template <typename T>
MUJOCO_ALWAYS_INLINE
T FloorDiv(T a, T b) {
inline T FloorDiv(T a, T b) {
ZeroDenominatorCheck(b);
return std::floor(static_cast<double>(a) / static_cast<double>(b));
}
template <typename Trait>
MUJOCO_ALWAYS_INLINE
void DefEnum(py::module_& m) {
py::enum_<typename Trait::type> e(m, Trait::name);
for (const auto& [name, enumerator] : Trait::values) {
@@ -137,7 +134,6 @@ void DefEnum(py::module_& m) {
}
template <typename Tuple>
MUJOCO_ALWAYS_INLINE
void DefAllEnums(py::module_& m, Tuple&& tuple) {
using TupleNoRef = std::remove_reference_t<Tuple>;
if constexpr (std::tuple_size_v<TupleNoRef> != 0) {
-5
View File
@@ -55,11 +55,6 @@
_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
+1 -2
View File
@@ -196,9 +196,8 @@ class BuildCMakeExtension(build_ext.build_ext):
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"}',
f'-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL={"OFF" if self.debug else "ON"}',
'-DCMAKE_Fortran_COMPILER:STRING=',
'-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON',
'-DBUILD_TESTING:BOOL=OFF',
]