summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-11-07 16:50:25 +0800
committerGitHub <[email protected]>2023-11-07 16:50:25 +0800
commitf374224ff3a1641c86e0e0ca8bfcd906b4931bc3 (patch)
tree5be215ac8e9d260389cc11f158d9e27358eef6b2
parent0dfe01c36d154fdf6fd0b9db51763d59d6037638 (diff)
parent00500d01dc3457d2531aeda985089f941ed468a1 (diff)
Merge pull request #4369 from xmake-io/manifest
improve manifest
-rw-r--r--CHANGELOG.md2
-rw-r--r--tests/projects/c++/manifest/xmake.lua8
-rw-r--r--xmake/core/project/policy.lua4
-rw-r--r--xmake/rules/platform/windows/manifest/xmake.lua35
4 files changed, 45 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 68cf9f10c..c855420af 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@
* [#4276](https://github.com/xmake-io/xmake/issues/4276): Support custom scope api
* [#4286](https://github.com/xmake-io/xmake/pull/4286): Add Apple XROS support
* [#4345](https://github.com/xmake-io/xmake/issues/4345): Support check sizeof
+* [#4369](https://github.com/xmake-io/xmake/pull/4369): Add windows.manifest.uac policy
### Changes
@@ -1687,6 +1688,7 @@
* [#4276](https://github.com/xmake-io/xmake/issues/4276): 支持自定义域 API
* [#4286](https://github.com/xmake-io/xmake/pull/4286): 添加 Apple XROS 支持
* [#4345](https://github.com/xmake-io/xmake/issues/4345): 支持检测类型大小 sizeof
+* [#4369](https://github.com/xmake-io/xmake/pull/4369): 添加 windows.manifest.uac 策略
### 改进
diff --git a/tests/projects/c++/manifest/xmake.lua b/tests/projects/c++/manifest/xmake.lua
index 121530a0c..b00cacd0f 100644
--- a/tests/projects/c++/manifest/xmake.lua
+++ b/tests/projects/c++/manifest/xmake.lua
@@ -1,6 +1,12 @@
add_rules("mode.debug", "mode.release")
-target("test")
+
+target("test1")
set_kind("binary")
add_files("src/*.cpp")
add_files("src/*.manifest")
+target("test2")
+ set_kind("binary")
+ add_files("src/*.cpp")
+ set_policy("windows.manifest.uac", "admin")
+
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua
index aa8e9ef9d..c0bf0e4e1 100644
--- a/xmake/core/project/policy.lua
+++ b/xmake/core/project/policy.lua
@@ -78,6 +78,10 @@ function policy.policies()
["build.c++.gcc.modules.cxx11abi"] = {description = "Force to enable new cxx11 abi in C++ modules for gcc.", type = "boolean"},
-- Enable cuda device link
["build.cuda.devlink"] = {description = "Enable Cuda devlink.", type = "boolean"},
+ -- Enable windows UAC and set level, e.g. invoker, admin, highest
+ ["windows.manifest.uac"] = {description = "Enable windows manifest UAC.", type = "string"},
+ -- Enable ui access for windows UAC
+ ["windows.manifest.uac.ui"] = {description = "Enable windows manifest UAC.", type = "boolean"},
-- Automatically build before running
["run.autobuild"] = {description = "Automatically build before running.", type = "boolean"},
-- Preprocessor configuration for ccache/distcc, we can disable linemarkers to speed up preprocess
diff --git a/xmake/rules/platform/windows/manifest/xmake.lua b/xmake/rules/platform/windows/manifest/xmake.lua
index e791d9398..cb9979342 100644
--- a/xmake/rules/platform/windows/manifest/xmake.lua
+++ b/xmake/rules/platform/windows/manifest/xmake.lua
@@ -23,21 +23,50 @@
rule("platform.windows.manifest")
set_extensions(".manifest")
on_config("windows", function (target)
- if not target:is_binary() then
+ if not target:is_binary() and not target:is_shared() then
return
end
- if target:has_tool("ld", "link") then
+ if target:has_tool("ld", "link") or target:has_tool("sh", "link") then
local manifest = false
+ local uac = false
local sourcebatch = target:sourcebatches()["platform.windows.manifest"]
if sourcebatch then
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
- target:add("ldflags", "/ManifestInput:" .. path.translate(sourcefile), {force = true})
+ target:add("ldflags", "/manifestinput:" .. path.translate(sourcefile), {force = true})
+ target:add("shflags", "/manifestinput:" .. path.translate(sourcefile), {force = true})
manifest = true
+ local content = io.readfile(sourcefile)
+ if content then
+ content = content:gsub("<!%-%-.-%-%->", "")
+ if content:find("requestedPrivileges", 1, true) then
+ uac = true
+ end
+ end
break
end
end
if manifest then
+ -- if manifest file is provided, we need disable default UAC manifest
+ -- @see https://github.com/xmake-io/xmake/pull/4362
+ if uac then
+ target:add("ldflags", "/manifestuac:no", {force = true})
+ end
+ target:add("shflags", "/manifestuac:no", {force = true})
+
target:add("ldflags", "/manifest:embed", {force = true})
+ target:add("shflags", "/manifest:embed", {force = true})
+ else
+ local level = target:policy("windows.manifest.uac")
+ if level then
+ local level_maps = {
+ invoker = "asInvoker",
+ admin = "requireAdministrator",
+ highest = "highestAvailable"
+ }
+ assert(level_maps[level], "unknown uac level %s, please set invoker, admin or highest", level)
+ local ui = target:policy("windows.manifest.uac.ui") or false
+ target:add("ldflags", "/manifest:embed", {("/manifestuac:Level='%s' uiAccess='%s'"):format(level_maps[level], ui)}, {force = true, expand = false})
+ end
end
end
end)