Skip to content

Commit 362e731

Browse files
committed
(rules) move platform.windows.subsystem rule to its right directory and add it to platform.windows
1 parent 221ca3c commit 362e731

File tree

7 files changed

+63
-41
lines changed

7 files changed

+63
-41
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--!A cross-platform build utility based on Lua
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
--
15+
-- Copyright (C) 2015-present, TBOOX Open Source Group.
16+
--
17+
-- @author ruki, Arthapz
18+
-- @file xmake.lua
19+
--
20+
21+
-- define rule: subsystem
22+
-- set any of "boot_application" "console" "efi_application" "efi_boot_service_driver" "efi_rom" "efi_runtime_driver" "native" "posix" "windows"
23+
-- with target:set_values("windows.subsystem", <your value>) and the rule will pass the proper flag to the linker
24+
rule("platform.windows.subsystem")
25+
on_config("mingw", "windows", function(target)
26+
local subsystems = {
27+
"BOOT_APPLICATION", "CONSOLE", "EFI_APPLICATION", "EFI_BOOT_SERVICE_DRIVER", "EFI_ROM", "EFI_RUNTIME_DRIVER", "NATIVE", "POSIX", "WINDOWS"
28+
}
29+
30+
local subsystem = target:values("windows.subsystem")
31+
if subsystem then
32+
local valid = false
33+
for _, s in ipairs(subsystems) do
34+
if subsystem:upper():startwiths(s) then
35+
valid = true
36+
break
37+
end
38+
end
39+
assert(valid, "Invalid subsystem " .. subsystem)
40+
41+
if target:has_tool("ld", "clang") then
42+
target:add("ldflags", "-Wl,-subsystem:" .. subsystem, { force = true })
43+
elseif target:has_tool("ld", "link", "lld-link") then
44+
target:add("ldflags", "/SUBSYSTEM:" .. upper(subsystem), { force = true })
45+
elseif target:has_tool("ld", "gcc", "g++") then
46+
target:add("ldflags", "-Wl,-m" .. subsystem, { force = true })
47+
elseif target:has_tool("ld", "ld") then
48+
target:add("ldflags", "-m" .. subsystem, { force = true })
49+
end
50+
end
51+
end)

xmake/rules/platform/xmake.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
--
2020

2121
rule("platform.wasm")
22-
add_deps("platform.wasm.preloadfiles")
23-
add_deps("platform.wasm.installfiles")
22+
add_deps("platform.wasm.preloadfiles",
23+
"platform.wasm.installfiles")
2424

2525
rule("platform.windows")
26-
add_deps("platform.windows.def")
27-
add_deps("platform.windows.idl")
26+
add_deps("platform.windows.def",
27+
"platform.windows.idl",
28+
"platform.windows.subsystem")
2829
if is_host("windows") then
2930
add_deps("platform.windows.manifest")
3031
end

xmake/rules/qt/xmake.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ rule("qt.shared")
6767

6868
-- define rule: qt console
6969
rule("qt.console")
70-
add_deps("qt.qrc", "qt.ui", "qt.moc", "qt.ts", "platform.windows.subsystem")
70+
add_deps("qt.qrc", "qt.ui", "qt.moc", "qt.ts")
7171

7272
-- we must set kind before target.on_load(), may we will use target in on_load()
7373
on_load(function (target)
@@ -83,7 +83,7 @@ rule("qt.console")
8383

8484
-- define rule: qt widgetapp
8585
rule("qt.widgetapp")
86-
add_deps("qt.ui", "qt.moc", "qt._wasm_app", "qt.qrc", "qt.ts", "platform.windows.subsystem")
86+
add_deps("qt.ui", "qt.moc", "qt._wasm_app", "qt.qrc", "qt.ts")
8787

8888
-- we must set kind before target.on_load(), may we will use target in on_load()
8989
on_load(function (target)

xmake/rules/wdk/xmake.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
rule("wdk.driver")
2323

2424
-- add rules
25-
add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof", "wdk.tracewpp", "wdk.sign", "wdk.package.cab", "platform.windows.subsystem")
25+
add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof", "wdk.tracewpp", "wdk.sign", "wdk.package.cab")
2626

2727
-- after load
2828
after_load(function (target)

xmake/rules/windows/xmake.lua

Lines changed: 0 additions & 27 deletions
This file was deleted.

xmake/rules/winsdk/mfc/xmake.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ rule("win.sdk.mfc.static")
4343
-- define rule: the application with shared mfc libraries
4444
rule("win.sdk.mfc.shared_app")
4545

46-
-- add mfc base and subsystem rule
47-
add_deps("win.sdk.mfc.env", "platform.windows.subsystem")
46+
-- add mfc base rule
47+
add_deps("win.sdk.mfc.env")
4848

4949
-- after load
5050
after_load(function (target)
@@ -54,8 +54,8 @@ rule("win.sdk.mfc.shared_app")
5454
-- define rule: the application with static mfc libraries
5555
rule("win.sdk.mfc.static_app")
5656

57-
-- add mfc base and subsystem rule
58-
add_deps("win.sdk.mfc.env", "platform.windows.subsystem")
57+
-- add mfc base rule
58+
add_deps("win.sdk.mfc.env")
5959

6060
-- after load
6161
after_load(function (target)

xmake/rules/winsdk/xmake.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ rule("win.sdk.application")
2929
target:set("kind", "binary")
3030
end)
3131

32-
-- set subsystem: windows
33-
add_deps("platform.windows.subsystem")
34-
3532
after_load(function (target)
3633
-- set windows subsystem
3734
if not target:values("windows.subsystem") then

0 commit comments

Comments
 (0)