-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmake.lua
More file actions
499 lines (449 loc) · 17.8 KB
/
Copy pathxmake.lua
File metadata and controls
499 lines (449 loc) · 17.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
set_project("cwinrt")
set_version("0.3.0")
set_languages("c23")
set_warnings("all", "extra")
-- Without this the "release" build carried no /O2, leaving the winmd parser /
-- sig decoder unoptimized (full regen ~350s). Optimize for speed across targets.
set_optimize("fastest")
if is_plat("windows") then
add_defines("_CRT_SECURE_NO_WARNINGS", "UNICODE", "_UNICODE")
end
if is_plat("mingw") then
add_cxflags("-Wno-logical-op-parentheses")
elseif is_plat("windows") then
add_cxflags("/wd4996")
end
-- clang-cl: xmake's c23 -> MSVC-standard fallback list ends in `-TP`. On a
-- clang-cl that accepts neither /std:c23 nor /std:clatest, xmake falls through
-- to that flag and hands C sources to the wrong frontend.
-- /TC forces C source mode; appended after the std flag, it overrides a stray -TP.
-- {force = true} bypasses xmake's auto-ignore-flags probe so /TC is always emitted.
-- No-op for MSVC/mingw (their C sources are already C); it only rescues clang-cl.
if is_plat("windows") then
add_cflags("/TC", {force = true})
end
-- Emit each function/datum into its own section so the linker (--gc-sections /
-- /OPT:REF) can drop unused wrappers at function granularity. Without it,
-- referencing one function from a namespace pulls that impl TU's entire wrapper
-- set into the binary (~46KB+ of dead code per consumer). File-scope: inherited
-- by every target defined below.
if is_plat("mingw") then
add_cflags("-ffunction-sections", "-fdata-sections")
elseif is_plat("windows") then
add_cflags("/Gy", "/Gw")
end
-- True when cwinrt is built on its own; false when it's `includes()`'d as a
-- dependency (then os.projectdir() is the *consuming* project, e.g. fluxent).
-- Consumers only need the library targets (runtime + bindings + umbrella); the
-- generator, tests, samples and dev tasks below are gated on this so a consumer's
-- `xmake build` doesn't compile cwinrt's whole conformance suite (link_all alone
-- pulls in all 343 *.impl.c).
local is_main = (os.projectdir() == os.scriptdir())
add_includedirs("include")
add_includedirs("gen")
-- Runtime (MSVC + MinGW on Windows)
target("cwinrt-rt")
set_kind("static")
add_files("rt/*.c")
add_headerfiles("include/cwinrt/bootstrap.h")
add_headerfiles("include/cwinrt/*.h")
if is_plat("windows", "mingw") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
if is_main then
-- Code generator (pure C ECMA-335 winmd reader)
target("cwinrt-gen")
set_kind("binary")
add_files("gen/*.c")
if is_plat("windows") then
-- Deep winmd signatures (e.g. Windows.Security.Isolation) need >1MB default stack.
add_ldflags("/STACK:8388608", {tools = {"link"}})
elseif is_plat("mingw") then
add_ldflags("-Wl,--stack,8388608", {tools = {"link"}})
end
if not is_plat("windows", "mingw", "linux", "macosx") then
set_enabled(false)
end
-- Smoke test (consumes rt + generated headers)
target("test_smoke")
set_kind("binary")
add_files("tests/test_smoke.c")
add_deps("cwinrt-rt")
add_includedirs("include")
if is_plat("windows", "mingw") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
target("test_abi")
set_kind("binary")
add_files("tests/abi/test_abi.c")
add_deps("cwinrt-rt")
add_includedirs("include")
if is_plat("windows", "mingw") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
end -- is_main (generator + smoke/abi tests)
target("cwinrt-bindings-composition")
set_kind("static")
add_files("include/cwinrt/impl/Windows.UI.Composition.impl.c")
add_includedirs("include")
add_deps("cwinrt-rt")
if is_plat("windows", "mingw") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
target("cwinrt-bindings-foundation")
set_kind("static")
add_files("include/cwinrt/impl/Windows.Foundation.impl.c")
add_includedirs("include")
add_deps("cwinrt-rt")
if is_plat("windows", "mingw") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
target("cwinrt-bindings-interactions")
set_kind("static")
add_files("include/cwinrt/impl/Windows.UI.Composition.Interactions.impl.c")
add_includedirs("include")
add_deps("cwinrt-rt")
if is_plat("windows", "mingw") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
target("cwinrt-bindings-viewmanagement")
set_kind("static")
add_files("include/cwinrt/impl/Windows.UI.ViewManagement.impl.c")
add_includedirs("include")
add_deps("cwinrt-rt")
if is_plat("windows", "mingw") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
target("cwinrt-bindings-numberformatting")
set_kind("static")
add_files("include/cwinrt/impl/Windows.Globalization.NumberFormatting.impl.c")
add_includedirs("include")
add_deps("cwinrt-rt")
if is_plat("windows", "mingw") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
target("cwinrt-bindings-input")
set_kind("static")
add_files("include/cwinrt/impl/Windows.UI.Input.impl.c")
add_includedirs("include")
add_deps("cwinrt-rt")
if is_plat("windows", "mingw") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
-- All generated impl units (present after xmake gen-all-impl)
target("cwinrt-bindings-all")
set_kind("static")
add_files("include/cwinrt/impl/*.impl.c")
add_includedirs("include")
add_deps("cwinrt-rt")
if is_plat("windows", "mingw") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
-- Public integration surface. Downstream projects add ONE line, `add_deps("cwinrt")`,
-- and inherit the header path, the runtime + every generated binding, AND the full
-- platform link recipe -- no add_includedirs/add_syslinks repetition. The {public}
-- config is what propagates to dependents (xmake interface deps). See docs/INTEGRATION.md.
target("cwinrt")
set_kind("phony")
add_deps("cwinrt-rt", "cwinrt-bindings-all")
add_includedirs("include", {public = true})
-- MSVC pulls uuid / IInspectable from its SDK automatically; mingw does not.
-- IID_IUnknown comes from uuid; IID_IInspectable / IID_IActivationFactory are
-- defined by rt/cwinrt_guids.c. We must NOT link winstorecompat for those two
-- GUIDs: it also replaces desktop Win32 APIs (GetStartupInfo, CreateFileW, ...)
-- with abort() stubs, which crashes the CRT before main in any desktop app.
if is_plat("mingw") then
add_syslinks("uuid", "runtimeobject", "ole32", "oleaut32", {public = true})
elseif is_plat("windows") then
add_syslinks("runtimeobject", "ole32", "oleaut32", {public = true})
end
if is_main then
-- 4b integration gate: a consumer wired with ONLY `add_deps("cwinrt")` (no include
-- dir, no syslinks). If it builds + runs, the public surface above is intact.
target("consume_cwinrt")
set_kind("binary")
add_files("tests/conform/consume_cwinrt.c")
add_deps("cwinrt")
-- link_all: link every impl TU + a stub main into one binary so the linker
-- surfaces cross-TU duplicate symbols (LNK2005) the per-file compile gate cannot.
-- Impl objects are linked directly, not via an archive.
target("link_all")
set_kind("binary")
add_files("include/cwinrt/impl/*.impl.c")
add_files("tests/conform/link_all_main.c")
add_includedirs("include")
add_deps("cwinrt-rt")
if is_plat("windows", "mingw") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
-- Real-hardware end-to-end: activation, cwinrt_query cast, and a value-type
-- round-trip down a deep slot chain (validates vtable slots on hardware).
target("e2e_composition")
set_kind("binary")
add_files("tests/conform/e2e_composition.c")
add_deps("cwinrt")
-- Headless variant (no interactive desktop required), so it runs in any
-- session/CI. Same purpose: validate vtable slots + the cast/IID on hardware.
target("e2e_headless")
set_kind("binary")
add_files("tests/conform/e2e_headless.c")
add_deps("cwinrt")
-- Headless: the delegate shim + async await actually fire.
target("e2e_async")
set_kind("binary")
add_files("tests/conform/e2e_async.c")
add_deps("cwinrt")
target("e2e_piid")
set_kind("binary")
add_files("tests/conform/e2e_piid.c")
add_deps("cwinrt")
target("e2e_box")
set_kind("binary")
add_files("tests/conform/e2e_box.c")
add_deps("cwinrt")
target("e2e_async_progress")
set_kind("binary")
add_files("tests/conform/e2e_async_progress.c")
add_deps("cwinrt")
target("test_conform")
set_kind("binary")
add_files("tests/conform/test_conform.c")
add_deps("cwinrt-rt")
add_includedirs("include")
if is_plat("mingw") then
set_enabled(false)
elseif is_plat("windows") then
add_syslinks("runtimeobject", "ole32", "oleaut32", "dcomp")
else
set_enabled(false)
end
target("test_header_compile")
set_kind("binary")
add_files("tests/conform/test_header_compile.c")
add_includedirs("include")
if is_plat("mingw") then
set_enabled(false)
end
target("test_header_compile_smoke")
set_kind("binary")
add_files("tests/conform/header_shards/compile_smoke.c")
add_includedirs("include")
if is_plat("mingw") then
set_enabled(false)
end
target("test_conform_factory")
set_kind("binary")
add_files("tests/conform/test_factory.c")
add_deps("cwinrt-rt")
add_includedirs("include")
if is_plat("mingw") then
set_enabled(false)
elseif is_plat("windows") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
target("test_conform_dispatch")
set_kind("binary")
add_files("tests/conform/test_dispatch.c")
add_deps("cwinrt-rt", "cwinrt-bindings-foundation")
add_links("cwinrt-bindings-foundation")
add_includedirs("include")
if is_plat("mingw") then
set_enabled(false)
elseif is_plat("windows") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
target("test_conform_dispatch_composition_abi")
set_kind("binary")
add_files("tests/conform/test_dispatch_composition_abi.c")
add_deps("cwinrt-rt", "cwinrt-bindings-composition")
add_links("cwinrt-bindings-composition")
add_includedirs("include")
if is_plat("mingw") then
set_enabled(false)
elseif is_plat("windows") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
target("test_conform_dispatch_composition_slots")
set_kind("binary")
add_files("tests/conform/test_dispatch_composition_slots.c")
add_deps("cwinrt-rt", "cwinrt-bindings-composition")
add_links("cwinrt-bindings-composition")
add_includedirs("include")
if is_plat("mingw") then
set_enabled(false)
elseif is_plat("windows") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
target("test_conform_dispatch_compositor")
set_kind("binary")
add_files("tests/conform/test_dispatch_compositor.c")
add_deps("cwinrt-rt", "cwinrt-bindings-composition")
add_links("cwinrt-bindings-composition")
add_includedirs("include")
if is_plat("mingw") then
set_enabled(false)
elseif is_plat("windows") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
add_ldflags("/MANIFEST:EMBED", {force = true})
add_ldflags("/MANIFESTINPUT:" .. path.join(os.projectdir(), "tests/conform/test_compositor.app.manifest"), {force = true})
end
target("test_diag_activate")
set_kind("binary")
add_files("tests/conform/test_diag_activate.c")
add_deps("cwinrt-rt")
add_includedirs("include")
if is_plat("windows") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
else
set_enabled(false)
end
target("test_conform_async")
set_kind("binary")
add_files("tests/conform/test_async.c")
add_deps("cwinrt-rt")
add_includedirs("include")
if is_plat("mingw") then
set_enabled(false)
elseif is_plat("windows") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
end
target("test_conform_type_mapping")
set_kind("binary")
add_files("tests/conform/test_type_mapping.c")
add_includedirs("include")
if is_plat("mingw") then
set_enabled(false)
end
target("test_conform_array_mapping")
set_kind("binary")
add_files("tests/conform/test_array_mapping.c")
add_includedirs("include")
if is_plat("mingw") then
set_enabled(false)
end
target("test_conform_golden")
set_kind("binary")
add_files("tests/conform/golden_guid.c")
add_deps("cwinrt-rt", "cwinrt-bindings-foundation")
add_links("cwinrt-bindings-foundation")
add_includedirs("include")
if is_plat("mingw") then
set_enabled(false)
elseif is_plat("windows") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
else
set_enabled(false)
end
-- Phony targets (xmake 3.x: custom task() is not registered in this project)
-- These are manual developer tasks (codegen / compile reports). set_default(false)
-- keeps them out of a blanket `xmake build`; otherwise, when cwinrt is an included
-- dep, they run during the consumer's build and fail. Their scripts live in
-- cwinrt/scripts, so resolve via os.scriptdir() (this xmake.lua's dir) rather than
-- os.projectdir(), which is the *consuming* project when cwinrt is a sub-include.
target("gen-headers")
set_kind("phony")
set_default(false)
on_build(function()
import("core.project.config")
local plat = config.plat() or "windows"
local arch = config.arch() or "x64"
local mode = config.mode() or "release"
local gen = path.join(os.projectdir(), "build", plat, arch, mode, "cwinrt-gen.exe")
if not os.isfile(gen) then
os.exec("xmake build cwinrt-gen")
end
local script = path.join(os.scriptdir(), "scripts", "gen_all_windows.ps1")
os.exec("powershell -NoProfile -ExecutionPolicy Bypass -File " .. script)
end)
target("gen-all-impl")
set_kind("phony")
set_default(false)
on_build(function()
if not os.isfile(path.join(os.projectdir(), "build", "windows", "x64", "release", "cwinrt-gen.exe")) then
os.exec("xmake build cwinrt-gen")
end
local script = path.join(os.scriptdir(), "scripts", "gen_all_windows.ps1")
os.exec("powershell -NoProfile -ExecutionPolicy Bypass -File " .. script .. " -Impl")
end)
target("verify-bindings")
set_kind("phony")
set_default(false)
on_build(function()
local script = path.join(os.scriptdir(), "scripts", "verify_impl.ps1")
os.exec("powershell -NoProfile -ExecutionPolicy Bypass -File " .. script)
end)
target("header-compile-all")
set_kind("phony")
set_default(false)
on_build(function()
local report = path.join(os.scriptdir(), "scripts", "header_compile_report.ps1")
os.exec("powershell -NoProfile -ExecutionPolicy Bypass -File " .. report)
end)
target("impl-compile-all")
set_kind("phony")
set_default(false)
on_build(function()
local report = path.join(os.scriptdir(), "scripts", "impl_compile_report.ps1")
os.exec("powershell -NoProfile -ExecutionPolicy Bypass -File " .. report)
end)
target("test_impl_link_all")
set_kind("binary")
add_files("tests/conform/test_impl_link_all.c")
add_deps("cwinrt-rt", "cwinrt-bindings-all")
add_links("cwinrt-bindings-all", "cwinrt-rt")
add_includedirs("include")
if is_plat("mingw") then
set_enabled(false)
elseif is_plat("windows") then
add_syslinks("runtimeobject", "ole32", "oleaut32")
else
set_enabled(false)
end
-- Build the link binary as a dependency, NOT via a nested `xmake build`: an
-- os.exec("xmake ...") inside on_build spawns a second xmake that blocks on the
-- parent's project lock while the parent blocks on the child -> deadlock (hangs
-- until CI's job timeout). add_deps builds it in-process, no second xmake.
target("impl-link-all")
set_kind("phony")
set_default(false)
-- test_impl_link_all is disabled on mingw (see above); only depend on it where built.
if not is_plat("mingw") then
add_deps("test_impl_link_all")
end
target("register-conform-sparse")
set_kind("phony")
set_default(false)
on_build(function()
local script = path.join(os.scriptdir(), "scripts", "register_conform_sparse.ps1")
os.exec("powershell -NoProfile -ExecutionPolicy Bypass -File " .. script)
end)
-- Test binaries are deps (built in-process), not nested `xmake build` calls,
-- which would deadlock on the project lock (see impl-link-all). The ps1 checks
-- run after, in on_build.
target("test-conform-mapping")
set_kind("phony")
set_default(false)
-- The mapping-test binaries are disabled on mingw (see above); don't depend on
-- disabled targets there or the build graph reports them as unknown.
if not is_plat("mingw") then
add_deps("test_conform_type_mapping", "test_conform_array_mapping")
end
on_build(function()
local naming = path.join(os.scriptdir(), "scripts", "conform_check_naming.ps1")
local types = path.join(os.scriptdir(), "scripts", "conform_check_types.ps1")
os.exec("powershell -NoProfile -ExecutionPolicy Bypass -File " .. naming)
os.exec("powershell -NoProfile -ExecutionPolicy Bypass -File " .. types)
end)
-- Samples: real demos. Each links via the consumable umbrella (add_deps("cwinrt")
-- inherits headers + runtime + all bindings + the base WinRT link recipe) plus the
-- extra system libs its scenario needs (DWM backdrop, Direct3D for capture).
for _, name in ipairs({"mica", "acrylic", "flyout", "capture"}) do
target("sample_" .. name)
set_kind("binary")
add_files("samples/" .. name .. "/main.c")
add_deps("cwinrt")
if is_plat("windows", "mingw") then
add_syslinks("user32", "dwmapi", "d3d11", "dxgi", "dxguid")
end
end -- samples loop
end -- is_main (tests, samples, dev tasks)