Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
466 lines (388 loc) · 20.8 KB
/
Copy pathCMakeLists.txt
File metadata and controls
466 lines (388 loc) · 20.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
# This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
if(EXT_PLATFORM_STRING)
include(EXTLuau.cmake)
return()
endif()
cmake_minimum_required(VERSION 3.10)
option(LUAU_BUILD_CLI "Build CLI" ON)
option(LUAU_BUILD_TESTS "Build tests" ON)
option(LUAU_BUILD_WEB "Build Web module" OFF)
option(LUAU_WERROR "Warnings as errors" OFF)
option(LUAU_STATIC_CRT "Link with the static CRT (/MT)" OFF)
option(LUAU_EXTERN_C "Use extern C for all APIs" OFF)
option(LUAU_BUILD_SHARED "Build as a shared library" OFF)
option(LUAU_TSAN "Build with ThreadSanitizer" OFF)
option(LUAU_SANITIZE "Build with ASAN and UBSAN" OFF)
# Compile time options for Luau features
option(LUAU_VECTOR_DOUBLE "Use 64-bit doubles for vector components" OFF)
option(LUAU_VECTOR_FOUR_WIDE "Enable 4-wide mode for vectors, adding a 'w' component" OFF)
if(LUAU_BUILD_SHARED AND NOT LUAU_EXTERN_C)
message(FATAL_ERROR "LUAU_BUILD_SHARED requires LUAU_EXTERN_C to be ON")
endif()
cmake_policy(SET CMP0054 NEW)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15")
cmake_policy(SET CMP0091 NEW)
endif()
if(LUAU_STATIC_CRT)
cmake_minimum_required(VERSION 3.15)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
project(Luau LANGUAGES CXX C)
if(LUAU_TSAN)
if(MSVC)
message(FATAL_ERROR "LUAU_TSAN requires a Clang or GCC toolchain")
endif()
add_compile_options(-fsanitize=thread)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=thread")
endif()
if(LUAU_SANITIZE)
if(MSVC)
message(FATAL_ERROR "LUAU_SANITIZE requires a Clang or GCC toolchain")
endif()
add_compile_options(-fsanitize=address,undefined -fno-sanitize=vptr -fno-sanitize-recover=all)
add_compile_definitions(LUAU_ENABLE_ASAN=1)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address,undefined")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address,undefined")
endif()
# Embed builtins.txt into a header file at configure time
file(READ "${CMAKE_SOURCE_DIR}/builtins.txt" BUILTINS_HEX HEX)
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1, " BUILTINS_HEX_ARRAY "${BUILTINS_HEX}")
configure_file(
"${CMAKE_SOURCE_DIR}/LSLBuiltins/src/builtins_embedded.h.in"
"${CMAKE_BINARY_DIR}/builtins_embedded.h"
@ONLY
)
if (LUAU_BUILD_SHARED)
add_library(Luau.Common SHARED)
add_library(Luau.CLI.lib SHARED)
add_library(Luau.LSLBuiltins SHARED)
add_library(Luau.Ast SHARED)
add_library(Luau.Bytecode SHARED)
add_library(Luau.Inliner SHARED)
add_library(Luau.Compiler SHARED)
add_library(Luau.Config SHARED)
add_library(Luau.Analysis SHARED)
add_library(Luau.CodeGen SHARED)
add_library(Luau.VM SHARED)
add_library(Luau.Executor SHARED)
add_library(Luau.Require SHARED)
add_library(isocline SHARED)
else()
add_library(Luau.Common STATIC)
add_library(Luau.CLI.lib STATIC)
add_library(Luau.LSLBuiltins STATIC)
add_library(Luau.Ast STATIC)
add_library(Luau.Bytecode STATIC)
add_library(Luau.Inliner STATIC)
add_library(Luau.Compiler STATIC)
add_library(Luau.Config STATIC)
add_library(Luau.Analysis STATIC)
add_library(Luau.CodeGen STATIC)
add_library(Luau.VM STATIC)
add_library(Luau.Executor STATIC)
add_library(Luau.Require STATIC)
add_library(isocline STATIC)
endif()
if(LUAU_BUILD_CLI)
add_executable(Luau.Repl.CLI)
add_executable(Luau.Analyze.CLI)
add_executable(Luau.Ast.CLI)
add_executable(Luau.Reduce.CLI)
add_executable(Luau.Compile.CLI)
add_executable(Luau.Bytecode.CLI)
add_executable(Luau.Harness.CLI)
# This also adds target `name` on Linux/macOS and `name.exe` on Windows
set_target_properties(Luau.Repl.CLI PROPERTIES OUTPUT_NAME slua)
set_target_properties(Luau.Analyze.CLI PROPERTIES OUTPUT_NAME slua-analyze)
set_target_properties(Luau.Ast.CLI PROPERTIES OUTPUT_NAME slua-ast)
set_target_properties(Luau.Reduce.CLI PROPERTIES OUTPUT_NAME slua-reduce)
set_target_properties(Luau.Compile.CLI PROPERTIES OUTPUT_NAME slua-compile)
set_target_properties(Luau.Bytecode.CLI PROPERTIES OUTPUT_NAME slua-bytecode)
set_target_properties(Luau.Harness.CLI PROPERTIES OUTPUT_NAME slua-harness)
endif()
if(LUAU_BUILD_TESTS)
add_executable(Luau.UnitTest)
add_executable(Luau.Conformance)
add_executable(Luau.CLI.Test)
endif()
if(LUAU_BUILD_WEB)
add_executable(Luau.Web)
endif()
# Proxy target to make it possible to depend on private VM headers
add_library(Luau.VM.Internals INTERFACE)
include(Sources.cmake)
target_compile_features(Luau.Common PUBLIC cxx_std_17)
target_include_directories(Luau.Common PUBLIC Common/include)
target_compile_features(Luau.CLI.lib PUBLIC cxx_std_17)
target_include_directories(Luau.CLI.lib PUBLIC CLI/include)
target_link_libraries(Luau.CLI.lib PRIVATE Luau.Common Luau.Config)
target_link_libraries(Luau.CLI.lib PUBLIC Luau.LSLBuiltins)
target_compile_features(Luau.LSLBuiltins PUBLIC cxx_std_17)
target_include_directories(Luau.LSLBuiltins PUBLIC LSLBuiltins/include)
target_include_directories(Luau.LSLBuiltins PRIVATE ${CMAKE_BINARY_DIR}) # For builtins_embedded.h
target_link_libraries(Luau.LSLBuiltins PUBLIC Luau.Common)
# ServerLua: the LSL frontend, needs Luau.LSLBuiltins configured first
add_subdirectory(Tailslide)
target_compile_features(Luau.Ast PUBLIC cxx_std_17)
target_include_directories(Luau.Ast PUBLIC Ast/include)
target_link_libraries(Luau.Ast PUBLIC Luau.Common)
target_compile_features(Luau.Bytecode PUBLIC cxx_std_17)
target_include_directories(Luau.Bytecode PUBLIC Bytecode/include)
target_link_libraries(Luau.Bytecode PUBLIC Luau.Common)
target_compile_features(Luau.Inliner PUBLIC cxx_std_17)
target_include_directories(Luau.Inliner PUBLIC Inliner/include)
target_include_directories(Luau.Inliner PRIVATE Bytecode/src)
target_link_libraries(Luau.Inliner PRIVATE Luau.VM Luau.VM.Internals)
target_link_libraries(Luau.Inliner PUBLIC Luau.Bytecode)
target_compile_features(Luau.Compiler PUBLIC cxx_std_17)
target_include_directories(Luau.Compiler PUBLIC Compiler/include)
# ServerLua: LSLCompiler.h includes tailslide, so it's part of the public interface
target_link_libraries(Luau.Compiler PUBLIC Luau.Ast Luau.Bytecode Luau.LSLBuiltins libtailslide)
target_compile_features(Luau.Config PUBLIC cxx_std_17)
target_include_directories(Luau.Config PUBLIC Config/include)
target_link_libraries(Luau.Config PUBLIC Luau.Ast)
target_link_libraries(Luau.Config PRIVATE Luau.Compiler Luau.VM)
target_compile_features(Luau.Analysis PUBLIC cxx_std_17)
target_include_directories(Luau.Analysis PUBLIC Analysis/include)
target_link_libraries(Luau.Analysis PUBLIC Luau.Ast Luau.Config)
target_link_libraries(Luau.Analysis PRIVATE Luau.Compiler Luau.VM)
target_compile_features(Luau.CodeGen PRIVATE cxx_std_17)
target_include_directories(Luau.CodeGen PUBLIC CodeGen/include)
target_link_libraries(Luau.CodeGen PRIVATE Luau.VM Luau.VM.Internals) # Code generation needs VM internals
target_link_libraries(Luau.CodeGen PUBLIC Luau.Common)
target_compile_features(Luau.VM PRIVATE cxx_std_17)
target_include_directories(Luau.VM PUBLIC VM/include)
target_link_libraries(Luau.VM PUBLIC Luau.Common Luau.LSLBuiltins)
# ServerLua: per-script execution engine shared with the script host
target_compile_features(Luau.Executor PUBLIC cxx_std_17)
target_include_directories(Luau.Executor PUBLIC Executor/include)
target_link_libraries(Luau.Executor PUBLIC Luau.VM Luau.Bytecode Luau.LSLBuiltins)
target_link_libraries(Luau.Executor PRIVATE Luau.VM.Internals)
target_compile_features(Luau.Require PUBLIC cxx_std_17)
target_include_directories(Luau.Require PUBLIC Require/include)
target_link_libraries(Luau.Require PUBLIC Luau.Config Luau.VM)
target_include_directories(isocline PUBLIC extern/isocline/include)
target_include_directories(Luau.VM.Internals INTERFACE VM/src)
set(LUAU_OPTIONS)
if(MSVC)
list(APPEND LUAU_OPTIONS /D_CRT_SECURE_NO_WARNINGS) # We need to use the portable CRT functions.
list(APPEND LUAU_OPTIONS "/we4018") # Signed/unsigned mismatch
list(APPEND LUAU_OPTIONS "/we4388") # Also signed/unsigned mismatch
else()
list(APPEND LUAU_OPTIONS -Wall) # All warnings
list(APPEND LUAU_OPTIONS -Wimplicit-fallthrough)
list(APPEND LUAU_OPTIONS -Wsign-compare) # This looks to be included in -Wall for GCC but not clang
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
list(APPEND LUAU_OPTIONS /MP) # Distribute single project compilation across multiple cores
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Some gcc versions treat var in `if (type var = val)` as unused
# Some gcc versions treat variables used in constexpr if blocks as unused
list(APPEND LUAU_OPTIONS -Wno-unused)
# some gcc versions warn maybe uninitialized on optional<string> members on structs
list(APPEND LUAU_OPTIONS -Wno-maybe-uninitialized)
endif()
# Enabled in CI; we should be warning free on our main compiler versions but don't guarantee being warning free everywhere
if(LUAU_WERROR)
if(MSVC)
list(APPEND LUAU_OPTIONS /WX) # Warnings are errors
else()
list(APPEND LUAU_OPTIONS -Werror) # Warnings are errors
endif()
endif()
if(LUAU_BUILD_WEB)
# add -fexceptions for emscripten to allow exceptions to be caught in C++
list(APPEND LUAU_OPTIONS -fexceptions)
endif()
set(ISOCLINE_OPTIONS)
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
list(APPEND ISOCLINE_OPTIONS -Wno-unused-function)
endif()
target_compile_options(Luau.Ast PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.Analysis PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.CLI.lib PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.LSLBuiltins PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.CodeGen PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.VM PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.Executor PRIVATE ${LUAU_OPTIONS})
target_compile_options(isocline PRIVATE ${LUAU_OPTIONS} ${ISOCLINE_OPTIONS})
if(LUAU_EXTERN_C)
# enable extern "C" for VM (lua.h, lualib.h) and Compiler (luacode.h) to make Luau friendlier to use from non-C++ languages
# note that we enable LUA_USE_LONGJMP=1 as well; otherwise functions like luaL_error will throw C++ exceptions, which can't be done from extern "C" functions
target_compile_definitions(Luau.VM PUBLIC LUA_USE_LONGJMP=1)
if(LUAU_BUILD_SHARED)
if(MSVC)
target_compile_definitions(Luau.VM PUBLIC "LUA_API=extern \"C\" __declspec(dllexport)")
target_compile_definitions(Luau.Compiler PUBLIC "LUACODE_API=extern \"C\" __declspec(dllexport)")
target_compile_definitions(Luau.CodeGen PUBLIC "LUACODEGEN_API=extern \"C\" __declspec(dllexport)")
else()
# GCC/Clang
target_compile_definitions(Luau.VM PUBLIC "LUA_API=extern \"C\" __attribute__((visibility(\"default\")))")
target_compile_definitions(Luau.Compiler PUBLIC "LUACODE_API=extern \"C\" __attribute__((visibility(\"default\")))")
target_compile_definitions(Luau.CodeGen PUBLIC "LUACODEGEN_API=extern \"C\" __attribute__((visibility(\"default\")))")
endif()
else()
# For static builds (or if not exporting) just use extern "C"
target_compile_definitions(Luau.VM PUBLIC "LUA_API=extern \"C\"")
target_compile_definitions(Luau.Compiler PUBLIC "LUACODE_API=extern \"C\"")
target_compile_definitions(Luau.CodeGen PUBLIC "LUACODEGEN_API=extern \"C\"")
endif()
endif()
if(LUAU_VECTOR_DOUBLE)
target_compile_definitions(Luau.VM PUBLIC "LUA_VECTOR_DOUBLE=1")
endif()
if(LUAU_VECTOR_FOUR_WIDE)
target_compile_definitions(Luau.VM PUBLIC "LUA_VECTOR_SIZE=4")
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER_EQUAL 1924)
# disable partial redundancy elimination which regresses interpreter codegen substantially in VS2022:
# https://developercommunity.visualstudio.com/t/performance-regression-on-a-complex-interpreter-lo/1631863
set_source_files_properties(VM/src/lvmexecute.cpp PROPERTIES COMPILE_FLAGS /d2ssa-pre-)
endif()
if (NOT MSVC)
# disable support for math_errno which allows compilers to lower sqrt() into a single CPU instruction
target_compile_options(Luau.VM PRIVATE -fno-math-errno)
endif()
if(MSVC AND LUAU_BUILD_CLI)
# the default stack size that MSVC linker uses is 1 MB; we need more stack space in Debug because stack frames are larger
set_target_properties(Luau.Analyze.CLI PROPERTIES LINK_FLAGS_DEBUG /STACK:2097152)
set_target_properties(Luau.Repl.CLI PROPERTIES LINK_FLAGS_DEBUG /STACK:2097152)
endif()
if(MSVC AND LUAU_BUILD_TESTS)
# the default stack size that MSVC linker uses is 1 MB; we need more stack space in Debug because stack frames are larger
set_target_properties(Luau.CLI.Test PROPERTIES LINK_FLAGS_DEBUG /STACK:2097152)
set_target_properties(Luau.Conformance PROPERTIES LINK_FLAGS_DEBUG /STACK:2097152)
set_target_properties(Luau.UnitTest PROPERTIES LINK_FLAGS_DEBUG /STACK:2097152)
set_target_properties(Luau.CLI.Test PROPERTIES LINK_FLAGS_OPTIMIZED /STACK:2097152)
set_target_properties(Luau.Conformance PROPERTIES LINK_FLAGS_OPTIMIZED /STACK:2097152)
endif()
# embed .natvis inside the library debug information
if(MSVC)
target_link_options(Luau.Ast INTERFACE /NATVIS:${CMAKE_CURRENT_SOURCE_DIR}/tools/natvis/Ast.natvis)
target_link_options(Luau.Analysis INTERFACE /NATVIS:${CMAKE_CURRENT_SOURCE_DIR}/tools/natvis/Analysis.natvis)
target_link_options(Luau.CodeGen INTERFACE /NATVIS:${CMAKE_CURRENT_SOURCE_DIR}/tools/natvis/CodeGen.natvis)
target_link_options(Luau.VM INTERFACE /NATVIS:${CMAKE_CURRENT_SOURCE_DIR}/tools/natvis/VM.natvis)
endif()
# make .natvis visible inside the solution
if(MSVC_IDE)
target_sources(Luau.Ast PRIVATE tools/natvis/Ast.natvis)
target_sources(Luau.Analysis PRIVATE tools/natvis/Analysis.natvis)
target_sources(Luau.CodeGen PRIVATE tools/natvis/CodeGen.natvis)
target_sources(Luau.VM PRIVATE tools/natvis/VM.natvis)
endif()
# ServerLua: GCC doesn't support the FP_CONTRACT pragma, so we have to use this to tell it it not to
# fuse multiply and add for these files.
set(FP_SENSITIVE_SOURCE_FILES
${CMAKE_SOURCE_DIR}/VM/src/lll.cpp
${CMAKE_SOURCE_DIR}/VM/src/llsl.cpp
)
set_source_files_properties(${FP_SENSITIVE_SOURCE_FILES} PROPERTIES COMPILE_FLAGS "-ffp-contract=off")
# On Windows and Android threads are provided, on Linux/Mac/iOS we use pthreads
add_library(osthreads INTERFACE)
if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin|iOS")
target_link_libraries(osthreads INTERFACE "-lpthread")
endif ()
# ServerLua: We use threads internally, library consumers need pthreads if applicable.
target_link_libraries(Luau.Executor PUBLIC osthreads)
# ServerLua: POSIX timers live in librt on glibc < 2.34, a stub elsewhere
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(Luau.Executor PUBLIC "-lrt")
endif ()
if(LUAU_BUILD_CLI)
target_compile_options(Luau.Repl.CLI PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.Reduce.CLI PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.Analyze.CLI PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.Ast.CLI PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.Compile.CLI PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.Bytecode.CLI PRIVATE ${LUAU_OPTIONS})
target_compile_options(Luau.Harness.CLI PRIVATE ${LUAU_OPTIONS})
target_include_directories(Luau.Repl.CLI PRIVATE extern extern/isocline/include)
target_link_libraries(Luau.Repl.CLI PRIVATE Luau.Compiler Luau.Inliner Luau.Config Luau.CodeGen Luau.VM Luau.Require Luau.CLI.lib isocline)
target_link_libraries(Luau.Repl.CLI PRIVATE osthreads)
target_link_libraries(Luau.Reduce.CLI PRIVATE osthreads)
target_link_libraries(Luau.Analyze.CLI PRIVATE osthreads)
target_link_libraries(Luau.Ast.CLI PRIVATE osthreads)
target_link_libraries(Luau.Compile.CLI PRIVATE osthreads)
target_link_libraries(Luau.Bytecode.CLI PRIVATE osthreads)
target_link_libraries(Luau.Harness.CLI PRIVATE osthreads)
target_link_libraries(Luau.Analyze.CLI PRIVATE Luau.Analysis Luau.CLI.lib Luau.Require)
target_link_libraries(Luau.Ast.CLI PRIVATE Luau.Ast Luau.Analysis Luau.CLI.lib)
target_compile_features(Luau.Reduce.CLI PRIVATE cxx_std_17)
target_include_directories(Luau.Reduce.CLI PUBLIC Reduce/include)
target_link_libraries(Luau.Reduce.CLI PRIVATE Luau.Common Luau.Ast Luau.Analysis Luau.CLI.lib)
target_link_libraries(Luau.Compile.CLI PRIVATE Luau.Compiler Luau.VM Luau.CodeGen Luau.CLI.lib)
target_link_libraries(Luau.Bytecode.CLI PRIVATE Luau.Compiler Luau.VM Luau.CodeGen Luau.CLI.lib)
target_link_libraries(Luau.Harness.CLI PRIVATE Luau.Compiler Luau.VM Luau.Executor Luau.LSLBuiltins Luau.CLI.lib)
endif()
if(LUAU_BUILD_TESTS)
target_compile_options(Luau.UnitTest PRIVATE ${LUAU_OPTIONS})
target_compile_definitions(Luau.UnitTest PRIVATE DOCTEST_CONFIG_DOUBLE_STRINGIFY DOCTEST_CONFIG_USE_STD_HEADERS)
# ServerLua: tailslide's tests use bare includes rooted at Tailslide/tailslide
target_include_directories(Luau.UnitTest PRIVATE extern Tailslide/tailslide)
target_link_libraries(Luau.UnitTest PRIVATE Luau.Analysis Luau.Bytecode Luau.Compiler Luau.CodeGen)
target_compile_options(Luau.Conformance PRIVATE ${LUAU_OPTIONS})
target_compile_definitions(Luau.Conformance PRIVATE DOCTEST_CONFIG_DOUBLE_STRINGIFY DOCTEST_CONFIG_USE_STD_HEADERS)
target_include_directories(Luau.Conformance PRIVATE extern VM/src)
target_link_libraries(Luau.Conformance PRIVATE Luau.Analysis Luau.Bytecode Luau.Inliner Luau.Compiler Luau.CodeGen Luau.VM Luau.Executor Luau.LSLBuiltins Luau.CLI.lib)
if(CMAKE_SYSTEM_NAME MATCHES "Android|iOS")
set(LUAU_CONFORMANCE_SOURCE_DIR "Client/Luau/tests/conformance")
else ()
# ServerLua: Use this form since the newer file() command needs CMake>=3.19.0
get_filename_component(LUAU_CONFORMANCE_SOURCE_DIR "tests/conformance" REALPATH)
endif ()
target_compile_definitions(Luau.Conformance PRIVATE LUAU_CONFORMANCE_SOURCE_DIR="${LUAU_CONFORMANCE_SOURCE_DIR}")
target_compile_options(Luau.CLI.Test PRIVATE ${LUAU_OPTIONS})
target_compile_definitions(Luau.CLI.Test PRIVATE DOCTEST_CONFIG_USE_STD_HEADERS)
target_include_directories(Luau.CLI.Test PRIVATE extern CLI)
target_link_libraries(Luau.CLI.Test PRIVATE Luau.Compiler Luau.Inliner Luau.Config Luau.CodeGen Luau.VM Luau.Require Luau.CLI.lib isocline)
target_link_libraries(Luau.CLI.Test PRIVATE osthreads)
add_subdirectory(fuzz)
endif()
if(LUAU_BUILD_CLI AND LUAU_BUILD_TESTS)
if(CMAKE_VERSION VERSION_LESS 3.12)
find_package(PythonInterp 3 REQUIRED)
set(LUAU_PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE}")
else()
find_package(Python3 COMPONENTS Interpreter REQUIRED)
set(LUAU_PYTHON_EXECUTABLE "${Python3_EXECUTABLE}")
endif()
add_custom_target(Luau.GoldenTest
COMMAND ${LUAU_PYTHON_EXECUTABLE} -m tools.golden.selftest
--luau "$<TARGET_FILE:Luau.Repl.CLI>"
--luau-analyze "$<TARGET_FILE:Luau.Analyze.CLI>"
COMMAND ${LUAU_PYTHON_EXECUTABLE} -m tools.golden
--luau "$<TARGET_FILE:Luau.Repl.CLI>"
--luau-analyze "$<TARGET_FILE:Luau.Analyze.CLI>"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
USES_TERMINAL
VERBATIM
)
add_dependencies(Luau.GoldenTest Luau.Repl.CLI Luau.Analyze.CLI)
endif()
if(LUAU_BUILD_WEB)
target_compile_options(Luau.Web PRIVATE ${LUAU_OPTIONS})
target_link_libraries(Luau.Web PRIVATE Luau.Compiler Luau.VM Luau.Analysis Luau.CLI.lib)
# declare exported functions to emscripten
target_link_options(Luau.Web PRIVATE -sEXPORTED_FUNCTIONS=["_executeScript","_checkScript"] -sEXPORTED_RUNTIME_METHODS=["ccall","cwrap"])
# add -fexceptions for emscripten to allow exceptions to be caught in C++
target_link_options(Luau.Web PRIVATE -fexceptions)
# the output is a single .js file with an embedded wasm blob
target_link_options(Luau.Web PRIVATE -sSINGLE_FILE=1)
endif()
# validate dependencies for internal libraries
foreach(LIB Luau.Ast Luau.Compiler Luau.Config Luau.Analysis Luau.CodeGen Luau.VM)
if(TARGET ${LIB})
get_target_property(DEPENDS ${LIB} LINK_LIBRARIES)
if(LIB MATCHES "CodeGen|VM" AND DEPENDS MATCHES "Ast|Analysis|Config|Compiler")
message(FATAL_ERROR ${LIB} " is a runtime component but it depends on one of the offline components")
endif()
if(LIB MATCHES "Ast|Compiler" AND DEPENDS MATCHES "CodeGen|VM")
message(FATAL_ERROR ${LIB} " is an offline component but it depends on one of the runtime components")
endif()
if(LIB MATCHES "Ast|Compiler" AND DEPENDS MATCHES "Analysis|Config")
message(FATAL_ERROR ${LIB} " is a compiler component but it depends on one of the analysis components")
endif()
endif()
endforeach()