1 # This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2 # See https://llvm.org/LICENSE.txt for license information.
3 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 """Helper macros to configure the LLVM overlay project."""
7 load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
8 load(":zlib.bzl", "llvm_zlib_disable", "llvm_zlib_system")
9 load(":terminfo.bzl", "llvm_terminfo_disable", "llvm_terminfo_system")
11 # Directory of overlay files relative to WORKSPACE
12 DEFAULT_OVERLAY_PATH = "llvm-project-overlay"
35 def _overlay_directories(repository_ctx):
36 src_path = repository_ctx.path(Label("//:WORKSPACE")).dirname
37 bazel_path = src_path.get_child("utils").get_child("bazel")
38 overlay_path = bazel_path.get_child("llvm-project-overlay")
39 script_path = bazel_path.get_child("overlay_directories.py")
41 python_bin = repository_ctx.which("python3")
43 # Windows typically just defines "python" as python3. The script itself
44 # contains a check to ensure python3.
45 python_bin = repository_ctx.which("python")
48 fail("Failed to find python3 binary")
60 exec_result = repository_ctx.execute(cmd, timeout = 20)
62 if exec_result.return_code != 0:
63 fail(("Failed to execute overlay script: '{cmd}'\n" +
64 "Exited with code {return_code}\n" +
65 "stdout:\n{stdout}\n" +
66 "stderr:\n{stderr}\n").format(
67 cmd = " ".join([str(arg) for arg in cmd]),
68 return_code = exec_result.return_code,
69 stdout = exec_result.stdout,
70 stderr = exec_result.stderr,
73 def _llvm_configure_impl(repository_ctx):
74 _overlay_directories(repository_ctx)
76 # Create a starlark file with the requested LLVM targets.
77 targets = repository_ctx.attr.targets
80 content = "llvm_targets = " + str(targets),
84 llvm_configure = repository_rule(
85 implementation = _llvm_configure_impl,
89 "targets": attr.string_list(default = DEFAULT_TARGETS),
93 def llvm_disable_optional_support_deps():
100 llvm_terminfo_disable,
101 name = "llvm_terminfo",
104 def llvm_use_system_support_deps():
111 llvm_terminfo_system,
112 name = "llvm_terminfo",