mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[robotpy] Add build scripts for wpilib and dependencies (#8348)
This gets the majority of projects from mostrobotpy building in this mirror. Projects missing still are cscore and the halsim wrappers.
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
load("@allwpilib_pip_deps//:requirements.bzl", "requirement")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test")
|
||||
load("@rules_java//java:defs.bzl", "java_binary")
|
||||
load("@rules_python//python:defs.bzl", "py_binary")
|
||||
load("//datalog:robotpy_native_build_info.bzl", "define_native_wrapper")
|
||||
load("//datalog:robotpy_pybind_build_info.bzl", "define_pybind_library", "wpilog_extension")
|
||||
load("//shared/bazel/rules:cc_rules.bzl", "wpilib_cc_library", "wpilib_cc_shared_library", "wpilib_cc_static_library")
|
||||
load("//shared/bazel/rules:java_rules.bzl", "wpilib_java_junit5_test")
|
||||
load("//shared/bazel/rules:jni_rules.bzl", "wpilib_jni_cc_library", "wpilib_jni_java_library")
|
||||
load("//shared/bazel/rules:packaging.bzl", "package_minimal_jni_project")
|
||||
load("//shared/bazel/rules/robotpy:build_info_gen.bzl", "generate_robotpy_native_wrapper_build_info", "generate_robotpy_pybind_build_info")
|
||||
load("//shared/bazel/rules/robotpy:pytest_util.bzl", "robotpy_py_test")
|
||||
|
||||
wpilib_cc_library(
|
||||
name = "datalog",
|
||||
@@ -146,3 +151,48 @@ package_minimal_jni_project(
|
||||
maven_artifact_name = "datalog-cpp",
|
||||
maven_group_id = "org.wpilib.datalog",
|
||||
)
|
||||
|
||||
generate_robotpy_native_wrapper_build_info(
|
||||
name = "robotpy-native-datalog-generator",
|
||||
pyproject_toml = "src/main/python/native-pyproject.toml",
|
||||
)
|
||||
|
||||
define_native_wrapper(
|
||||
name = "robotpy-native-datalog",
|
||||
pyproject_toml = "src/main/python/native-pyproject.toml",
|
||||
)
|
||||
|
||||
PYBIND_PKGCFG_DEPS = [
|
||||
"//datalog:native/datalog/robotpy-native-datalog.pc",
|
||||
"//wpiutil:native/wpiutil/robotpy-native-wpiutil.pc",
|
||||
"//wpiutil:robotpy-wpiutil.generated_pkgcfg_files",
|
||||
]
|
||||
|
||||
generate_robotpy_pybind_build_info(
|
||||
name = "robotpy-datalog-generator",
|
||||
additional_srcs = [":robotpy-native-datalog.copy_headers"],
|
||||
package_root_file = "src/main/python/wpilog/__init__.py",
|
||||
pkgcfgs = PYBIND_PKGCFG_DEPS,
|
||||
yaml_files = glob(["src/main/python/semiwrap/*.yml"]),
|
||||
)
|
||||
|
||||
wpilog_extension(
|
||||
srcs = ["src/main/python/src/main.cpp"],
|
||||
includes = [
|
||||
"src/main/python/datalog/",
|
||||
],
|
||||
)
|
||||
|
||||
define_pybind_library(
|
||||
name = "robotpy-wpilog",
|
||||
pkgcfgs = PYBIND_PKGCFG_DEPS,
|
||||
)
|
||||
|
||||
robotpy_py_test(
|
||||
"datalog_tests",
|
||||
srcs = glob(["src/test/python/**/*.py"]),
|
||||
deps = [
|
||||
":robotpy-wpilog",
|
||||
requirement("pytest"),
|
||||
],
|
||||
)
|
||||
|
||||
34
datalog/robotpy_native_build_info.bzl
generated
Normal file
34
datalog/robotpy_native_build_info.bzl
generated
Normal file
@@ -0,0 +1,34 @@
|
||||
# THIS FILE IS AUTO GENERATED
|
||||
|
||||
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
|
||||
load("//shared/bazel/rules/robotpy:pybind_rules.bzl", "native_wrappery_library")
|
||||
|
||||
def define_native_wrapper(name, pyproject_toml = None):
|
||||
copy_to_directory(
|
||||
name = "{}.copy_headers".format(name),
|
||||
srcs = native.glob(["src/main/native/include/**"]) + native.glob(["src/generated/main/native/include/**"], allow_empty = True),
|
||||
out = "native/datalog/include",
|
||||
root_paths = ["src/main/native/include/"],
|
||||
replace_prefixes = {
|
||||
"datalog/src/generated/main/native/include": "",
|
||||
"datalog/src/main/native/include": "",
|
||||
},
|
||||
verbose = False,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
native_wrappery_library(
|
||||
name = name,
|
||||
pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml",
|
||||
libinit_file = "native/datalog/_init_robotpy_native_datalog.py",
|
||||
pc_file = "native/datalog/robotpy-native-datalog.pc",
|
||||
pc_deps = [
|
||||
"//wpiutil:native/wpiutil/robotpy-native-wpiutil.pc",
|
||||
],
|
||||
deps = [
|
||||
"//wpiutil:robotpy-native-wpiutil",
|
||||
],
|
||||
headers = "{}.copy_headers".format(name),
|
||||
native_shared_library = "shared/datalog",
|
||||
install_path = "native/datalog/",
|
||||
)
|
||||
235
datalog/robotpy_pybind_build_info.bzl
generated
Normal file
235
datalog/robotpy_pybind_build_info.bzl
generated
Normal file
@@ -0,0 +1,235 @@
|
||||
# THIS FILE IS AUTO GENERATED
|
||||
|
||||
load("//shared/bazel/rules/gen:gen-version-file.bzl", "generate_version_file")
|
||||
load("//shared/bazel/rules/robotpy:pybind_rules.bzl", "create_pybind_library", "robotpy_library")
|
||||
load("//shared/bazel/rules/robotpy:semiwrap_helpers.bzl", "gen_libinit", "gen_modinit_hpp", "gen_pkgconf", "resolve_casters", "run_header_gen")
|
||||
load("//shared/bazel/rules/robotpy:semiwrap_tool_helpers.bzl", "scan_headers", "update_yaml_files")
|
||||
|
||||
def wpilog_extension(srcs = [], header_to_dat_deps = [], extra_hdrs = [], includes = [], extra_pyi_deps = []):
|
||||
WPILOG_HEADER_GEN = [
|
||||
struct(
|
||||
class_name = "DataLog",
|
||||
yml_file = "semiwrap/DataLog.yml",
|
||||
header_root = "$(execpath :robotpy-native-datalog.copy_headers)",
|
||||
header_file = "$(execpath :robotpy-native-datalog.copy_headers)/wpi/datalog/DataLog.hpp",
|
||||
tmpl_class_names = [
|
||||
("DataLog_tmpl1", "StructLogEntry"),
|
||||
("DataLog_tmpl2", "StructArrayLogEntry"),
|
||||
("DataLog_tmpl3", "_RawLogEntryImpl"),
|
||||
("DataLog_tmpl4", "_BooleanLogEntryImpl"),
|
||||
("DataLog_tmpl5", "_IntegerLogEntryImpl"),
|
||||
("DataLog_tmpl6", "_FloatLogEntryImpl"),
|
||||
("DataLog_tmpl7", "_DoubleLogEntryImpl"),
|
||||
("DataLog_tmpl8", "_StringLogEntryImpl"),
|
||||
("DataLog_tmpl9", "_BooleanArrayLogEntryImpl"),
|
||||
("DataLog_tmpl10", "_IntegerArrayLogEntryImpl"),
|
||||
("DataLog_tmpl11", "_FloatArrayLogEntryImpl"),
|
||||
("DataLog_tmpl12", "_DoubleArrayLogEntryImpl"),
|
||||
("DataLog_tmpl13", "_StringArrayLogEntryImpl"),
|
||||
],
|
||||
trampolines = [
|
||||
("wpi::log::DataLog", "wpi__log__DataLog.hpp"),
|
||||
("wpi::log::DataLogEntry", "wpi__log__DataLogEntry.hpp"),
|
||||
("wpi::log::DataLogValueEntryImpl", "wpi__log__DataLogValueEntryImpl.hpp"),
|
||||
("wpi::log::RawLogEntry", "wpi__log__RawLogEntry.hpp"),
|
||||
("wpi::log::BooleanLogEntry", "wpi__log__BooleanLogEntry.hpp"),
|
||||
("wpi::log::IntegerLogEntry", "wpi__log__IntegerLogEntry.hpp"),
|
||||
("wpi::log::FloatLogEntry", "wpi__log__FloatLogEntry.hpp"),
|
||||
("wpi::log::DoubleLogEntry", "wpi__log__DoubleLogEntry.hpp"),
|
||||
("wpi::log::StringLogEntry", "wpi__log__StringLogEntry.hpp"),
|
||||
("wpi::log::BooleanArrayLogEntry", "wpi__log__BooleanArrayLogEntry.hpp"),
|
||||
("wpi::log::IntegerArrayLogEntry", "wpi__log__IntegerArrayLogEntry.hpp"),
|
||||
("wpi::log::FloatArrayLogEntry", "wpi__log__FloatArrayLogEntry.hpp"),
|
||||
("wpi::log::DoubleArrayLogEntry", "wpi__log__DoubleArrayLogEntry.hpp"),
|
||||
("wpi::log::StringArrayLogEntry", "wpi__log__StringArrayLogEntry.hpp"),
|
||||
("wpi::log::StructLogEntry", "wpi__log__StructLogEntry.hpp"),
|
||||
("wpi::log::StructArrayLogEntry", "wpi__log__StructArrayLogEntry.hpp"),
|
||||
],
|
||||
),
|
||||
struct(
|
||||
class_name = "DataLogBackgroundWriter",
|
||||
yml_file = "semiwrap/DataLogBackgroundWriter.yml",
|
||||
header_root = "$(execpath :robotpy-native-datalog.copy_headers)",
|
||||
header_file = "$(execpath :robotpy-native-datalog.copy_headers)/wpi/datalog/DataLogBackgroundWriter.hpp",
|
||||
tmpl_class_names = [],
|
||||
trampolines = [
|
||||
("wpi::log::DataLogBackgroundWriter", "wpi__log__DataLogBackgroundWriter.hpp"),
|
||||
],
|
||||
),
|
||||
struct(
|
||||
class_name = "DataLogReader",
|
||||
yml_file = "semiwrap/DataLogReader.yml",
|
||||
header_root = "$(execpath :robotpy-native-datalog.copy_headers)",
|
||||
header_file = "$(execpath :robotpy-native-datalog.copy_headers)/wpi/datalog/DataLogReader.hpp",
|
||||
tmpl_class_names = [],
|
||||
trampolines = [
|
||||
("wpi::log::StartRecordData", "wpi__log__StartRecordData.hpp"),
|
||||
("wpi::log::MetadataRecordData", "wpi__log__MetadataRecordData.hpp"),
|
||||
("wpi::log::DataLogRecord", "wpi__log__DataLogRecord.hpp"),
|
||||
("wpi::log::DataLogReader", "wpi__log__DataLogReader.hpp"),
|
||||
],
|
||||
),
|
||||
struct(
|
||||
class_name = "DataLogWriter",
|
||||
yml_file = "semiwrap/DataLogWriter.yml",
|
||||
header_root = "$(execpath :robotpy-native-datalog.copy_headers)",
|
||||
header_file = "$(execpath :robotpy-native-datalog.copy_headers)/wpi/datalog/DataLogWriter.hpp",
|
||||
tmpl_class_names = [],
|
||||
trampolines = [
|
||||
("wpi::log::DataLogWriter", "wpi__log__DataLogWriter.hpp"),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
||||
resolve_casters(
|
||||
name = "wpilog.resolve_casters",
|
||||
caster_deps = ["//wpiutil:src/main/python/wpiutil/wpiutil-casters.pybind11.json"],
|
||||
casters_pkl_file = "wpilog.casters.pkl",
|
||||
dep_file = "wpilog.casters.d",
|
||||
)
|
||||
|
||||
gen_libinit(
|
||||
name = "wpilog.gen_lib_init",
|
||||
output_file = "src/main/python/wpilog/_init__wpilog.py",
|
||||
modules = ["native.datalog._init_robotpy_native_datalog", "wpiutil._init__wpiutil"],
|
||||
)
|
||||
|
||||
gen_pkgconf(
|
||||
name = "wpilog.gen_pkgconf",
|
||||
libinit_py = "wpilog._init__wpilog",
|
||||
module_pkg_name = "wpilog._wpilog",
|
||||
output_file = "wpilog.pc",
|
||||
pkg_name = "wpilog",
|
||||
install_path = "src/main/python/wpilog",
|
||||
project_file = "src/main/python/pyproject.toml",
|
||||
package_root = "src/main/python/wpilog/__init__.py",
|
||||
)
|
||||
|
||||
gen_modinit_hpp(
|
||||
name = "wpilog.gen_modinit_hpp",
|
||||
input_dats = [x.class_name for x in WPILOG_HEADER_GEN],
|
||||
libname = "_wpilog",
|
||||
output_file = "semiwrap_init.wpilog._wpilog.hpp",
|
||||
)
|
||||
|
||||
run_header_gen(
|
||||
name = "wpilog",
|
||||
casters_pickle = "wpilog.casters.pkl",
|
||||
header_gen_config = WPILOG_HEADER_GEN,
|
||||
trampoline_subpath = "src/main/python/wpilog",
|
||||
deps = header_to_dat_deps,
|
||||
local_native_libraries = [
|
||||
"//datalog:robotpy-native-datalog.copy_headers",
|
||||
"//wpiutil:robotpy-native-wpiutil.copy_headers",
|
||||
],
|
||||
)
|
||||
|
||||
create_pybind_library(
|
||||
name = "wpilog",
|
||||
install_path = "src/main/python/wpilog/",
|
||||
extension_name = "_wpilog",
|
||||
generated_srcs = [":wpilog.generated_srcs"],
|
||||
semiwrap_header = [":wpilog.gen_modinit_hpp"],
|
||||
deps = [
|
||||
":wpilog.tmpl_hdrs",
|
||||
":wpilog.trampoline_hdrs",
|
||||
"//datalog:datalog",
|
||||
"//wpiutil:wpiutil",
|
||||
"//wpiutil:wpiutil_pybind_library",
|
||||
],
|
||||
dynamic_deps = [
|
||||
"//datalog:shared/datalog",
|
||||
"//wpiutil:shared/wpiutil",
|
||||
],
|
||||
extra_hdrs = extra_hdrs,
|
||||
extra_srcs = srcs,
|
||||
includes = includes,
|
||||
)
|
||||
|
||||
native.filegroup(
|
||||
name = "wpilog.generated_files",
|
||||
srcs = [
|
||||
"wpilog.gen_modinit_hpp.gen",
|
||||
"wpilog.header_gen_files",
|
||||
"wpilog.gen_pkgconf",
|
||||
"wpilog.gen_lib_init",
|
||||
],
|
||||
tags = ["manual", "robotpy"],
|
||||
)
|
||||
|
||||
def define_pybind_library(name, pkgcfgs = []):
|
||||
# Helper used to generate all files with one target.
|
||||
native.filegroup(
|
||||
name = "{}.generated_files".format(name),
|
||||
srcs = [
|
||||
"wpilog.generated_files",
|
||||
],
|
||||
tags = ["manual", "robotpy"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
# Files that will be included in the wheel as data deps
|
||||
native.filegroup(
|
||||
name = "{}.generated_pkgcfg_files".format(name),
|
||||
srcs = [
|
||||
"src/main/python/wpilog/wpilog.pc",
|
||||
],
|
||||
tags = ["manual", "robotpy"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
# Contains all of the non-python files that need to be included in the wheel
|
||||
native.filegroup(
|
||||
name = "{}.extra_files".format(name),
|
||||
srcs = native.glob(["src/main/python/wpilog/**"], exclude = ["src/main/python/wpilog/**/*.py"], allow_empty = True),
|
||||
tags = ["manual", "robotpy"],
|
||||
)
|
||||
|
||||
generate_version_file(
|
||||
name = "{}.generate_version".format(name),
|
||||
output_file = "src/main/python/wpilog/version.py",
|
||||
template = "//shared/bazel/rules/robotpy:version_template.in",
|
||||
)
|
||||
|
||||
robotpy_library(
|
||||
name = name,
|
||||
srcs = native.glob(["src/main/python/wpilog/**/*.py"]) + [
|
||||
"src/main/python/wpilog/_init__wpilog.py",
|
||||
"{}.generate_version".format(name),
|
||||
],
|
||||
data = [
|
||||
"{}.generated_pkgcfg_files".format(name),
|
||||
"{}.extra_files".format(name),
|
||||
":src/main/python/wpilog/_wpilog",
|
||||
":wpilog.trampoline_hdr_files",
|
||||
],
|
||||
imports = ["src/main/python"],
|
||||
deps = [
|
||||
"//datalog:robotpy-native-datalog",
|
||||
"//wpiutil:robotpy-wpiutil",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
update_yaml_files(
|
||||
name = "{}-update-yaml".format(name),
|
||||
yaml_output_directory = "src/main/python/semiwrap",
|
||||
extra_hdrs = native.glob(["src/main/python/**/*.h"], allow_empty = True) + [
|
||||
"//datalog:robotpy-native-datalog.copy_headers",
|
||||
"//wpiutil:robotpy-native-wpiutil.copy_headers",
|
||||
],
|
||||
package_root_file = "src/main/python/wpilog/__init__.py",
|
||||
pkgcfgs = pkgcfgs,
|
||||
pyproject_toml = "src/main/python/pyproject.toml",
|
||||
yaml_files = native.glob(["src/main/python/semiwrap/**"]),
|
||||
)
|
||||
|
||||
scan_headers(
|
||||
name = "{}-scan-headers".format(name),
|
||||
extra_hdrs = native.glob(["src/main/python/**/*.h"], allow_empty = True) + [
|
||||
"//datalog:robotpy-native-datalog.copy_headers",
|
||||
],
|
||||
package_root_file = "src/main/python/wpilog/__init__.py",
|
||||
pkgcfgs = pkgcfgs,
|
||||
pyproject_toml = "src/main/python/pyproject.toml",
|
||||
)
|
||||
Reference in New Issue
Block a user