From 33f056a5a85c671792e3138fab690f0be758daf6 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sun, 22 Sep 2024 15:35:22 +0200 Subject: [PATCH 01/13] Fix dependency on correct pybind11-abi package and add test to check that the correct abi version is used --- recipe/meta.yaml | 16 ++++++++++++---- recipe/run_test.bat | 24 ++++++++++++++++++++++++ recipe/run_test.sh | 27 +++++++++++++++++++++++++++ recipe/test_abi/CMakeLists.txt | 7 +++++++ recipe/test_abi/test_abi.cpp | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 recipe/run_test.bat create mode 100644 recipe/run_test.sh create mode 100644 recipe/test_abi/CMakeLists.txt create mode 100644 recipe/test_abi/test_abi.cpp diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 201783a..19366b2 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -2,7 +2,10 @@ {% set sha256 = "e08cb87f4773da97fa7b5f035de8763abc656d87d5773e62f6da0587d1f0ec20" %} # this is set to PYBIND11_INTERNALS_VERSION -{% set abi_version = "4" %} +# since 2.12.0 pybind11 defines two ABI version. 4 and 5 for 3.12+ or msvc. +# https://github.com/pybind/pybind11/blob/v2.12.0/include/pybind11/detail/internals.h#L40 +{% set abi_version = "4" %} # [py<312 and not win] +{% set abi_version = "5" %} # [py>=312 or win] package: name: pybind11-split @@ -14,7 +17,7 @@ source: sha256: {{ sha256 }} build: - number: 0 + number: 1 requirements: build: @@ -33,8 +36,9 @@ outputs: source_files: - include/pybind11/detail/internals.h commands: - # make sure the internals version matches the package version - - if [ $(grep "#define PYBIND11_INTERNALS_VERSION" include/pybind11/detail/internals.h | cut -d' ' -f3) != "{{ abi_version }}" ]; then exit 1; fi + # the ABI version depends on both python version and operating system, so just check if the used version is one of the one defined in the header + - matched=false; while read -r version; do [ "$version" -eq "{{ abi_version }}" ] && { matched=true; break; }; done < <(awk '/define PYBIND11_INTERNALS_VERSION/{print $NF}' include/pybind11/detail/internals.h); [ "$matched" = true ] && exit 0 || exit 1 + - name: pybind11-global script: build-pybind11-global.sh # [unix] @@ -80,6 +84,10 @@ outputs: run_constrained: - pybind11-abi =={{ abi_version }} test: + script_env: + - PYBIND11_INTERNALS_VERSION={{ abi_version }} + files: + - test_abi imports: - pybind11 commands: diff --git a/recipe/run_test.bat b/recipe/run_test.bat new file mode 100644 index 0000000..caa8ca4 --- /dev/null +++ b/recipe/run_test.bat @@ -0,0 +1,24 @@ +cd test_abi + +REM Cleanup the build folder +rmdir /s /q build +if errorlevel 1 exit 1 + +REM Configure the project +cmake -GNinja -S. -Bbuild -DCMAKE_BUILD_TYPE=Release +if errorlevel 1 exit 1 + +REM Build the project and extract the line with PYBIND11_INTERNALS_VERSION= +for /F "tokens=*" %%i in ('cmake --build build ^| findstr /R /C:"^PYBIND11_INTERNALS_VERSION="') do set "line=%%i" +if errorlevel 1 exit 1 + +REM Extract the value after the equals sign in the line PYBIND11_INTERNALS_VERSION= +for /F "tokens=2 delims==" %%a in ("%line%") do set "version=%%a" + +REM Compare to the environment variable EXPECTED_PYBIND11_INTERNALS_VERSION +if "%version%"=="%EXPECTED_PYBIND11_INTERNALS_VERSION%" ( + echo Versions match. +) else ( + echo Error: PYBIND11_INTERNALS_VERSION version mismatch, compilation: "%version%" expected: "%EXPECTED_PYBIND11_INTERNALS_VERSION%" + exit 1 +) diff --git a/recipe/run_test.sh b/recipe/run_test.sh new file mode 100644 index 0000000..15d9659 --- /dev/null +++ b/recipe/run_test.sh @@ -0,0 +1,27 @@ +cd test_abi + +# Cleanup the build folder +rm -r ./build + +# Configure the project +cmake -GNinja -S. -Bbuild -DCMAKE_BUILD_TYPE=Release + +# Build the project and extract the line with PYBIND11_INTERNALS_VERSION= +line=$(cmake --build build | grep 'PYBIND11_INTERNALS_VERSION=') + +# Check if the line was found +if [ -z "$line" ]; then + echo "Error: PYBIND11_INTERNALS_VERSION not found." + exit 1 +fi + +# Extract the value after the equals sign +version=${line#PYBIND11_INTERNALS_VERSION=} + +# Compare to the environment variable EXPECTED_PYBIND11_INTERNALS_VERSION +if [ "$version" = "$EXPECTED_PYBIND11_INTERNALS_VERSION" ]; then + echo "Versions match." +else + echo "Error: Version mismatch - compilation: $version expected: $EXPECTED_PYBIND11_INTERNALS_VERSION" + exit 1 +fi diff --git a/recipe/test_abi/CMakeLists.txt b/recipe/test_abi/CMakeLists.txt new file mode 100644 index 0000000..289d826 --- /dev/null +++ b/recipe/test_abi/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required (VERSION 3.25) + +project(pybind11testabi) + +find_package(pybind11 REQUIRED) + +pybind11_add_module(test_abi_module test_abi.cpp) diff --git a/recipe/test_abi/test_abi.cpp b/recipe/test_abi/test_abi.cpp new file mode 100644 index 0000000..52cfe2d --- /dev/null +++ b/recipe/test_abi/test_abi.cpp @@ -0,0 +1,32 @@ +// Dummy module used only to print the PYBIND11_INTERNALS_VERSION version +// during the compilation process +#include + +#define STRINGIFY(x) #x +#define TO_STRING(x) STRINGIFY(x) + +#if defined(_MSC_VER) + // MSVC specific pragma + #pragma message ("PYBIND11_INTERNALS_VERSION=" TO_STRING(PYBIND11_INTERNALS_VERSION)) +#else + #pragma message "PYBIND11_INTERNALS_VERSION=" TO_STRING(PYBIND11_INTERNALS_VERSION) +#endif + +// The rest is just a copy of https://github.com/pybind/cmake_example/blob/7a94877f581a14de4de1a096fb053a55fc2a66bf/src/main.cpp +// to get a valid pybind11 module + +#include + +int add(int i, int j) { + return i + j; +} + +namespace py = pybind11; + +PYBIND11_MODULE(cmake_example, m) { + m.def("add", &add, R"pbdoc( + Add two numbers + + Some other explanation about the add function. + )pbdoc"); +} From f3ea806fcc162ca22b37e10b0af162b8fe8b96c3 Mon Sep 17 00:00:00 2001 From: "conda-forge-webservices[bot]" <91080706+conda-forge-webservices[bot]@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:38:39 +0000 Subject: [PATCH 02/13] MNT: Re-rendered with conda-build 24.7.1, conda-smithy 3.40.1, and conda-forge-pinning 2024.09.22.11.38.10 --- .scripts/build_steps.sh | 2 ++ .scripts/run_win_build.bat | 4 ++-- build-locally.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.scripts/build_steps.sh b/.scripts/build_steps.sh index ba4b251..856f469 100755 --- a/.scripts/build_steps.sh +++ b/.scripts/build_steps.sh @@ -43,6 +43,8 @@ setup_conda_rc "${FEEDSTOCK_ROOT}" "${RECIPE_ROOT}" "${CONFIG_FILE}" source run_conda_forge_build_setup + + # make the build number clobber make_build_number "${FEEDSTOCK_ROOT}" "${RECIPE_ROOT}" "${CONFIG_FILE}" diff --git a/.scripts/run_win_build.bat b/.scripts/run_win_build.bat index 65650bf..a45c34f 100755 --- a/.scripts/run_win_build.bat +++ b/.scripts/run_win_build.bat @@ -24,7 +24,7 @@ set "CONDA_LIBMAMBA_SOLVER_NO_CHANNELS_FROM_INSTALLED=1" :: Provision the necessary dependencies to build the recipe later echo Installing dependencies -mamba.exe install "python=3.10" pip mamba conda-build conda-forge-ci-setup=4 "conda-build>=24.1" -c conda-forge --strict-channel-priority --yes +mamba.exe install pip mamba conda-build conda-forge-ci-setup=4 "conda-build>=24.1" -c conda-forge --strict-channel-priority --yes if !errorlevel! neq 0 exit /b !errorlevel! :: Set basic configuration @@ -48,7 +48,7 @@ if NOT [%HOST_PLATFORM%] == [%BUILD_PLATFORM%] ( ) if NOT [%flow_run_id%] == [] ( - set "EXTRA_CB_OPTIONS=%EXTRA_CB_OPTIONS% --extra-meta flow_run_id=%flow_run_id% remote_url=%remote_url% sha=%sha%" + set "EXTRA_CB_OPTIONS=%EXTRA_CB_OPTIONS% --extra-meta flow_run_id=%flow_run_id% remote_url=%remote_url% sha=%sha%" ) call :end_group diff --git a/build-locally.py b/build-locally.py index 8ac9b84..6788aea 100755 --- a/build-locally.py +++ b/build-locally.py @@ -1,5 +1,5 @@ #!/bin/sh -"""exec' "python3" "$0" "$@" #""" # fmt: off # fmt: on +"""exec" "python3" "$0" "$@" #""" # fmt: off # fmt: on # # This file has been generated by conda-smithy in order to build the recipe # locally. From 3faacec97ce8ce6d3800f1071472c4d79921e96a Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sun, 22 Sep 2024 15:40:17 +0200 Subject: [PATCH 03/13] Update run_test.sh --- recipe/run_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipe/run_test.sh b/recipe/run_test.sh index 15d9659..c8a9ab5 100644 --- a/recipe/run_test.sh +++ b/recipe/run_test.sh @@ -20,7 +20,7 @@ version=${line#PYBIND11_INTERNALS_VERSION=} # Compare to the environment variable EXPECTED_PYBIND11_INTERNALS_VERSION if [ "$version" = "$EXPECTED_PYBIND11_INTERNALS_VERSION" ]; then - echo "Versions match." + echo "Versions match - compilation: $version expected: $EXPECTED_PYBIND11_INTERNALS_VERSION" else echo "Error: Version mismatch - compilation: $version expected: $EXPECTED_PYBIND11_INTERNALS_VERSION" exit 1 From 6d7c05fe95aa12fe96848ca279913544787d01b4 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sun, 22 Sep 2024 15:40:36 +0200 Subject: [PATCH 04/13] Update run_test.bat --- recipe/run_test.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipe/run_test.bat b/recipe/run_test.bat index caa8ca4..6de1b2b 100644 --- a/recipe/run_test.bat +++ b/recipe/run_test.bat @@ -17,7 +17,7 @@ for /F "tokens=2 delims==" %%a in ("%line%") do set "version=%%a" REM Compare to the environment variable EXPECTED_PYBIND11_INTERNALS_VERSION if "%version%"=="%EXPECTED_PYBIND11_INTERNALS_VERSION%" ( - echo Versions match. + echo Versions match, compilation: "%version%" expected: "%EXPECTED_PYBIND11_INTERNALS_VERSION%" ) else ( echo Error: PYBIND11_INTERNALS_VERSION version mismatch, compilation: "%version%" expected: "%EXPECTED_PYBIND11_INTERNALS_VERSION%" exit 1 From bd5779d584054068b7e1e2125fe0a87f1ff40253 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sun, 22 Sep 2024 15:49:32 +0200 Subject: [PATCH 05/13] Update meta.yaml --- recipe/meta.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 19366b2..186d8e7 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -97,6 +97,11 @@ outputs: - if exist %LIBRARY_INC%\pybind11\pybind11.h (exit 0) else (exit 1) # [win] - test -f $(python -c "import pybind11 as py; print(py.get_include())")/pybind11/pybind11.h # [unix] - if exist $(python -c "import pybind11 as py; print(py.get_include())")\pybind11\pybind11.h (exit 0) else (exit 1) # [win] + requires: + - cmake + - {{ compiler('c') }} + - {{ compiler('cxx') }} + - ninja about: home: https://github.com/pybind/pybind11/ From c784dff6d5d576ff0e744b3a5f930f572d6e37ae Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sun, 22 Sep 2024 15:53:02 +0200 Subject: [PATCH 06/13] Update meta.yaml --- recipe/meta.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 186d8e7..e3f4965 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -90,6 +90,8 @@ outputs: - test_abi imports: - pybind11 + script: run_test.bat # [win] + script: run_test.sh # [not win] commands: - test -f ${PREFIX}/share/cmake/pybind11/pybind11Config.cmake # [unix] - if exist %LIBRARY_PREFIX%\share\cmake\pybind11\pybind11Config.cmake (exit 0) else (exit 1) # [win] From c8893277cd586f951d15357db268672f7a968495 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sun, 22 Sep 2024 15:54:52 +0200 Subject: [PATCH 07/13] Fix names --- recipe/meta.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index e3f4965..cb90680 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -90,8 +90,8 @@ outputs: - test_abi imports: - pybind11 - script: run_test.bat # [win] - script: run_test.sh # [not win] + script: run-test-pybind11.sh # [unix] + script: run-test-pybind11.bat # [win] commands: - test -f ${PREFIX}/share/cmake/pybind11/pybind11Config.cmake # [unix] - if exist %LIBRARY_PREFIX%\share\cmake\pybind11\pybind11Config.cmake (exit 0) else (exit 1) # [win] From 83d2b8fc67a8720a35110ed830d10aeb2e0fb036 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sun, 22 Sep 2024 15:55:22 +0200 Subject: [PATCH 08/13] Update and rename run_test.bat to run-test-pybind11.bat --- recipe/{run_test.bat => run-test-pybind11.bat} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename recipe/{run_test.bat => run-test-pybind11.bat} (100%) diff --git a/recipe/run_test.bat b/recipe/run-test-pybind11.bat similarity index 100% rename from recipe/run_test.bat rename to recipe/run-test-pybind11.bat From 77fc18b505e375c62565b37d529e91778ecde476 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sun, 22 Sep 2024 15:55:39 +0200 Subject: [PATCH 09/13] Rename run_test.sh to run-test-pybind11.sh --- recipe/{run_test.sh => run-test-pybind11.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename recipe/{run_test.sh => run-test-pybind11.sh} (100%) diff --git a/recipe/run_test.sh b/recipe/run-test-pybind11.sh similarity index 100% rename from recipe/run_test.sh rename to recipe/run-test-pybind11.sh From 478431e5430dc2887fe41d928aa7cbc68732edb7 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sun, 22 Sep 2024 16:10:58 +0200 Subject: [PATCH 10/13] Fix --- recipe/meta.yaml | 2 +- recipe/run-test-pybind11.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index cb90680..1395e1e 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -85,7 +85,7 @@ outputs: - pybind11-abi =={{ abi_version }} test: script_env: - - PYBIND11_INTERNALS_VERSION={{ abi_version }} + - EXPECTED_PYBIND11_INTERNALS_VERSION={{ abi_version }} files: - test_abi imports: diff --git a/recipe/run-test-pybind11.sh b/recipe/run-test-pybind11.sh index c8a9ab5..5f47223 100644 --- a/recipe/run-test-pybind11.sh +++ b/recipe/run-test-pybind11.sh @@ -1,7 +1,7 @@ cd test_abi # Cleanup the build folder -rm -r ./build +rm -rf ./build # Configure the project cmake -GNinja -S. -Bbuild -DCMAKE_BUILD_TYPE=Release From 60e8fd6ae93e92af003dc332d8374abd826d1f25 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sun, 22 Sep 2024 16:30:32 +0200 Subject: [PATCH 11/13] Update run-test-pybind11.sh --- recipe/run-test-pybind11.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/recipe/run-test-pybind11.sh b/recipe/run-test-pybind11.sh index 5f47223..023ef48 100644 --- a/recipe/run-test-pybind11.sh +++ b/recipe/run-test-pybind11.sh @@ -1,5 +1,8 @@ cd test_abi +# Debug env variables +env + # Cleanup the build folder rm -rf ./build From 4f40d6060a7c6744cd7f65513df51e189a49a146 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sun, 22 Sep 2024 16:30:50 +0200 Subject: [PATCH 12/13] Update run-test-pybind11.bat --- recipe/run-test-pybind11.bat | 3 +++ 1 file changed, 3 insertions(+) diff --git a/recipe/run-test-pybind11.bat b/recipe/run-test-pybind11.bat index 6de1b2b..d9b91b5 100644 --- a/recipe/run-test-pybind11.bat +++ b/recipe/run-test-pybind11.bat @@ -1,5 +1,8 @@ cd test_abi +REM debug env variable +set + REM Cleanup the build folder rmdir /s /q build if errorlevel 1 exit 1 From 4ff61e072577a6e3d64eb330d72da9958e79edd2 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sun, 22 Sep 2024 16:38:20 +0200 Subject: [PATCH 13/13] Update meta.yaml --- recipe/meta.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 1395e1e..c3de525 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -66,6 +66,9 @@ outputs: - name: pybind11 script: build-pybind11.sh # [unix] script: build-pybind11.bat # [win] + build: + script_env: + - EXPECTED_PYBIND11_INTERNALS_VERSION={{ abi_version }} requirements: build: - python # [build_platform != target_platform] @@ -84,8 +87,6 @@ outputs: run_constrained: - pybind11-abi =={{ abi_version }} test: - script_env: - - EXPECTED_PYBIND11_INTERNALS_VERSION={{ abi_version }} files: - test_abi imports: