[bazel] Make publishers for c++ hdr / srcs, and java (#8114)

This commit is contained in:
PJ Reiniger
2025-07-24 09:11:09 -04:00
committed by GitHub
parent e2f901822c
commit c78bd942bb
37 changed files with 478 additions and 230 deletions

View File

@@ -135,7 +135,7 @@ def wpilib_cc_library(
pkg_zip(
name = name + "-srcs-zip",
srcs = maybe_license_pkg + extra_src_pkg_files + [name + "-srcs-pkg"] + [lib + "-srcs-pkg" for lib in third_party_libraries],
tags = ["no-remote"],
tags = ["manual"],
)
if hdrs_pkg_root:
@@ -148,7 +148,7 @@ def wpilib_cc_library(
pkg_zip(
name = name + "-hdrs-zip",
srcs = extra_hdr_pkg_files + maybe_license_pkg + [name + "-hdrs-pkg"] + [lib + "-hdrs-pkg" for lib in third_party_libraries + third_party_header_only_libraries],
tags = ["no-remote"],
tags = ["manual"],
)
def wpilib_cc_shared_library(
@@ -388,15 +388,3 @@ def wpilib_cc_static_library(
static_lib_name = static_lib_name,
**kwargs
)
pkg_files(
name = name + "-static.pkg",
srcs = [":" + name],
tags = ["manual"],
)
pkg_zip(
name = name + "-static-zip",
srcs = ["//:license_pkg_files", name + "-static.pkg"],
tags = ["no-remote", "manual"],
)

View File

@@ -9,6 +9,7 @@ def wpilib_halsim_extension(
wpilib_cc_library(
name = name,
includes = ["src/main/native/include"],
include_license_files = True,
target_compatible_with = select({
"@rules_bzlmodrio_toolchains//constraints/is_systemcore:systemcore": ["@platforms//:incompatible"],
"//conditions:default": [],

View File

@@ -1,4 +1,34 @@
load("@rules_java//java:defs.bzl", "java_binary")
load("@rules_java//java:defs.bzl", "java_binary", "java_library")
load("//shared/bazel/rules:packaging.bzl", "zip_java_srcs")
load("//shared/bazel/rules:publishing.bzl", "wpilib_maven_export")
def wpilib_java_library(
name,
maven_group_id,
maven_artifact_name,
tags = [],
extra_source_pkgs = [],
**kwargs):
tags = list(tags) if tags else []
maven_coordinates = "{}:{}:$(WPILIB_VERSION)".format(maven_group_id, maven_artifact_name)
tags.append("maven_coordinates=" + maven_coordinates)
java_library(
name = name,
tags = tags,
**kwargs
)
zip_java_srcs(name = name, extra_pkgs = extra_source_pkgs)
wpilib_maven_export(
name = "{}_publish".format(name),
classifier_artifacts = {"sources": ":lib{}-sources.jar".format(name)},
lib_name = name,
maven_coordinates = maven_coordinates,
visibility = ["//visibility:public"],
)
def wpilib_java_junit5_test(
name,

View File

@@ -2,9 +2,9 @@ load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load("@rules_java//java:defs.bzl", "java_library")
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
load("@rules_pkg//:mappings.bzl", "filter_directory")
load("//shared/bazel/rules:java_rules.bzl", "wpilib_java_library")
def _jni_headers_impl(ctx):
include_dir = ctx.actions.declare_directory(ctx.attr.name + ".h")
@@ -75,7 +75,8 @@ def wpilib_jni_java_library(
visibility = java_library_args.pop("visibility", default = None)
testonly = java_library_args.pop("testonly", default = None)
headers_name = name + ".hdrs"
java_library(
wpilib_java_library(
name = name,
visibility = visibility,
testonly = testonly,

View File

@@ -1,6 +1,8 @@
load("@rules_pkg//:mappings.bzl", "pkg_filegroup", "pkg_files")
load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
load("//shared/bazel/rules:publishing.bzl", "architectures_pkg_zip", "platform_prefix", "wpilib_maven_export")
def pkg_java_files(name):
def pkg_java_src_files(name):
pkg_files(
name = name + "-java-srcs",
srcs = native.glob(["src/main/java/**"]),
@@ -28,3 +30,128 @@ def pkg_java_files(name):
"//shared/bazel/rules:src_jar_dummy_manifest",
],
)
def zip_java_srcs(name, extra_pkgs = []):
pkg_java_src_files("{}-sources.pkg".format(name))
pkg_zip(
name = "lib{}-java-sources".format(name),
srcs = ["{}-sources.pkg".format(name)] + extra_pkgs,
out = "lib{}-sources.jar".format(name),
tags = ["manual"],
)
def package_default_jni_project(
name,
maven_group_id,
maven_artifact_name):
"""
Packages a the C++ libraries for a project that has a JNI component.
This assumes that static and shared libraries exist for the project, and
that it is built for all native platforms plus systemcore. It runs the
per-platform transitions and bundles them all into a single maven_export target.
"""
pkg_files(
name = "{}-static-files".format(name),
srcs = [
":static/{}".format(name),
],
prefix = platform_prefix("static"),
strip_prefix = "static",
)
pkg_filegroup(
name = "{}-shared-files".format(name),
srcs = [
":shared/lib{}-shared-files".format(name),
":shared/lib{}jni-shared-files".format(name),
],
prefix = platform_prefix("shared"),
)
architectures_pkg_zip(
name = "{}_static_zip".format(name),
srcs = [
":{}-static-files".format(name),
"//:license_pkg_files",
],
)
architectures_pkg_zip(
name = "{}_shared_zip".format(name),
srcs = [
":{}-shared-files".format(name),
"//:license_pkg_files",
],
)
wpilib_maven_export(
name = "{}-cpp_publish".format(name),
classifier_artifacts = {
"headers": ":{}-hdrs-zip".format(name),
"linuxsystemcore": ":{}_shared_zip-opt-systemcore".format(name),
"linuxsystemcoredebug": ":{}_shared_zip-dbg-systemcore".format(name),
"linuxsystemcorestatic": ":{}_static_zip-opt-systemcore".format(name),
"linuxsystemcorestaticdebug": ":{}_static_zip-dbg-systemcore".format(name),
"sources": ":{}-srcs-zip".format(name),
},
linux_artifacts = {
"linuxx86-64": ":{}_shared_zip-opt-linux-x86-64".format(name),
"linuxx86-64debug": ":{}_shared_zip-dbg-linux-x86-64".format(name),
"linuxx86-64static": ":{}_static_zip-opt-linux-x86-64".format(name),
"linuxx86-64staticdebug": ":{}_static_zip-dbg-linux-x86-64".format(name),
},
maven_coordinates = "{}:{}:$(WPILIB_VERSION)".format(maven_group_id, maven_artifact_name),
osx_artifacts = {
"osxuniversal": ":{}_shared_zip-opt-osxuniversal".format(name),
"osxuniversaldebug": ":{}_shared_zip-dbg-osxuniversal".format(name),
"osxuniversalstatic": ":{}_static_zip-opt-osxuniversal".format(name),
"osxuniversalstaticdebug": ":{}_static_zip-dbg-osxuniversal".format(name),
},
visibility = ["//visibility:public"],
windows_artifacts = {
"windowsarm64": ":{}_shared_zip-opt-windows-arm64".format(name),
"windowsarm64debug": ":{}_shared_zip-dbg-windows-arm64".format(name),
"windowsarm64static": ":{}_static_zip-opt-windows-arm64".format(name),
"windowsarm64staticdebug": ":{}_static_zip-dbg-windows-arm64".format(name),
"windowsx86-64": ":{}_shared_zip-opt-windows-x86-64".format(name),
"windowsx86-64debug": ":{}_shared_zip-dbg-windows-x86-64".format(name),
"windowsx86-64static": ":{}_static_zip-opt-windows-x86-64".format(name),
"windowsx86-64staticdebug": ":{}_static_zip-dbg-windows-x86-64".format(name),
},
)
def package_minimal_jni_project(
name,
maven_group_id,
maven_artifact_name):
wpilib_maven_export(
name = "{}-cpp_publish".format(name),
classifier_artifacts = {
"headers": ":{}-hdrs-zip".format(name),
"sources": ":{}-srcs-zip".format(name),
},
linux_artifacts = {},
maven_coordinates = "{}:{}:$(WPILIB_VERSION)".format(maven_group_id, maven_artifact_name),
osx_artifacts = {},
visibility = ["//visibility:public"],
windows_artifacts = {},
)
def package_minimal_cc_project(
name,
maven_group_id,
maven_artifact_name):
wpilib_maven_export(
name = "{}-cpp_publish".format(name),
classifier_artifacts = {
"headers": ":{}-hdrs-zip".format(name),
"sources": ":{}-srcs-zip".format(name),
},
linux_artifacts = {},
maven_coordinates = "{}:{}:$(WPILIB_VERSION)".format(maven_group_id, maven_artifact_name),
osx_artifacts = {},
visibility = ["//visibility:public"],
windows_artifacts = {},
)

View File

@@ -34,12 +34,14 @@ def publish_all(name, targets):
' "$arg"',
"done",
],
tags = ["manual"],
)
sh_binary(
name = name,
srcs = [publish_name + ".sh"],
args = ["$(location " + x + ".publish)" for x in targets],
data = [x + ".publish" for x in targets],
tags = ["manual"],
)
# Unfortunately, rules_jvm_external really wants each of the classifier
@@ -68,6 +70,7 @@ def architectures_pkg_zip(
zip_name = name + "-" + compilation_mode + "-arch-" + shortname
pkg_zip(
name = zip_name,
tags = ["manual"],
**kwargs
)
@@ -78,6 +81,7 @@ def architectures_pkg_zip(
target_platform = platform,
compilation_mode = compilation_mode,
target_compatible_with = architectures_target_compatible_with[shortname],
tags = ["manual"],
)
def platform_prefix(t):