[wpiutil,glass,dlt] Replace libprotobuf with upb for dynamic decode (#7988)

libprotobuf is a very annoying dependency to deal with, and with the switch to nanopb for generated C++ code, libprotobuf is only used for dynamic decode in the GUI apps. libprotobuf has been swapped out with upb, a much smaller C-based library that supports reflection and can therefore do dynamic decode. This means we can remove the libprotobuf dependency and stop dealing with build issues because of it.
This commit is contained in:
Gold856
2025-08-17 01:56:32 -04:00
committed by GitHub
parent 7f35104012
commit d4311d5a29
408 changed files with 31336 additions and 141509 deletions

115
upstream_utils/upb.py Executable file
View File

@@ -0,0 +1,115 @@
#!/usr/bin/env python3
import os
import shutil
from pathlib import Path
from upstream_utils import (
Lib,
comment_out_invalid_includes,
copy_to,
walk_cwd_and_copy_if,
)
def copy_upstream_src(wpilib_root: Path):
upstream_root = Path(".").absolute()
wpiutil = wpilib_root / "wpiutil"
# Delete old install
for d in [
"src/main/native/thirdparty/upb/include",
"src/main/native/thirdparty/upb/src",
]:
shutil.rmtree(wpiutil / d, ignore_errors=True)
os.chdir(upstream_root / "third_party/utf8_range")
copy_to(
[Path("utf8_range.h")],
wpiutil / "src/main/native/thirdparty/upb/include",
)
copy_to(
[
Path("utf8_range.c"),
Path("utf8_range_sse.inc"),
Path("utf8_range_neon.inc"),
],
wpiutil / "src/main/native/thirdparty/upb/src",
)
# Change directory to upb to minimize the number of files to walk
os.chdir(upstream_root / "upb")
include_files = walk_cwd_and_copy_if(
lambda dp, f: (
len(dp.parts) >= 1
and (
dp.parts[0] == "base"
or dp.parts[0] == "hash"
or dp.parts[0] == "mem"
or (
dp.parts[0] == "message"
and "compare" not in f
and "promote" not in f
and "accessors_split64" not in f
)
or dp.parts[0] == "mini_descriptor"
or (dp.parts[0] == "mini_table" and "compat" not in f)
or dp.parts[0] == "port"
or dp.parts[0] == "reflection"
or (
dp.parts[0] == "wire"
and "byte_size" not in f
and "decode_fast" not in dp.parts
and "test_util" not in dp.parts
)
)
and "cmake" not in dp.parts
)
and (f.endswith(".h") or f.endswith(".inc"))
or f == "generated_code_support.h",
wpiutil / "src/main/native/thirdparty/upb/include/upb",
)
for f in include_files:
comment_out_invalid_includes(
f, [wpiutil / "src/main/native/thirdparty/upb/include"]
)
walk_cwd_and_copy_if(
lambda dp, f: (
len(dp.parts) >= 1
and (
dp.parts[0] == "base"
or dp.parts[0] == "hash"
or dp.parts[0] == "mem"
or (
dp.parts[0] == "message"
and "compare" not in f
and "promote" not in f
)
or dp.parts[0] == "mini_descriptor"
or (dp.parts[0] == "mini_table" and "compat" not in f)
or dp.parts[0] == "port"
or dp.parts[0] == "reflection"
or (
dp.parts[0] == "wire"
and "byte_size" not in f
and "decode_fast" not in dp.parts
)
)
)
and f.endswith(".c")
and not f == "descriptor.upb_minitable.c",
wpiutil / "src/main/native/thirdparty/upb/src",
)
def main():
name = "upb"
url = "https://github.com/protocolbuffers/protobuf"
tag = "v32.0"
upb = Lib(name, url, tag, copy_upstream_src)
upb.main()
if __name__ == "__main__":
main()