1# This repository provides files that Soong emits during bp2build (other than
2# converted BUILD files), mostly .bzl files containing constants to support the
3# converted BUILD files.
4load("//build/bazel/rules:soong_injection.bzl", "soong_injection_repository")
5
6soong_injection_repository(name = "soong_injection")
7
8load("//build/bazel/rules:env.bzl", "env_repository")
9
10env_repository(
11    name = "env",
12)
13
14# This repository is a containter for API surface stub libraries.
15load("//build/bazel/rules:api_surfaces_injection.bzl", "api_surfaces_repository")
16
17# TODO: Once BUILD files for stubs are checked-in, this should be converted to a local_repository.
18api_surfaces_repository(name = "api_surfaces")
19
20load("//build/bazel_common_rules/workspace:external.bzl", "import_external_repositories")
21
22import_external_repositories(
23    bazel_skylib = True,
24    io_abseil_py = True,
25)
26
27load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
28
29bazel_skylib_workspace()
30
31local_repository(
32    name = "rules_android",
33    path = "external/bazelbuild-rules_android",
34)
35
36local_repository(
37    name = "rules_license",
38    path = "external/bazelbuild-rules_license",
39)
40
41local_repository(
42    name = "rules_python",
43    path = "external/bazelbuild-rules_python",
44)
45
46local_repository(
47    name = "rules_cc",
48    path = "external/bazelbuild-rules_cc",
49)
50
51register_toolchains(
52    "//prebuilts/build-tools:py_toolchain",
53
54    # For Android rules
55    "//prebuilts/sdk:all",
56
57    # For APEX rules
58    "//build/bazel/rules/apex:all",
59
60    # For partition rules
61    "//build/bazel/rules/partitions:all",
62)
63
64bind(
65    name = "databinding_annotation_processor",
66    actual = "//prebuilts/sdk:compiler_annotation_processor",
67)
68
69bind(
70    name = "android/dx_jar_import",
71    actual = "//prebuilts/sdk:dx_jar_import",
72)
73
74# The r8.jar in prebuilts/r8 happens to have the d8 classes needed
75# for Android app building, whereas the d8.jar in prebuilts/sdk/tools doesn't.
76bind(
77    name = "android/d8_jar_import",
78    actual = "//prebuilts/r8:r8lib-prebuilt",
79)
80
81# TODO(b/201242197): Avoid downloading remote_coverage_tools (on CI) by creating
82# a stub workspace. Test rules (e.g. sh_test) depend on this external dep, but
83# we don't support coverage yet. Either vendor the external dep into AOSP, or
84# cut the dependency from test rules to the external repo.
85local_repository(
86    name = "remote_coverage_tools",
87    path = "build/bazel_common_rules/rules/coverage/remote_coverage_tools",
88)
89
90# Stubbing the local_jdk both ensures that we don't accidentally download remote
91# repositories and allows us to let the Kotlin rules continue to access
92# @local_jdk//jar.
93local_repository(
94    name = "local_jdk",
95    path = "build/bazel/rules/java/stub_local_jdk",
96)
97
98# The following 2 repositories contain prebuilts that are necessary to the Java Rules.
99# They are vendored locally to avoid the need for CI bots to download them.
100local_repository(
101    name = "remote_java_tools",
102    path = "prebuilts/bazel/common/remote_java_tools",
103)
104
105local_repository(
106    name = "remote_java_tools_linux",
107    path = "prebuilts/bazel/linux-x86_64/remote_java_tools_linux",
108)
109
110# TODO(b/253667328): the below 3 repositories are all pointed to shim
111# repositories with targets that will cause failures if they are
112# actually depended on. Eventually we should properly vendor these
113# repositories.
114local_repository(
115    name = "remote_java_tools_darwin_x86_64",
116    path = "prebuilts/bazel/darwin-x86_64/remote_java_tools_darwin",
117)
118
119local_repository(
120    name = "remote_java_tools_darwin_arm64",
121    path = "prebuilts/bazel/darwin-x86_64/remote_java_tools_darwin",
122)
123
124local_repository(
125    name = "remote_java_tools_windows",
126    path = "prebuilts/bazel/darwin-x86_64/remote_java_tools_darwin",
127)
128
129# The following repository contains android_tools prebuilts.
130local_repository(
131    name = "android_tools",
132    path = "prebuilts/bazel/common/android_tools",
133)
134
135# The vendored rules_java repository.
136local_repository(
137    name = "rules_java",
138    path = "external/bazelbuild-rules_java",
139)
140
141register_toolchains(
142    "//prebuilts/jdk/jdk17:runtime_toolchain_definition",
143    "//build/bazel/rules/java:jdk17_host_toolchain_java_definition",
144)
145
146local_repository(
147    name = "kotlin_maven_interface",
148    path = "build/bazel/rules/kotlin/maven_interface",
149)
150
151local_repository(
152    name = "rules_kotlin",
153    path = "external/bazelbuild-kotlin-rules",
154    repo_mapping = {
155        "@maven": "@kotlin_maven_interface",
156        "@bazel_platforms": "@platforms",
157    },
158)
159
160new_local_repository(
161    name = "kotlinc",
162    build_file = "//build/bazel/rules/kotlin:kotlinc.BUILD",
163    path = "external/kotlinc",
164)
165
166register_toolchains("//build/bazel/rules/kotlin:kt_jvm_toolchain_linux")
167
168load("//build/bazel/toolchains/clang/host/linux-x86:cc_toolchain_config.bzl", "cc_register_toolchains")
169
170cc_register_toolchains()
171
172local_repository(
173    name = "io_bazel_rules_go",
174    path = "external/bazelbuild-rules_go",
175)
176
177load(
178    "@io_bazel_rules_go//go:deps.bzl",
179    "go_register_toolchains",
180    "go_rules_dependencies",
181    "go_wrap_sdk",
182)
183
184go_wrap_sdk(
185    name = "go_sdk",
186    # Add coveragedesign to experiments. This is a temporary hack due to two separate issues combinining together
187    # 1. android:
188    # Starting with go 1.20, the standard go sdk does not ship with .a files for the standard libraries
189    # However, this breaks the go rules in build/blueprint. As a temporary workaround, we distribute prebuilts of the standard libaries
190    # in prebuilts/go using GODEBUG='installgoroot=all' in the prebuilt update script
191    #
192    # 2. rules_go:
193    # coverage is not supported in rules_go, and therefore it adds nocoveragedesign to GOEXPERIMENT. This is not an issue for non Android cases
194    # since the go SDK used in those cases does not contain prebuilts of standard libraries. The stdlib is built from scratch with `nocoverageredesign`.
195    #
196    # Without this, we run into isues during compilation
197    # ```
198    # GoCompilePkg build/blueprint/blueprint-deptools.a failed
199    # build/blueprint/deptools/depfile.go:18:2: could not import fmt (object is [go object linux amd64 go1.20.2 GOAMD64=v1 X:unified,regabiwrappers,regabiargs,coverageredesign
200    #                                                                                                                                                          ^^^^^^^^^^^^^^^^
201    # ] expected [go object linux amd64 go1.20.2 GOAMD64=v1 X:unified,regabiwrappers,regabiargs
202    # ```
203    # TODO - b/288456805: Remove this hardcoded experiment value
204    experiments = ["coverageredesign"],
205    # The expected key format is <goos>_<goarch>
206    # The value is any file in the GOROOT for that platform
207    root_files = {
208        "linux_amd64": "@//:prebuilts/go/linux-x86/README.md",
209        "darwin_amd64": "@//prebuilts/go/darwin-x86/README.md",
210    },
211)
212
213go_rules_dependencies()
214
215go_register_toolchains(experiments = [])
216
217local_repository(
218    name = "rules_proto",
219    path = "build/bazel/rules/proto",
220)
221
222local_repository(
223    name = "rules_rust",
224    path = "external/bazelbuild-rules_rust",
225)
226
227new_local_repository(
228    name = "rules_rust_tinyjson",
229    build_file = "@rules_rust//util/process_wrapper:BUILD.tinyjson.bazel",
230    path = "external/rust/crates/tinyjson",
231)
232
233local_repository(
234    name = "rules_testing",
235    path = "external/bazelbuild-rules_testing",
236)
237
238register_toolchains(
239    # The base toolchains need to be registered before <os_arch>
240    # to ensure it is preferably resolved when it's enabled by
241    # base_toolchain_enabled config_setting
242    "//build/bazel/toolchains/rust/bootstrap:rust_toolchain_android_arm64_base",
243    "//build/bazel/toolchains/rust/bootstrap:rust_toolchain_android_arm_base",
244    "//build/bazel/toolchains/rust/bootstrap:rust_toolchain_android_x86_64_base",
245    "//build/bazel/toolchains/rust/bootstrap:rust_toolchain_android_x86_base",
246    "//build/bazel/toolchains/rust:rust_toolchain_android_arm64",
247    "//build/bazel/toolchains/rust:rust_toolchain_android_arm",
248    "//build/bazel/toolchains/rust:rust_toolchain_android_x86_64",
249    "//build/bazel/toolchains/rust:rust_toolchain_android_x86",
250    "build/bazel/toolchains/rust:rust_toolchain_x86_64_unknown-linux-gnu",
251    "build/bazel/toolchains/rust:proto-toolchain",
252)
253