diff --git a/.github/actions/openvic-sim-build/action.yml b/.github/actions/openvic-sim-build/action.yml index 326efdd74..ae84b7b04 100644 --- a/.github/actions/openvic-sim-build/action.yml +++ b/.github/actions/openvic-sim-build/action.yml @@ -20,10 +20,35 @@ inputs: run-tests: description: Whether to run the unit tests after building default: 'true' + enable-cache: + description: Whether to enable the cache for building + default: 'true' runs: using: composite steps: + - name: Install ccache and restore cache + if: inputs.enable-cache == 'true' + uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23 + with: + # Disables sporadic job summary behavior + job-summary: + append-timestamp: false + max-size: 1G + key: ${{ inputs.identifier }}-${{ github.ref }}-${{ github.sha }} + restore-keys: | + ${{ inputs.identifier }}-${{ github.ref }} + ${{ inputs.identifier }} + install: yes + + - name: Allow ccache to cache precompiled headers + if: inputs.enable-cache == 'true' + shell: bash + run: | + ccache --version | head -n 1 + ccache --set-config=sloppiness=pch_defines,time_macros + ccache -p | grep sloppiness + - name: Setup MSVC environment if: ${{ runner.os == 'Windows' }} shell: pwsh @@ -34,21 +59,8 @@ runs: Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -DevCmdArguments '-arch=x64 -host_arch=x64' Get-ChildItem env: | ForEach-Object { Add-Content -Path $env:GITHUB_ENV -Value "$($_.Name)=$($_.Value)" } - - name: Setup Ninja - shell: bash - run: | - # Ninja is preinstalled on GitHub-hosted images; fall back to the - # image's package manager if a future image drops it. - if ! command -v ninja >/dev/null 2>&1; then - if [ "$RUNNER_OS" = "macOS" ]; then - brew install ninja - elif [ "$RUNNER_OS" = "Windows" ]; then - choco install ninja -y - else - sudo apt-get update -y && sudo apt-get install -y ninja-build - fi - fi - ninja --version + - name: Get CMake and Ninja + uses: lukka/get-cmake@e6906078ebd1ccb8ce51ab4626ac46a1b5a517e3 # v4.4.0 - name: Install APT dependencies if: ${{ runner.os == 'Linux' }} @@ -68,25 +80,57 @@ runs: sudo update-alternatives --set g++ /usr/bin/g++-13 g++ --version - - name: Configure - shell: bash - run: | - cmake --preset ${{ inputs.preset }} \ - -DGODOTCPP_TARGET=${{ inputs.target }} \ - ${{ inputs.cmake-args }} - - name: Build - shell: bash - run: | - CONFIG_LOWER=$(echo "${{ inputs.configuration }}" | tr '[:upper:]' '[:lower:]') - cmake --build --preset ${{ inputs.preset }}-$CONFIG_LOWER + uses: lukka/run-cmake@5d55ea7949e25f69f0ecb516d8d572297e03a956 # v10.9 + if: ${{ inputs.run-tests != 'true' }} + env: + INPUTS_CONFIGURATION: ${{ inputs.configuration }} + INPUTS_TARGET: ${{ inputs.target }} + INPUTS_COMPLIANCE_TYPE: ${{ inputs.compliance-type }} + INPUTS_CMAKE_ARGS: ${{ inputs.cmake-args }} + INPUTS_ENABLE_CACHE: ${{ inputs.enable-cache }} + # Disables vcpkg on Windows + VCPKG_ROOT: + with: + configurePreset: ${{ inputs.preset }} + buildPreset: ${{ inputs.preset }} + # Arguments are evaluated by Javascript's eval function + configurePresetAdditionalArgs: | + [ + `-DGODOTCPP_TARGET=$[env.INPUTS_TARGET]`, + $[env.INPUTS_ENABLE_CACHE] ? `-DCMAKE_C_COMPILER_LAUNCHER=ccache` : ``, + $[env.INPUTS_ENABLE_CACHE] ? `-DCMAKE_CXX_COMPILER_LAUNCHER=ccache` : ``, + $[env.INPUTS_ENABLE_CACHE] ? `-DOPENVIC_USE_PCH=OFF` : ``, + $[env.INPUTS_ENABLE_CACHE] && `$[env.RUNNER_OS]` == 'Windows' ? `-DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=$<$:Embedded>` : `` + ].concat(`$[env.INPUTS_CMAKE_ARGS]`.split(/\s+/)).filter((v) => v.length > 0) + buildPresetCmdString: "[`--build`, `--preset`, `$[env.BUILD_PRESET_NAME]-` + `$[env.INPUTS_CONFIGURATION]`.toLowerCase()]" - - name: Run tests + - name: Build and Test + uses: lukka/run-cmake@5d55ea7949e25f69f0ecb516d8d572297e03a956 # v10.9 if: ${{ inputs.run-tests == 'true' }} - shell: bash - run: | - CONFIG_LOWER=$(echo "${{ inputs.configuration }}" | tr '[:upper:]' '[:lower:]') - ctest --preset ${{ inputs.preset }}-$CONFIG_LOWER + env: + INPUTS_CONFIGURATION: ${{ inputs.configuration }} + INPUTS_TARGET: ${{ inputs.target }} + INPUTS_COMPLIANCE_TYPE: ${{ inputs.compliance-type }} + INPUTS_CMAKE_ARGS: ${{ inputs.cmake-args }} + INPUTS_ENABLE_CACHE: ${{ inputs.enable-cache }} + # Disables vcpkg on Windows + VCPKG_ROOT: + with: + configurePreset: ${{ inputs.preset }} + buildPreset: ${{ inputs.preset }} + testPreset: ${{ inputs.preset }} + # Arguments are evaluated by Javascript's eval function + configurePresetAdditionalArgs: | + [ + `-DGODOTCPP_TARGET=$[env.INPUTS_TARGET]`, + $[env.INPUTS_ENABLE_CACHE] ? `-DCMAKE_C_COMPILER_LAUNCHER=ccache` : ``, + $[env.INPUTS_ENABLE_CACHE] ? `-DCMAKE_CXX_COMPILER_LAUNCHER=ccache` : ``, + $[env.INPUTS_ENABLE_CACHE] ? `-DOPENVIC_USE_PCH=OFF` : ``, + $[env.INPUTS_ENABLE_CACHE] && `$[env.RUNNER_OS]` == 'Windows' ? `-DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=$<$:Embedded>` : `` + ].concat(`$[env.INPUTS_CMAKE_ARGS]`.split(/\s+/)).filter((v) => v.length > 0) + buildPresetCmdString: "[`--build`, `--preset`, `$[env.BUILD_PRESET_NAME]-` + `$[env.INPUTS_CONFIGURATION]`.toLowerCase()]" + testPresetCmdString: "[`--preset`, `$[env.BUILD_PRESET_NAME]-` + `$[env.INPUTS_CONFIGURATION]`.toLowerCase()]" - name: Upload library artifact uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 diff --git a/.github/workflows/nightly-releases.yml b/.github/workflows/nightly-releases.yml index b648ece01..4ce900820 100644 --- a/.github/workflows/nightly-releases.yml +++ b/.github/workflows/nightly-releases.yml @@ -165,6 +165,7 @@ jobs: target: template_release run-tests: false cmake-args: -DOPENVIC_SIM_BUILD_TESTS=OFF ${{ matrix.cmake-args }} + enable-cache: false publish-nightly-release: name: Publish Release diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index 6e26ffe98..2c76946b7 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -92,6 +92,7 @@ jobs: target: template_release run-tests: false cmake-args: -DOPENVIC_SIM_BUILD_TESTS=OFF ${{ matrix.cmake-args }} + enable-cache: false publish-release: name: Publish Release diff --git a/src/openvic-simulation/core/memory/Formatting.hpp b/src/openvic-simulation/core/memory/Formatting.hpp index 60455099c..2e229ee18 100644 --- a/src/openvic-simulation/core/memory/Formatting.hpp +++ b/src/openvic-simulation/core/memory/Formatting.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include #include