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

Make openmp a package #1865

Closed
xq114 opened this issue Nov 28, 2021 · 6 comments
Closed

Make openmp a package #1865

xq114 opened this issue Nov 28, 2021 · 6 comments

Comments

@xq114
Copy link
Contributor

xq114 commented Nov 28, 2021

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

现在openmp 是以rule的形式引进的add_rules("c.openmp"),但这种方式不够灵活,无法很容易的检测编译器是否有openmp支持,同时需要使用openmp的package也无法直接用add_deps("openmp")来引入。

描述可能的解决方案

把openmp做成fetch-only的package,然后用package来取代之前的rule

其他信息

在on_fetch中探测编译器feature的best practice是怎样的?import("core.tool.compiler").has_flags("-fopenmp")这样正确吗?

@waruqi
Copy link
Member

waruqi commented Nov 28, 2021

import("core.tool.compiler").has_flags("-fopenmp")这样正确吗?

可以是可以,比较繁琐,交叉编译没法适配

得加个 package:has_flags() 或者 package:compiler()才能适配package的内部工具链

@waruqi
Copy link
Member

waruqi commented Nov 28, 2021

最好是加 add_cxflags 这种到 package 实现 flags 自动check追加,然后搭配 package:compiler/package:linker 此类接口,会更好些

on_load(function (package)
    if package:compiler("cxx"):is("gcc", "clang") then
        package:add("cxflags", "-fopenmp")
    end
end)

然后 has_flags 也可以放到 package:compiler("cxx"):has_flags/has_features 可选使用

target 里面也可以加此类接口,方便编译器判断

@waruqi waruqi added this to the v2.6.1 milestone Nov 28, 2021
@waruqi
Copy link
Member

waruqi commented Nov 29, 2021

我改进过了,其实 package 定义,原本就支持 add_cxflags 此类,直接对外导出 flags,并且支持自动检测

https://github.com/xmake-io/xmake-repo/blob/4f117f7cf2a11173d8ff4fd9ae769d61365ccc0d/packages/l/libomp/xmake.lua#L18-L39

我现在对 target/package 加了个 package:has_tool("cc", "clang", "gcc") 的接口,方便判断各种编译器

现在可以简化为

add_requires("libomp", {optional = true})
target("hello")
    set_kind("binary")
    add_files("src/*.c")
    add_packages("libomp")

不过需要同时更新下库和xmake

@waruqi waruqi closed this as completed Nov 29, 2021
@xq114
Copy link
Contributor Author

xq114 commented Nov 29, 2021

这样写不行,openmp是一个标准,libomp是openmp的llvm实现,还有很多别的实现比如gnu的libgomp,intel的libiomp,微软的microsoft openmp,应该加一个通用的openmp包(使用该编译器的默认实现),然后对不同的特殊实现包处理特殊实现的情况

@waruqi
Copy link
Member

waruqi commented Nov 29, 2021

那你搞个pr 过来吧,参考刚 添加 flags 的方式

@waruqi
Copy link
Member

waruqi commented Nov 30, 2021

改过了

add_requires("openmp")
target("hello")
    set_kind("binary")
    add_files("src/*.c")
    add_packages("openmp")

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

2 participants