python: protobuf

protobuf가 C++ 백엔드를 사용하는지 확인

# (1)
from google.protobuf.internal import api_implementation
print("Protobuf Backend:", api_implementation.Type())  # "cpp"여야 함
 
# (2)
import google.protobuf.pyext._message 에서 
# import error가 발생한다면, C++ 백엔드 사용을 못하는 것임

C++ 백엔드를 사용하도록 강제 설정

# bash
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
 
# powershell
$env:PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION="cpp"

Windows용 python module 빌드

git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git checkout v3.20.3
git submodule update --init --recursive

# /MT 옵션 사용

uv run --with=cmake==4.0.0 cmake -G "Visual Studio 15 2017" -A x64 -DCMAKE_BUILD_TYPE=Release -S cmake -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" -B build2 -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_BUILD_TESTS=OFF
uv run --with=cmake==4.0.0 cmake --build build2 --config Release

# %CD% 현재 폴더

set CL=/WX- /D_USE_MATH_DEFINES /wd4244 /wd4018
set INCLUDE=%CD%\src;%INCLUDE%
set LIB=%CD%\build2\Release;%LIB%
set PATH=%CD%\build2\Release;%PATH%

cd python
uv run --python=3.10 python setup.py build --cpp_implementation
uv run --python=3.10 --with=wheel python setup.py bdist_wheel --cpp_implementation