From 4e4ada804a9a85aadc2b9b53d16c551b07b4d5cc Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc Date: Thu, 22 Oct 2026 20:13:56 +0200 Subject: [PATCH 1/3] Copy the Linux CEF files once per destination and retry setup-cmake in CI The CEF targets of one directory share their output directory, and all of them share the CEF binary directory (ICU fix); each copied the CEF runtime files, resources and locales there in its own post-build step, so a parallel build could copy into one directory twice at once and fail with "Error copying directory ... locales". One copy target per destination now does it, and the CEF targets depend on it. setup-cmake sometimes fails with "Unable to find version matching 4.4.4" when the GitHub API lists no release; BuildAndTest tries once more after a pause. --- .github/workflows/BuildAndTest.yml | 39 ++++++++++++-- cmake/CEFSupport.cmake | 85 +++++++++++++++++++----------- docs/CHANGELOG.md | 6 +++ 3 files changed, 96 insertions(+), 34 deletions(-) diff --git a/.github/workflows/BuildAndTest.yml b/.github/workflows/BuildAndTest.yml index 311879ae..4c6d092d 100644 --- a/.github/workflows/BuildAndTest.yml +++ b/.github/workflows/BuildAndTest.yml @@ -61,7 +61,18 @@ jobs: node-version: 24 cache: npm cache-dependency-path: js/developer/vendor/package-lock.json - - uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 + # The action lists CMake releases through the GitHub API, which sometimes answers without them + # ("Unable to find version matching"): one more attempt after a pause. + - id: cmake + uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 + continue-on-error: true + with: + cmake-version: '4.4.4' + - if: steps.cmake.outcome == 'failure' + shell: bash + run: sleep 30 + - if: steps.cmake.outcome == 'failure' + uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 with: cmake-version: '4.4.4' - uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9 @@ -185,7 +196,18 @@ jobs: - uses: actions/setup-node@v6 with: node-version: 24 - - uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 + # The action lists CMake releases through the GitHub API, which sometimes answers without them + # ("Unable to find version matching"): one more attempt after a pause. + - id: cmake + uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 + continue-on-error: true + with: + cmake-version: '4.4.4' + - if: steps.cmake.outcome == 'failure' + shell: bash + run: sleep 30 + - if: steps.cmake.outcome == 'failure' + uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 with: cmake-version: '4.4.4' - name: Install Clang 23 and sanitizer runtimes @@ -257,7 +279,18 @@ jobs: with: node-version: 24 - - uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 + # The action lists CMake releases through the GitHub API, which sometimes answers without them + # ("Unable to find version matching"): one more attempt after a pause. + - id: cmake + uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 + continue-on-error: true + with: + cmake-version: '4.4.4' + - if: steps.cmake.outcome == 'failure' + shell: bash + run: sleep 30 + - if: steps.cmake.outcome == 'failure' + uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 with: cmake-version: '4.4.4' diff --git a/cmake/CEFSupport.cmake b/cmake/CEFSupport.cmake index cf930f54..f4c72b10 100644 --- a/cmake/CEFSupport.cmake +++ b/cmake/CEFSupport.cmake @@ -91,6 +91,44 @@ function(_cef_copy_directory_to_target target_name source_dir dest_dir comment_t ) endfunction() +# Linux: the CEF targets of one directory share their output directory, and every CEF target shares the CEF binary +# directory (ICU fix). Copying from each target's POST_BUILD step made parallel builds copy into one directory twice +# at the same time ("Error copying directory ... locales"). Each destination gets one copy target instead, named +# after the destination, on which the targets depend. +function(_cef_shared_copy_target target_name name destination comment) + if(NOT TARGET ${name}) + add_custom_target(${name} + COMMAND ${CMAKE_COMMAND} -E make_directory "${destination}" + ${ARGN} + COMMENT "${comment}" + VERBATIM) + endif() + add_dependencies(${target_name} ${name}) +endfunction() + +# The copy commands of a file list, into a directory that exists. +function(_cef_copy_commands out source_dir dest_dir file_list) + set(commands "") + foreach(file_name IN LISTS file_list) + list(APPEND commands COMMAND ${CMAKE_COMMAND} -E copy_if_different "${source_dir}/${file_name}" "${dest_dir}") + endforeach() + set(${out} ${commands} PARENT_SCOPE) +endfunction() + +# The output directory shared by the targets of the current directory that set no output directory of their own, +# and the key naming its copy targets. A path, not $: a copy target referencing one of the targets +# depending on it would form a cycle. +function(_cef_output_directory out_dir out_key) + get_property(multi GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(multi) + set(${out_dir} "${CMAKE_CURRENT_BINARY_DIR}/$" PARENT_SCOPE) + else() + set(${out_dir} "${CMAKE_CURRENT_BINARY_DIR}" PARENT_SCOPE) + endif() + string(MD5 key "${CMAKE_CURRENT_BINARY_DIR}") + set(${out_key} ${key} PARENT_SCOPE) +endfunction() + # Internal function to setup CEF paths and variables function(_cef_setup_paths) set(CEF_ROOT "${CMAKE_BINARY_DIR}/_deps/cef_binaries-src" PARENT_SCOPE) @@ -213,12 +251,10 @@ function(copy_cef_runtime_files target_name cef_build_dir) ) endif() elseif(UNIX) - _cef_copy_files_to_target(${target_name} - "${cef_build_dir}" - "${target_dir}" - "${CEF_LINUX_RUNTIME_FILES}" - "Copying CEF runtime files to output directory" - ) + _cef_output_directory(output key) + _cef_copy_commands(commands "${cef_build_dir}" "${output}" "${CEF_LINUX_RUNTIME_FILES}") + _cef_shared_copy_target(${target_name} webfront_cef_runtime_${key} "${output}" + "Copying CEF runtime files to ${CMAKE_CURRENT_BINARY_DIR}" ${commands}) endif() message(STATUS "CEF runtime files will be copied for ${target_name}") @@ -269,31 +305,18 @@ function(copy_cef_resource_files target_name) # This dual-copy approach fixes the ICU data loading issue where CEF # searches for icudtl.dat in its installation directory - # Copy to application directory (standard deployment) - _cef_copy_files_to_target(${target_name} - "${CEF_RESOURCE_SOURCE_DIR}" - "${target_dir}" - "${CEF_RESOURCE_FILES}" - "Copying CEF resource files to application directory" - ) - _cef_copy_directory_to_target(${target_name} - "${CEF_RESOURCE_SOURCE_DIR}/locales" - "${target_dir}/locales" - "Copying CEF locales to application directory" - ) - - # Copy to CEF binary directory (ICU loading fix) - _cef_copy_files_to_target(${target_name} - "${CEF_RESOURCE_SOURCE_DIR}" - "${CEF_BINARY_RELEASE_DIR}" - "${CEF_RESOURCE_FILES}" - "Copying CEF resource files to binary directory (ICU fix)" - ) - _cef_copy_directory_to_target(${target_name} - "${CEF_RESOURCE_SOURCE_DIR}/locales" - "${CEF_BINARY_RELEASE_DIR}/locales" - "Copying CEF locales to binary directory (ICU fix)" - ) + # Copy to application directory (standard deployment), once per output directory + _cef_output_directory(output key) + _cef_copy_commands(commands "${CEF_RESOURCE_SOURCE_DIR}" "${output}" "${CEF_RESOURCE_FILES}") + _cef_shared_copy_target(${target_name} webfront_cef_resources_${key} "${output}" + "Copying CEF resource files and locales to ${CMAKE_CURRENT_BINARY_DIR}" ${commands} + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CEF_RESOURCE_SOURCE_DIR}/locales" "${output}/locales") + + # Copy to CEF binary directory (ICU loading fix), once for all targets + _cef_copy_commands(commands "${CEF_RESOURCE_SOURCE_DIR}" "${CEF_BINARY_RELEASE_DIR}" "${CEF_RESOURCE_FILES}") + _cef_shared_copy_target(${target_name} webfront_cef_binary_resources "${CEF_BINARY_RELEASE_DIR}" + "Copying CEF resource files and locales to the CEF binary directory (ICU fix)" ${commands} + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CEF_RESOURCE_SOURCE_DIR}/locales" "${CEF_BINARY_RELEASE_DIR}/locales") endif() message(STATUS "CEF resource files will be copied for ${target_name}") diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 385c6eb2..35ab12ed 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -48,6 +48,12 @@ - Developer distribution 0.4.1 (published as `developer-v0.4.1`): generated providers include ``. Published 0.4.0 remains immutable. +### Fixed + +- Linux CEF builds: the runtime files, resources and locales are copied once per destination directory by a shared + copy target, instead of by every CEF target's post-build step, which made parallel builds fail intermittently + ("Error copying directory ... locales"). CI retries `setup-cmake` once when the GitHub API lists no CMake release. + ## 0.4.0 - 2026-10-21 ### Changed From c5ccaf42dac5b8a6954c0916bffa6a02dc05877d Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc Date: Thu, 22 Oct 2026 20:25:37 +0200 Subject: [PATCH 2/3] Copy CEF files to the target's output directory only when they change, and install CMake from its archive - The shared Linux copy targets now use the target's output directory (RUNTIME_OUTPUT_DIRECTORY, initialized from CMAKE_RUNTIME_OUTPUT_DIRECTORY) instead of the current binary directory, which broke projects building into bin/. Per-configuration output directories, and an output directory set after the frontend setup, are configure errors rather than a wrong deployment. - Copies are rules with outputs and dependencies (a stamp for locales/), so a build with nothing new copies nothing; each comment names the destination. - CEFCopyDestinations checks the destinations, the incremental copies and the refusals with stand-in files, without a compiler or CEF. - A local action installs CMake from the Kitware archive with a pinned SHA-256, without the GitHub API listing that failed intermittently; BuildAndTest, MddlogIntegration and ReleaseVersion use it. --- .github/actions/setup-cmake/action.yml | 50 ++++++++++ .github/workflows/BuildAndTest.yml | 45 ++------- .github/workflows/MddlogIntegration.yml | 8 +- .github/workflows/ReleaseVersion.yml | 4 +- cmake/CEFSupport.cmake | 120 +++++++++++++++-------- docs/CHANGELOG.md | 8 +- test/cmake/CheckCEFCopy.cmake | 89 +++++++++++++++++ test/cmake/cef-copy/CMakeLists.txt | 61 ++++++++++++ test/cmake/cef-copy/other/CMakeLists.txt | 8 ++ test/unit/CMakeLists.txt | 4 + 10 files changed, 310 insertions(+), 87 deletions(-) create mode 100644 .github/actions/setup-cmake/action.yml create mode 100644 test/cmake/CheckCEFCopy.cmake create mode 100644 test/cmake/cef-copy/CMakeLists.txt create mode 100644 test/cmake/cef-copy/other/CMakeLists.txt diff --git a/.github/actions/setup-cmake/action.yml b/.github/actions/setup-cmake/action.yml new file mode 100644 index 00000000..6ccaf593 --- /dev/null +++ b/.github/actions/setup-cmake/action.yml @@ -0,0 +1,50 @@ +name: Set up CMake +description: >- + Installs an exact CMake release from its Kitware archive, checked against a SHA-256 pinned here. No GitHub API call + lists the releases, so the installation cannot fail on an incomplete answer ("Unable to find version matching"). +inputs: + version: + description: Exact CMake version; its archives must have a pinned SHA-256 below. + required: true +runs: + using: composite + steps: + - name: Install CMake ${{ inputs.version }} + shell: bash + env: + VERSION: ${{ inputs.version }} + run: | + set -euo pipefail + case "$RUNNER_OS" in + Linux) platform=linux-x86_64; extension=tar.gz; bin=bin ;; + macOS) platform=macos-universal; extension=tar.gz; bin=CMake.app/Contents/bin ;; + Windows) platform=windows-x86_64; extension=zip; bin=bin ;; + *) echo "::error::No CMake archive for $RUNNER_OS"; exit 1 ;; + esac + name="cmake-$VERSION-$platform" + # From cmake--SHA-256.txt of each Kitware release. + case "$name.$extension" in + cmake-4.4.4-linux-x86_64.tar.gz) expected=e5bb807f7728cb60cd8b27ebc97a2edb469b68655f21e844a600c3575b76f5bb ;; + cmake-4.4.4-macos-universal.tar.gz) expected=4b7b73704b1db9b374e5c9ab8e17ac6148b817b6396ee75cd94a852cbac9d305 ;; + cmake-4.4.4-windows-x86_64.zip) expected=bace36e94b31c68ab6fa295f26dfa11219e0701cf7c94b0284a7d1cb13dac536 ;; + cmake-4.3.1-linux-x86_64.tar.gz) expected=208d76804009cbe8ec9aea0aa052c857c6e59bd289b43b9941c99324dc78b1d8 ;; + cmake-4.3.1-macos-universal.tar.gz) expected=c21fe4ade82a6a236aae0b9fbd8263c7ac6824a3fb32d03594456e30b06f3b7f ;; + cmake-4.3.1-windows-x86_64.zip) expected=03a610be931546474e46a442d171ef10532f4fc847de9cf76b7a8065bbef6a23 ;; + *) echo "::error::No pinned SHA-256 for $name.$extension: add it to .github/actions/setup-cmake/action.yml"; exit 1 ;; + esac + archive="$RUNNER_TEMP/$name.$extension" + curl -fsSL --retry 5 --retry-all-errors --retry-delay 15 -o "$archive" \ + "https://github.com/Kitware/CMake/releases/download/v$VERSION/$name.$extension" + if command -v sha256sum > /dev/null; then actual=$(sha256sum "$archive" | cut -d' ' -f1) + else actual=$(shasum -a 256 "$archive" | cut -d' ' -f1); fi + if [ "$actual" != "$expected" ]; then + echo "::error::$name.$extension has SHA-256 $actual, expected $expected"; exit 1 + fi + if [ "$extension" = zip ]; then + pwsh -NoProfile -Command "Expand-Archive -LiteralPath '$(cygpath -w "$archive")' -DestinationPath '$(cygpath -w "$RUNNER_TEMP")' -Force" + cygpath -w "$RUNNER_TEMP/$name/$bin" >> "$GITHUB_PATH" + else + tar -xzf "$archive" -C "$RUNNER_TEMP" + echo "$RUNNER_TEMP/$name/$bin" >> "$GITHUB_PATH" + fi + "$RUNNER_TEMP/$name/$bin/cmake" --version diff --git a/.github/workflows/BuildAndTest.yml b/.github/workflows/BuildAndTest.yml index 4c6d092d..133f2d27 100644 --- a/.github/workflows/BuildAndTest.yml +++ b/.github/workflows/BuildAndTest.yml @@ -61,20 +61,9 @@ jobs: node-version: 24 cache: npm cache-dependency-path: js/developer/vendor/package-lock.json - # The action lists CMake releases through the GitHub API, which sometimes answers without them - # ("Unable to find version matching"): one more attempt after a pause. - - id: cmake - uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 - continue-on-error: true + - uses: ./.github/actions/setup-cmake with: - cmake-version: '4.4.4' - - if: steps.cmake.outcome == 'failure' - shell: bash - run: sleep 30 - - if: steps.cmake.outcome == 'failure' - uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 - with: - cmake-version: '4.4.4' + version: '4.4.4' - uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9 - uses: actions/cache@v4 with: @@ -196,20 +185,9 @@ jobs: - uses: actions/setup-node@v6 with: node-version: 24 - # The action lists CMake releases through the GitHub API, which sometimes answers without them - # ("Unable to find version matching"): one more attempt after a pause. - - id: cmake - uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 - continue-on-error: true - with: - cmake-version: '4.4.4' - - if: steps.cmake.outcome == 'failure' - shell: bash - run: sleep 30 - - if: steps.cmake.outcome == 'failure' - uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 + - uses: ./.github/actions/setup-cmake with: - cmake-version: '4.4.4' + version: '4.4.4' - name: Install Clang 23 and sanitizer runtimes run: | wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor | sudo tee /usr/share/keyrings/llvm-archive-keyring.gpg > /dev/null @@ -279,20 +257,9 @@ jobs: with: node-version: 24 - # The action lists CMake releases through the GitHub API, which sometimes answers without them - # ("Unable to find version matching"): one more attempt after a pause. - - id: cmake - uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 - continue-on-error: true - with: - cmake-version: '4.4.4' - - if: steps.cmake.outcome == 'failure' - shell: bash - run: sleep 30 - - if: steps.cmake.outcome == 'failure' - uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 + - uses: ./.github/actions/setup-cmake with: - cmake-version: '4.4.4' + version: '4.4.4' - name: Install Clang 23 if: matrix.compiler == 'clang' diff --git a/.github/workflows/MddlogIntegration.yml b/.github/workflows/MddlogIntegration.yml index d7f9e909..4f9e261f 100644 --- a/.github/workflows/MddlogIntegration.yml +++ b/.github/workflows/MddlogIntegration.yml @@ -22,9 +22,9 @@ jobs: ref: 5b43265664d83c3b7135d328f611e685792a1b02 path: dependencies/mddlog - name: Setup CMake (4.3.1, within the qualified 4.0-4.3 window) - uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 + uses: ./.github/actions/setup-cmake with: - cmake-version: '4.3.1' + version: '4.3.1' - name: Install LLVM/Clang 21 and libc++ run: | @@ -97,9 +97,9 @@ jobs: ref: 5b43265664d83c3b7135d328f611e685792a1b02 path: dependencies/mddlog - name: Setup CMake (4.3.1, within the qualified 4.0-4.3 window) - uses: jwlawson/actions-setup-cmake@0d6a7d60b009d01c9e7523be22153ff8f19460d3 # v2 + uses: ./.github/actions/setup-cmake with: - cmake-version: '4.3.1' + version: '4.3.1' - name: Install LLVM/Clang 21 and libc++ run: | diff --git a/.github/workflows/ReleaseVersion.yml b/.github/workflows/ReleaseVersion.yml index 8134cfde..cb698686 100644 --- a/.github/workflows/ReleaseVersion.yml +++ b/.github/workflows/ReleaseVersion.yml @@ -18,9 +18,9 @@ jobs: - uses: actions/checkout@v7 with: ref: ${{ github.event.release.tag_name || github.ref }} - - uses: jwlawson/actions-setup-cmake@v2 + - uses: ./.github/actions/setup-cmake with: - cmake-version: '4.4.4' + version: '4.4.4' - name: Detect project version with CMake run: cmake -S . -B build -DWEBFRONT_EMBED_CEF=OFF -DENABLE_TESTING=ON -DWEBFRONT_BUILD_EXAMPLES=OFF - name: Compare release tag with header and CMake diff --git a/cmake/CEFSupport.cmake b/cmake/CEFSupport.cmake index f4c72b10..242e6ed9 100644 --- a/cmake/CEFSupport.cmake +++ b/cmake/CEFSupport.cmake @@ -91,42 +91,85 @@ function(_cef_copy_directory_to_target target_name source_dir dest_dir comment_t ) endfunction() -# Linux: the CEF targets of one directory share their output directory, and every CEF target shares the CEF binary -# directory (ICU fix). Copying from each target's POST_BUILD step made parallel builds copy into one directory twice -# at the same time ("Error copying directory ... locales"). Each destination gets one copy target instead, named -# after the destination, on which the targets depend. -function(_cef_shared_copy_target target_name name destination comment) +# Linux: CEF targets that build into one directory share it, and every CEF target shares the CEF binary directory +# (ICU fix). Copying from each target's POST_BUILD step made parallel builds copy into one directory twice at the +# same time ("Error copying directory ... locales"). Each destination gets one copy target instead, named after the +# destination, on which its targets depend. Its rules produce the copied files from their sources, so a build with +# nothing to copy copies nothing; a directory is copied with a stamp file standing for its contents. +function(_cef_shared_copy target_name destination) + cmake_parse_arguments(PARSE_ARGV 2 copy "" "NAME;SOURCE_DIR;DIRECTORY" "FILES") + string(MD5 key "${destination}") + set(name webfront_cef_${copy_NAME}_${key}) if(NOT TARGET ${name}) - add_custom_target(${name} - COMMAND ${CMAKE_COMMAND} -E make_directory "${destination}" - ${ARGN} - COMMENT "${comment}" - VERBATIM) + set(outputs "") + foreach(file_name IN LISTS copy_FILES) + add_custom_command(OUTPUT "${destination}/${file_name}" + COMMAND ${CMAKE_COMMAND} -E make_directory "${destination}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${copy_SOURCE_DIR}/${file_name}" "${destination}/${file_name}" + DEPENDS "${copy_SOURCE_DIR}/${file_name}" + COMMENT "Copying CEF ${file_name} to ${destination}" + VERBATIM) + list(APPEND outputs "${destination}/${file_name}") + endforeach() + if(copy_DIRECTORY) + file(GLOB_RECURSE contents CONFIGURE_DEPENDS "${copy_SOURCE_DIR}/${copy_DIRECTORY}/*") + set(stamp "${destination}/${copy_DIRECTORY}/.webfront-copied") + add_custom_command(OUTPUT "${stamp}" + COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different "${copy_SOURCE_DIR}/${copy_DIRECTORY}" "${destination}/${copy_DIRECTORY}" + COMMAND ${CMAKE_COMMAND} -E touch "${stamp}" + DEPENDS ${contents} + COMMENT "Copying CEF ${copy_DIRECTORY} to ${destination}" + VERBATIM) + list(APPEND outputs "${stamp}") + endif() + add_custom_target(${name} DEPENDS ${outputs}) endif() add_dependencies(${target_name} ${name}) endfunction() -# The copy commands of a file list, into a directory that exists. -function(_cef_copy_commands out source_dir dest_dir file_list) - set(commands "") - foreach(file_name IN LISTS file_list) - list(APPEND commands COMMAND ${CMAKE_COMMAND} -E copy_if_different "${source_dir}/${file_name}" "${dest_dir}") - endforeach() - set(${out} ${commands} PARENT_SCOPE) +# Fails at the end of the directory if the target's output directory changed after the copy was planned for it. +function(_cef_check_output_directory target_name planned) + _cef_output_directory(${target_name} actual) + if(NOT actual STREQUAL planned) + message(FATAL_ERROR "The CEF files of ${target_name} are copied to ${planned}, but it now builds into ${actual}: " + "set its RUNTIME_OUTPUT_DIRECTORY (or CMAKE_RUNTIME_OUTPUT_DIRECTORY) before calling the WebFront frontend setup") + endif() endfunction() -# The output directory shared by the targets of the current directory that set no output directory of their own, -# and the key naming its copy targets. A path, not $: a copy target referencing one of the targets -# depending on it would form a cycle. -function(_cef_output_directory out_dir out_key) +# The directory a target's executable is built into, as $ would name it: its RUNTIME_OUTPUT_DIRECTORY +# (initialized from CMAKE_RUNTIME_OUTPUT_DIRECTORY), else the binary directory of the directory that created it, plus +# the configuration with a multi-config generator. A path, not $: a copy target referencing a target +# that depends on it would form a cycle. Per-configuration output directories are refused rather than guessed. +function(_cef_output_directory target_name out_dir) + foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES CMAKE_BUILD_TYPE) + string(TOUPPER "${config}" upper) + get_target_property(per_config ${target_name} RUNTIME_OUTPUT_DIRECTORY_${upper}) + if(per_config) + message(FATAL_ERROR "${target_name} sets RUNTIME_OUTPUT_DIRECTORY_${upper}, which the CEF file copy does not " + "support on Linux: set RUNTIME_OUTPUT_DIRECTORY instead") + endif() + endforeach() + get_target_property(binary_dir ${target_name} BINARY_DIR) + get_target_property(directory ${target_name} RUNTIME_OUTPUT_DIRECTORY) + if(NOT directory) + set(directory "${binary_dir}") + elseif(NOT IS_ABSOLUTE "${directory}" AND NOT directory MATCHES "^\\$<") + set(directory "${binary_dir}/${directory}") + endif() get_property(multi GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) - if(multi) - set(${out_dir} "${CMAKE_CURRENT_BINARY_DIR}/$" PARENT_SCOPE) - else() - set(${out_dir} "${CMAKE_CURRENT_BINARY_DIR}" PARENT_SCOPE) + # Multi-config generators add the configuration unless the directory is a generator expression. + if(multi AND NOT directory MATCHES "\\$<") + set(directory "${directory}/$") endif() - string(MD5 key "${CMAKE_CURRENT_BINARY_DIR}") - set(${out_key} ${key} PARENT_SCOPE) + set(${out_dir} "${directory}" PARENT_SCOPE) +endfunction() + +# The output directory of a target, checked again once its directory is processed. +function(_cef_planned_output_directory target_name out_dir) + _cef_output_directory(${target_name} directory) + cmake_language(EVAL CODE + "cmake_language(DEFER CALL _cef_check_output_directory [==[${target_name}]==] [==[${directory}]==])") + set(${out_dir} "${directory}" PARENT_SCOPE) endfunction() # Internal function to setup CEF paths and variables @@ -251,10 +294,8 @@ function(copy_cef_runtime_files target_name cef_build_dir) ) endif() elseif(UNIX) - _cef_output_directory(output key) - _cef_copy_commands(commands "${cef_build_dir}" "${output}" "${CEF_LINUX_RUNTIME_FILES}") - _cef_shared_copy_target(${target_name} webfront_cef_runtime_${key} "${output}" - "Copying CEF runtime files to ${CMAKE_CURRENT_BINARY_DIR}" ${commands}) + _cef_planned_output_directory(${target_name} output) + _cef_shared_copy(${target_name} "${output}" NAME runtime SOURCE_DIR "${cef_build_dir}" FILES ${CEF_LINUX_RUNTIME_FILES}) endif() message(STATUS "CEF runtime files will be copied for ${target_name}") @@ -306,17 +347,14 @@ function(copy_cef_resource_files target_name) # searches for icudtl.dat in its installation directory # Copy to application directory (standard deployment), once per output directory - _cef_output_directory(output key) - _cef_copy_commands(commands "${CEF_RESOURCE_SOURCE_DIR}" "${output}" "${CEF_RESOURCE_FILES}") - _cef_shared_copy_target(${target_name} webfront_cef_resources_${key} "${output}" - "Copying CEF resource files and locales to ${CMAKE_CURRENT_BINARY_DIR}" ${commands} - COMMAND ${CMAKE_COMMAND} -E copy_directory "${CEF_RESOURCE_SOURCE_DIR}/locales" "${output}/locales") + _cef_planned_output_directory(${target_name} output) + _cef_shared_copy(${target_name} "${output}" NAME resources SOURCE_DIR "${CEF_RESOURCE_SOURCE_DIR}" + FILES ${CEF_RESOURCE_FILES} DIRECTORY locales) - # Copy to CEF binary directory (ICU loading fix), once for all targets - _cef_copy_commands(commands "${CEF_RESOURCE_SOURCE_DIR}" "${CEF_BINARY_RELEASE_DIR}" "${CEF_RESOURCE_FILES}") - _cef_shared_copy_target(${target_name} webfront_cef_binary_resources "${CEF_BINARY_RELEASE_DIR}" - "Copying CEF resource files and locales to the CEF binary directory (ICU fix)" ${commands} - COMMAND ${CMAKE_COMMAND} -E copy_directory "${CEF_RESOURCE_SOURCE_DIR}/locales" "${CEF_BINARY_RELEASE_DIR}/locales") + # Copy to CEF binary directory (ICU loading fix), once for all targets. As before, this is the Release + # directory in every configuration. + _cef_shared_copy(${target_name} "${CEF_BINARY_RELEASE_DIR}" NAME resources SOURCE_DIR "${CEF_RESOURCE_SOURCE_DIR}" + FILES ${CEF_RESOURCE_FILES} DIRECTORY locales) endif() message(STATUS "CEF resource files will be copied for ${target_name}") diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 35ab12ed..e3b81496 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -52,7 +52,13 @@ - Linux CEF builds: the runtime files, resources and locales are copied once per destination directory by a shared copy target, instead of by every CEF target's post-build step, which made parallel builds fail intermittently - ("Error copying directory ... locales"). CI retries `setup-cmake` once when the GitHub API lists no CMake release. + ("Error copying directory ... locales"). The destination is the target's output directory + (`RUNTIME_OUTPUT_DIRECTORY`, initialized from `CMAKE_RUNTIME_OUTPUT_DIRECTORY`); a per-configuration output + directory, or one set after the frontend setup, is an explicit configure error. A build with nothing new copies + nothing. +- CI installs CMake from the Kitware release archive checked against a pinned SHA-256 + (`.github/actions/setup-cmake`), instead of an action that lists the releases through the GitHub API and failed + intermittently ("Unable to find version matching"). ## 0.4.0 - 2026-10-21 diff --git a/test/cmake/CheckCEFCopy.cmake b/test/cmake/CheckCEFCopy.cmake new file mode 100644 index 00000000..34614c67 --- /dev/null +++ b/test/cmake/CheckCEFCopy.cmake @@ -0,0 +1,89 @@ +# The Linux CEF file copy of cmake/CEFSupport.cmake, with stand-in CEF files: one copy per destination, which is the +# target's own output directory; nothing copied again by a build with nothing to copy; explicit errors for the output +# directories it cannot honour. No compiler, SDK or network. +# cmake -DROOT= [-DTEST_GENERATOR=] -P test/cmake/CheckCEFCopy.cmake +cmake_minimum_required(VERSION 3.31) +if(NOT ROOT) + message(FATAL_ERROR "ROOT must be supplied") +endif() +set(generator_args "") +if(TEST_GENERATOR) + list(APPEND generator_args -G "${TEST_GENERATOR}") +endif() +set(work "${CMAKE_CURRENT_BINARY_DIR}/cef-copy") +set(source "${work}/source") +file(REMOVE_RECURSE "${work}") +file(WRITE "${source}/libcef.so" "library 1") +file(WRITE "${source}/locales/en-US.pak" "locale") + +function(configure state out_result out_log) + execute_process( + COMMAND "${CMAKE_COMMAND}" -S "${ROOT}/test/cmake/cef-copy" -B "${work}/${state}" ${generator_args} + -DROOT=${ROOT} -DSOURCE_DIR=${source} -DSTATE=${state} -DCMAKE_BUILD_TYPE=Release + RESULT_VARIABLE result OUTPUT_VARIABLE output ERROR_VARIABLE error) + set(${out_result} ${result} PARENT_SCOPE) + set(${out_log} "${output}${error}" PARENT_SCOPE) +endfunction() + +function(build out_log) + execute_process(COMMAND "${CMAKE_COMMAND}" --build "${work}/plan" --config Release + RESULT_VARIABLE result OUTPUT_VARIABLE output ERROR_VARIABLE error) + if(NOT result EQUAL 0) + message(FATAL_ERROR "Build of the copy fixture failed: ${output}${error}") + endif() + set(${out_log} "${output}${error}" PARENT_SCOPE) +endfunction() + +function(expect_file path content) + if(NOT EXISTS "${path}") + message(FATAL_ERROR "Missing copied file ${path}") + endif() + file(READ "${path}" actual) + if(NOT actual STREQUAL content) + message(FATAL_ERROR "${path} holds '${actual}', expected '${content}'") + endif() +endfunction() + +configure(plan result log) +if(NOT result EQUAL 0) + message(FATAL_ERROR "Copy destinations: ${log}") +endif() +build(first) +string(REGEX MATCHALL "Copying CEF libcef.so to [^\n]*" copies "${first}") +list(LENGTH copies count) +if(NOT count EQUAL 2) + message(FATAL_ERROR "Each of the two destinations must be copied once, got ${count}: ${first}") +endif() +foreach(destination "${work}/plan" "${work}/plan/bin") + if(NOT EXISTS "${destination}/libcef.so" AND EXISTS "${destination}/Release/libcef.so") + set(destination "${destination}/Release") + endif() + expect_file("${destination}/libcef.so" "library 1") + expect_file("${destination}/locales/en-US.pak" "locale") +endforeach() +build(second) +if(second MATCHES "Copying CEF") + message(FATAL_ERROR "A build with nothing to copy must copy nothing: ${second}") +endif() +file(WRITE "${source}/libcef.so" "library 2") +build(third) +if(NOT third MATCHES "Copying CEF libcef.so" OR third MATCHES "Copying CEF locales") + message(FATAL_ERROR "Only the changed file must be copied again: ${third}") +endif() +foreach(destination "${work}/plan" "${work}/plan/bin") + if(NOT EXISTS "${destination}/libcef.so" AND EXISTS "${destination}/Release/libcef.so") + set(destination "${destination}/Release") + endif() + expect_file("${destination}/libcef.so" "library 2") +endforeach() + +configure(per-config result log) +# CMake wraps long messages: any whitespace may separate the words. +if(result EQUAL 0 OR NOT log MATCHES "sets[ \t\r\n]+RUNTIME_OUTPUT_DIRECTORY_RELEASE") + message(FATAL_ERROR "A per-configuration output directory must be refused: ${log}") +endif() +configure(late result log) +if(result EQUAL 0 OR NOT log MATCHES "now[ \t\r\n]+builds[ \t\r\n]+into") + message(FATAL_ERROR "An output directory set after the copy was planned must be refused: ${log}") +endif() +message(STATUS "CEF copy destinations, incremental copies and refusals checked") diff --git a/test/cmake/cef-copy/CMakeLists.txt b/test/cmake/cef-copy/CMakeLists.txt new file mode 100644 index 00000000..846fef74 --- /dev/null +++ b/test/cmake/cef-copy/CMakeLists.txt @@ -0,0 +1,61 @@ +# Fixture of CheckCEFCopy.cmake: the Linux CEF file copy of cmake/CEFSupport.cmake, with stand-in CEF files and +# custom targets, so that no compiler, SDK or network is needed. STATE selects the case. +cmake_minimum_required(VERSION 3.31) +project(CEFCopyFixture LANGUAGES NONE) +include("${ROOT}/cmake/CEFSupport.cmake") + +if(NOT ROOT OR NOT IS_DIRECTORY "${SOURCE_DIR}") + message(FATAL_ERROR "ROOT and SOURCE_DIR (the stand-in CEF files) must be supplied") +endif() +set(source "${SOURCE_DIR}") +get_property(multi GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +set(config "") +if(multi) + set(config "/$") +endif() + +function(expect actual expected what) + if(NOT actual STREQUAL expected) + message(FATAL_ERROR "${what}: ${actual}, expected ${expected}") + endif() +endfunction() + +# Copies the stand-in runtime file and locales for a target, as copy_cef_runtime_files and copy_cef_resource_files do. +function(copy_for target_name) + _cef_planned_output_directory(${target_name} output) + _cef_shared_copy(${target_name} "${output}" NAME runtime SOURCE_DIR "${source}" FILES libcef.so DIRECTORY locales) + set(planned "${output}" PARENT_SCOPE) +endfunction() + +add_custom_target(everything ALL) + +if(STATE STREQUAL "plan") + # Two targets of this directory without an output directory share it, and one copy target. + add_custom_target(first) + add_custom_target(second) + copy_for(first) + expect("${planned}" "${CMAKE_CURRENT_BINARY_DIR}${config}" "default destination") + copy_for(second) + string(MD5 key "${planned}") + get_target_property(dependencies second MANUALLY_ADDED_DEPENDENCIES) + expect("${dependencies}" "webfront_cef_runtime_${key}" "second target's copy target") + # A relative RUNTIME_OUTPUT_DIRECTORY is under the target's binary directory. + add_custom_target(binned) + set_target_properties(binned PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin) + copy_for(binned) + expect("${planned}" "${CMAKE_CURRENT_BINARY_DIR}/bin${config}" "relative output directory") + # A target of another directory building into the same absolute directory shares that copy target. + add_subdirectory(other) + add_dependencies(everything first second binned elsewhere) +elseif(STATE STREQUAL "per-config") + add_custom_target(configured) + set_target_properties(configured PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE bin) + set(CMAKE_BUILD_TYPE Release) + copy_for(configured) +elseif(STATE STREQUAL "late") + add_custom_target(late) + copy_for(late) + set_target_properties(late PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin) +else() + message(FATAL_ERROR "Unknown STATE ${STATE}") +endif() diff --git a/test/cmake/cef-copy/other/CMakeLists.txt b/test/cmake/cef-copy/other/CMakeLists.txt new file mode 100644 index 00000000..feafe598 --- /dev/null +++ b/test/cmake/cef-copy/other/CMakeLists.txt @@ -0,0 +1,8 @@ +# A target of another directory, building into the directory of the target "binned": it shares its copy target. +add_custom_target(elsewhere) +set_target_properties(elsewhere PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") +copy_for(elsewhere) +expect("${planned}" "${CMAKE_BINARY_DIR}/bin${config}" "absolute output directory") +string(MD5 key "${planned}") +get_target_property(dependencies elsewhere MANUALLY_ADDED_DEPENDENCIES) +expect("${dependencies}" "webfront_cef_runtime_${key}" "shared copy target across directories") diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index c2a092b4..2124924d 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -96,6 +96,10 @@ add_test(NAME CEFTestingState COMMAND ${CMAKE_COMMAND} -DROOT=${PROJECT_SOURCE_DIR} -DCPM_MODULE=${CPM_DOWNLOAD_LOCATION} "-DTEST_GENERATOR=${CMAKE_GENERATOR}" -P ${PROJECT_SOURCE_DIR}/test/cmake/CheckCEFTestingState.cmake) +# The Linux CEF file copy, with stand-in files: destinations, incremental copies and refusals. +add_test(NAME CEFCopyDestinations + COMMAND ${CMAKE_COMMAND} -DROOT=${PROJECT_SOURCE_DIR} "-DTEST_GENERATOR=${CMAKE_GENERATOR}" + -P ${PROJECT_SOURCE_DIR}/test/cmake/CheckCEFCopy.cmake) add_test(NAME WebView2UnsupportedToolchain COMMAND ${CMAKE_COMMAND} -DROOT=${PROJECT_SOURCE_DIR} -P ${PROJECT_SOURCE_DIR}/test/cmake/CheckWebView2Toolchain.cmake) add_test(NAME WebView2LoaderArchitecture From be75abb57234339a3f49867d5db0260cbbb4ef84 Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc Date: Thu, 22 Oct 2026 20:37:24 +0200 Subject: [PATCH 3/3] Hash the CMake archive from standard input in the setup action On Windows the archive path holds backslashes, so sha256sum escapes the file name and prefixes its output with a backslash: the pinned hash never matched. --- .github/actions/setup-cmake/action.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/actions/setup-cmake/action.yml b/.github/actions/setup-cmake/action.yml index 6ccaf593..60235d23 100644 --- a/.github/actions/setup-cmake/action.yml +++ b/.github/actions/setup-cmake/action.yml @@ -35,8 +35,9 @@ runs: archive="$RUNNER_TEMP/$name.$extension" curl -fsSL --retry 5 --retry-all-errors --retry-delay 15 -o "$archive" \ "https://github.com/Kitware/CMake/releases/download/v$VERSION/$name.$extension" - if command -v sha256sum > /dev/null; then actual=$(sha256sum "$archive" | cut -d' ' -f1) - else actual=$(shasum -a 256 "$archive" | cut -d' ' -f1); fi + # From standard input: with a file name, sha256sum escapes a Windows path and prefixes the hash with "\". + if command -v sha256sum > /dev/null; then actual=$(sha256sum < "$archive" | cut -d' ' -f1) + else actual=$(shasum -a 256 < "$archive" | cut -d' ' -f1); fi if [ "$actual" != "$expected" ]; then echo "::error::$name.$extension has SHA-256 $actual, expected $expected"; exit 1 fi