DepperDan/build_functions/build_boost.py

72 lines
2.4 KiB
Python

# (c) 2025 by Stephan Menzel
# Licensed under the Apache License, Version 2.0.
# See attached file LICENSE for full details
import os
from pathlib import Path
from build_functions.build_utils import run_in_shell, print_banner, file_and_console_log
from common.azure import write_package_version_batch
from common.directory_helpers import pushd, get_local_prefix
from common.git_helpers import clone_git_tag
import common.settings
from package.package_info import get_package_info
def build_boost(prefix: Path | str, sbom: dict):
print_banner("Building Boost")
package_info = get_package_info("boost")
package_info.add_to_sbom(sbom)
boost_dir = clone_git_tag(package_info, recursive=True)
with pushd(boost_dir):
prefix = package_info.install_location()
if not common.settings.rebuild and os.path.exists("built_and_installed.txt"):
file_and_console_log("already built, exiting")
return prefix
if os.name == 'nt':
bootstrap_suffix = "bat"
b2_suffix = ".exe"
cmdprefix = ""
flags = "define=BOOST_USE_WINAPI_VERSION=0x0A00 define=_WIN32_WINNT=0x0A00"
else:
cmdprefix = "./"
bootstrap_suffix = "sh"
b2_suffix = ""
flags = "cxxflags=-fPIC cflags=-fPIC"
if os.name != 'nt':
run_in_shell('chmod +x bootstrap.sh')
run_in_shell('chmod +x ./tools/build/src/engine/build.sh')
run_in_shell(
f"{cmdprefix}bootstrap.{bootstrap_suffix} {common.settings.boost_bootstrap_toolset} --prefix={prefix}")
# Normally I wouldn't exclude this many (or indeed any) libs from the build
# but I have to save time to get the pipeline run below 1h
run_in_shell(
f"{cmdprefix}b2{b2_suffix} {flags} {common.settings.boost_toolset} cxxstd={common.settings.cpp_standard} -j {common.settings.num_cores} "
f"--prefix={prefix} "
"--without-mpi "
"--without-graph_parallel "
# "--without-python "
"address-model=64 architecture=x86 link=static runtime-link=shared "
"variant=release threading=multi install")
with open("built_and_installed.txt", "w") as lockfile:
lockfile.write("built")
write_package_version_batch(package_info.version)
# This stopped working somehow...
# if run_in_buildpipeline:
# shutil.rmtree(local_directory)
return prefix