mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
[bazel] Build and publish ntcoreffi too (#8147)
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
load("@rules_python//python:defs.bzl", "py_binary")
|
||||
|
||||
exports_files(["defs.bzl"])
|
||||
|
||||
py_binary(
|
||||
name = "gen_versionscript",
|
||||
srcs = ["gen_versionscript.py"],
|
||||
main = "gen_versionscript.py",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
py_binary(
|
||||
name = "gen_resources",
|
||||
srcs = ["gen_resources.py"],
|
||||
|
||||
56
shared/bazel/rules/gen/defs.bzl
Normal file
56
shared/bazel/rules/gen/defs.bzl
Normal file
@@ -0,0 +1,56 @@
|
||||
"""Starlark rule for generating a version script from a symbols file."""
|
||||
|
||||
def _gen_versionscript_impl(ctx):
|
||||
ext = ".txt"
|
||||
if ctx.attr.format == "windows":
|
||||
ext = ".def"
|
||||
elif ctx.attr.format == "osx":
|
||||
ext = ".list"
|
||||
|
||||
output_file = ctx.actions.declare_file(ctx.label.name + ext)
|
||||
|
||||
ctx.actions.run(
|
||||
outputs = [output_file],
|
||||
inputs = [ctx.file.src],
|
||||
executable = ctx.executable._tool,
|
||||
arguments = [
|
||||
"--input",
|
||||
ctx.file.src.path,
|
||||
"--output",
|
||||
output_file.path,
|
||||
"--lib_name",
|
||||
ctx.attr.lib_name,
|
||||
"--format",
|
||||
ctx.attr.format,
|
||||
],
|
||||
mnemonic = "GenVersionScript",
|
||||
progress_message = "Generating version script for %{label}",
|
||||
)
|
||||
|
||||
return [DefaultInfo(files = depset([output_file]), runfiles = ctx.runfiles(files = [output_file])), OutputGroupInfo(version_script_file = depset([output_file]))]
|
||||
|
||||
gen_versionscript = rule(
|
||||
implementation = _gen_versionscript_impl,
|
||||
attrs = {
|
||||
"format": attr.string(
|
||||
mandatory = True,
|
||||
values = ["linux", "windows", "osx"],
|
||||
doc = "The output format.",
|
||||
),
|
||||
"lib_name": attr.string(
|
||||
mandatory = True,
|
||||
doc = "The name of the library.",
|
||||
),
|
||||
"src": attr.label(
|
||||
mandatory = True,
|
||||
allow_single_file = True,
|
||||
doc = "The input symbols file.",
|
||||
),
|
||||
"_tool": attr.label(
|
||||
default = Label("//shared/bazel/rules/gen:gen_versionscript"),
|
||||
executable = True,
|
||||
cfg = "exec",
|
||||
),
|
||||
},
|
||||
doc = "Generates a version script from a symbols file.",
|
||||
)
|
||||
49
shared/bazel/rules/gen/gen_versionscript.py
Normal file
49
shared/bazel/rules/gen/gen_versionscript.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import argparse
|
||||
|
||||
# Quick script to generate a version script for each OS from a list of symbols.
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Generate a version script.")
|
||||
parser.add_argument("--input", required=True, help="Input symbols file")
|
||||
parser.add_argument("--output", required=True, help="Output version script file")
|
||||
parser.add_argument(
|
||||
"--lib_name", required=True, help="Name of the library for the version script"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--format",
|
||||
required=True,
|
||||
choices=["linux", "windows", "osx"],
|
||||
help="Output format",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
with open(args.input, "r") as f:
|
||||
symbols = f.read().splitlines()
|
||||
|
||||
with open(args.output, "w") as f:
|
||||
if args.format == "linux":
|
||||
f.write(f"{args.lib_name} {{\n")
|
||||
f.write(" global: ")
|
||||
for symbol in symbols:
|
||||
symbol = symbol.strip()
|
||||
if symbol:
|
||||
f.write(f"{symbol}; ")
|
||||
f.write("\n local: *;\n")
|
||||
f.write("};\n")
|
||||
elif args.format == "windows":
|
||||
f.write(f"LIBRARY {args.lib_name}\n")
|
||||
f.write("EXPORTS\n")
|
||||
for symbol in symbols:
|
||||
symbol = symbol.strip()
|
||||
if symbol:
|
||||
f.write(f" {symbol}\n")
|
||||
elif args.format == "osx":
|
||||
for symbol in symbols:
|
||||
symbol = symbol.strip()
|
||||
if symbol:
|
||||
f.write(f"_{symbol}\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user