From e9749a53c8cefb469b44b91faabbcb1de5ffa10c Mon Sep 17 00:00:00 2001 From: star9029 Date: Tue, 10 Dec 2024 23:17:13 +0800 Subject: [PATCH] protoc: Use protobuf-cpp as deps (#5881) * protoc: use base protobuf-cpp * protoc: improve test * use add_deps * abseil: fix syslinks * protoc: use host protobuf * fix plat * fix host build * abseil: fix host build * abseil: fix msys syslinks --- packages/a/abseil/xmake.lua | 16 +++---- .../patches/0.4.9/nanopb_generator.patch | 15 +++++++ packages/n/nanopb/xmake.lua | 4 +- packages/p/protobuf-cpp/xmake.lua | 44 +++++++++++++------ packages/p/protoc/xmake.lua | 43 ++---------------- 5 files changed, 59 insertions(+), 63 deletions(-) create mode 100644 packages/n/nanopb/patches/0.4.9/nanopb_generator.patch diff --git a/packages/a/abseil/xmake.lua b/packages/a/abseil/xmake.lua index 3c32f0f09..bb133a9b5 100644 --- a/packages/a/abseil/xmake.lua +++ b/packages/a/abseil/xmake.lua @@ -24,15 +24,15 @@ package("abseil") add_configs("cxx_standard", {description = "Select c++ standard to build.", default = "17", type = "string", values = {"14", "17", "20"}}) - if is_plat("windows", "mingw") then - add_syslinks("advapi32", "dbghelp", "bcrypt") - elseif is_plat("linux", "bsd") then - add_syslinks("pthread") - elseif is_plat("macosx") then - add_frameworks("CoreFoundation") - end - on_load(function (package) + if package:is_plat("windows", "mingw", "msys") then + package:add("syslinks", "advapi32", "dbghelp", "bcrypt") + elseif package:is_plat("linux", "bsd") then + package:add("syslinks", "pthread") + elseif package:is_plat("macosx", "iphoneos") then + package:add("frameworks", "CoreFoundation") + end + if package:is_plat("windows") and package:config("shared") then package:add("defines", "ABSL_CONSUME_DLL") end diff --git a/packages/n/nanopb/patches/0.4.9/nanopb_generator.patch b/packages/n/nanopb/patches/0.4.9/nanopb_generator.patch new file mode 100644 index 000000000..489d356e3 --- /dev/null +++ b/packages/n/nanopb/patches/0.4.9/nanopb_generator.patch @@ -0,0 +1,15 @@ +diff --git a/extra/script_wrappers/nanopb_generator.py.in b/extra/script_wrappers/nanopb_generator.py.in +index 36540f74..4afedaf9 100644 +--- a/extra/script_wrappers/nanopb_generator.py.in ++++ b/extra/script_wrappers/nanopb_generator.py.in +@@ -21,4 +21,7 @@ if python_instdir[0] != '@': + + from nanopb.generator.nanopb_generator import main_cli, main_plugin + if __name__ == '__main__': +- sys.exit(main_cli()) +\ No newline at end of file ++ if 'protoc-gen-' in sys.argv[0] or '--protoc-plugin' in sys.argv: ++ main_plugin() ++ else: ++ main_cli() +\ No newline at end of file diff --git a/packages/n/nanopb/xmake.lua b/packages/n/nanopb/xmake.lua index faaaad021..cbc6a742e 100644 --- a/packages/n/nanopb/xmake.lua +++ b/packages/n/nanopb/xmake.lua @@ -10,13 +10,13 @@ package("nanopb") add_configs("generator", {description = "Build the protoc plugin for code generation", default = false, type = "boolean"}) - add_deps("cmake") - add_deps("protobuf-cpp") + add_deps("cmake", "protoc") on_load(function (package) if package:config("generator") then package:add("deps", "python 3.x", {kind = "binary"}) package:addenv("PYTHONPATH", "lib/site-packages") + package:add("patches", ">=0.4.9", "patches/0.4.9/nanopb_generator.patch", "40031727bac5719c2e98bdd2c2b7b05d58e649b8706087fea1b17413f171df72") end end) diff --git a/packages/p/protobuf-cpp/xmake.lua b/packages/p/protobuf-cpp/xmake.lua index b9342672b..3763faeb9 100644 --- a/packages/p/protobuf-cpp/xmake.lua +++ b/packages/p/protobuf-cpp/xmake.lua @@ -3,6 +3,7 @@ package("protobuf-cpp") set_description("Google's data interchange format for cpp") set_license("BSD-3-Clause") + add_urls("https://github.com/protocolbuffers/protobuf.git") add_urls("https://github.com/protocolbuffers/protobuf/releases/download/v$(version)", {version = function (version) if version:le("3.19.4") then return version .. "/protobuf-cpp-" .. version .. ".zip" @@ -36,23 +37,40 @@ package("protobuf-cpp") add_configs("lite", {description = "Build lite version", default = true, type = "boolean", readonly = true}) add_configs("upb", {description = "Build upb", default = false, type = "boolean"}) - add_deps("cmake") - if is_plat("android") and is_host("windows") then - add_deps("ninja") - set_policy("package.cmake_generator.ninja", true) - end - - if is_plat("windows") then - add_links("libprotoc", "libprotobuf", "utf8_range", "utf8_validity") - else - add_links("protoc", "protobuf", "utf8_range", "utf8_validity") + if is_plat("mingw") and is_subhost("msys") then + add_extsources("pacman::protobuf") + elseif is_plat("linux") then + add_extsources("pacman::protobuf") + elseif is_plat("macosx") then + add_extsources("brew::protobuf") end - if is_plat("linux", "bsd", "mingw") then - add_syslinks("m", "pthread") - end + add_deps("cmake") on_load(function (package) + if package:is_plat("android") and is_host("windows") then + package:add("deps", "ninja") + package:set("policy", "package.cmake_generator.ninja", true) + end + + if package:is_plat("windows") then + package:add("links", "libprotoc", "libprotobuf", "utf8_range", "utf8_validity") + else + package:add("links", "protoc", "protobuf", "utf8_range", "utf8_validity") + end + + if package:is_plat("linux", "bsd", "mingw") then + package:add("syslinks", "m", "pthread") + end + + if package:is_plat("linux") then + if package:is_binary() then + package:add("extsources", "apt::protobuf-compiler") + elseif package:is_library() then + package:add("extsources", "apt::libprotobuf-dev", "apt::libprotoc-dev") + end + end + if not package:is_cross() then package:addenv("PATH", "bin") end diff --git a/packages/p/protoc/xmake.lua b/packages/p/protoc/xmake.lua index 601b4828d..374050332 100644 --- a/packages/p/protoc/xmake.lua +++ b/packages/p/protoc/xmake.lua @@ -1,49 +1,12 @@ package("protoc") - set_kind("binary") set_homepage("https://developers.google.com/protocol-buffers/") set_description("Google's data interchange format compiler") - if is_host("windows") then - if is_arch("x64") then - add_urls("https://github.com/protocolbuffers/protobuf/releases/download/v$(version)/protoc-$(version)-win64.zip") - add_versions("3.8.0", "ac07cd66824f93026a796482dc85fa89deaf5be1b0e459de9100cff2992e6905") - else - add_urls("https://github.com/protocolbuffers/protobuf/releases/download/v$(version)/protoc-$(version)-win32.zip") - add_versions("3.8.0", "93c5b7efe418b539896b2952ab005dd81fa418b76abee8c4341b4796b391999e") - end - elseif is_host("macosx") then - if is_arch("x86_64") then - add_urls("https://github.com/protocolbuffers/protobuf/releases/download/v$(version)/protoc-$(version)-osx-x86_64.zip") - add_versions("3.8.0", "8093a79ca6f22bd9b178cc457a3cf44945c088f162e237b075584f6851ca316c") - else - add_urls("https://github.com/protocolbuffers/protobuf/releases/download/v$(version)/protoc-$(version)-osx-x86_32.zip") - add_versions("3.8.0", "14376f58d19a7579c43ee95d9f87ed383391d695d4968107f02ed226c13448ae") - end - else - add_urls("https://github.com/protocolbuffers/protobuf/releases/download/v$(version)/protobuf-cpp-$(version).zip") - add_versions("3.8.0", "91ea92a8c37825bd502d96af9054064694899c5c7ecea21b8d11b1b5e7e993b5") - end - - on_install("@windows", "@msys", "@cygwin", "@macosx", function (package) - os.cp("bin", package:installdir()) - os.cp("include", package:installdir()) - end) + add_deps("protobuf-cpp") - on_install("@linux", function (package) - import("package.tools.autoconf").install(package, {"--enable-shared=no", "--enable-static=no"}) - end) + on_install(function (package) end) on_test(function (package) - io.writefile("test.proto", [[ - syntax = "proto3"; - package test; - message TestCase { - string name = 4; - } - message Test { - repeated TestCase case = 1; - } - ]]) - os.vrun("protoc test.proto --cpp_out=.") + os.vrun("protoc --version") end)