From cbe25bb91c0ef09448e4da379d122856b32bea89 Mon Sep 17 00:00:00 2001 From: Ben Howe Date: Sun, 31 May 2026 20:06:53 +0000 Subject: [PATCH 1/3] Add per-PR workflow to validate patches Signed-off-by: Ben Howe --- .github/workflows/pr_workflow.yaml | 39 +++++++- .../workflows/scripts/check_cudaq_patch.sh | 96 +++++++++++++++++++ 2 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/scripts/check_cudaq_patch.sh diff --git a/.github/workflows/pr_workflow.yaml b/.github/workflows/pr_workflow.yaml index 05c3b5b7..4b3422c6 100644 --- a/.github/workflows/pr_workflow.yaml +++ b/.github/workflows/pr_workflow.yaml @@ -14,6 +14,7 @@ jobs: name: Check changes runs-on: ubuntu-latest outputs: + check-cudaq-patch: ${{ steps.filter.outputs.check-cudaq-patch }} build-cudaq: ${{ steps.filter.outputs.build-cudaq }} build-docs: ${{ steps.filter.outputs.build-docs }} build-all: ${{ steps.filter.outputs.build-all }} @@ -39,11 +40,18 @@ jobs: with: base: ${{ fromJSON(steps.get-pr-info.outputs.pr-info).base.sha }} filters: | + check-cudaq-patch: + - '.cudaq_version' + - '.github/actions/get-cudaq-version/**' + - '.github/workflows/pr_workflow.yaml' + - '.github/workflows/scripts/build_cudaq.sh' + - '.github/workflows/scripts/check_cudaq_patch.sh' + - 'scripts/ci/build_cudaq_wheel.sh' build-cudaq: + - '.cudaq_version' - '.github/actions/get-cudaq-build/**' - '.github/actions/get-cudaq-version/**' - '.github/workflows/scripts/build_cudaq.sh' - - '.cudaq_version' build-docs: - '.github/workflows/docs.yaml' - 'docs/**' @@ -91,6 +99,25 @@ jobs: build-examples-solvers: - 'docs/sphinx/examples/solvers/**' + check-cudaq-patch: + name: Check CUDAQ patch + needs: [check-changes] + if: needs.check-changes.outputs.check-cudaq-patch == 'true' + runs-on: linux-amd64-cpu4 + steps: + - name: Get code + uses: actions/checkout@v4 + with: + set-safe-directory: true + + - name: Install jq + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends jq + + - name: Verify CUDAQ patch applies + run: bash .github/workflows/scripts/check_cudaq_patch.sh + build-cudaq: name: Build CUDAQ needs: [check-changes] @@ -184,6 +211,7 @@ jobs: name: Verify PR if: ${{ always() }} needs: + - check-cudaq-patch - build-cudaq - build-all - build-qec @@ -206,10 +234,11 @@ jobs: fi } - check_result "build-cudaq" "${{needs.build-cudaq.result}}" - check_result "build-all" "${{needs.build-all.result}}" - check_result "build-qec" "${{needs.build-qec.result}}" - check_result "build-solvers" "${{needs.build-solvers.result}}" + check_result "check-cudaq-patch" "${{ needs.check-cudaq-patch.result }}" + check_result "build-cudaq" "${{ needs.build-cudaq.result }}" + check_result "build-all" "${{ needs.build-all.result }}" + check_result "build-qec" "${{ needs.build-qec.result }}" + check_result "build-solvers" "${{ needs.build-solvers.result }}" if [[ "$status" != "success" ]]; then exit 1 diff --git a/.github/workflows/scripts/check_cudaq_patch.sh b/.github/workflows/scripts/check_cudaq_patch.sh new file mode 100644 index 00000000..303c57c1 --- /dev/null +++ b/.github/workflows/scripts/check_cudaq_patch.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +# ============================================================================ # +# Copyright (c) 2022 - 2026 NVIDIA Corporation & Affiliates. # +# All rights reserved. # +# # +# This source code and the accompanying materials are made available under # +# the terms of the Apache License 2.0 which accompanies this distribution. # +# ============================================================================ # + +# Verify that the embedded CUDAQ_PATCH in the CUDA-Q build scripts still +# applies cleanly against the CUDA-Q commit pinned in .cudaq_version. +# +# The patches are sourced and piped to `git apply` exactly the way the build +# scripts apply them (assign the CUDAQ_PATCH heredoc, then +# `echo "$CUDAQ_PATCH" | git apply`). This is important because the trailing +# newline added by `echo` is part of the patch payload (it supplies the final +# blank context line in the second hunk). Anything that extracts the patch +# via a different mechanism may produce a payload that git apply rejects even +# though the build scripts apply the same bytes successfully. + +set -eo pipefail + +REPO_ROOT="$(cd "$(dirname "$0")/../../.." && pwd)" +WORKFLOW_SCRIPT="$REPO_ROOT/.github/workflows/scripts/build_cudaq.sh" +WHEEL_SCRIPT="$REPO_ROOT/scripts/ci/build_cudaq_wheel.sh" +CUDAQ_VERSION_FILE="$REPO_ROOT/.cudaq_version" + +# Source the CUDAQ_PATCH='...' heredoc out of a build script and echo it back +# the same way the build script does, so the trailing newline matches. +emit_patch_from_script() { + local script=$1 + local shell=$2 + "${shell}" -c "$(sed -n "/^CUDAQ_PATCH='/,/^'\$/p" "${script}")"$'\n''echo "$CUDAQ_PATCH"' +} + +# Apply (or check) the patch via the same code path the build script uses. +apply_patch_like_build_script() { + local script=$1 + local shell=$2 + local mode=$3 # "--check" or empty + emit_patch_from_script "${script}" "${shell}" \ + | git apply ${mode} --verbose +} + +if [ ! -f "${CUDAQ_VERSION_FILE}" ]; then + echo "Missing ${CUDAQ_VERSION_FILE}" >&2 + exit 1 +fi + +if ! command -v jq >/dev/null 2>&1; then + echo "jq is required" >&2 + exit 1 +fi + +CUDAQ_REPO=$(jq -r '.cudaq.repository' "${CUDAQ_VERSION_FILE}") +CUDAQ_REF=$(jq -r '.cudaq.ref' "${CUDAQ_VERSION_FILE}") + +echo "Checking CUDAQ_PATCH against ${CUDAQ_REPO}@${CUDAQ_REF}" + +WORKDIR=$(mktemp -d) +trap 'rm -rf "${WORKDIR}"' EXIT + +# Compare the two embedded patches byte-for-byte, using the same emission +# path each build script uses. +WORKFLOW_PATCH_BYTES="${WORKDIR}/workflow.patch" +WHEEL_PATCH_BYTES="${WORKDIR}/wheel.patch" +emit_patch_from_script "${WORKFLOW_SCRIPT}" bash > "${WORKFLOW_PATCH_BYTES}" +emit_patch_from_script "${WHEEL_SCRIPT}" sh > "${WHEEL_PATCH_BYTES}" + +if ! cmp -s "${WORKFLOW_PATCH_BYTES}" "${WHEEL_PATCH_BYTES}"; then + echo "CUDAQ_PATCH differs between:" >&2 + echo " ${WORKFLOW_SCRIPT}" >&2 + echo " ${WHEEL_SCRIPT}" >&2 + diff -u "${WORKFLOW_PATCH_BYTES}" "${WHEEL_PATCH_BYTES}" >&2 || true + exit 1 +fi +echo "CUDAQ_PATCH matches in both build scripts." + +git clone --filter=blob:none --no-checkout \ + "https://github.com/${CUDAQ_REPO}.git" "${WORKDIR}/cudaq" +git -C "${WORKDIR}/cudaq" checkout "${CUDAQ_REF}" + +echo "Checking patch from .github/workflows/scripts/build_cudaq.sh (bash) ..." +( + cd "${WORKDIR}/cudaq" + apply_patch_like_build_script "${WORKFLOW_SCRIPT}" bash --check +) + +echo "Checking patch from scripts/ci/build_cudaq_wheel.sh (sh) ..." +( + cd "${WORKDIR}/cudaq" + apply_patch_like_build_script "${WHEEL_SCRIPT}" sh --check +) + +echo "CUDAQ_PATCH applies cleanly to ${CUDAQ_REPO}@${CUDAQ_REF}." From c05e72dc072106ed4d568f1230f3a46bb5784ae6 Mon Sep 17 00:00:00 2001 From: Ben Howe Date: Sun, 31 May 2026 20:13:03 +0000 Subject: [PATCH 2/3] Add a new patch This may be needed due to https://github.com/NVIDIA/cuda-quantum/pull/4558 Signed-off-by: Ben Howe --- .github/workflows/scripts/build_cudaq.sh | 13 +++++++++++++ scripts/ci/build_cudaq_wheel.sh | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/.github/workflows/scripts/build_cudaq.sh b/.github/workflows/scripts/build_cudaq.sh index 5eca4024..569daa47 100755 --- a/.github/workflows/scripts/build_cudaq.sh +++ b/.github/workflows/scripts/build_cudaq.sh @@ -132,6 +132,19 @@ diff --git a/python/runtime/cudaq/domains/plugins/CMakeLists.txt b/python/runtim + nanobind-static Python3::Module cudaq-chemistry cudaq-operator cudaq cudaq-py-utils cudaq-platform-default) endif() + +diff --git a/runtime/common/CMakeLists.txt b/runtime/common/CMakeLists.txt +--- a/runtime/common/CMakeLists.txt ++++ b/runtime/common/CMakeLists.txt +@@ -80,7 +80,7 @@ if(OPENSSL_FOUND) + if(APPLE) + target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr ZLIB::ZLIB) + else() +- target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr -Wl,--start-group ZLIB::ZLIB) ++ target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr dl -Wl,--start-group ZLIB::ZLIB) + endif() + target_compile_definitions(${LIBRARY_NAME} PRIVATE -DCUDAQ_RESTCLIENT_AVAILABLE) + # Override the global flat_namespace for this library. cudaq-common doesn'\''t need ' echo "$CUDAQ_PATCH" | git apply --verbose diff --git a/scripts/ci/build_cudaq_wheel.sh b/scripts/ci/build_cudaq_wheel.sh index 6c93dc3d..cad15727 100644 --- a/scripts/ci/build_cudaq_wheel.sh +++ b/scripts/ci/build_cudaq_wheel.sh @@ -111,6 +111,19 @@ diff --git a/python/runtime/cudaq/domains/plugins/CMakeLists.txt b/python/runtim + nanobind-static Python3::Module cudaq-chemistry cudaq-operator cudaq cudaq-py-utils cudaq-platform-default) endif() + +diff --git a/runtime/common/CMakeLists.txt b/runtime/common/CMakeLists.txt +--- a/runtime/common/CMakeLists.txt ++++ b/runtime/common/CMakeLists.txt +@@ -80,7 +80,7 @@ if(OPENSSL_FOUND) + if(APPLE) + target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr ZLIB::ZLIB) + else() +- target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr -Wl,--start-group ZLIB::ZLIB) ++ target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr dl -Wl,--start-group ZLIB::ZLIB) + endif() + target_compile_definitions(${LIBRARY_NAME} PRIVATE -DCUDAQ_RESTCLIENT_AVAILABLE) + # Override the global flat_namespace for this library. cudaq-common doesn'\''t need ' echo "$CUDAQ_PATCH" | git apply --verbose From 86c37a7bde1059df8265b4f9936c1aa649b83725 Mon Sep 17 00:00:00 2001 From: Ben Howe Date: Mon, 1 Jun 2026 03:42:31 +0000 Subject: [PATCH 3/3] Try updated patch Signed-off-by: Ben Howe --- .github/workflows/scripts/build_cudaq.sh | 2 +- scripts/ci/build_cudaq_wheel.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts/build_cudaq.sh b/.github/workflows/scripts/build_cudaq.sh index 569daa47..6c9a4728 100755 --- a/.github/workflows/scripts/build_cudaq.sh +++ b/.github/workflows/scripts/build_cudaq.sh @@ -141,7 +141,7 @@ diff --git a/runtime/common/CMakeLists.txt b/runtime/common/CMakeLists.txt target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr ZLIB::ZLIB) else() - target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr -Wl,--start-group ZLIB::ZLIB) -+ target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr dl -Wl,--start-group ZLIB::ZLIB) ++ target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr -Wl,--start-group ZLIB::ZLIB ${CMAKE_DL_LIBS}) endif() target_compile_definitions(${LIBRARY_NAME} PRIVATE -DCUDAQ_RESTCLIENT_AVAILABLE) # Override the global flat_namespace for this library. cudaq-common doesn'\''t need diff --git a/scripts/ci/build_cudaq_wheel.sh b/scripts/ci/build_cudaq_wheel.sh index cad15727..837732e6 100644 --- a/scripts/ci/build_cudaq_wheel.sh +++ b/scripts/ci/build_cudaq_wheel.sh @@ -120,7 +120,7 @@ diff --git a/runtime/common/CMakeLists.txt b/runtime/common/CMakeLists.txt target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr ZLIB::ZLIB) else() - target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr -Wl,--start-group ZLIB::ZLIB) -+ target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr dl -Wl,--start-group ZLIB::ZLIB) ++ target_link_libraries(${LIBRARY_NAME} PRIVATE cpr::cpr -Wl,--start-group ZLIB::ZLIB ${CMAKE_DL_LIBS}) endif() target_compile_definitions(${LIBRARY_NAME} PRIVATE -DCUDAQ_RESTCLIENT_AVAILABLE) # Override the global flat_namespace for this library. cudaq-common doesn'\''t need