Skip to content

Commit

Permalink
Merge pull request #90 from menny/bazel-6
Browse files Browse the repository at this point in the history
Bazel 6
  • Loading branch information
menny authored Apr 4, 2023
2 parents 99ece6e + 565ba5f commit 98ac875
Show file tree
Hide file tree
Showing 62 changed files with 809 additions and 488 deletions.
7 changes: 7 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test --sandbox_tmpfs_path=/tmp

build --java_runtime_version=remotejdk_11
build --tool_java_runtime_version=remotejdk_11
build --java_language_version=11

test --build_tests_only
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.0
6.1.0
14 changes: 7 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ on:

jobs:
checks:
runs-on: ubuntu-18.04
container: menny/android_bazel:1.13.8
runs-on: ubuntu-22.04
container: ghcr.io/menny/android_bazel:1.17.0
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3.5.0
with:
fetch-depth: 1
- name: build
Expand All @@ -27,15 +27,15 @@ jobs:
- name: verify-rules-generation
run: ./scripts/ci_verify_rules_generation.sh
examples:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
needs: [checks]
container: menny/android_bazel:1.13.8
container: ghcr.io/menny/android_bazel:1.17.0
strategy:
matrix:
example_name: [plain_java, java_plugin, android, kotlin]
example_name: [plain_java, java_plugin, android, kotlin, android-kotlin]
fail-fast: false
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3.5.0
with:
fetch-depth: 1
- name: build-examples
Expand Down
13 changes: 13 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")

alias(
name = "buildifier_bin",
actual = select({
"//platforms:darwin_arm64": "@buildifier_darwin_arm64//file",
"//platforms:darwin_x86": "@buildifier_darwin_amd64//file",
"//platforms:linux_arm64": "@buildifier_linux_arm64//file",
"//platforms:linux_x86": "@buildifier_linux_amd64//file",
"//platforms:windows_x86": "@buildifier_windows_amd64//file",
}),
)

buildifier(
name = "buildifier_fix",
buildifier = ":buildifier_bin",
lint_mode = "fix",
lint_warnings = ["all"],
)

buildifier(
name = "buildifier",
buildifier = ":buildifier_bin",
lint_mode = "warn",
lint_warnings = ["all"],
mode = "check",
Expand Down
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,34 @@ There are several attempts to solve this problem (such as [sync-deps](https://gi
## Example

### WORKSPACE file
Add this repository to your WORKSPACE (set `bazel_mvn_deps_version` to the latest [release](https://github.com/menny/mabel/releases) or, if you are adventurous, [commit](https://github.com/menny/mabel/commits/master)):
Add this repository to your WORKSPACE (set `mabel_version` to the latest [release](https://github.com/menny/mabel/releases) or, if you are adventurous, [commit](https://github.com/menny/mabel/commits/main)):
```python
# We'll need the java_rules already setup, you probably have that already anyway:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_java",
urls = [
"https://github.com/bazelbuild/rules_java/releases/download/5.5.0/rules_java-5.5.0.tar.gz",
],
sha256 = "bcfabfb407cb0c8820141310faa102f7fb92cc806b0f0e26a625196101b0b57e",
)
load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")
rules_java_dependencies()
rules_java_toolchains()

# Actual mabel setup
# Check out the release page for the latest version
mabel_version = "0.20.0"
mabel_sha = "eeeb41abe0e4199bcbebe6c5f5d8d6221863f67fd140878dfafd5b8d028a7456"
http_archive(
name = "mabel",
urls = ["https://github.com/menny/mabel/archive/%s.zip" % mabel_version],
type = "zip",
sha256 = mabel_sha,
strip_prefix = "mabel-%s" % mabel_version
)

load("@mabel//:init_deps.bzl", "init_mabel_deps")
init_mabel_deps()
load("@mabel//:init_rules.bzl", "init_mabel_rules")
init_mabel_rules()
```
Expand Down
55 changes: 25 additions & 30 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,47 +1,42 @@
workspace(name = "mabel")

load("//:init_deps.bzl", "init_mabel_deps")

init_mabel_deps()

load("//:init_rules.bzl", "init_mabel_rules")

init_mabel_rules()

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

#### Below: Buildifier setup, which is only for local development
# buildifier is written in Go and hence needs rules_go to be built.
# See https://github.com/bazelbuild/rules_go for the up to date setup instructions.
http_archive(
name = "io_bazel_rules_go",
sha256 = "a8d6b1b354d371a646d2f7927319974e0f9e52f73a2452d2b3877118169eb6bb",
name = "rules_java",
sha256 = "bcfabfb407cb0c8820141310faa102f7fb92cc806b0f0e26a625196101b0b57e",
urls = [
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/v0.23.3/rules_go-v0.23.3.tar.gz",
"https://github.com/bazelbuild/rules_go/releases/download/v0.23.3/rules_go-v0.23.3.tar.gz",
"https://github.com/bazelbuild/rules_java/releases/download/5.5.0/rules_java-5.5.0.tar.gz",
],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@rules_java//java:repositories.bzl", "remote_jdk19_repos", "rules_java_dependencies", "rules_java_toolchains")

go_rules_dependencies()
rules_java_dependencies()

go_register_toolchains()
remote_jdk19_repos()

http_archive(
name = "com_google_protobuf",
sha256 = "36f81e03a0702f8f935fffd5a486dac1c0fc6d4bae1cd02c7a32448ad6e63bcb",
strip_prefix = "protobuf-3.17.2",
url = "https://github.com/protocolbuffers/protobuf/archive/v3.17.2.tar.gz",
)
rules_java_toolchains()

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@//:init_rules.bzl", "init_mabel_rules")

protobuf_deps()
init_mabel_rules()

http_archive(
name = "com_github_bazelbuild_buildtools",
sha256 = "c28eef4d30ba1a195c6837acf6c75a4034981f5b4002dda3c5aa6e48ce023cf1",
strip_prefix = "buildtools-4.0.1",
url = "https://github.com/bazelbuild/buildtools/archive/4.0.1.tar.gz",
name = "platforms",
sha256 = "5308fc1d8865406a49427ba24a9ab53087f17f5266a7aabbfc28823f3916e1ca",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.6/platforms-0.0.6.tar.gz",
"https://github.com/bazelbuild/platforms/releases/download/0.0.6/platforms-0.0.6.tar.gz",
],
)

load("@//:buildifier.bzl", "init_buildifier")

init_buildifier()

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.17.2")
69 changes: 69 additions & 0 deletions buildifier.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""
buildifier support
"""

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

_BUILDIFIER_VERSION = "6.1.0"
_BUILDIFIER_URL = "https://github.com/bazelbuild/buildtools/releases/download"

def init_buildifier():
"""
Initializing buildifier
"""

# buildifier is written in Go and hence needs rules_go to be built.
# See https://github.com/bazelbuild/rules_go for the up to date setup instructions.
http_archive(
name = "io_bazel_rules_go",
sha256 = "d6b2513456fe2229811da7eb67a444be7785f5323c6708b38d851d2b51e54d83",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.30.0/rules_go-v0.30.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.30.0/rules_go-v0.30.0.zip",
],
)

http_archive(
name = "com_github_bazelbuild_buildtools",
sha256 = "a75c337f4d046e560298f52ae95add73b9b933e4d6fb01ed86d57313e53b68e6",
strip_prefix = "buildtools-{}".format(_BUILDIFIER_VERSION),
urls = [
"https://github.com/bazelbuild/buildtools/archive/refs/tags/{}.tar.gz".format(_BUILDIFIER_VERSION),
],
)

http_file(
name = "buildifier_darwin_amd64",
url = "{}/{}/buildifier-darwin-amd64".format(_BUILDIFIER_URL, _BUILDIFIER_VERSION),
sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b812",
downloaded_file_path = "buildifier",
executable = True,
)
http_file(
name = "buildifier_darwin_arm64",
url = "{}/{}/buildifier-darwin-amd64".format(_BUILDIFIER_URL, _BUILDIFIER_VERSION),
sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852a812",
downloaded_file_path = "buildifier",
executable = True,
)
http_file(
name = "buildifier_linux_amd64",
url = "{}/{}/buildifier-linux-amd64".format(_BUILDIFIER_URL, _BUILDIFIER_VERSION),
sha256 = "0b51a6cb81bc3b51466ea2210053992654987a907063d0c2b9c03be29de52eff",
downloaded_file_path = "buildifier",
executable = True,
)
http_file(
name = "buildifier_linux_arm64",
url = "{}/{}/buildifier-linux-arm64".format(_BUILDIFIER_URL, _BUILDIFIER_VERSION),
sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495911b7852b812",
downloaded_file_path = "buildifier",
executable = True,
)
http_file(
name = "buildifier_windows_amd64",
url = "{}/{}/buildifier-windows-amd64.exe".format(_BUILDIFIER_URL, _BUILDIFIER_VERSION),
sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495911b1852b112",
downloaded_file_path = "buildifier.exe",
executable = True,
)
2 changes: 1 addition & 1 deletion examples/android-kotlin/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.0
6.1.0
28 changes: 11 additions & 17 deletions examples/android-kotlin/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,38 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"],
)

# Configure Android SDK Path
load("@build_bazel_rules_android//android:rules.bzl", "android_sdk_repository")

android_sdk_repository(
name = "androidsdk",
api_level = 29,
build_tools_version = "29.0.2",
)

### Kotlin rules
rules_kotlin_version = "1.7.1"

rules_kotlin_sha = "fd92a98bd8a8f0e1cdcb490b93f5acef1f1727ed992571232d33de42395ca9b3"

http_archive(
name = "io_bazel_rules_kotlin",
sha256 = "eeae65f973b70896e474c57aa7681e444d7a5446d9ec0a59bb88c59fc263ff62",
urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/v1.5.0-alpha-3/rules_kotlin_release.tgz"],
sha256 = rules_kotlin_sha,
urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/v%s/rules_kotlin_release.tgz" % rules_kotlin_version],
)

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

KOTLIN_COMPILER_RELEASE = {
"sha256": "ccd0db87981f1c0e3f209a1a4acb6778f14e63fe3e561a98948b5317e526cc6c",
"urls": [
"https://github.com/JetBrains/kotlin/releases/download/v1.3.72/kotlin-compiler-1.3.72.zip",
],
}
kotlin_repositories() # if you want the default. Otherwise see custom kotlinc distribution below

kotlin_repositories(compiler_release = KOTLIN_COMPILER_RELEASE)
load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")

kt_register_toolchains()
kt_register_toolchains() # to use the default toolchain, otherwise see toolchains below

# Of course, this `local_repository` should be `http_archive` in your project (read the README.md file at the root)
local_repository(
name = "mabel",
path = "../../",
)

load("@mabel//:init_deps.bzl", "init_mabel_deps")

init_mabel_deps()

load("@mabel//:init_rules.bzl", "init_mabel_rules")

init_mabel_rules()
Expand Down
7 changes: 6 additions & 1 deletion examples/android-kotlin/program/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ load(":g_artifact.bzl", "g_artifact")

generate_transitive_dependency_targets(
aar_import = aar_import,
kt_android_library = kt_android_library,
)

mabel_rule(
Expand Down Expand Up @@ -37,6 +36,11 @@ mabel_rule(
],
)

kt_android_library(
name = "lib",
srcs = ["StringFormat.kt"],
)

android_binary(
name = "app",
srcs = ["HelloActivity.java"],
Expand All @@ -52,6 +56,7 @@ android_binary(
resource_files = glob(["res/**/*"]),
visibility = ["//visibility:public"],
deps = [
":lib",
"//program:androidx_fragment__fragment",
"//program/main_deps/androidx/annotation/annotation",
"//program/main_deps/androidx/appcompat/appcompat",
Expand Down
4 changes: 4 additions & 0 deletions examples/android-kotlin/program/HelloActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.evendanan.bazel.mvn.example;

import android.app.Activity;
import android.widget.TextView;
import android.content.Intent;
import android.os.Bundle;

Expand All @@ -13,5 +14,8 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main_activity);

TextView t = findViewById(R.id.root_content);
t.setText(new StringFormat().hello("mabel"));
}
}
5 changes: 5 additions & 0 deletions examples/android-kotlin/program/StringFormat.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.evendanan.bazel.mvn.example;

class StringFormat {
fun hello(name: String) = "Hello, ${name}"
}
Loading

0 comments on commit 98ac875

Please sign in to comment.