Browse Source

add protobuf-c

ruki 6 years ago
parent
commit
b5e070c0fa
2 changed files with 52 additions and 3 deletions
  1. 47 0
      packages/p/protobuf-c/xmake.lua
  2. 5 3
      packages/p/protobuf-cpp/xmake.lua

+ 47 - 0
packages/p/protobuf-c/xmake.lua

@@ -0,0 +1,47 @@
+package("protobuf-c")
+
+    set_homepage("https://github.com/protobuf-c/protobuf-c")
+    set_description("Google's data interchange format for c")
+
+    add_urls("https://github.com/protobuf-c/protobuf-c/releases/download/v$(version)/protobuf-c-$(version).tar.gz")
+    add_versions("1.3.1", "51472d3a191d6d7b425e32b612e477c06f73fe23e07f6a6a839b11808e9d2267")
+
+    -- fix "error: no type named 'Reflection' in 'google::protobuf::Message'"
+    -- see https://github.com/protobuf-c/protobuf-c/pull/342
+    -- and https://github.com/protobuf-c/protobuf-c/issues/356
+    add_patches("1.3.1", "https://github.com/protobuf-c/protobuf-c/pull/342.patch", "050306bae86af55f90606613d3c362c3c93af779aa6be3e639c6a1df3c228c87")
+
+    add_deps("protobuf-cpp")
+    if is_plat("windows") then
+        add_deps("cmake")
+    end
+
+    add_links("protobuf-c")
+
+    on_load(function (package)
+        package:addenv("PATH", "bin")
+    end)
+
+    on_install("windows", function (package)
+        os.cd("build-cmake")
+        import("package.tools.cmake").install(package)
+    end)
+
+    on_install("linux", "macosx", function (package)
+        import("package.tools.autoconf").install(package, {"--enable-shared=no"})
+    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-c test.proto -I. --c_out=.")
+        assert(package:check_csnippets({test = io.readfile("test.pb-c.c")}, {configs = {includedirs = {".", package:installdir("include")}}}))
+    end)

+ 5 - 3
packages/p/protobuf-cpp/xmake.lua

@@ -6,13 +6,16 @@ package("protobuf-cpp")
     add_urls("https://github.com/protocolbuffers/protobuf/releases/download/v$(version)/protobuf-cpp-$(version).zip")
     add_urls("https://github.com/protocolbuffers/protobuf/releases/download/v$(version)/protobuf-cpp-$(version).zip")
     add_versions("3.8.0", "91ea92a8c37825bd502d96af9054064694899c5c7ecea21b8d11b1b5e7e993b5")
     add_versions("3.8.0", "91ea92a8c37825bd502d96af9054064694899c5c7ecea21b8d11b1b5e7e993b5")
 
 
-    add_deps("protoc")
     if is_plat("windows") then
     if is_plat("windows") then
         add_deps("cmake")
         add_deps("cmake")
     end
     end
 
 
     add_links("protobuf")
     add_links("protobuf")
 
 
+    on_load(function (package)
+        package:addenv("PATH", "bin")
+    end)
+
     on_install("windows", function (package)
     on_install("windows", function (package)
         os.cd("cmake")
         os.cd("cmake")
         import("package.tools.cmake").install(package)
         import("package.tools.cmake").install(package)
@@ -33,7 +36,6 @@ package("protobuf-cpp")
                 repeated TestCase case = 1;
                 repeated TestCase case = 1;
             }
             }
         ]])
         ]])
-        local protoc = path.join(package:dep("protoc"):installdir("bin"), "protoc" .. (is_host("windows") and ".exe" or ""))
-        os.vrunv(protoc, {"test.proto", "--cpp_out=."})
+        os.vrun("protoc test.proto --cpp_out=.")
         assert(package:check_cxxsnippets({test = io.readfile("test.pb.cc")}, {configs = {includedirs = {".", package:installdir("include")}, languages = "c++11"}}))
         assert(package:check_cxxsnippets({test = io.readfile("test.pb.cc")}, {configs = {includedirs = {".", package:installdir("include")}, languages = "c++11"}}))
     end)
     end)