diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..df4af73 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,66 @@ +FROM ubuntu:24.04 + +# Install apt dependencies +ARG DEBIAN_FRONTEND=noninteractive +ARG NODE_MAJOR=20 +RUN apt-get update -qq \ + && apt-get install -y \ + curl \ + cmake \ + ccache \ + libsdl2-dev \ + g++ \ + gdb \ + git \ + libpng-dev \ + ninja-build \ + sudo \ + python3-pip \ + python3-venv \ + && rm -rf /var/cache/apt/* /var/lib/apt/lists/* + +# Install nodejs based dependencies +RUN curl -sL https://deb.nodesource.com/setup_${NODE_MAJOR}.x -o nodesource_setup.sh \ + && bash nodesource_setup.sh \ + && apt-get update -qq \ + && apt-get install -y nodejs \ + && npm install -g \ + lv_font_conv@1.5.2 \ + && rm nodesource_setup.sh \ + && rm -rf /var/cache/apt/* /var/lib/apt/lists/* + +# Install Python dependencies +RUN pip install --break-system-packages \ + wheel \ + Pillow \ + && pip cache purge + +# The user ubuntu already exists set its password to ubuntu and add to sudo group for developing in devcontainer +RUN usermod -aG sudo ubuntu \ + && echo "ubuntu:ubuntu" | chpasswd + +# Persist bash history across container rebuilds +# Reference: https://code.visualstudio.com/remote/advancedcontainers/persist-bash-history +ARG USERNAME=ubuntu +RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \ + && mkdir /commandhistory \ + && touch /commandhistory/.bash_history \ + && chown -R $USERNAME /commandhistory \ + && echo "$SNIPPET" >> "/home/$USERNAME/.bashrc" + +USER ubuntu + +# Section for interactive compilation during docker run + +WORKDIR /sources +# Directory if InfiniTime source code +ENV InfiniTime_DIR="/sources/InfiniTime" +# Passed to CMake generate step +ENV GENERATE_ARGS="" +# Passed to CMake build step +ENV BUILD_ARGS="" +# Build directory +ENV BUILD_DIRECTORY="build" + +CMD ["bash", "-c", "cmake -S . -B ${BUILD_DIRECTORY} -G Ninja -DInfiniTime_DIR=${InfiniTime_DIR} ${GENERATE_ARGS} \ + && cmake --build ${BUILD_DIRECTORY} ${BUILD_ARGS}"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..0fe8586 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,35 @@ +// For format details, see https://aka.ms/devcontainer.json. +{ + "name": "InfiniSim Dev Container", + "build": { + "dockerfile": "Dockerfile" + }, + + // Configure tool-specific properties. + "customizations": { + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-vscode.cpptools", + "ms-vscode.cmake-tools", + "notskm.clang-tidy", + "mjohns.clang-format", + "timonwong.shellcheck" + ] + } + }, + + "mounts": [ + // Local volume to store bash history across rebuilds + "source=infinisim-bashhistory,target=/commandhistory,type=volume" + // Uncomment and modify path to mount external InfiniTime source into the container + //,"source=/home/example/git/InfiniTime,target=/workspaces/InfiniTime,type=bind,consistency=cached" + ], + + // Sudo password "ubuntu" + "remoteUser": "ubuntu" + // This might be needed when you do not have a local user called ubuntu but your dev container implementation + // tries to find it in the local /etc/passwd and fails to build your container. + // The default is true. + //,"updateRemoteUserUID": false +} diff --git a/README.md b/README.md index b8008b9..9ac1747 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,32 @@ The following configuration settings can be added to the first `cmake -S . -B bu Ex: `-DENABLE_USERAPPS="Apps::Timer, Apps::Alarm"`. The default list of user applications will be selected if this variable is not set. +### Build with Docker + +You can also build the simulator using Docker. +This is useful if you don't want to install all the dependencies on your system. +First build the Docker image: +```sh +docker build -t infinisim-build .devcontainer +``` + +Afterwards you can build the simulator with: +```sh +docker run --rm -it -v ${PWD}:/sources infinisim-build +``` + +By default this builds the simulator using the InfiniTime files from the submodule in your `${PWD}`. +If you want to use a different repository, you got to mount it and pass the path to the `INFINITIME_DIR` variable: +```sh +docker run --rm -it -v ${PWD}:/sources -v ${PWD}/../InfiniTime:/infinitime -e INFINITIME_DIR=/infinitime infinisim-build +``` + +Other CMake generation and build arguments can be passed to the `GENERATE_ARGS` and `BUILD_ARGS` variables: +```sh +docker run --rm -it -v ${PWD}:/sources -e GENERATE_ARGS=-DENABLE_USERAPPS="Apps::Timer,Apps::Alarm" -e BUILD_ARGS=-j16 infinisim-build +``` + + ## Run Simulator When the build was successful the simulator binary can be started with