summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-05-23 22:39:39 +0800
committerruki <[email protected]>2024-05-23 22:39:39 +0800
commite4a3ca8b3412581eaa9b6a7acb00d7d2b5a6b27a (patch)
tree0528a32c85f0fa02738c0073fc60075da4b3807a
parentcfafccfa0bae60f83d27fdda1cb593da9aa0d309 (diff)
add icx for windows
-rw-r--r--xmake/modules/detect/sdks/find_icxenv.lua106
-rw-r--r--xmake/toolchains/icx/check.lua44
-rw-r--r--xmake/toolchains/icx/load.lua73
3 files changed, 215 insertions, 8 deletions
diff --git a/xmake/modules/detect/sdks/find_icxenv.lua b/xmake/modules/detect/sdks/find_icxenv.lua
index 55cd7d56e..df0c50dde 100644
--- a/xmake/modules/detect/sdks/find_icxenv.lua
+++ b/xmake/modules/detect/sdks/find_icxenv.lua
@@ -22,11 +22,113 @@
import("lib.detect.find_file")
import("lib.detect.find_tool")
--- find intel c/c++ envirnoment on windows
+-- init icx variables
+local icxvars = {"path",
+ "lib",
+ "libpath",
+ "include",
+ "DevEnvdir",
+ "VSInstallDir",
+ "VCInstallDir",
+ "WindowsSdkDir",
+ "WindowsLibPath",
+ "WindowsSDKVersion",
+ "WindowsSdkBinPath",
+ "UniversalCRTSdkDir",
+ "UCRTVersion"}
+
+-- load icxvars_bat environment variables
+function _load_icxvars(icxvars_bat, arch, opt)
+
+ -- make the genicxvars.bat
+ opt = opt or {}
+ local genicxvars_bat = os.tmpfile() .. "_genicxvars.bat"
+ local genicxvars_dat = os.tmpfile() .. "_genicxvars.txt"
+ local file = io.open(genicxvars_bat, "w")
+ file:print("@echo off")
+ file:print("call \"%s\" -arch %s > nul", icxvars_bat, arch)
+ for idx, var in ipairs(icxvars) do
+ file:print("echo " .. var .. " = %%" .. var .. "%% %s %s", idx == 1 and ">" or ">>", genicxvars_dat)
+ end
+ file:close()
+
+ -- run genicxvars.bat
+ os.run(genicxvars_bat)
+
+ -- load all envirnoment variables
+ local variables = {}
+ for _, line in ipairs((io.readfile(genicxvars_dat) or ""):split("\n")) do
+ local p = line:find('=', 1, true)
+ if p then
+ local name = line:sub(1, p - 1):trim()
+ local value = line:sub(p + 1):trim()
+ variables[name] = value
+ end
+ end
+ if not variables.path then
+ return
+ end
+
+ -- remove some empty entries
+ for _, name in ipairs(icxvars) do
+ if variables[name] and #variables[name]:trim() == 0 then
+ variables[name] = nil
+ end
+ end
+
+ -- fix bin path for ia32
+ if variables.path and arch == "ia32" then
+ variables.path = variables.path:gsub("windows\\bin\\intel64;", "windows\\bin\\intel64_ia32;")
+ end
+
+ -- convert path/lib/include to PATH/LIB/INCLUDE
+ variables.PATH = variables.path
+ variables.LIB = variables.lib
+ variables.LIBPATH = variables.libpath
+ variables.INCLUDE = variables.include
+ variables.path = nil
+ variables.lib = nil
+ variables.include = nil
+ variables.libpath = nil
+ return variables
+end
+
+-- find intel llvm c/c++ envirnoment on windows
function _find_intel_on_windows(opt)
+
+ -- init options
+ opt = opt or {}
+
+ -- find icxvars_bat.bat
+ local paths = {"$(env ICPP_COMPILER20)"}
+ local icxvars_bat = find_file("bin/icxvars.bat", paths)
+ -- look for setvars.bat which is new in 2021
+ if not icxvars_bat then
+ -- find setvars.bat in intel oneapi toolkits rootdir
+ paths = {"$(env ONEAPI_ROOT)"}
+ icxvars_bat = find_file("setvars.bat", paths)
+ end
+ if not icxvars_bat then
+ -- find setvars.bat using ICPP_COMPILER.*
+ paths = {
+ "$(env ICPP_COMPILER21)",
+ "$(env ICPP_COMPILER22)",
+ "$(env ICPP_COMPILER23)"
+ }
+ icxvars_bat = find_file("../../../setvars.bat", paths)
+ end
+ if icxvars_bat then
+
+ -- load icxvars_bat
+ local icxvars_x86 = _load_icxvars(icxvars_bat, "ia32", opt)
+ local icxvars_x64 = _load_icxvars(icxvars_bat, "intel64", opt)
+
+ -- save results
+ return {icxvars_bat = icxvars_bat, icxvars = {x86 = icxvars_x86, x64 = icxvars_x64}}
+ end
end
--- find intel c/c++ envirnoment on linux
+-- find intel llvm c/c++ envirnoment on linux
function _find_intel_on_linux(opt)
-- attempt to find the sdk directory
diff --git a/xmake/toolchains/icx/check.lua b/xmake/toolchains/icx/check.lua
index 4d627915b..d22889f14 100644
--- a/xmake/toolchains/icx/check.lua
+++ b/xmake/toolchains/icx/check.lua
@@ -24,17 +24,44 @@ import("core.project.config")
import("detect.sdks.find_icxenv")
import("lib.detect.find_tool")
--- main entry
-function main(toolchain)
+-- check intel on windows
+function _check_intel_on_windows(toolchain)
+
+ -- have been checked?
+ local varsall = toolchain:config("varsall")
+ if varsall then
+ return true
+ end
+
+ -- find intel llvm c/c++ compiler environment
+ local icxenv = find_icxenv()
+ if icxenv and icxenv.icxvars then
+ local icxvarsall = icxenv.icxvars
+ local icxenv = icxvarsall[toolchain:arch()]
+ if icxenv and icxenv.PATH and icxenv.INCLUDE and icxenv.LIB then
+ local tool = find_tool("icx.exe", {force = true, envs = icxenv, version = true})
+ if tool then
+ cprint("checking for Intel LLVM C/C++ Compiler (%s) ... ${color.success}${text.success}", toolchain:arch())
+ toolchain:config_set("varsall", icxvarsall)
+ toolchain:configs_save()
+ return true
+ end
+ end
+ end
+end
+
+-- check intel on linux
+function _check_intel_on_linux(toolchain)
local icxenv = toolchain:config("icxenv")
if icxenv then
return true
end
icxenv = find_icxenv()
if icxenv then
- local tool = find_tool("icx", {force = true, paths = icxenv.bindir})
+ local ldname = is_host("macosx") and "DYLD_LIBRARY_PATH" or "LD_LIBRARY_PATH"
+ local tool = find_tool("icx", {force = true, envs = {[ldname] = icxenv.libdir}, paths = icxenv.bindir})
if tool then
- cprint("checking for Intel LLVM C/C++ Compiler (%s) ... ${color.success}${text.success}", toolchain:arch())
+ cprint("checking for Intel C/C++ Compiler (%s) ... ${color.success}${text.success}", toolchain:arch())
toolchain:config_set("icxenv", icxenv)
toolchain:config_set("bindir", icxenv.bindir)
toolchain:configs_save()
@@ -44,3 +71,12 @@ function main(toolchain)
end
end
+-- main entry
+function main(toolchain)
+ if is_host("windows") then
+ return _check_intel_on_windows(toolchain)
+ else
+ return _check_intel_on_linux(toolchain)
+ end
+end
+
diff --git a/xmake/toolchains/icx/load.lua b/xmake/toolchains/icx/load.lua
index 4608c15ae..ebe3e8554 100644
--- a/xmake/toolchains/icx/load.lua
+++ b/xmake/toolchains/icx/load.lua
@@ -22,8 +22,61 @@
import("core.base.option")
import("core.project.config")
--- main entry
-function main(toolchain)
+-- add the given icx environment
+function _add_icxenv(toolchain, name)
+
+ -- get icxvarsall
+ local icxvarsall = toolchain:config("varsall")
+ if not icxvarsall then
+ return
+ end
+
+ -- get icx environment for the current arch
+ local arch = toolchain:arch()
+ local icxenv = icxvarsall[arch] or {}
+
+ -- get the paths for the icx environment
+ local env = icxenv[name]
+ if env then
+ toolchain:add("runenvs", name:upper(), path.splitenv(env))
+ end
+end
+
+-- load intel on windows
+function _load_intel_on_windows(toolchain)
+
+ -- set toolset
+ if toolchain:is_plat("windows") then
+ toolchain:set("toolset", "cc", "icx.exe")
+ toolchain:set("toolset", "cxx", "icx.exe")
+ toolchain:set("toolset", "mrc", "rc.exe")
+ if toolchain:is_arch("x64") then
+ toolchain:set("toolset", "as", "ml64.exe")
+ else
+ toolchain:set("toolset", "as", "ml.exe")
+ end
+ toolchain:set("toolset", "ld", "link.exe")
+ toolchain:set("toolset", "sh", "link.exe")
+ toolchain:set("toolset", "ar", "link.exe")
+ else
+ toolchain:set("toolset", "cc", "icx")
+ toolchain:set("toolset", "cxx", "icpx", "icx")
+ toolchain:set("toolset", "ld", "icpx", "icx")
+ toolchain:set("toolset", "sh", "icpx", "icx")
+ toolchain:set("toolset", "ar", "ar")
+ toolchain:set("toolset", "strip", "strip")
+ toolchain:set("toolset", "as", "icx")
+ end
+
+ -- add icx environments
+ _add_icxenv(toolchain, "PATH")
+ _add_icxenv(toolchain, "LIB")
+ _add_icxenv(toolchain, "INCLUDE")
+ _add_icxenv(toolchain, "LIBPATH")
+end
+
+-- load intel on linux
+function _load_intel_on_linux(toolchain)
-- set toolset
toolchain:set("toolset", "cc", "icx")
@@ -47,5 +100,21 @@ function main(toolchain)
toolchain:add("ldflags", march)
toolchain:add("shflags", march)
end
+
+ -- get icx environments
+ local icxenv = toolchain:config("icxenv")
+ if icxenv then
+ local ldname = is_host("macosx") and "DYLD_LIBRARY_PATH" or "LD_LIBRARY_PATH"
+ toolchain:add("runenvs", ldname, icxenv.libdir)
+ end
+end
+
+-- main entry
+function main(toolchain)
+ if is_host("windows") then
+ return _load_intel_on_windows(toolchain)
+ else
+ return _load_intel_on_linux(toolchain)
+ end
end