From c86fce2811b0952f9d7d9bba4a0abc0ea777b69e Mon Sep 17 00:00:00 2001 From: Max Lepikhin Date: Sun, 25 Oct 2026 17:31:47 -0600 Subject: [PATCH 1/3] edencommon: avoid unavailable pipe2 on macOS --- build/fbcode_builder/manifests/edencommon | 1 + .../patches/edencommon_pipe_darwin.patch | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 build/fbcode_builder/patches/edencommon_pipe_darwin.patch diff --git a/build/fbcode_builder/manifests/edencommon b/build/fbcode_builder/manifests/edencommon index d21bc13fcc691..c2806e2ba1d5e 100644 --- a/build/fbcode_builder/manifests/edencommon +++ b/build/fbcode_builder/manifests/edencommon @@ -9,6 +9,7 @@ repo_url = https://github.com/facebookexperimental/edencommon.git [build] builder = cmake +patchfile = edencommon_pipe_darwin.patch [dependencies] boost diff --git a/build/fbcode_builder/patches/edencommon_pipe_darwin.patch b/build/fbcode_builder/patches/edencommon_pipe_darwin.patch new file mode 100644 index 0000000000000..f06af5c6db70b --- /dev/null +++ b/build/fbcode_builder/patches/edencommon_pipe_darwin.patch @@ -0,0 +1,22 @@ +diff --git a/eden/common/utils/Pipe.cpp b/eden/common/utils/Pipe.cpp +index 1724dbd1..67e188b2 100644 +--- a/eden/common/utils/Pipe.cpp ++++ b/eden/common/utils/Pipe.cpp +@@ -43,7 +43,7 @@ Pipe::Pipe(bool nonBlocking) { + #else + int fds[2]; + int res; +-#if FOLLY_HAVE_PIPE2 ++#if FOLLY_HAVE_PIPE2 && !defined(__APPLE__) + res = pipe2(fds, (nonBlocking ? O_NONBLOCK : 0) | O_CLOEXEC); + #else + res = pipe(fds); +@@ -58,7 +58,7 @@ Pipe::Pipe(bool nonBlocking) { + read = FileDescriptor(fds[0], FileDescriptor::FDType::Pipe); + write = FileDescriptor(fds[1], FileDescriptor::FDType::Pipe); + +-#if !FOLLY_HAVE_PIPE2 ++#if !FOLLY_HAVE_PIPE2 || defined(__APPLE__) + read.setCloExec(); + write.setCloExec(); + if (nonBlocking) { From 761ee1f33f5c18599c0371a95ac3dbe8d5c91131 Mon Sep 17 00:00:00 2001 From: Max Lepikhin Date: Sun, 25 Oct 2026 17:31:50 -0600 Subject: [PATCH 2/3] eden: correct managed macOS dependency recipes --- build/fbcode_builder/manifests/cpptoml | 3 +++ build/fbcode_builder/manifests/eden | 7 +++---- .../patches/glog_default_visibility.patch | 11 +++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/build/fbcode_builder/manifests/cpptoml b/build/fbcode_builder/manifests/cpptoml index c4d6d8d9c5656..15f4206269173 100644 --- a/build/fbcode_builder/manifests/cpptoml +++ b/build/fbcode_builder/manifests/cpptoml @@ -14,3 +14,6 @@ subdir = cpptoml-0.1.2 [cmake.defines.os=freebsd] ENABLE_LIBCXX=NO + +[cmake.defines.os=darwin] +ENABLE_LIBCXX=NO diff --git a/build/fbcode_builder/manifests/eden b/build/fbcode_builder/manifests/eden index 0a00e9f9b1e0c..b0d6e8ad996fc 100644 --- a/build/fbcode_builder/manifests/eden +++ b/build/fbcode_builder/manifests/eden @@ -37,15 +37,14 @@ rust-shed [dependencies.fbsource=on] rust -[dependencies.os=darwin] -osxfuse - [dependencies.not(os=windows)] # TODO: teach getdeps to compile curl on Windows. # Enabling curl on Windows requires us to find a way to compile libcurl with # msvc. libcurl -# Added so that OSS doesn't see system "python" which is python 2 on darwin and some linux + +[dependencies.not(any(os=windows, os=darwin))] +# On Linux, avoid finding a system "python" that may still be Python 2. python [dependencies.test=on] diff --git a/build/fbcode_builder/patches/glog_default_visibility.patch b/build/fbcode_builder/patches/glog_default_visibility.patch index 5ef0d6a8bf488..73e42c721217a 100644 --- a/build/fbcode_builder/patches/glog_default_visibility.patch +++ b/build/fbcode_builder/patches/glog_default_visibility.patch @@ -9,3 +9,14 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -set (CMAKE_VISIBILITY_INLINES_HIDDEN ON) set (CMAKE_DEBUG_POSTFIX d) +diff --git a/src/logging.cc b/src/logging.cc +--- a/src/logging.cc ++++ b/src/logging.cc +@@ -35,6 +35,7 @@ + #include + #include + #include ++#include + #ifdef HAVE_UNISTD_H + # include // For _exit. + #endif From 5e0cfe0379f03a14b8d9a964628abae42cd2cb5b Mon Sep 17 00:00:00 2001 From: Max Lepikhin Date: Sun, 25 Oct 2026 17:33:19 -0600 Subject: [PATCH 3/3] getdeps: package Folly and Thrift Python runtimes on macOS --- CMake/EdenConfigChecks.cmake | 10 +- .../CMake/FBThriftPythonLibrary.cmake | 24 +- .../fbcode_builder/manifests/fbthrift-python | 29 +- build/fbcode_builder/manifests/folly-python | 29 +- .../patches/fbthrift_python_darwin.patch | 271 ++++++++++++++++++ .../patches/folly_python_darwin.patch | 13 + 6 files changed, 349 insertions(+), 27 deletions(-) create mode 100644 build/fbcode_builder/patches/fbthrift_python_darwin.patch create mode 100644 build/fbcode_builder/patches/folly_python_darwin.patch diff --git a/CMake/EdenConfigChecks.cmake b/CMake/EdenConfigChecks.cmake index ec26dbbc82ba7..b5304b4313ec8 100644 --- a/CMake/EdenConfigChecks.cmake +++ b/CMake/EdenConfigChecks.cmake @@ -42,8 +42,8 @@ fb_find_or_fetch(FBThrift) include_directories(${FBTHRIFT_INCLUDE_DIR}) # The Python CLI uses fb303's thrift-python modules, which, like thrift-python, -# getdeps only builds on Linux. -if (CMAKE_SYSTEM_NAME STREQUAL "Linux") +# getdeps builds on Linux and macOS. +if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR APPLE) set(FB303_THRIFT_PYTHON ON) endif() fb_find_or_fetch(fb303) @@ -111,9 +111,9 @@ if (NOT BLAKE3_FOUND) endif() include_directories(${BLAKE3_INCLUDE_DIR}) -# The Python CLI uses thrift-python, which getdeps only builds on Linux, and -# the thrift-python modules that fb303 builds with FB303_THRIFT_PYTHON. -if (ENABLE_THRIFT_PYTHON AND CMAKE_SYSTEM_NAME STREQUAL "Linux") +# The Python CLI uses thrift-python and the thrift-python modules that fb303 +# builds with FB303_THRIFT_PYTHON. getdeps provides them on Linux and macOS. +if (ENABLE_THRIFT_PYTHON AND (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR APPLE)) include(FBThriftPythonLibrary) if (ENABLE_THRIFT_PYTHON STREQUAL "AUTO") fb_find_thrift_python_runtime(QUIET) diff --git a/build/fbcode_builder/CMake/FBThriftPythonLibrary.cmake b/build/fbcode_builder/CMake/FBThriftPythonLibrary.cmake index 16ca6e153e495..7ddd9ff95b82a 100644 --- a/build/fbcode_builder/CMake/FBThriftPythonLibrary.cmake +++ b/build/fbcode_builder/CMake/FBThriftPythonLibrary.cmake @@ -67,7 +67,7 @@ macro(fb_find_thrift_python_runtime) if( NOT _FB_THRIFT_PYTHON_RUNTIME_FOUND OR NOT EXISTS "${THRIFT_PYTHON_SITE_PACKAGES}/thrift/python" OR - NOT EXISTS "${THRIFT_PYTHON_SITE_PACKAGES}/thrift.libs" OR + (NOT APPLE AND NOT EXISTS "${THRIFT_PYTHON_SITE_PACKAGES}/thrift.libs") OR NOT EXISTS "${FOLLY_PYTHON_SITE_PACKAGES}/folly" ) # Ensure Python3 is found so we can use ${Python3_EXECUTABLE} @@ -121,7 +121,7 @@ macro(fb_find_thrift_python_runtime) "fbthrift-python was found at ${THRIFT_PYTHON_SITE_PACKAGES}, but " "its thrift/python runtime package is missing.") unset(THRIFT_PYTHON_SITE_PACKAGES) - elseif(NOT EXISTS "${THRIFT_PYTHON_SITE_PACKAGES}/thrift.libs") + elseif(NOT APPLE AND NOT EXISTS "${THRIFT_PYTHON_SITE_PACKAGES}/thrift.libs") message(WARNING "fbthrift-python was found at ${THRIFT_PYTHON_SITE_PACKAGES}, but " "thrift.libs is missing. Install an auditwheel-repaired " @@ -370,7 +370,7 @@ function(add_fb_thrift_python_executable TARGET) if( THRIFT_PYTHON_SITE_PACKAGES AND EXISTS "${THRIFT_PYTHON_SITE_PACKAGES}/thrift/python" AND - EXISTS "${THRIFT_PYTHON_SITE_PACKAGES}/thrift.libs" + (APPLE OR EXISTS "${THRIFT_PYTHON_SITE_PACKAGES}/thrift.libs") ) # The bundled thrift/ hides the wheel's namespace package, so link all of # its subpackages: thrift.python imports thrift.py3, for example. @@ -390,17 +390,23 @@ function(add_fb_thrift_python_executable TARGET) ) endif() endforeach() + set(thrift_libs_link_commands) + if(EXISTS "${THRIFT_PYTHON_SITE_PACKAGES}/thrift.libs") + list(APPEND thrift_libs_link_commands + COMMAND ${CMAKE_COMMAND} + "-DFB_REMOVE_PATH=${target_dir}/thrift.libs" + -P "${_FB_THRIFT_PYTHON_REMOVE_PATH_SCRIPT}" + COMMAND ${CMAKE_COMMAND} -E create_symlink + "${THRIFT_PYTHON_SITE_PACKAGES}/thrift.libs" + "${target_dir}/thrift.libs" + ) + endif() add_custom_command( TARGET ${TARGET}.GEN_PY_EXE POST_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory "${target_dir}/thrift" COMMAND ${CMAKE_COMMAND} -E touch "${target_dir}/thrift/__init__.py" ${link_commands} - COMMAND ${CMAKE_COMMAND} - "-DFB_REMOVE_PATH=${target_dir}/thrift.libs" - -P "${_FB_THRIFT_PYTHON_REMOVE_PATH_SCRIPT}" - COMMAND ${CMAKE_COMMAND} -E create_symlink - "${THRIFT_PYTHON_SITE_PACKAGES}/thrift.libs" - "${target_dir}/thrift.libs" + ${thrift_libs_link_commands} COMMENT "Symlinking thrift-python and its native dependencies into ${TARGET}" ) else() diff --git a/build/fbcode_builder/manifests/fbthrift-python b/build/fbcode_builder/manifests/fbthrift-python index 3245c726036bc..69c0b544ec7a6 100644 --- a/build/fbcode_builder/manifests/fbthrift-python +++ b/build/fbcode_builder/manifests/fbthrift-python @@ -16,8 +16,12 @@ fbthrift = thrift/lib/rust [build] builder = cmake job_weight_mib = 3072 +patchfile = fbthrift_python_darwin.patch -[build.not(os=linux)] +[build.os=darwin] +builder = cmake + +[build.os=windows] builder = nop [cmake.defines] @@ -34,25 +38,38 @@ THRIFT_TESTS=OFF [cmake.defines.os=linux] THRIFT_PYTHON=ON +[cmake.defines.os=darwin] +THRIFT_PYTHON=ON + [dependencies] benchmark -fizz-python -fmt-python folly-python googletest libsodium -wangle-python -zstd-python -mvfst-python xxhash # Thrift also depends on openssl but since the latter requires a platform- # specific configuration we rely on the folly manifest to provide this # dependency to avoid duplication. [dependencies.os=linux] +fizz-python +fmt-python +wangle-python +zstd-python +mvfst-python libaio-python libevent-python +[dependencies.os=darwin] +fizz +fmt +wangle +zstd +mvfst +liboqs +libevent +libdwarf + [shipit.pathmap] xplat/thrift/public_tld = . xplat/thrift = thrift diff --git a/build/fbcode_builder/manifests/folly-python b/build/fbcode_builder/manifests/folly-python index 0da2df690fa02..94eb9948c3efe 100644 --- a/build/fbcode_builder/manifests/folly-python +++ b/build/fbcode_builder/manifests/folly-python @@ -10,8 +10,12 @@ repo_url = https://github.com/facebook/folly.git [build] builder = cmake job_weight_mib = 1024 +patchfile = folly_python_darwin.patch -[build.not(os=linux)] +[build.os=darwin] +builder = cmake + +[build.os=windows] builder = nop [dependencies] @@ -20,15 +24,9 @@ gflags # copy of glog. glog = shared_libs googletest -boost-python -libdwarf-python -libevent-python libsodium fast_float -fmt-python -lz4-python snappy -zstd-python # no openssl or zlib in the linux case, why? # these are usually installed on the system # and are the easiest system deps to pull in. @@ -41,6 +39,12 @@ zstd-python # to build our own. [dependencies.os=darwin] openssl +boost +libdwarf +libevent +fmt +lz4 +zstd # Windows has neither openssl nor zlib, so we get # to provide both @@ -49,6 +53,12 @@ openssl zlib [dependencies.os=linux] +boost-python +libdwarf-python +libevent-python +fmt-python +lz4-python +zstd-python libaio-python libiberty-python libunwind @@ -70,6 +80,11 @@ fbcode/folly = folly PYTHON_EXTENSIONS=ON BUILD_SHARED_LIBS=ON +[cmake.defines.os=darwin] +PYTHON_EXTENSIONS=ON +BUILD_SHARED_LIBS=ON +CMAKE_CXX_FLAGS=-DGLOG_USE_GLOG_EXPORT + [cmake.defines.not(os=windows)] BOOST_LINK_STATIC=ON diff --git a/build/fbcode_builder/patches/fbthrift_python_darwin.patch b/build/fbcode_builder/patches/fbthrift_python_darwin.patch new file mode 100644 index 0000000000000..ee86445ed206d --- /dev/null +++ b/build/fbcode_builder/patches/fbthrift_python_darwin.patch @@ -0,0 +1,271 @@ +diff --git a/thrift/lib/python/CMakeLists.txt b/thrift/lib/python/CMakeLists.txt +index 45796d5b65..6ef64ff190 100644 +--- a/thrift/lib/python/CMakeLists.txt ++++ b/thrift/lib/python/CMakeLists.txt +@@ -27,7 +27,14 @@ find_package( + # - local/lib/pythonX.Y/dist-packages/ (pip --prefix on Debian/Ubuntu) + set(_folly_py_version "python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}") + unset(_folly_pxd_file CACHE) +-find_file( ++if(APPLE AND FOLLY_PREFIX_DIR) ++ set(_folly_pxd_file ++ "${FOLLY_PREFIX_DIR}/lib/${_folly_py_version}/site-packages/folly/__init__.pxd") ++ if(NOT EXISTS "${_folly_pxd_file}") ++ message(FATAL_ERROR "Folly Python headers not found: ${_folly_pxd_file}") ++ endif() ++else() ++ find_file( + _folly_pxd_file + NAMES folly/__init__.pxd + HINTS +@@ -39,7 +46,8 @@ find_file( + "${FOLLY_PREFIX_DIR}/lib64/x86_64-linux-gnu/${_folly_py_version}/site-packages" + "${FOLLY_PREFIX_DIR}/local/lib/x86_64-linux-gnu/${_folly_py_version}/dist-packages" + "${FOLLY_PREFIX_DIR}/local/lib64/x86_64-linux-gnu/${_folly_py_version}/dist-packages" +- NO_DEFAULT_PATH REQUIRED) ++ NO_DEFAULT_PATH REQUIRED) ++endif() + + # Extract site-packages directory (two levels up from folly/__init__.pxd) + get_filename_component(_folly_pkg_dir "${_folly_pxd_file}" DIRECTORY) +@@ -100,10 +108,30 @@ option(DEBUG_BUILD "Enable debug messages" OFF) + + # Libevent: Force static link to embed symbols + set(LIBEVENT_STATIC_LINK TRUE) +-find_package(Libevent REQUIRED CONFIG) ++if (APPLE) ++ find_path(EDEN_LIBEVENT_INCLUDE_DIR event.h REQUIRED) ++ find_library(EDEN_LIBEVENT_CORE event_core REQUIRED) ++ find_library(EDEN_LIBEVENT_EXTRA event_extra REQUIRED) ++ if (NOT TARGET libevent::core) ++ add_library(libevent::core UNKNOWN IMPORTED) ++ set_target_properties(libevent::core PROPERTIES ++ IMPORTED_LOCATION "${EDEN_LIBEVENT_CORE}" ++ INTERFACE_INCLUDE_DIRECTORIES "${EDEN_LIBEVENT_INCLUDE_DIR}") ++ endif () ++ if (NOT TARGET libevent::extra) ++ add_library(libevent::extra UNKNOWN IMPORTED) ++ set_target_properties(libevent::extra PROPERTIES ++ IMPORTED_LOCATION "${EDEN_LIBEVENT_EXTRA}" ++ INTERFACE_INCLUDE_DIRECTORIES "${EDEN_LIBEVENT_INCLUDE_DIR}") ++ endif () ++else () ++ find_package(Libevent REQUIRED CONFIG) ++endif () + + # Libiberty: Provides cplus_demangle_v3_callback for folly stack traces +-find_package(Libiberty REQUIRED) ++if (NOT APPLE) ++ find_package(Libiberty REQUIRED) ++endif () + + # gflags warning: + # This section adds explicit dependencies that --whole-archive bypasses. +@@ -312,7 +340,11 @@ endif () + # Set default LDFLAGS for setup.py to fix undefined symbol issues + # --no-as-needed ensures libfolly.so is in NEEDED list even if linker + # thinks it's not needed +-set(DEFAULT_SETUP_LDFLAGS "-Wl,--no-as-needed") ++if (APPLE) ++ set(DEFAULT_SETUP_LDFLAGS "") ++else () ++ set(DEFAULT_SETUP_LDFLAGS "-Wl,--no-as-needed") ++endif () + + # Allow users to override via environment variable (e.g., for custom RPATH) + if (DEFINED ENV{LDFLAGS}) +@@ -565,8 +597,18 @@ target_compile_definitions(thrift_python_cpp + PRIVATE THRIFT_NO_HTTP_CLIENT_CHANNEL) + # Workaround for https://github.com/cython/cython/issues/5973 + target_compile_definitions(thrift_python_cpp PRIVATE __PYX_ENUM_CLASS_DECL=) +-target_include_directories(thrift_python_cpp PRIVATE "${_cybld}" +- ${Python3_INCLUDE_DIRS}) ++if (APPLE) ++ # The wheel staging root contains folly/executor.h, which shadows ++ # Folly's Executor.h on case-insensitive filesystems. ++ file(MAKE_DIRECTORY "${_cybld}/cpp_include") ++ if (NOT EXISTS "${_cybld}/cpp_include/thrift") ++ file(CREATE_LINK "${_cybld}/thrift" "${_cybld}/cpp_include/thrift" SYMBOLIC) ++ endif () ++ target_include_directories(thrift_python_cpp PRIVATE "${_cybld}/cpp_include") ++else () ++ target_include_directories(thrift_python_cpp PRIVATE "${_cybld}") ++endif () ++target_include_directories(thrift_python_cpp PRIVATE ${Python3_INCLUDE_DIRS}) + # Link strategy: + # - STATIC libs (thrift + deps): embed with --whole-archive to consolidate + # into single .so +@@ -576,11 +618,17 @@ target_include_directories(thrift_python_cpp PRIVATE "${_cybld}" + # TJSONProtocol.cpp) + # libevent/libiberty: needed for undefined symbols, + # --allow-multiple-definition handles duplicates ++if (APPLE) ++ set(_whole_archive_prefix "") ++ set(_whole_archive_suffix "") ++else () ++ set(_whole_archive_prefix "-Wl,--whole-archive" "-Wl,--allow-multiple-definition") ++ set(_whole_archive_suffix "-Wl,--no-whole-archive") ++endif () + target_link_libraries( + thrift_python_cpp + PUBLIC # Static libs - embed all symbols +- "-Wl,--whole-archive" +- "-Wl,--allow-multiple-definition" ++ ${_whole_archive_prefix} + thriftcpp2 + rpcmetadata + thrift_annotation +@@ -594,12 +642,17 @@ target_link_libraries( + libevent::core + libevent::extra + ${LIBIBERTY_LIBRARIES} +- "-Wl,--no-whole-archive" ++ ${_whole_archive_suffix} + # Shared libs - runtime deps (see manifests/folly, manifests/fmt) + Folly::folly + Folly::folly_python_cpp + fmt::fmt + glog::glog) ++if (APPLE) ++ target_link_libraries(thrift_python_cpp PRIVATE Python3::Python) ++ target_link_options(thrift_python_cpp PRIVATE ++ "LINKER:-force_load,$") ++endif () + install(TARGETS thrift_python_cpp EXPORT thrift) + install(TARGETS thrift_python_cpp DESTINATION ${py_install_dir}) + +@@ -721,6 +774,7 @@ add_custom_command( + # Run auditwheel repair to make the wheel self-contained + # This bundles .so dependencies and rewrites RPATH to $ORIGIN + # LD_LIBRARY_PATH tells auditwheel where to find the libraries to bundle ++if (NOT APPLE) + add_custom_command( + TARGET thrift_python_and_py3_bindings + COMMAND ${CMAKE_COMMAND} -E make_directory "${_cybld}/dist_self_contained" +@@ -729,6 +783,12 @@ add_custom_command( + ${Python3_EXECUTABLE} -m auditwheel repair --wheel-dir + "${_cybld}/dist_self_contained" "${_cybld}/dist/*.whl" + WORKING_DIRECTORY ${_cybld}) ++else () ++ add_custom_command( ++ TARGET thrift_python_and_py3_bindings ++ COMMAND ${CMAKE_COMMAND} -E copy_directory ++ "${_cybld}/dist" "${_cybld}/dist_self_contained") ++endif () + + # Install the self-contained wheel to the install prefix + # for users to pip install +diff --git a/thrift/lib/setup.py b/thrift/lib/setup.py +index dcf05b5524..c46c0dee31 100644 +--- a/thrift/lib/setup.py ++++ b/thrift/lib/setup.py +@@ -18,6 +18,7 @@ + # created as tree of links to the real source files. + + import os ++import shutil + import sys + + import Cython +@@ -107,13 +108,25 @@ if "--api-only" in sys.argv: + language_level=3, + ) + # Compile streaming modules to generate *_api.h headers ++ # APFS may be case-insensitive: sink.cpp must not shadow Sink.cpp. ++ if sys.platform == "darwin": ++ os.makedirs("generated_api", exist_ok=True) ++ sink_options = Options.CompilationOptions( ++ compilation_options, output_file="generated_api/sink.cpp" ++ ) ++ else: ++ sink_options = compilation_options + Cython.Compiler.Main.compile( + "thrift/python/streaming/sink.pyx", +- options=compilation_options, ++ options=sink_options, + full_module_name="thrift.python.streaming.sink", + cplus=True, + language_level=3, + ) ++ if sys.platform == "darwin": ++ shutil.copyfile( ++ "generated_api/sink_api.h", "thrift/python/streaming/sink_api.h" ++ ) + Cython.Compiler.Main.compile( + "thrift/python/streaming/bidistream.pyx", + options=compilation_options, +@@ -140,7 +153,7 @@ if "--api-only" in sys.argv: + + else: + python_lib_idx = sys.argv.index("--libpython") +- python_lib = sys.argv[python_lib_idx + 1][len("lib") : -len(".so")] ++ python_lib = os.path.splitext(sys.argv[python_lib_idx + 1])[0][len("lib") :] + del sys.argv[python_lib_idx : python_lib_idx + 2] + + # Library search paths from CMakeLists (passed via LIBRARY_DIRS env var) +@@ -163,6 +176,9 @@ else: + "sodium", + "unwind", + ] ++ if sys.platform == "darwin": ++ dynamic_libs = [lib for lib in dynamic_libs if lib not in ("aio", "unwind")] ++ dynamic_libs.append("fmt") + + extra_link_args = [] + +@@ -177,18 +192,42 @@ else: + # Use $ORIGIN so auditwheel can properly bundle libraries into the wheel. + # $ORIGIN/.libs is where auditwheel places bundled shared libraries. + # We also add $ORIGIN for libraries in the same directory as the extension. +- extra_link_args.append("-Wl,-rpath,$ORIGIN/.libs") +- extra_link_args.append("-Wl,-rpath,$ORIGIN") ++ origin = "@loader_path" if sys.platform == "darwin" else "$ORIGIN" ++ extra_link_args.append(f"-Wl,-rpath,{origin}/.libs") ++ extra_link_args.append(f"-Wl,-rpath,{origin}") ++ ++ cpp_include_dirs = include_dirs ++ if sys.platform == "darwin": ++ # Prefer Folly's C++ Executor.h to the staged Cython executor.h. ++ folly_cpp_include = next( ++ ( ++ path ++ for path in include_dirs ++ if os.path.isdir(os.path.join(path, "folly")) ++ and "Executor.h" in os.listdir(os.path.join(path, "folly")) ++ ), ++ None, ++ ) ++ if folly_cpp_include: ++ cpp_include_dirs = [folly_cpp_include] + include_dirs + + common_options = { + "language": "c++", +- "include_dirs": include_dirs, ++ "include_dirs": cpp_include_dirs, + "library_dirs": lib_search_paths, # Tell linker where to find dynamic libraries + "libraries": dynamic_libs + [python_lib], +- "extra_compile_args": ["-std=c++20", "-fcoroutines"], ++ "extra_compile_args": ["-std=c++20", "-fcoroutines"] ++ + (["-DGLOG_USE_GLOG_EXPORT"] if sys.platform == "darwin" else []), + "extra_link_args": extra_link_args, + } + ++ sink_cpp_source = "thrift/python/streaming/Sink.cpp" ++ if sys.platform == "darwin": ++ # Cython's build directory also contains generated sink.cpp. ++ sink_cpp_source = "thrift/python/streaming/SinkNative.cpp" ++ if not os.path.exists(sink_cpp_source): ++ os.symlink("Sink.cpp", sink_cpp_source) ++ + exts = [ + # thrift.python extension modules + Extension( +@@ -338,7 +377,7 @@ else: + "thrift.python.streaming.sink", + sources=[ + "thrift/python/streaming/sink.pyx", +- "thrift/python/streaming/Sink.cpp", ++ sink_cpp_source, + ], + **common_options, + ), diff --git a/build/fbcode_builder/patches/folly_python_darwin.patch b/build/fbcode_builder/patches/folly_python_darwin.patch new file mode 100644 index 0000000000000..b6118940d7609 --- /dev/null +++ b/build/fbcode_builder/patches/folly_python_darwin.patch @@ -0,0 +1,13 @@ +diff --git a/folly/python/CMakeLists.txt b/folly/python/CMakeLists.txt +--- a/folly/python/CMakeLists.txt ++++ b/folly/python/CMakeLists.txt +@@ -137,6 +137,9 @@ + add_dependencies(folly_python_cpp folly create_post_binding_symlink) + set_property(TARGET folly_python_cpp PROPERTY VERSION ${PACKAGE_VERSION}) + target_compile_definitions(folly_python_cpp PRIVATE BOOST_NO_AUTO_PTR) ++if(APPLE) ++ target_include_directories(folly_python_cpp BEFORE PRIVATE "${CMAKE_SOURCE_DIR}") ++endif() + target_include_directories(folly_python_cpp PRIVATE "${_cybld}") + target_link_libraries(folly_python_cpp PUBLIC folly) + apply_folly_compile_options_to_target(folly_python_cpp)