-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathya.py
More file actions
350 lines (324 loc) · 11 KB
/
ya.py
File metadata and controls
350 lines (324 loc) · 11 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
import platform
import os
project("yui",
version='0.0.1',
desc='yui is an gui for ai mean agui, project page: https://github.com/evilbinary/yui',
targets=[
'yui',
'test_blur_cache',
'test_content_size',
'test_text_render',
'test_text_simple'
]
)
# 判断是否为指定平台
def is_plat(plat_name):
plat = get_plat()
return plat == plat_name
prefix_env=''
if platform.system()=='Windows':
prefix_env=''
elif platform.system()=='Darwin':
os.environ['DYLD_FRAMEWORK_PATH'] = '../libs'
os.environ['DYLD_LIBRARY_PATH'] = '../libs'
elif platform.system()=='Linux':
# 设置环境变量,不通过shell方式
os.environ['LD_LIBRARY_PATH'] = '../libs'
elif is_plat("stm32"):
# STM32平台不需要设置环境变量
prefix_env=''
def add_flags():
checkmem=True
if platform.system()=='Windows':
checkmem=False
if checkmem and not is_plat("stm32"):
tool=get_toolchain_node()
tool['ld']='gcc'
add_cflags(
'-fsanitize=address',
)
add_ldflags(
'-fsanitize=address',
)
if get_plat() in['emscripten','em']:
set_toolchain('emscripten')
tool=get_toolchain_node()
tool['cc']='emcc'
tool['cxx']='emcc'
tool['ld']='emcc'
tool['ar']='emar'
if platform.system()=='Windows':
mingw64='E:\\soft\\msys2\\mingw64'
add_cflags(
# '--use-port=sdl2 ',
'-g',
'-Wno-incompatible-pointer-types -Wno-implicit-function-declaration',
'-F../libs/',
'-I'+mingw64+'\\include\\SDL2',
'-I.',
'-I./src/components',
'-I./src/'
)
add_ldflags(
'-s USE_SDL=2',
'-s USE_SDL_IMAGE=2',
'-s USE_SDL_TTF=2',
'-s ALLOW_MEMORY_GROWTH=1',
'-s ASSERTIONS=1',
#'-s EXPORTED_FUNCTIONS=["_main"]',
#'-s EXPORTED_RUNTIME_METHODS=["ccall","cwrap","FS","stringToUTF8","UTF8ToString"]',
'-s EXPORT_ALL=1 ',
'-s ASSERTIONS=2 ',
'-s STACK_OVERFLOW_CHECK=2',
'-g4',
'-O0',
'-Wbad-function-cast ',
'-Wcast-function-type',
'--source-map-base http://localhost:6931/',
'-s ERROR_ON_UNDEFINED_SYMBOLS=0',
'-s AGGRESSIVE_VARIABLE_ELIMINATION=1',
'--preload-file app/playground/',
'--preload-file app/assets/',
'--preload-file app/lib/',
'--preload-file app',
'-L'+mingw64+'\\lib',
'-lSDL2main',
'-lSDL2',
'-lSDL2_ttf',
'-lSDL2_image',
'-lm'
)
else:
mingw64='../libs/'
add_cflags(
# '--use-port=sdl2 ',
'-g',
'-gsource-map',
'-Wno-incompatible-pointer-types -Wno-implicit-function-declaration',
'-F../libs/',
'-I'+mingw64+'\\include\\SDL2',
'-I.',
'-I./src/components',
'-I./src/',
'-s USE_SDL=2',
'-s USE_SDL_IMAGE=2',
'-s USE_SDL_TTF=2',
)
add_ldflags(
'-gsource-map',
'-s USE_SDL=2',
'-s USE_SDL_IMAGE=2',
'-s USE_SDL_TTF=2',
'-s ALLOW_MEMORY_GROWTH=1',
'-s ASSERTIONS=1',
#'-s EXPORTED_FUNCTIONS=["_main"]',
#'-s EXPORTED_RUNTIME_METHODS=["ccall","cwrap","FS","stringToUTF8","UTF8ToString"]',
'-s EXPORT_ALL=1 ',
'-s ASSERTIONS=2 ',
'-s STACK_OVERFLOW_CHECK=2',
'-g4',
'-O0',
'-Wbad-function-cast ',
'-Wcast-function-type',
# '--source-map-base http://localhost:6931/',
'-s ERROR_ON_UNDEFINED_SYMBOLS=0',
'-s AGGRESSIVE_VARIABLE_ELIMINATION=1',
'--preload-file app/playground/',
'--preload-file app/assets/',
'--preload-file app/lib/',
'--preload-file app',
# '-s USE_WEBGL2=1', # 启用 WebGL2 支持(现代浏览器兼容性更好)
# '-s FULL_ES2=1', # 启用完整的 OpenGL ES 3 特性
# '-s MIN_WEBGL_VERSION=2', # 要求 WebGL 最低版本为 2
'-s ASSERTIONS=2', # 启用运行时断言,便于调试
# '-s GL_ASSERTIONS=1', # 启用 GL 断言,捕捉 WebGL 错误
'-L'+mingw64+'\\lib',
'-lSDL2',
'-lSDL2_ttf',
'-lSDL2_image',
'-lm'
)
elif is_plat("stm32"):
# STM32平台特定的编译选项
add_cflags(
'-g',
'-mcpu=cortex-m7',
'-mthumb',
'-mfpu=fpv5-d16',
'-mfloat-abi=hard',
'-DSTM32F7xx',
'-DUSE_HAL_DRIVER',
'-Isrc',
'-Ilib',
'-IInc', # STM32 HAL头文件
'-I../Drivers/STM32F7xx_HAL_Driver/Inc',
'-I../Drivers/STM32F7xx_HAL_Driver/Inc/Legacy',
'-I../Drivers/CMSIS/Device/ST/STM32F7xx/Include',
'-I../Drivers/CMSIS/Include',
'-I../Middlewares/Third_Party/FreeRTOS/Source/include',
'-I../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS',
'-I../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM7/r0p1'
),
add_ldflags(
'-mcpu=cortex-m7',
'-mthumb',
'-mfpu=fpv5-d16',
'-mfloat-abi=hard',
'-specs=nano.specs',
'-TSTM32F746NGHx_FLASH.ld',
'-Wl,--gc-sections',
'-static',
'--specs=nosys.specs',
'-specs=nano.specs',
'-Wl,--start-group',
'-lc',
'-lm',
'-lstdc++',
'-lsupc++',
'-Wl,--end-group'
),
elif platform.system()=='Darwin':
add_cflags(
'-g',
'-F../libs/',
'-I../libs/SDL2.framework/Headers',
'-I../libs/SDL2_ttf.framework/Headers',
'-I../libs/SDL2_image.framework/Headers',
'-Isrc',
'-Ilib',
'-Ilib/mquickjs',
'-DHAS_JS_MODULE'
),
add_ldflags(
'-F../libs/',
'-framework SDL2',
'-framework SDL2_ttf',
'-framework SDL2_image ',
'-F../libs/'
),
elif platform.system()=='Linux':
add_cflags(
'-g',
'-F../libs/',
'-I../libs/SDL2.framework/Headers',
'-I../libs/SDL2_ttf.framework/Headers',
'-I../libs/SDL2_image.framework/Headers',
'-Isrc'
)
add_ldflags(
'-F../libs/',
'-framework SDL2',
'-framework SDL2_ttf',
'-framework SDL2_image ',
'-F../libs/'
)
elif platform.system()=='Windows':
mingw64='E:\\soft\\msys2\\mingw64'
if get_plat() in['emscripten','em']:
tool=get_toolchain_node()
tool['cc']='emcc'
tool['cxx']='emcc'
tool['ld']='emcc'
tool['ar']='emar'
add_cflags(
# '--use-port=sdl2 ',
'-g',
'-Wno-incompatible-pointer-types -Wno-implicit-function-declaration',
'-F../libs/',
'-I'+mingw64+'\\include\\SDL2',
'-I.',
'-I./src/components',
'-I./src/'
)
add_ldflags(
'-s USE_SDL=2',
'-s USE_SDL_IMAGE=2',
'-s USE_SDL_TTF=2',
'-s ALLOW_MEMORY_GROWTH=1',
'-s ASSERTIONS=1',
#'-s EXPORTED_FUNCTIONS=["_main"]',
#'-s EXPORTED_RUNTIME_METHODS=["ccall","cwrap","FS","stringToUTF8","UTF8ToString"]',
'-s EXPORT_ALL=1 ',
'-s ASSERTIONS=2 ',
'-s STACK_OVERFLOW_CHECK=2',
'-g4',
'-O0',
'-Wbad-function-cast ',
'-Wcast-function-type',
# '--source-map-base http://localhost:6931/',
'-s ERROR_ON_UNDEFINED_SYMBOLS=0',
'-s AGGRESSIVE_VARIABLE_ELIMINATION=1',
'--preload-file app/playground/',
'--preload-file app/assets/',
'--preload-file app/lib/',
'--preload-file app',
'-L'+mingw64+'\\lib',
'-lSDL2main',
'-lSDL2',
'-lSDL2_ttf',
'-lSDL2_image',
'-lm'
)
else:
tool=get_toolchain_node()
tool['cc']=mingw64+'\\bin\\gcc.exe'
tool['cxx']=mingw64+'\\bin\\g++.exe'
tool['ld']=mingw64+'\\bin\\gcc.exe'
tool['ar']=mingw64+'\\bin\\ar.exe'
add_cflags(
'-g',
'-Wno-incompatible-pointer-types -Wno-implicit-function-declaration',
'-F../libs/',
'-I'+mingw64+'\\include\\SDL2',
'-I.',
'-I./src/components',
'-I./src/'
)
add_ldflags(
'-L'+mingw64+'\\lib',
'-lSDL2main',
'-lSDL2',
'-lSDL2_ttf',
'-lSDL2_image',
'-lm',
'-lws2_32'
)
def run(target):
targetfile = target.targetfile()
sourcefiles = target.sourcefiles()
arch=target.get_arch()
arch_type= target.get_arch_type()
mode =target.get_config('mode')
plat=target.plat()
if platform.system()=='Windows':
yui=targetfile.replace('/','\\')
os.system(yui)
elif is_plat("stm32"):
# STM32平台通过调试器运行
print("STM32 target, run through debugger (e.g., ST-Link)")
print("Binary file:", targetfile)
# 这里可以添加通过ST-Link或其他调试器运行的代码
else:
# 直接使用 Python 的 subprocess 来运行,确保环境变量正确传递
import subprocess
cmd = ["./" + targetfile]
# 复制当前环境变量并确保关键变量存在
env = os.environ.copy()
if platform.system()=='Darwin':
env['DYLD_FRAMEWORK_PATH'] = '../libs'
env['DYLD_LIBRARY_PATH'] = '../libs'
elif platform.system()=='Linux':
env['LD_LIBRARY_PATH'] = '../libs'
print('run', ' '.join(cmd))
subprocess.run(cmd, env=env)
def add_run():
on_run(run)
def get_prefix():
return prefix_env
add_buildin('add_flags',add_flags)
add_buildin('add_run',add_run)
add_buildin('get_prefix',get_prefix)
includes("./src/ya.py")
includes("./lib/ya.py")
includes("./app/ya.py")
includes("./tests/ya.py")