Show the cpp library path and generate the bazel project template. This command MUST be run from the ray project root directory if --generate-bazel-project-template-to is set.
(show_library_path, generate_bazel_project_template_to, bazel_version)
| 2789 | ) |
| 2790 | @add_click_logging_options |
| 2791 | def cpp(show_library_path, generate_bazel_project_template_to, bazel_version): |
| 2792 | """Show the cpp library path and generate the bazel project template. |
| 2793 | |
| 2794 | This command MUST be run from the ray project root directory if |
| 2795 | --generate-bazel-project-template-to is set. |
| 2796 | """ |
| 2797 | if sys.platform == "win32": |
| 2798 | raise click.ClickException("Ray C++ API is not supported on Windows currently.") |
| 2799 | |
| 2800 | if not show_library_path and not generate_bazel_project_template_to: |
| 2801 | raise ValueError( |
| 2802 | "Please input at least one option of '--show-library-path'" |
| 2803 | " and '--generate-bazel-project-template-to'." |
| 2804 | ) |
| 2805 | |
| 2806 | raydir = os.path.abspath(os.path.dirname(ray.__file__)) |
| 2807 | cpp_dir = os.path.join(raydir, "cpp") |
| 2808 | cpp_template_dir = os.path.join(cpp_dir, "example") |
| 2809 | include_dir = os.path.join(cpp_dir, "include") |
| 2810 | lib_dir = os.path.join(cpp_dir, "lib") |
| 2811 | if not os.path.isdir(cpp_dir): |
| 2812 | raise ValueError('Please install ray with C++ API by "pip install ray[cpp]".') |
| 2813 | if show_library_path: |
| 2814 | cli_logger.print("Ray C++ include path {} ", cf.bold(f"{include_dir}")) |
| 2815 | cli_logger.print("Ray C++ library path {} ", cf.bold(f"{lib_dir}")) |
| 2816 | if generate_bazel_project_template_to: |
| 2817 | out_dir = generate_bazel_project_template_to |
| 2818 | # copytree expects that the dst dir doesn't exist |
| 2819 | # so we manually delete it if it exists. |
| 2820 | if os.path.exists(out_dir): |
| 2821 | shutil.rmtree(out_dir) |
| 2822 | |
| 2823 | shutil.copytree(cpp_template_dir, out_dir) |
| 2824 | for filename in ["_WORKSPACE", "_BUILD.bazel", "_.bazelrc"]: |
| 2825 | # Renames the bazel related files by removing the leading underscore. |
| 2826 | dest_name = os.path.join(out_dir, filename[1:]) |
| 2827 | shutil.move(os.path.join(out_dir, filename), dest_name) |
| 2828 | |
| 2829 | out_include_dir = os.path.join(out_dir, "thirdparty/include") |
| 2830 | shutil.copytree(include_dir, out_include_dir) |
| 2831 | out_lib_dir = os.path.join(out_dir, "thirdparty/lib") |
| 2832 | shutil.copytree(lib_dir, out_lib_dir) |
| 2833 | |
| 2834 | with open(os.path.join(out_dir, ".bazelversion"), "w") as f: |
| 2835 | f.write(bazel_version.strip() + "\n") |
| 2836 | |
| 2837 | cli_logger.print( |
| 2838 | "Project template generated to {}", |
| 2839 | cf.bold(f"{os.path.abspath(out_dir)}"), |
| 2840 | ) |
| 2841 | |
| 2842 | cli_logger.print("To build and run this template, run") |
| 2843 | cli_logger.print(cf.bold(f" cd {os.path.abspath(out_dir)} && bash run.sh")) |
| 2844 | |
| 2845 | |
| 2846 | @cli.command(hidden=True) |