DepperDan/build_functions/build_protobuf.py

45 lines
1.8 KiB
Python

# (c) 2025 by Stephan Menzel
# Licensed under the Apache License, Version 2.0.
# See attached file LICENSE for full details
from pathlib import Path
from build_functions.build_utils import print_banner
from common.azure import write_package_version_batch
from common.cmake import cmake_build_install
from common.git_helpers import clone_git_tag
import common.settings
from package.package_info import get_package_info
def build_protobuf(prefix: Path | str, sbom: dict):
print_banner("Building Protobuf")
package_info = get_package_info("protobuf")
package_info.add_to_sbom(sbom)
abseil_install_path = package_info.dependency_path("abseil-cpp")
zlib_install_path = package_info.dependency_path("zlib")
protobuf_cmake_args = [
("BUILD_SHARED_LIBS:BOOL", "OFF"),
("BUILD_TESTING:BOOL", "OFF"),
("protobuf_BUILD_TESTS:BOOL", "OFF"),
("protobuf_WITH_ZLIB:BOOL", "ON"),
("ABSL_PROPAGATE_CXX_STD:BOOL", "ON"),
("protobuf_MSVC_STATIC_RUNTIME:BOOL", "OFF"),
("protobuf_ABSL_PROVIDER:STRING", "package"),
("absl_DIR:PATH", str(abseil_install_path / "lib" / "cmake" / "absl")),
("protobuf_INSTALL:BOOL", "ON"),
("protobuf_ZLIB_PROVIDER:STRING", "package"),
("ZLIB_ROOT:PATH", str(zlib_install_path)),
("ZLIB_USE_STATIC_LIBS:BOOL", "ON"), # doesn't appear to do its job
("ZLIB_LIBRARY_RELEASE:FILEPATH", str(zlib_install_path / "lib" / common.settings.zlib_static_lib_name)),
("ZLIB_LIBRARY_DEBUG:FILEPATH", str(zlib_install_path / "lib" / common.settings.zlib_static_lib_name))
# We are on fake debug
]
protobuf_dir = clone_git_tag(package_info, recursive=False)
install_dir = cmake_build_install(protobuf_dir, package_info, cmake_args=protobuf_cmake_args)
write_package_version_batch(package_info.version)
return install_dir