From 68d24bb29ec048fb33926a4e2a994db5e135f865 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Fri, 15 May 2026 00:52:39 -0400 Subject: [PATCH] [python] Improve robotpy generation (#8867) The initial build file generation for robotpy projects was relatively naive and purpose built to get `allwpilib` compiling, without supporting all the available features. This modifies the generation scripts to be able to support multiple embedded libraries, which will be necessary for #8858, since `mrclib.so` will need to be bundled along with the hal libraries. In addition some cleanup was done to get the wheels looking more like what is in pypi. --- apriltag/robotpy_native_build_info.bzl | 39 ++++++-- apriltag/robotpy_pybind_build_info.bzl | 4 +- .../src/main/python/native-pyproject.toml | 1 + apriltag/src/main/python/pyproject.toml | 1 + commandsv2/BUILD.bazel | 42 ++++---- commandsv2/src/main/python/pyproject.toml | 4 +- datalog/robotpy_native_build_info.bzl | 39 ++++++-- datalog/robotpy_pybind_build_info.bzl | 4 +- datalog/src/main/python/native-pyproject.toml | 1 + datalog/src/main/python/pyproject.toml | 1 + hal/robotpy_native_build_info.bzl | 39 ++++++-- hal/robotpy_pybind_build_info.bzl | 4 +- hal/src/main/python/native-pyproject.toml | 1 + hal/src/main/python/pyproject.toml | 1 + ntcore/robotpy_native_build_info.bzl | 39 ++++++-- ntcore/robotpy_pybind_build_info.bzl | 4 +- ntcore/src/main/python/native-pyproject.toml | 1 + ntcore/src/main/python/pyproject.toml | 1 + romiVendordep/robotpy_native_build_info.bzl | 39 ++++++-- romiVendordep/robotpy_pybind_build_info.bzl | 4 +- .../src/main/python/native-pyproject.toml | 1 + romiVendordep/src/main/python/pyproject.toml | 1 + shared/bazel/rules/robotpy/BUILD.bazel | 1 + .../robotpy/generate_native_build_file.py | 95 +++++++++++++++---- .../robotpy/generate_pybind_build_file.py | 2 + .../generate_native_lib_files.py | 32 ++++--- .../robotpy/pybind_build_file_template.jinja2 | 4 +- .../{pybind_rules.bzl => robotpy_rules.bzl} | 82 +++------------- simulation/halsim_ds_socket/BUILD.bazel | 29 ++++-- .../src/main/python/pyproject.toml | 1 + .../halsim_gui/robotpy_pybind_build_info.bzl | 3 +- .../halsim_gui/src/main/python/pyproject.toml | 1 + simulation/halsim_ws_core/BUILD.bazel | 30 +++++- .../src/main/python/pyproject.toml | 1 + wpilibc/robotpy_native_build_info.bzl | 39 ++++++-- wpilibc/robotpy_pybind_build_info.bzl | 4 +- wpilibc/src/main/python/native-pyproject.toml | 1 + wpilibc/src/main/python/pyproject.toml | 1 + wpimath/robotpy_native_build_info.bzl | 39 ++++++-- wpimath/robotpy_pybind_build_info.bzl | 4 +- wpimath/robotpy_pybind_test_info.bzl | 4 +- wpimath/src/main/python/native-pyproject.toml | 1 + wpimath/src/main/python/pyproject.toml | 1 + wpimath/src/test/python/cpp/pyproject.toml | 1 + wpinet/robotpy_native_build_info.bzl | 39 ++++++-- wpinet/robotpy_pybind_build_info.bzl | 4 +- wpinet/src/main/python/native-pyproject.toml | 1 + wpinet/src/main/python/pyproject.toml | 1 + wpiutil/BUILD.bazel | 2 +- wpiutil/robotpy_native_build_info.bzl | 39 ++++++-- wpiutil/robotpy_pybind_build_info.bzl | 4 +- wpiutil/src/main/python/native-pyproject.toml | 1 + wpiutil/src/main/python/pyproject.toml | 1 + xrpVendordep/robotpy_native_build_info.bzl | 39 ++++++-- xrpVendordep/robotpy_pybind_build_info.bzl | 4 +- .../src/main/python/native-pyproject.toml | 1 + xrpVendordep/src/main/python/pyproject.toml | 1 + 57 files changed, 530 insertions(+), 254 deletions(-) rename shared/bazel/rules/robotpy/{pybind_rules.bzl => robotpy_rules.bzl} (77%) diff --git a/apriltag/robotpy_native_build_info.bzl b/apriltag/robotpy_native_build_info.bzl index 5fc24670f6..1294b53632 100644 --- a/apriltag/robotpy_native_build_info.bzl +++ b/apriltag/robotpy_native_build_info.bzl @@ -1,9 +1,11 @@ # 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") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "copy_native_file", "generate_native_files", "robotpy_library") def define_native_wrapper(name, pyproject_toml = None): + pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml" + 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) + native.glob([ @@ -20,25 +22,42 @@ def define_native_wrapper(name, pyproject_toml = None): visibility = ["//visibility:public"], ) - native_wrappery_library( + libinit_files = ["native/apriltag/_init_robotpy_native_apriltag.py"] + + generate_native_files( name = name, - pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml", - libinit_file = "native/apriltag/_init_robotpy_native_apriltag.py", - pc_file = "native/apriltag/robotpy-native-apriltag.pc", + pyproject_toml = pyproject_toml, pc_deps = [ "//wpimath:native/wpimath/robotpy-native-wpimath.pc", "//wpiutil:native/wpiutil/robotpy-native-wpiutil.pc", ], + libinit_files = libinit_files, + pc_files = ["native/apriltag/robotpy-native-apriltag.pc"], + ) + + copy_native_file( + name = "apriltag", + library = "shared/apriltag", + base_path = "native/apriltag/", + ) + + robotpy_library( + name = name, + distribution = "robotpy-native-apriltag", + srcs = libinit_files, + data = [ + name + ".pc_wrapper", + ":apriltag.copy_lib", + "{}.copy_headers".format(name), + ], deps = [ "//wpimath:robotpy-native-wpimath", "//wpiutil:robotpy-native-wpiutil", ], - headers = "{}.copy_headers".format(name), - native_shared_library = "shared/apriltag", - install_path = "native/apriltag/", - strip_path_prefixes = ["apriltag"], - requires = ["robotpy-native-wpiutil==0.0.0", "robotpy-native-wpimath==0.0.0"], summary = "WPILib AprilTag Library", + requires = ["robotpy-native-wpiutil==0.0.0", "robotpy-native-wpimath==0.0.0"], + python_requires = ">=3.11", + strip_path_prefixes = ["apriltag"], entry_points = { "pkg_config": [ "apriltag = native.apriltag", diff --git a/apriltag/robotpy_pybind_build_info.bzl b/apriltag/robotpy_pybind_build_info.bzl index 5f186a6a64..13f59af343 100644 --- a/apriltag/robotpy_pybind_build_info.bzl +++ b/apriltag/robotpy_pybind_build_info.bzl @@ -1,7 +1,7 @@ # 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:robotpy_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") @@ -198,6 +198,7 @@ def define_pybind_library(name, pkgcfgs = []): robotpy_library( name = name, + distribution = "robotpy-apriltag", srcs = native.glob(["src/main/python/robotpy_apriltag/**/*.py"]) + [ "src/main/python/robotpy_apriltag/_init__apriltag.py", "{}.generate_version".format(name), @@ -219,6 +220,7 @@ def define_pybind_library(name, pkgcfgs = []): project_urls = {"Source code": "https://github.com/robotpy/mostrobotpy"}, author_email = "RobotPy Development Team ", requires = ["robotpy-native-apriltag==0.0.0", "robotpy-wpiutil==0.0.0", "robotpy-wpimath==0.0.0"], + python_requires = ">=3.11", entry_points = { "pkg_config": ["apriltag = robotpy_apriltag"], }, diff --git a/apriltag/src/main/python/native-pyproject.toml b/apriltag/src/main/python/native-pyproject.toml index 46e22485f4..d9c3bb3b8c 100644 --- a/apriltag/src/main/python/native-pyproject.toml +++ b/apriltag/src/main/python/native-pyproject.toml @@ -12,6 +12,7 @@ requires = [ name = "robotpy-native-apriltag" version = "0.0.0" description = "WPILib AprilTag Library" +requires-python = ">=3.11" license = "BSD-3-Clause" dependencies = [ diff --git a/apriltag/src/main/python/pyproject.toml b/apriltag/src/main/python/pyproject.toml index 708a9273ab..ed1e63d7ec 100644 --- a/apriltag/src/main/python/pyproject.toml +++ b/apriltag/src/main/python/pyproject.toml @@ -14,6 +14,7 @@ requires = [ name = "robotpy-apriltag" version = "0.0.0" description = "RobotPy bindings for WPILib's AprilTag library" +requires-python = ">=3.11" authors = [ {name = "RobotPy Development Team", email = "robotpy@googlegroups.com"}, ] diff --git a/commandsv2/BUILD.bazel b/commandsv2/BUILD.bazel index 5391d08d65..8604b94dda 100644 --- a/commandsv2/BUILD.bazel +++ b/commandsv2/BUILD.bazel @@ -2,14 +2,13 @@ load("@allwpilib_pip_deps//:requirements.bzl", "requirement") load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test") load("@rules_java//java:defs.bzl", "java_binary") -load("@rules_pycross//pycross:defs.bzl", "pycross_wheel_library") -load("@rules_python//python:defs.bzl", "py_binary", "py_library") -load("@rules_python//python:packaging.bzl", "py_wheel") +load("@rules_python//python:defs.bzl", "py_binary") load("//commandsv2:generate.bzl", "generate_wpilib_new_commands") load("//shared/bazel/rules:cc_rules.bzl", "third_party_cc_lib_helper", "wpilib_cc_library", "wpilib_cc_shared_library", "wpilib_cc_static_library") load("//shared/bazel/rules:java_rules.bzl", "wpilib_java_junit5_test", "wpilib_java_library") load("//shared/bazel/rules:packaging.bzl", "package_default_cc_project") load("//shared/bazel/rules/robotpy:pytest_util.bzl", "robotpy_py_test") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "robotpy_library") filegroup( name = "doxygen-files", @@ -188,30 +187,21 @@ package_default_cc_project( maven_group_id = "org.wpilib.commandsv2", ) -py_library( - name = "commandsv2-py-lib", - srcs = glob(["src/main/python/**/*.py"]), - imports = ["src/main/python"], - deps = [ - "//wpilibc:robotpy-wpilib", - requirement("typing-extensions"), - ], -) - -py_wheel( - name = "commandsv2-wheel", - distribution = "commandsv2", - strip_path_prefixes = ["commandsv2/src/main/python"], - tags = ["robotpy"], - version = "$(ROBOTPY_VERSION)", - deps = [":commandsv2-py-lib"], -) - -pycross_wheel_library( +robotpy_library( name = "commandsv2-py", - tags = ["manual"], - visibility = ["//visibility:public"], - wheel = ":commandsv2-wheel", + srcs = glob(["src/main/python/**/*.py"]), + author_email = "RobotPy Development Team ", + description_file = "src/main/python/README.md", + distribution = "robotpy-commands-v2", + imports = ["src/main/python"], + project_urls = {"Source code": "https://github.com/robotpy/mostrobotpy"}, + python_requires = ">=3.10", + requires = [ + "wpilib==0.0.0", + "typing_extensions>=4.1.0,<5", + ], + strip_path_prefixes = ["commandsv2/src/main/python"], + summary = "WPILib command framework v2", deps = [ "//wpilibc:robotpy-wpilib", requirement("typing-extensions"), diff --git a/commandsv2/src/main/python/pyproject.toml b/commandsv2/src/main/python/pyproject.toml index 737405e705..675d580606 100644 --- a/commandsv2/src/main/python/pyproject.toml +++ b/commandsv2/src/main/python/pyproject.toml @@ -7,7 +7,7 @@ name = "robotpy-commands-v2" version = "0.0.0" description = "WPILib command framework v2" readme = "README.md" -requires-python = ">=3.10" +requires-python = ">=3.11" license = "BSD-3-Clause" license-files = ["LICENSE"] dependencies = [ @@ -24,7 +24,7 @@ name = "RobotPy Development Team" email = "robotpy@googlegroups.com" [project.urls] -"Source code" = "https://github.com/robotpy/robotpy-commands-v2" +"Source code" = "https://github.com/robotpy/mostrobotpy" [tool.hatch.version] source = "vcs" diff --git a/datalog/robotpy_native_build_info.bzl b/datalog/robotpy_native_build_info.bzl index 217ee2d26d..4f1a819361 100644 --- a/datalog/robotpy_native_build_info.bzl +++ b/datalog/robotpy_native_build_info.bzl @@ -1,9 +1,11 @@ # 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") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "copy_native_file", "generate_native_files", "robotpy_library") def define_native_wrapper(name, pyproject_toml = None): + pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml" + 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), @@ -17,23 +19,40 @@ def define_native_wrapper(name, pyproject_toml = None): visibility = ["//visibility:public"], ) - native_wrappery_library( + libinit_files = ["native/datalog/_init_robotpy_native_datalog.py"] + + generate_native_files( 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", + pyproject_toml = pyproject_toml, pc_deps = [ "//wpiutil:native/wpiutil/robotpy-native-wpiutil.pc", ], + libinit_files = libinit_files, + pc_files = ["native/datalog/robotpy-native-datalog.pc"], + ) + + copy_native_file( + name = "datalog", + library = "shared/datalog", + base_path = "native/datalog/", + ) + + robotpy_library( + name = name, + distribution = "robotpy-native-datalog", + srcs = libinit_files, + data = [ + name + ".pc_wrapper", + ":datalog.copy_lib", + "{}.copy_headers".format(name), + ], deps = [ "//wpiutil:robotpy-native-wpiutil", ], - headers = "{}.copy_headers".format(name), - native_shared_library = "shared/datalog", - install_path = "native/datalog/", - strip_path_prefixes = ["datalog"], - requires = ["robotpy-native-wpiutil==0.0.0"], summary = "WPILib Utility Library", + requires = ["robotpy-native-wpiutil==0.0.0"], + python_requires = ">=3.11", + strip_path_prefixes = ["datalog"], entry_points = { "pkg_config": [ "datalog = native.datalog", diff --git a/datalog/robotpy_pybind_build_info.bzl b/datalog/robotpy_pybind_build_info.bzl index 0ea9b0def7..2ce865e67d 100644 --- a/datalog/robotpy_pybind_build_info.bzl +++ b/datalog/robotpy_pybind_build_info.bzl @@ -1,7 +1,7 @@ # 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:robotpy_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") @@ -193,6 +193,7 @@ def define_pybind_library(name, pkgcfgs = []): robotpy_library( name = name, + distribution = "robotpy-wpilog", srcs = native.glob(["src/main/python/wpilog/**/*.py"]) + [ "src/main/python/wpilog/_init__wpilog.py", "{}.generate_version".format(name), @@ -213,6 +214,7 @@ def define_pybind_library(name, pkgcfgs = []): project_urls = {"Source code": "https://github.com/robotpy/mostrobotpy"}, author_email = "RobotPy Development Team ", requires = ["robotpy-native-datalog==0.0.0", "robotpy-wpiutil==0.0.0"], + python_requires = ">=3.11", entry_points = { "pkg_config": ["wpilog = wpilog"], }, diff --git a/datalog/src/main/python/native-pyproject.toml b/datalog/src/main/python/native-pyproject.toml index 968ca48dd5..a8b68f2c46 100644 --- a/datalog/src/main/python/native-pyproject.toml +++ b/datalog/src/main/python/native-pyproject.toml @@ -11,6 +11,7 @@ requires = [ name = "robotpy-native-datalog" version = "0.0.0" description = "WPILib Utility Library" +requires-python = ">=3.11" license = "BSD-3-Clause" dependencies = [ diff --git a/datalog/src/main/python/pyproject.toml b/datalog/src/main/python/pyproject.toml index 065fb70b76..056e118954 100644 --- a/datalog/src/main/python/pyproject.toml +++ b/datalog/src/main/python/pyproject.toml @@ -12,6 +12,7 @@ requires = [ name = "robotpy-wpilog" version = "0.0.0" description = "Binary wrapper for WPILib logging library" +requires-python = ">=3.11" authors = [ {name = "RobotPy Development Team", email = "robotpy@googlegroups.com"}, ] diff --git a/hal/robotpy_native_build_info.bzl b/hal/robotpy_native_build_info.bzl index e921831445..211714f76f 100644 --- a/hal/robotpy_native_build_info.bzl +++ b/hal/robotpy_native_build_info.bzl @@ -1,9 +1,11 @@ # 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") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "copy_native_file", "generate_native_files", "robotpy_library") def define_native_wrapper(name, pyproject_toml = None): + pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml" + 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), @@ -17,25 +19,42 @@ def define_native_wrapper(name, pyproject_toml = None): visibility = ["//visibility:public"], ) - native_wrappery_library( + libinit_files = ["native/wpihal/_init_robotpy_native_wpihal.py"] + + generate_native_files( name = name, - pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml", - libinit_file = "native/wpihal/_init_robotpy_native_wpihal.py", - pc_file = "native/wpihal/robotpy-native-wpihal.pc", + pyproject_toml = pyproject_toml, pc_deps = [ "//ntcore:native/ntcore/robotpy-native-ntcore.pc", "//wpiutil:native/wpiutil/robotpy-native-wpiutil.pc", ], + libinit_files = libinit_files, + pc_files = ["native/wpihal/robotpy-native-wpihal.pc"], + ) + + copy_native_file( + name = "wpiHal", + library = "shared/wpiHal", + base_path = "native/wpihal/", + ) + + robotpy_library( + name = name, + distribution = "robotpy-native-wpihal", + srcs = libinit_files, + data = [ + name + ".pc_wrapper", + ":wpiHal.copy_lib", + "{}.copy_headers".format(name), + ], deps = [ "//ntcore:robotpy-native-ntcore", "//wpiutil:robotpy-native-wpiutil", ], - headers = "{}.copy_headers".format(name), - native_shared_library = "shared/wpiHal", - install_path = "native/wpihal/", - strip_path_prefixes = ["hal"], - requires = ["robotpy-native-wpiutil==0.0.0", "robotpy-native-ntcore==0.0.0"], summary = "WPILib HAL implementation", + requires = ["robotpy-native-wpiutil==0.0.0", "robotpy-native-ntcore==0.0.0"], + python_requires = ">=3.11", + strip_path_prefixes = ["hal"], entry_points = { "pkg_config": [ "wpihal = native.wpihal", diff --git a/hal/robotpy_pybind_build_info.bzl b/hal/robotpy_pybind_build_info.bzl index da541e5a23..45d2f79404 100644 --- a/hal/robotpy_pybind_build_info.bzl +++ b/hal/robotpy_pybind_build_info.bzl @@ -1,7 +1,7 @@ # 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:robotpy_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") @@ -402,6 +402,7 @@ def define_pybind_library(name, pkgcfgs = []): robotpy_library( name = name, + distribution = "robotpy-hal", srcs = native.glob(["src/main/python/hal/**/*.py"]) + [ "src/main/python/hal/simulation/_init__simulation.py", "src/main/python/hal/_init__wpiHal.py", @@ -426,6 +427,7 @@ def define_pybind_library(name, pkgcfgs = []): project_urls = {"Source code": "https://github.com/robotpy/mostrobotpy"}, author_email = "RobotPy Development Team ", requires = ["pyntcore==0.0.0", "robotpy-native-wpihal==0.0.0", "robotpy-wpiutil==0.0.0"], + python_requires = ">=3.11", entry_points = { "pkg_config": ["hal_simulation = hal.simulation", "wpihal = hal"], }, diff --git a/hal/src/main/python/native-pyproject.toml b/hal/src/main/python/native-pyproject.toml index 7180e9356e..47a4ebedda 100644 --- a/hal/src/main/python/native-pyproject.toml +++ b/hal/src/main/python/native-pyproject.toml @@ -12,6 +12,7 @@ requires = [ name = "robotpy-native-wpihal" version = "0.0.0" description = "WPILib HAL implementation" +requires-python = ">=3.11" license = "BSD-3-Clause" dependencies = [ diff --git a/hal/src/main/python/pyproject.toml b/hal/src/main/python/pyproject.toml index 3171e17fe2..40ca2664dd 100644 --- a/hal/src/main/python/pyproject.toml +++ b/hal/src/main/python/pyproject.toml @@ -13,6 +13,7 @@ requires = [ name = "robotpy-hal" version = "0.0.0" description = "Binary wrapper for WPILib HAL" +requires-python = ">=3.11" authors = [ {name = "RobotPy Development Team", email = "robotpy@googlegroups.com"}, ] diff --git a/ntcore/robotpy_native_build_info.bzl b/ntcore/robotpy_native_build_info.bzl index 21cb992010..5925df2e45 100644 --- a/ntcore/robotpy_native_build_info.bzl +++ b/ntcore/robotpy_native_build_info.bzl @@ -1,9 +1,11 @@ # 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") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "copy_native_file", "generate_native_files", "robotpy_library") def define_native_wrapper(name, pyproject_toml = None): + pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml" + 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), @@ -17,27 +19,44 @@ def define_native_wrapper(name, pyproject_toml = None): visibility = ["//visibility:public"], ) - native_wrappery_library( + libinit_files = ["native/ntcore/_init_robotpy_native_ntcore.py"] + + generate_native_files( name = name, - pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml", - libinit_file = "native/ntcore/_init_robotpy_native_ntcore.py", - pc_file = "native/ntcore/robotpy-native-ntcore.pc", + pyproject_toml = pyproject_toml, pc_deps = [ "//datalog:native/datalog/robotpy-native-datalog.pc", "//wpinet:native/wpinet/robotpy-native-wpinet.pc", "//wpiutil:native/wpiutil/robotpy-native-wpiutil.pc", ], + libinit_files = libinit_files, + pc_files = ["native/ntcore/robotpy-native-ntcore.pc"], + ) + + copy_native_file( + name = "ntcore", + library = "shared/ntcore", + base_path = "native/ntcore/", + ) + + robotpy_library( + name = name, + distribution = "robotpy-native-ntcore", + srcs = libinit_files, + data = [ + name + ".pc_wrapper", + ":ntcore.copy_lib", + "{}.copy_headers".format(name), + ], deps = [ "//datalog:robotpy-native-datalog", "//wpinet:robotpy-native-wpinet", "//wpiutil:robotpy-native-wpiutil", ], - headers = "{}.copy_headers".format(name), - native_shared_library = "shared/ntcore", - install_path = "native/ntcore/", - strip_path_prefixes = ["ntcore"], - requires = ["robotpy-native-wpiutil==0.0.0", "robotpy-native-wpinet==0.0.0", "robotpy-native-datalog==0.0.0"], summary = "WPILib NetworkTables Library", + requires = ["robotpy-native-wpiutil==0.0.0", "robotpy-native-wpinet==0.0.0", "robotpy-native-datalog==0.0.0"], + python_requires = ">=3.11", + strip_path_prefixes = ["ntcore"], entry_points = { "pkg_config": [ "ntcore = native.ntcore", diff --git a/ntcore/robotpy_pybind_build_info.bzl b/ntcore/robotpy_pybind_build_info.bzl index 75eed60537..fb2529281a 100644 --- a/ntcore/robotpy_pybind_build_info.bzl +++ b/ntcore/robotpy_pybind_build_info.bzl @@ -1,7 +1,7 @@ # 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:robotpy_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") @@ -468,6 +468,7 @@ def define_pybind_library(name, pkgcfgs = []): robotpy_library( name = name, + distribution = "pyntcore", srcs = native.glob(["src/main/python/ntcore/**/*.py"]) + [ "src/main/python/ntcore/_init__ntcore.py", "{}.generate_version".format(name), @@ -490,6 +491,7 @@ def define_pybind_library(name, pkgcfgs = []): project_urls = {"Source code": "https://github.com/robotpy/mostrobotpy"}, author_email = "RobotPy Development Team ", requires = ["robotpy-native-ntcore==0.0.0", "robotpy-wpiutil==0.0.0", "robotpy-wpinet==0.0.0", "robotpy-wpilog==0.0.0"], + python_requires = ">=3.11", entry_points = { "pkg_config": ["ntcore = ntcore"], }, diff --git a/ntcore/src/main/python/native-pyproject.toml b/ntcore/src/main/python/native-pyproject.toml index 888d18292b..b44097dfec 100644 --- a/ntcore/src/main/python/native-pyproject.toml +++ b/ntcore/src/main/python/native-pyproject.toml @@ -13,6 +13,7 @@ requires = [ name = "robotpy-native-ntcore" version = "0.0.0" description = "WPILib NetworkTables Library" +requires-python = ">=3.11" license = "BSD-3-Clause" dependencies = [ diff --git a/ntcore/src/main/python/pyproject.toml b/ntcore/src/main/python/pyproject.toml index 75283e5ca8..ccccc73030 100644 --- a/ntcore/src/main/python/pyproject.toml +++ b/ntcore/src/main/python/pyproject.toml @@ -16,6 +16,7 @@ requires = [ name = "pyntcore" version = "0.0.0" description = "Binary wrappers for the FIRST ntcore library" +requires-python = ">=3.11" authors = [ {name = "RobotPy Development Team", email = "robotpy@googlegroups.com"}, ] diff --git a/romiVendordep/robotpy_native_build_info.bzl b/romiVendordep/robotpy_native_build_info.bzl index 7b790587ff..4aff704aeb 100644 --- a/romiVendordep/robotpy_native_build_info.bzl +++ b/romiVendordep/robotpy_native_build_info.bzl @@ -1,9 +1,11 @@ # 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") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "copy_native_file", "generate_native_files", "robotpy_library") def define_native_wrapper(name, pyproject_toml = None): + pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml" + 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), @@ -17,23 +19,40 @@ def define_native_wrapper(name, pyproject_toml = None): visibility = ["//visibility:public"], ) - native_wrappery_library( + libinit_files = ["native/romi/_init_robotpy_native_romi.py"] + + generate_native_files( 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", + pyproject_toml = pyproject_toml, pc_deps = [ "//wpilibc:native/wpilib/robotpy-native-wpilib.pc", ], + libinit_files = libinit_files, + pc_files = ["native/romi/robotpy-native-romi.pc"], + ) + + copy_native_file( + name = "romiVendordep", + library = "shared/romiVendordep", + base_path = "native/romi/", + ) + + robotpy_library( + name = name, + distribution = "robotpy-native-romi", + srcs = libinit_files, + data = [ + name + ".pc_wrapper", + ":romiVendordep.copy_lib", + "{}.copy_headers".format(name), + ], deps = [ "//wpilibc:robotpy-native-wpilib", ], - headers = "{}.copy_headers".format(name), - native_shared_library = "shared/romiVendordep", - install_path = "native/romi/", - strip_path_prefixes = ["romiVendordep"], - requires = ["robotpy-native-wpilib==0.0.0"], summary = "WPILib Romi support library", + requires = ["robotpy-native-wpilib==0.0.0"], + python_requires = ">=3.11", + strip_path_prefixes = ["romiVendordep"], entry_points = { "pkg_config": [ "romi = native.romi", diff --git a/romiVendordep/robotpy_pybind_build_info.bzl b/romiVendordep/robotpy_pybind_build_info.bzl index 5ccb710743..9e115333a8 100644 --- a/romiVendordep/robotpy_pybind_build_info.bzl +++ b/romiVendordep/robotpy_pybind_build_info.bzl @@ -1,7 +1,7 @@ # 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:robotpy_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") @@ -160,6 +160,7 @@ def define_pybind_library(name, pkgcfgs = []): robotpy_library( name = name, + distribution = "robotpy-romi", srcs = native.glob(["src/main/python/romi/**/*.py"]) + [ "src/main/python/romi/_init__romi.py", "{}.generate_version".format(name), @@ -181,6 +182,7 @@ def define_pybind_library(name, pkgcfgs = []): project_urls = {"Source code": "https://github.com/robotpy/mostrobotpy"}, author_email = "RobotPy Development Team ", requires = ["robotpy-native-romi==0.0.0", "wpilib==0.0.0", "robotpy-halsim-ws==0.0.0"], + python_requires = ">=3.11", entry_points = { "pkg_config": ["romi = romi"], "robotpy_cli.2027": ["run-romi = romi.cli:RunRomi"], diff --git a/romiVendordep/src/main/python/native-pyproject.toml b/romiVendordep/src/main/python/native-pyproject.toml index 0a96e8a6d1..f3fc1f9b13 100644 --- a/romiVendordep/src/main/python/native-pyproject.toml +++ b/romiVendordep/src/main/python/native-pyproject.toml @@ -11,6 +11,7 @@ requires = [ name = "robotpy-native-romi" version = "0.0.0" description = "WPILib Romi support library" +requires-python = ">=3.11" license = "BSD-3-Clause" dependencies = [ diff --git a/romiVendordep/src/main/python/pyproject.toml b/romiVendordep/src/main/python/pyproject.toml index 2b7a337888..98e1bbbc6b 100644 --- a/romiVendordep/src/main/python/pyproject.toml +++ b/romiVendordep/src/main/python/pyproject.toml @@ -14,6 +14,7 @@ requires = [ name = "robotpy-romi" version = "0.0.0" description = "Binary wrapper for WPILib Romi Vendor library" +requires-python = ">=3.11" authors = [ {name = "RobotPy Development Team", email = "robotpy@googlegroups.com"}, ] diff --git a/shared/bazel/rules/robotpy/BUILD.bazel b/shared/bazel/rules/robotpy/BUILD.bazel index a4646c3918..95cb4631aa 100644 --- a/shared/bazel/rules/robotpy/BUILD.bazel +++ b/shared/bazel/rules/robotpy/BUILD.bazel @@ -31,6 +31,7 @@ py_binary( deps = [ ":generation_utils", ":hack_pkgcfgs", + "//shared/bazel/rules/robotpy/hatchlib_native_port:generate_native_lib_files", requirement("semiwrap"), requirement("jinja2"), ], diff --git a/shared/bazel/rules/robotpy/generate_native_build_file.py b/shared/bazel/rules/robotpy/generate_native_build_file.py index 349ca9ce4f..3b355fc435 100644 --- a/shared/bazel/rules/robotpy/generate_native_build_file.py +++ b/shared/bazel/rules/robotpy/generate_native_build_file.py @@ -3,12 +3,14 @@ import json import tomli from jinja2 import BaseLoader, Environment +from packaging.markers import Marker from shared.bazel.rules.robotpy.generation_utils import ( fixup_python_dep_name, fixup_root_package_name, - fixup_shared_lib_name, ) +from shared.bazel.rules.robotpy.hatchlib_native_port.config import PcFileConfig +from shared.bazel.rules.robotpy.hatchlib_native_port.validate import parse_input def main(): @@ -40,20 +42,48 @@ def main(): env.filters["double_quotes"] = double_quotes env.filters["get_pc_dep"] = get_pc_dep env.filters["get_python_dep"] = get_python_dep + env.filters["strip_src_prefix"] = lambda x: str(x).removeprefix("src/") template = env.from_string(BUILD_FILE_TEMPLATE) nativelib_config = raw_config["tool"]["hatch"]["build"]["hooks"]["nativelib"] - project_name = nativelib_config["pcfile"][0]["name"] + project_name = raw_config["project"]["name"].replace("robotpy-native-", "") root_package = fixup_root_package_name(project_name) - shared_library_name = fixup_shared_lib_name(project_name) + pc_files = [] + + local_pc_names = set() + for i, raw_pc in enumerate(nativelib_config.get("pcfile", [])): + pcfile = parse_input( + raw_pc, + PcFileConfig, + "pyproject.toml", + f"tool.hatch.build.hooks.nativelib.pcfile[{i}]", + ) + if pcfile.enable_if and not Marker(pcfile.enable_if).evaluate(): + continue + pc_files.append(pcfile) + local_pc_names.add(pcfile.get_pc_path().name[:-3]) + + requires = set() + for pcfile in pc_files: + if pcfile.requires: + for dep in pcfile.requires: + if dep not in local_pc_names: + requires.add(dep) + + maven_downloads = raw_config["tool"]["hatch"]["build"]["hooks"]["robotpy"][ + "maven_lib_download" + ] with open(args.output_file, "w") as f: f.write( template.render( raw_project_config=raw_config["project"], nativelib_config=nativelib_config, root_package=root_package, - shared_library_name=shared_library_name, + maven_downloads=maven_downloads, third_party_dirs=args.third_party_dirs or [], + pc_files=pc_files, + requires=requires, + project_name=project_name, ) ) @@ -61,9 +91,11 @@ def main(): BUILD_FILE_TEMPLATE = """# 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") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "copy_native_file", "generate_native_files", "robotpy_library") def define_native_wrapper(name, pyproject_toml = None): + pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml" + 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){% if third_party_dirs %} + native.glob([ @@ -71,7 +103,7 @@ def define_native_wrapper(name, pyproject_toml = None): "src/main/native/thirdparty/{{dir}}/include/**", {%- endfor %} ]){%- endif %}, - out = "native/{{nativelib_config.pcfile[0].name}}/include", + out = "native/{{project_name}}/include", root_paths = ["src/main/native/include/"], replace_prefixes = { "{{root_package}}/src/generated/main/native/include": "", @@ -84,30 +116,57 @@ def define_native_wrapper(name, pyproject_toml = None): visibility = ["//visibility:public"], ) - native_wrappery_library( + libinit_files = [{% for pcfile in pc_files %}"{{pcfile.get_init_module_path() | strip_src_prefix}}"{% if not loop.last %}, {% endif %}{%- endfor %}] + + generate_native_files( name = name, - pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml", - libinit_file = "native/{{nativelib_config.pcfile[0].name}}/_init_{{raw_project_config.name.replace("-", "_")}}.py", - pc_file = "native/{{nativelib_config.pcfile[0].name}}/{{raw_project_config.name}}.pc", + pyproject_toml = pyproject_toml, pc_deps = [ - {%- for dep in nativelib_config.pcfile[0].requires | sort %} + {%- for dep in requires | sort %} "{{dep | get_pc_dep}}", {%- endfor %} ], + libinit_files = libinit_files, + pc_files = [{% for pcfile in pc_files %}"{{pcfile.pcfile | strip_src_prefix}}"{% if not loop.last %}, {% endif %}{%- endfor %}], + ) + {%- for maven_info in maven_downloads %} + {%- for lib in maven_info["libs"] %} + + copy_native_file( + name = "{{lib}}", + library = "shared/{{lib}}", + base_path = "native/{{project_name}}/", + ) + {%- endfor %} + {%- endfor %} + + robotpy_library( + name = name, + distribution = "{{raw_project_config.name}}", + srcs = libinit_files, + data = [ + name + ".pc_wrapper", + {%- for maven_info in maven_downloads %} + {%- for lib in maven_info["libs"] %} + ":{{lib}}.copy_lib", + {%- endfor %} + {%- endfor %} + "{}.copy_headers".format(name), + ], deps = [ - {%- for dep in nativelib_config.pcfile[0].requires | sort %} + {%- for dep in requires | sort %} "{{dep | get_python_dep}}", {%- endfor %} ], - headers = "{}.copy_headers".format(name), - native_shared_library = "shared/{{shared_library_name}}", - install_path = "native/{{nativelib_config.pcfile[0].name}}/", - strip_path_prefixes = ["{{root_package}}"], - requires = {{raw_project_config.dependencies | double_quotes}}, summary = "{{raw_project_config.description}}", + requires = {{raw_project_config.dependencies | double_quotes}}, + python_requires = "{{raw_project_config["requires-python"]}}", + strip_path_prefixes = ["{{root_package}}"], entry_points = { "pkg_config": [ - "{{nativelib_config.pcfile[0].name}} = native.{{nativelib_config.pcfile[0].name}}", + {%- for pcfile in pc_files %} + "{{pcfile.name}} = native.{{pcfile.name}}", + {%- endfor %} ], }, ) diff --git a/shared/bazel/rules/robotpy/generate_pybind_build_file.py b/shared/bazel/rules/robotpy/generate_pybind_build_file.py index e1b3fcbfdd..f1fd27344f 100644 --- a/shared/bazel/rules/robotpy/generate_pybind_build_file.py +++ b/shared/bazel/rules/robotpy/generate_pybind_build_file.py @@ -209,6 +209,8 @@ class BazelExtensionModule: transitive_deps = set() self._get_transitive_native_dependencies(dep_name, transitive_deps) for d in transitive_deps: + if d == "robotpy-native-mrclib": + continue base_library = fixup_root_package_name( d.replace("robotpy-native-", "") ) diff --git a/shared/bazel/rules/robotpy/hatchlib_native_port/generate_native_lib_files.py b/shared/bazel/rules/robotpy/hatchlib_native_port/generate_native_lib_files.py index 4d5117bf12..cf80f60c47 100644 --- a/shared/bazel/rules/robotpy/hatchlib_native_port/generate_native_lib_files.py +++ b/shared/bazel/rules/robotpy/hatchlib_native_port/generate_native_lib_files.py @@ -1,4 +1,5 @@ import functools +import os import pathlib import platform import sys @@ -22,9 +23,7 @@ is_macos = platform_sys == "Darwin" class NativelibHook: - def __init__(self, output_pcfile, output_libinit, config, metadata): - self.output_pcfile = output_pcfile - self.output_libinit = output_libinit + def __init__(self, output_pcfile, config, metadata): self.config = config self.root_pth = output_pcfile.parent.parent.parent @@ -32,7 +31,19 @@ class NativelibHook: def initialize(self): for pcfg in self._pcfiles: - self._generate_pcfile(pcfg, {}) + pcfile = self._generate_pcfile(pcfg, {}) + self._add_pkg_config_path(str(pcfile.parent)) + + def _add_pkg_config_path(self, *paths: str) -> None: + current = os.environ.get("PKG_CONFIG_PATH") + entries = current.split(os.pathsep) if current else [] + + for path in paths: + if path not in entries: + entries.append(path) + + if entries: + os.environ["PKG_CONFIG_PATH"] = os.pathsep.join(entries) def _get_pkg_from_path(self, path: pathlib.Path) -> str: rel = path.relative_to(self.root_pth) @@ -43,7 +54,7 @@ class NativelibHook: ) -> pathlib.Path: pcfile_rel = pcfg.get_pc_path() - pcfile = self.output_pcfile + pcfile = self.root_pth / str(pcfile_rel).removeprefix("src/") prefix_rel = pcfile_rel.parent prefix_path = pcfile.parent @@ -147,7 +158,7 @@ class NativelibHook: build_data: T.Dict[str, T.Any], ): libinit_py_rel = pcfg.get_init_module_path() - self.root_pth / libinit_py_rel + libinit_py = self.root_pth / str(libinit_py_rel).removeprefix("src/") libdir = prefix_path if pcfg.libdir: @@ -165,7 +176,7 @@ class NativelibHook: else: requires = [] - _write_libinit_py(self.output_libinit, lib_paths, requires) + _write_libinit_py(libinit_py, lib_paths, requires) def _make_shared_lib_fname(self, lib: str): if is_windows: @@ -298,9 +309,8 @@ def _write_libinit_py( def main(): pyproject_toml = sys.argv[1] - libinit_file = pathlib.Path(sys.argv[2]) - pc_file = pathlib.Path(sys.argv[3]) - pkgcfgs = [pathlib.Path(x) for x in sys.argv[4:]] + pc_file = pathlib.Path(sys.argv[2]) + pkgcfgs = [pathlib.Path(x) for x in sys.argv[3:]] hack_pkgconfig(pkgcfgs) @@ -310,7 +320,7 @@ def main(): nativelib_cfg = raw_config["tool"]["hatch"]["build"]["hooks"]["nativelib"] metadata = raw_config["project"] - generator = NativelibHook(pc_file, libinit_file, nativelib_cfg, metadata) + generator = NativelibHook(pc_file, nativelib_cfg, metadata) generator.initialize() diff --git a/shared/bazel/rules/robotpy/pybind_build_file_template.jinja2 b/shared/bazel/rules/robotpy/pybind_build_file_template.jinja2 index 623b48d7b0..11ea4b6c31 100644 --- a/shared/bazel/rules/robotpy/pybind_build_file_template.jinja2 +++ b/shared/bazel/rules/robotpy/pybind_build_file_template.jinja2 @@ -8,7 +8,7 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") {%- if version_file %} load("//shared/bazel/rules/gen:gen-version-file.bzl", "generate_version_file") {%- endif %} -load("//shared/bazel/rules/robotpy:pybind_rules.bzl", "create_pybind_library", "robotpy_library") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "create_pybind_library", "robotpy_library") load("//shared/bazel/rules/robotpy:semiwrap_helpers.bzl", "gen_libinit", "gen_modinit_hpp", "gen_pkgconf", {% if publish_casters_targets %}"publish_casters", {% endif %}"resolve_casters", "run_header_gen") load("//shared/bazel/rules/robotpy:semiwrap_tool_helpers.bzl", "scan_headers", "update_yaml_files") {% for extension_module in extension_modules%} @@ -193,6 +193,7 @@ def define_pybind_library(name, pkgcfgs = []): {% endif %} robotpy_library( name = name, + distribution = "{{raw_project_config.name}}", srcs = native.glob(["{{stripped_include_prefix}}/{{top_level_name}}/**/*.py"]) + [ {%- for em in extension_modules %} "{{stripped_include_prefix}}/{{ em.gen_pkgconf.libinit_py.replace(".", "/") }}.py", @@ -222,6 +223,7 @@ def define_pybind_library(name, pkgcfgs = []): project_urls = {{raw_project_config.urls | jsonify}}, author_email = "RobotPy Development Team ", requires = {{raw_project_config.dependencies | jsonify}}, + python_requires = {{raw_project_config["requires-python"] | jsonify}}, entry_points = { {%- for group, entries in entry_points.items() %} "{{ group }}": {{entries | jsonify}}, diff --git a/shared/bazel/rules/robotpy/pybind_rules.bzl b/shared/bazel/rules/robotpy/robotpy_rules.bzl similarity index 77% rename from shared/bazel/rules/robotpy/pybind_rules.bzl rename to shared/bazel/rules/robotpy/robotpy_rules.bzl index 5a1e58094f..6d5739fa71 100644 --- a/shared/bazel/rules/robotpy/pybind_rules.bzl +++ b/shared/bazel/rules/robotpy/robotpy_rules.bzl @@ -87,11 +87,14 @@ def robotpy_library( deps = [], data = [], strip_path_prefixes = None, + distribution = None, summary = None, project_urls = None, author_email = None, entry_points = None, requires = None, + description_file = None, + python_requires = None, **kwargs): """ Defines a python library that is wrapping a series of pybind extensions. @@ -110,7 +113,7 @@ def robotpy_library( py_wheel( name = "{}-wheel".format(name), - distribution = name, + distribution = distribution, stamp = 1, version = "$(ROBOTPY_VERSION)", summary = summary, @@ -120,6 +123,8 @@ def robotpy_library( deps = data + [":{}-lib".format(name)], strip_path_prefixes = strip_path_prefixes, entry_points = entry_points, + description_file = description_file, + python_requires = python_requires, license = "BSD-3-Clause", tags = ["robotpy"], ) @@ -172,90 +177,25 @@ def copy_native_file(name, library, base_path): tags = ["robotpy"], ) -def _folder_prefix(name): - if "/" in name: - last_slash = name.rfind("/") - return (name[0:last_slash], name[last_slash + 1:]) - else: - return ("", name) - -def native_wrappery_library( - name, - pyproject_toml, - libinit_file, - pc_file, - pc_deps, - native_shared_library, - install_path, - headers, - strip_path_prefixes = [], - summary = None, - project_urls = None, - author_email = None, - entry_points = None, - requires = None, - deps = []): - """ - This function provides a sugar wrapper for defining a python library that wraps an allwpilib native library - """ +def generate_native_files(name, pyproject_toml, pc_deps, libinit_files, pc_files): cmd = "$(locations //shared/bazel/rules/robotpy/hatchlib_native_port:generate_native_lib_files) " cmd += " $(location " + pyproject_toml + ")" - cmd += " $(OUTS) " + cmd += " $(location " + pc_files[0] + ") " for pc_dep in pc_deps: cmd += " $(location " + pc_dep + ")" native.genrule( name = name + ".gen", srcs = [pyproject_toml], - outs = [libinit_file, pc_file], + outs = libinit_files + pc_files, cmd = cmd, tools = ["//shared/bazel/rules/robotpy/hatchlib_native_port:generate_native_lib_files"] + pc_deps, visibility = ["//visibility:public"], tags = ["robotpy"], - ) - - prefix, libname = _folder_prefix(native_shared_library) - - copy_native_file( - name = libname, - library = native_shared_library, - base_path = install_path, + target_compatible_with = robotpy_compatibility_select(), ) native.filegroup( name = name + ".pc_wrapper", - srcs = [pc_file], - ) - - py_library( - name = name + "-lib", - srcs = [libinit_file], - data = [pc_file, ":{}.copy_lib".format(libname), headers], - deps = deps, - imports = ["."], - tags = ["robotpy"], - ) - - py_wheel( - name = "{}-wheel".format(name), - distribution = name, - stamp = 1, - version = "$(ROBOTPY_VERSION)", - summary = summary, - requires = requires, - project_urls = project_urls, - author_email = author_email, - deps = [name + "-lib", ":{}.copy_lib".format(libname), headers, name + ".pc_wrapper"], - strip_path_prefixes = strip_path_prefixes, - entry_points = entry_points, - tags = ["robotpy"], - license = "BSD-3-Clause", - ) - - pycross_wheel_library( - name = "{}".format(name), - wheel = "{}-wheel".format(name), - visibility = ["//visibility:public"], - tags = ["manual"], - deps = deps, + srcs = pc_files, ) diff --git a/simulation/halsim_ds_socket/BUILD.bazel b/simulation/halsim_ds_socket/BUILD.bazel index 1ea4bd915f..ab5d9f2807 100644 --- a/simulation/halsim_ds_socket/BUILD.bazel +++ b/simulation/halsim_ds_socket/BUILD.bazel @@ -1,11 +1,11 @@ load("@allwpilib_pip_deps//:requirements.bzl", "requirement") load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") -load("@rules_python//python:defs.bzl", "py_library") load("//shared/bazel/rules:cc_rules.bzl", "wpilib_cc_library", "wpilib_cc_shared_library", "wpilib_cc_static_library") load("//shared/bazel/rules:packaging.bzl", "package_default_cc_project") load("//shared/bazel/rules:publishing.bzl", "host_architectures") -load("//shared/bazel/rules/robotpy:pybind_rules.bzl", "copy_native_file") +load("//shared/bazel/rules/gen:gen-version-file.bzl", "generate_version_file") load("//shared/bazel/rules/robotpy:pytest_util.bzl", "robotpy_py_test") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "copy_native_file", "robotpy_library") cc_library( name = "headers", @@ -103,13 +103,28 @@ copy_native_file( library = "shared/halsim_ds_socket", ) -py_library( +generate_version_file( + name = "generate_python_version", + output_file = "src/main/python/halsim_ds_socket/version.py", + template = "//shared/bazel/rules/robotpy:version_template.in", +) + +robotpy_library( name = "robotpy-halsim-ds-socket", - srcs = glob(["src/main/python/**/*.py"]), - data = [ - ":halsim_ds_socket.copy_lib", - ], + srcs = glob(["src/main/python/**/*.py"]) + [":generate_python_version"], + author_email = "RobotPy Development Team ", + data = [":halsim_ds_socket.copy_lib"], + distribution = "robotpy-halsim-ds-socket", + entry_points = { + "robotpy_sim.2027": ["ds-socket = halsim_ds_socket"], + }, imports = ["src/main/python"], + requires = [ + "robotpy-native-wpihal==0.0.0", + "robotpy-native-wpinet==0.0.0", + ], + strip_path_prefixes = ["simulation/halsim_ds_socket/src/main/python"], + summary = "WPILib simulator DS Socket Extension", deps = [ "//hal:robotpy-native-wpihal", "//wpinet:robotpy-native-wpinet", diff --git a/simulation/halsim_ds_socket/src/main/python/pyproject.toml b/simulation/halsim_ds_socket/src/main/python/pyproject.toml index 2df613abdf..82265d8d67 100644 --- a/simulation/halsim_ds_socket/src/main/python/pyproject.toml +++ b/simulation/halsim_ds_socket/src/main/python/pyproject.toml @@ -9,6 +9,7 @@ requires = [ name = "robotpy-halsim-ds-socket" version = "0.0.0" description = "WPILib simulator DS Socket Extension" +requires-python = ">=3.11" authors = [ {name = "RobotPy Development Team", email = "robotpy@googlegroups.com"}, ] diff --git a/simulation/halsim_gui/robotpy_pybind_build_info.bzl b/simulation/halsim_gui/robotpy_pybind_build_info.bzl index 7e9356ea48..00563162bd 100644 --- a/simulation/halsim_gui/robotpy_pybind_build_info.bzl +++ b/simulation/halsim_gui/robotpy_pybind_build_info.bzl @@ -1,7 +1,7 @@ # 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", "copy_native_file", "create_pybind_library", "robotpy_library") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "copy_native_file", "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") def halsim_gui_ext_extension(srcs = [], header_to_dat_deps = [], extra_hdrs = [], includes = []): @@ -130,6 +130,7 @@ def define_pybind_library(name, pkgcfgs = []): robotpy_library( name = name, + distribution = "robotpy-halsim-gui", srcs = native.glob(["src/main/python/halsim_gui/**/*.py"]) + [ "src/main/python/halsim_gui/_ext/_init__halsim_gui_ext.py", "{}.generate_version".format(name), diff --git a/simulation/halsim_gui/src/main/python/pyproject.toml b/simulation/halsim_gui/src/main/python/pyproject.toml index 4f425830d2..423edfc54b 100644 --- a/simulation/halsim_gui/src/main/python/pyproject.toml +++ b/simulation/halsim_gui/src/main/python/pyproject.toml @@ -15,6 +15,7 @@ requires = [ name = "robotpy-halsim-gui" version = "0.0.0" description = "WPILib simulation GUI" +requires-python = ">=3.11" authors = [ {name = "RobotPy Development Team", email = "robotpy@googlegroups.com"}, ] diff --git a/simulation/halsim_ws_core/BUILD.bazel b/simulation/halsim_ws_core/BUILD.bazel index 38e290b678..a3cfbd0dfd 100644 --- a/simulation/halsim_ws_core/BUILD.bazel +++ b/simulation/halsim_ws_core/BUILD.bazel @@ -1,10 +1,10 @@ load("@allwpilib_pip_deps//:requirements.bzl", "requirement") -load("@rules_python//python:defs.bzl", "py_library") load("//shared/bazel/rules:cc_rules.bzl", "wpilib_cc_library", "wpilib_cc_shared_library", "wpilib_cc_static_library") load("//shared/bazel/rules:packaging.bzl", "package_default_cc_project") load("//shared/bazel/rules:publishing.bzl", "host_architectures") -load("//shared/bazel/rules/robotpy:pybind_rules.bzl", "copy_native_file") +load("//shared/bazel/rules/gen:gen-version-file.bzl", "generate_version_file") load("//shared/bazel/rules/robotpy:pytest_util.bzl", "robotpy_py_test") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "copy_native_file", "robotpy_library") wpilib_cc_library( name = "halsim_ws_core", @@ -71,15 +71,35 @@ copy_native_file( library = "//simulation/halsim_ws_server:shared/halsim_ws_server", ) -py_library( +generate_version_file( + name = "generate_python_version", + output_file = "src/main/python/halsim_ws/version.py", + template = "//shared/bazel/rules/robotpy:version_template.in", +) + +robotpy_library( name = "robotpy-halsim-ws", - srcs = glob(["src/main/python/**/*.py"]), + srcs = glob(["src/main/python/**/*.py"]) + [":generate_python_version"], + author_email = "RobotPy Development Team ", data = [ ":halsim_ws_client.copy_lib", ":halsim_ws_server.copy_lib", ], + distribution = "robotpy-halsim-ws", + entry_points = { + "robotpy_sim.2027": [ + "ws-client = halsim_ws.client", + "ws-server = halsim_ws.server", + ], + }, imports = ["src/main/python"], - visibility = ["//visibility:public"], + project_urls = {"Source code": "https://github.com/robotpy/mostrobotpy"}, + requires = [ + "robotpy-native-wpihal==0.0.0", + "robotpy-native-wpinet==0.0.0", + ], + strip_path_prefixes = ["simulation/halsim_ws_core/src/main/python"], + summary = "WPILib simulator websim Extensions", deps = [ "//hal:robotpy-native-wpihal", "//wpinet:robotpy-native-wpinet", diff --git a/simulation/halsim_ws_core/src/main/python/pyproject.toml b/simulation/halsim_ws_core/src/main/python/pyproject.toml index b2692d47d7..c2a327d738 100644 --- a/simulation/halsim_ws_core/src/main/python/pyproject.toml +++ b/simulation/halsim_ws_core/src/main/python/pyproject.toml @@ -9,6 +9,7 @@ requires = [ name = "robotpy-halsim-ws" version = "0.0.0" description = "WPILib simulator websim Extensions" +requires-python = ">=3.11" authors = [ {name = "RobotPy Development Team", email = "robotpy@googlegroups.com"}, ] diff --git a/wpilibc/robotpy_native_build_info.bzl b/wpilibc/robotpy_native_build_info.bzl index dd896556f1..f2a7428c7e 100644 --- a/wpilibc/robotpy_native_build_info.bzl +++ b/wpilibc/robotpy_native_build_info.bzl @@ -1,9 +1,11 @@ # 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") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "copy_native_file", "generate_native_files", "robotpy_library") def define_native_wrapper(name, pyproject_toml = None): + pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml" + 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), @@ -17,11 +19,11 @@ def define_native_wrapper(name, pyproject_toml = None): visibility = ["//visibility:public"], ) - native_wrappery_library( + libinit_files = ["native/wpilib/_init_robotpy_native_wpilib.py"] + + generate_native_files( name = name, - pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml", - libinit_file = "native/wpilib/_init_robotpy_native_wpilib.py", - pc_file = "native/wpilib/robotpy-native-wpilib.pc", + pyproject_toml = pyproject_toml, pc_deps = [ "//ntcore:native/ntcore/robotpy-native-ntcore.pc", "//hal:native/wpihal/robotpy-native-wpihal.pc", @@ -29,6 +31,25 @@ def define_native_wrapper(name, pyproject_toml = None): "//wpinet:native/wpinet/robotpy-native-wpinet.pc", "//wpiutil:native/wpiutil/robotpy-native-wpiutil.pc", ], + libinit_files = libinit_files, + pc_files = ["native/wpilib/robotpy-native-wpilib.pc"], + ) + + copy_native_file( + name = "wpilibc", + library = "shared/wpilibc", + base_path = "native/wpilib/", + ) + + robotpy_library( + name = name, + distribution = "robotpy-native-wpilib", + srcs = libinit_files, + data = [ + name + ".pc_wrapper", + ":wpilibc.copy_lib", + "{}.copy_headers".format(name), + ], deps = [ "//ntcore:robotpy-native-ntcore", "//hal:robotpy-native-wpihal", @@ -36,12 +57,10 @@ def define_native_wrapper(name, pyproject_toml = None): "//wpinet:robotpy-native-wpinet", "//wpiutil:robotpy-native-wpiutil", ], - headers = "{}.copy_headers".format(name), - native_shared_library = "shared/wpilibc", - install_path = "native/wpilib/", - strip_path_prefixes = ["wpilibc"], - requires = ["robotpy-native-wpiutil==0.0.0", "robotpy-native-wpinet==0.0.0", "robotpy-native-ntcore==0.0.0", "robotpy-native-wpimath==0.0.0", "robotpy-native-wpihal==0.0.0"], summary = "WPILib Robotics Library", + requires = ["robotpy-native-wpiutil==0.0.0", "robotpy-native-wpinet==0.0.0", "robotpy-native-ntcore==0.0.0", "robotpy-native-wpimath==0.0.0", "robotpy-native-wpihal==0.0.0"], + python_requires = ">=3.11", + strip_path_prefixes = ["wpilibc"], entry_points = { "pkg_config": [ "wpilib = native.wpilib", diff --git a/wpilibc/robotpy_pybind_build_info.bzl b/wpilibc/robotpy_pybind_build_info.bzl index 6a98cd3b28..c298998eef 100644 --- a/wpilibc/robotpy_pybind_build_info.bzl +++ b/wpilibc/robotpy_pybind_build_info.bzl @@ -2,7 +2,7 @@ load("@allwpilib_pip_deps//:requirements.bzl", "requirement") 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:robotpy_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") @@ -1720,6 +1720,7 @@ def define_pybind_library(name, pkgcfgs = []): robotpy_library( name = name, + distribution = "wpilib", srcs = native.glob(["src/main/python/wpilib/**/*.py"]) + [ "src/main/python/wpilib/_init__wpilib.py", "src/main/python/wpilib/simulation/_init__simulation.py", @@ -1749,6 +1750,7 @@ def define_pybind_library(name, pkgcfgs = []): project_urls = {"Source code": "https://github.com/robotpy/mostrobotpy"}, author_email = "RobotPy Development Team ", requires = ["robotpy-native-wpilib==0.0.0", "robotpy-wpiutil==0.0.0", "robotpy-wpimath==0.0.0", "robotpy-hal==0.0.0", "pyntcore==0.0.0", "robotpy-cli~=2027.0.0a1", "pytest>=3.9", "pytest-reraise"], + python_requires = ">=3.11", entry_points = { "pkg_config": ["wpilib = wpilib", "wpilib_simulation = wpilib.simulation"], "robotpy_cli.2027": ["add-tests = wpilib._impl.cli_add_tests:AddTests", "run = wpilib._impl.cli_run:Main", "sim = wpilib._impl.cli_sim:RobotSim", "test = wpilib._impl.cli_test:RobotTest"], diff --git a/wpilibc/src/main/python/native-pyproject.toml b/wpilibc/src/main/python/native-pyproject.toml index 70371e1eb1..27592d8c02 100644 --- a/wpilibc/src/main/python/native-pyproject.toml +++ b/wpilibc/src/main/python/native-pyproject.toml @@ -15,6 +15,7 @@ requires = [ name = "robotpy-native-wpilib" version = "0.0.0" description = "WPILib Robotics Library" +requires-python = ">=3.11" license = "BSD-3-Clause" dependencies = [ diff --git a/wpilibc/src/main/python/pyproject.toml b/wpilibc/src/main/python/pyproject.toml index ea95817ac3..c849304ddc 100644 --- a/wpilibc/src/main/python/pyproject.toml +++ b/wpilibc/src/main/python/pyproject.toml @@ -16,6 +16,7 @@ requires = [ name = "wpilib" version = "0.0.0" description = "Binary wrapper for WPILib" +requires-python = ">=3.11" authors = [ {name = "RobotPy Development Team", email = "robotpy@googlegroups.com"}, ] diff --git a/wpimath/robotpy_native_build_info.bzl b/wpimath/robotpy_native_build_info.bzl index 2418b0d3ea..059c8de99d 100644 --- a/wpimath/robotpy_native_build_info.bzl +++ b/wpimath/robotpy_native_build_info.bzl @@ -1,9 +1,11 @@ # 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") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "copy_native_file", "generate_native_files", "robotpy_library") def define_native_wrapper(name, pyproject_toml = None): + pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml" + 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) + native.glob([ @@ -22,23 +24,40 @@ def define_native_wrapper(name, pyproject_toml = None): visibility = ["//visibility:public"], ) - native_wrappery_library( + libinit_files = ["native/wpimath/_init_robotpy_native_wpimath.py"] + + generate_native_files( name = name, - pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml", - libinit_file = "native/wpimath/_init_robotpy_native_wpimath.py", - pc_file = "native/wpimath/robotpy-native-wpimath.pc", + pyproject_toml = pyproject_toml, pc_deps = [ "//wpiutil:native/wpiutil/robotpy-native-wpiutil.pc", ], + libinit_files = libinit_files, + pc_files = ["native/wpimath/robotpy-native-wpimath.pc"], + ) + + copy_native_file( + name = "wpimath", + library = "shared/wpimath", + base_path = "native/wpimath/", + ) + + robotpy_library( + name = name, + distribution = "robotpy-native-wpimath", + srcs = libinit_files, + data = [ + name + ".pc_wrapper", + ":wpimath.copy_lib", + "{}.copy_headers".format(name), + ], deps = [ "//wpiutil:robotpy-native-wpiutil", ], - headers = "{}.copy_headers".format(name), - native_shared_library = "shared/wpimath", - install_path = "native/wpimath/", - strip_path_prefixes = ["wpimath"], - requires = ["robotpy-native-wpiutil==0.0.0"], summary = "WPILib Math Library", + requires = ["robotpy-native-wpiutil==0.0.0"], + python_requires = ">=3.11", + strip_path_prefixes = ["wpimath"], entry_points = { "pkg_config": [ "wpimath = native.wpimath", diff --git a/wpimath/robotpy_pybind_build_info.bzl b/wpimath/robotpy_pybind_build_info.bzl index 337c9e9168..77b541846d 100644 --- a/wpimath/robotpy_pybind_build_info.bzl +++ b/wpimath/robotpy_pybind_build_info.bzl @@ -2,7 +2,7 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") 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:robotpy_rules.bzl", "create_pybind_library", "robotpy_library") load("//shared/bazel/rules/robotpy:semiwrap_helpers.bzl", "gen_libinit", "gen_modinit_hpp", "gen_pkgconf", "publish_casters", "resolve_casters", "run_header_gen") load("//shared/bazel/rules/robotpy:semiwrap_tool_helpers.bzl", "scan_headers", "update_yaml_files") @@ -1281,6 +1281,7 @@ def define_pybind_library(name, pkgcfgs = []): robotpy_library( name = name, + distribution = "robotpy-wpimath", srcs = native.glob(["src/main/python/wpimath/**/*.py"]) + [ "src/main/python/wpimath/_init__wpimath.py", "{}.generate_version".format(name), @@ -1301,6 +1302,7 @@ def define_pybind_library(name, pkgcfgs = []): project_urls = {"Source code": "https://github.com/robotpy/mostrobotpy"}, author_email = "RobotPy Development Team ", requires = ["robotpy-native-wpimath==0.0.0", "robotpy-wpiutil==0.0.0"], + python_requires = ">=3.11", entry_points = { "pkg_config": ["wpimath-casters = wpimath", "wpimath = wpimath"], }, diff --git a/wpimath/robotpy_pybind_test_info.bzl b/wpimath/robotpy_pybind_test_info.bzl index 9dff3e9ec9..b0d16b5f38 100644 --- a/wpimath/robotpy_pybind_test_info.bzl +++ b/wpimath/robotpy_pybind_test_info.bzl @@ -1,6 +1,6 @@ # THIS FILE IS AUTO GENERATED -load("//shared/bazel/rules/robotpy:pybind_rules.bzl", "create_pybind_library", "robotpy_library") +load("//shared/bazel/rules/robotpy:robotpy_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") @@ -121,6 +121,7 @@ def define_pybind_library(name, pkgcfgs = []): robotpy_library( name = name, + distribution = "wpimath_test", srcs = native.glob(["src/test/python/cpp/wpimath_test/**/*.py"]) + [ "src/test/python/cpp/wpimath_test/_init__wpimath_test.py", ], @@ -138,6 +139,7 @@ def define_pybind_library(name, pkgcfgs = []): project_urls = None, author_email = "RobotPy Development Team ", requires = None, + python_requires = ">=3.11", entry_points = { "pkg_config": ["wpimath_test = wpimath_test"], }, diff --git a/wpimath/src/main/python/native-pyproject.toml b/wpimath/src/main/python/native-pyproject.toml index 5769d64a41..d48dba8bf5 100644 --- a/wpimath/src/main/python/native-pyproject.toml +++ b/wpimath/src/main/python/native-pyproject.toml @@ -11,6 +11,7 @@ requires = [ name = "robotpy-native-wpimath" version = "0.0.0" description = "WPILib Math Library" +requires-python = ">=3.11" license = "BSD-3-Clause" dependencies = [ diff --git a/wpimath/src/main/python/pyproject.toml b/wpimath/src/main/python/pyproject.toml index c8d62ce5ed..fa8b8012f6 100644 --- a/wpimath/src/main/python/pyproject.toml +++ b/wpimath/src/main/python/pyproject.toml @@ -14,6 +14,7 @@ requires = [ name = "robotpy-wpimath" version = "0.0.0" description = "Binary wrapper for WPILib Math library" +requires-python = ">=3.11" authors = [ {name = "RobotPy Development Team", email = "robotpy@googlegroups.com"}, ] diff --git a/wpimath/src/test/python/cpp/pyproject.toml b/wpimath/src/test/python/cpp/pyproject.toml index 4320ebbe48..e803099427 100644 --- a/wpimath/src/test/python/cpp/pyproject.toml +++ b/wpimath/src/test/python/cpp/pyproject.toml @@ -8,6 +8,7 @@ requires = [ name = "wpimath_test" version = "0.1" description = "Test project for verifying robotpy-build behavior" +requires-python = ">=3.11" authors = [ {name = "RobotPy Development Team", email = "robotpy@googlegroups.com"}, ] diff --git a/wpinet/robotpy_native_build_info.bzl b/wpinet/robotpy_native_build_info.bzl index 8d6530a61d..74f13e622f 100644 --- a/wpinet/robotpy_native_build_info.bzl +++ b/wpinet/robotpy_native_build_info.bzl @@ -1,9 +1,11 @@ # 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") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "copy_native_file", "generate_native_files", "robotpy_library") def define_native_wrapper(name, pyproject_toml = None): + pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml" + 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) + native.glob([ @@ -22,23 +24,40 @@ def define_native_wrapper(name, pyproject_toml = None): visibility = ["//visibility:public"], ) - native_wrappery_library( + libinit_files = ["native/wpinet/_init_robotpy_native_wpinet.py"] + + generate_native_files( name = name, - pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml", - libinit_file = "native/wpinet/_init_robotpy_native_wpinet.py", - pc_file = "native/wpinet/robotpy-native-wpinet.pc", + pyproject_toml = pyproject_toml, pc_deps = [ "//wpiutil:native/wpiutil/robotpy-native-wpiutil.pc", ], + libinit_files = libinit_files, + pc_files = ["native/wpinet/robotpy-native-wpinet.pc"], + ) + + copy_native_file( + name = "wpinet", + library = "shared/wpinet", + base_path = "native/wpinet/", + ) + + robotpy_library( + name = name, + distribution = "robotpy-native-wpinet", + srcs = libinit_files, + data = [ + name + ".pc_wrapper", + ":wpinet.copy_lib", + "{}.copy_headers".format(name), + ], deps = [ "//wpiutil:robotpy-native-wpiutil", ], - headers = "{}.copy_headers".format(name), - native_shared_library = "shared/wpinet", - install_path = "native/wpinet/", - strip_path_prefixes = ["wpinet"], - requires = ["robotpy-native-wpiutil==0.0.0"], summary = "WPILib Networking Library", + requires = ["robotpy-native-wpiutil==0.0.0"], + python_requires = ">=3.11", + strip_path_prefixes = ["wpinet"], entry_points = { "pkg_config": [ "wpinet = native.wpinet", diff --git a/wpinet/robotpy_pybind_build_info.bzl b/wpinet/robotpy_pybind_build_info.bzl index 30f59718e2..6b566ba17e 100644 --- a/wpinet/robotpy_pybind_build_info.bzl +++ b/wpinet/robotpy_pybind_build_info.bzl @@ -1,7 +1,7 @@ # 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:robotpy_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") @@ -141,6 +141,7 @@ def define_pybind_library(name, pkgcfgs = []): robotpy_library( name = name, + distribution = "robotpy-wpinet", srcs = native.glob(["src/main/python/wpinet/**/*.py"]) + [ "src/main/python/wpinet/_init__wpinet.py", "{}.generate_version".format(name), @@ -161,6 +162,7 @@ def define_pybind_library(name, pkgcfgs = []): project_urls = {"Source code": "https://github.com/robotpy/mostrobotpy"}, author_email = "RobotPy Development Team ", requires = ["robotpy-native-wpinet==0.0.0", "robotpy-wpiutil==0.0.0"], + python_requires = ">=3.11", entry_points = { "pkg_config": ["wpinet = wpinet"], }, diff --git a/wpinet/src/main/python/native-pyproject.toml b/wpinet/src/main/python/native-pyproject.toml index 1175227015..842023167f 100644 --- a/wpinet/src/main/python/native-pyproject.toml +++ b/wpinet/src/main/python/native-pyproject.toml @@ -11,6 +11,7 @@ requires = [ name = "robotpy-native-wpinet" version = "0.0.0" description = "WPILib Networking Library" +requires-python = ">=3.11" license = "BSD-3-Clause" dependencies = [ diff --git a/wpinet/src/main/python/pyproject.toml b/wpinet/src/main/python/pyproject.toml index 182a508c16..c13cdbb560 100644 --- a/wpinet/src/main/python/pyproject.toml +++ b/wpinet/src/main/python/pyproject.toml @@ -14,6 +14,7 @@ requires = [ name = "robotpy-wpinet" version = "0.0.0" description = "Binary wrapper for WPILib networking library" +requires-python = ">=3.11" authors = [ {name = "RobotPy Development Team", email = "robotpy@googlegroups.com"}, ] diff --git a/wpiutil/BUILD.bazel b/wpiutil/BUILD.bazel index 18a5898b0d..67179fe43f 100644 --- a/wpiutil/BUILD.bazel +++ b/wpiutil/BUILD.bazel @@ -9,8 +9,8 @@ load("//shared/bazel/rules:jni_rules.bzl", "wpilib_jni_cc_library", "wpilib_jni_ load("//shared/bazel/rules:packaging.bzl", "package_default_jni_project") load("//shared/bazel/rules/gen:gen-resources.bzl", "generate_resources") 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:pybind_rules.bzl", "create_pybind_library") load("//shared/bazel/rules/robotpy:pytest_util.bzl", "robotpy_py_test") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "create_pybind_library") load("//wpiutil:generate.bzl", "generate_wpiutil") load("//wpiutil:robotpy_native_build_info.bzl", "define_native_wrapper") load("//wpiutil:robotpy_pybind_build_info.bzl", "define_pybind_library", "publish_library_casters", "wpiutil_extension") diff --git a/wpiutil/robotpy_native_build_info.bzl b/wpiutil/robotpy_native_build_info.bzl index 0ba99da483..e6d22bf848 100644 --- a/wpiutil/robotpy_native_build_info.bzl +++ b/wpiutil/robotpy_native_build_info.bzl @@ -1,9 +1,11 @@ # 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") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "copy_native_file", "generate_native_files", "robotpy_library") def define_native_wrapper(name, pyproject_toml = None): + pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml" + 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) + native.glob([ @@ -40,21 +42,38 @@ def define_native_wrapper(name, pyproject_toml = None): visibility = ["//visibility:public"], ) - native_wrappery_library( + libinit_files = ["native/wpiutil/_init_robotpy_native_wpiutil.py"] + + generate_native_files( name = name, - pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml", - libinit_file = "native/wpiutil/_init_robotpy_native_wpiutil.py", - pc_file = "native/wpiutil/robotpy-native-wpiutil.pc", + pyproject_toml = pyproject_toml, pc_deps = [ ], + libinit_files = libinit_files, + pc_files = ["native/wpiutil/robotpy-native-wpiutil.pc"], + ) + + copy_native_file( + name = "wpiutil", + library = "shared/wpiutil", + base_path = "native/wpiutil/", + ) + + robotpy_library( + name = name, + distribution = "robotpy-native-wpiutil", + srcs = libinit_files, + data = [ + name + ".pc_wrapper", + ":wpiutil.copy_lib", + "{}.copy_headers".format(name), + ], deps = [ ], - headers = "{}.copy_headers".format(name), - native_shared_library = "shared/wpiutil", - install_path = "native/wpiutil/", - strip_path_prefixes = ["wpiutil"], - requires = ["msvc-runtime>=14.42.34433; platform_system == 'Windows'"], summary = "WPILib Utility Library", + requires = ["msvc-runtime>=14.42.34433; platform_system == 'Windows'"], + python_requires = ">=3.11", + strip_path_prefixes = ["wpiutil"], entry_points = { "pkg_config": [ "wpiutil = native.wpiutil", diff --git a/wpiutil/robotpy_pybind_build_info.bzl b/wpiutil/robotpy_pybind_build_info.bzl index 7266380fa7..c525f62315 100644 --- a/wpiutil/robotpy_pybind_build_info.bzl +++ b/wpiutil/robotpy_pybind_build_info.bzl @@ -2,7 +2,7 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") 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:robotpy_rules.bzl", "create_pybind_library", "robotpy_library") load("//shared/bazel/rules/robotpy:semiwrap_helpers.bzl", "gen_libinit", "gen_modinit_hpp", "gen_pkgconf", "publish_casters", "resolve_casters", "run_header_gen") load("//shared/bazel/rules/robotpy:semiwrap_tool_helpers.bzl", "scan_headers", "update_yaml_files") @@ -238,6 +238,7 @@ def define_pybind_library(name, pkgcfgs = []): robotpy_library( name = name, + distribution = "robotpy-wpiutil", srcs = native.glob(["src/main/python/wpiutil/**/*.py"]) + [ "src/main/python/wpiutil/_init__wpiutil.py", "{}.generate_version".format(name), @@ -257,6 +258,7 @@ def define_pybind_library(name, pkgcfgs = []): project_urls = {"Source code": "https://github.com/robotpy/mostrobotpy"}, author_email = "RobotPy Development Team ", requires = ["robotpy-native-wpiutil==0.0.0"], + python_requires = ">=3.11", entry_points = { "pkg_config": ["wpiutil-casters = wpiutil", "wpiutil = wpiutil"], }, diff --git a/wpiutil/src/main/python/native-pyproject.toml b/wpiutil/src/main/python/native-pyproject.toml index 583dce76ad..54c2da1ddd 100644 --- a/wpiutil/src/main/python/native-pyproject.toml +++ b/wpiutil/src/main/python/native-pyproject.toml @@ -10,6 +10,7 @@ requires = [ name = "robotpy-native-wpiutil" version = "0.0.0" description = "WPILib Utility Library" +requires-python = ">=3.11" license = "BSD-3-Clause" dependencies = [ diff --git a/wpiutil/src/main/python/pyproject.toml b/wpiutil/src/main/python/pyproject.toml index 027183000a..0453ed35f9 100644 --- a/wpiutil/src/main/python/pyproject.toml +++ b/wpiutil/src/main/python/pyproject.toml @@ -12,6 +12,7 @@ requires = [ name = "robotpy-wpiutil" version = "0.0.0" description = "Binary wrapper for WPILib utilities library" +requires-python = ">=3.11" authors = [ {name = "RobotPy Development Team", email = "robotpy@googlegroups.com"}, ] diff --git a/xrpVendordep/robotpy_native_build_info.bzl b/xrpVendordep/robotpy_native_build_info.bzl index 40516a6da9..232fc8c177 100644 --- a/xrpVendordep/robotpy_native_build_info.bzl +++ b/xrpVendordep/robotpy_native_build_info.bzl @@ -1,9 +1,11 @@ # 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") +load("//shared/bazel/rules/robotpy:robotpy_rules.bzl", "copy_native_file", "generate_native_files", "robotpy_library") def define_native_wrapper(name, pyproject_toml = None): + pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml" + 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), @@ -17,23 +19,40 @@ def define_native_wrapper(name, pyproject_toml = None): visibility = ["//visibility:public"], ) - native_wrappery_library( + libinit_files = ["native/xrp/_init_robotpy_native_xrp.py"] + + generate_native_files( name = name, - pyproject_toml = pyproject_toml or "src/main/python/native-pyproject.toml", - libinit_file = "native/xrp/_init_robotpy_native_xrp.py", - pc_file = "native/xrp/robotpy-native-xrp.pc", + pyproject_toml = pyproject_toml, pc_deps = [ "//wpilibc:native/wpilib/robotpy-native-wpilib.pc", ], + libinit_files = libinit_files, + pc_files = ["native/xrp/robotpy-native-xrp.pc"], + ) + + copy_native_file( + name = "xrpVendordep", + library = "shared/xrpVendordep", + base_path = "native/xrp/", + ) + + robotpy_library( + name = name, + distribution = "robotpy-native-xrp", + srcs = libinit_files, + data = [ + name + ".pc_wrapper", + ":xrpVendordep.copy_lib", + "{}.copy_headers".format(name), + ], deps = [ "//wpilibc:robotpy-native-wpilib", ], - headers = "{}.copy_headers".format(name), - native_shared_library = "shared/xrpVendordep", - install_path = "native/xrp/", - strip_path_prefixes = ["xrpVendordep"], - requires = ["robotpy-native-wpilib==0.0.0"], summary = "WPILib XRP vendor library", + requires = ["robotpy-native-wpilib==0.0.0"], + python_requires = ">=3.11", + strip_path_prefixes = ["xrpVendordep"], entry_points = { "pkg_config": [ "xrp = native.xrp", diff --git a/xrpVendordep/robotpy_pybind_build_info.bzl b/xrpVendordep/robotpy_pybind_build_info.bzl index 5d4d3765a2..21eb801dc8 100644 --- a/xrpVendordep/robotpy_pybind_build_info.bzl +++ b/xrpVendordep/robotpy_pybind_build_info.bzl @@ -1,7 +1,7 @@ # 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:robotpy_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") @@ -190,6 +190,7 @@ def define_pybind_library(name, pkgcfgs = []): robotpy_library( name = name, + distribution = "robotpy-xrp", srcs = native.glob(["src/main/python/xrp/**/*.py"]) + [ "src/main/python/xrp/_init__xrp.py", "{}.generate_version".format(name), @@ -210,6 +211,7 @@ def define_pybind_library(name, pkgcfgs = []): project_urls = None, author_email = "RobotPy Development Team ", requires = ["robotpy-native-xrp==0.0.0", "wpilib==0.0.0"], + python_requires = ">=3.11", entry_points = { "pkg_config": ["xrp = xrp"], "robotpy_cli.2027": ["run-xrp = xrp.cli:RunXrp"], diff --git a/xrpVendordep/src/main/python/native-pyproject.toml b/xrpVendordep/src/main/python/native-pyproject.toml index 5c559dbac0..c3a1da05bf 100644 --- a/xrpVendordep/src/main/python/native-pyproject.toml +++ b/xrpVendordep/src/main/python/native-pyproject.toml @@ -11,6 +11,7 @@ requires = [ name = "robotpy-native-xrp" version = "0.0.0" description = "WPILib XRP vendor library" +requires-python = ">=3.11" license = "BSD-3-Clause" dependencies = [ diff --git a/xrpVendordep/src/main/python/pyproject.toml b/xrpVendordep/src/main/python/pyproject.toml index ec014b053d..70d99eddad 100644 --- a/xrpVendordep/src/main/python/pyproject.toml +++ b/xrpVendordep/src/main/python/pyproject.toml @@ -14,6 +14,7 @@ requires = [ name = "robotpy-xrp" version = "0.0.0" description = "Binary wrapper for WPILib XRP Vendor library" +requires-python = ">=3.11" authors = [ {name = "RobotPy Development Team", email = "robotpy@googlegroups.com"}, ]