|
23 | 23 | rule("platform.windows.manifest") |
24 | 24 | set_extensions(".manifest") |
25 | 25 | on_config("windows", function (target) |
26 | | - if not target:is_binary() then |
| 26 | + if not target:is_binary() and not target:is_shared() then |
27 | 27 | return |
28 | 28 | end |
29 | | - if target:has_tool("ld", "link") then |
| 29 | + if target:has_tool("ld", "link") or target:has_tool("sh", "link") then |
30 | 30 | local manifest = false |
| 31 | + local uac = false |
31 | 32 | local sourcebatch = target:sourcebatches()["platform.windows.manifest"] |
32 | 33 | if sourcebatch then |
33 | 34 | 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}) |
35 | 37 | 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 |
36 | 45 | break |
37 | 46 | end |
38 | 47 | end |
39 | 48 | 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 | + |
40 | 56 | 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 |
41 | 70 | end |
42 | 71 | end |
43 | 72 | end) |
0 commit comments