xref: /aosp_15_r20/external/pytorch/tools/build_libtorch.py (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1import argparse
2import sys
3from os.path import abspath, dirname
4
5
6# By appending pytorch_root to sys.path, this module can import other torch
7# modules even when run as a standalone script. i.e., it's okay either you
8# do `python build_libtorch.py` or `python -m tools.build_libtorch`.
9pytorch_root = dirname(dirname(abspath(__file__)))
10sys.path.append(pytorch_root)
11
12from tools.build_pytorch_libs import build_caffe2
13from tools.setup_helpers.cmake import CMake
14
15
16if __name__ == "__main__":
17    # Placeholder for future interface. For now just gives a nice -h.
18    parser = argparse.ArgumentParser(description="Build libtorch")
19    parser.add_argument("--rerun-cmake", action="store_true", help="rerun cmake")
20    parser.add_argument(
21        "--cmake-only",
22        action="store_true",
23        help="Stop once cmake terminates. Leave users a chance to adjust build options",
24    )
25    options = parser.parse_args()
26
27    build_caffe2(
28        version=None,
29        cmake_python_library=None,
30        build_python=False,
31        rerun_cmake=options.rerun_cmake,
32        cmake_only=options.cmake_only,
33        cmake=CMake(),
34    )
35