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

148 add devcontainer #163

Merged
merged 14 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM ubuntu:22.04

# Install python
RUN apt-get update
RUN apt-get install -y \
python3 \
python3-venv \
python3-pip

# Dev tools require an additional update
RUN apt-get update
RUN apt-get install -y \
git \
gdb \
curl \
zip \
unzip \
tar \
autoconf \
libtool \
libtool-bin \
pkg-config
Comment on lines +12 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not an issue, but I believe the build-essential metapackage includes git, gdb, gcc, autconf, libtool, automake, and pkgconfig. It's sometimes handy if you need to set up the environment without needing to remember all the individual packages.

I don't know if you also need automake. Presumably not if the builds are running.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the GitHub CI images like ubuntu-latest these tools are present, but for the regular container I had to add them manually. It seems that the default ubuntu image is very minimal (no git for example).


WORKDIR /tools

# Create new venv at container root and install libs
RUN python3 -m venv /tools/venv
ENV PATH /tools/venv/bin:$PATH
RUN pip install --upgrade pip setuptools wheel
RUN pip install \
cmake \
ninja \
pybind11 \
numpy \
pytest \
pytest-cov

# FIXME make conditional on arm, s390x, ppc64le and riscv
ENV VCPKG_FORCE_SYSTEM_BINARIES=1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon checking the documentation, this just forces VCPKG not to install things like CMake and Ninja. This probably doesn't hurt anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, I saw your last reply after I'd made a change! I've made it conditional so only sets this when uname -m is aarch64. I'll leave it in though, as I would prefer not to set build flags unnecessarily; now if one is working on a Linux container they can be sure no extra flags are being set.


# Install vcpkg in checkout location
RUN git clone https://github.com/Microsoft/vcpkg.git /tools/vcpkg
RUN /tools/vcpkg/bootstrap-vcpkg.sh
ENV PATH /tools/vcpkg:$PATH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to add vcpkg too the PATH. Since RoughPy uses a manifest build, we never actually interact with the binary itself directly. Instead, you should set the VCPKG_ROOT environment variable (RoughPy's configuration will detect this), or set the CMAKE_TOOLCHAIN_FILE environment variable to ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake, or otherwise specify this on the command line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Sam. Setting VCPKG_ROOT works perfectly. Double-checked on fresh clone and it's building everything from scratch correctly.


# This is required to be able to run pytest in the VSCode terminal
ENV PYTHONPATH=.
34 changes: 34 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Build and debug in VSCode devcontainer

The `.devcontainer/` folder provides a consistent build and debug environment that can be run in VSCode locally or in GitHub Codespaces remotely.

## Opening devcontainer locally

When you open the cloned RoughPy folder in VSCode, it will detect the `.devcontainer/` folder. Accept the popup to open in a Dev Container or run the editor command `Dev Containers: Reopen in Dev Container`. If the container image needs to be rebuilt, it will take a few extra minutes.

VSCode will restart inside a container that mounts your checkout folder to `/workspaces/<dirname>`. Be mindful that editing files is affecting this folder on your machine.

The devcontainer `Dockerfile` sets up a root `/tools` folder that contains a `venv` with build dependencies pre-installed, and a clone of `vcpkg`; both of which are added to `$PATH`.

On the first run, the project will need to be configured in CMake and additional build dependencies will be fetched by vcpkg. You must wait for this to finish before you can build and run any tests. Progress can be tracked under 'CMake/Build' in the VSCode 'Output' panel.


## Building, testing and debugging

Run the editor command `CMake: Select Configure Preset` and select `Debug Develop` to compile with debug symbols. Then run `CMake: build`.

The devcontainer automatically installs the pytest and CTest extension, so after building you can launch any of the tests from the VSCode test explorer panel. Alternatively, you can run directly `pytest` directly from the integrated terminal.

VSCode loads debug scenarios from `.vscode/launch.json`. However, developers frequently need to edit this file with changes that should not be committed, so instead it is stored in `.devcontainer/example_launch.json`. Manually copy this over with:

```sh
cp .devcontainer/example_launch.json .vscode/launch.json
```

Select a debug scenario in the Run and Debug panel, add a breakpoint on the code to stop on, and launch with F5.

The three example scenarios are:

- `debugpy pytest` - Debug a specific `pytest` unit test in a python debugger.
- `gdb pytest` - Start a python test and debug any underlying C++.
- `gdb gtest` - Debug a specific GTest unit test in a C++ debugger.
37 changes: 37 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
{
"name": "RoughPy",

"build": {
"dockerfile": "Dockerfile"
},

"customizations": {
"vscode":{
"extensions": [
"ms-python.debugpy",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-vscode.cmake-tools",
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack"
],
"settings": {
"python.defaultInterpreterPath": "/tools/venv/bin/python",
"python.languageServer": "Pylance",
"python.testing.pytestEnabled": true,
"cmake.cmakePath": "/tools/venv/bin/cmake",
"cmake.configureArgs": [
"-DCMAKE_MAKE_PROGRAM=/tools/venv/bin/ninja",
"-DCMAKE_TOOLCHAIN_FILE=/tools/vcpkg/scripts/buildsystems/vcpkg.cmake"
]
}
}
},

// Enable debugging in container
"capAdd": [
"SYS_PTRACE"
]
}
73 changes: 73 additions & 0 deletions .devcontainer/example_launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "debugpy pytest",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"console": "integratedTerminal",
"args": [
"-k", "test_exp_log_roundtrip_poly_coeffs"
],
"env": {},
"preLaunchTask": "CMake: build"
},
{
"name": "gdb pytest",
"type": "cppdbg",
"request": "launch",
"program": "${config:python.defaultInterpreterPath}",
"args": [
"-m", "pytest",
"-k", "test_exp_log_roundtrip_poly_coeffs"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "CMake: build"
},
{
"name": "gdb gtest",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/dev-debug/intervals/src/test_intervals",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "CMake: build"
}
]
}
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Unreleased
- Added VSCode `.devcontainer` settings for containerised developer environment for debugging tests. See `.devcontainer/README.md` for instructions (@alexallmont #148)

Version 0.1.2
- Documentation is now in sync with the main branch (@philipparubin PR #85)
- Fixed a fault when constructing with larger than expected array (Issue #70, @inakleinbottle PR #72)
Expand Down
10 changes: 10 additions & 0 deletions tools/triplets/arm64-linux.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)

set(VCPKG_CMAKE_SYSTEM_NAME Linux)

# FIXME for discussion in PR. I had to add this to get containers working in MacOS, as it seems the macro is not set correctly by default.
if (PORT MATCHES "mpg123")
set(VCPKG_CMAKE_CONFIGURE_OPTIONS "-DHAVE_FPU=1")
endif()
Loading