Skip to content

Commit

Permalink
Clean up Bazel workspace rules
Browse files Browse the repository at this point in the history
  * Migrated most WORKSPACE deps to MODULE.bazel (will be required in Bazel 9.x).
  * Use `.bazelversion` to declare Bazel version instead of `USE_BAZEL_VERSION`
    env variable (makes it easier to run locally with same bazel version).
  * Explicitly set `source`/`target` for `dagger.android` api, and use
    `.bazelrc` to set default `source`/`target` for annotation processors.
  * Removed unused bazel common dependencies in WORKSPACE
     * Removed `bazel_skylib`
     * Removed `google_bazel_common`
     * Removed `rules_python`
     * Removed `zlib`
  * Removed obsolete `tools/bazel.rc` config

RELNOTES=N/A
PiperOrigin-RevId: 654352167
  • Loading branch information
bcorso authored and Dagger Team committed Jul 21, 2024
1 parent 140e201 commit 97d1183
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 139 deletions.
24 changes: 24 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,27 @@ build --host_javacopt=-g
# TODO(ronshapiro): explore how much work it would be to reenable this
build --javacopt="-Xep:BetaApi:OFF"
build --host_javacopt="-Xep:BetaApi:OFF"

# Enable Bzlmod for every Bazel command. This flag will be enabled by default in
# Bazel 7.0.0, but for now we enable it manually.
common --enable_bzlmod

# Note: This flag is required to prevent actions from clashing with each when
# reading/writing tmp files. Without this flag we get errors like:
#
# Error: Cannot use file /tmp/hsperfdata_runner/12 because it is locked by
# another process
#
# This flag will be enabled by default in Bazel 7.0.0, but for now we enable it
# manually. For more details: https://github.com/bazelbuild/bazel/issues/3236.
build --incompatible_sandbox_hermetic_tmp

# Sets the JDK for compiling sources and executing tests.
build --java_language_version=11
build --tool_java_language_version=11
build --java_runtime_version=remotejdk_11
build --tool_java_runtime_version=remotejdk_11

# Sets the default source/target for Dagger's processors. Note that Dagger's api
# libraries can target JDK 8, so we set it explicitly on the Bazel target.
build --javacopt="-source 8 -target 11"
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.4.0
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ env:
USE_JAVA_VERSION: '11'
# This is required by AGP 8.3+.
USE_JAVA_VERSION_FOR_PLUGIN: '17'
# Our Bazel builds currently rely on 6.4.0. The version is set via
# baselisk by USE_BAZEL_VERSION: https://github.com/bazelbuild/bazelisk.
USE_BAZEL_VERSION: '6.4.0'
# The default Maven 3.9.0 has a regression so we manually install 3.8.7.
# https://issues.apache.org/jira/browse/MNG-7679
USE_MAVEN_VERSION: '3.8.7'
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ env:
USE_JAVA_VERSION: '11'
# This is required by AGP 8.3+.
USE_JAVA_VERSION_FOR_PLUGIN: '17'
# Our Bazel builds currently rely on 6.4.0. The version is set via
# baselisk by USE_BAZEL_VERSION: https://github.com/bazelbuild/bazelisk.
USE_BAZEL_VERSION: '6.4.0'
DAGGER_RELEASE_VERSION: "${{ github.event.inputs.dagger_release_version }}"
# The default Maven 3.9.0 has a regression so we manually install 3.8.7.
# https://issues.apache.org/jira/browse/MNG-7679
Expand Down
40 changes: 40 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (C) 2024 The Dagger Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

bazel_dep(
name = "bazel_skylib",
version = "1.7.1",
)

bazel_dep(
name = "rules_java",
version = "7.0.6",
)

bazel_dep(
name = "rules_kotlin",
version = "1.9.0",
repo_name = "io_bazel_rules_kotlin",
)

bazel_dep(
name = "rules_jvm_external",
version = "5.3",
)

bazel_dep(
name = "rules_robolectric",
version = "4.11.1",
repo_name = "robolectric",
)
122 changes: 2 additions & 120 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# limitations under the License.


load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

#############################
# Load nested repository
#############################
Expand All @@ -26,37 +24,6 @@ local_repository(
path = "examples/bazel",
)

#############################
# Load Bazel Skylib rules
#############################

BAZEL_SKYLIB_VERSION = "1.5.0"

BAZEL_SKYLIB_SHA = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94"

http_archive(
name = "bazel_skylib",
sha256 = BAZEL_SKYLIB_SHA,
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/%s/bazel-skylib-%s.tar.gz" % (BAZEL_SKYLIB_VERSION, BAZEL_SKYLIB_VERSION),
"https://github.com/bazelbuild/bazel-skylib/releases/download/%s/bazel-skylib-%s.tar.gz" % (BAZEL_SKYLIB_VERSION, BAZEL_SKYLIB_VERSION),
],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

#############################
# Load rules_java repository
#############################

http_archive(
name = "rules_java",
sha256 = "c73336802d0b4882e40770666ad055212df4ea62cfa6edf9cb0f9d29828a0934",
url = "https://github.com/bazelbuild/rules_java/releases/download/5.3.5/rules_java-5.3.5.tar.gz",
)

#############################
# Load Android Sdk
#############################
Expand All @@ -67,84 +34,10 @@ android_sdk_repository(
build_tools_version = "32.0.0",
)

####################################################
# Load Protobuf repository (needed by bazel-common)
####################################################

http_archive(
name = "rules_proto",
# output from `sha256sum` on the downloaded tar.gz file
sha256 = "66bfdf8782796239d3875d37e7de19b1d94301e8972b3cbd2446b332429b4df1",
strip_prefix = "rules_proto-4.0.0",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0.tar.gz",
"https://github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0.tar.gz",
],
)

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")

rules_proto_dependencies()

rules_proto_toolchains()

#############################
# Load Protobuf dependencies
#############################

# rules_python and zlib are required by protobuf.
# TODO(ronshapiro): Figure out if zlib is in fact necessary, or if proto can depend on the
# @bazel_tools library directly. See discussion in
# https://github.com/protocolbuffers/protobuf/pull/5389#issuecomment-481785716
# TODO(cpovirk): Should we eventually get rules_python from "Bazel Federation?"
# https://github.com/bazelbuild/rules_python#getting-started

http_archive(
name = "rules_python",
sha256 = "e5470e92a18aa51830db99a4d9c492cc613761d5bdb7131c04bd92b9834380f6",
strip_prefix = "rules_python-4b84ad270387a7c439ebdccfd530e2339601ef27",
urls = ["https://github.com/bazelbuild/rules_python/archive/4b84ad270387a7c439ebdccfd530e2339601ef27.tar.gz"],
)

http_archive(
name = "zlib",
build_file = "@com_google_protobuf//:third_party/zlib.BUILD",
sha256 = "629380c90a77b964d896ed37163f5c3a34f6e6d897311f1df2a7016355c45eff",
strip_prefix = "zlib-1.2.11",
urls = ["https://github.com/madler/zlib/archive/v1.2.11.tar.gz"],
)

#############################
# Load Robolectric repository
#############################

ROBOLECTRIC_VERSION = "4.4"

http_archive(
name = "robolectric",
sha256 = "d4f2eb078a51f4e534ebf5e18b6cd4646d05eae9b362ac40b93831bdf46112c7",
strip_prefix = "robolectric-bazel-%s" % ROBOLECTRIC_VERSION,
urls = ["https://github.com/robolectric/robolectric-bazel/archive/%s.tar.gz" % ROBOLECTRIC_VERSION],
)

load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")

robolectric_repositories()

#############################
# Load Kotlin repository
#############################

RULES_KOTLIN_TAG = "v1.8"

RULES_KOTLIN_SHA = "01293740a16e474669aba5b5a1fe3d368de5832442f164e4fbfc566815a8bc3a"

http_archive(
name = "io_bazel_rules_kotlin",
sha256 = RULES_KOTLIN_SHA,
urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/%s/rules_kotlin_release.tgz" % RULES_KOTLIN_TAG],
)

load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "kotlinc_version")

KOTLIN_VERSION = "1.9.23"
Expand All @@ -167,17 +60,6 @@ kt_register_toolchains()
# Load Maven dependencies
#############################

RULES_JVM_EXTERNAL_TAG = "4.5"

RULES_JVM_EXTERNAL_SHA = "b17d7388feb9bfa7f2fa09031b32707df529f26c91ab9e5d909eb1676badd9a6"

http_archive(
name = "rules_jvm_external",
sha256 = RULES_JVM_EXTERNAL_SHA,
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)

load("@rules_jvm_external//:defs.bzl", "maven_install")

ANDROID_LINT_VERSION = "30.1.0"
Expand Down Expand Up @@ -301,8 +183,8 @@ maven_install(
"org.ow2.asm:asm:%s" % ASM_VERSION,
"org.ow2.asm:asm-tree:%s" % ASM_VERSION,
"org.ow2.asm:asm-commons:%s" % ASM_VERSION,
"org.robolectric:robolectric:4.4",
"org.robolectric:shadows-framework:4.4", # For ActivityController
"org.robolectric:robolectric:%s" % ROBOLECTRIC_VERSION,
"org.robolectric:shadows-framework:%s" % ROBOLECTRIC_VERSION, # For ActivityController
],
repositories = [
"https://repo1.maven.org/maven2",
Expand Down
2 changes: 1 addition & 1 deletion build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DOCLINT_HTML_AND_SYNTAX = ["-Xdoclint:html,syntax"]
DOCLINT_REFERENCES = ["-Xdoclint:reference"]

JAVA_RELEASE_MIN = [
"-source 7 -target 7",
"-source 8 -target 8",
]

POM_VERSION = "${project.version}"
3 changes: 3 additions & 0 deletions java/dagger/android/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

load(
"//:build_defs.bzl",
"DOCLINT_HTML_AND_SYNTAX",
"JAVA_RELEASE_MIN",
"POM_VERSION",
)
load("//tools:dejetify.bzl", "dejetified_library")
Expand All @@ -43,6 +45,7 @@ filegroup(
android_library(
name = "android",
srcs = SRCS,
javacopts = JAVA_RELEASE_MIN + DOCLINT_HTML_AND_SYNTAX,
plugins = [
"//java/dagger/android/internal/proguard:plugin",
],
Expand Down
3 changes: 3 additions & 0 deletions java/dagger/android/support/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

load(
"//:build_defs.bzl",
"DOCLINT_HTML_AND_SYNTAX",
"JAVA_RELEASE_MIN",
"POM_VERSION",
)
load("//tools:dejetify.bzl", "dejetified_library")
Expand All @@ -36,6 +38,7 @@ filegroup(
android_library(
name = "support",
srcs = glob(["*.java"]),
javacopts = JAVA_RELEASE_MIN + DOCLINT_HTML_AND_SYNTAX,
tags = ["maven_coordinates=com.google.dagger:dagger-android-support:" + POM_VERSION],
deps = [
"//:dagger_with_compiler",
Expand Down
1 change: 1 addition & 0 deletions test_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

load("@rules_java//java:defs.bzl", "java_library", "java_test")
load("//:build_defs.bzl", "JAVA_RELEASE_MIN")

load(
"@io_bazel_rules_kotlin//kotlin:kotlin.bzl",
"kt_jvm_library",
Expand Down
11 changes: 0 additions & 11 deletions tools/bazel.rc

This file was deleted.

5 changes: 4 additions & 1 deletion tools/maven/maven.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,10 @@ def _validate_list(name, actual_list, expected_list, banned_list = []):
fail("\t[Error]: Found banned {}: \n\t\t".format(name) + "\n\t\t".join(banned))

def _strip_artifact_version(artifact):
return artifact.rsplit(":", 1)[0]
artifact = artifact.rsplit(":", 1)[0]
if artifact.endswith(":aar"):
return artifact.rsplit(":aar", 1)[0]
return artifact

_validate_maven_deps = rule(
implementation = _validate_maven_deps_impl,
Expand Down

0 comments on commit 97d1183

Please sign in to comment.