Skip to content

Commit

Permalink
feat: add conan package manager to amp-devcontainer-cpp (#607)
Browse files Browse the repository at this point in the history
* feat: add conan package manager to amp-devcontainer-cpp

* test: add Conan test

* chore: create a default conan profile

* chore: fix conan profile setup

* fix: revert accidental typo in BATS_VERSION

* docs: update README to mention package managers

* test: remove explicit generator from Conan test
  • Loading branch information
rjaegers authored Oct 22, 2024
1 parent e73794d commit e142e40
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 14 deletions.
10 changes: 7 additions & 3 deletions .devcontainer/cpp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ ENV CMAKE_GENERATOR="Ninja"
ENV CMAKE_EXPORT_COMPILE_COMMANDS="On"
ENV CCACHE_DIR=/root/.ccache

# Install CPM.cmake to the CMake module path
RUN wget -qP /usr/local/lib/python*/dist-packages/cmake/data/share/cmake-*/Modules/ https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_VERSION}/CPM.cmake

# Install clang toolchain
COPY .devcontainer/cpp/apt-requirements-clang.json /tmp/apt-requirements-clang.json
# hadolint ignore=SC1091
Expand Down Expand Up @@ -108,3 +105,10 @@ RUN update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-13 20 \
&& update-alternatives --install /usr/lib/mull-ir-frontend mull-ir-frontend /usr/local/lib/mull-ir-frontend-${CLANG_VERSION} 10 \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 10 \
&& cp /etc/skel/.bashrc /root/.bashrc

# Set up package managers CPM and Conan
# - Install CPM.cmake to the CMake module path
# - Configure a default profile for Conan and set the CMake generator to Ninja
RUN wget -qP /usr/local/lib/python*/dist-packages/cmake/data/share/cmake-*/Modules/ https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_VERSION}/CPM.cmake \
&& conan profile detect \
&& echo -e "\n[conf]\ntools.cmake.cmaketoolchain:generator=Ninja" >> "$(conan profile path default)"
1 change: 1 addition & 0 deletions .devcontainer/cpp/requirements.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cmake==3.30.5
conan==2.8.1
gcovr==8.2
220 changes: 212 additions & 8 deletions .devcontainer/cpp/requirements.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .devcontainer/cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.24)
cmake_minimum_required(VERSION 3.30)
project(devcontainer-test LANGUAGES ASM C CXX)

include(CTest)
Expand Down
8 changes: 8 additions & 0 deletions .devcontainer/cpp/test/package-managers/conan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Seperate project as Conan is in the drivers seat

cmake_minimum_required(VERSION 3.30)
project(conan-test LANGUAGES CXX)

find_package(fmt REQUIRED)
add_executable(test-conan main.cpp)
target_link_libraries(test-conan PRIVATE fmt::fmt)
9 changes: 9 additions & 0 deletions .devcontainer/cpp/test/package-managers/conan/conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[requires]
fmt/11.0.2

[generators]
CMakeDeps
CMakeToolchain

[layout]
cmake_layout
7 changes: 7 additions & 0 deletions .devcontainer/cpp/test/package-managers/conan/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <fmt/core.h>

int main()
{
fmt::print("Hello, world!\n");
return 0;
}
13 changes: 12 additions & 1 deletion .devcontainer/cpp/test/testsuite.bats
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ setup() {
}

teardown() {
rm -rf build crash-*
rm -rf build crash-* $(conan config home)/p
}

@test "valid code input should result in working executable using host compiler" {
Expand Down Expand Up @@ -170,6 +170,17 @@ teardown() {
build_and_run_with_sanitizers clang
}

@test "using Conan as package manager should resolve external dependencies" {
pushd package-managers/conan

conan install . --output-folder=../../build --build=missing

cmake --preset conan-release
cmake --build --preset conan-release

popd
}

@test "using CPM as package manager should resolve external dependencies" {
cmake --preset cpm
cmake --build --preset cpm
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ test-results/
*.profdata
*.profraw
**/playwright/.auth/user.json
CMakeUserPresets.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ A summary of the included tools can be found below. For the full list of all inc

The amp-devcontainer-cpp built from this repository contains compilers and tools to facilitate modern, embedded, C++ development.
The amp-devcontainer-cpp includes support for host- and cross-compilation using gcc, arm-gcc and clang compilers.
Next to the compilers there is support for code-coverage measurement, mutation testing (using [mull](https://github.com/mull-project/mull)), fuzzing (using [libfuzzer](https://www.llvm.org/docs/LibFuzzer.html)) and static analysis and formatting (clang-format, clang-tidy, clangd, include-what-you-use).
Next to the compilers there is support for package management (using [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) and [Conan](https://conan.io/)) code-coverage measurement, mutation testing (using [mull](https://github.com/mull-project/mull)), fuzzing (using [libfuzzer](https://www.llvm.org/docs/LibFuzzer.html)) and static analysis and formatting (clang-format, clang-tidy, clangd, include-what-you-use).

The default build system is set up to use CMake, Ninja and CCache.

Expand Down

0 comments on commit e142e40

Please sign in to comment.