Skip to content

Commit 65423b3

Browse files
Niall Coolinggeekbozu
authored andcommitted
added devcontainer files
1 parent 57b3397 commit 65423b3

3 files changed

Lines changed: 153 additions & 0 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
FROM ubuntu:18.04
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
RUN apt-get update -qq \
5+
&& apt-get install -y \
6+
# x86_64 / generic packages
7+
bash \
8+
build-essential \
9+
cmake \
10+
git \
11+
make \
12+
python3 \
13+
python3-pip \
14+
tar \
15+
unzip \
16+
wget \
17+
curl \
18+
# aarch64 packages
19+
libffi-dev \
20+
libssl-dev \
21+
python3-dev \
22+
rustc \
23+
&& rm -rf /var/cache/apt/* /var/lib/apt/lists/*;
24+
25+
RUN adduser infinitime
26+
27+
RUN pip3 install adafruit-nrfutil
28+
# required for McuBoot
29+
RUN pip3 install setuptools_rust
30+
31+
WORKDIR /opt/
32+
# build.sh knows how to compile
33+
COPY build.sh .
34+
35+
# Lets get each in a separate docker layer for better downloads
36+
# GCC
37+
RUN bash -c "source /opt/build.sh; GetGcc;"
38+
# NrfSdk
39+
RUN bash -c "source /opt/build.sh; GetNrfSdk;"
40+
# McuBoot
41+
RUN bash -c "source /opt/build.sh; GetMcuBoot;"
42+
43+
ENV SOURCES_DIR /workspaces/Pinetime

.devcontainer/build.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
(return 0 2>/dev/null) && SOURCED="true" || SOURCED="false"
3+
export LC_ALL=C.UTF-8
4+
export LANG=C.UTF-8
5+
set -x
6+
set -e
7+
8+
# Default locations if the var isn't already set
9+
export TOOLS_DIR="${TOOLS_DIR:=/opt}"
10+
export SOURCES_DIR="${SOURCES_DIR:=/sources}"
11+
export BUILD_DIR="${BUILD_DIR:=$SOURCES_DIR/build}"
12+
export OUTPUT_DIR="${OUTPUT_DIR:=$BUILD_DIR/output}"
13+
14+
export BUILD_TYPE=${BUILD_TYPE:=Release}
15+
export GCC_ARM_VER=${GCC_ARM_VER:="gcc-arm-none-eabi-9-2020-q2-update"}
16+
export NRF_SDK_VER=${NRF_SDK_VER:="nRF5_SDK_15.3.0_59ac345"}
17+
18+
MACHINE="$(uname -m)"
19+
[[ "$MACHINE" == "arm64" ]] && MACHINE="aarch64"
20+
21+
main() {
22+
local target="$1"
23+
24+
mkdir -p "$TOOLS_DIR"
25+
26+
[[ ! -d "$TOOLS_DIR/$GCC_ARM_VER" ]] && GetGcc
27+
[[ ! -d "$TOOLS_DIR/$NRF_SDK_VER" ]] && GetNrfSdk
28+
[[ ! -d "$TOOLS_DIR/mcuboot" ]] && GetMcuBoot
29+
30+
mkdir -p "$BUILD_DIR"
31+
32+
CmakeGenerate
33+
CmakeBuild $target
34+
BUILD_RESULT=$?
35+
if [ "$DISABLE_POSTBUILD" != "true" -a "$BUILD_RESULT" == 0 ]; then
36+
source "$BUILD_DIR/post_build.sh"
37+
fi
38+
}
39+
40+
GetGcc() {
41+
GCC_SRC="$GCC_ARM_VER-$MACHINE-linux.tar.bz"
42+
wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/$GCC_SRC -O - | tar -xj -C $TOOLS_DIR/
43+
}
44+
45+
GetMcuBoot() {
46+
git clone https://github.com/JuulLabs-OSS/mcuboot.git "$TOOLS_DIR/mcuboot"
47+
pip3 install -r "$TOOLS_DIR/mcuboot/scripts/requirements.txt"
48+
}
49+
50+
GetNrfSdk() {
51+
wget -q "https://developer.nordicsemi.com/nRF5_SDK/nRF5_SDK_v15.x.x/$NRF_SDK_VER.zip" -O /tmp/$NRF_SDK_VER
52+
unzip -q /tmp/$NRF_SDK_VER -d "$TOOLS_DIR/"
53+
rm /tmp/$NRF_SDK_VER
54+
}
55+
56+
CmakeGenerate() {
57+
# We can swap the CD and trailing SOURCES_DIR for -B and -S respectively
58+
# once we go to newer CMake (Ubuntu 18.10 gives us CMake 3.10)
59+
cd "$BUILD_DIR"
60+
61+
cmake -G "Unix Makefiles" \
62+
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
63+
-DUSE_OPENOCD=1 \
64+
-DARM_NONE_EABI_TOOLCHAIN_PATH="$TOOLS_DIR/$GCC_ARM_VER" \
65+
-DNRF5_SDK_PATH="$TOOLS_DIR/$NRF_SDK_VER" \
66+
"$SOURCES_DIR"
67+
cmake -L -N .
68+
}
69+
70+
CmakeBuild() {
71+
local target="$1"
72+
[[ -n "$target" ]] && target="--target $target"
73+
if cmake --build "$BUILD_DIR" --config $BUILD_TYPE $target -- -j$(nproc)
74+
then return 0; else return 1;
75+
fi
76+
}
77+
78+
[[ $SOURCED == "false" ]] && main "$@" || echo "Sourced!"

.devcontainer/devcontainer.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.154.2/containers/cpp
3+
{
4+
// "name": "Pinetime",
5+
// "image": "feabhas/pinetime-dev"
6+
"build": {
7+
"dockerfile": "Dockerfile",
8+
// Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-10, debian-9, ubuntu-20.04, ubuntu-18.04
9+
// "args": { "VARIANT": "ubuntu-20.04" }
10+
},
11+
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],
12+
13+
// Set *default* container specific settings.json values on container create.
14+
"settings": {
15+
"terminal.integrated.shell.linux": "/bin/bash"
16+
},
17+
18+
// Add the IDs of extensions you want installed when the container is created.
19+
"extensions": [
20+
"ms-vscode.cpptools"
21+
],
22+
23+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
24+
// "forwardPorts": [],
25+
26+
// Use 'postCreateCommand' to run commands after the container is created.
27+
// "postCreateCommand": "gcc -v",
28+
29+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
30+
// "remoteUser": "vscode"
31+
"remoteUser": "infinitime"
32+
}

0 commit comments

Comments
 (0)