-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmake.lua
More file actions
169 lines (152 loc) · 5.76 KB
/
xmake.lua
File metadata and controls
169 lines (152 loc) · 5.76 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
set_project("xent-core")
set_version("0.1.0")
set_languages("c11")
add_rules("mode.debug", "mode.release")
set_warnings("all")
local unit_tests = {
"test_tree",
"test_layout_flex",
"test_layout_flex_spec",
"test_layout_swiftstack",
"test_layout_swiftstack_spec",
"test_direction",
"test_layout_rounding",
"test_layout_stress",
"test_dirty",
"test_text_cache",
"test_text_backend_contract",
"test_text_linebreak_policy",
"test_text_shaping",
"test_mixed_protocols",
"test_rtl_baseline_conformance",
"test_layout_grid",
"test_layout_grid_spec",
"test_yoga_generated",
"test_cli",
"test_profile",
}
option("simd")
set_default(false)
set_description("Enable experimental SIMD path scaffolding")
option_end()
option("ispc")
set_default(false)
set_showmenu(true)
set_description("Enable ISPC SIMD backend when available")
option_end()
target("xent_core")
set_kind("static")
add_includedirs("include", { public = true })
add_headerfiles("include/xent/*.h")
add_files("src/core/*.c", "src/layout/*.c", "src/text/*.c", "src/cli/*.c", "src/plugins/*.c")
if is_plat("mingw") then
add_cflags("-ffunction-sections", "-fdata-sections", { force = true })
end
if is_plat("windows") then
add_cflags("/Gy", "/Gw", { tools = "cl", force = true })
end
if has_config("simd") then
add_defines("XENT_ENABLE_SIMD=1", { public = true })
else
add_defines("XENT_ENABLE_SIMD=0", { public = true })
end
if has_config("ispc") then
add_defines("XENT_ISPC_ENABLED=1", { public = true })
-- Register the generated-header include directory at load time so
-- every C source that #includes the ISPC header can find it.
on_load( function (target)
local headerdir = path.join(target:autogendir(), "rules", "ispc")
target:add("includedirs", headerdir)
end)
-- Compile every .ispc file *before* any C file is compiled.
-- This guarantees the generated _ispc.h header already exists when
-- xent_simd.c is built. Multi-target builds (e.g. sse4 + avx2)
-- produce per-ISA object files that are all added to the link.
before_build( function (target)
import("lib.detect.find_program")
local ispc_bin = find_program("ispc")
assert(ispc_bin, "ispc compiler not found on PATH – install via `scoop install ispc`")
local headerdir = path.join(target:autogendir(), "rules", "ispc")
local objdir = path.join(target:autogendir(), "rules", "ispc", "objs")
os.mkdir(headerdir)
os.mkdir(objdir)
local ispc_targets = { "sse4", "avx2" }
local targets_str = table.concat(ispc_targets, ",")
local sources = os.files(path.join(os.scriptdir(), "src/simd/*.ispc"))
for _, sourcefile in ipairs(sources) do
local basename = path.basename(sourcefile)
local objectfile = path.join(objdir, basename .. ".obj")
local headerfile = path.join(headerdir, basename .. "_ispc.h")
-- Incremental: skip when source has not changed.
local src_mtime = os.mtime(sourcefile)
local obj_mtime = os.mtime(objectfile)
if src_mtime > obj_mtime then
local argv = {
sourcefile,
"-o", objectfile,
"-h", headerfile,
"--target=" .. targets_str,
"--arch=x86-64",
"--opt=fast-math",
}
if is_mode("debug") then
table.insert(argv, "-g")
end
os.vrunv(ispc_bin, argv)
end
end
end)
-- After the normal archive is produced, append the ISPC object files
-- into the static library so consumers link them transparently.
after_build( function (target)
local objdir = path.join(target:autogendir(), "rules", "ispc", "objs")
local objs = os.files(path.join(objdir, "*.obj"))
if #objs > 0 then
local ar = target:tool("ar")
os.vrunv(ar, table.join({ "rcs", target:targetfile() }, objs))
end
end)
else
add_defines("XENT_ISPC_ENABLED=0", { public = true })
end
for _, demo in ipairs({ "demo_basic", "demo_flex_vs_swiftstack", "demo_dump_json" }) do
target(demo)
set_kind("binary")
add_files("examples/" .. demo .. ".c")
add_deps("xent_core")
add_includedirs("include")
end
for _, bench_name in ipairs({ "bench_layout", "bench_simd", "bench_compare_recursive_baseline", "bench_dirty_vs_full", "bench_regression_gates" }) do
target(bench_name)
set_kind("binary")
add_files("bench/" .. bench_name .. ".c")
add_deps("xent_core")
add_includedirs("include")
end
target("bench_yoga_native")
set_kind("binary")
add_files("bench/yoga/bench_yoga_native.c")
add_deps("xent_core")
add_includedirs("include")
for _, test_name in ipairs(unit_tests) do
target(test_name)
set_kind("binary")
if test_name == "test_yoga_generated" then
add_files("tests/yoga/test_yoga_generated.c")
else
add_files("tests/" .. test_name .. ".c")
end
add_deps("xent_core")
add_includedirs("include", "tests")
end
task("test")
set_menu {
usage = "xmake test",
description = "Build and run all unit tests.",
}
on_run( function ()
for _, t in ipairs(unit_tests) do
os.exec("xmake build " .. t)
os.exec("xmake run " .. t)
end
end)