Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for Bazel 5 #110

Merged
merged 10 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ test --noincompatible_strict_action_env
build:ci --repo_env=CC=clang
build:ci --features=layering_check

# Requires Bazel 5.
build:bzlmod --experimental_enable_bzlmod
build:bzlmod --enable_bzlmod
build:workspace --noexperimental_enable_bzlmod

test --test_output=errors
2 changes: 1 addition & 1 deletion .github/workflows/check-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Go environment
uses: actions/setup-go@v2
with:
go-version: '^1.15.5'
go-version: '^1.22'

- name: Install formatters
run: |
Expand Down
38 changes: 22 additions & 16 deletions .github/workflows/run-tests-externally.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,40 @@ jobs:
strategy:
fail-fast: false
matrix:
bazel: [5.0.0, latest, last_green]
bazel: [6.x, 7.x, last_green]
bazel_mode: [workspace, module]
os: [ubuntu-latest, macos-latest, windows-2019]
jdk: [8, 11, 17]
os: [ubuntu-latest, macos-13, macos-latest, windows-2019]
jdk: [8, 11, 17, 21]
exclude:
- bazel: 5.0.0
- bazel: 6.x
jdk: 11
- bazel: 5.0.0
- bazel: 6.x
jdk: 17
- bazel: 5.0.0
bazel_mode: module
- bazel: 6.x
jdk: 21
- bazel: last_green
jdk: 8
- bazel: last_green
jdk: 11
- bazel_mode: module
jdk: 8
- bazel_mode: module
jdk: 11
- bazel: last_green
jdk: 17
- bazel_mode: workspace
jdk: 17
- bazel_mode: workspace
jdk: 21
include:
- os: ubuntu-latest
cache: "/home/runner/.cache/bazel-disk"
- os: macos-13
cache: "/private/var/tmp/bazel-disk"
- os: macos-latest
cache: "/private/var/tmp/bazel-disk"
bazel_macos_args: "--xcode_version_config=//.github:host_xcodes"
- os: windows-2019
cache: "C:\\tmp\\bazel-disk"
- bazel_mode: module
bazel_extra_args: "--config=bzlmod"
- bazel_mode: workspace
bazel_extra_args: "--config=workspace"
name: Test externally (${{ matrix.os }}, Bazel ${{ matrix.bazel }} ${{ matrix.bazel_mode }}, JDK ${{ matrix.jdk }})
env:
BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -54,8 +59,9 @@ jobs:
- uses: actions/checkout@v2

- name: Set up JDK
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: ${{ matrix.jdk }}

- name: Mount Bazel disk cache
Expand All @@ -73,16 +79,16 @@ jobs:
env:
USE_BAZEL_VERSION: ${{ matrix.bazel }}
working-directory: ./tests
run: bazelisk test --config=ci --disk_cache=${{ matrix.cache }} --profile=${{ github.workspace }}/profile.gz ${{ matrix.bazel_extra_args }} ${{ matrix.bazel_macos_args }} //...
run: bazelisk test --config=ci --disk_cache=${{ matrix.cache }} --profile=${{ github.workspace }}/profile.gz ${{ matrix.bazel_extra_args }} //...

- name: Check coverage
if: ${{ (matrix.os == 'ubuntu-latest') && (matrix.jdk == '11') }}
if: ${{ (matrix.os == 'ubuntu-latest') && (matrix.jdk == '17') }}
env:
USE_BAZEL_VERSION: ${{ matrix.bazel }}
working-directory: ./tests
run: |
sudo apt install clang-14 llvm-14
bazelisk coverage --config=ci --disk_cache=${{ matrix.cache }} --profile=${{ github.workspace }}/profile.gz ${{ matrix.bazel_extra_args }} ${{ matrix.bazel_macos_args }} //...
bazelisk coverage --config=ci --disk_cache=${{ matrix.cache }} --profile=${{ github.workspace }}/profile.gz ${{ matrix.bazel_extra_args }} //...
./verify_coverage.sh

- name: Upload test logs
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/run-tests-internally.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ jobs:
runs-on: ubuntu-latest
env:
BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Build and test internally (ubuntu-latest, Bazel last_green workspace, JDK 17)
name: Build and test internally (ubuntu-latest, Bazel last_green workspace, JDK 21)

steps:
- uses: actions/checkout@v2

- name: Set up JDK
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu'
java-version: 21

- name: Mount Bazel disk cache
uses: actions/cache@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.ijwb
.clwb
.vscode
bazel-*
MODULE.bazel.lock
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "rules_license", version = "0.0.7")

bazel_dep(name = "apple_support", version = "1.15.1", dev_dependency = True, repo_name = "build_bazel_apple_support")

download_jdk_deps = use_extension(
"@rules_jni//bzlmod:extensions.bzl",
"download_jdk_deps",
Expand Down
38 changes: 15 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ not covered by the native Bazel rules:

## Setup

Add the following snippet to your `WORKSPACE`:
If you are [MODULE.bazel](https://bazel.build/external/overview#bzlmod), add the following to your
`MODULE.bazel`:

```starlark
bazel_dep(name = "rules_jni", version = "<latest release>")
# Alternatively, to keep using the repository as @fmeum_rules_jni, use:
bazel_dep(name = "rules_jni", version = "<latest release>", repo_name = "fmeum_rules_jni")
```

Otherwise, add the following snippet to your `WORKSPACE`:

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

http_archive(
name = "fmeum_rules_jni",
sha256 = "9a387a066f683a8aac4d165917dc7fe15ec2a20931894a97e153a9caab6123ca",
strip_prefix = "rules_jni-0.4.0",
url = "https://github.com/fmeum/rules_jni/archive/refs/tags/v0.4.0.tar.gz",
sha256 = "<sha of the release tarball>",
strip_prefix = "rules_jni-<latest release>",
url = "https://github.com/fmeum/rules_jni/archive/refs/tags/v<latest release>.tar.gz",
)

load("@fmeum_rules_jni//jni:repositories.bzl", "rules_jni_dependencies")

rules_jni_dependencies()
```

If you are using Bazel 5 with [bzlmod](https://docs.bazel.build/versions/main/bzlmod.html), add the following to your
`MODULE.bazel`:

```starlark
bazel_dep(name = "rules_jni", version = "0.4.0")
# Alternatively, to keep using the repository as @fmeum_rules_jni, use:
bazel_dep(name = "rules_jni", version = "0.4.0", repo_name = "fmeum_rules_jni")
```

## Documentation

See the documentation for [targets](docs/targets.md), [rules](docs/rules.md)
Expand All @@ -57,9 +57,8 @@ Bazel runfiles using the

## Compatibility

rules_jni heavily uses [platforms](https://docs.bazel.build/versions/main/platforms.html) and thus requires at least
Bazel 4.0.0. For advanced use cases such as multi-platform native libraries,
enabling [`--incompatible_enable_cc_toolchain_resolution`](https://github.com/bazelbuild/bazel/issues/7260) is required.
rules_jni requires at least Bazel 6.0.0. For advanced use cases such as multi-platform native libraries,
enabling [`--incompatible_enable_cc_toolchain_resolution`](https://github.com/bazelbuild/bazel/issues/7260) is required (default in Bazel 7+).

## Multi-language coverage

Expand All @@ -71,13 +70,6 @@ and `@fmeum_rules_jni//jni:libjvm`. This feature currently has the following lim
rather than `@fmeum_rules_jni//jni:libjvm_lite` and `rules_jni_init` has to be called.
* All jars on the classpath of a JVM started with `JNI_CreateJavaVM` have to be deploy jars.

There are also the following known issues with Bazel Java coverage to keep in mind:

* `java_test` does not collect coverage for `cc_binary` targets it executes at
runtime (https://github.com/bazelbuild/bazel/issues/15098)
* Java coverage is not collected correctly with JDK 16+ (https://github.com/bazelbuild/bazel/pull/15081)
* Coverage is not collected for native code that transitively depends on a `java_jni_library` target (https://github.com/bazelbuild/bazel/pull/15118)

To enable this feature, add the following lines to your project's `.bazelrc`:

```
Expand Down
15 changes: 14 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
workspace(name = "fmeum_rules_jni")

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

rules_jni_dependencies()

Expand All @@ -11,6 +11,19 @@ local_repository(
path = "tests",
)

http_archive(
name = "build_bazel_apple_support",
sha256 = "c4bb2b7367c484382300aee75be598b92f847896fb31bbd22f3a2346adf66a80",
url = "https://github.com/bazelbuild/apple_support/releases/download/1.15.1/apple_support.1.15.1.tar.gz",
)

load(
"@build_bazel_apple_support//lib:repositories.bzl",
"apple_support_dependencies",
)

apple_support_dependencies()

http_archive(
name = "rules_jvm_external",
sha256 = "b17d7388feb9bfa7f2fa09031b32707df529f26c91ab9e5d909eb1676badd9a6",
Expand Down
2 changes: 1 addition & 1 deletion jni/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("//jni/internal:cc_jni_library.bzl", _cc_jni_library = "cc_jni_library")
load("//jni/internal:java_jni_library.bzl", _java_jni_library = "java_jni_library")
load("//jni/internal:jni_headers.bzl", _jni_headers = "jni_headers")
load("//jni/internal:cc_jni_library.bzl", _cc_jni_library = "cc_jni_library")

java_jni_library = _java_jni_library
jni_headers = _jni_headers
Expand Down
24 changes: 1 addition & 23 deletions jni/internal/cc_jni_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load(":coverage.bzl", "cc_jni_coverage_helper_library", "java_jni_coverage_helper_library")
load(":jni_headers.bzl", "jni_headers")
load(":os_cpu_utils.bzl", "SELECT_TARGET_CPU", "SELECT_TARGET_OS")
load(":transitions.bzl", "multi_platform_transition")
Expand Down Expand Up @@ -188,26 +187,9 @@ def cc_jni_library(
# Arguments to be set on all targets.
testonly = cc_binary_args.pop("testonly", default = None)

java_coverage_helper_name = "%s_java_coverage_helper" % name
java_jni_coverage_helper_library(
name = java_coverage_helper_name,
library_name = basename,
)

cc_coverage_helper_name = "%s_cc_coverage_helper" % name
cc_jni_coverage_helper_library(
name = cc_coverage_helper_name,
library_name = basename,
)

# Simple concatenation is compatible with select, append is not.
cc_binary_args.setdefault("deps", [])
cc_binary_args["deps"] += [
Label("//jni"),
] + select({
str(Label("//jni/internal:collect_coverage")): [":" + cc_coverage_helper_name],
"//conditions:default": [],
})
cc_binary_args["deps"] += [Label("//jni")]

native.cc_binary(
name = macos_library_name,
Expand Down Expand Up @@ -267,10 +249,6 @@ def cc_jni_library(
name = name,
resources = [":" + multi_platform_artifact_name],
resource_strip_prefix = _maven_resource_prefix_if_present(),
runtime_deps = select({
str(Label("//jni/internal:collect_coverage")): [":" + java_coverage_helper_name],
"//conditions:default": [],
}),
tags = tags,
testonly = testonly,
visibility = visibility,
Expand Down
Loading
Loading