Skip to content

Commit

Permalink
Introduce more dependencies in Bazel Bzlmod build
Browse files Browse the repository at this point in the history
Working towards: bazelbuild#18957

RELNOTES:
PiperOrigin-RevId: 552886589
Change-Id: I2d170deae5bdaf05dbece4779ffb5b1137ee7b81
  • Loading branch information
meteorcloudy authored and copybara-github committed Aug 1, 2023
1 parent 32df891 commit cf14039
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 21 deletions.
89 changes: 68 additions & 21 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# To build Bazel with Bzlmod: `bazel build --enable_bzlmod //src:bazel_nojdk`.

module(
name = "bazel",
version = "7.0.0-pre",
Expand All @@ -20,15 +18,33 @@ bazel_dep(name = "rules_cc", version = "0.0.8")
bazel_dep(name = "rules_java", version = "6.3.0")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(name = "rules_jvm_external", version = "5.2")
bazel_dep(name = "rules_python", version = "0.19.0")
bazel_dep(name = "rules_python", version = "0.24.0")
bazel_dep(name = "rules_testing", version = "0.0.4")

# TODO(pcloudy): Add remoteapis and googleapis as Bazel modules in the BCR.
bazel_dep(name = "remoteapis", version = "")
bazel_dep(name = "googleapis", version = "")

single_version_override(
module_name = "rules_jvm_external",
patch_strip = 1,
patches = ["//third_party:rules_jvm_external_5.2.patch"],
)

local_path_override(
module_name = "remoteapis",
path = "./third_party/remoteapis",
)

local_path_override(
module_name = "googleapis",
path = "./third_party/googleapis",
)

# =========================================
# Bazel Java dependencies
# =========================================

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
# We don't yet specify the maven coordinates in the MODULE.bazel to avoid duplicating information.
Expand All @@ -41,35 +57,66 @@ maven.install(
)
use_repo(maven, "maven")

# TODO(pcloudy): Add remoteapis and googleapis as Bazel modules in the BCR.
bazel_dep(name = "remoteapis", version = "")
bazel_dep(name = "googleapis", version = "")

local_path_override(
module_name = "remoteapis",
path = "./third_party/remoteapis",
)

local_path_override(
module_name = "googleapis",
path = "./third_party/googleapis",
)
# =========================================
# Other Bazel internal dependencies
# - embedded JDKs
# - repos for Debian build
# =========================================

bazel_internal_deps = use_extension("//:extensions.bzl", "bazel_internal_deps")
use_repo(
bazel_internal_deps,
"openjdk_linux_vanilla",
"debian_cc_deps",
"openjdk_linux_aarch64_vanilla",
"openjdk_linux_ppc64le_vanilla",
"openjdk_linux_s390x_vanilla",
"openjdk_macos_x86_64_vanilla",
"openjdk_linux_vanilla",
"openjdk_macos_aarch64_vanilla",
"openjdk_win_vanilla",
"openjdk_macos_x86_64_vanilla",
"openjdk_win_arm64_vanilla",
"openjdk_win_vanilla",
)

# =========================================
# Register platforms & toolchains
# =========================================

register_execution_platforms("//:default_host_platform")

register_toolchains("@bazel_tools//tools/python:autodetecting_toolchain")

# Dev dependencies
register_toolchains("//src/main/res:empty_rc_toolchain")

# =========================================
# Android tools dependencies
# =========================================

maven_android = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven_android.install(
name = "maven_android",
# We don't yet specify the maven coordinates in the MODULE.bazel to avoid duplicating information.
# Always respect the maven_install.json file generated by rules_jvm_external from the WORKSPACE file.
# TODO(pcloudy): We should add maven coordinates here when we enable Bzlmod in the default build for Bazel.
lock_file = "//src/tools/android:maven_android_install.json",
repositories = [
"https://dl.google.com/android/maven2",
"https://repo1.maven.org/maven2",
],
)
use_repo(maven_android, "maven_android")

bazel_android_deps = use_extension("//:extensions.bzl", "bazel_android_deps")
use_repo(
bazel_android_deps,
"android_gmaven_r8",
"desugar_jdk_libs",
)

# =========================================
# Bazel dev dependencies
# =========================================

bazel_dep(name = "googletest", version = "1.12.1", repo_name = "com_google_googletest")

bazel_dep(name = "googletest", version = "1.12.1", repo_name = "com_google_googletest", dev_dependency = True)
bazel_dev_deps = use_extension("//:extensions.bzl", "bazel_dev_deps")
use_repo(bazel_dev_deps, "local_bazel_source_list")
52 changes: 52 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -1,2 +1,54 @@
# This file will replace the content of the WORKSPACE file when Bzlmod is enabled
# No WORKSPACE prefix or suffix are added.

bind(
name = "android/sdk",
actual = "@bazel_tools//tools/android:poison_pill_android_sdk",
)

bind(
name = "android/dx_jar_import",
actual = "@bazel_tools//tools/android:no_android_sdk_repository_error",
)

bind(
name = "android/d8_jar_import",
actual = "@bazel_tools//tools/android:no_android_sdk_repository_error",
)

bind(
name = "android/crosstool",
actual = "@bazel_tools//tools/cpp:toolchain",
)

bind(
name = "android_sdk_for_testing",
actual = "@bazel_tools//tools/android:empty",
)

bind(
name = "android_ndk_for_testing",
actual = "@bazel_tools//tools/android:empty",
)

bind(
name = "databinding_annotation_processor",
actual = "@bazel_tools//tools/android:empty",
)

# This value is overridden by android_sdk_repository function to allow targets
# to select on whether or not android_sdk_repository has run.
bind(
name = "has_androidsdk",
actual = "@bazel_tools//tools/android:always_false",
)

# To run the Android integration tests in //src/test/shell/bazel/android:all or
# build the Android sample app in //examples/android/java/bazel:hello_world
#
# 1. Install an Android SDK and NDK from https://developer.android.com
# 2. Set the $ANDROID_HOME and $ANDROID_NDK_HOME environment variables
# 3. Uncomment the two lines below
#
# android_sdk_repository(name = "androidsdk")
# android_ndk_repository(name = "androidndk")
21 changes: 21 additions & 0 deletions extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,29 @@
"""

load("//:repositories.bzl", "embedded_jdk_repositories")
load("//:distdir.bzl", "dist_http_archive", "dist_http_jar")
load("//tools/distributions/debian:deps.bzl", "debian_deps")
load("//src/test/shell/bazel:list_source_repository.bzl", "list_source_repository")

### Extra dependencies for building Bazel

def _bazel_internal_deps(_ctx):
embedded_jdk_repositories()
debian_deps()

bazel_internal_deps = module_extension(implementation = _bazel_internal_deps)

### Extra dependencies for testing Bazel

def _bazel_dev_deps(_ctx):
list_source_repository(name = "local_bazel_source_list")

bazel_dev_deps = module_extension(implementation = _bazel_dev_deps)

### Extra dependencies for Bazel Android tools

def _bazel_android_deps(_ctx):
dist_http_jar(name = "android_gmaven_r8")
dist_http_archive(name = "desugar_jdk_libs")

bazel_android_deps = module_extension(implementation = _bazel_android_deps)

0 comments on commit cf14039

Please sign in to comment.