diff --git a/.devcontainer/entrypoint.sh b/.devcontainer/entrypoint.sh index 7a5fe096..4c0e4035 100755 --- a/.devcontainer/entrypoint.sh +++ b/.devcontainer/entrypoint.sh @@ -1,12 +1,10 @@ -##!/usr/bin/env bash +#!/usr/bin/env bash echo "------" echo "Setting up environment variables..." # Makes GNUPG ask for password in the terminal export GPG_TTY=$(tty) echo "GPG_TTY=$GPG_TTY" -export CYTHON_CACHE_DIR=$HOME/.cython -echo "CYTHON_CACHE_DIR=$CYTHON_CACHE_DIR" echo "" echo "------" @@ -14,8 +12,8 @@ echo "ccache is configured as follows:" # Copy cache from the image to the local repository # This ensures that cache is kept between successive container runs echo "Synching local .ccache in your workspace with the pre-built cache in the docker image" -rsync -a ~/.cache/ccache/ ~/superbuild/.ccache --exclude='**.tmp.*' --ignore-existing -export CCACHE_DIR=$HOME/superbuild/.ccache +rsync -a ~/.cache/ccache/ ~/workspace/.ccache --exclude='**.tmp.*' --ignore-existing +export CCACHE_DIR=~/workspace/.ccache ccache -sv echo "" @@ -23,23 +21,25 @@ echo "------" echo "Welcome to mc-rtc-superbuild image for Ubuntu `lsb_release -cs`!" echo "All the tools needed to work with mc_rtc are pre-installed in this image." echo "To build, use one of the proposed cmake presets:" +echo "" cd ~/superbuild cmake --list-presets echo "" -echo '$ cmake --preset relwithdebinfo' -echo "- configures cmake and install system dependencies" +echo '$ cmake --preset relwithdebinfo # configures cmake and install system dependencies' echo "" echo '$ cmake --build --preset relwithdebinfo' -echo '- clones projects in ./devel and builds all projects in the superbuild' -echo '- generates a build folder for the superbuild in build/relwithdebinfo/superbuild' -echo '- generates a build folder for all projects superbuild in build/relwithdebinfo/projects/' +echo '- clones projects in ~/workspace/devel and builds all projects in the superbuild' +echo '- generates a build folder for the superbuild in ~/workspace/build/superbuild' +echo '- generates a build folder for all projects in ~/workspace/build/projects/' echo echo 'To update all projects in the superbuild, run:' echo '$ cmake --build --preset relwithdebinfo --target update' echo '$ cmake --build --preset relwithdebinfo' echo -echo 'Projects are installed in ./install/relwithdebinfo' -echo 'After building, please run source ./install/relwithdebinfo/setup_mc_rtc.sh' +echo 'Projects are installed in ~/workspace/install' echo echo "Please refer to README.md for more information about the superbuild." echo "" +echo "" +echo 'After building, please run source ~/workspace/install/setup_mc_rtc.sh' +echo "" diff --git a/.devcontainer/jammy/devcontainer.json b/.devcontainer/jammy/devcontainer.json index c6242796..6125635c 100644 --- a/.devcontainer/jammy/devcontainer.json +++ b/.devcontainer/jammy/devcontainer.json @@ -1,5 +1,5 @@ { - "name": "mc-rtc-superbuild-jammy-image", + "name": "mc-rtc-superbuild-jammy", // See .github/devcontainer/ubuntu-22.04/devcontainer.json to see how this image was built // This image contains: @@ -12,29 +12,18 @@ "mounts": [ // "type=bind,source=/home/${localEnv:USER}/.gitconfig,target=/home/vscode/.gitconfig", - "type=bind,source=/tmp/.X11-unix,target=/tmp/.X11-unix,consistency=cached" + "type=bind,source=/tmp/.X11-unix,target=/tmp/.X11-unix,consistency=cached", + "source=${localEnv:HOME}${localEnv:USERPROFILE}/docker-ws/mc-rtc-superbuild-jammy,target=/home/vscode/workspace,type=bind,consistency=cached" ], "features": { - // "ghcr.io/duduribeiro/devcontainer-features/neovim:1.0.1": {}, - "ghcr.io/devcontainers/features/github-cli": { "version": "latest" }, - "ghcr.io/georgofenbeck/features/lazygit-linuxbinary:1": { "version": "latest" } }, // Configure tool-specific properties. "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" ] } }, @@ -42,6 +31,12 @@ "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. + "--ulimit core=-1", // allow core dumps + "--privileged" // 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": { diff --git a/.devcontainer/noble/devcontainer.json b/.devcontainer/noble/devcontainer.json index 028f2abc..e6e27f2e 100644 --- a/.devcontainer/noble/devcontainer.json +++ b/.devcontainer/noble/devcontainer.json @@ -11,29 +11,18 @@ "image": "ghcr.io/mc-rtc/mc-rtc-superbuild:noble", "mounts": [ - "type=bind,source=/tmp/.X11-unix,target=/tmp/.X11-unix,consistency=cached" + "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" ], "features": { - // "ghcr.io/duduribeiro/devcontainer-features/neovim:1.0.1": {}, - "ghcr.io/devcontainers/features/github-cli": { "version": "latest" }, - "ghcr.io/georgofenbeck/features/lazygit-linuxbinary:1": { "version": "latest" } }, // Configure tool-specific properties. "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" ] } }, @@ -41,6 +30,12 @@ "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. + "--ulimit core=-1", // allow core dumps + "--privileged" // 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": { diff --git a/.devcontainer/setupShell.sh b/.devcontainer/setupShell.sh index 0e4a25f6..19ba63bc 100755 --- a/.devcontainer/setupShell.sh +++ b/.devcontainer/setupShell.sh @@ -1,4 +1,4 @@ -#/usr/bin/zsh +#!/usr/bin/env bash cp ~/superbuild/.devcontainer/.zshrc ~/.zshrc git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions diff --git a/.github/devcontainer/jammy/Dockerfile b/.github/devcontainer/jammy/Dockerfile index 23f76e79..e807733b 100644 --- a/.github/devcontainer/jammy/Dockerfile +++ b/.github/devcontainer/jammy/Dockerfile @@ -1,6 +1,7 @@ FROM ubuntu:jammy as build ARG EMAIL="devcontainer@mc-rtc-superbuild.com" ARG NAME="mc_rtc devcontainer" +ENV UBUNTU_VERSION="jammy" RUN export DEBIAN_FRONTEND=noninteractive ENV TZ=Europe/Paris @@ -12,7 +13,7 @@ RUN rm -f /etc/apt/apt.conf.d/docker-clean # Install sudo RUN --mount=type=cache,target=/var/cache/apt \ apt-get update \ - && apt-get install -y --no-install-recommends sudo ccache ripgrep rsync curl wget zsh gnupg2 gpg-agent python3.10-venv clangd \ + && apt-get install -y --no-install-recommends sudo ccache ripgrep rsync curl wget zsh gnupg2 gpg-agent openssh-server clangd \ && rm -rf /var/lib/apt/lists/* # Create ubuntu user with sudo privileges @@ -22,34 +23,26 @@ RUN useradd -ms /bin/zsh vscode && \ && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \ && echo "User vscode (uid=`id -u vscode`:gid=`id -g vscode`) created with passwordless sudo privileges" -USER vscode +# Build time cache directory to speed up sucessive rebuilds of this image +ENV CCACHE_BUILD_DIR=/tmp/ccache +# The ccache cache generated in CCACHE_BUILD_DIR is copied to the CCACHE_IMAGE_DIR for fast initial build times +# when using this image +ENV CCACHE_IMAGE_DIR=/home/vscode/.cache/ccache -# Explicitely set ccache directory -# This ensures that ccache will always look here even if tools change the default cache location with XDG_CACHE_HOME (e.g nvim-remote) -ENV CCACHE_DIR=/home/vscode/.cache/ccache -ENV CYTHON_CACHE_DIR=/home/vscode/.cython +# Use build time ccache directory (mounted in docker build cache) +ENV CCACHE_DIR=${CCACHE_BUILD_DIR} -RUN --mount=type=cache,uid=1000,gid=1000,target=/home/vscode/.cache/ccache \ - if [ "$(ls -A ~/.cache/ccache)" ]; then \ +RUN --mount=type=cache,uid=1000,gid=1000,target=${CCACHE_BUILD_DIR} \ + if [ "$(ls -A ${CCACHE_BUILD_DIR})" ]; then \ echo "Found ccache cache in the docker build cache, using it"; \ - du -h ~/.cache/ccache; \ + du -h ${CCACHE_BUILD_DIR}; \ ccache -z; \ ccache -sv; \ else \ - echo "ccache mount directory is empty"; \ - fi - -# Use cython cache (only for caching pyx to c conversion) -RUN --mount=type=cache,uid=1000,gid=1000,target=/home/vscode/.cython \ - if [ "$(ls -A ~/.cython)" ]; then \ - echo "Found cython cache, using it"; \ - else \ - echo "cython mount directory is empty"; \ + echo "ccache mount directory is empty, it will be populated during the superbuild build step"; \ fi # Add mc-rtc-superbuild to the build context -# Note that in theory this could be copied into a separate directory as the runtime workspace -# However due to generated config headers containing install source paths for mc_rtc # It is better to keep it in the same folder in order to increase ccache hit rate COPY --chown=vscode:vscode ../../.. /home/vscode/superbuild WORKDIR /home/vscode/superbuild @@ -60,55 +53,44 @@ RUN --mount=type=cache,target=/var/cache/apt \ && git config --global user.email "${EMAIL}" && git config --global user.name "${NAME}" \ && sudo rm -rf /var/lib/apt/lists/* -# Configure CMake will install all APT/PIP dependencies (keep downloaded packages in mounted APT cache) -# Build everything to populate cache: -# - ccache in mounted cache ~/.cache/ccache -# - cython in ~/.cython +RUN echo 'kill cache' +# 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=cache,uid=1000,gid=1000,target=/home/vscode/.cache/pip \ - --mount=type=cache,uid=1000,gid=1000,target=/home/vscode/.cache/ccache \ - --mount=type=cache,uid=1000,gid=1000,target=/home/vscode/.cython \ + --mount=type=cache,uid=1000,gid=1000,target=${CCACHE_BUILD_DIR} \ ccache -z \ && cmake --preset relwithdebinfo \ && cmake --build --preset relwithdebinfo \ - && echo "Removing temporary build artefacts from the image" \ - && rm -rf /home/vscode/superbuild \ - && rm /home/vscode/.gitconfig \ + && echo "Checking ccache:" \ && ccache -sv \ + && echo "Removing temporary build artefacts from the image" \ + && rm -rf ~/superbuild \ + && rm ~/.gitconfig \ && sudo rm -rf /var/lib/apt/lists/* -# Copy ccache/cython folder into the docker image's build cache. -# This enables reuse on the next build of this image -RUN --mount=type=cache,uid=1000,gid=1000,target=/home/vscode/.cache/ccache \ - ccache -z \ - && echo "Copying ccache /home/vscode/.cache/ccache to the temporary image folder /home/vscode/.cache/docker-ccache" \ - && cp -r /home/vscode/.cache/ccache /tmp/ccache - -RUN echo "Moving the generated ccache cache to the image folder /home/vscode/.cache/ccache so that it can be used at runtime" \ - && sudo chown -R vscode ~/.cache \ - && ls -al ~/.cache \ - && mv /tmp/ccache /home/vscode/.cache/ccache - -RUN --mount=type=cache,uid=1000,gid=1000,target=/home/vscode/.cython \ - echo "Copying cython cache /home/vscode/.cython to the temporary image folder /home/vscode/.cache/cython-cache" \ - && cp -r /home/vscode/.cython /home/vscode/.cache/cython-cache - -RUN echo "Moving the generated cython cache to the image folder /home/vscode/.cache/cython so that it can be used at runtime" \ - && mv /home/vscode/.cache/cython-cache /home/vscode/.cython +RUN --mount=type=cache,uid=1000,gid=1000,target=${CCACHE_BUILD_DIR} \ + echo "Moving the generated ccache cache to the image folder ${CCACHE_IMAGE_DIR} so that it can be used at runtime" \ + && mkdir -p ${CCACHE_IMAGE_DIR} \ + && cp -r ${CCACHE_BUILD_DIR}/* ${CCACHE_IMAGE_DIR} +ENV CCACHE_DIR=${CCACHE_IMAGE_DIR} RUN echo "Checking cache contents" \ - && ls /home/vscode/.cache/ccache \ - && ls /home/vscode/.cython + && ccache -sv +# Switch back to the official remote when https://github.com/deluan/zsh-in-docker/pull/28 is merged # oh-my-zsh & plugins -RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.2.1/zsh-in-docker.sh)" -- \ +RUN sh -c "$(curl -L https://raw.githubusercontent.com/balancedscorpion/zsh-in-docker/new_user/zsh-in-docker.sh)" -- \ -t 'bira' \ -p git \ - && echo 'source $HOME/superbuild/.devcontainer/entrypoint.sh' >> /home/vscode/.zshrc + -u vscode \ + && echo 'source $HOME/superbuild/.devcontainer/entrypoint.sh' >> ~/.zshrc -FROM ubuntu:22.04 +FROM ubuntu:jammy COPY --from=build / / LABEL org.opencontainers.image.source=https://github.com/mc-rtc/mc-rtc-superbuild -LABEL org.opencontainers.image.description="Development environment for mc-rtc-superbuild from source" +LABEL org.opencontainers.image.description="Development environment for mc-rtc-superbuild from source (ubuntu jammy)" LABEL org.opencontainers.image.licenses=BSD-2 +# entrypoint.sh will sync this default image cache with the local folder cache upon starting the container +# This is done to allow updating the cache while working within the container +ENV CCACHE_DIR="/home/vscode/workspace/.ccache" +ENV UBUNTU_VERSION="jammy" ENTRYPOINT ["/usr/bin/zsh", "-c"] diff --git a/.github/devcontainer/jammy/devcontainer.json b/.github/devcontainer/jammy/devcontainer.json index ab43ff15..42825239 100644 --- a/.github/devcontainer/jammy/devcontainer.json +++ b/.github/devcontainer/jammy/devcontainer.json @@ -1,6 +1,5 @@ { "name": "mc-rtc-superbuild-jammy-build", - "remoteUser": "vscode", "build": { "dockerfile": "Dockerfile", @@ -12,7 +11,8 @@ }, "mounts": [ - "source=/tmp/.X11-unix,target=/tmp/.X11-unix,type=bind,consistency=cached" + "source=/tmp/.X11-unix,target=/tmp/.X11-unix,type=bind,consistency=cached", + "source=${localEnv:HOME}${localEnv:USERPROFILE}/docker-ws/mc-rtc-superbuild-jammy,target=/home/vscode/workspace,type=bind,consistency=cached" ], "features": @@ -23,9 +23,6 @@ "ghcr.io/georgofenbeck/features/lazygit-linuxbinary:1": { "version": "latest" } }, - "postCreateCommand": "~/superbuild/.devcontainer/setupShell.sh", - - // Configure tool-specific properties. "customizations": { "vscode": { "extensions": [ @@ -42,11 +39,20 @@ } }, + "postCreateCommand": "~/superbuild/.devcontainer/setupShell.sh", + "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. + "--ulimit core=-1", // allow core dumps + "--privileged" // 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/devcontainer/noble/Dockerfile b/.github/devcontainer/noble/Dockerfile index f5249063..695ced2d 100644 --- a/.github/devcontainer/noble/Dockerfile +++ b/.github/devcontainer/noble/Dockerfile @@ -2,6 +2,7 @@ FROM ubuntu:noble as build RUN userdel -r ubuntu ARG EMAIL="devcontainer@mc-rtc-superbuild.com" ARG NAME="mc_rtc devcontainer" +ENV UBUNTU_VERSION="noble" RUN export DEBIAN_FRONTEND=noninteractive ENV TZ=Europe/Paris @@ -13,7 +14,7 @@ RUN rm -f /etc/apt/apt.conf.d/docker-clean # Install sudo RUN --mount=type=cache,target=/var/cache/apt \ apt-get update \ - && apt-get install -y --no-install-recommends sudo ccache ripgrep rsync curl wget zsh gnupg2 gpg-agent clangd \ + && apt-get install -y --no-install-recommends sudo ccache ripgrep rsync curl wget zsh gnupg2 gpg-agent openssh-server clangd \ && rm -rf /var/lib/apt/lists/* # Create ubuntu user with sudo privileges @@ -25,93 +26,70 @@ RUN useradd -ms /bin/zsh vscode && \ USER vscode -# Explicitely set ccache directory -# This ensures that ccache will always look here even if tools change the default cache location with XDG_CACHE_HOME (e.g nvim-remote) -ENV CCACHE_DIR=/home/vscode/.cache/ccache -ENV CYTHON_CACHE_DIR=/home/vscode/.cython +# Build time cache directory to speed up sucessive rebuilds of this image +ENV CCACHE_BUILD_DIR=/tmp/ccache +# The ccache cache generated in CCACHE_BUILD_DIR is copied to the CCACHE_IMAGE_DIR for fast initial build times +# when using this image +ENV CCACHE_IMAGE_DIR=/home/vscode/.cache/ccache -RUN --mount=type=cache,uid=1000,gid=1000,target=/home/vscode/.cache/ccache \ - if [ "$(ls -A ~/.cache/ccache)" ]; then \ +# Use build time ccache directory (mounted in docker build cache) +ENV CCACHE_DIR=${CCACHE_BUILD_DIR} + +RUN --mount=type=cache,uid=1000,gid=1000,target=${CCACHE_BUILD_DIR} \ + if [ "$(ls -A ${CCACHE_BUILD_DIR})" ]; then \ echo "Found ccache cache in the docker build cache, using it"; \ - du -h ~/.cache/ccache; \ + du -h ${CCACHE_BUILD_DIR}; \ ccache -z; \ ccache -sv; \ else \ - echo "ccache mount directory is empty"; \ - fi - -# Use cython cache (only for caching pyx to c conversion) -RUN --mount=type=cache,uid=1000,gid=1000,target=/home/vscode/.cython \ - if [ "$(ls -A ~/.cython)" ]; then \ - echo "Found cython cache, using it"; \ - else \ - echo "cython mount directory is empty"; \ + echo "ccache mount directory is empty, it will be populated during the superbuild build step"; \ fi # Add mc-rtc-superbuild to the build context -# Note that in theory this could be copied into a separate directory as the runtime workspace -# However due to generated config headers containing install source paths for mc_rtc # It is better to keep it in the same folder in order to increase ccache hit rate COPY --chown=vscode:vscode ../../.. /home/vscode/superbuild WORKDIR /home/vscode/superbuild RUN --mount=type=cache,target=/var/cache/apt \ - sudo chown -R vscode ~/.cache \ - && ./utils/bootstrap-linux.sh \ + ./utils/bootstrap-linux.sh \ && sudo apt-get install -y --no-install-recommends ccache gdb \ && git config --global user.email "${EMAIL}" && git config --global user.name "${NAME}" \ && sudo rm -rf /var/lib/apt/lists/* -# Configure CMake will install all APT/PIP dependencies (keep downloaded packages in mounted APT cache) -# Build everything to populate cache: -# - ccache in mounted cache ~/.cache/ccache -# - cython in ~/.cython +# 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=cache,uid=1000,gid=1000,target=/home/vscode/.cache/pip \ - --mount=type=cache,uid=1000,gid=1000,target=/home/vscode/.cache/ccache \ - --mount=type=cache,uid=1000,gid=1000,target=/home/vscode/.cython \ + --mount=type=cache,uid=1000,gid=1000,target=${CCACHE_BUILD_DIR} \ ccache -z \ - # FIXME: as of now mc_rtc does not build in devcontainer - # && cmake --preset relwithdebinfo \ - # && cmake --build --preset relwithdebinfo \ - && echo "Removing temporary build artefacts from the image" \ - && rm -rf /home/vscode/superbuild \ - && rm /home/vscode/.gitconfig \ + && cmake --preset relwithdebinfo-noble \ + && cmake --build --preset relwithdebinfo-noble \ + && echo "Checking ccache:" \ && ccache -sv \ + && echo "Removing temporary build artefacts from the image" \ + && rm -rf ~/superbuild \ + && rm ~/.gitconfig \ && sudo rm -rf /var/lib/apt/lists/* -# Copy ccache/cython folder into the docker image's build cache. -# This enables reuse on the next build of this image -RUN --mount=type=cache,uid=1000,gid=1000,target=/home/vscode/.cache/ccache \ - ccache -z \ - && echo "Copying ccache /home/vscode/.cache/ccache to the temporary image folder /home/vscode/.cache/docker-ccache" \ - && cp -r /home/vscode/.cache/ccache /tmp/ccache - -RUN echo "Moving the generated ccache cache to the image folder /home/vscode/.cache/ccache so that it can be used at runtime" \ - && sudo chown -R vscode ~/.cache \ - && ls -al ~/.cache \ - && mv /tmp/ccache /home/vscode/.cache/ccache - -RUN --mount=type=cache,uid=1000,gid=1000,target=/home/vscode/.cython \ - echo "Copying cython cache /home/vscode/.cython to the temporary image folder /home/vscode/.cache/cython-cache" \ - && cp -r /home/vscode/.cython /home/vscode/.cache/cython-cache - -RUN echo "Moving the generated cython cache to the image folder /home/vscode/.cache/cython so that it can be used at runtime" \ - && mv /home/vscode/.cache/cython-cache /home/vscode/.cython +RUN --mount=type=cache,uid=1000,gid=1000,target=${CCACHE_BUILD_DIR} \ + echo "Moving the generated ccache cache to the image folder ${CCACHE_IMAGE_DIR} so that it can be used at runtime" \ + && mkdir -p ${CCACHE_IMAGE_DIR} \ + && ls -al ${CCACHE_IMAGE_DIR} \ + && cp -r ${CCACHE_BUILD_DIR}/* ${CCACHE_IMAGE_DIR} +ENV CCACHE_DIR=~/.cache/ccache RUN echo "Checking cache contents" \ - && ls /home/vscode/.cache/ccache \ - && ls /home/vscode/.cython + && ccache -sv # oh-my-zsh & plugins RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.2.1/zsh-in-docker.sh)" -- \ -t 'bira' \ -p git \ - && echo 'source $HOME/superbuild/.devcontainer/entrypoint.sh' >> /home/vscode/.zshrc + && echo 'source $HOME/superbuild/.devcontainer/entrypoint.sh' >> ~/.zshrc -FROM ubuntu:22.04 +FROM ubuntu:noble COPY --from=build / / LABEL org.opencontainers.image.source=https://github.com/mc-rtc/mc-rtc-superbuild -LABEL org.opencontainers.image.description="Development environment for mc-rtc-superbuild from source" +LABEL org.opencontainers.image.description="Development environment for mc-rtc-superbuild from source (ubuntu noble)" LABEL org.opencontainers.image.licenses=BSD-2 +ENV CCACHE_DIR="/home/vscode/workspace/.ccache" +ENV UBUNTU_VERSION="noble" ENTRYPOINT ["/usr/bin/zsh", "-c"] diff --git a/.github/devcontainer/noble/devcontainer.json b/.github/devcontainer/noble/devcontainer.json index 34a8e878..4ee1bed9 100644 --- a/.github/devcontainer/noble/devcontainer.json +++ b/.github/devcontainer/noble/devcontainer.json @@ -11,17 +11,18 @@ }, "mounts": [ - "type=bind,source=/tmp/.X11-unix,target=/tmp/.X11-unix,consistency=cached" + "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" ], "features": { + "ghcr.io/devcontainers/features/node:1": {}, "ghcr.io/duduribeiro/devcontainer-features/neovim:1.0.1": {}, "ghcr.io/devcontainers/features/github-cli": { "version": "latest" }, "ghcr.io/georgofenbeck/features/lazygit-linuxbinary:1": { "version": "latest" } }, - // Configure tool-specific properties. "customizations": { "vscode": { "extensions": [ @@ -43,10 +44,12 @@ "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. - // "-v", - // "${env:SSH_AUTH_SOCK}:/tmp/ssh-agent.socket", - // "-e", - // "SSH_AUTH_SOCK=/tmp/ssh-agent.socket" + "--ulimit core=-1", // allow core dumps + "--privileged" // 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", diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 53bdaf4e..6e1afeab 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,25 +20,6 @@ repos: - id: fix-byte-order-marker - id: mixed-line-ending - id: trailing-whitespace -- repo: https://github.com/psf/black - rev: 25.1.0 - hooks: - - id: black - exclude: | - (?x)^( - .cmake-format.py - )$ -- repo: https://github.com/PyCQA/flake8 - rev: 7.1.1 - hooks: - - id: flake8 - args: - - "--max-line-length=88" - - "--extend-ignore=E203,E501" - exclude: | - (?x)^( - .cmake-format.py - )$ - repo: https://github.com/cheshirekow/cmake-format-precommit rev: v0.6.13 hooks: diff --git a/CMakeLists.txt b/CMakeLists.txt index 772125bf..ab6d08c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,9 +42,11 @@ if(${CMAKE_GENERATOR} STREQUAL "Ninja") endif() find_program(CCACHE_PROGRAM ccache) +# For ccache < 4.8 if(CCACHE_PROGRAM) message(NOTICE "Selected CCache: ${CCACHE_PROGRAM}") - cmake_path(GET PROJECT_SOURCE_DIR PARENT_PATH PARENT_DIR) + # path is $HOME/workspace/devel, rewrite relative to $HOME + get_filename_component(CCACHE_BASE_DIR "${SOURCE_DESTINATION}/../.." REALPATH) set(ccacheEnv # Rewrite all absolute paths that contain the CCACHE_BASEDIR into relative paths # This is done to ensure that the cache will be used even if the project is pulled @@ -52,7 +54,7 @@ if(CCACHE_PROGRAM) # than the one used for generating the cache (e.g docker workspace path, other # user's machine, etc) # See https://ccache.dev/manual/4.10.2.html#_compiling_in_different_directories - CCACHE_BASEDIR=${PARENT_DIR} + CCACHE_BASEDIR=${CCACHE_BASE_DIR} # locale and umask are important for docker containers: if either differs, the # cache won't be used. no_hash_dir useful? CCACHE_SLOPPINESS="umask,locale,no_hash_dir,pch_defines,file_macro,include_file_ctime" @@ -68,6 +70,17 @@ if(CCACHE_PROGRAM) set(CYTHON_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM}) endif() endif() +# For ccache >= 4.8 (from ubuntu noble) cmake-format off if(CCACHE_PROGRAM) +# message(NOTICE "Selected CCache: ${CCACHE_PROGRAM}") # path is +# /home/vscode/workspace/devel, rewrite as /home/vscode +# get_filename_component(CCACHE_BASE_DIR "${SOURCE_DESTINATION}/../.." REALPATH) +# message(STATUS "ccache base_dir is: ${CCACHE_BASE_DIR}") set(CMAKE_C_COMPILER_LAUNCHER +# ${CCACHE_PROGRAM} base_dir=${CCACHE_BASE_DIR} hash_dir=false +# sloppiness="umask,locale,no_hash_dir,pch_defines,file_macro,include_file_ctime" ) +# set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM} base_dir=${CCACHE_BASE_DIR} +# hash_dir=false +# sloppiness="umask,locale,no_hash_dir,pch_defines,file_macro,include_file_ctime" ) +# endif() cmake-format on if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES diff --git a/CMakePresets.json b/CMakePresets.json index 5f4557e9..c210d10f 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -6,13 +6,12 @@ "name": "relwithdebinfo", "displayName": "RelWithDebInfo", "generator": "Unix Makefiles", - "binaryDir": "${sourceDir}/build/relwithdebinfo/superbuild", + "binaryDir": "${sourceDir}/../workspace/build/superbuild", "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo", - "SOURCE_DESTINATION": "${sourceDir}/devel", - "BUILD_DESTINATION": "${sourceDir}/build/relwithdebinfo/projects", - "CMAKE_INSTALL_PREFIX": "${sourceDir}/install/relwithdebinfo", - "CMAKE_CXX_COMPILER_LAUNCHER": "ccache" + "SOURCE_DESTINATION": "${sourceDir}/../workspace/devel", + "BUILD_DESTINATION": "${sourceDir}/../workspace/build/projects", + "CMAKE_INSTALL_PREFIX": "${sourceDir}/../workspace/install" } }, { @@ -24,6 +23,22 @@ "cacheVariables": { "BUILD_TESTING": "OFF" } + }, + { + "name": "relwithdebinfo-noble", + "displayName": "RelWithDebInfo (noble, no ROS, no Python)", + "inherits": [ + "relwithdebinfo" + ], + "cacheVariables": { + "PYTHON_BINDING": "OFF", + "WITH_ROS_SUPPORT": "OFF" + }, + "condition": { + "type": "equals", + "lhs": "$env{UBUNTU_VERSION}", + "rhs": "noble" + } } ], "buildPresets": [ @@ -33,7 +48,7 @@ "configurePreset": "relwithdebinfo", "configuration": "RelWithDebInfo", "targets": [ - "all" + "install" ] }, { @@ -42,7 +57,16 @@ "configurePreset": "relwithdebinfo-notests", "configuration": "RelWithDebInfo", "targets": [ - "all" + "install" + ] + }, + { + "name": "relwithdebinfo-noble", + "displayName": "RelWithDebInfo (ubuntu noble)", + "configurePreset": "relwithdebinfo-noble", + "configuration": "RelWithDebInfo", + "targets": [ + "install" ] } ] diff --git a/cmake/linux/noble.cmake b/cmake/linux/noble.cmake new file mode 100644 index 00000000..a5606a68 --- /dev/null +++ b/cmake/linux/noble.cmake @@ -0,0 +1,54 @@ +set(MC_LOG_UI_PYTHON_EXECUTABLE python3) +set(APT_HAS_PYTHON2_PACKAGES OFF) +set(ROS_IS_ROS2 ON) +set(ROS_DISTRO humble) +set(ROS_WORKSPACE_INSTALL_PYTHON_DESTINATION "lib/python3.10/site-packages") +set(APT_DEPENDENCIES + curl + wget + cmake + build-essential + gfortran + cython3 + # python3-nose python3-pytest python3-numpy python3-coverage python3-setuptools + # python3-pip + 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 +) +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 Focal, 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/project.cmake b/cmake/project.cmake index 99223c7e..546683a5 100644 --- a/cmake/project.cmake +++ b/cmake/project.cmake @@ -287,6 +287,7 @@ You have local changes in ${SOURCE_DIR} that would be overwritten by this change "-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON" "-DINSTALL_DOCUMENTATION:BOOL=${INSTALL_DOCUMENTATION}" "-DPYTHON_BINDING:BOOL=${PYTHON_BINDING}" + "-DNANOBIND_BINDINGS:BOOL=${NANOBIND_BINDINGS}" "-DPYTHON_BINDING_USER_INSTALL:BOOL=${PYTHON_BINDING_USER_INSTALL}" "-DPYTHON_BINDING_FORCE_PYTHON2:BOOL=${PYTHON_BINDING_FORCE_PYTHON2}" "-DPYTHON_BINDING_FORCE_PYTHON3:BOOL=${PYTHON_BINDING_FORCE_PYTHON3}" diff --git a/doc/devcontainer.md b/doc/devcontainer.md index a8d67505..a90e5014 100644 --- a/doc/devcontainer.md +++ b/doc/devcontainer.md @@ -21,23 +21,27 @@ Additionally, `mc-rtc-superbuild` comes with pre-configured `CMakePresets.json` Available images can be pulled from `ghcr.io/mc-rtc/mc-rtc-superbuild:`: -| Image | Description | Image URI | I -| ----- | ----------- | --------- | -| jammy | Ubuntu 22.04 | ghcr.io/mc-rtc/mc-rtc-superbuild:jammy -| noble | Ubuntu 24.04 | ghcr.io/mc-rtc/mc-rtc-superbuild:noble +| Image | Description | Image URI | Local mount folder | Mounts to (devcontainer) | +| :--- | :--- | :--- | :--- | :--- | +| jammy | Ubuntu 22.04 | ghcr.io/mc-rtc/mc-rtc-superbuild:jammy | `$HOME/docker-ws/mc-rtc-superbuild-jammy` | `$HOME/workspace` | +| noble | Ubuntu 24.04 | ghcr.io/mc-rtc/mc-rtc-superbuild:noble | `$HOME/docker-ws/mc-rtc-superbuild-noble` | `$HOME/workspace` | + +By default the devcontainer will attempt to mount the "local mount folder" path specified above to store all files that need to persist after the container has been stopped. In particular, this is where all source code will be stored. ## Setting up the devcontainer You can take advantage of these devcontainers in the following ways: -- By using [DevPod](https://devpod.sh/) to manage your devcontainers. This is the most flexible way as it allows to easily use the devcontainer from both the terminal/vscode/neovim/... -- By using VSCode directly. This is slightly easier, but will only work from within VSCode. +- By using VSCode with the devcontainer extension. If you are already used to using VSCode, this is by far the easiest option. +- Manually by using [DevPod](https://devpod.sh/) or [devcontainer cli](https://github.com/devcontainers/cli) to manage your devcontainers. This is the most flexible way as it allows to easily use the devcontainer from both the terminal/vscode/neovim/... ### General setup This section contains common instructions that are needed no matter how you intend to use the provided devcontainers. - Install docker from https://docs.docker.com/engine/install/ubuntu/ -- The devcontainers will automatically forward your ssh-agent socket to the devcontainer, so that you can use your ssh keys from within the devcontainer. For this to work, you need to add the following to your `~/.bashrc`: +- Adjust the devcontainer settings to your liking in `.devcontainer//devcontainer.json`. In general the default settings will be sufficient. If you wish to do so, you can select a different mount point in the `mounts` property. +- The devcontainers are configured to automatically forward your `ssh-agent`/`gpg-agent` socket to the devcontainer, so that you can use your ssh keys from within the devcontainer. For this to work, you need to add the following to your `~/.bashrc`: + ```bash # For ssh-forwarding, we need to # - Run the ssh-agent @@ -46,9 +50,28 @@ eval $(ssh-agent -s) ssh-add ~/.ssh/id_rsa # replace with the private key(s) you wish to share with the container ``` +### VSCode + +
+ If you wish to use the provided devcontainers within VSCode, please read this section: + +Using devcontainers in vscode is simple. + +- Clone `mc-rtc-superbuild` +- Open the cloned folder in VSCode +- VSCode will prompt you to install recommended extensions, in particular the `Devcontainer` extension +- Once done, VSCode will prompt you to re-open the current folder in a devcontainer, select the image you wish. +- VSCode will install a vscode server within the docker environment, then re-open the workspace within the devcontainer. In the bottom left corner of VSCode window, you should see the name of the image you selected. Note that from this point on, any file you modify is either a file of the container itself (that will be deleted once the container stops) or one in the specified mount folder(s) (by default + +To go further, please read [Developing inside a Container](https://code.visualstudio.com/docs/devcontainers/containers) from the official VSCode documenation. +
+ ### Using DevPod CLI -The easiest way to use the devcontainer from the terminal is to use [Devpod](https://devpod.sh/). +
+If you wish to use the provided devcontainers from the CLI, please follow this section: + +To use the provided devcontainers from the terminal, you can use [Devpod CLI](https://devpod.sh/). - [Install DevPod CLI](https://devpod.sh/docs/getting-started/install#install-devpod-cli) - Add docker to devpod providers: @@ -77,46 +100,109 @@ contexts: Note that using devpod, you can also take advantage of VSCode by using `--ide=vscode`. When working with multiple devcontainers, you can use the `--id` flag to specify a name. -#### Neovim +
-For neovim users, you can use the [remote-nvim.nvim](https://github.com/amitds1997/remote-nvim.nvim) plugin. -### VSCode +#### Neovim -- Clone `mc-rtc-superbuild` -- Open the cloned folder in VSCode -- VSCode will prompt you to install recommended extensions, in particular the `Devcontainer` extension -- Once done, VSCode will prompt you to re-open the current folder in a devcontainer, select the image you wish. -- VSCode will re-open the workspace within the devcontainer. In the bottom left corner of VSCode window, you should see the name of the image you selected. +
+ If you wish to use the provided devcontainers within Neovim, please read this section: + For neovim users, you can use the [remote-nvim.nvim](https://github.com/amitds1997/remote-nvim.nvim) plugin. +
## Working within the devcontainer Once your devcontainer workspace has been created, be it with VSCode or Devpod, you can now work within the devcontainer as you would on your host system. -### Building +### Mounted folders -You can now build from the terminal, or use VSCode's "CMake Tools" extension to select your desired build preset. -Note that default presets will: -- clone all projects in `./devel` -- build all projects in `./build/` -- install all projects in `./install/` +By default the following folders are mounted within the container: +- `/home/vscode/superbuild` : A mount point for the local `mc-rtc-superbuild` folder from which you created the container +- `/home/vscode/workspace` : A mount point to a local developement workspace. By default `$HOME/docker-ws/mc-rtc-superbuild-`. Within this folder mc-rtc-superbuild will create: + - `devel/` : all source code managed by `mc-rtc-superbuild` + - `build/projects` : a build directory for each project managed by `mc-rtc-superbuild` + - `build/superbuild` : the build directory of `mc-rtc-superbuild` itself. This is used to track which projects need to be cloned/updated/built + - `.ccache/` : A pre-populated compilation cache is included within the docker image. Upon startup of the container, this cache is copied to the `.ccache/` folder. `mc-rtc-superbuild` configures `cmake` to make use of this cache to speed up compilation. Since the cache is now stored on your local machine, any subsequent changes to the code will benefit from this cache. -```bash -# Setup cmake and install all dependencies if necessary -cmake --preset relwithdebinfo -``` -Note that all default dependencies of mc-rtc-superbuild come pre-installed in the container images, so this will install nothing. +### Building with `mc-rtc-superbuild` -```bash -# Build all projects -cmake --build --preset relwithdebinfo -``` +`mc-rtc-superbuild` is mounted to the `/home/vscode/superbuild` folder within the container. To simplify building`CMakePresets.json` are provided. The default preset `relwithdebinfo` will: +- Clone all projects to `/home/vscode/workspace/devel` +- Configure: since all dependencies have already been installed within the container this will simply set-up cmake build files (in `/home/vscode/workspace/build`) +- Build: The default build preset will build all projects (build folder: `/home/vscode/workspace/build/`). Since ccache compilation cache has been pre-populated from the container image, this will only take a few minutes. All projects are installed in `/home/vscode/workspace/install`. + +
+ Build with vscode + To build within vscode simply select one of the provided presets (`relwithdebinfo`) within the `CMakeTools` extensions in your leftmost vertical panel. Then configure and build the project. +
+ +
+ Build within the terminal + You can now build from the terminal, or use VSCode's "CMake Tools" extension to select your desired build preset. + Note that default presets will: + - clone all projects in `./devel` + - build all projects in `./build/` + - install all projects in `./install/` + + ```bash + # Setup cmake and install all dependencies if necessary + cmake --preset relwithdebinfo + ``` + + Note that all default dependencies of mc-rtc-superbuild come pre-installed in the container images, so this will install nothing. + + ```bash + # Build all projects + cmake --build --preset relwithdebinfo + ``` + + Since the container images come with a pre-generated [ccache](https://ccache.dev/), this will be fairly quick (a few minutes). +
+ +
+ Cutom build + + To customize the build process, create a `CMakeUserPresets.json` file that inherits from one of the default presets, and set up your preferred build options (build folders, cmake arguments, build type, etc) + + For example: + ```json + { + "version": 10, + "$schema": "https://cmake.org/cmake/help/latest/_downloads/3e2d73bff478d88a7de0de736ba5e361/schema.json", + "configurePresets": [ + { + "name": "nanobind", + "displayName": "RelWithDebInfo (nanobind/noble)", + "inherits": [ + "relwithdebinfo-noble" + ], + "cacheVariables": { + "PYTHON_BINDING": "OFF", + "NANOBIND_BINDINGS": "ON" + } + } + ], + "buildPresets": [ + { + "name": "nanobind", + "displayName": "RelWithDebInfo (nanobind)", + "configurePreset": "nanobind", + "configuration": "RelWithDebInfo", + "targets": [ + "install" + ] + } + ] + } + ``` + + As always, you can also add additional projects to the superbuild in the `extensions/` folder. +
-Since the container images come with a pre-generated [ccache](https://ccache.dev/), this will be fairly quick (a few minutes). -## Running +### Running To use `mc_rtc`, you need to setup the environment variables for the local installation of `mc_rtc`. This can be done by sourcing the following file: