diff --git a/.devcontainer/noble/devcontainer.json b/.devcontainer/noble/devcontainer.json index 2ac3e9a7..f94f861f 100644 --- a/.devcontainer/noble/devcontainer.json +++ b/.devcontainer/noble/devcontainer.json @@ -19,7 +19,7 @@ "--network=host", "--cap-add=sys_nice", // Grants the container the CAP_SYS_NICE capability, which allows the container to raise process nice values, set real-time scheduling policies, set CPU affinity, and other operations. "--security-opt", // allow core dumps - "seccomp=unconfined", // allow core dumps + "seccomp=unconfined" // allow core dumps // Uncomment for containers requiring use of nvidia GPUs // You will need to install NVIDIA Container Toolkit first // "--runtime=nvidia", diff --git a/.devcontainer/resolute/devcontainer.json b/.devcontainer/resolute/devcontainer.json new file mode 100644 index 00000000..6aa30bc1 --- /dev/null +++ b/.devcontainer/resolute/devcontainer.json @@ -0,0 +1,61 @@ +{ + "name": "mc-rtc-superbuild-resolute-image", + + // See .github/devcontainer/ubuntu-22.04/devcontainer.json to see how this image was built + // This image contains: + // - All of mc-rtc-superbuild dependencies + // - A ccache build cache built from the latest sources + // - A cython build cache built from the latest sources + // - All tools required to build the project + // - A sensible default configuration for vscode + "image": "ghcr.io/mc-rtc/mc-rtc-superbuild:resolute-devcontainer-latest", + + "mounts": [ + "type=bind,source=/tmp/.X11-unix,target=/tmp/.X11-unix,consistency=cached" + // "source=${localEnv:HOME}${localEnv:USERPROFILE}/docker-ws/mc-rtc-superbuild-noble,target=/home/vscode/workspace,type=bind,consistency=cached" + ], + + "runArgs": [ + "--network=host", + "--cap-add=sys_nice", // Grants the container the CAP_SYS_NICE capability, which allows the container to raise process nice values, set real-time scheduling policies, set CPU affinity, and other operations. + "--security-opt", // allow core dumps + "seccomp=unconfined" // allow core dumps + // Uncomment for containers requiring use of nvidia GPUs + // You will need to install NVIDIA Container Toolkit first + // "--runtime=nvidia", + // "--gpus=all", + ], + + + "containerEnv": { + "DISPLAY": "${localEnv:DISPLAY}" + }, + + "remoteUser": "vscode", + "workspaceMount": "source=${localWorkspaceFolder},target=/home/vscode/superbuild,type=bind", + "workspaceFolder": "/home/vscode/superbuild", + + "features": + { + "ghcr.io/devcontainers/features/node:1": {}, + "ghcr.io/arntanguy/nvim-devcontainer-feature/nvim:latest": {}, + "ghcr.io/devcontainers/features/github-cli": { "version": "latest" }, + "ghcr.io/georgofenbeck/features/lazygit-linuxbinary:1": { "version": "latest" } + }, + + "customizations": { + "vscode": { + "extensions": [ + "twxs.cmake", + "ms-vscode.cmake-tools", + "josetr.cmake-language-support-vscode", + "ms-vscode.cpptools", + "ms-vscode.docker", + "ms-vscode.cpptools-extension-pack", + "ms-vscode-remote.remote-containers", + "ms-python.python", + "GitHub.vscode-github-actions" + ] + } + } +} diff --git a/.github/devcontainer/Dockerfile b/.github/devcontainer/Dockerfile index 43ed1251..166eb653 100644 --- a/.github/devcontainer/Dockerfile +++ b/.github/devcontainer/Dockerfile @@ -193,7 +193,7 @@ RUN --mount=type=cache,target=/var/cache/apt \ # Workaround screen refresh issues with neovim/ncurses ENV TERM="xterm-256color" RUN \ - if [ "$UBUNTU_VERSION" = "noble" ]; then \ + if [ "$UBUNTU_VERSION" = "noble" ] || [ "$UBUNTU_VERSION" = "resolute" ]; then \ apt install --no-install-recommends -y libtinfo6 ncurses-term; \ else \ apt install --no-install-recommends -y libtinfo5 ncurses-term; \ @@ -203,7 +203,7 @@ RUN \ # Rename ubuntu user to vscode (noble) # Create a new vscode user (jammy) RUN \ - if [ "$UBUNTU_VERSION" = "noble" ]; then \ + if [ "$UBUNTU_VERSION" = "noble" ] || [ "$UBUNTU_VERSION" = "resolute" ]; then \ usermod -l vscode ubuntu \ && usermod -d /home/vscode -m vscode \ && groupmod -n vscode ubuntu; \ @@ -255,7 +255,8 @@ RUN cp $SUPERBUILD_DIR/.devcontainer/docker-entrypoint.sh ~/.docker-entrypoint.s # CMake configure will install all APT/PIP dependencies (keep downloaded packages in mounted APT cache) RUN --mount=type=cache,target=/var/cache/apt \ --mount=type=ssh,uid=1000 \ - .github/devcontainer/build_superbuild.sh + mkdir -p $CCACHE_IMAGE_DIR \ + && .github/devcontainer/build_superbuild.sh # mc_rtc configuration copy if MC_RTC_CONTROLLER_CONFIG is set and file exists RUN mkdir -p ~/.config/mc_rtc && \ diff --git a/.github/devcontainer/build_superbuild.sh b/.github/devcontainer/build_superbuild.sh index 10680b13..e6a83281 100755 --- a/.github/devcontainer/build_superbuild.sh +++ b/.github/devcontainer/build_superbuild.sh @@ -6,6 +6,7 @@ if [ "$BUILD_SUPERBUILD" != "true" ]; then echo "SUPERBUILD: Skipping build because BUILD_SUPERBUILD=$BUILD_SUPERBUILD" else ./utils/bootstrap-linux.sh + source ~/.mc-rtc-venv/bin/activate git config --global user.email "$EMAIL" && git config --global user.name "$NAME" # CMake configure will install all APT/PIP dependencies (keep downloaded packages in mounted APT cache) diff --git a/.github/devcontainer/jammy/devcontainer.json b/.github/devcontainer/jammy/devcontainer.json index 96c1c67e..9513fc3e 100644 --- a/.github/devcontainer/jammy/devcontainer.json +++ b/.github/devcontainer/jammy/devcontainer.json @@ -3,6 +3,7 @@ "build": { "dockerfile": "../Dockerfile", + "target": "devcontainer", "context": "../../..", "args": { diff --git a/.github/devcontainer/noble/devcontainer.json b/.github/devcontainer/noble/devcontainer.json index 7738195e..1307e8e3 100644 --- a/.github/devcontainer/noble/devcontainer.json +++ b/.github/devcontainer/noble/devcontainer.json @@ -3,10 +3,11 @@ "build": { "dockerfile": "../Dockerfile", + "target": "devcontainer", "context": "../../..", "args": { - "CMAKE_PRESET": "${localEnv:CMAKE_PRESET:relwithdebinfo-noble}", + "CMAKE_PRESET": "${localEnv:CMAKE_PRESET:relwithdebinfo}", "BUILD_VERSION": "${localEnv:BUILD_VERSION:devcontainer}", "IMAGE_SOURCE_REPO": "", "UBUNTU_VERSION": "noble" @@ -48,13 +49,13 @@ "GitHub.vscode-github-actions" ] } - } + }, "runArgs": [ "--network=host", "--cap-add=sys_nice", // Grants the container the CAP_SYS_NICE capability, which allows the container to raise process nice values, set real-time scheduling policies, set CPU affinity, and other operations. "--security-opt", // allow core dumps - "seccomp=unconfined", // allow core dumps + "seccomp=unconfined" // allow core dumps // Uncomment for containers requiring use of nvidia GPUs // You will need to install NVIDIA Container Toolkit first // "--runtime=nvidia", diff --git a/.github/devcontainer/resolute/devcontainer.json b/.github/devcontainer/resolute/devcontainer.json new file mode 100644 index 00000000..79350cb9 --- /dev/null +++ b/.github/devcontainer/resolute/devcontainer.json @@ -0,0 +1,71 @@ +{ + "name": "mc-rtc-superbuild-resolute-build", + + "build": { + "dockerfile": "../Dockerfile", + "target": "devcontainer", + "context": "../../..", + "args": + { + "CMAKE_PRESET": "${localEnv:CMAKE_PRESET:relwithdebinfo}", + "BUILD_VERSION": "${localEnv:BUILD_VERSION:devcontainer}", + "IMAGE_SOURCE_REPO": "", + "UBUNTU_VERSION": "resolute", + // FIXME + "BUILD_SUPERBUILD": "false" + }, + "options": + [ + // "${localEnv:SSH_OPT:''}" + "${localEnv:SSH_OPT:--ssh=default}" + ] + }, + + "containerEnv": { + "DISPLAY": "${localEnv:DISPLAY}" + }, + + "mounts": [ + "type=bind,source=/tmp/.X11-unix,target=/tmp/.X11-unix,consistency=cached", + "source=${localEnv:HOME}${localEnv:USERPROFILE}/devcontainers/volumes/mc-rtc-superbuild-resolute,target=/home/vscode/workspace,type=bind,consistency=cached" + ], + + "features": + { + "ghcr.io/devcontainers/features/node:1": {}, + // "ghcr.io/arntanguy/nvim-devcontainer-feature/nvim:latest": {}, + "ghcr.io/devcontainers/features/github-cli": { "version": "latest" }, + "ghcr.io/georgofenbeck/features/lazygit-linuxbinary:1": { "version": "latest" } + }, + + "customizations": { + "vscode": { + "extensions": [ + "twxs.cmake", + "ms-vscode.cmake-tools", + "josetr.cmake-language-support-vscode", + "ms-vscode.cpptools", + "ms-vscode.docker", + "ms-vscode.cpptools-extension-pack", + "ms-vscode-remote.remote-containers", + "ms-python.python", + "GitHub.vscode-github-actions" + ] + } + }, + + "runArgs": [ + "--network=host", + "--cap-add=sys_nice", // Grants the container the CAP_SYS_NICE capability, which allows the container to raise process nice values, set real-time scheduling policies, set CPU affinity, and other operations. + "--security-opt", // allow core dumps + "seccomp=unconfined" // allow core dumps + // Uncomment for containers requiring use of nvidia GPUs + // You will need to install NVIDIA Container Toolkit first + // "--runtime=nvidia", + // "--gpus=all", + ], + + "remoteUser": "vscode", + "workspaceMount": "source=${localWorkspaceFolder},target=/home/vscode/superbuild,type=bind", + "workspaceFolder": "/home/vscode/superbuild" +} diff --git a/.github/workflows/jammy-ci.yml b/.github/workflows/build.yml similarity index 77% rename from .github/workflows/jammy-ci.yml rename to .github/workflows/build.yml index a6d800ed..c8a74100 100644 --- a/.github/workflows/jammy-ci.yml +++ b/.github/workflows/build.yml @@ -1,9 +1,9 @@ -name: CI Ubuntu Jammy +name: CI Ubuntu on: repository_dispatch: types: - - build-jammy + - build push: branches: - 'main' @@ -21,15 +21,21 @@ concurrency: jobs: run: + name: "${{ matrix.os }}, use apt: ${{ matrix.use-mc-rtc-apt-mirror }} (stable: ${{ matrix.use-mc-rtc-apt-mirror-stable }})" strategy: fail-fast: false matrix: use-mc-rtc-apt-mirror: [ON, OFF] use-mc-rtc-apt-mirror-stable: [ON, OFF] + # TODO: add ubuntu-26.04 once the github runner is available + os: [ ubuntu-22.04, ubuntu-24.04 ] exclude: - use-mc-rtc-apt-mirror: OFF use-mc-rtc-apt-mirror-stable: ON - runs-on: ubuntu-22.04 + # TODO: generate packages for 24.04 + - os: ubuntu-24.04 + use-mc-rtc-apt-mirror: ON + runs-on: ${{ matrix.os }} steps: - name: Maximize build space shell: bash @@ -54,14 +60,16 @@ jobs: shell: bash run: | ./utils/bootstrap-linux.sh - - name: Install system dependencies + - name: Configure superbuild shell: bash run: | + source ~/.mc-rtc-venv/bin/activate mkdir -p ${TMPDIR-/tmp}/build-mc-rtc cmake -S ${GITHUB_WORKSPACE} -B ${TMPDIR-/tmp}/build-mc-rtc -DCMAKE_BUILD_TYPE=RelWithDebInfo -DVERBOSE_TEST_OUTPUT=ON -DUSE_MC_RTC_APT_MIRROR=${{ matrix.use-mc-rtc-apt-mirror }} -DUSE_MC_RTC_APT_MIRROR_STABLE=${{ matrix.use-mc-rtc-apt-mirror-stable }} - name: Install mc_rtc and related projects shell: bash run: | + source ~/.mc-rtc-venv/bin/activate git config --global user.name "GitHub Actions" git config --global user.email "actions@example.com" cmake --build ${TMPDIR-/tmp}/build-mc-rtc --config RelWithDebInfo diff --git a/.github/workflows/devcontainer-ci.yaml b/.github/workflows/devcontainer-ci.yaml index 50b4c227..a4cf56fd 100644 --- a/.github/workflows/devcontainer-ci.yaml +++ b/.github/workflows/devcontainer-ci.yaml @@ -5,6 +5,7 @@ on: types: - build-jammy - build-noble + - build-resolute push: branches: - 'main' @@ -22,18 +23,20 @@ jobs: strategy: fail-fast: false matrix: - os: [jammy, noble] + os: [jammy, noble, resolute] uses: jrl-umi3218/github-actions/.github/workflows/superbuild-devcontainer.yml@master with: runner: ubuntu-24.04 free-disk-space: true os: ${{ matrix.os }} - preset: relwithdebinfo${{ matrix.os == 'noble' && '-noble' || '' }} + preset: relwithdebinfo include-preset-in-name: false build-standalone-release: true build-standalone-devel: true build-devcontainer: true - container-repository: ghcr.io/mc-rtc/mc-rtc-superbuild - push: ${{ github.ref == 'refs/heads/main' && github.repository == 'mc-rtc/mc-rtc-superbuild' }} + # container-repository: ghcr.io/mc-rtc/mc-rtc-superbuild + # push: ${{ github.ref == 'refs/heads/main' && github.repository == 'mc-rtc/mc-rtc-superbuild' }} + container-repository: ghcr.io/arntanguy/mc-rtc-superbuild + push: ${{ github.ref == 'refs/heads/topic/noble' }} secrets: SSH_KEY: ${{ secrets.SSH_KEY }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a6b55d3..ec11119a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,8 @@ if(EMSCRIPTEN) ) endif() +include(cmake/detect-system.cmake) +include(cmake/python.cmake) include(cmake/project.cmake) if(APPLE) diff --git a/CMakePresets.json b/CMakePresets.json index 8dc03308..f3ac077f 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -11,7 +11,8 @@ "CMAKE_BUILD_TYPE": "RelWithDebInfo", "SOURCE_DESTINATION": "${sourceDir}/../workspace/devel", "BUILD_DESTINATION": "${sourceDir}/../workspace/build/projects", - "CMAKE_INSTALL_PREFIX": "${sourceDir}/../workspace/install" + "CMAKE_INSTALL_PREFIX": "${sourceDir}/../workspace/install", + "MC_RTC_SUPERBUILD_VERBOSE": "ON" } }, { @@ -23,22 +24,6 @@ "cacheVariables": { "BUILD_TESTING": "OFF" } - }, - { - "name": "relwithdebinfo-noble", - "displayName": "RelWithDebInfo (noble, ROS, no Python)", - "inherits": [ - "relwithdebinfo" - ], - "cacheVariables": { - "PYTHON_BINDING": "OFF", - "WITH_ROS_SUPPORT": "ON" - }, - "condition": { - "type": "equals", - "lhs": "$env{UBUNTU_VERSION}", - "rhs": "noble" - } } ], "buildPresets": [ @@ -59,15 +44,6 @@ "targets": [ "install" ] - }, - { - "name": "relwithdebinfo-noble", - "displayName": "RelWithDebInfo (ubuntu noble)", - "configurePreset": "relwithdebinfo-noble", - "configuration": "RelWithDebInfo", - "targets": [ - "install" - ] } ] } diff --git a/cmake/command-prefix.cmake b/cmake/command-prefix.cmake index fef115be..4439ac44 100644 --- a/cmake/command-prefix.cmake +++ b/cmake/command-prefix.cmake @@ -15,7 +15,6 @@ function(GetCommandPrefix VAR WRITE_TO) APPEND CMAKE_COMMAND_PREFIX ROS_DISTRO=$ENV{ROS_DISTRO} - PYTHONPATH=$ENV{PYTHONPATH} ROS_ROOT=$ENV{ROS_ROOT} ROS_ETC_DIR=$ENV{ROS_ETC_DIR} ROS_PARALLEL_JOBS="$ENV{ROS_PARALLEL_JOBS}" @@ -48,6 +47,10 @@ function(GetCommandPrefix VAR WRITE_TO) "LDFLAGS=-s USE_PTHREADS=1 -s DISABLE_EXCEPTION_CATCHING=0" ) endif() + # python + list(APPEND CMAKE_COMMAND_PREFIX PATH=$ENV{VIRTUAL_ENV}/bin:$ENV{PATH} + VIRTUAL_ENV=$ENV{VIRTUAL_ENV} PYTHONPATH=$ENV{PYTHONPATH} + ) list(TRANSFORM CMAKE_COMMAND_PREFIX REPLACE " " "\\\\ " OUTPUT_VARIABLE CMAKE_COMMAND_PREFIX ) # restore backslash before spaces in env variables @@ -58,4 +61,6 @@ function(GetCommandPrefix VAR WRITE_TO) ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/scripts/cmake-with-prefix.cmake -- PARENT_SCOPE ) + # FIXME + message(STATUS "CMAKE_COMMAND_PREFIX IS ${CMAKE_COMMAND_PREFIX}") endfunction() diff --git a/cmake/detect-system.cmake b/cmake/detect-system.cmake new file mode 100644 index 00000000..fbff70af --- /dev/null +++ b/cmake/detect-system.cmake @@ -0,0 +1,13 @@ +macro(detect_distro OUT_VAR) + find_program(LSB_RELEASE lsb_release) + if(NOT LSB_RELEASE) + message(FATAL_ERROR "lsb_release must be installed before running this script") + endif() + execute_process( + COMMAND lsb_release -sc + OUTPUT_VARIABLE ${OUT_VAR} + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +endmacro() + +detect_distro(DISTRO) diff --git a/cmake/linux-dependencies.cmake b/cmake/linux-dependencies.cmake index 6f5e4154..c6ec4924 100644 --- a/cmake/linux-dependencies.cmake +++ b/cmake/linux-dependencies.cmake @@ -1,16 +1,5 @@ -find_program(LSB_RELEASE lsb_release) - -if(NOT LSB_RELEASE) - message(FATAL_ERROR "lsb_release must be installed before running this script") -endif() - set(ROS_IS_ROS2 OFF) set(APT_HAS_PYTHON2_PACKAGES ON) -execute_process( - COMMAND lsb_release -sc - OUTPUT_VARIABLE DISTRO - OUTPUT_STRIP_TRAILING_WHITESPACE -) if(EXISTS ${PROJECT_SOURCE_DIR}/cmake/linux/${DISTRO}.cmake) include(${PROJECT_SOURCE_DIR}/cmake/linux/${DISTRO}.cmake) @@ -47,6 +36,9 @@ if(DPKG) endif() endif() +message(STATUS "Installing pip dependencies ${PIP_DEPENDENCIES}") +execute_process(COMMAND pip install ${PIP_DEPENDENCIES}) + if(WITH_ROS_SUPPORT AND ROS_DISTRO) if(DPKG) if(${DISTRO} STREQUAL "buster") diff --git a/cmake/linux/noble.cmake b/cmake/linux/noble.cmake index 17f33059..1958d271 100644 --- a/cmake/linux/noble.cmake +++ b/cmake/linux/noble.cmake @@ -9,9 +9,6 @@ set(APT_DEPENDENCIES cmake build-essential gfortran - cython3 - # python3-nose python3-pytest python3-numpy python3-coverage python3-setuptools - # python3-pip libeigen3-dev libboost-all-dev libtinyxml2-dev @@ -27,6 +24,8 @@ set(APT_DEPENDENCIES libnotify-dev # python3-git ) +set(PIP_DEPENDENCIES cython numpy coverage setuptools pytest) + if(BUILD_BENCHMARKS) list(APPEND APT_DEPENDENCIES libbenchmark-dev) endif() diff --git a/cmake/linux/resolute.cmake b/cmake/linux/resolute.cmake new file mode 100644 index 00000000..36330973 --- /dev/null +++ b/cmake/linux/resolute.cmake @@ -0,0 +1,56 @@ +set(MC_LOG_UI_PYTHON_EXECUTABLE python3) +set(APT_HAS_PYTHON2_PACKAGES OFF) +set(ROS_IS_ROS2 ON) +set(ROS_DISTRO lyrical) +set(ROS_WORKSPACE_INSTALL_PYTHON_DESTINATION "lib/python3.14/site-packages") +set(APT_DEPENDENCIES + curl + wget + cmake + build-essential + gfortran + rapidjson-dev + libeigen3-dev + libboost-all-dev + libtinyxml2-dev + libgeos++-dev + libnanomsg-dev + libyaml-cpp-dev + libltdl-dev + libqwt-qt5-dev + # python3-matplotlib python3-pyqt5 + libspdlog-dev + ninja-build + # python-is-python3 + libnotify-dev + # python3-git +) +set(PIP_DEPENDENCIES cython numpy coverage setuptools pytest) + +if(BUILD_BENCHMARKS) + list(APPEND APT_DEPENDENCIES libbenchmark-dev) +endif() +if(INSTALL_DOCUMENTATION) + list(APPEND APT_DEPENDENCIES doxygen doxygen-latex) +endif() + +function(mc_rtc_extra_steps) + if(PYTHON_BINDING_BUILD_PYTHON2_AND_PYTHON3 OR PYTHON_BINDING_FORCE_PYTHON2) + message( + FATAL_ERROR + "Python 2 is not supported on Resolute, disable PYTHON_BINDING or enable Python 3 binding only" + ) + endif() +endfunction() + +AddProject( + geos-cpp-inline + GITHUB isri-aist/geos-cpp-inline-deb + GIT_TAG origin/main + INSTALL_PREFIX /usr + SKIP_TEST NO_SOURCE_MONITOR + APT_PACKAGES libgeos++-inline-dev +) +list(APPEND GLOBAL_DEPENDS geos-cpp-inline) + +include(${CMAKE_CURRENT_LIST_DIR}/mc-rtc-mirror.cmake) diff --git a/cmake/macos-dependencies.cmake b/cmake/macos-dependencies.cmake index 991e682f..7528bf5e 100644 --- a/cmake/macos-dependencies.cmake +++ b/cmake/macos-dependencies.cmake @@ -65,8 +65,7 @@ if(INSTALL_SYSTEM_DEPENDENCIES) ) endif() execute_process( - COMMAND sudo ${MC_RTC_SUPERBUILD_DEFAULT_PYTHON} -m pip install - ${PIP_DEPENDENCIES} + COMMAND ${MC_RTC_SUPERBUILD_DEFAULT_PYTHON} -m pip install ${PIP_DEPENDENCIES} ) endif() endif() diff --git a/cmake/options.cmake b/cmake/options.cmake index b9f01d7b..8b56094b 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -39,7 +39,6 @@ set(BUILD_PARALLEL_JOBS # ###################################################################################### set(PYTHON_BINDING_DEFAULT ON) set(PYTHON_BINDING_FORCE_PYTHON3_DEFAULT ON) -set(PYTHON_BINDING_FORCE_PYTHON2_DEFAULT OFF) option(CYTHON_USE_CCACHE "Use CCache for Cython compilation" ON) find_program(MC_RTC_SUPERBUILD_DEFAULT_PYTHON python3) @@ -47,12 +46,7 @@ if(NOT MC_RTC_SUPERBUILD_DEFAULT_PYTHON) set(PYTHON_BINDING_FORCE_PYTHON3_DEFAULT OFF) find_program(MC_RTC_SUPERBUILD_DEFAULT_PYTHON python) if(NOT MC_RTC_SUPERBUILD_DEFAULT_PYTHON) - find_program(MC_RTC_SUPERBUILD_DEFAULT_PYTHON python2) - if(MC_RTC_SUPERBUILD_DEFAULT_PYTHON) - set(PYTHON_BINDING_FORCE_PYTHON2_DEFAULT ON) - else() - set(PYTHON_BINDING_DEFAULT OFF) - endif() + set(PYTHON_BINDING_DEFAULT OFF) endif() endif() @@ -67,7 +61,10 @@ if(MC_RTC_SUPERBUILD_DEFAULT_PYTHON) OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET ) if(MC_RTC_SUPERBUILD_DEFAULT_PYTHON_USER_BASE STREQUAL "") - message(FATAL_ERROR "Failed to find Python user base directory") + message( + FATAL_ERROR + "Failed to find Python user base directory: ${MC_RTC_SUPERBUILD_DEFAULT_PYTHON}" + ) endif() if(WIN32) execute_process( @@ -85,6 +82,34 @@ if(MC_RTC_SUPERBUILD_DEFAULT_PYTHON) "${MC_RTC_SUPERBUILD_DEFAULT_PYTHON_USER_BASE}/bin" ) endif() + if(DISTRO STREQUAL "noble") + # on ubuntu noble onwards, pip requires a virtualenv + # detect if we are already in one and if not create one for mc-rtc + + # Check if we are already in a virtualenv + execute_process( + COMMAND + python3 -c + "import sys; exit(0) if (hasattr(sys, 'real_prefix') or (getattr(sys, 'base_prefix', sys.prefix) != sys.prefix)) else exit(1)" + RESULT_VARIABLE IN_VENV # 0 if in venv, 1 otherwise + ) + if(IN_VENV EQUAL 0) + message(STATUS "Already in the expected Python virtualenv: $ENV{VIRTUAL_ENV}") + else() + message( + FATAL_ERROR + "You must create or activate a python virtualenv first: + +$ python3 -m venv --system-site-packages ~/.mc-rtc-venv + +Note that --system-site-packages is required in order to access ros python packages + +Then activate it with +$ source ~/.mc-rtc-venv/biin/activate +" + ) + endif() + endif() find_program( MC_RTC_SUPERBUILD_PRE_COMMIT NAMES pre-commit diff --git a/cmake/python.cmake b/cmake/python.cmake new file mode 100644 index 00000000..23812f34 --- /dev/null +++ b/cmake/python.cmake @@ -0,0 +1,13 @@ +execute_process( + COMMAND + ${MC_RTC_SUPERBUILD_DEFAULT_PYTHON} -c + "import sys; print(\"python{}.{}\".format(sys.version_info.major, sys.version_info.minor));" + OUTPUT_VARIABLE PYTHON_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +set(ENV{PYTHONPATH} + "${CMAKE_INSTALL_PREFIX}/lib/${PYTHON_VERSION}/site-packages:$ENV{PYTHONPATH}" +) +set(ENV{PATH} "$ENV{VIRTUAL_ENV}/bin:$ENV{PATH}") +message(WARNING "python: PATH is $ENV{PATH}") diff --git a/mc_rtc.cmake b/mc_rtc.cmake index f08ce82b..1878a014 100644 --- a/mc_rtc.cmake +++ b/mc_rtc.cmake @@ -41,7 +41,8 @@ if(PYTHON_BINDING) AddProject( Eigen3ToPython GITHUB jrl-umi3218/Eigen3ToPython - GIT_TAG origin/master + # GIT_TAG origin/master + GIT_TAG origin/python-venv CMAKE_ARGS -DPIP_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} APT_PACKAGES python-eigen python3-eigen ) @@ -51,7 +52,9 @@ endif() AddProject( SpaceVecAlg GITHUB jrl-umi3218/SpaceVecAlg - GIT_TAG origin/master + # GIT_TAG origin/master + GIT_TAG origin/python-venv + CMAKE_ARGS -DPython3_EXECUTABLE=${MC_RTC_SUPERBUILD_DEFAULT_PYTHON} DEPENDS ${SpaceVecAlg_DEPENDS} APT_PACKAGES libspacevecalg-dev python-spacevecalg python3-spacevecalg ) @@ -82,7 +85,8 @@ if(PYTHON_BINDING) AddProject( sch-core-python GITHUB jrl-umi3218/sch-core-python - GIT_TAG origin/master + #GIT_TAG origin/master + GIT_TAG origin/python-venv CMAKE_ARGS -DPIP_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} DEPENDS sch-core SpaceVecAlg APT_PACKAGES python-sch-core python3-sch-core @@ -92,7 +96,8 @@ endif() AddProject( RBDyn GITHUB jrl-umi3218/RBDyn - GIT_TAG origin/master + # GIT_TAG origin/master + GIT_TAG origin/python-venv DEPENDS SpaceVecAlg APT_PACKAGES librbdyn-dev python-rbdyn python3-rbdyn ) @@ -109,7 +114,8 @@ endif() AddProject( eigen-qld GITHUB jrl-umi3218/eigen-qld - GIT_TAG origin/master + #GIT_TAG origin/master + GIT_TAG origin/python-venv NO_NINJA NO_COLOR CMAKE_ARGS ${USE_F2C_ARGS} APT_PACKAGES libeigen-qld-dev python-eigen-qld python3-eigen-qld @@ -147,7 +153,8 @@ endif() AddProject( Tasks GITHUB jrl-umi3218/Tasks - GIT_TAG origin/master + # GIT_TAG origin/master + GIT_TAG origin/python-venv DEPENDS ${Tasks_DEPENDS} APT_PACKAGES libtasks-qld-dev python-tasks python3-tasks ) @@ -228,7 +235,8 @@ if(WITH_ROS_SUPPORT) GITHUB jrl-umi3218/mc_rtc_msgs GIT_TAG origin/master WORKSPACE data_ws - APT_PACKAGES ros-${ROS_DISTRO}-mc-rtc-msgs + APT_PACKAGES ros-${ROS_DISTRO}-mc-rtc-msgs ros-${ROS_DISTRO}-rosidl-adapter + python3-empy ) list(APPEND mc_rtc_DEPENDS mc_rtc_msgs) list(APPEND mc_rtc_APT_PACKAGES ros-${ROS_DISTRO}-mc-rtc-plugin) @@ -259,8 +267,10 @@ else() endif() AddProject( mc_rtc - GITHUB jrl-umi3218/mc_rtc - GIT_TAG origin/master + # GITHUB jrl-umi3218/mc_rtc + GITHUB arntanguy/mc_rtc + #GIT_TAG origin/master + GIT_TAG origin/python-venv CMAKE_ARGS -DMC_LOG_UI_PYTHON_EXECUTABLE=${MC_LOG_UI_PYTHON_EXECUTABLE} ${MC_RTC_ROS_OPTION} ${MC_RTC_EXTRA_OPTIONS} DEPENDS ${mc_rtc_DEPENDS} diff --git a/utils/bootstrap-linux.sh b/utils/bootstrap-linux.sh index 5c33d9cd..3554a7fb 100755 --- a/utils/bootstrap-linux.sh +++ b/utils/bootstrap-linux.sh @@ -19,11 +19,7 @@ then fi ${SUDO} apt-get update -${SUDO} apt-get install -y --no-install-recommends wget apt-transport-https software-properties-common gnupg lsb-release build-essential gfortran curl git sudo cmake cmake-curses-gui python3-pip ccache -if [[ `lsb_release -cs` == "noble" ]] -then - ${SUDO} apt-get install -y --no-install-recommends pipx -fi +${SUDO} apt-get install -y --no-install-recommends wget apt-transport-https software-properties-common gnupg lsb-release build-essential gfortran curl git sudo cmake cmake-curses-gui python3-pip pipx ccache if [[ `lsb_release -si` == "Ubuntu" ]] then @@ -39,12 +35,22 @@ else ${SUDO} /tmp/cmake-${CMAKE_VERSION_FULL} --skip-license --prefix=/usr --exclude-subdir fi -if [[ ! -f $HOME/.local/bin/pre-commit ]] +if ! command -v pre-commit &> /dev/null then - if [[ `lsb_release -cs` == "noble" ]] - then + echo "pre-commit not found. Installing via pipx..." pipx install pre-commit - else - /usr/bin/python3 -m pip install --user pre-commit - fi + pipx ensurepath +else + echo "pre-commit is already installed." +fi + +if [[ "$VIRTUAL_ENV" == "" ]] +then + echo "You are not in a python virtual environment, creating a default one in ~/.mc-rtc-venv" + # enable system-site-packages so that we can use ROS python packages + python3 -m venv --system-site-packages ~/.mc-rtc-venv + source ~/.mc-rtc-venv/bin/activate + echo "You must activate a python virtual environment before building + source ~/.mc-rtc-venv/bin/activate + " fi