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

当一个 object target 添加另一个 object target 作为依赖时无法继承 .o 文件 #4887

Closed
TOMO-CAT opened this issue Mar 27, 2024 · 13 comments

Comments

@TOMO-CAT
Copy link

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

image
按照文档描述 object target 是编译完的目标文件集合,当前项目中有多个 object target 而且存在依赖关系,例如:

target("zlog", function()
    set_kind("object")
    add_files("zlog/*.cc|*_test.cc")
    add_syslinks("PocoFoundation", "pthread", "dl")
end)

target("convert", function()
    set_kind("object")
    add_files("zutil/convert/*.cc|*_test.cc")
    add_syslinks("pthread")
    add_deps("zlog")
end)

target("coord_convert_test", function()
    set_kind("binary")
    set_default(false)
    add_files("zutil/convert/coord_convert_test.cc")
    add_syslinks("pthread")
    add_packages("gtest")
    add_deps("convert")
end)

在这种写法下 coord_convert_test 编译会丢失 zlog 的 .o 文件,虽然可以通过在 target coord_convert_test 中 add_deps("zlog", "convert") 解决,但是一旦项目中 object target 较多就会很麻烦。

描述可能的解决方案

希望一个 object target 可以继承它所有通过 add_deps() 引入的 object target 的 .o 文件。比如可以加一个 {public = true } 配置:

target("convert", function()
set_kind("object")
add_files("zutil/convert/.cc|_test.cc")
add_syslinks("pthread")
add_deps("zlog", {public = true}) -- 导出 zlog 的目标文件
end)

描述你认为的候选方案

No response

其他信息

No response

@Issues-translate-bot
Copy link

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


Title: Cannot inherit .o files when an object target adds another object target as a dependency

In what scenario do you need this feature?

image
According to the document description, object target is a collection of compiled target files. There are multiple object targets in the current project and there are dependencies, for example:

target("zlog", function()
    set_kind("object")
    add_files("zlog/*.cc|*_test.cc")
    add_syslinks("PocoFoundation", "pthread", "dl")
end)

target("convert", function()
    set_kind("object")
    add_files("zutil/convert/*.cc|*_test.cc")
    add_syslinks("pthread")
    add_deps("zlog")
end)

target("coord_convert_test", function()
    set_kind("binary")
    set_default(false)
    add_files("zutil/convert/coord_convert_test.cc")
    add_syslinks("pthread")
    add_packages("gtest")
    add_deps("convert")
end)

In this way of writing, coord_convert_test compilation will lose zlog's .o file. Although it can be solved by adding_deps("zlog", "convert") in target coord_convert_test, it will be very troublesome once there are many object targets in the project.

Describe possible solutions

It is expected that an object target can inherit the .o files of all the object targets it introduces through add_deps(). For example, you can add a {public = true} configuration:

target("convert", function()
set_kind("object")
add_files("zutil/convert/.cc|_test.cc")
add_syslinks("pthread")
add_deps("zlog", {public = true}) -- Export the zlog target file
end)

Describe your alternatives

No response

other information

No response

waruqi added a commit that referenced this issue Mar 29, 2024
@waruqi
Copy link
Member

waruqi commented Mar 29, 2024

再试试 xmake update -s dev

@waruqi waruqi added this to the v2.9.1 milestone Mar 29, 2024
@Issues-translate-bot
Copy link

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


Try xmake update -s dev again

@TOMO-CAT
Copy link
Author

再试试 xmake update -s dev

报错了,不知道是不是和我环境没清理干净相关:

Already up to date.
ok
/usr/bin/git rev-parse HEAD
/usr/bin/git rev-parse HEAD
checking for cmake ... no
checking for cmake ... /usr/bin/cmake
error: @programdir/core/main.lua:329: @programdir/core/sandbox/modules/import/core/base/task.lua:65: @programdir/modules/async/runjobs.lua:338: ....xmake/repositories/xmake-repo/packages/z/zlib/xmake.lua:26: attempt to index a nil value
stack traceback:
    [....xmake/repositories/xmake-repo/packages/z/zlib/xmake.lua:26]: in function 'on_fetch'
    [@programdir/core/package/package.lua:1733]: in function '_fetch_library'
    [@programdir/core/package/package.lua:1943]: in function 'fetch'
    [...modules/private/action/require/impl/install_packages.lua:333]: in function 'jobfunc'
    [@programdir/modules/async/runjobs.lua:256]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:961: in function 'os.raiselevel'
        (...tail calls...)
        @programdir/core/main.lua:329: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>

image

@TOMO-CAT
Copy link
Author

我用的是 gitee 的源:
image

@Issues-translate-bot
Copy link

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


I am using the gitee source:
image

@waruqi
Copy link
Member

waruqi commented Mar 29, 2024

执行 xmake l xmake.version 看下,不行就全量重装下

@Issues-translate-bot
Copy link

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


Execute xmake l xmake.version and check. If it doesn’t work, reinstall it completely.

@TOMO-CAT
Copy link
Author

执行 xmake l xmake.version 看下,不行就全量重装下

继承 .o 的可以了,还有个问题请教下,object target 里的 add_syslinks 不能被导出到 binary 里去。

target("zutil.thunder", function()
    set_kind("object")
    add_files("*.cc")
    remove_files("*_test.cc")
    add_syslinks("curl")  -- 未导出
    add_deps("zlog")
end)

target("zutil.thunder.http_url_test", function()
    set_kind("binary")
    add_files("http_url_test.cc")
    add_deps("zutil.thunder")
    add_packages("gtest")
end)

编译时报错:

image

虽然加一个 {public = true} 可以解决,但是我理解这种链接时参数应该是无条件导出的,毕竟生成 .o 时也用不上,还是有啥其他考虑呢?

@waruqi
Copy link
Member

waruqi commented Mar 29, 2024

再试试,xmake update -s dev

@Issues-translate-bot
Copy link

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


Try again, xmake update -s dev

@TOMO-CAT
Copy link
Author

再试试,xmake update -s dev

可以了,能正常导出 syslinks

@Issues-translate-bot
Copy link

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


Try again, xmake update -s dev

OK, syslinks can be exported normally

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

3 participants