diff --git a/.devcontainer.json b/.devcontainer.json new file mode 100644 index 0000000000..95a27dac74 --- /dev/null +++ b/.devcontainer.json @@ -0,0 +1,32 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.154.2/containers/cpp +{ + "build": { + "dockerfile": "docker/Dockerfile" + }, + "customizations": { + "vscode": { + "settings": { + // Set *default* container specific settings.json values on container create. + "terminal.integrated.profiles.linux": { + "bash": { + "path": "/bin/bash" + } + }, + "terminal.integrated.defaultProfile.linux": "bash", + "editor.formatOnSave": true, + // FIXME: This and the Dockerfile might get out of sync + "clang-format.executable": "clang-format-14" + }, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-vscode.cpptools", + "ms-vscode.cmake-tools", + "marus25.cortex-debug", + "notskm.clang-tidy", + "mjohns.clang-format" + ] + } + }, + "remoteUser": "infinitime" +} \ No newline at end of file diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index e4ad5c4fa8..0000000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,66 +0,0 @@ -FROM ubuntu:latest - -ARG DEBIAN_FRONTEND=noninteractive -RUN apt-get update -qq \ - && apt-get install -y \ -# x86_64 / generic packages - bash \ - build-essential \ - cmake \ - git \ - make \ - python3 \ - python3-pip \ - python3-pil \ - tar \ - unzip \ - wget \ - curl \ - dos2unix \ - clang-format-12 \ - clang-tidy \ - locales \ - libncurses5 \ -# aarch64 packages - libffi-dev \ - libssl-dev \ - python3-dev \ - rustc \ - && rm -rf /var/cache/apt/* /var/lib/apt/lists/*; - -#SET LOCALE -RUN locale-gen en_US.UTF-8 -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US:en -ENV LC_ALL en_US.UTF-8 - -RUN pip3 install adafruit-nrfutil -# required for McuBoot -RUN pip3 install setuptools_rust - -WORKDIR /opt/ -# build.sh knows how to compile but it problimatic on Win10 -COPY build.sh . -RUN chmod +x build.sh -# create_build_openocd.sh uses cmake to crate to build directory -COPY create_build_openocd.sh . -RUN chmod +x create_build_openocd.sh -# Lets get each in a separate docker layer for better downloads -# GCC -# RUN bash -c "source /opt/build.sh; GetGcc;" -RUN wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2 -O - | tar -xj -C /opt -# NrfSdk -# RUN bash -c "source /opt/build.sh; GetNrfSdk;" -RUN wget -q "https://developer.nordicsemi.com/nRF5_SDK/nRF5_SDK_v15.x.x/nRF5_SDK_15.3.0_59ac345.zip" -O /tmp/nRF5_SDK_15.3.0_59ac345 -RUN unzip -q /tmp/nRF5_SDK_15.3.0_59ac345 -d /opt -RUN rm /tmp/nRF5_SDK_15.3.0_59ac345 -# McuBoot -# RUN bash -c "source /opt/build.sh; GetMcuBoot;" -RUN git clone https://github.com/mcu-tools/mcuboot.git -RUN pip3 install -r ./mcuboot/scripts/requirements.txt - -RUN adduser infinitime - -ENV NRF5_SDK_PATH /opt/nRF5_SDK_15.3.0_59ac345 -ENV ARM_NONE_EABI_TOOLCHAIN_PATH /opt/gcc-arm-none-eabi-9-2020-q2-update -ENV SOURCES_DIR /workspaces/InfiniTime diff --git a/.devcontainer/build.sh b/.devcontainer/build.sh deleted file mode 100644 index b4f080dd92..0000000000 --- a/.devcontainer/build.sh +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/bash -(return 0 2>/dev/null) && SOURCED="true" || SOURCED="false" -export LC_ALL=C.UTF-8 -export LANG=C.UTF-8 -set -x -set -e - -# Default locations if the var isn't already set -export TOOLS_DIR="${TOOLS_DIR:=/opt}" -export SOURCES_DIR="${SOURCES_DIR:=/sources}" -export BUILD_DIR="${BUILD_DIR:=$SOURCES_DIR/build}" -export OUTPUT_DIR="${OUTPUT_DIR:=$BUILD_DIR/output}" - -export BUILD_TYPE=${BUILD_TYPE:=Release} -export GCC_ARM_VER=${GCC_ARM_VER:="gcc-arm-none-eabi-9-2020-q2-update"} -export NRF_SDK_VER=${NRF_SDK_VER:="nRF5_SDK_15.3.0_59ac345"} - -MACHINE="$(uname -m)" -[[ "$MACHINE" == "arm64" ]] && MACHINE="aarch64" - -main() { - local target="$1" - - mkdir -p "$TOOLS_DIR" - - [[ ! -d "$TOOLS_DIR/$GCC_ARM_VER" ]] && GetGcc - [[ ! -d "$TOOLS_DIR/$NRF_SDK_VER" ]] && GetNrfSdk - [[ ! -d "$TOOLS_DIR/mcuboot" ]] && GetMcuBoot - - mkdir -p "$BUILD_DIR" - - CmakeGenerate - CmakeBuild $target - BUILD_RESULT=$? - if [ "$DISABLE_POSTBUILD" != "true" -a "$BUILD_RESULT" == 0 ]; then - source "$BUILD_DIR/post_build.sh" - fi - # assuming post_build.sh will never fail on a successful build - return $BUILD_RESULT -} - -GetGcc() { - GCC_SRC="$GCC_ARM_VER-$MACHINE-linux.tar.bz" - wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/$GCC_SRC -O - | tar -xj -C $TOOLS_DIR/ -} - -GetMcuBoot() { - git clone https://github.com/mcu-tools/mcuboot.git "$TOOLS_DIR/mcuboot" - pip3 install -r "$TOOLS_DIR/mcuboot/scripts/requirements.txt" -} - -GetNrfSdk() { - wget -q "https://developer.nordicsemi.com/nRF5_SDK/nRF5_SDK_v15.x.x/$NRF_SDK_VER.zip" -O /tmp/$NRF_SDK_VER - unzip -q /tmp/$NRF_SDK_VER -d "$TOOLS_DIR/" - rm /tmp/$NRF_SDK_VER -} - -CmakeGenerate() { - # We can swap the CD and trailing SOURCES_DIR for -B and -S respectively - # once we go to newer CMake (Ubuntu 18.10 gives us CMake 3.10) - cd "$BUILD_DIR" - - cmake -G "Unix Makefiles" \ - -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ - -DARM_NONE_EABI_TOOLCHAIN_PATH="$TOOLS_DIR/$GCC_ARM_VER" \ - -DNRF5_SDK_PATH="$TOOLS_DIR/$NRF_SDK_VER" \ - "$SOURCES_DIR" - cmake -L -N . -} - -CmakeBuild() { - local target="$1" - [[ -n "$target" ]] && target="--target $target" - if cmake --build "$BUILD_DIR" --config $BUILD_TYPE $target -- -j$(nproc) - then return 0; else return 1; - fi -} - -if [[ $SOURCED == "false" ]]; then - # It is important to return exit code of main - # To be future-proof, this is handled explicitely - main "$@" - BUILD_RESULT=$? - exit $BUILD_RESULT -else - echo "Sourced!" -fi diff --git a/.devcontainer/build_app.sh b/.devcontainer/build_app.sh deleted file mode 100644 index 0f578cc642..0000000000 --- a/.devcontainer/build_app.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -cmake --build /workspaces/Pinetime/build --config Release -- -j6 pinetime-app \ No newline at end of file diff --git a/.devcontainer/create_build_openocd.sh b/.devcontainer/create_build_openocd.sh deleted file mode 100644 index c5bff5c89b..0000000000 --- a/.devcontainer/create_build_openocd.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -rm -rf build/ -cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Release -DUSE_OPENOCD=1 -DARM_NONE_EABI_TOOLCHAIN_PATH=/opt/gcc-arm-none-eabi-9-2020-q2-update -DNRF5_SDK_PATH=/opt/nRF5_SDK_15.3.0_59ac345 -S . -Bbuild \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index 1bb315f7ef..0000000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,38 +0,0 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.154.2/containers/cpp -{ - // "name": "Pinetime", - // "image": "feabhas/pinetime-dev" - "build": { - "dockerfile": "Dockerfile", - // Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-10, debian-9, ubuntu-20.04, ubuntu-18.04 - // "args": { "VARIANT": "ubuntu-20.04" } - }, - "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"], - - // Set *default* container specific settings.json values on container create. - "settings": { - "terminal.integrated.shell.linux": "/bin/bash", - "editor.formatOnSave": true, - "clang-format.executable": "clang-format-12" - }, - - // Add the IDs of extensions you want installed when the container is created. - "extensions": [ - "ms-vscode.cpptools", - "ms-vscode.cmake-tools", - "marus25.cortex-debug", - "notskm.clang-tidy", - "mjohns.clang-format" - ], - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "bash /opt/create_build_openocd.sh", - - // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - // "remoteUser": "vscode" - "remoteUser": "infinitime" -} diff --git a/.devcontainer/make_build_dir.sh b/.devcontainer/make_build_dir.sh deleted file mode 100644 index 76240037c2..0000000000 --- a/.devcontainer/make_build_dir.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Release -DUSE_OPENOCD=1 -DARM_NONE_EABI_TOOLCHAIN_PATH=/opt/gcc-arm-none-eabi-9-2020-q2-update -DNRF5_SDK_PATH=/opt/nRF5_SDK_15.3.0_59ac345 ${SOURCES_DIR} diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 392f4151e4..c5f88a827b 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,4 +1,9 @@ { + "env": { + // TODO: This is a duplication of the configuration set in /docker/build.sh! + "TOOLS_DIR": "/opt", + "GCC_ARM_PATH": "gcc-arm-none-eabi-10.3-2021.10" + }, "configurations": [ { "name": "nrfCC", @@ -14,7 +19,22 @@ "intelliSenseMode": "linux-gcc-arm", "configurationProvider": "ms-vscode.cpp-tools", "compileCommands": "${workspaceFolder}/build/compile_commands.json" + }, + { + "name": "nrfCC Devcontainer", + "includePath": [ + "${workspaceFolder}/**", + "${workspaceFolder}/src/**", + "${workspaceFolder}/src" + ], + "defines": [], + "compilerPath": "${TOOLS_DIR}/${GCC_ARM_PATH}/bin/arm-none-eabi-gcc", + "cStandard": "c99", + "cppStandard": "c++20", + "intelliSenseMode": "linux-gcc-arm", + "configurationProvider": "ms-vscode.cpp-tools", + "compileCommands": "${workspaceFolder}/build/compile_commands.json" } ], "version": 4 -} \ No newline at end of file +} diff --git a/.vscode/cmake-kits.json b/.vscode/cmake-kits.json new file mode 100644 index 0000000000..95bb600b33 --- /dev/null +++ b/.vscode/cmake-kits.json @@ -0,0 +1,6 @@ +[ + { + "name": "InfiniTime Compiler", + "environmentSetupScript": "${workspaceFolder}/docker/build.sh" + } +] diff --git a/.vscode/launch.json b/.vscode/launch.json index a50270d25b..7d3f17a11c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,20 +1,18 @@ - { +{ "version": "0.1.0", "configurations": [ { "name": "Debug - Openocd docker Remote", - "type":"cortex-debug", - "cortex-debug.armToolchainPath":"${env:ARM_NONE_EABI_TOOLCHAIN_PATH}/bin", + "type": "cortex-debug", "cwd": "${workspaceRoot}", "executable": "${command:cmake.launchTargetPath}", "request": "launch", "servertype": "external", - // This may need to be arm-none-eabi-gdb depending on your system - "gdbPath" : "${env:ARM_NONE_EABI_TOOLCHAIN_PATH}/bin/arm-none-eabi-gdb", + "gdbPath": "${env:ARM_NONE_EABI_TOOLCHAIN_PATH}/bin/arm-none-eabi-gdb", // Connect to an already running OpenOCD instance "gdbTarget": "host.docker.internal:3333", "svdFile": "${workspaceRoot}/nrf52.svd", - "runToMain": true, + "runToEntryPoint": "main", // Work around for stopping at main on restart "postRestartCommands": [ "break main", @@ -23,18 +21,16 @@ }, { "name": "Debug - Openocd Local", - "type":"cortex-debug", - "cortex-debug.armToolchainPath":"${env:ARM_NONE_EABI_TOOLCHAIN_PATH}/bin", + "type": "cortex-debug", "cwd": "${workspaceRoot}", "executable": "${command:cmake.launchTargetPath}", "request": "launch", "servertype": "openocd", - // This may need to be arm-none-eabi-gdb depending on your system - "gdbPath" : "${env:ARM_NONE_EABI_TOOLCHAIN_PATH}/bin/arm-none-eabi-gdb", + "gdbPath": "${env:ARM_NONE_EABI_TOOLCHAIN_PATH}/bin/arm-none-eabi-gdb", // Connect to an already running OpenOCD instance "gdbTarget": "localhost:3333", "svdFile": "${workspaceRoot}/nrf52.svd", - "runToMain": true, + "runToEntryPoint": "main", // Work around for stopping at main on restart "postRestartCommands": [ "break main", @@ -51,6 +47,11 @@ "showDevDebugOutput": false, "servertype": "openocd", "runToMain": true, + // Work around for stopping at main on restart + "postRestartCommands": [ + "break main", + "continue" + ], // Only use armToolchainPath if your arm-none-eabi-gdb is not in your path (some GCC packages does not contain arm-none-eabi-gdb) "armToolchainPath": "${workspaceRoot}/../gcc-arm-none-eabi-10.3-2021.10/bin", "svdFile": "${workspaceRoot}/nrf52.svd", @@ -58,7 +59,25 @@ "interface/stlink.cfg", "target/nrf52.cfg" ], - } - + }, + { + "name": "Debug - Openocd Devcontainer", + "type": "cortex-debug", + "cwd": "${workspaceRoot}", + "executable": "${command:cmake.launchTargetPath}", + "request": "launch", + "servertype": "external", + // FIXME: This is hardcoded. I have no idea how to use the values set in build.sh here + "gdbPath": "/opt/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gdb", + // Connect to an already running OpenOCD instance + "gdbTarget": "host.docker.internal:3333", + "svdFile": "${workspaceRoot}/nrf52.svd", + "runToEntryPoint": "main", + // Work around for stopping at main on restart + "postRestartCommands": [ + "break main", + "continue" + ] + }, ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index f1cc3a8176..a7b04eea3c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,20 @@ { "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", "cmake.configureArgs": [ - "-DARM_NONE_EABI_TOOLCHAIN_PATH=${env:ARM_NONE_EABI_TOOLCHAIN_PATH}", - "-DNRF5_SDK_PATH=${env:NRF5_SDK_PATH}", + "-DARM_NONE_EABI_TOOLCHAIN_PATH=${env:TOOLS_DIR}/${env:GCC_ARM_PATH}", + "-DNRF5_SDK_PATH=${env:TOOLS_DIR}/${env:NRF_SDK_VER}", ], + "cmake.statusbar.advanced": { + "launch": { + "visibility": "hidden" + }, + "launchTarget": { + "visibility": "hidden" + }, + "debug": { + "visibility": "hidden" + } + }, "cmake.generator": "Unix Makefiles", "clang-tidy.buildPath": "build/compile_commands.json", "files.associations": { diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 17f51f5efd..06a08bfceb 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,20 +1,6 @@ { "version": "2.0.0", "tasks": [ - { - "label": "create openocd build", - "type": "shell", - "command": "/opt/create_build_openocd.sh", - "group": { - "kind": "build", - "isDefault": true - }, - "presentation": { - "reveal": "always", - "panel": "shared" - }, - "problemMatcher": [] - }, { "label": "update submodules", "type": "shell", @@ -31,14 +17,6 @@ "panel": "shared" }, "problemMatcher": [] - }, - { - "label": "BuildInit", - "dependsOn": [ - "update submodules", - "create openocd build" - ], - "problemMatcher": [] } ] } \ No newline at end of file diff --git a/doc/buildWithVScode.md b/doc/buildWithVScode.md index 9d0a5bdfea..5f8724828a 100644 --- a/doc/buildWithVScode.md +++ b/doc/buildWithVScode.md @@ -32,7 +32,7 @@ The .devcontainer folder contains the configuration and scripts for using a Dock Using the [Remote-Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension is recommended. It will handle configuring the Docker virtual machine and setting everything up. -More documentation is available in the [readme in .devcontainer](../.devcontainer/README.md) +More documentation is available in the [readme in .devcontainer](usingDevcontainers.md) ### DevContainer on Ubuntu diff --git a/.devcontainer/README.md b/doc/usingDevcontainers.md similarity index 100% rename from .devcontainer/README.md rename to doc/usingDevcontainers.md diff --git a/docker/Dockerfile b/docker/Dockerfile index 22bf7bd7dd..bb5d5f65be 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -37,6 +37,13 @@ RUN apt-get update -qq \ libpangocairo-1.0-0 \ && rm -rf /var/cache/apt/* /var/lib/apt/lists/*; +# Add the necessary apt-gets for the devcontainer +RUN apt-get update -qq \ + && apt-get install -y \ + clang-format-14 \ + clang-tidy \ + libncurses5 + # Git needed for PROJECT_GIT_COMMIT_HASH variable setting RUN pip3 install adafruit-nrfutil @@ -55,5 +62,8 @@ RUN bash -c "source /opt/build.sh; GetNrfSdk;" # McuBoot RUN bash -c "source /opt/build.sh; GetMcuBoot;" +# Add the infinitime user for connecting devcontainer +RUN adduser infinitime + ENV SOURCES_DIR /sources CMD ["/opt/build.sh"]