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

使用mingw toolchain无法检测 HAVE_INTPTR_T #4173

Closed
da-liii opened this issue Sep 6, 2023 · 11 comments
Closed

使用mingw toolchain无法检测 HAVE_INTPTR_T #4173

da-liii opened this issue Sep 6, 2023 · 11 comments
Labels

Comments

@da-liii
Copy link
Member

da-liii commented Sep 6, 2023

Xmake 版本

dev and 2.8.2

操作系统版本和架构

Windows 11

描述问题

xmake config -p mingw

无法检测

configvar_check_cxxtypes("HAVE_INTPTR_T", "intptr_t", {includes = {"memory"}})

在手动将mingw相关路径加入之后,可以检测到 HAVE_INTPTR_T,比如 https://github.com/XmacsLabs/lolly/blob/main/bin/config_mingw

期待的结果

HAVE_INTPTR_T能够被检测到

工程配置

附加信息和错误日志

xmake config的关键信息

checking for HAVE_INTTYPES_H ... no
checking for HAVE_INTPTR_T ... no

出错信息(和lolly仓库有关)

error: C:/Users/darcy/AppData/Local/.xmake/packages/m/mingw-w64/8.1.0/56aa6e64d5e4436e887c6df8f2e26e92/x86_64-w64-mingw32/include/crtdefs.h:62:35: error: conflicting declaration 'typedef long long int intptr_t'
 __MINGW_EXTENSION typedef __int64 intptr_t;
                                   ^~~~~~~~
In file included from <command-line>:
./build/L1/config.h:16:14: note: previous declaration as 'typedef long int intptr_t'
 typedef long intptr_t;
              ^~~~~~~~
  > in tests\Kernel\Types\tree_test.cpp
@da-liii da-liii added the bug label Sep 6, 2023
@waruqi
Copy link
Member

waruqi commented Sep 7, 2023

出错信息(和lolly仓库有关)

这只是你的编译错误,要看 xmake f -vD; xmake -vD 的 check error info 。。贴下

@Issues-translate-bot
Copy link

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


Error message (related to the lolly warehouse)

This is just your compilation error, it depends on the check error info of xmake f -vD; xmake -vD. . posted

@da-liii
Copy link
Member Author

da-liii commented Sep 7, 2023

关键日志:

> xmake config -p mingw -vD
checking for architecture ... x86_64
checking for mingw directory ... no
> checking for c++ snippet(CONFIG_LARGE_POINTER)
checkinfo: ...amdir\core\sandbox\modules\import\core\tool\compiler.lua:37: cannot get program for cxx
stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:921]:
    [...amdir\core\sandbox\modules\import\core\tool\compiler.lua:37]: in function 'load'
    [...amdir\core\sandbox\modules\import\core\tool\compiler.lua:60]: in function 'compargv'
    [...amdir\core\sandbox\modules\import\core\tool\compiler.lua:44]: in function 'compcmd'
    [@programdir\modules\lib\detect\check_cxsnippets.lua:244]:

checking for CONFIG_LARGE_POINTER ... no
> checking for c++ includes(memory)
> checking for c++ types(time_t)
checkinfo: ...amdir\core\sandbox\modules\import\core\tool\compiler.lua:37: cannot get program for cxx
stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:921]:
    [...amdir\core\sandbox\modules\import\core\tool\compiler.lua:37]: in function 'load'
    [...amdir\core\sandbox\modules\import\core\tool\compiler.lua:60]: in function 'compargv'
    [...amdir\core\sandbox\modules\import\core\tool\compiler.lua:44]: in function 'compcmd'
    [@programdir\modules\lib\detect\check_cxsnippets.lua:244]:

checking for HAVE_TIME_T ... no
> checking for c++ includes(inttypes.h)
checkinfo: ...amdir\core\sandbox\modules\import\core\tool\compiler.lua:37: cannot get program for cxx
stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:921]:
    [...amdir\core\sandbox\modules\import\core\tool\compiler.lua:37]: in function 'load'
    [...amdir\core\sandbox\modules\import\core\tool\compiler.lua:60]: in function 'compargv'
    [...amdir\core\sandbox\modules\import\core\tool\compiler.lua:44]: in function 'compcmd'
    [@programdir\modules\lib\detect\check_cxsnippets.lua:244]:

checking for HAVE_INTTYPES_H ... no
> checking for c++ includes(mutex)
> checking for c++ types(std::mutex)
checkinfo: ...amdir\core\sandbox\modules\import\core\tool\compiler.lua:37: cannot get program for cxx
stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:921]:
    [...amdir\core\sandbox\modules\import\core\tool\compiler.lua:37]: in function 'load'
    [...amdir\core\sandbox\modules\import\core\tool\compiler.lua:60]: in function 'compargv'
    [...amdir\core\sandbox\modules\import\core\tool\compiler.lua:44]: in function 'compcmd'
    [@programdir\modules\lib\detect\check_cxsnippets.lua:244]:

@waruqi
Copy link
Member

waruqi commented Sep 8, 2023

这个不太好搞,因为你用了 add_requires + add_toolchains + mingw 去绑定的工具链,这个是 target 粒度的,尽管是对所有 target 生效,但毕竟不是全局的。。

而 你用的 configvar_check_cxxtypes 是全局接口,跟 target 没有关系,因此它无法获取到 add_toolchains 的工具链信息,只能从全局平台层 获取工具链,而全局平台工具链,如果系统没有 mingw,也没 xmake f -p mingw --mingw=/xxx 指定路径,是获取不到的,因此检测会失败。

而 configvar_check_cxxtypes 内部实现走的 option,这个阶段不太可能取到 add_toolschains 的信息,即使后期想支持也不好实现

如果想要在自动绑定 toolchains 的前提下,也能实现自动检测,得用 target 的检测接口才行。。

add_requires("mingw-w64 8.1.0")
set_toolchains("mingw@mingw-w64")

target("test")
    on_config(function (target)
        if target:has_cxxtypes("intptr_t", {includes = "memory"}) then
            target:set("configvar", "HAVE_INTPTR_T", 1)
        end
    end)

其他的检测接口类似,target 层的检测接口,跟 add_toolchains 工具链绑定是同步的,而且不同 target 可以绑定 不同的 toolchains ,也不会干扰检测。。

具体见 #3522
https://xmake.io/#/zh-cn/manual/target_instance?id=targethas_cxxtypes

如果觉得每个 target 都这么配置比较繁琐,可以单独搞个 check.lua 的模块,配置所有检测后,统一处理。。

独立模块可以像 cmake 那样,单独搞个 xmake 目录维护所有配置脚本,然后用 add_moduledirs + import 引入

https://xmake.io/#/zh-cn/manual/global_interfaces?id=add_moduledirs

- projectdiur
- xmake
  - check.lua
- src
- xmake.lua
add_moduledirs("xmake")

-- 全局配置,所有 target 生效
on_config(function (target)
    import("check")
    check(target)
end)

target("test1")
target("test2")

check.lua

function main(target)
    -- check cxxtypes
    -- check includes
    -- check functions ...
end

@da-liii
Copy link
Member Author

da-liii commented Sep 8, 2023

感谢,已成功配置:XmacsLabs/lolly#137

@jingkaimori
Copy link
Contributor

在target进行的检测可以缓存吗?on_config事件每次编译前都会触发,导致重复检测

@Issues-translate-bot
Copy link

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


Can detection performed at target be cached? The on_config event will be triggered before each compilation, resulting in repeated detection.

@waruqi
Copy link
Member

waruqi commented Sep 11, 2023

在target进行的检测可以缓存吗?on_config事件每次编译前都会触发,导致重复检测

没有, on_config 每次配置都会被执行,不过 dev 我刚加了个 recheck 状态,你可以根据这个来判断是否需要检测

on_config(target, opt)
    if opt.recheck and target:has_cfuncs(...) then
    end
 end

@Issues-translate-bot
Copy link

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


Can detection performed at target be cached? The on_config event will be triggered before each compilation, resulting in repeated detection.

No, on_config will be executed every time the configuration is configured, but I just added a recheck status to dev. You can use this to determine whether detection is needed.

on_config(target, opt)
     if opt.recheck and target:has_cfuncs(...) then
    end
 end

@waruqi
Copy link
Member

waruqi commented Sep 12, 2023

参考这个 patch, tboox/tbox#235

@Issues-translate-bot
Copy link

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


Refer to this patch, tboox/tbox#235

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

No branches or pull requests

4 participants