From 87308bf268e614d537f96dd6bc57df7be89c6d4b Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Sat, 14 Jun 2025 16:15:42 +0200 Subject: [PATCH 01/13] Fixed debian package CI get version step --- .github/workflows/build-deb.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-deb.yml b/.github/workflows/build-deb.yml index 53b7084a9..ef3a927a0 100644 --- a/.github/workflows/build-deb.yml +++ b/.github/workflows/build-deb.yml @@ -28,12 +28,12 @@ jobs: - name: Set version based on ref if: ${{ !inputs.version }} run: | - mkdir -p cpr/build - pushd cpr/build + mkdir -p build + pushd build cmake .. -DCPR_BUILD_VERSION_OUTPUT_ONLY=ON -DCPR_USE_SYSTEM_LIB_PSL=ON -DCPR_USE_SYSTEM_CURL=ON echo "RELEASE_VERSION=$(cat version.txt)" >> $GITHUB_ENV popd - rm -rf cpr/build + rm -rf build - name: Print Version run: echo "deb version will be '${{ env.RELEASE_VERSION }}'" # Build package of runtime library From ab19bc7e95c07d127bd6fda8572ee8d29027a682 Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Sat, 14 Jun 2025 16:19:57 +0200 Subject: [PATCH 02/13] Fixed build debian package CI version input description --- .github/workflows/build-deb.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-deb.yml b/.github/workflows/build-deb.yml index ef3a927a0..ddaf0801a 100644 --- a/.github/workflows/build-deb.yml +++ b/.github/workflows/build-deb.yml @@ -5,7 +5,7 @@ on: workflow_dispatch: inputs: version: - description: 'The optional semantic version number. If not supplied the branch/tag will be used.' + description: 'The optional semantic version number. If not supplied the version from the main cpr CMake project will be used.' type: string jobs: From 3e5d7146da8f77c3f88fad8dd81c24af8b009992 Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Sat, 14 Jun 2025 16:29:18 +0200 Subject: [PATCH 03/13] Fixed deb package path --- .github/workflows/build-deb.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-deb.yml b/.github/workflows/build-deb.yml index ddaf0801a..1078552a6 100644 --- a/.github/workflows/build-deb.yml +++ b/.github/workflows/build-deb.yml @@ -40,7 +40,7 @@ jobs: - name: "Package build of runtime library" env: VERSION: ${{ env.RELEASE_VERSION }} - run: bash cpr/package-build/build-package.sh cpr + run: bash package-build/build-package.sh $(pwd) - name: "Upload deb-packages" uses: actions/upload-artifact@v4 From c68b8e1f933a1dfd6844f293cb26ed20b39354d1 Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Sat, 14 Jun 2025 16:57:50 +0200 Subject: [PATCH 04/13] Write a meson cross compilation file Write a meson cross compilation file to allow cross compiling for example for building NuGet packages although usually it is not required. --- cmake/libpsl.cmake | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cmake/libpsl.cmake b/cmake/libpsl.cmake index 380bcb586..52e79412b 100644 --- a/cmake/libpsl.cmake +++ b/cmake/libpsl.cmake @@ -17,6 +17,35 @@ set(LIBPSL_BUILD_DIR "${libpsl_src_BINARY_DIR}") set(LIBPSL_INSTALL_DIR "${CMAKE_BINARY_DIR}/libpsl_src-install") file(MAKE_DIRECTORY "${LIBPSL_BUILD_DIR}") +string(TOLOWER "${CMAKE_SYSTEM_NAME}" HOST_SYSTEM_NAME) +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64)$") + set(HOST_CPU_FAMILY "x86_64") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86)$") + set(HOST_CPU_FAMILY "x86") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv7|armv6|arm)$") + set(HOST_CPU_FAMILY "arm") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)$") + set(HOST_CPU_FAMILY "aarch64") +else() + set(HOST_CPU_FAMILY "${CMAKE_SYSTEM_PROCESSOR}") +endif() + +# Write a meson cross compilation file to allow cross compiling +# for example for building NuGet packages although usually it is not required. +file(WRITE "${CMAKE_BINARY_DIR}/libpsl-meson-cross.txt" " +[binaries] +c = '${CMAKE_C_COMPILER}' +cpp = '${CMAKE_CXX_COMPILER}' +ar = '${CMAKE_AR}' +strip = '${CMAKE_STRIP}' + +[host_machine] +system = '${HOST_SYSTEM_NAME}' +cpu_family = '${HOST_CPU_FAMILY}' +cpu = '${CMAKE_SYSTEM_PROCESSOR}' +endian = 'little' +") + # Meson configure # We only care about static libraries of psl. In case you need a dynamic version, feel free to add support for it. message(STATUS "Configuring libpsl...") @@ -25,6 +54,7 @@ execute_process(COMMAND "${MESON_PATH}" setup "${LIBPSL_SOURCE_DIR}" -Dtests=false -Ddocs=false + --cross-file "${CMAKE_BINARY_DIR}/libpsl-meson-cross.txt" --buildtype=release --prefix "${LIBPSL_INSTALL_DIR}" --default-library=static From fecd27e2724c73bdd7698ac53359fbeb7ff76561 Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Sat, 28 Jun 2025 17:28:58 +0200 Subject: [PATCH 05/13] NuGet cross compilation --- .github/workflows/build-nuget.yml | 104 +++++++++++++----------------- cmake/libpsl.cmake | 59 +++++++++++------ nuget/build/native/libcpr.props | 5 +- nuget/build/native/libcpr.targets | 7 +- 4 files changed, 92 insertions(+), 83 deletions(-) diff --git a/.github/workflows/build-nuget.yml b/.github/workflows/build-nuget.yml index 2b001c3b2..c2c16807c 100644 --- a/.github/workflows/build-nuget.yml +++ b/.github/workflows/build-nuget.yml @@ -1,3 +1,8 @@ +# Let me start of with "I (COM8) hate Windows!"... +# How can it be easier to cross compile on Linux via mingw for Windows X86 and X86_64 than natively on Windows. +# I spend hours and hours trying to get the cross compilation and linker flags correct on Windows while battling the awfully slow Windows file system. +# At one point I gave up and I had mingw build up and running in less than an hour - that irony :) + name: Build NuGet Package on: push: @@ -13,103 +18,86 @@ on: default: false jobs: - package-windows-latest: - runs-on: windows-2019 + package-nuget: + runs-on: ubuntu-latest + container: fedora:latest steps: - name: Set version based on input if: ${{ inputs.version }} - run: echo "RELEASE_VERSION=${{ inputs.version }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + run: echo "RELEASE_VERSION=${{ inputs.version }}" >> "$GITHUB_ENV" - name: Set version based on ref if: ${{ !inputs.version }} - run: echo "RELEASE_VERSION=$($env:GITHUB_REF -replace 'refs/.*/', '')" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> "$GITHUB_ENV" - name: Print Version - run: echo "NuGet version will be '${{ env.RELEASE_VERSION }}'" + run: echo "NuGet version will be '${{env.RELEASE_VERSION}}'" - name: Checkout uses: actions/checkout@v3 - - name: Setup NuGet.exe - uses: nuget/setup-nuget@v2 - - name: Install meson - run: pip install meson + - name: Prepare NuGet Output Directory + run: | + mkdir -p ${{github.workspace}} + # Note: {{github.workspace}} expands to outside the container while GITHUB_WORKSPACE is inside the container + cp -r $GITHUB_WORKSPACE/nuget ${{github.workspace}} + cp $GITHUB_WORKSPACE/README.md ${{github.workspace}}/nuget + mkdir -p ${{github.workspace}}/nuget/build/native/{x86,x64}/{Debug,Release} + - name: Install Dependencies + run: | + dnf install -y mingw32-gcc mingw64-gcc mingw32-gcc-c++ mingw64-gcc-c++ mingw32-binutils mingw64-binutils mingw32-winpthreads mingw64-winpthreads wine meson cmake git nuget mono-complete + nuget update -self - name: "[Release_x86] Build & Install" - env: - CMAKE_GENERATOR: "Visual Studio 16 2019" uses: ashutoshvarma/action-cmake-build@master with: - build-dir: ${{github.workspace}}/build + build-dir: ${{github.workspace}}/build-release-x86 source-dir: ${{github.workspace}} build-type: Release - target: ALL_BUILD run-test: false - configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -A Win32 + configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_PROCESSOR=i686 install-build: true - install-options: --prefix ${{github.workspace}}\install --config Release - - name: "[Release_x86] Copy install files for Release_x86" - run: xcopy /e /i /y ${{github.workspace}}\install ${{github.workspace}}\nuget\build\native\x86\Release && xcopy /e /i /y ${{github.workspace}}\install ${{github.workspace}}\nuget\build\native\Win32\Release - - name: "[Release_x86] Clean build" - run: rm -r -fo ${{github.workspace}}/build + install-options: --prefix ${{github.workspace}}/nuget/build/native/x86/Release --config Release - name: "[Debug_x86] Build & Install" - env: - CMAKE_GENERATOR: "Visual Studio 16 2019" uses: ashutoshvarma/action-cmake-build@master with: - build-dir: ${{github.workspace}}/build + build-dir: ${{github.workspace}}/build-debug-x86 source-dir: ${{github.workspace}} build-type: Debug - target: ALL_BUILD run-test: false - configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -A Win32 + configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_PROCESSOR=i686 install-build: true - install-options: --prefix ${{github.workspace}}\install --config Debug - - name: "[Debug_x86] Copy install files for Debug_x86" - run: xcopy /e /i /y ${{github.workspace}}\install ${{github.workspace}}\nuget\build\native\x86\Debug && xcopy /e /i /y ${{github.workspace}}\install ${{github.workspace}}\nuget\build\native\Win32\Debug - - name: "[Debug_x86] Clean build" - run: rm -r -fo ${{github.workspace}}/build + install-options: --prefix ${{github.workspace}}/nuget/build/native/x86/Debug --config Debug - name: "[Release_x64] Build & Install" - env: - CMAKE_GENERATOR: "Visual Studio 16 2019" uses: ashutoshvarma/action-cmake-build@master with: - build-dir: ${{github.workspace}}/build + build-dir: ${{github.workspace}}/build-release-x64 source-dir: ${{github.workspace}} build-type: Release - target: ALL_BUILD run-test: false - configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -A x64 + configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_PROCESSOR=x86_64 install-build: true - install-options: --prefix ${{github.workspace}}\install --config Release - - name: "[Release_x64] Copy install files for Release_x64" - run: xcopy /e /i /y ${{github.workspace}}\install ${{github.workspace}}\nuget\build\native\x64\Release - - name: "[Release_x64] Clean build" - run: rm -r -fo ${{github.workspace}}/build + install-options: --prefix ${{github.workspace}}/nuget/build/native/x64/Release --config Release - name: "[Debug_x64] Build & Install" - env: - CMAKE_GENERATOR: "Visual Studio 16 2019" uses: ashutoshvarma/action-cmake-build@master with: - build-dir: ${{github.workspace}}/build + build-dir: ${{github.workspace}}/build-debug-x64 source-dir: ${{github.workspace}} build-type: Debug - target: ALL_BUILD run-test: false - configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -A x64 + configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_PROCESSOR=x86_64 install-build: true - install-options: --prefix ${{github.workspace}}\install --config Debug - - name: "[Debug_x64] Copy install files for Debug_x64" - run: xcopy /e /i /y ${{github.workspace}}\install ${{github.workspace}}\nuget\build\native\x64\Debug - - name: "Copy Readme.md" - run: xcopy /y ${{github.workspace}}\README.md ${{github.workspace}}\nuget + install-options: --prefix ${{github.workspace}}/nuget/build/native/x64/Debug --config Debug - name: "Create NuGet package" env: - VERSION: ${{ env.RELEASE_VERSION }} - COMMIT_HASH: ${{ github.sha }} - run: nuget pack ${{github.workspace}}\nuget\libcpr.nuspec -OutputDirectory ${{github.workspace}} -Properties "VERSION=$ENV:VERSION;COMMIT_HASH=$ENV:COMMIT_HASH" + VERSION: ${{env.RELEASE_VERSION}} + COMMIT_HASH: ${{github.sha}} + run: | + nuget pack ${{github.workspace}}/nuget/libcpr.nuspec -OutputDirectory ${{github.workspace}} -Properties "VERSION=${VERSION};COMMIT_HASH=${COMMIT_HASH}" + # Copy result to outside the container + cp ${{github.workspace}}/*.nupkg $GITHUB_WORKSPACE + - name: "Publish package to NuGet.org" + if: ${{ !inputs.no_publish }} + env: + NUGET_API_KEY: ${{secrets.NUGET_API_KEY}} + run: nuget push ${{github.workspace}}/*.nupkg ${NUGET_API_KEY} -Source https://api.nuget.org/v3/index.json - name: "Upload artifact" uses: actions/upload-artifact@v4 with: name: artifact-nuget - path: ${{github.workspace}}\*.nupkg - - name: "Publish package to NuGet.org" - if: ${{ !inputs.no_publish }} - env: - NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} - run: nuget push ${{github.workspace}}\*.nupkg $ENV:NUGET_API_KEY -Source https://api.nuget.org/v3/index.json + path: ${{github.workspace}}/*.nupkg diff --git a/cmake/libpsl.cmake b/cmake/libpsl.cmake index 52e79412b..5d5523367 100644 --- a/cmake/libpsl.cmake +++ b/cmake/libpsl.cmake @@ -17,33 +17,46 @@ set(LIBPSL_BUILD_DIR "${libpsl_src_BINARY_DIR}") set(LIBPSL_INSTALL_DIR "${CMAKE_BINARY_DIR}/libpsl_src-install") file(MAKE_DIRECTORY "${LIBPSL_BUILD_DIR}") -string(TOLOWER "${CMAKE_SYSTEM_NAME}" HOST_SYSTEM_NAME) -if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64)$") - set(HOST_CPU_FAMILY "x86_64") -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86)$") - set(HOST_CPU_FAMILY "x86") -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv7|armv6|arm)$") - set(HOST_CPU_FAMILY "arm") -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)$") - set(HOST_CPU_FAMILY "aarch64") +string(TOLOWER "${CMAKE_SYSTEM_NAME}" MESON_TARGET_HOST_SYSTEM_NAME) +string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" MESON_TARGET_SYSTEM_PROCESSOR_LOWER) +if(MESON_TARGET_SYSTEM_PROCESSOR_LOWER MATCHES "^(x86_64|amd64)$") + set(MESON_TARGET_HOST_CPU_FAMILY "x86_64") +elseif(MESON_TARGET_SYSTEM_PROCESSOR_LOWER MATCHES "^(i.86|x86)$") + set(MESON_TARGET_HOST_CPU_FAMILY "x86") +elseif(MESON_TARGET_SYSTEM_PROCESSOR_LOWER MATCHES "^(armv7|armv6|arm)$") + set(MESON_TARGET_HOST_CPU_FAMILY "arm") +elseif(MESON_TARGET_SYSTEM_PROCESSOR_LOWER MATCHES "^(aarch64|arm64)$") + set(MESON_TARGET_HOST_CPU_FAMILY "aarch64") else() - set(HOST_CPU_FAMILY "${CMAKE_SYSTEM_PROCESSOR}") + set(MESON_TARGET_HOST_CPU_FAMILY "${MESON_TARGET_SYSTEM_PROCESSOR_LOWER}") +endif() + +include (TestBigEndian) +TEST_BIG_ENDIAN(IS_BIG_ENDIAN) +if(IS_BIG_ENDIAN) + set(MESON_ENDIAN "big") +else() + set(MESON_ENDIAN "little") +endif() + +# libpsl is plain C. Make sure CMake initializes a C tool-chain. +if(NOT CMAKE_C_COMPILER) + enable_language(C) # initializes CMAKE_C_COMPILER, CMAKE_AR, … endif() # Write a meson cross compilation file to allow cross compiling # for example for building NuGet packages although usually it is not required. -file(WRITE "${CMAKE_BINARY_DIR}/libpsl-meson-cross.txt" " -[binaries] +file(WRITE "${CMAKE_BINARY_DIR}/libpsl-meson-cross.txt" "[binaries] c = '${CMAKE_C_COMPILER}' cpp = '${CMAKE_CXX_COMPILER}' ar = '${CMAKE_AR}' strip = '${CMAKE_STRIP}' [host_machine] -system = '${HOST_SYSTEM_NAME}' -cpu_family = '${HOST_CPU_FAMILY}' -cpu = '${CMAKE_SYSTEM_PROCESSOR}' -endian = 'little' +system = '${MESON_TARGET_HOST_SYSTEM_NAME}' +cpu_family = '${MESON_TARGET_HOST_CPU_FAMILY}' +cpu = '${MESON_TARGET_HOST_CPU_FAMILY}' +endian = '${MESON_ENDIAN}' ") # Meson configure @@ -65,7 +78,7 @@ endif() # Meson build message(STATUS "Building libpsl...") -execute_process(COMMAND "${MESON_PATH}" compile -C "${LIBPSL_BUILD_DIR}" +execute_process(COMMAND "${MESON_PATH}" compile --verbose -C "${LIBPSL_BUILD_DIR}" RESULT_VARIABLE MESON_COMPILE_RC ) if(MESON_COMPILE_RC) @@ -80,10 +93,18 @@ if(MESON_INSTALL_RC) message(FATAL_ERROR "Meson install for libpsl failed!") endif() -list(APPEND CMAKE_LIBRARY_PATH "${LIBPSL_INSTALL_DIR}/lib64") -list(APPEND CMAKE_LIBRARY_PATH "${LIBPSL_INSTALL_DIR}/lib") list(APPEND CMAKE_INCLUDE_PATH "${LIBPSL_INSTALL_DIR}/include") +if(EXISTS "${LIBPSL_INSTALL_DIR}/lib64") + set(LIBPSL_LIBRARY "${LIBPSL_INSTALL_DIR}/lib/libpsl.a") + list(APPEND CMAKE_LIBRARY_PATH "${LIBPSL_INSTALL_DIR}/lib64") +else() + set(LIBPSL_LIBRARY "${LIBPSL_INSTALL_DIR}/lib/libpsl.a") + list(APPEND CMAKE_LIBRARY_PATH "${LIBPSL_INSTALL_DIR}/lib") +endif() + +set(LIBPSL_INCLUDE_DIR "${LIBPSL_INSTALL_DIR}/include") + # Workaround for Windows compilation. # Ref: https://github.com/microsoft/vcpkg/pull/38847/files#diff-922fe829582a7e5acf5b0c35181daa63064fc12a2c889c5d89a19e5e02113f1bL44 add_compile_definitions(PSL_STATIC=1) diff --git a/nuget/build/native/libcpr.props b/nuget/build/native/libcpr.props index ea6c69547..4ffa169f9 100644 --- a/nuget/build/native/libcpr.props +++ b/nuget/build/native/libcpr.props @@ -1,12 +1,11 @@ - + mdd md - + diff --git a/nuget/build/native/libcpr.targets b/nuget/build/native/libcpr.targets index 01248913f..b1e1bc189 100644 --- a/nuget/build/native/libcpr.targets +++ b/nuget/build/native/libcpr.targets @@ -1,7 +1,8 @@ - - - + + + From 7d8d657b4e39b33e032a2e9363296b4ac9bc1c7a Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Fri, 11 Jul 2025 20:19:13 +0200 Subject: [PATCH 06/13] Increased version to 1.12.1 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bfff7f81..6e79f354c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.15) -project(cpr VERSION 1.12.0 LANGUAGES CXX) +project(cpr VERSION 1.12.1 LANGUAGES CXX) math(EXPR cpr_VERSION_NUM "${cpr_VERSION_MAJOR} * 0x10000 + ${cpr_VERSION_MINOR} * 0x100 + ${cpr_VERSION_PATCH}" OUTPUT_FORMAT HEXADECIMAL) configure_file("${cpr_SOURCE_DIR}/cmake/cprver.h.in" "${cpr_BINARY_DIR}/cpr_generated_includes/cpr/cprver.h") From e5e0c09940e1b16f4193be5b6c4710017e1dac78 Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Fri, 11 Jul 2025 20:21:01 +0200 Subject: [PATCH 07/13] Removed meson debug output --- cmake/libpsl.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/libpsl.cmake b/cmake/libpsl.cmake index 5d5523367..eb8467d92 100644 --- a/cmake/libpsl.cmake +++ b/cmake/libpsl.cmake @@ -78,7 +78,7 @@ endif() # Meson build message(STATUS "Building libpsl...") -execute_process(COMMAND "${MESON_PATH}" compile --verbose -C "${LIBPSL_BUILD_DIR}" +execute_process(COMMAND "${MESON_PATH}" compile -C "${LIBPSL_BUILD_DIR}" RESULT_VARIABLE MESON_COMPILE_RC ) if(MESON_COMPILE_RC) From 347b3f74cbaf49ebd4582e76240dd976aa8f1ffc Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Sat, 12 Jul 2025 08:05:51 +0100 Subject: [PATCH 08/13] Switched back to a Windows based CI run for building NuGet packages --- .github/workflows/build-nuget.yml | 161 ++++++++++++++++-------------- 1 file changed, 84 insertions(+), 77 deletions(-) diff --git a/.github/workflows/build-nuget.yml b/.github/workflows/build-nuget.yml index c2c16807c..3ac49d7f4 100644 --- a/.github/workflows/build-nuget.yml +++ b/.github/workflows/build-nuget.yml @@ -1,8 +1,3 @@ -# Let me start of with "I (COM8) hate Windows!"... -# How can it be easier to cross compile on Linux via mingw for Windows X86 and X86_64 than natively on Windows. -# I spend hours and hours trying to get the cross compilation and linker flags correct on Windows while battling the awfully slow Windows file system. -# At one point I gave up and I had mingw build up and running in less than an hour - that irony :) - name: Build NuGet Package on: push: @@ -19,85 +14,97 @@ on: jobs: package-nuget: - runs-on: ubuntu-latest - container: fedora:latest + runs-on: windows-latest + + # Use PowerShell everywhere unless a step overrides it. + defaults: + run: + shell: pwsh + steps: - - name: Set version based on input - if: ${{ inputs.version }} - run: echo "RELEASE_VERSION=${{ inputs.version }}" >> "$GITHUB_ENV" - - name: Set version based on ref - if: ${{ !inputs.version }} - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> "$GITHUB_ENV" - - name: Print Version - run: echo "NuGet version will be '${{env.RELEASE_VERSION}}'" - - name: Checkout - uses: actions/checkout@v3 - - name: Prepare NuGet Output Directory + # ────────────────────────────── Version handling ───────────────────────────── + - name: Set version from manual input + if: ${{ github.event_name == 'workflow_dispatch' && inputs.version != '' }} run: | - mkdir -p ${{github.workspace}} - # Note: {{github.workspace}} expands to outside the container while GITHUB_WORKSPACE is inside the container - cp -r $GITHUB_WORKSPACE/nuget ${{github.workspace}} - cp $GITHUB_WORKSPACE/README.md ${{github.workspace}}/nuget - mkdir -p ${{github.workspace}}/nuget/build/native/{x86,x64}/{Debug,Release} - - name: Install Dependencies - run: | - dnf install -y mingw32-gcc mingw64-gcc mingw32-gcc-c++ mingw64-gcc-c++ mingw32-binutils mingw64-binutils mingw32-winpthreads mingw64-winpthreads wine meson cmake git nuget mono-complete - nuget update -self - - name: "[Release_x86] Build & Install" - uses: ashutoshvarma/action-cmake-build@master - with: - build-dir: ${{github.workspace}}/build-release-x86 - source-dir: ${{github.workspace}} - build-type: Release - run-test: false - configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_PROCESSOR=i686 - install-build: true - install-options: --prefix ${{github.workspace}}/nuget/build/native/x86/Release --config Release - - name: "[Debug_x86] Build & Install" - uses: ashutoshvarma/action-cmake-build@master - with: - build-dir: ${{github.workspace}}/build-debug-x86 - source-dir: ${{github.workspace}} - build-type: Debug - run-test: false - configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_PROCESSOR=i686 - install-build: true - install-options: --prefix ${{github.workspace}}/nuget/build/native/x86/Debug --config Debug - - name: "[Release_x64] Build & Install" - uses: ashutoshvarma/action-cmake-build@master + "RELEASE_VERSION=${{ inputs.version }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + + - name: Set version from Git ref + if: ${{ env.RELEASE_VERSION == '' }} + run: | + $ref = "${{ github.ref }}".Split('/')[-1] + "RELEASE_VERSION=$ref" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + + - name: Print version + run: Write-Host "NuGet package version will be '$env:RELEASE_VERSION'." + + # ───────────────────────────── Repository & tools ──────────────────────────── + - uses: actions/checkout@v4 + + # Add MSBuild (and the full VS developer environment) to PATH + - uses: microsoft/setup-msbuild@v2 + + - uses: actions/setup-python@v5 + + - name: Install meson + run: pip install meson + + # Prepare output folder paths + - name: Prepare NuGet output layout + shell: bash + run: | + set -eux + mkdir -p "$GITHUB_WORKSPACE/nuget/build/native/{x86,x64}/{Debug,Release}" + cp README.md "$GITHUB_WORKSPACE/nuget" + + # ─────────────────────────────── Build x86 ───────────────────────────────── + - name: Enable MSVC x86 toolchain + uses: ilammy/msvc-dev-cmd@v1 with: - build-dir: ${{github.workspace}}/build-release-x64 - source-dir: ${{github.workspace}} - build-type: Release - run-test: false - configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_PROCESSOR=x86_64 - install-build: true - install-options: --prefix ${{github.workspace}}/nuget/build/native/x64/Release --config Release - - name: "[Debug_x64] Build & Install" - uses: ashutoshvarma/action-cmake-build@master + arch: x86 + + - name: Configure & build Release_x86 + run: | + cmake -S . -B build-release-x86 -G "Visual Studio 17 2022" -A Win32 -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x86/Release" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF + cmake --build build-release-x86 --config Release --target install + + - name: Configure & build Debug_x86 + run: | + cmake -S . -B build-debug-x86 -G "Visual Studio 17 2022" -A Win32 ` -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x86/Debug" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF + cmake --build build-debug-x86 --config Debug --target install + + # ─────────────────────────────── Build x64 ───────────────────────────────── + - name: Enable MSVC x64 toolchain + uses: ilammy/msvc-dev-cmd@v1 with: - build-dir: ${{github.workspace}}/build-debug-x64 - source-dir: ${{github.workspace}} - build-type: Debug - run-test: false - configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_PROCESSOR=x86_64 - install-build: true - install-options: --prefix ${{github.workspace}}/nuget/build/native/x64/Debug --config Debug - - name: "Create NuGet package" - env: - VERSION: ${{env.RELEASE_VERSION}} - COMMIT_HASH: ${{github.sha}} + arch: x64 + + - name: Configure & build Release_x64 + run: | + cmake -S . -B build-release-x64 -G "Visual Studio 17 2022" -A x64 -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x64/Release" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF + cmake --build build-release-x64 --config Release --target install + + - name: Configure & build Debug_x64 + run: | + cmake -S . -B build-debug-x64 -G "Visual Studio 17 2022" -A x64 -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x64/Debug" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF + cmake --build build-debug-x64 --config Debug --target install + + # ────────────────────────── Pack, push, artefact ───────────────────────────── + - name: Create NuGet package + env: + VERSION: ${{ env.RELEASE_VERSION }} + COMMIT_HASH: ${{ github.sha }} run: | - nuget pack ${{github.workspace}}/nuget/libcpr.nuspec -OutputDirectory ${{github.workspace}} -Properties "VERSION=${VERSION};COMMIT_HASH=${COMMIT_HASH}" - # Copy result to outside the container - cp ${{github.workspace}}/*.nupkg $GITHUB_WORKSPACE - - name: "Publish package to NuGet.org" + nuget pack "$env:GITHUB_WORKSPACE/nuget/libcpr.nuspec" -OutputDirectory "$env:GITHUB_WORKSPACE" -Properties "VERSION=$env:VERSION;COMMIT_HASH=$env:COMMIT_HASH" + + - name: Publish package to NuGet.org if: ${{ !inputs.no_publish }} env: - NUGET_API_KEY: ${{secrets.NUGET_API_KEY}} - run: nuget push ${{github.workspace}}/*.nupkg ${NUGET_API_KEY} -Source https://api.nuget.org/v3/index.json - - name: "Upload artifact" + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + run: | + nuget push "$env:GITHUB_WORKSPACE\*.nupkg" $env:NUGET_API_KEY -Source https://api.nuget.org/v3/index.json + + - name: Upload built .nupkg as workflow artefact uses: actions/upload-artifact@v4 with: name: artifact-nuget - path: ${{github.workspace}}/*.nupkg + path: '*.nupkg' From 454287dad54812691b1aeec76f6f5c81a58cbf0d Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Sat, 12 Jul 2025 08:19:16 +0100 Subject: [PATCH 09/13] Correctly setting the meson build type --- cmake/libpsl.cmake | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmake/libpsl.cmake b/cmake/libpsl.cmake index eb8467d92..0041a116a 100644 --- a/cmake/libpsl.cmake +++ b/cmake/libpsl.cmake @@ -31,6 +31,14 @@ else() set(MESON_TARGET_HOST_CPU_FAMILY "${MESON_TARGET_SYSTEM_PROCESSOR_LOWER}") endif() +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(MESON_BUILD_TYPE debug) +elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + set(MESON_BUILD_TYPE debugoptimized) +else() + set(MESON_BUILD_TYPE release) +endif() + include (TestBigEndian) TEST_BIG_ENDIAN(IS_BIG_ENDIAN) if(IS_BIG_ENDIAN) @@ -68,7 +76,7 @@ execute_process(COMMAND "${MESON_PATH}" setup -Dtests=false -Ddocs=false --cross-file "${CMAKE_BINARY_DIR}/libpsl-meson-cross.txt" - --buildtype=release + --buildtype=${MESON_BUILD_TYPE} --prefix "${LIBPSL_INSTALL_DIR}" --default-library=static RESULT_VARIABLE MESON_SETUP_RC) From 7e26da6383dd4bb9f64b66db8cd360f51f8abfee Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Sat, 12 Jul 2025 08:21:34 +0100 Subject: [PATCH 10/13] Correctly setting the release version for non published builds --- .github/workflows/build-nuget.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build-nuget.yml b/.github/workflows/build-nuget.yml index 3ac49d7f4..0832a686e 100644 --- a/.github/workflows/build-nuget.yml +++ b/.github/workflows/build-nuget.yml @@ -91,10 +91,9 @@ jobs: # ────────────────────────── Pack, push, artefact ───────────────────────────── - name: Create NuGet package env: - VERSION: ${{ env.RELEASE_VERSION }} COMMIT_HASH: ${{ github.sha }} run: | - nuget pack "$env:GITHUB_WORKSPACE/nuget/libcpr.nuspec" -OutputDirectory "$env:GITHUB_WORKSPACE" -Properties "VERSION=$env:VERSION;COMMIT_HASH=$env:COMMIT_HASH" + nuget pack "$env:GITHUB_WORKSPACE/nuget/libcpr.nuspec" -OutputDirectory "$env:GITHUB_WORKSPACE" -Properties "VERSION=$env:RELEASE_VERSION;COMMIT_HASH=$env:COMMIT_HASH" - name: Publish package to NuGet.org if: ${{ !inputs.no_publish }} From df6788494f764888b7df3591f97617042f6917cb Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Sat, 12 Jul 2025 09:01:22 +0100 Subject: [PATCH 11/13] skip ci [skip ci] --- .github/workflows/build-nuget.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-nuget.yml b/.github/workflows/build-nuget.yml index 0832a686e..888e903e9 100644 --- a/.github/workflows/build-nuget.yml +++ b/.github/workflows/build-nuget.yml @@ -64,12 +64,12 @@ jobs: - name: Configure & build Release_x86 run: | - cmake -S . -B build-release-x86 -G "Visual Studio 17 2022" -A Win32 -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x86/Release" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF + cmake -S . -B build-release-x86 -G "Visual Studio 17 2022" -A Win32 -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x86/Release" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_BUILD_TYPE=Release cmake --build build-release-x86 --config Release --target install - name: Configure & build Debug_x86 run: | - cmake -S . -B build-debug-x86 -G "Visual Studio 17 2022" -A Win32 ` -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x86/Debug" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF + cmake -S . -B build-debug-x86 -G "Visual Studio 17 2022" -A Win32 ` -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x86/Debug" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_BUILD_TYPE=Debug cmake --build build-debug-x86 --config Debug --target install # ─────────────────────────────── Build x64 ───────────────────────────────── @@ -80,12 +80,12 @@ jobs: - name: Configure & build Release_x64 run: | - cmake -S . -B build-release-x64 -G "Visual Studio 17 2022" -A x64 -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x64/Release" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF + cmake -S . -B build-release-x64 -G "Visual Studio 17 2022" -A x64 -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x64/Release" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_BUILD_TYPE=Release cmake --build build-release-x64 --config Release --target install - name: Configure & build Debug_x64 run: | - cmake -S . -B build-debug-x64 -G "Visual Studio 17 2022" -A x64 -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x64/Debug" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF + cmake -S . -B build-debug-x64 -G "Visual Studio 17 2022" -A x64 -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x64/Debug" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_BUILD_TYPE=Debug cmake --build build-debug-x64 --config Debug --target install # ────────────────────────── Pack, push, artefact ───────────────────────────── From 5ca64d0bd5f156f7093c3a684139da08c86f0cb4 Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Sat, 12 Jul 2025 10:17:47 +0100 Subject: [PATCH 12/13] skip ci [skip ci] --- .github/workflows/build-nuget.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-nuget.yml b/.github/workflows/build-nuget.yml index 888e903e9..8561b0294 100644 --- a/.github/workflows/build-nuget.yml +++ b/.github/workflows/build-nuget.yml @@ -14,7 +14,7 @@ on: jobs: package-nuget: - runs-on: windows-latest + runs-on: windows-2022 # Use PowerShell everywhere unless a step overrides it. defaults: @@ -62,15 +62,15 @@ jobs: with: arch: x86 - - name: Configure & build Release_x86 + - name: Configure & build Release x86 run: | cmake -S . -B build-release-x86 -G "Visual Studio 17 2022" -A Win32 -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x86/Release" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_BUILD_TYPE=Release - cmake --build build-release-x86 --config Release --target install + cmake --build build-release-x86 --target install - - name: Configure & build Debug_x86 + - name: Configure & build Debug x86 run: | - cmake -S . -B build-debug-x86 -G "Visual Studio 17 2022" -A Win32 ` -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x86/Debug" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_BUILD_TYPE=Debug - cmake --build build-debug-x86 --config Debug --target install + cmake -S . -B build-debug-x86 -G "Visual Studio 17 2022" -A Win32 -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x86/Debug" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_BUILD_TYPE=Debug + cmake --build build-debug-x86 --target install # ─────────────────────────────── Build x64 ───────────────────────────────── - name: Enable MSVC x64 toolchain @@ -78,15 +78,15 @@ jobs: with: arch: x64 - - name: Configure & build Release_x64 + - name: Configure & build Release x64 run: | cmake -S . -B build-release-x64 -G "Visual Studio 17 2022" -A x64 -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x64/Release" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_BUILD_TYPE=Release - cmake --build build-release-x64 --config Release --target install + cmake --build build-release-x64 --target install - - name: Configure & build Debug_x64 + - name: Configure & build Debug x64 run: | cmake -S . -B build-debug-x64 -G "Visual Studio 17 2022" -A x64 -DCMAKE_INSTALL_PREFIX="$env:GITHUB_WORKSPACE/nuget/build/native/x64/Debug" -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -DCMAKE_BUILD_TYPE=Debug - cmake --build build-debug-x64 --config Debug --target install + cmake --build build-debug-x64 --target install # ────────────────────────── Pack, push, artefact ───────────────────────────── - name: Create NuGet package From 9c49b637f92217ffb444eaffc8bf422aa1cafe90 Mon Sep 17 00:00:00 2001 From: Fabian Sauter Date: Sat, 12 Jul 2025 10:18:51 +0100 Subject: [PATCH 13/13] skip ci [skip ci] --- .github/workflows/build-nuget.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-nuget.yml b/.github/workflows/build-nuget.yml index 8561b0294..62dbc9d5a 100644 --- a/.github/workflows/build-nuget.yml +++ b/.github/workflows/build-nuget.yml @@ -40,9 +40,6 @@ jobs: # ───────────────────────────── Repository & tools ──────────────────────────── - uses: actions/checkout@v4 - # Add MSBuild (and the full VS developer environment) to PATH - - uses: microsoft/setup-msbuild@v2 - - uses: actions/setup-python@v5 - name: Install meson @@ -92,15 +89,13 @@ jobs: - name: Create NuGet package env: COMMIT_HASH: ${{ github.sha }} - run: | - nuget pack "$env:GITHUB_WORKSPACE/nuget/libcpr.nuspec" -OutputDirectory "$env:GITHUB_WORKSPACE" -Properties "VERSION=$env:RELEASE_VERSION;COMMIT_HASH=$env:COMMIT_HASH" + run: nuget pack "$env:GITHUB_WORKSPACE/nuget/libcpr.nuspec" -OutputDirectory "$env:GITHUB_WORKSPACE" -Properties "VERSION=$env:RELEASE_VERSION;COMMIT_HASH=$env:COMMIT_HASH" - name: Publish package to NuGet.org if: ${{ !inputs.no_publish }} env: NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} - run: | - nuget push "$env:GITHUB_WORKSPACE\*.nupkg" $env:NUGET_API_KEY -Source https://api.nuget.org/v3/index.json + run: nuget push "$env:GITHUB_WORKSPACE\*.nupkg" $env:NUGET_API_KEY -Source https://api.nuget.org/v3/index.json - name: Upload built .nupkg as workflow artefact uses: actions/upload-artifact@v4