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,8 +1,13 @@
|
||||
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("//romiVendordep:robotpy_native_build_info.bzl", "define_native_wrapper")
|
||||
load("//romiVendordep:robotpy_pybind_build_info.bzl", "define_pybind_library", "romi_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_library")
|
||||
load("//shared/bazel/rules:packaging.bzl", "package_minimal_cc_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")
|
||||
|
||||
filegroup(
|
||||
name = "doxygen-files",
|
||||
@@ -101,3 +106,57 @@ package_minimal_cc_project(
|
||||
maven_artifact_name = "romiVendordep-cpp",
|
||||
maven_group_id = "org.wpilib.romiVendordep",
|
||||
)
|
||||
|
||||
generate_robotpy_native_wrapper_build_info(
|
||||
name = "robotpy-native-xrp-generator",
|
||||
pyproject_toml = "src/main/python/native-pyproject.toml",
|
||||
)
|
||||
|
||||
define_native_wrapper(
|
||||
name = "robotpy-native-romi",
|
||||
pyproject_toml = "src/main/python/native-pyproject.toml",
|
||||
)
|
||||
|
||||
PKG_CONFIG_DEPS = [
|
||||
"//datalog:native/datalog/robotpy-native-datalog.pc",
|
||||
"//datalog:robotpy-wpilog.generated_pkgcfg_files",
|
||||
"//hal:native/wpihal/robotpy-native-wpihal.pc",
|
||||
"//hal:robotpy-hal.generated_pkgcfg_files",
|
||||
"//ntcore:native/ntcore/robotpy-native-ntcore.pc",
|
||||
"//ntcore:pyntcore.generated_pkgcfg_files",
|
||||
"//wpilibc:native/wpilib/robotpy-native-wpilib.pc",
|
||||
"//wpilibc:robotpy-wpilib.generated_pkgcfg_files",
|
||||
"//wpimath:native/wpimath/robotpy-native-wpimath.pc",
|
||||
"//wpimath:robotpy-wpimath.generated_pkgcfg_files",
|
||||
"//wpinet:native/wpinet/robotpy-native-wpinet.pc",
|
||||
"//wpinet:robotpy-wpinet.generated_pkgcfg_files",
|
||||
"//wpiutil:native/wpiutil/robotpy-native-wpiutil.pc",
|
||||
"//wpiutil:robotpy-wpiutil.generated_pkgcfg_files",
|
||||
"//romiVendordep:native/romi/robotpy-native-romi.pc",
|
||||
]
|
||||
|
||||
generate_robotpy_pybind_build_info(
|
||||
name = "robotpy-romi-generator",
|
||||
additional_srcs = [":robotpy-native-romi.copy_headers"],
|
||||
package_root_file = "src/main/python/romi/__init__.py",
|
||||
pkgcfgs = PKG_CONFIG_DEPS,
|
||||
yaml_files = glob(["src/main/python/semiwrap/**/*.yml"]),
|
||||
)
|
||||
|
||||
romi_extension(
|
||||
srcs = ["src/main/python/romi/src/main.cpp"],
|
||||
)
|
||||
|
||||
define_pybind_library(
|
||||
name = "robotpy-romi",
|
||||
pkgcfgs = PKG_CONFIG_DEPS,
|
||||
)
|
||||
|
||||
robotpy_py_test(
|
||||
"python_tests",
|
||||
srcs = glob(["src/test/python/**/*.py"]),
|
||||
deps = [
|
||||
":robotpy-romi",
|
||||
requirement("pytest"),
|
||||
],
|
||||
)
|
||||
|
||||
34
romiVendordep/robotpy_native_build_info.bzl
generated
Normal file
34
romiVendordep/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/romi/include",
|
||||
root_paths = ["src/main/native/include/"],
|
||||
replace_prefixes = {
|
||||
"romiVendordep/src/generated/main/native/include": "",
|
||||
"romiVendordep/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/romi/_init_robotpy_native_romi.py",
|
||||
pc_file = "native/romi/robotpy-native-romi.pc",
|
||||
pc_deps = [
|
||||
"//wpilibc:native/wpilib/robotpy-native-wpilib.pc",
|
||||
],
|
||||
deps = [
|
||||
"//wpilibc:robotpy-native-wpilib",
|
||||
],
|
||||
headers = "{}.copy_headers".format(name),
|
||||
native_shared_library = "shared/romiVendordep",
|
||||
install_path = "native/romi/",
|
||||
)
|
||||
208
romiVendordep/robotpy_pybind_build_info.bzl
generated
Normal file
208
romiVendordep/robotpy_pybind_build_info.bzl
generated
Normal file
@@ -0,0 +1,208 @@
|
||||
# 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 romi_extension(srcs = [], header_to_dat_deps = [], extra_hdrs = [], includes = [], extra_pyi_deps = []):
|
||||
ROMI_HEADER_GEN = [
|
||||
struct(
|
||||
class_name = "OnBoardIO",
|
||||
yml_file = "semiwrap/OnBoardIO.yml",
|
||||
header_root = "$(execpath :robotpy-native-romi.copy_headers)",
|
||||
header_file = "$(execpath :robotpy-native-romi.copy_headers)/wpi/romi/OnBoardIO.hpp",
|
||||
tmpl_class_names = [],
|
||||
trampolines = [
|
||||
("wpi::romi::OnBoardIO", "wpi__romi__OnBoardIO.hpp"),
|
||||
],
|
||||
),
|
||||
struct(
|
||||
class_name = "RomiGyro",
|
||||
yml_file = "semiwrap/RomiGyro.yml",
|
||||
header_root = "$(execpath :robotpy-native-romi.copy_headers)",
|
||||
header_file = "$(execpath :robotpy-native-romi.copy_headers)/wpi/romi/RomiGyro.hpp",
|
||||
tmpl_class_names = [],
|
||||
trampolines = [
|
||||
("wpi::romi::RomiGyro", "wpi__romi__RomiGyro.hpp"),
|
||||
],
|
||||
),
|
||||
struct(
|
||||
class_name = "RomiMotor",
|
||||
yml_file = "semiwrap/RomiMotor.yml",
|
||||
header_root = "$(execpath :robotpy-native-romi.copy_headers)",
|
||||
header_file = "$(execpath :robotpy-native-romi.copy_headers)/wpi/romi/RomiMotor.hpp",
|
||||
tmpl_class_names = [],
|
||||
trampolines = [
|
||||
("wpi::romi::RomiMotor", "wpi__romi__RomiMotor.hpp"),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
||||
resolve_casters(
|
||||
name = "romi.resolve_casters",
|
||||
caster_deps = ["//wpimath:src/main/python/wpimath/wpimath-casters.pybind11.json", "//wpiutil:src/main/python/wpiutil/wpiutil-casters.pybind11.json"],
|
||||
casters_pkl_file = "romi.casters.pkl",
|
||||
dep_file = "romi.casters.d",
|
||||
)
|
||||
|
||||
gen_libinit(
|
||||
name = "romi.gen_lib_init",
|
||||
output_file = "src/main/python/romi/_init__romi.py",
|
||||
modules = ["native.romi._init_robotpy_native_romi", "wpilib._init__wpilib", "wpimath.geometry._init__geometry"],
|
||||
)
|
||||
|
||||
gen_pkgconf(
|
||||
name = "romi.gen_pkgconf",
|
||||
libinit_py = "romi._init__romi",
|
||||
module_pkg_name = "romi._romi",
|
||||
output_file = "romi.pc",
|
||||
pkg_name = "romi",
|
||||
install_path = "src/main/python/romi",
|
||||
project_file = "src/main/python/pyproject.toml",
|
||||
package_root = "src/main/python/romi/__init__.py",
|
||||
)
|
||||
|
||||
gen_modinit_hpp(
|
||||
name = "romi.gen_modinit_hpp",
|
||||
input_dats = [x.class_name for x in ROMI_HEADER_GEN],
|
||||
libname = "_romi",
|
||||
output_file = "semiwrap_init.romi._romi.hpp",
|
||||
)
|
||||
|
||||
run_header_gen(
|
||||
name = "romi",
|
||||
casters_pickle = "romi.casters.pkl",
|
||||
header_gen_config = ROMI_HEADER_GEN,
|
||||
trampoline_subpath = "src/main/python/romi",
|
||||
deps = header_to_dat_deps,
|
||||
local_native_libraries = [
|
||||
"//datalog:robotpy-native-datalog.copy_headers",
|
||||
"//hal:robotpy-native-wpihal.copy_headers",
|
||||
"//ntcore:robotpy-native-ntcore.copy_headers",
|
||||
"//romiVendordep:robotpy-native-romi.copy_headers",
|
||||
"//wpilibc:robotpy-native-wpilib.copy_headers",
|
||||
"//wpimath:robotpy-native-wpimath.copy_headers",
|
||||
"//wpinet:robotpy-native-wpinet.copy_headers",
|
||||
"//wpiutil:robotpy-native-wpiutil.copy_headers",
|
||||
],
|
||||
)
|
||||
|
||||
create_pybind_library(
|
||||
name = "romi",
|
||||
install_path = "src/main/python/romi/",
|
||||
extension_name = "_romi",
|
||||
generated_srcs = [":romi.generated_srcs"],
|
||||
semiwrap_header = [":romi.gen_modinit_hpp"],
|
||||
deps = [
|
||||
":romi.tmpl_hdrs",
|
||||
":romi.trampoline_hdrs",
|
||||
"//romiVendordep:romiVendordep",
|
||||
"//wpilibc:wpilib_pybind_library",
|
||||
"//wpilibc:wpilibc",
|
||||
"//wpimath:wpimath",
|
||||
"//wpimath:wpimath_geometry_pybind_library",
|
||||
],
|
||||
dynamic_deps = [
|
||||
"//romiVendordep:shared/romiVendordep",
|
||||
"//wpilibc:shared/wpilibc",
|
||||
"//wpimath:shared/wpimath",
|
||||
],
|
||||
extra_hdrs = extra_hdrs,
|
||||
extra_srcs = srcs,
|
||||
includes = includes,
|
||||
)
|
||||
|
||||
native.filegroup(
|
||||
name = "romi.generated_files",
|
||||
srcs = [
|
||||
"romi.gen_modinit_hpp.gen",
|
||||
"romi.header_gen_files",
|
||||
"romi.gen_pkgconf",
|
||||
"romi.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 = [
|
||||
"romi.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/romi/romi.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/romi/**"], exclude = ["src/main/python/romi/**/*.py"], allow_empty = True),
|
||||
tags = ["manual", "robotpy"],
|
||||
)
|
||||
|
||||
generate_version_file(
|
||||
name = "{}.generate_version".format(name),
|
||||
output_file = "src/main/python/romi/version.py",
|
||||
template = "//shared/bazel/rules/robotpy:version_template.in",
|
||||
)
|
||||
|
||||
robotpy_library(
|
||||
name = name,
|
||||
srcs = native.glob(["src/main/python/romi/**/*.py"]) + [
|
||||
"src/main/python/romi/_init__romi.py",
|
||||
"{}.generate_version".format(name),
|
||||
],
|
||||
data = [
|
||||
"{}.generated_pkgcfg_files".format(name),
|
||||
"{}.extra_files".format(name),
|
||||
":src/main/python/romi/_romi",
|
||||
":romi.trampoline_hdr_files",
|
||||
],
|
||||
imports = ["src/main/python"],
|
||||
deps = [
|
||||
"//romiVendordep:robotpy-native-romi",
|
||||
"//wpilibc:robotpy-wpilib",
|
||||
],
|
||||
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",
|
||||
"//hal:robotpy-native-wpihal.copy_headers",
|
||||
"//ntcore:robotpy-native-ntcore.copy_headers",
|
||||
"//romiVendordep:robotpy-native-romi.copy_headers",
|
||||
"//wpilibc:robotpy-native-wpilib.copy_headers",
|
||||
"//wpimath:robotpy-native-wpimath.copy_headers",
|
||||
"//wpinet:robotpy-native-wpinet.copy_headers",
|
||||
"//wpiutil:robotpy-native-wpiutil.copy_headers",
|
||||
],
|
||||
package_root_file = "src/main/python/romi/__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) + [
|
||||
"//romiVendordep:robotpy-native-romi.copy_headers",
|
||||
],
|
||||
package_root_file = "src/main/python/romi/__init__.py",
|
||||
pkgcfgs = pkgcfgs,
|
||||
pyproject_toml = "src/main/python/pyproject.toml",
|
||||
)
|
||||
Reference in New Issue
Block a user