Skip to content

Commit 1581ada

Browse files
committed
[Build] Disable C++11 ABI when necessary for libtorch compatibility
See also: - pytorch/text#931 - https://stackoverflow.com/a/55406930
1 parent 7a36c55 commit 1581ada

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

build_tools/setup_helpers/extension.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import subprocess
44
from pathlib import Path
55

6+
import torch
67
from torch.utils.cpp_extension import (
78
CppExtension,
89
BuildExtension as TorchBuildExtension
@@ -109,12 +110,22 @@ def _get_libraries():
109110
return [] if _BUILD_SOX else ['sox']
110111

111112

113+
def _get_cxx11_abi():
114+
try:
115+
value = int(torch._C._GLIBCXX_USE_CXX11_ABI)
116+
except ImportError:
117+
value = 0
118+
return f'-D_GLIBCXX_USE_CXX11_ABI={value}'
119+
120+
112121
def _build_third_party(base_build_dir):
113122
build_dir = os.path.join(base_build_dir, 'third_party')
114123
os.makedirs(build_dir, exist_ok=True)
115124
subprocess.run(
116125
args=[
117126
'cmake',
127+
f'-DCMAKE_CXX_FLAGS=\'{_get_cxx11_abi()}\'',
128+
f'-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON',
118129
f'-DCMAKE_INSTALL_PREFIX={_TP_INSTALL_DIR}',
119130
f'-DBUILD_SOX={"ON" if _BUILD_SOX else "OFF"}',
120131
f'-DBUILD_TRANSDUCER={"ON" if _BUILD_TRANSDUCER else "OFF"}',

0 commit comments

Comments
 (0)