diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 46e2facbde..bba62fb7be 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,65 +1,48 @@ -FROM ubuntu:latest +# devcontainer-specific docker container. +# +# Infinitime has a "build" container which is created by the files in +# /docker/build/. This container can be built locally and is also built +# automatically by the github workflow. +# +# We essentially "wrap" this main docker image so that devcontainers +# can make any customisations required without duplicating the main +# dockerfile or altering it in ways that might break the CI/CD build +# system. -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 \ - 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 +# You can use your own locally-built infinitime-build container (see +# `/docker/README.md), or you can let it download the latest container +# from dockerhub. -RUN pip3 install adafruit-nrfutil -# required for McuBoot -RUN pip3 install setuptools_rust +FROM infinitime/infinitime-build:latest +#FROM infinitime-build:latest -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 +# Add the infinitime user so that devcontainer can set our UID +# to ensure bind mounts have the right permissions on them. +# Also create and chown the mountpoints. +RUN \ + adduser infinitime && \ + mkdir -p /home/infinitime/.vscode-server/extensions && \ + mkdir -p /home/infinitime/.vscode-server-insiders/extensions && \ + chown -R infinitime:infinitime /home/infinitime/.vscode* && \ + # Get required vars into the local env at "login" + echo "source /opt/build.sh" >> /home/infinitime/.bashrc && \ + # Undo the exit-on-error and PS4-echo flags set in build.sh + echo "set +e" >> /home/infinitime/.bashrc && \ + echo "set +x" >> /home/infinitime/.bashrc && \ + # symlink the crosscompiler path so that the intellisense extension + # can find it in a predictable location. Future builder containers + # will already have this link. FIXME: This should be removed once + # fixed in the published image so that we aren't version-tied here. + if [ ! -h /opt/gcc-arm-none-eabi ]; then ln -s /opt/gcc-arm-none-eabi-10.3-2021.10 /opt/gcc-arm-none-eabi; fi && \ + if [ ! -h /opt/nRF5_SDK ]; then ln -s /opt/nRF5_SDK_15.3.0_59ac345 /opt/nRF5_SDK; fi -RUN adduser infinitime +# Setup envars used in vscode settings to symlinks created by build.sh in the build container +ENV NRF5_SDK_PATH /opt/nRF5_SDK +ENV ARM_NONE_EABI_TOOLCHAIN_PATH /opt/gcc-arm-none-eabi +ENV SOURCES_DIR /sources -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 +USER infinitime + +RUN bash -c "source /opt/build.sh; " + +CMD ["/opt/build.sh"] diff --git a/.devcontainer/build.sh b/.devcontainer/build.sh deleted file mode 100644 index 3d8aecbff3..0000000000 --- a/.devcontainer/build.sh +++ /dev/null @@ -1,77 +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 -} - -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 -} - -[[ $SOURCED == "false" ]] && main "$@" || echo "Sourced!" \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1bb315f7ef..afa980bcc7 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,38 +1,48 @@ -// 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 +// This file defines how vscode will work with a docker container to +// present your build environment. +// Info at https://containers.dev/implementors/json_reference/ +// { - // "name": "Pinetime", - // "image": "feabhas/pinetime-dev" + "name": "infinitime_devcontainer", "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" } + // This refers to the dockerfile in this directory. + "dockerfile": "Dockerfile" }, - "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"], - + // Security options required to enable cpp debugging + "capAdd": [ + "SYS_PTRACE" + ], + "securityOpt": [ + "seccomp=unconfined" + ], + // Mount the repository into /sources in the container + "workspaceMount": "source=${localWorkspaceFolder},target=/sources,type=bind", + "workspaceFolder": "/sources", + "mounts": [ + // These volumes store the vscode-specific stuff, and allow us + // to persist them across sessions rather than reinstalling them + // every time. + "source=vscode-devcon-infinitime,target=/home/infinitime/.vscode-server/extensions,type=volume", + "source=vscode-devcon-infinitime-insiders,target=/home/infinitime/.vscode-server-insiders/extensions,type=volume", + // Bind-mount the current build.sh in case it's newer than the one in the builder image. + "source=${localWorkspaceFolder}/docker/build.sh,target=/opt/build.sh,type=bind" + ], // Set *default* container specific settings.json values on container create. - "settings": { + "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", + // this gets in the way of build.sh: "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" + // For linux we need to ensure the UID is mapped to match the local user + // so that files created during the build end up belonging to the local user. + "containerUser": "infinitime", + "updateRemoteUserUID": true } diff --git a/.gitattributes b/.gitattributes index 2257cac4e5..12b8eddf61 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,18 @@ -# Set the default behavior, in case people don't have core.autocrlf set. -* text=auto +# By default treat line-endings as posix-style LF so that windows +# machines can check out a version that will build OK in a +# docker container. + +* text=auto eol=lf + +# Windows-specific files (.bat, .cmd) will require cr/lf endings +*.{cmd,[cC][mM][dD]} text eol=crlf +*.{bat,[bB][aA][tT]} text eol=crlf + +# If one is working on getting bare-metal windows builds to work, +# the following might assist, and you may wish to start by checking +# out your repo with `--config core.eol=crlf`. Note that a repo checked- +# out this way won't build in a docker container due to line-endings +# being being dos-style (CRLF) rather than everything-else style (LF). # Explicitly declare text files you want to always be normalized and converted # to native line endings on checkout. diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index f8da48d59e..ae20e94201 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -8,6 +8,8 @@ "${workspaceFolder}/src" ], "defines": [], + // This should point to the path (inside the devcontainer). See + // the Dockerfile and build.sh "compilerPath": "${env:ARM_NONE_EABI_TOOLCHAIN_PATH}/bin/arm-none-eabi-gcc", "cStandard": "c11", "cppStandard": "c++14", @@ -17,4 +19,4 @@ } ], "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..035b0710c6 --- /dev/null +++ b/.vscode/cmake-kits.json @@ -0,0 +1,10 @@ +[ + { + "name": "Infinitime buildimage kit", + "preferredGenerator": {}, + "compilers": { + "CC": "/opt/gcc-arm-none-eabi/bin/arm-none-eabi-gcc", + "CXX": "/opt/gcc-arm-none-eabi/bin/arm-none-eabi-g++" + } + } +] diff --git a/.vscode/launch.json b/.vscode/launch.json index a50270d25b..16e93cf135 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,16 +1,16 @@ - { +{ "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", + "armToolchainPath": "${env:ARM_NONE_EABI_TOOLCHAIN_PATH}/bin", "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", @@ -23,14 +23,14 @@ }, { "name": "Debug - Openocd Local", - "type":"cortex-debug", - "cortex-debug.armToolchainPath":"${env:ARM_NONE_EABI_TOOLCHAIN_PATH}/bin", + "type": "cortex-debug", + "armToolchainPath": "${env:ARM_NONE_EABI_TOOLCHAIN_PATH}/bin", "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", @@ -48,7 +48,7 @@ "name": "Debug OpenOCD ST-LINK pinetime-app-1.3.0.out", "request": "launch", "type": "cortex-debug", - "showDevDebugOutput": false, + "showDevDebugOutput": "none", "servertype": "openocd", "runToMain": true, // Only use armToolchainPath if your arm-none-eabi-gdb is not in your path (some GCC packages does not contain arm-none-eabi-gdb) @@ -59,6 +59,5 @@ "target/nrf52.cfg" ], } - ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index f1cc3a8176..f64336b809 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,6 @@ { + // *actual* text files end with empty newlines. + "files.insertFinalNewline": true, "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", "cmake.configureArgs": [ "-DARM_NONE_EABI_TOOLCHAIN_PATH=${env:ARM_NONE_EABI_TOOLCHAIN_PATH}", @@ -55,5 +57,6 @@ "streambuf": "cpp", "cinttypes": "cpp", "typeinfo": "cpp" - } + }, + "cmake.configureOnOpen": false } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 17f51f5efd..28eee5f4a1 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -39,6 +39,12 @@ "create openocd build" ], "problemMatcher": [] + }, + { + "label": "Docker build", + "type": "shell", + "command": "/opt/build.sh", + "problemMatcher": [] } ] -} \ No newline at end of file +} diff --git a/docker/build.sh b/docker/build.sh index 07e0d17e49..470397b849 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -33,6 +33,10 @@ main() { [[ ! -d "$TOOLS_DIR/$NRF_SDK_VER" ]] && GetNrfSdk [[ ! -d "$TOOLS_DIR/mcuboot" ]] && GetMcuBoot + # Symlink the toolchain and SDK paths so vscode has predictable locations for them + [[ ! -h "$TOOLS_DIR/gcc-arm-none-eabi" ]] && ln -s $TOOLS_DIR/$GCC_ARM_PATH $TOOLS_DIR/gcc-arm-none-eabi + [[ ! -h "$TOOLS_DIR/nRF5_SDK" ]] && ln -s $TOOLS_DIR/$NRF_SDK_VER $TOOLS_DIR/nRF5_SDK + mkdir -p "$BUILD_DIR" CmakeGenerate