diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index f229431..13466c5 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -2,9 +2,9 @@ ARG DEBIAN_VERSION=forky FROM debian:${DEBIAN_VERSION}-slim -ARG CLANG_VERSION -ARG CMAKE_VERSION -ARG CPPCHECK_VERSION +ARG CLANG_VERSION=21 +ARG CMAKE_VERSION=4.2.1 +ARG CPPCHECK_VERSION=2.18.0 # install base packages diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1752c36..670f2b0 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,12 +1,7 @@ { "name": "C++ Devcontainer", "build": { - "dockerfile": "Dockerfile", - "args": { - "CLANG_VERSION": "21", - "CMAKE_VERSION": "4.2.1", - "CPPCHECK_VERSION": "2.18.0" - } + "dockerfile": "Dockerfile" }, "remoteUser": "user" } diff --git a/.github/workflows/sanity-checks.yaml b/.github/workflows/sanity-checks.yaml new file mode 100644 index 0000000..8054930 --- /dev/null +++ b/.github/workflows/sanity-checks.yaml @@ -0,0 +1,84 @@ +name: Sanity Checks +on: + push: + branches: + - main + pull_request: + branches: + - main +env: + GHCR_URL_WITH_UPPERCASE: ghcr.io/${{ github.repository }} +jobs: + build-devcontainer-image: + name: Build devcontainer + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v6 + - name: Convert GHCR url to lower case + run: echo "GHCR_URL=${GHCR_URL_WITH_UPPERCASE@L}" >> ${GITHUB_ENV} + - name: Login to Github Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Pre-build dev container image + uses: devcontainers/ci@v0.3 + with: + imageName: ${{ env.GHCR_URL }} + cacheFrom: ${{ env.GHCR_URL }} + push: always + check-tools-installed: + name: Check if all tools are installed + needs: build-devcontainer-image + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v6 + - name: Convert GHCR url to lower case + run: echo "GHCR_URL=${GHCR_URL_WITH_UPPERCASE@L}" >> ${GITHUB_ENV} + - name: Login to Github Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Check tools + uses: devcontainers/ci@v0.3 + with: + cacheFrom: ${{ env.GHCR_URL }} + push: never + runCmd: | + clang --version + cmake --version + cppcheck --version + vcpkg --version + build-test-project: + name: Build test project + needs: build-devcontainer-image + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v6 + - name: Convert GHCR url to lower case + run: echo "GHCR_URL=${GHCR_URL_WITH_UPPERCASE@L}" >> ${GITHUB_ENV} + - name: Login to Github Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build test project + uses: devcontainers/ci@v0.3 + with: + cacheFrom: ${{ env.GHCR_URL }} + push: never + runCmd: | + cd test + cmake --preset clang-debug + cmake --build --preset clang-debug-build + ./build/clang-debug/hello_world diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..bcf3d28 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 4.2 FATAL_ERROR) + +# workaround clang bug +set(CMAKE_CXX_STDLIB_MODULES_JSON "/usr/lib/llvm-21/lib/libc++.modules.json") + +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "d0edc3af-4c50-42ea-a356-e2862fe7a444") +set(CMAKE_CXX_MODULE_STD ON) +set(CMAKE_CXX_STANDARD 26) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +project(TestCppDevcontainer LANGUAGES CXX) + +add_executable(hello_world) +target_sources(hello_world PRIVATE "main.cpp") diff --git a/test/CMakePresets.json b/test/CMakePresets.json new file mode 100644 index 0000000..7c18531 --- /dev/null +++ b/test/CMakePresets.json @@ -0,0 +1,26 @@ +{ + "version": 6, + "cmakeMinimumRequired": { + "major": 4, + "minor": 2, + "patch": 0 + }, + "configurePresets": [ + { + "name": "clang-debug", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_CXX_COMPILER": "/usr/bin/clang++", + "CMAKE_CXX_FLAGS": "-stdlib=libc++", + "CMAKE_BUILD_TYPE": "Debug" + } + } + ], + "buildPresets": [ + { + "name": "clang-debug-build", + "configurePreset": "clang-debug" + } + ] +} diff --git a/test/main.cpp b/test/main.cpp new file mode 100644 index 0000000..f0c6fa9 --- /dev/null +++ b/test/main.cpp @@ -0,0 +1,6 @@ +import std; + +int main() +{ + std::println("Hello, world!"); +}