From 6f9431a389fc14f113f6a436b363ed3454d828c2 Mon Sep 17 00:00:00 2001 From: cnc Date: Mon, 1 Jun 2026 06:42:35 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC6=E7=BB=84=EF=BC=9A=E5=90=AF=E7=94=A8c?= =?UTF-8?q?cache=E5=8A=A0=E9=80=9F=E9=87=8D=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=B9=B6=E4=BF=9D=E6=8C=81=E9=97=AD=E7=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-wasm.sh | 10 +++++++++- docs/linuxcnc-source-policy.md | 3 +++ test-all-native.sh | 9 +++++++++ test-linuxcnc-source-link.sh | 3 +++ test-linuxcnc-source-syntax.sh | 3 +++ test-linuxcnc-wasm-cmake-safe-probe.sh | 5 +++++ test-native.sh | 3 +++ 7 files changed, 35 insertions(+), 1 deletion(-) diff --git a/build-wasm.sh b/build-wasm.sh index bf83724..0db7908 100755 --- a/build-wasm.sh +++ b/build-wasm.sh @@ -10,6 +10,13 @@ if ! [[ "$build_jobs" =~ ^[1-9][0-9]*$ ]]; then echo "CNC_SIM_BUILD_JOBS must be a positive integer: $build_jobs" >&2 exit 1 fi +cmake_compiler_launcher_args=() +if [[ -z ${CXX:-} ]] && command -v ccache >/dev/null 2>&1; then + cmake_compiler_launcher_args+=( + -DCMAKE_C_COMPILER_LAUNCHER=ccache + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + ) +fi LINUXCNC_ROOT="$linuxcnc_root" ./check-linuxcnc-inputs.sh "$manifest" manifest=$(cd "$(dirname "$manifest")" && pwd)/$(basename "$manifest") @@ -117,7 +124,8 @@ emcmake cmake -S core -B build/wasm \ -DCMAKE_BUILD_TYPE=Release \ -DCNC_SIM_LINUXCNC_ROOT="$linuxcnc_root" \ -DCNC_SIM_LINUXCNC_WASM_SOURCE_MANIFEST="$manifest" \ - -DCNC_SIM_ENABLE_LINUXCNC_WASM_SAFE_PROBE=ON + -DCNC_SIM_ENABLE_LINUXCNC_WASM_SAFE_PROBE=ON \ + "${cmake_compiler_launcher_args[@]}" cmake --build build/wasm --target cnc_sim_wasm_runtime_probe --parallel "$build_jobs" cmake --build build/wasm --target cnc_sim_wasm --parallel "$build_jobs" mkdir -p web/public diff --git a/docs/linuxcnc-source-policy.md b/docs/linuxcnc-source-policy.md index 4894b46..2728ad5 100644 --- a/docs/linuxcnc-source-policy.md +++ b/docs/linuxcnc-source-policy.md @@ -57,6 +57,9 @@ Efficiency rules: - Default native, source-link, build-wasm, and wasm-safe CMake probe parallelism to `CNC_SIM_BUILD_JOBS:-8`; raise it only by explicit positive-integer environment override. +- When `ccache` is available and `CXX` is unset, native and wasm build paths + should enable compiler caching automatically rather than requiring a manual + wrapper. - Persistent native, source-link, and wasm-safe CMake probe build directories may be overridden for local workflows, but must not point at the filesystem root. diff --git a/test-all-native.sh b/test-all-native.sh index 4c0dec5..3c523a4 100755 --- a/test-all-native.sh +++ b/test-all-native.sh @@ -192,10 +192,19 @@ grep -F 'printf '\''\t@$(CXX) $(COMMON_FLAGS) -MMD -MP -MF %s/source_%s.d %s\n'\ grep -F 'make --output-sync=target -j"$build_jobs" -f "$source_syntax_makefile"' test-linuxcnc-source-syntax.sh >/dev/null grep -F 'build_jobs=${CNC_SIM_BUILD_JOBS:-8}' build-wasm.sh >/dev/null grep -F 'CNC_SIM_BUILD_JOBS must be a positive integer: $build_jobs' build-wasm.sh >/dev/null +grep -F 'command -v ccache >/dev/null 2>&1' build-wasm.sh >/dev/null +grep -F 'CMAKE_C_COMPILER_LAUNCHER=ccache' build-wasm.sh >/dev/null +grep -F 'CMAKE_CXX_COMPILER_LAUNCHER=ccache' build-wasm.sh >/dev/null grep -F 'cmake --build build/wasm --target cnc_sim_wasm_runtime_probe --parallel "$build_jobs"' build-wasm.sh >/dev/null grep -F 'cmake --build build/wasm --target cnc_sim_wasm --parallel "$build_jobs"' build-wasm.sh >/dev/null +grep -F 'command -v ccache >/dev/null 2>&1' test-native.sh >/dev/null +grep -F 'command -v ccache >/dev/null 2>&1' test-linuxcnc-source-link.sh >/dev/null +grep -F 'command -v ccache >/dev/null 2>&1' test-linuxcnc-source-syntax.sh >/dev/null grep -F 'build_jobs=${CNC_SIM_BUILD_JOBS:-8}' test-linuxcnc-wasm-cmake-safe-probe.sh >/dev/null grep -F 'CNC_SIM_BUILD_JOBS must be a positive integer: $build_jobs' test-linuxcnc-wasm-cmake-safe-probe.sh >/dev/null +grep -F 'cmake_compiler_launcher_mode=none' test-linuxcnc-wasm-cmake-safe-probe.sh >/dev/null +grep -F 'cmake_compiler_launcher_mode=ccache' test-linuxcnc-wasm-cmake-safe-probe.sh >/dev/null +grep -F 'COMPILER_LAUNCHER=%s\n' test-linuxcnc-wasm-cmake-safe-probe.sh >/dev/null grep -F 'build_dir=${CNC_SIM_WASM_CMAKE_SAFE_PROBE_BUILD_DIR-build/wasm-cmake-safe-probe}' test-linuxcnc-wasm-cmake-safe-probe.sh >/dev/null grep -F 'CNC_SIM_WASM_CMAKE_SAFE_PROBE_BUILD_DIR must not be empty' test-linuxcnc-wasm-cmake-safe-probe.sh >/dev/null grep -F 'CNC_SIM_WASM_CMAKE_SAFE_PROBE_BUILD_DIR must not contain whitespace: $build_dir' test-linuxcnc-wasm-cmake-safe-probe.sh >/dev/null diff --git a/test-linuxcnc-source-link.sh b/test-linuxcnc-source-link.sh index 9874f68..654fa09 100755 --- a/test-linuxcnc-source-link.sh +++ b/test-linuxcnc-source-link.sh @@ -5,6 +5,9 @@ cd "$(dirname "$0")" linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc} cxx=${CXX:-g++} +if [[ -z ${CXX:-} ]] && command -v ccache >/dev/null 2>&1; then + cxx="ccache $cxx" +fi build_jobs=${CNC_SIM_BUILD_JOBS:-8} if ! [[ "$build_jobs" =~ ^[1-9][0-9]*$ ]]; then echo "CNC_SIM_BUILD_JOBS must be a positive integer: $build_jobs" >&2 diff --git a/test-linuxcnc-source-syntax.sh b/test-linuxcnc-source-syntax.sh index 1fcd19f..3356e82 100755 --- a/test-linuxcnc-source-syntax.sh +++ b/test-linuxcnc-source-syntax.sh @@ -5,6 +5,9 @@ cd "$(dirname "$0")" linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc} cxx=${CXX:-g++} +if [[ -z ${CXX:-} ]] && command -v ccache >/dev/null 2>&1; then + cxx="ccache $cxx" +fi build_jobs=${CNC_SIM_BUILD_JOBS:-8} if ! [[ "$build_jobs" =~ ^[1-9][0-9]*$ ]]; then echo "CNC_SIM_BUILD_JOBS must be a positive integer: $build_jobs" >&2 diff --git a/test-linuxcnc-wasm-cmake-safe-probe.sh b/test-linuxcnc-wasm-cmake-safe-probe.sh index 34d46d7..dcc1ef8 100755 --- a/test-linuxcnc-wasm-cmake-safe-probe.sh +++ b/test-linuxcnc-wasm-cmake-safe-probe.sh @@ -9,6 +9,10 @@ if ! [[ "$build_jobs" =~ ^[1-9][0-9]*$ ]]; then echo "CNC_SIM_BUILD_JOBS must be a positive integer: $build_jobs" >&2 exit 1 fi +cmake_compiler_launcher_mode=none +if [[ -z ${CXX:-} ]] && command -v ccache >/dev/null 2>&1; then + cmake_compiler_launcher_mode=ccache +fi build_dir=${CNC_SIM_WASM_CMAKE_SAFE_PROBE_BUILD_DIR-build/wasm-cmake-safe-probe} if [[ -z "$build_dir" ]]; then echo "CNC_SIM_WASM_CMAKE_SAFE_PROBE_BUILD_DIR must not be empty" >&2 @@ -99,6 +103,7 @@ build_next_signature=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_wasm_cmake_safe_probe.sig printf 'LINUXCNC_ROOT=%s\n' "$linuxcnc_root" printf 'MANIFEST=%s\n' "$manifest" printf 'BUILD_JOBS=%s\n' "$build_jobs" + printf 'COMPILER_LAUNCHER=%s\n' "$cmake_compiler_launcher_mode" } > "$build_next_signature" if [[ ! -f "$build_signature" ]] || ! cmp -s "$build_signature" "$build_next_signature"; then rm -rf "$build_dir" diff --git a/test-native.sh b/test-native.sh index fecebcd..cd47dfb 100755 --- a/test-native.sh +++ b/test-native.sh @@ -4,6 +4,9 @@ set -euo pipefail cd "$(dirname "$0")" cxx=${CXX:-g++} +if [[ -z ${CXX:-} ]] && command -v ccache >/dev/null 2>&1; then + cxx="ccache $cxx" +fi build_jobs=${CNC_SIM_BUILD_JOBS:-8} if ! [[ "$build_jobs" =~ ^[1-9][0-9]*$ ]]; then echo "CNC_SIM_BUILD_JOBS must be a positive integer: $build_jobs" >&2