diff --git a/CMakeLists.txt b/CMakeLists.txt index e5fd1f96a7..add8df6dd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,6 +152,9 @@ else() endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${warning_flags} ${TORCH_CXX_FLAGS}") +# Ensure that torchaudio is torch ABI stable. +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTORCH_TARGET_VERSION=0x020a000000000000") + find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) message(STATUS "Found ccache") diff --git a/src/libtorchaudio/cuctc/src/python_binding.cpp b/src/libtorchaudio/cuctc/src/python_binding.cpp index abbc057bb2..eb71832224 100644 --- a/src/libtorchaudio/cuctc/src/python_binding.cpp +++ b/src/libtorchaudio/cuctc/src/python_binding.cpp @@ -23,12 +23,25 @@ // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// It is safe to temporarily disable TORCH_TARGET_VERSION for pybind11 +// as it is a header-only library. +#ifdef TORCH_TARGET_VERSION +#define SAVE_TORCH_TARGET_VERSION TORCH_TARGET_VERSION +#undef TORCH_TARGET_VERSION +#endif #include #include +#ifdef SAVE_TORCH_TARGET_VERSION +#define TORCH_TARGET_VERSION SAVE_TORCH_TARGET_VERSION +#undef SAVE_TORCH_TARGET_VERSION +#endif + #include #include #include #include "include/ctc_prefix_decoder.h" + namespace py = pybind11; std::tuple>>>> diff --git a/src/libtorchaudio/pybind/pybind.cpp b/src/libtorchaudio/pybind/pybind.cpp index 6067839a27..a7a643d265 100644 --- a/src/libtorchaudio/pybind/pybind.cpp +++ b/src/libtorchaudio/pybind/pybind.cpp @@ -1,6 +1,17 @@ #include + +// It is safe to temporarily disable TORCH_TARGET_VERSION for pybind11 +// as it is a header-only library. +#ifdef TORCH_TARGET_VERSION +#define SAVE_TORCH_TARGET_VERSION TORCH_TARGET_VERSION +#undef TORCH_TARGET_VERSION +#endif #include #include +#ifdef SAVE_TORCH_TARGET_VERSION +#define TORCH_TARGET_VERSION SAVE_TORCH_TARGET_VERSION +#undef SAVE_TORCH_TARGET_VERSION +#endif namespace torchaudio { namespace {