protobuf-cpp: support more platform (#5848)

* protobuf-cpp: support more platform

* abseil: fix syslinks

* fix android

* support lite version

* fix msys2-mingw-i386

* use zmqpb for test

* Revert "use zmqpb for test"

This reverts commit a8fb4aa604.

* readonly for lite config
pull/5795/head
star9029 2 weeks ago committed by GitHub
parent 85a27ae922
commit 220a03bceb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 15
      packages/a/abseil/xmake.lua
  2. 142
      packages/p/protobuf-cpp/xmake.lua

@ -3,7 +3,7 @@ package("abseil")
set_description("C++ Common Libraries") set_description("C++ Common Libraries")
set_license("Apache-2.0") set_license("Apache-2.0")
add_urls("https://github.com/abseil/abseil-cpp/archive/$(version).tar.gz", add_urls("https://github.com/abseil/abseil-cpp/archive/refs/tags/$(version).tar.gz",
"https://github.com/abseil/abseil-cpp.git") "https://github.com/abseil/abseil-cpp.git")
add_versions("20200225.1", "0db0d26f43ba6806a8a3338da3e646bb581f0ca5359b3a201d8fb8e4752fd5f8") add_versions("20200225.1", "0db0d26f43ba6806a8a3338da3e646bb581f0ca5359b3a201d8fb8e4752fd5f8")
@ -24,7 +24,9 @@ package("abseil")
add_configs("cxx_standard", {description = "Select c++ standard to build.", default = "17", type = "string", values = {"14", "17", "20"}}) add_configs("cxx_standard", {description = "Select c++ standard to build.", default = "17", type = "string", values = {"14", "17", "20"}})
if is_plat("linux") then if is_plat("windows", "mingw") then
add_syslinks("advapi32", "dbghelp", "bcrypt")
elseif is_plat("linux", "bsd") then
add_syslinks("pthread") add_syslinks("pthread")
elseif is_plat("macosx") then elseif is_plat("macosx") then
add_frameworks("CoreFoundation") add_frameworks("CoreFoundation")
@ -43,8 +45,13 @@ package("abseil")
end end
io.replace("CMakeLists.txt", [[set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")]], "", {plain = true}) io.replace("CMakeLists.txt", [[set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")]], "", {plain = true})
io.replace("CMakeLists.txt", [[set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")]], "", {plain = true}) io.replace("CMakeLists.txt", [[set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")]], "", {plain = true})
local configs = {"-DCMAKE_CXX_STANDARD=" .. package:config("cxx_standard"), "-DABSL_ENABLE_INSTALL=ON", "-DABSL_PROPAGATE_CXX_STD=ON"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release")) local configs = {
"-DCMAKE_CXX_STANDARD=" .. package:config("cxx_standard"),
"-DABSL_ENABLE_INSTALL=ON",
"-DABSL_PROPAGATE_CXX_STD=ON",
}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
import("package.tools.cmake").install(package, configs, {buildir = os.tmpfile() .. ".dir"}) import("package.tools.cmake").install(package, configs, {buildir = os.tmpfile() .. ".dir"})

@ -1,7 +1,7 @@
package("protobuf-cpp") package("protobuf-cpp")
set_homepage("https://developers.google.com/protocol-buffers/") set_homepage("https://developers.google.com/protocol-buffers/")
set_description("Google's data interchange format for cpp") set_description("Google's data interchange format for cpp")
set_license("BSD-3-Clause")
add_urls("https://github.com/protocolbuffers/protobuf/releases/download/v$(version)", {version = function (version) add_urls("https://github.com/protocolbuffers/protobuf/releases/download/v$(version)", {version = function (version)
if version:le("3.19.4") then if version:le("3.19.4") then
@ -11,6 +11,7 @@ package("protobuf-cpp")
end end
end}) end})
-- TODO: Use x.y.z version? https://protobuf.dev/support/version-support
add_versions("28.1", "0ac35978514f3e868181ea60237e695d892d4748ac03fb926a26ac7e2698aa29") add_versions("28.1", "0ac35978514f3e868181ea60237e695d892d4748ac03fb926a26ac7e2698aa29")
add_versions("28.0", "979027233837dceaf927402e789261e46d4ff87ce45b3e38be8b15c4a1f696a3") add_versions("28.0", "979027233837dceaf927402e789261e46d4ff87ce45b3e38be8b15c4a1f696a3")
add_versions("27.3", "a49147217f69e8d19aab0cc5c0059d6201261f5cb62145f8ab4ac8b94e7ffa86") add_versions("27.3", "a49147217f69e8d19aab0cc5c0059d6201261f5cb62145f8ab4ac8b94e7ffa86")
@ -30,18 +31,25 @@ package("protobuf-cpp")
add_patches("3.17.3", path.join(os.scriptdir(), "patches", "3.17.3", "field_access_listener.patch"), "ac9bdf49611b01e563fe74b2aaf1398214129454c3e18f1198245549eb281e85") add_patches("3.17.3", path.join(os.scriptdir(), "patches", "3.17.3", "field_access_listener.patch"), "ac9bdf49611b01e563fe74b2aaf1398214129454c3e18f1198245549eb281e85")
add_patches("3.19.4", path.join(os.scriptdir(), "patches", "3.19.4", "vs_runtime.patch"), "8e73e585d29f3b9dca3c279df0b11b3ee7651728c07f51381a69e5899b93c367") add_patches("3.19.4", path.join(os.scriptdir(), "patches", "3.19.4", "vs_runtime.patch"), "8e73e585d29f3b9dca3c279df0b11b3ee7651728c07f51381a69e5899b93c367")
add_configs("rtti", {description = "Enable runtime type information", default = true, type = "boolean"})
add_configs("zlib", {description = "Enable zlib", default = false, type = "boolean"}) add_configs("zlib", {description = "Enable zlib", default = false, type = "boolean"})
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") 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 if is_plat("windows") then
add_links("libprotobuf", "libprotoc", "utf8_range", "utf8_validity") add_links("libprotoc", "libprotobuf", "utf8_range", "utf8_validity")
else else
add_links("protobuf", "protoc", "utf8_range", "utf8_validity") add_links("protoc", "protobuf", "utf8_range", "utf8_validity")
end end
if is_plat("linux") then if is_plat("linux", "bsd") then
add_syslinks("pthread") add_syslinks("m", "pthread")
end end
on_load(function (package) on_load(function (package)
@ -52,54 +60,116 @@ package("protobuf-cpp")
if package:version():ge("22.0") then if package:version():ge("22.0") then
package:add("deps", "abseil") package:add("deps", "abseil")
end end
if package:is_plat("windows") and package:config("shared") then
package:add("defines", "PROTOBUF_USE_DLLS")
end
end)
-- ref: https://github.com/conan-io/conan-center-index/blob/19c9de61cce5a5089ce42b0cf15a88ade7763275/recipes/protobuf/all/conanfile.py
on_component("utf8_range", function (package, component)
component:add("extsources", "pkgconfig::utf8_range")
component:add("links", "utf8_validity", "utf8_range")
end)
on_component("protobuf", function (package, component)
component:add("extsources", "pkgconfig::protobuf")
if is_plat("windows") then
component:add("links", "libprotobuf", "utf8_validity")
else
component:add("links", "protobuf", "utf8_validity")
end
end)
on_component("protobuf-lite", function (package, component)
component:add("extsources", "pkgconfig::protobuf-lite")
if is_plat("windows") then
component:add("links", "libprotobuf-lite", "utf8_validity")
else
component:add("links", "protobuf-lite", "utf8_validity")
end
end)
on_component("protoc", function (package, component)
component:add("deps", "protobuf")
if is_plat("windows") then
component:add("links", "libprotoc")
else
component:add("links", "protoc")
end
end)
on_component("upb", function (package, component)
if is_plat("windows") then
component:add("links", "libupb", "utf8_range")
else
component:add("links", "upb", "utf8_range")
end
end) end)
on_install("windows", "linux", "macosx", function (package) on_install(function (package)
if package:version():le("3.19.4") then local version = package:version()
if version:le("3.19.4") then
os.cd("cmake") os.cd("cmake")
end end
io.replace("CMakeLists.txt", "set(protobuf_DEBUG_POSTFIX \"d\"", "set(protobuf_DEBUG_POSTFIX \"\"", {plain = true}) io.replace("CMakeLists.txt", "set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>)", "", {plain = true})
if package:version():ge("26.1") then io.replace("CMakeLists.txt", "set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>DLL)", "", {plain = true})
io.replace("CMakeLists.txt", "set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)", "", {plain = true})
if version:ge("26.1") then
io.replace("cmake/abseil-cpp.cmake", "BUILD_SHARED_LIBS AND MSVC", "FALSE", {plain = true}) io.replace("cmake/abseil-cpp.cmake", "BUILD_SHARED_LIBS AND MSVC", "FALSE", {plain = true})
end end
local configs = {"-Dprotobuf_BUILD_TESTS=OFF", "-Dprotobuf_BUILD_PROTOC_BINARIES=ON"} local configs = {
"-Dprotobuf_BUILD_TESTS=OFF",
"-Dprotobuf_LOCAL_DEPENDENCIES_ONLY=ON",
"-Dprotobuf_BUILD_PROTOC_BINARIES=ON",
"-Dprotobuf_DEBUG_POSTFIX=''",
}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release")) table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-Dprotobuf_DISABLE_RTTI=" .. (package:config("rtti") and "OFF" or "ON"))
local packagedeps = {}
if package:version():ge("22.0") then
table.insert(packagedeps, "abseil")
table.insert(configs, "-Dprotobuf_ABSL_PROVIDER=package")
end
if package:is_plat("windows") then if package:is_plat("windows") then
table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''") table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''")
table.insert(configs, "-Dprotobuf_MSVC_STATIC_RUNTIME=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF")) table.insert(configs, "-Dprotobuf_MSVC_STATIC_RUNTIME=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
if package:config("shared") then
package:add("defines", "PROTOBUF_USE_DLLS")
end
end end
if package:config("zlib") then
table.insert(configs, "-Dprotobuf_WITH_ZLIB=ON") table.insert(configs, "-Dprotobuf_WITH_ZLIB=" .. (package:config("zlib") and "ON" or "OFF"))
table.insert(configs, "-Dprotobuf_BUILD_LIBUPB=" .. (package:config("upb") and "ON" or "OFF"))
local opt = {}
opt.buildir = "build"
if version:ge("22.0") then
opt.packagedeps = "abseil"
table.insert(configs, "-Dprotobuf_ABSL_PROVIDER=package")
end end
import("package.tools.cmake").install(package, configs, {buildir = "build", packagedeps = packagedeps}) import("package.tools.cmake").install(package, configs, opt)
os.trycp("build/Release/protoc.exe", package:installdir("bin")) os.trycp("build/Release/protoc.exe", package:installdir("bin"))
end) end)
on_test(function (package) on_test(function (package)
if package:is_cross() then if not package:is_cross() and
return -- Missing libgcc_s_xxx.dll, Maybe msys2 bug
not (is_subhost("msys") and package:is_plat("mingw", "msys") and package:is_arch("i386")) then
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=.")
end
if package:is_library() then
assert(package:check_cxxsnippets({test = [[
#include <google/protobuf/timestamp.pb.h>
#include <google/protobuf/util/time_util.h>
void test() {
google::protobuf::Timestamp ts;
google::protobuf::util::TimeUtil::FromString("1972-01-01T10:00:20.021Z", &ts);
}
]]}, {configs = {languages = "c++17"}}))
end end
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=.")
end) end)

Loading…
Cancel
Save