[AMDGPU] Make v8i16/v8f16 legal
[llvm-project.git] / utils / bazel / configure.bzl
blob4c5ab8bd097249c87d94389ce518dc50172d7c79
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"
14 DEFAULT_TARGETS = [
15     "AArch64",
16     "AMDGPU",
17     "ARM",
18     "AVR",
19     "BPF",
20     "Hexagon",
21     "Lanai",
22     "Mips",
23     "MSP430",
24     "NVPTX",
25     "PowerPC",
26     "RISCV",
27     "Sparc",
28     "SystemZ",
29     "WebAssembly",
30     "X86",
31     "XCore",
34 def _overlay_directories(repository_ctx):
35     src_path = repository_ctx.path(Label("//:WORKSPACE")).dirname
36     bazel_path = src_path.get_child("utils").get_child("bazel")
37     overlay_path = bazel_path.get_child("llvm-project-overlay")
38     script_path = bazel_path.get_child("overlay_directories.py")
40     python_bin = repository_ctx.which("python3")
41     if not python_bin:
42         # Windows typically just defines "python" as python3. The script itself
43         # contains a check to ensure python3.
44         python_bin = repository_ctx.which("python")
46     if not python_bin:
47         fail("Failed to find python3 binary")
49     cmd = [
50         python_bin,
51         script_path,
52         "--src",
53         src_path,
54         "--overlay",
55         overlay_path,
56         "--target",
57         ".",
58     ]
59     exec_result = repository_ctx.execute(cmd, timeout = 20)
61     if exec_result.return_code != 0:
62         fail(("Failed to execute overlay script: '{cmd}'\n" +
63               "Exited with code {return_code}\n" +
64               "stdout:\n{stdout}\n" +
65               "stderr:\n{stderr}\n").format(
66             cmd = " ".join([str(arg) for arg in cmd]),
67             return_code = exec_result.return_code,
68             stdout = exec_result.stdout,
69             stderr = exec_result.stderr,
70         ))
72 def _llvm_configure_impl(repository_ctx):
73     _overlay_directories(repository_ctx)
75     # Create a starlark file with the requested LLVM targets.
76     targets = repository_ctx.attr.targets
77     repository_ctx.file(
78         "llvm/targets.bzl",
79         content = "llvm_targets = " + str(targets),
80         executable = False,
81     )
83 llvm_configure = repository_rule(
84     implementation = _llvm_configure_impl,
85     local = True,
86     configure = True,
87     attrs = {
88         "targets": attr.string_list(default = DEFAULT_TARGETS),
89     },
92 def llvm_disable_optional_support_deps():
93     maybe(
94         llvm_zlib_disable,
95         name = "llvm_zlib",
96     )
98     maybe(
99         llvm_terminfo_disable,
100         name = "llvm_terminfo",
101     )
103 def llvm_use_system_support_deps():
104     maybe(
105         llvm_zlib_system,
106         name = "llvm_zlib",
107     )
109     maybe(
110         llvm_terminfo_system,
111         name = "llvm_terminfo",
112     )