diff --git a/.github/workflows/build-deb.yml b/.github/workflows/build-deb.yml index 53b7084a9..1078552a6 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: @@ -28,19 +28,19 @@ 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 - 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 diff --git a/.github/workflows/build-nuget.yml b/.github/workflows/build-nuget.yml index 2b001c3b2..62dbc9d5a 100644 --- a/.github/workflows/build-nuget.yml +++ b/.github/workflows/build-nuget.yml @@ -13,103 +13,92 @@ on: default: false jobs: - package-windows-latest: - runs-on: windows-2019 + package-nuget: + runs-on: windows-2022 + + # 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 }}" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 - - 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 - - name: Print 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 + # ────────────────────────────── Version handling ───────────────────────────── + - name: Set version from manual input + if: ${{ github.event_name == 'workflow_dispatch' && inputs.version != '' }} + run: | + "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 + + - uses: actions/setup-python@v5 + - name: Install meson run: pip install meson - - name: "[Release_x86] Build & Install" - env: - CMAKE_GENERATOR: "Visual Studio 16 2019" - uses: ashutoshvarma/action-cmake-build@master - with: - build-dir: ${{github.workspace}}/build - source-dir: ${{github.workspace}} - build-type: Release - target: ALL_BUILD - run-test: false - configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -A Win32 - 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 - - name: "[Debug_x86] Build & Install" - env: - CMAKE_GENERATOR: "Visual Studio 16 2019" - uses: ashutoshvarma/action-cmake-build@master + + # 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 - source-dir: ${{github.workspace}} - build-type: Debug - target: ALL_BUILD - run-test: false - configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -A Win32 - 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 - - name: "[Release_x64] Build & Install" - env: - CMAKE_GENERATOR: "Visual Studio 16 2019" - 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 -DCMAKE_BUILD_TYPE=Release + cmake --build build-release-x86 --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 -DCMAKE_BUILD_TYPE=Debug + cmake --build build-debug-x86 --target install + + # ─────────────────────────────── Build x64 ───────────────────────────────── + - name: Enable MSVC x64 toolchain + uses: ilammy/msvc-dev-cmd@v1 with: - build-dir: ${{github.workspace}}/build - source-dir: ${{github.workspace}} - build-type: Release - target: ALL_BUILD - run-test: false - configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -A x64 - 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 - - name: "[Debug_x64] Build & Install" + 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 -DCMAKE_BUILD_TYPE=Release + cmake --build build-release-x64 --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 -DCMAKE_BUILD_TYPE=Debug + cmake --build build-debug-x64 --target install + + # ────────────────────────── Pack, push, artefact ───────────────────────────── + - name: Create NuGet package env: - CMAKE_GENERATOR: "Visual Studio 16 2019" - uses: ashutoshvarma/action-cmake-build@master - with: - build-dir: ${{github.workspace}}/build - source-dir: ${{github.workspace}} - build-type: Debug - target: ALL_BUILD - run-test: false - configure-options: -DBUILD_SHARED_LIBS=ON -DCURL_ZLIB=OFF -A x64 - 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 - - 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" - - name: "Upload artifact" - uses: actions/upload-artifact@v4 - with: - name: artifact-nuget - path: ${{github.workspace}}\*.nupkg - - name: "Publish package to NuGet.org" + 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 ${{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 + with: + name: artifact-nuget + path: '*.nupkg' 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") diff --git a/cmake/libpsl.cmake b/cmake/libpsl.cmake index 380bcb586..0041a116a 100644 --- a/cmake/libpsl.cmake +++ b/cmake/libpsl.cmake @@ -17,6 +17,56 @@ 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}" 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(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) + 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] +c = '${CMAKE_C_COMPILER}' +cpp = '${CMAKE_CXX_COMPILER}' +ar = '${CMAKE_AR}' +strip = '${CMAKE_STRIP}' + +[host_machine] +system = '${MESON_TARGET_HOST_SYSTEM_NAME}' +cpu_family = '${MESON_TARGET_HOST_CPU_FAMILY}' +cpu = '${MESON_TARGET_HOST_CPU_FAMILY}' +endian = '${MESON_ENDIAN}' +") + # 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,7 +75,8 @@ execute_process(COMMAND "${MESON_PATH}" setup "${LIBPSL_SOURCE_DIR}" -Dtests=false -Ddocs=false - --buildtype=release + --cross-file "${CMAKE_BINARY_DIR}/libpsl-meson-cross.txt" + --buildtype=${MESON_BUILD_TYPE} --prefix "${LIBPSL_INSTALL_DIR}" --default-library=static RESULT_VARIABLE MESON_SETUP_RC) @@ -50,10 +101,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 @@ - - - + + +