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