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

[bazel] Add macros to build jni code and java tests #7693

Open
wants to merge 7 commits into
base: 2027
Choose a base branch
from

Conversation

pjreiniger
Copy link
Contributor

This adds the ability to build the JNI code, and a helper macro to build the code for java tests. This greatly increases the coverage of files built by bazel, and hits pretty much everything but the examples (covered by #7690), and things involving wpigui (that will be the next traunch of stuff after this lands and also gets up and running in the 2027 branch)

The JNI helper is slightly complicated because the policy in wpilib seems to be to include the auto-generated headers in the jni.cpp's. Luckily bazel gives you access to those generated files through a zip file. There are a couple other steps you can do to get the jar to automatically bring the jni.so library around with it that I have implemented in my mega-fork, but it requires that the code is built into a shared library which we are kicking down the road.

In addition, this creates a little helper function to easily build java unit tests. At the moment, because of the lack of shared libraries the tests are tempoarily getting built as a binary instead of a test so that they don't fail. In my mega-fork this macro also handles putting the shared libraries in a special spot so the test can find them, but again that will be a later problem to address.

@pjreiniger pjreiniger requested review from PeterJohnson and a team as code owners January 16, 2025 00:07
@github-actions github-actions bot added component: ntcore NetworkTables library component: cscore CameraServer library component: wpiutil WPI utility library component: wpilibj WPILib Java component: hal Hardware Abstraction Layer component: command-based WPILib Command Based Library component: wpimath Math library component: wpinet WPI networking library component: apriltag AprilTag library component: wpiunits Java units library component: epilogue Annotation-based logging library labels Jan 16, 2025
@@ -14,6 +14,7 @@ modifiableFileExclude {
thirdparty/
\.patch$
gradlew
BUILD.bazel
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wpiformat was fighting buildifier when it comes to empty BUILD.bazel files


def wpilib_jni_java_library(
name,
native_libs = [],
Copy link
Contributor

@Gold856 Gold856 Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

native_libs is unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now. I think it is fine to leave unused and populated in the files that use it

There are a couple other steps you can do to get the jar to automatically bring the jni.so library around with it that I have implemented in my mega-fork, but it requires that the code is built into a shared library which we are kicking down the road.

@pjreiniger pjreiniger changed the base branch from main to 2027 January 18, 2025 01:54
@github-actions github-actions bot added the 2027 2027 target label Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2027 2027 target component: apriltag AprilTag library component: command-based WPILib Command Based Library component: cscore CameraServer library component: epilogue Annotation-based logging library component: hal Hardware Abstraction Layer component: ntcore NetworkTables library component: wpilibj WPILib Java component: wpimath Math library component: wpinet WPI networking library component: wpiunits Java units library component: wpiutil WPI utility library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants