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

onedpl add fetch.lua #4324

Merged
merged 12 commits into from
Jun 11, 2024
Merged
44 changes: 44 additions & 0 deletions packages/o/onedpl/fetch.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import("lib.detect.find_path")
import("lib.detect.find_library")

function _find_package(package, opt)
local paths = {
"$(env DPL_ROOT)",
"$(env ONEAPI_ROOT)/dpl/latest"
}
-- find library
local result = {links = {}, linkdirs = {}, includedirs = {}}

-- find include
local includepath = find_path(path.join("oneapi","dpl","algorithm"), paths, {suffixes = "include"})
if includepath then
table.insert(result.includedirs, includepath)
end

if #result.includedirs > 0 then
local version_file = path.join(includepath, "oneapi","dpl","pstl","onedpl_config.h")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还有这,逗号两边空格

if os.isfile(version_file) then
local content = io.readfile(version_file)
local major = content:match("ONEDPL_VERSION_MAJOR +(%d+)\n")
local minor = content:match("ONEDPL_VERSION_MINOR +(%d+)\n")
local patch = content:match("ONEDPL_VERSION_PATCH +(%d+)\n")
if patch then
result.version = format("%s.%s.%s", major, minor, patch)
else
result.version = format("%s.%s", major, minor)
end
end

return result
end
end

function main(package, opt)
if opt.system and package.find_package then
local result = _find_package(package, opt)
if not result then
result = package:find_package("onedpl", opt)
end
return result or false
end
end
24 changes: 23 additions & 1 deletion packages/o/onedpl/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,37 @@ package("onedpl")
set_homepage("https://www.intel.com/content/www/us/en/developer/tools/oneapi/dpc-library.html")
set_description("oneAPI DPC++ Library")

add_urls("https://github.com/oneapi-src/oneDPL/archive/refs/tags/oneDPL-$(version).tar.gz")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该放开头,否则每次都有一次 404 failed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果以后出了新的,它是-release.tar.gz而不是.rc?.tar.gz,是不是还要把顺序换回来o.O我在想或者直接把release写到版本号得了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参考 sqlite3 的包,写 version function

add_urls("https://github.com/oneapi-src/oneDPL/archive/refs/tags/oneDPL-$(version)-release.tar.gz")
add_versions("2021.6.1", "4995fe2ed2724b89cdb52c4b6c9af22e146b48d2561abdafdaaa06262dbd67c4")
add_versions("2022.5.0-rc1", "9180c60331ec5b307dd89a5d8bfcd096667985c6761c52322405d4b69193ed88")

add_configs("backend", {description = "Choose threading backend.", default = "tbb", type = "string", values = {"tbb", "dpcpp", "dpcpp_only", "omp", "serial"}})

add_deps("cmake")

on_fetch("fetch")
on_load("windows", "linux", function (package)
local backend = package:config("backend")
if backend == "tbb" or backend == "dpcpp" then
if backend == "tbb" then
package:add("deps", "tbb")
package:add("defines", "ONEDPL_USE_TBB_BACKEND=1")
package:add("ldflags", "-ltbb")
elseif backend == "omp" then
package:add("deps", "openmp")
package:add("defines", "ONEDPL_USE_OPENMP_BACKEND=1")
elseif backend == "dpcpp" then
package:add("deps", "tbb")
package:add("ldflags", "-ltbb")
package:add("defines", "ONEDPL_USE_TBB_BACKEND=1")
package:add("defines", "ONEDPL_USE_DPCPP_BACKEND=1")
elseif backend == "dpcpp_only" then
package:add("defines", "ONEDPL_USE_TBB_BACKEND=0")
package:add("defines", "ONEDPL_USE_DPCPP_BACKEND=1")
elseif backend == "serial" then
package:add("defines", "ONEDPL_USE_OPENMP_BACKEND=0")
package:add("defines", "ONEDPL_USE_TBB_BACKEND=0")
package:add("defines", "ONEDPL_USE_DPCPP_BACKEND=0")
end
if package:is_plat("windows") then
package:add("cxxflags", "/Zc:__cplusplus")
Expand All @@ -24,6 +43,9 @@ package("onedpl")

on_install("windows", "linux", function (package)
io.replace("CMakeLists.txt", "add_subdirectory(test)", "", {plain = true})
-- c.f. https://github.com/oneapi-src/oneDPL/issues/1602 and https://github.com/oneapi-src/oneDPL/commit/e25afef957b50536c5091ed23150fff10921b18f
io.replace("include/oneapi/dpl/pstl/algorithm_impl.h", "(_PSTL_UDR_PRESENT || _ONEDPL_UDR_PRESENT)", "_ONEDPL_UDR_PRESENT // _PSTL_UDR_PRESENT", {plain = true})
io.replace("include/oneapi/dpl/pstl/numeric_impl.h", "(_PSTL_UDS_PRESENT || _ONEDPL_UDS_PRESENT)", "_ONEDPL_UDS_PRESENT // PSTL_UDS_PRESENT", {plain = true})
local configs = {}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
table.insert(configs, "-DONEDPL_BACKEND=" .. package:config("backend"))
Expand Down
Loading