Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_rules("protobuf.cpp") 应该以 host 方式编译 并使用 protoc #5399

Open
19317362 opened this issue Jul 26, 2024 · 5 comments
Open

Comments

@19317362
Copy link
Contributor

你在什么场景下需要该功能?

目前的版本,交叉编译时,protoc 也交叉编译了,造成交叉编译时不会基于 proto文件生成 .pb.cc 和 .pb.h

描述可能的解决方案

add_rules("protobuf.cpp") 应该以 host 方式编译 并使用 protoc

描述你认为的候选方案

No response

其他信息

No response

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: add_rules("protobuf.cpp") should be compiled in host mode and use protoc

In what scenario do you need this feature?

In the current version, when cross-compiling, protoc is also cross-compiled, causing .pb.cc and .pb.h to not be generated based on the proto file during cross-compilation.

Describe possible solutions

add_rules("protobuf.cpp") should be compiled in host mode and use protoc

Describe your alternatives

No response

other information

No response

@waruqi
Copy link
Member

waruqi commented Jul 26, 2024

目前这个包原本就还不支持交叉编译。你可以提 pr 过来改进这个包。

https://github.com/xmake-io/xmake-repo/blob/3a7bd844fd0f9d9702b9bbd11710d1fa685c99e8/packages/p/protobuf-cpp/xmake.lua#L54

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Currently, this package does not originally support cross-compilation. You can submit a PR to improve this package.

https://github.com/xmake-io/xmake-repo/blob/3a7bd844fd0f9d9702b9bbd11710d1fa685c99e8/packages/p/protobuf-cpp/xmake.lua#L54

@star-hengxing
Copy link
Contributor

我改进了一下 protoc 包,原来是直接下载预编译二进制,现在是 binary package,永远只会构建 host tool。
因为 protobuf-cpp 没有单独构建 protoc 的选项,所以 protoc 的实现很简单,直接用 protobuf-cpp 作为依赖。

package("protoc")
    set_kind("binary")
    add_deps("protobuf-cpp")

    on_install(function (package) end)

    on_test(function (package)
        os.vrun("protoc --version")
    end)

protoc 的版本需要用 add_requireconfs 指定。

add_requires("protoc", "protobuf-cpp")
add_requireconfs("protoc.protobuf-cpp", {version = "1.0.0"})

add_packages("protoc", "protobuf-cpp")

如果不用 protoc 包,交叉编译就这样:

add_requires("protobuf-cpp~host", {host = true, alias = "protoc"})
add_requires("protobuf-cpp")

add_packages("protoc", {links = {}})
add_packages("protobuf-cpp")

@waruqi
Copy link
Member

waruqi commented Dec 11, 2024

我改进了一下 protoc 包,原来是直接下载预编译二进制,现在是 binary package,永远只会构建 host tool。 因为 protobuf-cpp 没有单独构建 protoc 的选项,所以 protoc 的实现很简单,直接用 protobuf-cpp 作为依赖。

package("protoc")
    set_kind("binary")
    add_deps("protobuf-cpp")

    on_install(function (package) end)

    on_test(function (package)
        os.vrun("protoc --version")
    end)

protoc 的版本需要用 add_requireconfs 指定。

add_requires("protoc", "protobuf-cpp")
add_requireconfs("protoc.protobuf-cpp", {version = "1.0.0"})

add_packages("protoc", "protobuf-cpp")

如果不用 protoc 包,交叉编译就这样:

add_requires("protobuf-cpp~host", {host = true, alias = "protoc"})
add_requires("protobuf-cpp")

add_packages("protoc", {links = {}})
add_packages("protobuf-cpp")

如果用法变了,最好同步下 tests example 和相关文档

https://github.com/xmake-io/xmake/blob/dev/tests/projects/c%2B%2B/protobuf/xmake.lua

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants