diff --git a/.github/workflows/build_all.yml b/.github/workflows/build_all.yml index 41fe9d2302..41f2573a24 100644 --- a/.github/workflows/build_all.yml +++ b/.github/workflows/build_all.yml @@ -194,7 +194,7 @@ jobs: restore-keys: flatpak-builder-${{ matrix.variant.arch }}- - name: Disable debug info for faster CI builds run: | - sed -i '/^build-options:/a\ no-debuginfo: true\n strip: true' \ + sed -i '/^build-options:/a\ no-debuginfo: true\n strip: true\n cflags: "-g0"\n cxxflags: "-g0"' \ scripts/flatpak/io.github.orcaslicer.OrcaSlicer.yml shell: bash - name: Inject git commit hash into Flatpak manifest @@ -202,6 +202,14 @@ jobs: sed -i "/name: OrcaSlicer/{n;s|buildsystem: simple|buildsystem: simple\n build-options:\n env:\n git_commit_hash: \"$git_commit_hash\"|}" \ scripts/flatpak/io.github.orcaslicer.OrcaSlicer.yml shell: bash + - name: Restore manifest mtime for deterministic cache keys + run: | + # sed changes mtime, which flatpak-builder uses for SOURCE_DATE_EPOCH + # and type:dir module cache keys. Restore to git commit time so cache + # keys are stable across builds of the same source. + touch -d @$(git log -1 --format='%ct' -- scripts/flatpak/io.github.orcaslicer.OrcaSlicer.yml) \ + scripts/flatpak/io.github.orcaslicer.OrcaSlicer.yml + shell: bash - uses: flatpak/flatpak-github-actions/flatpak-builder@master with: bundle: OrcaSlicer-Linux-flatpak_${{ env.ver }}_${{ matrix.variant.arch }}.flatpak diff --git a/build_flatpak.sh b/build_flatpak.sh index 225cf25e66..af78376a49 100755 --- a/build_flatpak.sh +++ b/build_flatpak.sh @@ -20,8 +20,8 @@ CLEANUP=false INSTALL_RUNTIME=false JOBS=$(nproc) FORCE_CLEAN=false -ENABLE_CCACHE=false -DISABLE_ROFILES_FUSE=false +ENABLE_CCACHE=true +DISABLE_ROFILES_FUSE=true NO_DEBUGINFO=true CACHE_DIR=".flatpak-builder" @@ -37,19 +37,19 @@ show_help() { echo " -j, --jobs JOBS Number of parallel build jobs for flatpak-builder and modules [default: $JOBS]" echo " -c, --cleanup Clean build directory before building" echo " -f, --force-clean Force clean build (disables caching)" - echo " --ccache Enable ccache for faster rebuilds (requires ccache in SDK)" - echo " --disable-rofiles-fuse Disable rofiles-fuse (workaround for FUSE issues)" + echo " --no-ccache Disable ccache (enabled by default)" + echo " --enable-rofiles-fuse Enable rofiles-fuse (disabled by default as workaround for FUSE issues)" echo " --with-debuginfo Include debug info (slower builds, needed for Flathub)" echo " --cache-dir DIR Flatpak builder cache directory [default: $CACHE_DIR]" echo " -i, --install-runtime Install required Flatpak runtime and SDK" echo " -h, --help Show this help message" echo "" echo "Examples:" - echo " $0 # Build for current architecture with caching enabled" + echo " $0 # Build with defaults (ccache enabled, rofiles-fuse disabled)" echo " $0 -f # Force clean build (no caching)" - echo " $0 --ccache -j 8 # Use ccache and 8 parallel jobs for faster builds" + echo " $0 --no-ccache -j 8 # Disable ccache and use 8 parallel jobs" echo " $0 -a x86_64 -c # Build for x86_64 and cleanup first" - echo " $0 -i -j 16 --ccache # Install runtime, build with 16 jobs and ccache" + echo " $0 -i -j 16 # Install runtime and build with 16 jobs" } # Parse command line arguments @@ -75,12 +75,12 @@ while [[ $# -gt 0 ]]; do FORCE_CLEAN=true shift ;; - --ccache) - ENABLE_CCACHE=true + --no-ccache) + ENABLE_CCACHE=false shift ;; - --disable-rofiles-fuse) - DISABLE_ROFILES_FUSE=true + --enable-rofiles-fuse) + DISABLE_ROFILES_FUSE=false shift ;; --with-debuginfo) @@ -249,9 +249,13 @@ if [[ "$CLEANUP" == true ]]; then echo -e "${BLUE}Note: Host build directories (deps/build, build) are preserved${NC}" fi -# Create build directory +# Create build directory and set up log file mkdir -p "$BUILD_DIR" rm -rf "$BUILD_DIR/build-dir" +LOG_FILE="$BUILD_DIR/build_flatpak_$(date +'%Y%m%d_%H%M%S').log" +exec > >(tee -a "$LOG_FILE") 2>&1 +echo -e "${BLUE}Logging to: ${GREEN}$LOG_FILE${NC}" +echo "" # Check if flatpak manifest exists if [[ ! -f "./scripts/flatpak/io.github.orcaslicer.OrcaSlicer.yml" ]]; then @@ -303,6 +307,13 @@ else fi # Add ccache if enabled +# NOTE: flatpak-builder's --ccache only creates symlinks for gcc/g++, not +# clang/clang++. The actual ccache integration is done via +# CMAKE_C_COMPILER_LAUNCHER=ccache in the manifest's build-commands. +# --ccache is still needed because it: +# 1. Bind-mounts the ccache directory into the sandbox at /run/ccache +# 2. Sets CCACHE_DIR=/run/ccache for persistent caching +# 3. Makes /usr/bin/ccache available in the build environment if [[ "$ENABLE_CCACHE" == true ]]; then BUILDER_ARGS+=(--ccache) echo -e "${GREEN}Using ccache for compiler caching${NC}" @@ -318,9 +329,12 @@ fi MANIFEST="scripts/flatpak/io.github.orcaslicer.OrcaSlicer.yml" if [[ "$NO_DEBUGINFO" == true ]]; then MANIFEST="scripts/flatpak/io.github.orcaslicer.OrcaSlicer.no-debug.yml" - sed '/^build-options:/a\ no-debuginfo: true\n strip: true' \ + sed '/^build-options:/a\ no-debuginfo: true\n strip: true\n cflags: "-g0"\n cxxflags: "-g0"' \ scripts/flatpak/io.github.orcaslicer.OrcaSlicer.yml > "$MANIFEST" - echo -e "${YELLOW}Debug info disabled (using temp manifest)${NC}" + # Preserve original manifest's mtime so flatpak-builder computes a + # deterministic SOURCE_DATE_EPOCH and module cache keys stay stable. + touch -r scripts/flatpak/io.github.orcaslicer.OrcaSlicer.yml "$MANIFEST" + echo -e "${YELLOW}Debug info disabled (using temp manifest with -g0)${NC}" fi if ! flatpak-builder \ @@ -328,7 +342,7 @@ if ! flatpak-builder \ "$BUILD_DIR/build-dir" \ "$MANIFEST"; then echo -e "${RED}Error: flatpak-builder failed${NC}" - echo -e "${YELLOW}Check the build log above for details${NC}" + echo -e "${YELLOW}Check the build log for details: $LOG_FILE${NC}" rm -f "scripts/flatpak/io.github.orcaslicer.OrcaSlicer.no-debug.yml" exit 1 fi @@ -336,6 +350,15 @@ fi # Clean up temp manifest rm -f "scripts/flatpak/io.github.orcaslicer.OrcaSlicer.no-debug.yml" +# Show ccache statistics if ccache was enabled +if [[ "$ENABLE_CCACHE" == true ]]; then + echo -e "${BLUE}=== ccache statistics ===${NC}" + CCACHE_DIR="$CACHE_DIR/ccache" ccache -sv 2>/dev/null || \ + CCACHE_DIR="$CACHE_DIR/ccache" ccache -s 2>/dev/null || \ + echo -e "${YELLOW}Could not retrieve ccache stats${NC}" + echo "" +fi + # Create bundle echo -e "${YELLOW}Creating Flatpak bundle...${NC}" if ! flatpak build-bundle \ @@ -352,6 +375,7 @@ echo "" echo -e "${GREEN}✓ Flatpak build completed successfully!${NC}" echo -e "Bundle created: ${GREEN}$BUNDLE_NAME${NC}" echo -e "Size: ${GREEN}$(du -h "$BUNDLE_NAME" | cut -f1)${NC}" +echo -e "Build log: ${GREEN}$LOG_FILE${NC}" if [[ "$FORCE_CLEAN" != true ]]; then echo -e "Build cache: ${GREEN}$CACHE_DIR${NC} (preserved for faster future builds)" fi diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 1826c029d0..c8933b5304 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -188,6 +188,8 @@ if (NOT IS_CROSS_COMPILE OR NOT APPLE) -DCMAKE_DEBUG_POSTFIX:STRING=d -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER_LAUNCHER:STRING=${CMAKE_C_COMPILER_LAUNCHER} + -DCMAKE_CXX_COMPILER_LAUNCHER:STRING=${CMAKE_CXX_COMPILER_LAUNCHER} -DCMAKE_TOOLCHAIN_FILE:STRING=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS} -DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS} @@ -232,6 +234,8 @@ else() -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_INSTALL_PREFIX:STRING=${DESTDIR} -DCMAKE_PREFIX_PATH:STRING=${DESTDIR} + -DCMAKE_C_COMPILER_LAUNCHER:STRING=${CMAKE_C_COMPILER_LAUNCHER} + -DCMAKE_CXX_COMPILER_LAUNCHER:STRING=${CMAKE_CXX_COMPILER_LAUNCHER} -DBUILD_SHARED_LIBS:BOOL=OFF ${_cmake_osx_arch} "${_configs_line}" diff --git a/scripts/flatpak/io.github.orcaslicer.OrcaSlicer.yml b/scripts/flatpak/io.github.orcaslicer.OrcaSlicer.yml index b161f99477..6f90839059 100644 --- a/scripts/flatpak/io.github.orcaslicer.OrcaSlicer.yml +++ b/scripts/flatpak/io.github.orcaslicer.OrcaSlicer.yml @@ -14,6 +14,9 @@ build-options: CC: clang CXX: clang++ LDFLAGS: "-fuse-ld=lld" + CCACHE_SLOPPINESS: "pch_defines,time_macros,include_file_mtime,include_file_ctime" + CCACHE_BASEDIR: "/run/build" + CCACHE_NOHASHDIR: "1" finish-args: - --share=ipc - --socket=x11 @@ -130,16 +133,26 @@ modules: BUILD_DIR: deps/build_flatpak build-commands: - | + CCACHE_LAUNCHER="" + if command -v ccache >/dev/null 2>&1; then + CCACHE_LAUNCHER="-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache" + fi cmake -S deps -B $BUILD_DIR \ -DFLATPAK=ON \ -DDEP_DOWNLOAD_DIR=/run/build/orca_deps/external-packages \ -DCMAKE_PREFIX_PATH=/app \ -DDESTDIR=/app \ -DCMAKE_INSTALL_PREFIX=/app \ + $CCACHE_LAUNCHER \ -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \ -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld" \ -DCMAKE_MODULE_LINKER_FLAGS="-fuse-ld=lld" - cmake --build $BUILD_DIR --parallel + - | + if command -v ccache >/dev/null 2>&1; then + echo "=== ccache statistics (after orca_deps) ===" + ccache -sv || ccache -s || true + fi - rm -rf /run/build/orca_deps/external-packages cleanup: @@ -306,17 +319,28 @@ modules: buildsystem: simple build-commands: - | + CCACHE_LAUNCHER="" + if command -v ccache >/dev/null 2>&1; then + CCACHE_LAUNCHER="-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache" + fi cmake . -B build_flatpak \ -DFLATPAK=ON \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_PREFIX_PATH=/app \ -DCMAKE_INSTALL_PREFIX=/app \ + $CCACHE_LAUNCHER \ + -DSLIC3R_PCH=OFF \ -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \ -DCMAKE_SHARED_LINKER_FLAGS="-fuse-ld=lld" \ -DCMAKE_MODULE_LINKER_FLAGS="-fuse-ld=lld" - cmake --build build_flatpak --target OrcaSlicer -j$FLATPAK_BUILDER_N_JOBS - ./scripts/run_gettext.sh - cmake --build build_flatpak --target install -j$FLATPAK_BUILDER_N_JOBS + - | + if command -v ccache >/dev/null 2>&1; then + echo "=== ccache statistics (after OrcaSlicer) ===" + ccache -sv || ccache -s || true + fi cleanup: - /include