sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=cwd).decode('ascii').strip() except Exception: pass if os.getenv('PYTORCH_BUILD_VERSION'): assert os.getenv('PYTORCH_BUILD_NUMBER') is not None build_number = int(os.getenv('PYTORCH_BUILD_NUMBER')) version = os.getenv('PYTORCH_BUILD_VERSION') if build_number > 1: version += '.post' + str(build_number) elif sha != 'Unknown': version += '+' + sha[:7] report("Building wheel {}-{}".format(package_name, version)) cmake = CMake('build') # all the work we need to do _before_ setup runs def build_deps(): report('-- Building version ' + version) version_path = os.path.join(cwd, 'torch', 'version.py') with open(version_path, 'w') as f: f.write("__version__ = '{}'\n".format(version)) # NB: This is not 100% accurate, because you could have built the # library code with DEBUG, but csrc without DEBUG (in which case # this would claim to be a release build when it's not.) f.write("debug = {}\n".format(repr(DEBUG))) f.write("cuda = {}\n".format(repr(CUDA_VERSION))) f.write("git_version = {}\n".format(repr(sha)))
sha = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=cwd).decode('ascii').strip() except Exception: pass if os.getenv('PYTORCH_BUILD_VERSION'): assert os.getenv('PYTORCH_BUILD_NUMBER') is not None build_number = int(os.getenv('PYTORCH_BUILD_NUMBER')) version = os.getenv('PYTORCH_BUILD_VERSION') if build_number > 1: version += '.post' + str(build_number) elif sha != 'Unknown': version += '+' + sha[:7] report("Building wheel {}-{}".format(package_name, version)) cmake = CMake() # all the work we need to do _before_ setup runs def build_deps(): report('-- Building version ' + version) def check_file(f): if not os.path.exists(f): report("Could not find {}".format(f)) report("Did you run 'git submodule update --init --recursive'?") sys.exit(1) check_file(os.path.join(third_party_path, "gloo", "CMakeLists.txt")) check_file(os.path.join(third_party_path, "pybind11", "CMakeLists.txt")) check_file(os.path.join(third_party_path, 'cpuinfo', 'CMakeLists.txt'))
import argparse from os.path import dirname, abspath import sys # By appending pytorch_root to sys.path, this module can import other torch # modules even when run as a standalone script. i.e., it's okay either you # do `python build_libtorch.py` or `python -m tools.build_libtorch`. pytorch_root = dirname(dirname(abspath(__file__))) sys.path.append(pytorch_root) # If you want to modify flags or environmental variables that is set when # building torch, you should do it in tools/setup_helpers/configure.py. # Please don't add it here unless it's only used in LibTorch. from tools.build_pytorch_libs import build_caffe2 from tools.setup_helpers.cmake import CMake if __name__ == '__main__': # Placeholder for future interface. For now just gives a nice -h. parser = argparse.ArgumentParser(description='Build libtorch') options = parser.parse_args() build_caffe2(version=None, cmake_python_library=None, build_python=False, rerun_cmake=True, cmake_only=False, cmake=CMake('.'))