From cbdfb8581392eb426dd7abce07b16308d6ba5a25 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 7 Nov 2023 23:33:43 +0800 Subject: improve manifest --- xmake/rules/platform/windows/manifest/xmake.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/xmake/rules/platform/windows/manifest/xmake.lua b/xmake/rules/platform/windows/manifest/xmake.lua index e791d9398..112a93841 100644 --- a/xmake/rules/platform/windows/manifest/xmake.lua +++ b/xmake/rules/platform/windows/manifest/xmake.lua @@ -28,15 +28,25 @@ rule("platform.windows.manifest") end if target:has_tool("ld", "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}) manifest = true + local content = io.readfile(sourcefile) + if content and content:find("requestedPrivileges", 1, true) then + uac = true + 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("ldflags", "/manifest:embed", {force = true}) end end -- cgit v1.3.1 From 15fbe183b3508313ec28e23006db5cf6f2088da6 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 7 Nov 2023 23:37:48 +0800 Subject: add uac policy --- xmake/core/project/policy.lua | 4 ++++ xmake/rules/platform/windows/manifest/xmake.lua | 12 ++++++++++++ 2 files changed, 16 insertions(+) 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 112a93841..40c99fc67 100644 --- a/xmake/rules/platform/windows/manifest/xmake.lua +++ b/xmake/rules/platform/windows/manifest/xmake.lua @@ -48,6 +48,18 @@ rule("platform.windows.manifest") target:add("ldflags", "/manifestuac:no", {force = true}) end target:add("ldflags", "/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", {("/manifestuac:Level='%s' uiAccess='%s'"):format(level_maps[level], ui)}, {force = true, expand = false}) + end end end end) -- cgit v1.3.1 From 8eb314a2a511ab589828a0d29cb06de4703654c8 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 7 Nov 2023 23:38:04 +0800 Subject: improve test --- tests/projects/c++/manifest/xmake.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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") + -- cgit v1.3.1 From 7e5b59c9fb29f587546dfe691385f397024937ec Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 7 Nov 2023 23:38:54 +0800 Subject: ignore comment --- xmake/rules/platform/windows/manifest/xmake.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xmake/rules/platform/windows/manifest/xmake.lua b/xmake/rules/platform/windows/manifest/xmake.lua index 40c99fc67..8019930cd 100644 --- a/xmake/rules/platform/windows/manifest/xmake.lua +++ b/xmake/rules/platform/windows/manifest/xmake.lua @@ -35,8 +35,11 @@ rule("platform.windows.manifest") target:add("ldflags", "/manifestinput:" .. path.translate(sourcefile), {force = true}) manifest = true local content = io.readfile(sourcefile) - if content and content:find("requestedPrivileges", 1, true) then - uac = true + if content then + content = content:gsub("", "") + if content:find("requestedPrivileges", 1, true) then + uac = true + end end break end -- cgit v1.3.1 From 0e4c855a6b3e3b02ce1b55d4ac74ae0d098a22e6 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 7 Nov 2023 23:39:30 +0800 Subject: update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) 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 策略 ### 改进 -- cgit v1.3.1 From a1538c616b01bde50770ace4cefb0be49c8313b4 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 7 Nov 2023 23:43:35 +0800 Subject: enable embed --- xmake/rules/platform/windows/manifest/xmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/rules/platform/windows/manifest/xmake.lua b/xmake/rules/platform/windows/manifest/xmake.lua index 8019930cd..b545b3586 100644 --- a/xmake/rules/platform/windows/manifest/xmake.lua +++ b/xmake/rules/platform/windows/manifest/xmake.lua @@ -61,7 +61,7 @@ rule("platform.windows.manifest") } 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", {("/manifestuac:Level='%s' uiAccess='%s'"):format(level_maps[level], ui)}, {force = true, expand = false}) + target:add("ldflags", "/manifest:embed", {("/manifestuac:Level='%s' uiAccess='%s'"):format(level_maps[level], ui)}, {force = true, expand = false}) end end end -- cgit v1.3.1 From 00500d01dc3457d2531aeda985089f941ed468a1 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 7 Nov 2023 23:44:41 +0800 Subject: enable manifest for shared --- xmake/rules/platform/windows/manifest/xmake.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xmake/rules/platform/windows/manifest/xmake.lua b/xmake/rules/platform/windows/manifest/xmake.lua index b545b3586..cb9979342 100644 --- a/xmake/rules/platform/windows/manifest/xmake.lua +++ b/xmake/rules/platform/windows/manifest/xmake.lua @@ -23,16 +23,17 @@ 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("shflags", "/manifestinput:" .. path.translate(sourcefile), {force = true}) manifest = true local content = io.readfile(sourcefile) if content then @@ -50,7 +51,10 @@ rule("platform.windows.manifest") 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 -- cgit v1.3.1