summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2025-05-09 17:02:57 +0200
committerArthur LAURENT <[email protected]>2025-05-09 17:02:57 +0200
commit7d1f8a065d1eb5c886016ab5af201e086c9c5f67 (patch)
treee14b8c2264632aa346b075ebc678cc9e7b4c8a6e
parentd88bd9c5ace6c64981420569fb886f7c646135c0 (diff)
(rules) add win.subsystem rules
-rw-r--r--xmake/rules/windows/xmake.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/xmake/rules/windows/xmake.lua b/xmake/rules/windows/xmake.lua
new file mode 100644
index 000000000..6bffb4bea
--- /dev/null
+++ b/xmake/rules/windows/xmake.lua
@@ -0,0 +1,40 @@
+rule("win.subsystem.console")
+ add_deps("win.subsystem")
+ on_load(function(target)
+ target:data_set("win.subsystem", "console")
+ end)
+
+rule("win.subsystem.windows")
+ add_deps("win.subsystem")
+ on_load(function(target)
+ target:data_set("win.subsystem", "windows")
+ end)
+
+rule("win.subsystem")
+ on_config("mingw", "windows", function(target)
+ local subsystems = {
+ "BOOT_APPLICATION", "CONSOLE", "EFI_APPLICATION", "EFI_BOOT_SERVICE_DRIVER", "EFI_ROM", "EFI_RUNTIME_DRIVER", "NATIVE", "POSIX", "WINDOWS"
+ }
+
+ local subsystem = target:data("win.subsystem")
+ local valid = false
+ for _, s in ipairs(subsystems) do
+ if string.upper(subsystem):startswith(s) then
+ valid = true
+ break
+ end
+ end
+ assert(valid, "Invalid subsystem " .. subsystem)
+
+ local linker = target:tool("ld")
+ linker = path.filename(linker)
+ if linker:startswith("clang") then
+ target:add("ldflags", "-Wl,-subsystem:" .. subsystem, { force = true })
+ elseif linker:startswith("link") or linker:startswith("lld-link") then
+ target:add("ldflags", "/SUBSYSTEM:" .. string.upper(subsystem), { force = true })
+ elseif linker:startswith("gcc") or linker:startswith("g++") then
+ target:add("ldflags", "-Wl,-m" .. subsystem, { force = true })
+ elseif linker:startswith("ld") then
+ target:add("ldflags", "-m" .. subsystem, { force = true })
+ end
+ end)