Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update vscode configuration for devcontainers #1401

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
103 changes: 43 additions & 60 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
77 changes: 0 additions & 77 deletions .devcontainer/build.sh

This file was deleted.

54 changes: 32 additions & 22 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 15 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 3 additions & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -17,4 +19,4 @@
}
],
"version": 4
}
}
10 changes: 10 additions & 0 deletions .vscode/cmake-kits.json
Original file line number Diff line number Diff line change
@@ -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++"
}
}
]
17 changes: 8 additions & 9 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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)
Expand All @@ -59,6 +59,5 @@
"target/nrf52.cfg"
],
}

]
}
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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}",
Expand Down Expand Up @@ -55,5 +57,6 @@
"streambuf": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp"
}
},
"cmake.configureOnOpen": false
}
8 changes: 7 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
"create openocd build"
],
"problemMatcher": []
},
{
"label": "Docker build",
"type": "shell",
"command": "/opt/build.sh",
"problemMatcher": []
}
]
}
}
Loading