[bazel] Build and publish ntcoreffi too (#8147)

This commit is contained in:
Austin Schuh
2025-08-02 21:59:50 -07:00
committed by GitHub
parent 1ab705b354
commit 0dd77e55cb
7 changed files with 238 additions and 0 deletions

59
ntcoreffi/BUILD.bazel Normal file
View File

@@ -0,0 +1,59 @@
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_python//python:defs.bzl", "py_binary")
load("//shared/bazel/rules:cc_rules.bzl", "wpilib_cc_library", "wpilib_cc_shared_library")
load("//shared/bazel/rules:packaging.bzl", "package_shared_cc_project")
py_binary(
name = "generate_exported_symbols",
srcs = [
"generate_exported_symbols.py",
],
)
genrule(
name = "do_generate_exported_symbols",
srcs = ["src/main/native/symbols.txt"],
outs = ["src/generated/headers/ExportedSymbols.h"],
cmd = "$(location :generate_exported_symbols) --output $(OUTS) --symbols $(SRCS)",
tools = [":generate_exported_symbols"],
)
cc_library(
name = "exported_symbols",
hdrs = [
"src/generated/headers/ExportedSymbols.h",
],
strip_include_prefix = "src/generated/headers/",
)
wpilib_cc_library(
name = "ntcoreffi",
srcs = glob([
"src/main/native/c/**",
"src/main/native/cpp/**",
]),
hdrs = glob(["src/main/native/include/**"]),
include_license_files = True,
strip_include_prefix = "src/main/native/include",
visibility = ["//visibility:public"],
deps = [
":exported_symbols",
"//ntcore",
"//wpinet",
"//wpiutil",
],
)
wpilib_cc_shared_library(
name = "shared/ntcoreffi",
symbols = "src/main/native/symbols.txt",
use_debug_name = False,
visibility = ["//visibility:public"],
deps = [":ntcoreffi"],
)
package_shared_cc_project(
name = "ntcoreffi",
maven_artifact_name = "ntcoreffi-cpp",
maven_group_id = "edu.wpi.first.ntcoreffi",
)

View File

@@ -0,0 +1,31 @@
#!/usr/bin/python
import argparse
from pathlib import Path
def generate_symbol_text(output_directory, symbols):
with open(output_directory, "w") as out:
with open(symbols, "r") as f:
for line in f:
out.write(f"AddFunctionToLink({line.strip()});\n")
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"--symbols",
help="Read the symbols from this file",
type=Path,
)
parser.add_argument(
"--output",
help="Output the generated symbols to this file",
type=Path,
)
args = parser.parse_args()
generate_symbol_text(args.output, args.symbols)
if __name__ == "__main__":
main()