pytorch/tools/build_libtorch.py
Peter Goldsborough 8311bbee7f Fix Windows build and test in CI (#11716)
Summary:
This PR adds Windows support for the C++ frontend. A lot of declarations were missing `TORCH_API` macros, and lots of code just did not compile on MSVC.

ebetica ezyang orionr
Pull Request resolved: https://github.com/pytorch/pytorch/pull/11716

Reviewed By: orionr

Differential Revision: D13038253

Pulled By: goldsborough

fbshipit-source-id: c8e5a45efd26117aeb99e768b56fcd5a89fcb9f8
2018-11-13 16:35:54 -08:00

39 lines
1.2 KiB
Python

import argparse
import os
import shlex
import subprocess
import sys
from setup_helpers.cuda import USE_CUDA
from setup_helpers.env import check_env_flag
if __name__ == '__main__':
# Placeholder for future interface. For now just gives a nice -h.
parser = argparse.ArgumentParser(description='Build libtorch')
options = parser.parse_args()
os.environ['BUILD_TORCH'] = 'ON'
os.environ['BUILD_TEST'] = 'ON'
os.environ['ONNX_NAMESPACE'] = 'onnx_torch'
os.environ['PYTORCH_PYTHON'] = sys.executable
tools_path = os.path.dirname(os.path.abspath(__file__))
if sys.platform == 'win32':
build_pytorch_libs = os.path.join(tools_path, 'build_pytorch_libs.bat')
else:
build_pytorch_libs = os.path.join(tools_path, 'build_pytorch_libs.sh')
command = [build_pytorch_libs, '--use-nnpack']
USE_MKLDNN = check_env_flag('USE_MKLDNN', 'ON')
if USE_MKLDNN:
command.append('--use-mkldnn')
if USE_CUDA:
command.append('--use-cuda')
if os.environ.get('USE_CUDA_STATIC_LINK', False):
command.append('--cuda-static-link')
command.append('caffe2')
sys.stdout.flush()
sys.stderr.flush()
subprocess.check_call(command, universal_newlines=True)