diff --git a/.claude/skills/orca-wxwidgets/references/painting-custom-widgets.md b/.claude/skills/orca-wxwidgets/references/painting-custom-widgets.md index 4f047042c3..7563d8db94 100644 --- a/.claude/skills/orca-wxwidgets/references/painting-custom-widgets.md +++ b/.claude/skills/orca-wxwidgets/references/painting-custom-widgets.md @@ -739,6 +739,12 @@ plain window. static `GetParentBackgroundColor(wxWindow*)`. Protected members: `radius`, `border_width`, `top_margin`, `border_style`, `state_handler`, `border_color`, `background_color`, `background_color2`, `badge`. +- **Input corner radius:** the boxed inputs (`TextInput` and so `ComboBox`, `SpinInput`, `TempInput`) + share `StaticBox::InputCornerRadius` (DIP). Their constructor sets the protected `input_corner_radius` + flag, and `Create()` and `Rescale()` call `apply_input_corner_radius()`, which re-applies + `FromDIP(InputCornerRadius)` at the current DPI. `SetCornerRadius()` clears the flag, so an explicit + radius (`0` for square cells in tables and grids) survives a DPI change. A new boxed input follows + the same three steps. - **`SetBackgroundColor` ≠ wx `SetBackgroundColour`.** The former sets the `StateColor` fill that `doRender` paints; the latter is the wx window colour that the erase pass uses outside the rounded rect. They are different things on purpose. diff --git a/.github/workflows/build_all.yml b/.github/workflows/build_all.yml index 1aa14d9810..3fb204ef42 100644 --- a/.github/workflows/build_all.yml +++ b/.github/workflows/build_all.yml @@ -34,6 +34,7 @@ on: branches: - main - release/* + # build_optional.yml keeps the same list, plus scripts/flatpak/**. paths: - 'deps/**' - 'deps_src/**' @@ -52,7 +53,6 @@ on: - 'scripts/build_preset_cache.*' - 'scripts/prune_cached_presets.ps1' - 'scripts/test_prune_cached_presets.ps1' - - 'scripts/flatpak/**' - 'scripts/msix/**' - 'scripts/sign_windows.ps1' - 'tests/**' @@ -78,9 +78,40 @@ concurrency: jobs: - # build_win.bat ships a test suite. Run it before the Windows builds. + # build_win.bat and two of the scripts it runs ship test suites. They run + # before the Windows builds, on a pull request only when it changes one of + # the scripts or the suites: the suites build their own fixtures and read + # nothing else from the tree. Pushes and the nightly always run them. + build_script_changes: + name: Look for build script changes + if: ${{ github.event_name == 'pull_request' }} + runs-on: ubuntu-24.04 + outputs: + changed: ${{ steps.changes.outputs.changed }} + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + lfs: 'false' + # The merge commit plus its first parent, the base it is diffed against. + fetch-depth: 2 + sparse-checkout: .github/workflows + - name: Look for changed files + id: changes + run: | + if git diff --quiet HEAD^1 HEAD -- build_win.bat .github/workflows/build_all.yml \ + scripts/check_exception_throw_info.ps1 scripts/prune_cached_presets.ps1 \ + scripts/test_build_win.ps1 scripts/test_check_exception_throw_info.ps1 scripts/test_prune_cached_presets.ps1; then + echo "No build script changes." + else + echo "changed=true" >> "$GITHUB_OUTPUT" + fi check_build_script: name: Windows build script tests + needs: build_script_changes + # Runs unless the lookup ran and found nothing: skipped off pull requests, + # and failed lookups run the suites rather than skip them. + if: ${{ !cancelled() && (needs.build_script_changes.result != 'success' || needs.build_script_changes.outputs.changed == 'true') }} runs-on: windows-latest steps: - name: Checkout @@ -125,10 +156,14 @@ jobs: strategy: fail-fast: false # SELF_HOSTED skips arm64 (the self-hosted Windows server is x64-only). + # So does a pull request; build_optional.yml builds arm64 on the + # build-windows-arm64 label or a change outside the sources. matrix: include: ${{ fromJSON(vars.SELF_HOSTED && '[{"arch":"x64","os":"orca-win-server","compiler":"clang"}]' - || '[{"arch":"x64","os":"windows-latest","compiler":"clang"},{"arch":"arm64","os":"windows-11-vs2026-arm","compiler":"clang"}]') }} + || (github.event_name == 'pull_request' + && '[{"arch":"x64","os":"windows-latest","compiler":"clang"}]' + || '[{"arch":"x64","os":"windows-latest","compiler":"clang"},{"arch":"arm64","os":"windows-11-vs2026-arm","compiler":"clang"}]')) }} needs: check_build_script # id-token lets release builds sign through Google Cloud Workload Identity Federation (see # "Configure code signing" in build_orca.yml); the rest is what the build already used. @@ -137,7 +172,7 @@ jobs: contents: write id-token: write # Don't run scheduled builds on forks: - if: ${{ !cancelled() && needs.check_build_script.result == 'success' && (github.event_name != 'schedule' || github.repository == 'OrcaSlicer/OrcaSlicer') }} + if: ${{ !cancelled() && contains(fromJSON('["success", "skipped"]'), needs.check_build_script.result) && (github.event_name != 'schedule' || github.repository == 'OrcaSlicer/OrcaSlicer') }} uses: ./.github/workflows/build_check_cache.yml with: os: ${{ matrix.os }} @@ -149,10 +184,11 @@ jobs: build_macos_arch: strategy: fail-fast: false + # Hosted macOS runners are scarce, so a pull request builds arm64 only and + # ships it as its own DMG; build_optional.yml builds x86_64 on the + # build-macos-x86_64 label. Pushes build both and combine them below. matrix: - arch: - - arm64 - - x86_64 + arch: ${{ fromJSON(github.event_name == 'pull_request' && '["arm64"]' || '["arm64", "x86_64"]') }} # Don't run scheduled builds on forks: if: ${{ !cancelled() && (github.event_name != 'schedule' || github.repository == 'OrcaSlicer/OrcaSlicer') }} uses: ./.github/workflows/build_check_cache.yml @@ -165,7 +201,7 @@ jobs: build_macos_universal: name: Build macOS Universal needs: build_macos_arch - if: ${{ !cancelled() && needs.build_macos_arch.result == 'success' && !inputs.build-deps-only && (github.event_name != 'schedule' || github.repository == 'OrcaSlicer/OrcaSlicer') }} + if: ${{ !cancelled() && needs.build_macos_arch.result == 'success' && !inputs.build-deps-only && github.event_name != 'pull_request' && (github.event_name != 'schedule' || github.repository == 'OrcaSlicer/OrcaSlicer') }} uses: ./.github/workflows/build_orca.yml with: os: ${{ vars.SELF_HOSTED && 'orca-macos-arm64' || 'macos-15' }} @@ -189,10 +225,11 @@ jobs: with: os: ubuntu-24.04-arm artifact: ${{ github.sha }}-tests-linux-aarch64 + # The explicit result, as the script tests ahead of the build may be skipped. unit_tests_windows_x64: name: Windows x64 needs: build_windows - if: ${{ !cancelled() && success() }} + if: ${{ !cancelled() && needs.build_windows.result == 'success' }} uses: ./.github/workflows/unit_tests.yml with: os: ${{ vars.SELF_HOSTED && 'orca-win-server' || 'windows-latest' }} @@ -200,7 +237,7 @@ jobs: unit_tests_windows_arm64: name: Windows arm64 needs: build_windows - if: ${{ !cancelled() && success() && !vars.SELF_HOSTED }} + if: ${{ !cancelled() && needs.build_windows.result == 'success' && !vars.SELF_HOSTED && github.event_name != 'pull_request' }} uses: ./.github/workflows/unit_tests.yml with: os: windows-11-vs2026-arm @@ -243,7 +280,7 @@ jobs: ./validator-bin/OrcaSlicer_profile_validator -p "${{ github.workspace }}/resources/profiles" -s -l 2 publish_test_results: name: Publish Test Results - needs: [unit_tests_linux_x86_64, unit_tests_linux_aarch64, unit_tests_windows_x64, unit_tests_windows_arm64, unit_tests_macos_arm64, unit_tests_flatpak_x86_64, unit_tests_flatpak_aarch64] + needs: [unit_tests_linux_x86_64, unit_tests_linux_aarch64, unit_tests_windows_x64, unit_tests_windows_arm64, unit_tests_macos_arm64, flatpak] if: ${{ !cancelled() }} runs-on: ubuntu-latest steps: @@ -265,259 +302,10 @@ jobs: with: name: test-results-* failOnError: false + # Pull requests build it on the build-flatpak label, from build_optional.yml. flatpak: - name: "Flatpak" - container: - image: ghcr.io/flathub-infra/flatpak-github-actions:gnome-50 - options: --privileged - volumes: - - /usr/local/lib/android:/usr/local/lib/android - - /usr/share/dotnet:/usr/share/dotnet - - /opt/ghc:/opt/ghc1 - - /usr/local/share/boost:/usr/local/share/boost1 - - /opt/hostedtoolcache:/opt/hostedtoolcache1 - # Updating a runtime renames its old deployment, which fails with - # "Invalid cross-device link" on hosts whose Docker overlay cannot - # rename directories from an image layer. A volume is not overlay. - - /var/lib/flatpak - strategy: - fail-fast: false - matrix: - variant: - - arch: x86_64 - runner: ubuntu-24.04 - - arch: aarch64 - runner: ubuntu-24.04-arm + name: Flatpak # Don't run scheduled builds on forks; skip entirely on self-hosted runners - if: ${{ !cancelled() && !vars.SELF_HOSTED && (github.event_name != 'schedule' || github.repository == 'OrcaSlicer/OrcaSlicer') }} - - runs-on: ${{ matrix.variant.runner }} - env: - date: - ver: - ver_pure: - steps: - - name: "Remove unneeded stuff to free disk space" - run: - rm -rf /usr/local/lib/android/* /usr/share/dotnet/* /opt/ghc1/* "/usr/local/share/boost1/*" /opt/hostedtoolcache1/* - - uses: actions/checkout@v7 - - name: Get the version and date - run: | - ver_pure=$(grep 'set(SoftFever_VERSION' version.inc | cut -d '"' -f2) - if [[ "${{ github.event_name }}" == "pull_request" ]]; then - ver="PR-${{ github.event.number }}" - git_commit_hash="${{ github.event.pull_request.head.sha }}" - else - ver=V$ver_pure - git_commit_hash="${{ github.sha }}" - fi - echo "ver=$ver" >> $GITHUB_ENV - echo "ver_pure=$ver_pure" >> $GITHUB_ENV - echo "date=$(date +'%Y%m%d')" >> $GITHUB_ENV - echo "git_commit_hash=$git_commit_hash" >> $GITHUB_ENV - shell: bash - - name: Compute the flatpak-builder cache key - id: fp_cache_key - run: echo "key=flatpak-builder-${{ matrix.variant.arch }}-${{ hashFiles('deps/**', 'scripts/flatpak/com.orcaslicer.OrcaSlicer.yml', 'scripts/flatpak/make_deps_tar.sh') }}" >> "$GITHUB_OUTPUT" - shell: bash - # Manage flatpak-builder cache externally so PRs restore but never upload. - # The compiler cache under it is keyed per run below, so it is left out. - - name: Restore flatpak-builder cache - if: github.event_name == 'pull_request' - uses: actions/cache/restore@v6 - with: - path: | - .flatpak-builder/* - !.flatpak-builder/ccache - key: ${{ steps.fp_cache_key.outputs.key }} - restore-keys: flatpak-builder-${{ matrix.variant.arch }}- - - name: Save/restore flatpak-builder cache - if: github.event_name != 'pull_request' - uses: actions/cache@v6 - with: - path: | - .flatpak-builder/* - !.flatpak-builder/ccache - key: ${{ steps.fp_cache_key.outputs.key }} - restore-keys: flatpak-builder-${{ matrix.variant.arch }}- - # Compiler cache for the OrcaSlicer module, as in build_orca.yml. Pull - # requests only restore it; every other run (main, release branches, the - # nightly, a dispatch) saves it. orca_deps stays on the state cache above. - - name: Name the compiler cache leg - run: | - leg="Flatpak-${{ matrix.variant.arch }}" - echo "CCACHE_LEG=$leg" >> "$GITHUB_ENV" - echo "CCACHE_ENTRY=ccache-$leg-${{ github.run_id }}-${{ github.run_attempt }}" >> "$GITHUB_ENV" - shell: bash - - name: Restore compiler cache - id: ccache_restore - uses: actions/cache/restore@v6 - with: - path: .flatpak-builder/ccache - key: ${{ env.CCACHE_ENTRY }} - restore-keys: ccache-${{ env.CCACHE_LEG }}- - - name: Disable debug info for faster CI builds - run: | - sed -i '/^build-options:/a\ no-debuginfo: true\n strip: true' \ - scripts/flatpak/com.orcaslicer.OrcaSlicer.yml - shell: bash - # flatpak-builder reuses a module from its cache when the definition and - # sources are unchanged, so a re-run of the same commit would skip the - # OrcaSlicer module and ship no test asset. A per-run value in that module's - # env keeps it rebuilding; orca_deps stays cached, and the compiler cache - # still serves the rebuild. run-tests on the same module builds the test - # binaries. - - name: Inject commit hash, run-tests and cache buster into Flatpak manifest - env: - flatpak_builder_cache_buster: ${{ github.run_id }}-${{ github.run_attempt }} - run: | - sed -i "/name: OrcaSlicer/{n;s|buildsystem: simple|buildsystem: simple\n run-tests: true\n build-options:\n env:\n flatpak_builder_cache_buster: \"$flatpak_builder_cache_buster\"\n git_commit_hash: \"$git_commit_hash\"|}" \ - scripts/flatpak/com.orcaslicer.OrcaSlicer.yml - shell: bash - # flatpak-builder's --ccache only wraps cc and gcc, and the manifest builds - # with clang, so CMake's launcher runs ccache instead; --ccache is still what - # mounts the cache directory into the sandbox. The settings go into that - # directory's own config file, which the sandbox reads too. - - name: Enable compiler cache - run: | - printf ' %s\n' \ - 'CMAKE_C_COMPILER_LAUNCHER: ccache' \ - 'CMAKE_CXX_COMPILER_LAUNCHER: ccache' > "$RUNNER_TEMP/ccache-env.yml" - sed -i "/^ git_commit_hash: /r $RUNNER_TEMP/ccache-env.yml" \ - scripts/flatpak/com.orcaslicer.OrcaSlicer.yml - grep -q '^ CMAKE_CXX_COMPILER_LAUNCHER: ccache$' scripts/flatpak/com.orcaslicer.OrcaSlicer.yml - mkdir -p .flatpak-builder/ccache - export CCACHE_DIR=$PWD/.flatpak-builder/ccache - ccache --set-config=max_size=3G - # The compiler is reinstalled every run, so its mtime means nothing. - ccache --set-config=compiler_check=content - # Headers a fresh checkout has just written, the few files that use - # __DATE__ or __TIME__, and the precompiled header, whose macros ccache - # cannot see. - ccache --set-config=sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime - # Hash the includes the compiler reports instead of preprocessing every - # miss before compiling it. - ccache --set-config=depend_mode=true - # The restored directory carries the previous run's counters. - ccache -z - shell: bash - - name: Check the manifest keeps orca_deps cacheable - run: ./scripts/flatpak/check_manifest_cacheable.sh - shell: bash - - name: Pack deps/ for the Flatpak manifest - run: ./scripts/flatpak/make_deps_tar.sh - shell: bash - - uses: flatpak/flatpak-github-actions/flatpak-builder@master - with: - bundle: OrcaSlicer-Linux-flatpak_${{ env.ver }}_${{ matrix.variant.arch }}.flatpak - manifest-path: scripts/flatpak/com.orcaslicer.OrcaSlicer.yml - # cache only turns on flatpak-builder --ccache; the caching itself is above. - cache: true - restore-cache: false - save-cache: false - arch: ${{ matrix.variant.arch }} - upload-artifact: false - keep-build-dirs: true - # The build has just touched everything it can use, so an object untouched - # for a week is dead, usually orphaned by a flag change. - - name: Compiler cache statistics - if: always() - run: | - export CCACHE_DIR=$PWD/.flatpak-builder/ccache - ccache --evict-older-than 7d - ccache -s -v || ccache -s - shell: bash - # Save the new entry first, then drop the older ones for this leg on this - # ref, so a failed save leaves the previous entry in place. A cancelled or - # failed build saves too, since what it compiled is still valid; a restore - # that did not finish does not, since the directory may be a truncated copy. - - name: Save compiler cache - id: ccache_save - if: ${{ always() && steps.ccache_restore.outcome == 'success' && github.event_name != 'pull_request' }} - uses: actions/cache/save@v6 - with: - path: .flatpak-builder/ccache - key: ${{ env.CCACHE_ENTRY }} - - name: Drop older compiler cache entries - if: ${{ always() && steps.ccache_save.outcome == 'success' }} - # The container has no gh, so this is the list and delete over the REST API. - # Older means a lower run id, so two runs finishing close together keep - # the newer entry whichever of them cleans up last. - continue-on-error: true - env: - GH_TOKEN: ${{ github.token }} - run: | - api="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/caches" - # The save step reports success even when its tar failed, so keep - # the older entries unless the new one is listed. - if ! curl -sSf -H "Authorization: Bearer $GH_TOKEN" \ - "$api?ref=$GITHUB_REF&key=$CCACHE_ENTRY" \ - | jq -e --arg entry "$CCACHE_ENTRY" 'any(.actions_caches[]; .key == $entry)' > /dev/null; then - echo "$CCACHE_ENTRY was not saved; keeping the older entries." - exit 0 - fi - curl -sSf -H "Authorization: Bearer $GH_TOKEN" \ - "$api?ref=$GITHUB_REF&key=ccache-$CCACHE_LEG-&per_page=100" \ - | jq -r --arg prefix "ccache-$CCACHE_LEG-" --argjson run "$GITHUB_RUN_ID" \ - '.actions_caches[] | select((.key | ltrimstr($prefix) | split("-")[0] | tonumber?) < $run) | .id' \ - | while read -r id; do - curl -sSf -X DELETE -H "Authorization: Bearer $GH_TOKEN" "$api/$id" - done - shell: bash - - name: Upload artifacts Flatpak - uses: actions/upload-artifact@v7 - with: - name: OrcaSlicer-Linux-flatpak_${{ env.ver }}_${{ matrix.variant.arch }}.flatpak - path: '/__w/OrcaSlicer/OrcaSlicer/OrcaSlicer-Linux-flatpak_${{ env.ver }}_${{ matrix.variant.arch }}.flatpak' - - name: Deploy Flatpak to nightly release - if: github.repository == 'OrcaSlicer/OrcaSlicer' && github.ref == 'refs/heads/main' - uses: ./.github/actions/deploy-nightly - with: - asset_path: /__w/OrcaSlicer/OrcaSlicer/OrcaSlicer-Linux-flatpak_${{ env.ver }}_${{ matrix.variant.arch }}.flatpak - asset_name: OrcaSlicer-Linux-flatpak_nightly_${{ matrix.variant.arch }}.flatpak - # The asset is /app (the exes link it at runtime) plus the build tree - # slimmed to what ctest needs. - - name: Package flatpak test asset - shell: bash - run: | - d=$(ls -d .flatpak-builder/build/OrcaSlicer-* | tail -1) - find "$d/build_flatpak" -mindepth 1 -maxdepth 1 ! -name tests -exec rm -rf {} + - # Strip debug info (the SDK builds with -g, only the app gets stripped); - # the bounds checks are compiled in, so a stripped exe still catches them. - find "$d/build_flatpak/tests" -type f -perm -u+x -exec strip --strip-unneeded {} + 2>/dev/null || true - # At runtime the tests read tests/ (TEST_DATA_DIR), scripts/, and under - # resources/ the shipped profiles (PROFILES_DIR), the printers/ maps, and - # the icon SVGs (NativeCommands icon names are checked against them). - find "$d" -mindepth 1 -maxdepth 1 -type d \ - ! -name tests ! -name build_flatpak ! -name scripts ! -name resources -exec rm -rf {} + - find "$d/resources" -mindepth 1 -maxdepth 1 ! -name profiles ! -name printers ! -name images -exec rm -rf {} + - # Only the SVGs are read; the png/ico/icns/gif assets are ~35MB of dead weight. - find "$d/resources/images" -mindepth 1 -maxdepth 1 ! -name '*.svg' -exec rm -rf {} + 2>/dev/null || true - tar -cf flatpak-test-asset.tar flatpak_app "$d" - - name: Upload flatpak test asset - uses: actions/upload-artifact@v7 - with: - name: ${{ github.sha }}-flatpak-tests-${{ matrix.variant.arch }} - path: flatpak-test-asset.tar - retention-days: 1 - # keep-build-dirs would otherwise land in the flatpak-builder cache saved post-job. - - name: Drop the kept build dirs before the flatpak-builder cache saves - if: always() - shell: bash - run: rm -rf .flatpak-builder/build - unit_tests_flatpak_x86_64: - name: Flatpak x86_64 - needs: flatpak - if: ${{ !cancelled() && success() }} - uses: ./.github/workflows/unit_tests_flatpak.yml - with: - os: ubuntu-24.04 - artifact: ${{ github.sha }}-flatpak-tests-x86_64 - unit_tests_flatpak_aarch64: - name: Flatpak aarch64 - needs: flatpak - if: ${{ !cancelled() && success() }} - uses: ./.github/workflows/unit_tests_flatpak.yml - with: - os: ubuntu-24.04-arm - artifact: ${{ github.sha }}-flatpak-tests-aarch64 + if: ${{ !cancelled() && !vars.SELF_HOSTED && github.event_name != 'pull_request' && (github.event_name != 'schedule' || github.repository == 'OrcaSlicer/OrcaSlicer') }} + uses: ./.github/workflows/build_flatpak.yml + secrets: inherit diff --git a/.github/workflows/build_check_cache.yml b/.github/workflows/build_check_cache.yml index 0da6c2b7b4..b7fdbcdc3d 100644 --- a/.github/workflows/build_check_cache.yml +++ b/.github/workflows/build_check_cache.yml @@ -20,10 +20,13 @@ on: required: false type: boolean -# Read by scripts/ci_deps_cache.sh. +# Read by scripts/ci_deps_cache.sh and scripts/ci_macos_admission.py. env: REPO: ${{ github.repository }} - WORKFLOW_REF: ${{ github.workflow_ref }} + # The workflow whose push and nightly builds save the deps caches. + WORKFLOW: build_all.yml + # Every workflow with macOS builds, the first of them the one above. + MACOS_WORKFLOWS: build_all.yml build_optional.yml BASE_REF: ${{ github.base_ref }} jobs: diff --git a/.github/workflows/build_flatpak.yml b/.github/workflows/build_flatpak.yml new file mode 100644 index 0000000000..88f39a8be6 --- /dev/null +++ b/.github/workflows/build_flatpak.yml @@ -0,0 +1,261 @@ +# The Flatpak build and its unit tests, for build_all.yml and for a pull request +# that asks for it (build_optional.yml). +name: Build Flatpak + +on: + workflow_call: + +jobs: + flatpak: + name: Build Flatpak + container: + image: ghcr.io/flathub-infra/flatpak-github-actions:gnome-50 + options: --privileged + volumes: + - /usr/local/lib/android:/usr/local/lib/android + - /usr/share/dotnet:/usr/share/dotnet + - /opt/ghc:/opt/ghc1 + - /usr/local/share/boost:/usr/local/share/boost1 + - /opt/hostedtoolcache:/opt/hostedtoolcache1 + # Updating a runtime renames its old deployment, which fails with + # "Invalid cross-device link" on hosts whose Docker overlay cannot + # rename directories from an image layer. A volume is not overlay. + - /var/lib/flatpak + strategy: + fail-fast: false + matrix: + variant: + - arch: x86_64 + runner: ubuntu-24.04 + - arch: aarch64 + runner: ubuntu-24.04-arm + runs-on: ${{ matrix.variant.runner }} + env: + date: + ver: + ver_pure: + steps: + - name: "Remove unneeded stuff to free disk space" + run: + rm -rf /usr/local/lib/android/* /usr/share/dotnet/* /opt/ghc1/* "/usr/local/share/boost1/*" /opt/hostedtoolcache1/* + - uses: actions/checkout@v7 + - name: Get the version and date + run: | + ver_pure=$(grep 'set(SoftFever_VERSION' version.inc | cut -d '"' -f2) + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + ver="PR-${{ github.event.number }}" + git_commit_hash="${{ github.event.pull_request.head.sha }}" + else + ver=V$ver_pure + git_commit_hash="${{ github.sha }}" + fi + echo "ver=$ver" >> $GITHUB_ENV + echo "ver_pure=$ver_pure" >> $GITHUB_ENV + echo "date=$(date +'%Y%m%d')" >> $GITHUB_ENV + echo "git_commit_hash=$git_commit_hash" >> $GITHUB_ENV + shell: bash + - name: Compute the flatpak-builder cache key + id: fp_cache_key + run: echo "key=flatpak-builder-${{ matrix.variant.arch }}-${{ hashFiles('deps/**', 'scripts/flatpak/com.orcaslicer.OrcaSlicer.yml', 'scripts/flatpak/make_deps_tar.sh') }}" >> "$GITHUB_OUTPUT" + shell: bash + # Manage flatpak-builder cache externally so PRs restore but never upload. + # The compiler cache under it is keyed per run below, so it is left out. + - name: Restore flatpak-builder cache + if: github.event_name == 'pull_request' + uses: actions/cache/restore@v6 + with: + path: | + .flatpak-builder/* + !.flatpak-builder/ccache + key: ${{ steps.fp_cache_key.outputs.key }} + restore-keys: flatpak-builder-${{ matrix.variant.arch }}- + - name: Save/restore flatpak-builder cache + if: github.event_name != 'pull_request' + uses: actions/cache@v6 + with: + path: | + .flatpak-builder/* + !.flatpak-builder/ccache + key: ${{ steps.fp_cache_key.outputs.key }} + restore-keys: flatpak-builder-${{ matrix.variant.arch }}- + # Compiler cache for the OrcaSlicer module, as in build_orca.yml. Pull + # requests only restore it; every other run (main, release branches, the + # nightly, a dispatch) saves it. orca_deps stays on the state cache above. + - name: Name the compiler cache leg + run: | + leg="Flatpak-${{ matrix.variant.arch }}" + echo "CCACHE_LEG=$leg" >> "$GITHUB_ENV" + echo "CCACHE_ENTRY=ccache-$leg-${{ github.run_id }}-${{ github.run_attempt }}" >> "$GITHUB_ENV" + shell: bash + - name: Restore compiler cache + id: ccache_restore + uses: actions/cache/restore@v6 + with: + path: .flatpak-builder/ccache + key: ${{ env.CCACHE_ENTRY }} + restore-keys: ccache-${{ env.CCACHE_LEG }}- + - name: Disable debug info for faster CI builds + run: | + sed -i '/^build-options:/a\ no-debuginfo: true\n strip: true' \ + scripts/flatpak/com.orcaslicer.OrcaSlicer.yml + shell: bash + # flatpak-builder reuses a module from its cache when the definition and + # sources are unchanged, so a re-run of the same commit would skip the + # OrcaSlicer module and ship no test asset. A per-run value in that module's + # env keeps it rebuilding; orca_deps stays cached, and the compiler cache + # still serves the rebuild. run-tests on the same module builds the test + # binaries. + - name: Inject commit hash, run-tests and cache buster into Flatpak manifest + env: + flatpak_builder_cache_buster: ${{ github.run_id }}-${{ github.run_attempt }} + run: | + sed -i "/name: OrcaSlicer/{n;s|buildsystem: simple|buildsystem: simple\n run-tests: true\n build-options:\n env:\n flatpak_builder_cache_buster: \"$flatpak_builder_cache_buster\"\n git_commit_hash: \"$git_commit_hash\"|}" \ + scripts/flatpak/com.orcaslicer.OrcaSlicer.yml + shell: bash + # flatpak-builder's --ccache only wraps cc and gcc, and the manifest builds + # with clang, so CMake's launcher runs ccache instead; --ccache is still what + # mounts the cache directory into the sandbox. The settings go into that + # directory's own config file, which the sandbox reads too. + - name: Enable compiler cache + run: | + printf ' %s\n' \ + 'CMAKE_C_COMPILER_LAUNCHER: ccache' \ + 'CMAKE_CXX_COMPILER_LAUNCHER: ccache' > "$RUNNER_TEMP/ccache-env.yml" + sed -i "/^ git_commit_hash: /r $RUNNER_TEMP/ccache-env.yml" \ + scripts/flatpak/com.orcaslicer.OrcaSlicer.yml + grep -q '^ CMAKE_CXX_COMPILER_LAUNCHER: ccache$' scripts/flatpak/com.orcaslicer.OrcaSlicer.yml + mkdir -p .flatpak-builder/ccache + export CCACHE_DIR=$PWD/.flatpak-builder/ccache + ccache --set-config=max_size=3G + # The compiler is reinstalled every run, so its mtime means nothing. + ccache --set-config=compiler_check=content + # Headers a fresh checkout has just written, the few files that use + # __DATE__ or __TIME__, and the precompiled header, whose macros ccache + # cannot see. + ccache --set-config=sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime + # Hash the includes the compiler reports instead of preprocessing every + # miss before compiling it. + ccache --set-config=depend_mode=true + # The restored directory carries the previous run's counters. + ccache -z + shell: bash + - name: Check the manifest keeps orca_deps cacheable + run: ./scripts/flatpak/check_manifest_cacheable.sh + shell: bash + - name: Pack deps/ for the Flatpak manifest + run: ./scripts/flatpak/make_deps_tar.sh + shell: bash + - uses: flatpak/flatpak-github-actions/flatpak-builder@master + with: + bundle: OrcaSlicer-Linux-flatpak_${{ env.ver }}_${{ matrix.variant.arch }}.flatpak + manifest-path: scripts/flatpak/com.orcaslicer.OrcaSlicer.yml + # cache only turns on flatpak-builder --ccache; the caching itself is above. + cache: true + restore-cache: false + save-cache: false + arch: ${{ matrix.variant.arch }} + upload-artifact: false + keep-build-dirs: true + # The build has just touched everything it can use, so an object untouched + # for a week is dead, usually orphaned by a flag change. + - name: Compiler cache statistics + if: always() + run: | + export CCACHE_DIR=$PWD/.flatpak-builder/ccache + ccache --evict-older-than 7d + ccache -s -v || ccache -s + shell: bash + # Save the new entry first, then drop the older ones for this leg on this + # ref, so a failed save leaves the previous entry in place. A cancelled or + # failed build saves too, since what it compiled is still valid; a restore + # that did not finish does not, since the directory may be a truncated copy. + - name: Save compiler cache + id: ccache_save + if: ${{ always() && steps.ccache_restore.outcome == 'success' && github.event_name != 'pull_request' }} + uses: actions/cache/save@v6 + with: + path: .flatpak-builder/ccache + key: ${{ env.CCACHE_ENTRY }} + - name: Drop older compiler cache entries + if: ${{ always() && steps.ccache_save.outcome == 'success' }} + # The container has no gh, so this is the list and delete over the REST API. + # Older means a lower run id, so two runs finishing close together keep + # the newer entry whichever of them cleans up last. + continue-on-error: true + env: + GH_TOKEN: ${{ github.token }} + run: | + api="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/caches" + # The save step reports success even when its tar failed, so keep + # the older entries unless the new one is listed. + if ! curl -sSf -H "Authorization: Bearer $GH_TOKEN" \ + "$api?ref=$GITHUB_REF&key=$CCACHE_ENTRY" \ + | jq -e --arg entry "$CCACHE_ENTRY" 'any(.actions_caches[]; .key == $entry)' > /dev/null; then + echo "$CCACHE_ENTRY was not saved; keeping the older entries." + exit 0 + fi + curl -sSf -H "Authorization: Bearer $GH_TOKEN" \ + "$api?ref=$GITHUB_REF&key=ccache-$CCACHE_LEG-&per_page=100" \ + | jq -r --arg prefix "ccache-$CCACHE_LEG-" --argjson run "$GITHUB_RUN_ID" \ + '.actions_caches[] | select((.key | ltrimstr($prefix) | split("-")[0] | tonumber?) < $run) | .id' \ + | while read -r id; do + curl -sSf -X DELETE -H "Authorization: Bearer $GH_TOKEN" "$api/$id" + done + shell: bash + - name: Upload artifacts Flatpak + uses: actions/upload-artifact@v7 + with: + name: OrcaSlicer-Linux-flatpak_${{ env.ver }}_${{ matrix.variant.arch }}.flatpak + path: '/__w/OrcaSlicer/OrcaSlicer/OrcaSlicer-Linux-flatpak_${{ env.ver }}_${{ matrix.variant.arch }}.flatpak' + - name: Deploy Flatpak to nightly release + if: github.repository == 'OrcaSlicer/OrcaSlicer' && github.ref == 'refs/heads/main' + uses: ./.github/actions/deploy-nightly + with: + asset_path: /__w/OrcaSlicer/OrcaSlicer/OrcaSlicer-Linux-flatpak_${{ env.ver }}_${{ matrix.variant.arch }}.flatpak + asset_name: OrcaSlicer-Linux-flatpak_nightly_${{ matrix.variant.arch }}.flatpak + # The asset is /app (the exes link it at runtime) plus the build tree + # slimmed to what ctest needs. + - name: Package flatpak test asset + shell: bash + run: | + d=$(ls -d .flatpak-builder/build/OrcaSlicer-* | tail -1) + find "$d/build_flatpak" -mindepth 1 -maxdepth 1 ! -name tests -exec rm -rf {} + + # Strip debug info (the SDK builds with -g, only the app gets stripped); + # the bounds checks are compiled in, so a stripped exe still catches them. + find "$d/build_flatpak/tests" -type f -perm -u+x -exec strip --strip-unneeded {} + 2>/dev/null || true + # At runtime the tests read tests/ (TEST_DATA_DIR), scripts/, and under + # resources/ the shipped profiles (PROFILES_DIR), the printers/ maps, and + # the icon SVGs (NativeCommands icon names are checked against them). + find "$d" -mindepth 1 -maxdepth 1 -type d \ + ! -name tests ! -name build_flatpak ! -name scripts ! -name resources -exec rm -rf {} + + find "$d/resources" -mindepth 1 -maxdepth 1 ! -name profiles ! -name printers ! -name images -exec rm -rf {} + + # Only the SVGs are read; the png/ico/icns/gif assets are ~35MB of dead weight. + find "$d/resources/images" -mindepth 1 -maxdepth 1 ! -name '*.svg' -exec rm -rf {} + 2>/dev/null || true + tar -cf flatpak-test-asset.tar flatpak_app "$d" + - name: Upload flatpak test asset + uses: actions/upload-artifact@v7 + with: + name: ${{ github.sha }}-flatpak-tests-${{ matrix.variant.arch }} + path: flatpak-test-asset.tar + retention-days: 1 + # keep-build-dirs would otherwise land in the flatpak-builder cache saved post-job. + - name: Drop the kept build dirs before the flatpak-builder cache saves + if: always() + shell: bash + run: rm -rf .flatpak-builder/build + unit_tests_flatpak_x86_64: + name: Flatpak x86_64 + needs: flatpak + if: ${{ !cancelled() && success() }} + uses: ./.github/workflows/unit_tests_flatpak.yml + with: + os: ubuntu-24.04 + artifact: ${{ github.sha }}-flatpak-tests-x86_64 + unit_tests_flatpak_aarch64: + name: Flatpak aarch64 + needs: flatpak + if: ${{ !cancelled() && success() }} + uses: ./.github/workflows/unit_tests_flatpak.yml + with: + os: ubuntu-24.04-arm + artifact: ${{ github.sha }}-flatpak-tests-aarch64 diff --git a/.github/workflows/build_optional.yml b/.github/workflows/build_optional.yml new file mode 100644 index 0000000000..fa2f356999 --- /dev/null +++ b/.github/workflows/build_optional.yml @@ -0,0 +1,212 @@ +# The builds a pull request gets only when asked for. build_all.yml leaves them +# out of pull requests and builds them on every push to main: the Flatpak is +# the slowest Linux leg, a macOS x86_64 build holds one of the few hosted macOS +# runners for an hour, and Windows arm64 doubles the Windows legs. +# +# A label asks for one, from the moment it is added and on every later push to +# the pull request: build-flatpak, build-macos-x86_64, build-windows-arm64, +# build-windows-msvc. build-all asks for the first three, the builds every pull +# request once got; the MSVC build is another compiler's, never a build a pull +# request got, and the first one builds the deps too, so it stays label-only. +# Removing and adding a label again rebuilds the same commit. +# +# A pull request that changes anything but sources, tests, profiles, +# translations and docs builds the Flatpak and Windows arm64 without a label: +# what breaks only those legs lives in deps/, cmake/, the build scripts and the +# workflows, and a list of those places would go stale, so the safe places are +# listed instead. The macOS and the cl.exe builds never start on their own: +# what breaks only cl comes from source changes, which no path rule can see. +# +# Each label added starts a run of its own, and the pull request's checks show +# the newest run only, so every run builds everything the labels and the +# changed files ask for. Each build keeps its own concurrency group: the newest +# run's build cancels the one an earlier run of the commit started, and a push +# cancels the builds of the commit it replaces. cancel_closed_pr_builds.yml +# joins the groups by name, so update that file with any change here. +name: Optional builds + +on: + pull_request: + branches: + - main + - release/* + # Build all's pull_request paths, plus the Flatpak packaging: a pull request + # that Build all skips has nothing for these builds to check either, and + # the filter applies to labeled too. Keep the two lists in step. + paths: + - 'deps/**' + - 'deps_src/**' + - 'cmake/**' + - 'src/**' + - '**/CMakeLists.txt' + - 'version.inc' + - ".github/workflows/build_*.yml" + - ".github/workflows/unit_tests*.yml" + - 'build_linux.sh' + - 'build_win.bat' + - 'scripts/test_build_win.ps1' + - 'scripts/check_exception_throw_info.ps1' + - 'scripts/test_check_exception_throw_info.ps1' + - 'build_release_macos.sh' + - 'scripts/build_preset_cache.*' + - 'scripts/prune_cached_presets.ps1' + - 'scripts/test_prune_cached_presets.ps1' + - 'scripts/flatpak/**' + - 'scripts/msix/**' + - 'tests/**' + # labeled, so adding a label starts the build it asks for. + types: [opened, reopened, synchronize, labeled] + +jobs: + select: + name: Select builds + runs-on: ubuntu-24.04 + outputs: + flatpak: ${{ steps.select.outputs.flatpak }} + macos-x86_64: ${{ steps.select.outputs.macos-x86_64 }} + windows-arm64: ${{ steps.select.outputs.windows-arm64 }} + windows-msvc: ${{ steps.select.outputs.windows-msvc }} + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + lfs: 'false' + # The merge commit plus its first parent, the base it is diffed against. + fetch-depth: 2 + sparse-checkout: .github/workflows + - name: Select the builds the labels and the changed files ask for + id: select + env: + LABELS: ${{ join(github.event.pull_request.labels.*.name, ' ') }} + run: | + has_label() { [[ " $LABELS " == *" $1 "* ]]; } + infra=false + changed=$(git diff --name-only HEAD^1 HEAD \ + | grep -vE '^(src|tests|resources|localization|docs)/' | grep -vE '\.md$' || true) + if [ -n "$changed" ]; then + echo "This pull request changes files outside the sources, tests, profiles, translations and docs:" + echo "$changed" | head -20 + infra=true + fi + # pick