Skip to content

Commit f374224

Browse files
authored
Merge pull request #4369 from xmake-io/manifest
improve manifest
2 parents 0dfe01c + 00500d0 commit f374224

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* [#4276](https://github.com/xmake-io/xmake/issues/4276): Support custom scope api
1111
* [#4286](https://github.com/xmake-io/xmake/pull/4286): Add Apple XROS support
1212
* [#4345](https://github.com/xmake-io/xmake/issues/4345): Support check sizeof
13+
* [#4369](https://github.com/xmake-io/xmake/pull/4369): Add windows.manifest.uac policy
1314

1415
### Changes
1516

@@ -1687,6 +1688,7 @@
16871688
* [#4276](https://github.com/xmake-io/xmake/issues/4276): 支持自定义域 API
16881689
* [#4286](https://github.com/xmake-io/xmake/pull/4286): 添加 Apple XROS 支持
16891690
* [#4345](https://github.com/xmake-io/xmake/issues/4345): 支持检测类型大小 sizeof
1691+
* [#4369](https://github.com/xmake-io/xmake/pull/4369): 添加 windows.manifest.uac 策略
16901692

16911693
### 改进
16921694

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
add_rules("mode.debug", "mode.release")
2-
target("test")
2+
3+
target("test1")
34
set_kind("binary")
45
add_files("src/*.cpp")
56
add_files("src/*.manifest")
67

8+
target("test2")
9+
set_kind("binary")
10+
add_files("src/*.cpp")
11+
set_policy("windows.manifest.uac", "admin")
12+

xmake/core/project/policy.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ function policy.policies()
7878
["build.c++.gcc.modules.cxx11abi"] = {description = "Force to enable new cxx11 abi in C++ modules for gcc.", type = "boolean"},
7979
-- Enable cuda device link
8080
["build.cuda.devlink"] = {description = "Enable Cuda devlink.", type = "boolean"},
81+
-- Enable windows UAC and set level, e.g. invoker, admin, highest
82+
["windows.manifest.uac"] = {description = "Enable windows manifest UAC.", type = "string"},
83+
-- Enable ui access for windows UAC
84+
["windows.manifest.uac.ui"] = {description = "Enable windows manifest UAC.", type = "boolean"},
8185
-- Automatically build before running
8286
["run.autobuild"] = {description = "Automatically build before running.", type = "boolean"},
8387
-- Preprocessor configuration for ccache/distcc, we can disable linemarkers to speed up preprocess

xmake/rules/platform/windows/manifest/xmake.lua

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,50 @@
2323
rule("platform.windows.manifest")
2424
set_extensions(".manifest")
2525
on_config("windows", function (target)
26-
if not target:is_binary() then
26+
if not target:is_binary() and not target:is_shared() then
2727
return
2828
end
29-
if target:has_tool("ld", "link") then
29+
if target:has_tool("ld", "link") or target:has_tool("sh", "link") then
3030
local manifest = false
31+
local uac = false
3132
local sourcebatch = target:sourcebatches()["platform.windows.manifest"]
3233
if sourcebatch then
3334
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
34-
target:add("ldflags", "/ManifestInput:" .. path.translate(sourcefile), {force = true})
35+
target:add("ldflags", "/manifestinput:" .. path.translate(sourcefile), {force = true})
36+
target:add("shflags", "/manifestinput:" .. path.translate(sourcefile), {force = true})
3537
manifest = true
38+
local content = io.readfile(sourcefile)
39+
if content then
40+
content = content:gsub("<!%-%-.-%-%->", "")
41+
if content:find("requestedPrivileges", 1, true) then
42+
uac = true
43+
end
44+
end
3645
break
3746
end
3847
end
3948
if manifest then
49+
-- if manifest file is provided, we need disable default UAC manifest
50+
-- @see https://github.com/xmake-io/xmake/pull/4362
51+
if uac then
52+
target:add("ldflags", "/manifestuac:no", {force = true})
53+
end
54+
target:add("shflags", "/manifestuac:no", {force = true})
55+
4056
target:add("ldflags", "/manifest:embed", {force = true})
57+
target:add("shflags", "/manifest:embed", {force = true})
58+
else
59+
local level = target:policy("windows.manifest.uac")
60+
if level then
61+
local level_maps = {
62+
invoker = "asInvoker",
63+
admin = "requireAdministrator",
64+
highest = "highestAvailable"
65+
}
66+
assert(level_maps[level], "unknown uac level %s, please set invoker, admin or highest", level)
67+
local ui = target:policy("windows.manifest.uac.ui") or false
68+
target:add("ldflags", "/manifest:embed", {("/manifestuac:Level='%s' uiAccess='%s'"):format(level_maps[level], ui)}, {force = true, expand = false})
69+
end
4170
end
4271
end
4372
end)

0 commit comments

Comments
 (0)