Unverified Commit 72b76803 authored by moto's avatar moto Committed by GitHub
Browse files

[Build] Disable C++11 ABI when necessary for libtorch compatibility (#880)

With this change, `BUILD_TRANSDUCER=1 python setup.py build_ext` now sees `-D_GLIBCXX_USE_CXX11_ABI=` in the compilation command. (Note: sox is C-only so it is not relevant to sox build process)

See also:
 - https://github.com/pytorch/text/pull/931
 - https://stackoverflow.com/a/55406930
parent 092a7869
...@@ -3,6 +3,7 @@ import platform ...@@ -3,6 +3,7 @@ import platform
import subprocess import subprocess
from pathlib import Path from pathlib import Path
import torch
from torch.utils.cpp_extension import ( from torch.utils.cpp_extension import (
CppExtension, CppExtension,
BuildExtension as TorchBuildExtension BuildExtension as TorchBuildExtension
...@@ -109,12 +110,22 @@ def _get_libraries(): ...@@ -109,12 +110,22 @@ def _get_libraries():
return [] if _BUILD_SOX else ['sox'] return [] if _BUILD_SOX else ['sox']
def _get_cxx11_abi():
try:
value = int(torch._C._GLIBCXX_USE_CXX11_ABI)
except ImportError:
value = 0
return f'-D_GLIBCXX_USE_CXX11_ABI={value}'
def _build_third_party(base_build_dir): def _build_third_party(base_build_dir):
build_dir = os.path.join(base_build_dir, 'third_party') build_dir = os.path.join(base_build_dir, 'third_party')
os.makedirs(build_dir, exist_ok=True) os.makedirs(build_dir, exist_ok=True)
subprocess.run( subprocess.run(
args=[ args=[
'cmake', 'cmake',
f"-DCMAKE_CXX_FLAGS='{_get_cxx11_abi()}'",
'-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON',
f'-DCMAKE_INSTALL_PREFIX={_TP_INSTALL_DIR}', f'-DCMAKE_INSTALL_PREFIX={_TP_INSTALL_DIR}',
f'-DBUILD_SOX={"ON" if _BUILD_SOX else "OFF"}', f'-DBUILD_SOX={"ON" if _BUILD_SOX else "OFF"}',
f'-DBUILD_TRANSDUCER={"ON" if _BUILD_TRANSDUCER else "OFF"}', f'-DBUILD_TRANSDUCER={"ON" if _BUILD_TRANSDUCER else "OFF"}',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment