blob: 654649508d3c758a1ab4bd7ca9cbc3b604b32ff0 [file] [log] [blame]
Geoffrey Martin-Noble552d3f82021-05-25 17:56:09 -07001# Copyright 2021 The IREE Authors
Geoffrey Martin-Noblef5b323e2021-01-12 18:32:08 -08002#
Geoffrey Martin-Noble552d3f82021-05-25 17:56:09 -07003# Licensed under the Apache License v2.0 with LLVM Exceptions.
4# See https://llvm.org/LICENSE.txt for license information.
5# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Geoffrey Martin-Noblef5b323e2021-01-12 18:32:08 -08006"""Helper functions for configuring IREE and dependent project WORKSPACE files."""
7
Geoffrey Martin-Noblef5b323e2021-01-12 18:32:08 -08008load("@bazel_skylib//lib:paths.bzl", "paths")
Stella Laurenzo04259d02023-09-19 13:07:56 -07009load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
Geoffrey Martin-Noblef5b323e2021-01-12 18:32:08 -080010
Stella Laurenzoa9d23f62022-12-27 17:28:58 -080011CUDA_TOOLKIT_ROOT_ENV_KEY = "IREE_CUDA_TOOLKIT_ROOT"
12
13# Our CI docker images use a stripped down CUDA directory tree in some
14# images, and it is tailored just to support building key elements.
15# When this is done, the IREE_CUDA_DEPS_DIR env var is set, and we
16# respect that here in order to match the CMake side (which needs it
17# because CUDA toolkit detection differs depending on whether it is
18# stripped down or not).
19# TODO: Simplify this on the CMake/docker side and update here to match.
Scott Todd0636abd2024-09-18 18:58:34 -070020# TODO(#15332): Dockerfiles no longer include these deps. Simplify.
Stella Laurenzoa9d23f62022-12-27 17:28:58 -080021CUDA_DEPS_DIR_FOR_CI_ENV_KEY = "IREE_CUDA_DEPS_DIR"
22
23def cuda_auto_configure_impl(repository_ctx):
24 env = repository_ctx.os.environ
25 cuda_toolkit_root = None
26 iree_repo_alias = repository_ctx.attr.iree_repo_alias
27
28 # Probe environment for CUDA toolkit location.
29 env_cuda_toolkit_root = env.get(CUDA_TOOLKIT_ROOT_ENV_KEY)
30 env_cuda_deps_dir_for_ci = env.get(CUDA_DEPS_DIR_FOR_CI_ENV_KEY)
31 if env_cuda_toolkit_root:
32 cuda_toolkit_root = env_cuda_toolkit_root
33 elif env_cuda_deps_dir_for_ci:
34 cuda_toolkit_root = env_cuda_deps_dir_for_ci
35
36 # Symlink the tree.
37 libdevice_rel_path = "iree_local/libdevice.bc"
38 if cuda_toolkit_root != None:
39 # Symlink top-level directories we care about.
40 repository_ctx.symlink(cuda_toolkit_root + "/include", "include")
41
42 # TODO: Should be probing for the libdevice, as it can change from
43 # version to version.
44 repository_ctx.symlink(
45 cuda_toolkit_root + "/nvvm/libdevice/libdevice.10.bc",
46 libdevice_rel_path,
47 )
48
49 repository_ctx.template(
50 "BUILD",
51 Label("%s//:build_tools/third_party/cuda/BUILD.template" % iree_repo_alias),
52 {
53 "%ENABLED%": "True" if cuda_toolkit_root else "False",
Jacques Pienaar4db7c1a2023-10-19 06:56:00 -070054 "%LIBDEVICE_REL_PATH%": libdevice_rel_path if cuda_toolkit_root else "BUILD",
Stella Laurenzoa9d23f62022-12-27 17:28:58 -080055 "%IREE_REPO_ALIAS%": iree_repo_alias,
56 },
57 )
58
59cuda_auto_configure = repository_rule(
60 environ = [
61 CUDA_DEPS_DIR_FOR_CI_ENV_KEY,
62 CUDA_TOOLKIT_ROOT_ENV_KEY,
63 ],
64 implementation = cuda_auto_configure_impl,
65 attrs = {
66 "iree_repo_alias": attr.string(default = "@iree_core"),
67 },
68)
69
70def configure_iree_cuda_deps(iree_repo_alias = None):
71 maybe(
72 cuda_auto_configure,
73 name = "iree_cuda",
74 iree_repo_alias = iree_repo_alias,
75 )
76
Geoffrey Martin-Noblef5b323e2021-01-12 18:32:08 -080077def configure_iree_submodule_deps(iree_repo_alias = "@", iree_path = "./"):
78 """Configure all of IREE's simple repository dependencies that come from submodules.
79
80 Simple is defined here as just calls to `local_repository` or
81 `new_local_repository`. This assumes you have a directory that includes IREE
82 and all its submodules. Note that fetching a GitHub archive does not include
83 submodules.
84 Yes it is necessary to have both the workspace alias and path argument...
85
86 Args:
87 iree_repo_alias: The alias for the IREE repository.
88 iree_path: The path to the IREE repository containing submodules
89 """
90
91 maybe(
92 native.local_repository,
Geoffrey Martin-Noblef5b323e2021-01-12 18:32:08 -080093 name = "com_google_googletest",
94 path = paths.join(iree_path, "third_party/googletest"),
95 )
96
97 maybe(
98 native.new_local_repository,
99 name = "com_github_dvidelabs_flatcc",
100 build_file = iree_repo_alias + "//:build_tools/third_party/flatcc/BUILD.overlay",
101 path = paths.join(iree_path, "third_party/flatcc"),
102 )
103
Ben Vanika9036492021-06-25 09:39:53 -0700104 maybe(
105 native.new_local_repository,
Geoffrey Martin-Noblea3287612021-08-25 10:53:26 -0700106 name = "vulkan_headers",
Geoffrey Martin-Noblef5b323e2021-01-12 18:32:08 -0800107 build_file = iree_repo_alias + "//:build_tools/third_party/vulkan_headers/BUILD.overlay",
108 path = paths.join(iree_path, "third_party/vulkan_headers"),
109 )
110
111 maybe(
Geoffrey Martin-Noblef5b323e2021-01-12 18:32:08 -0800112 native.local_repository,
Jakub Kuderski3546f2a2023-06-14 13:18:44 -0400113 name = "stablehlo",
114 path = paths.join(iree_path, "third_party/stablehlo"),
Geoffrey Martin-Noblef5b323e2021-01-12 18:32:08 -0800115 )
116
117 maybe(
118 native.local_repository,
119 name = "com_google_benchmark",
120 path = paths.join(iree_path, "third_party/benchmark"),
121 )
122
123 maybe(
Lei Zhangf8e85742023-05-15 08:32:00 -0700124 native.local_repository,
Geoffrey Martin-Noblef5b323e2021-01-12 18:32:08 -0800125 name = "cpuinfo",
Geoffrey Martin-Noblef5b323e2021-01-12 18:32:08 -0800126 path = paths.join(iree_path, "third_party/cpuinfo"),
127 )
128
129 maybe(
130 native.new_local_repository,
Geoffrey Martin-Noblef5b323e2021-01-12 18:32:08 -0800131 name = "spirv_cross",
132 build_file = iree_repo_alias + "//:build_tools/third_party/spirv_cross/BUILD.overlay",
133 path = paths.join(iree_path, "third_party/spirv_cross"),
134 )
Yi Zhangacf3e8d2022-03-28 21:59:35 -0400135
136 maybe(
137 native.new_local_repository,
Stella Laurenzo4cf4b5a2022-12-27 14:01:06 -0800138 name = "tracy_client",
139 build_file = iree_repo_alias + "//:build_tools/third_party/tracy_client/BUILD.overlay",
140 path = paths.join(iree_path, "third_party/tracy"),
141 )
Okwan Kwonc31c8a02023-01-13 16:36:40 -0800142
143 maybe(
144 native.new_local_repository,
145 name = "nccl",
146 build_file = iree_repo_alias + "//:build_tools/third_party/nccl/BUILD.overlay",
147 path = paths.join(iree_path, "third_party/nccl"),
148 )
Scott Toddad321b62023-06-05 14:39:30 -0700149
150 maybe(
151 native.new_local_repository,
152 name = "webgpu_headers",
153 build_file = iree_repo_alias + "//:build_tools/third_party/webgpu-headers/BUILD.overlay",
154 path = paths.join(iree_path, "third_party/webgpu-headers"),
155 )