summaryrefslogtreecommitdiff
path: root/xmake/modules/private/utils/toolchain.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-20 00:45:39 +0800
committerruki <[email protected]>2025-12-20 00:45:39 +0800
commitd3ded5d78ea15d2f2299cab3d03165ab8d07951b (patch)
treeebb675e7d9ef99a69294f024bea24ba22ac33cf6 /xmake/modules/private/utils/toolchain.lua
parentb89cfa3d77e20ddf8da83423052eba23f64d8777 (diff)
add vsenvs in toolchain utils
Diffstat (limited to 'xmake/modules/private/utils/toolchain.lua')
-rw-r--r--xmake/modules/private/utils/toolchain.lua44
1 files changed, 42 insertions, 2 deletions
diff --git a/xmake/modules/private/utils/toolchain.lua b/xmake/modules/private/utils/toolchain.lua
index 2d6e63b15..f2b4ca593 100644
--- a/xmake/modules/private/utils/toolchain.lua
+++ b/xmake/modules/private/utils/toolchain.lua
@@ -91,6 +91,48 @@ function check_vstudio(toolchain, check)
return vs
end
+-- add the given vs environment
+function _add_vsenv(toolchain, name, curenvs)
+
+ -- get vcvars
+ local vcvars = toolchain:config("vcvars")
+ if not vcvars then
+ return
+ end
+
+ -- get the paths for the vs environment
+ local new = vcvars[name]
+ if new then
+ -- fix case naming conflict for cmake/msbuild between the new msvc envs and current environment, if we are running xmake in vs prompt.
+ -- @see https://github.com/xmake-io/xmake/issues/4751
+ for k, c in pairs(curenvs) do
+ if name:lower() == k:lower() and name ~= k then
+ name = k
+ break
+ end
+ end
+ if name == "INCLUDE" or name == "LIB" then
+ toolchain:add("runenvs", name, table.concat(path.splitenv(new), ";"))
+ else
+ toolchain:add("runenvs", name, table.unwrap(path.splitenv(new)))
+ end
+ end
+end
+
+-- add vs environments
+function add_vsenvs(toolchain, expect_vars)
+ local curenvs = os.getenvs()
+ expect_vars = expect_vars or {"PATH", "LIB", "INCLUDE", "LIBPATH"}
+ for _, name in ipairs(expect_vars) do
+ _add_vsenv(toolchain, name, curenvs)
+ end
+ for _, name in ipairs(find_vstudio.get_vcvars()) do
+ if not table.contains(expect_vars, name:upper()) then
+ _add_vsenv(toolchain, name, curenvs)
+ end
+ end
+end
+
-- set llvm runtimes
function set_llvm_runtimes(toolchain)
-- We should set them up uniformly here, because runtimes will be accessed early (in sanitizer),
@@ -381,5 +423,3 @@ function add_llvm_runenvs(toolchain)
end
end
end
-
-