-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.cmake
More file actions
150 lines (134 loc) · 5.14 KB
/
runtime.cmake
File metadata and controls
150 lines (134 loc) · 5.14 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
set(LUAU_BUILD_CLI OFF)
set(LUAU_BUILD_TESTS OFF)
set(LUAU_EXTERN_C ON)
set(LUAU_BUILD_SHARED OFF)
include(FetchContent)
FetchContent_Declare(
luau
GIT_REPOSITORY https://github.com/luau-lang/luau.git
GIT_TAG 0.718
PATCH_COMMAND ${CMAKE_COMMAND} -DPATCH_FILE=${CMAKE_SOURCE_DIR}/vendor/luau.diff -P ${CMAKE_SOURCE_DIR}/vendor/apply_patch.cmake
)
FetchContent_MakeAvailable(luau)
set(LUAU_DIR ${luau_SOURCE_DIR})
# Inject luau git hash
find_package(Git REQUIRED)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${LUAU_DIR}
RESULT_VARIABLE LUAU_GIT_HASH_RESULT
OUTPUT_VARIABLE LUAU_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags
WORKING_DIRECTORY ${LUAU_DIR}
RESULT_VARIABLE LUAU_APPROX_VERSION_RESULT
OUTPUT_VARIABLE LUAU_APPROX_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT LUAU_GIT_HASH_RESULT EQUAL 0)
set(LUAU_GIT_HASH "unknown")
endif()
if(NOT LUAU_APPROX_VERSION_RESULT EQUAL 0)
set(LUAU_APPROX_VERSION "unknown")
endif()
# In shared mode (normal or hybrid), Luau symbols must be dllexported so
# EryxShared can re-export them. In full-embed mode this is unnecessary.
if(ERYX_EMBED AND NOT ERYX_HYBRID)
set(_ERYX_LIB_TYPE STATIC)
set(_ERYX_LINK_VISIBILITY PUBLIC)
target_compile_definitions(Luau.VM PRIVATE "LUAI_FUNC=")
target_compile_definitions(Luau.VM PRIVATE "LUAI_DATA=extern")
# target_compile_definitions(Luau.CodeGen PRIVATE "LUAI_FUNC=extern \"C\"")
else()
set(_ERYX_LIB_TYPE SHARED)
set(_ERYX_LINK_VISIBILITY PRIVATE)
if(WIN32)
target_compile_definitions(Luau.VM PRIVATE "LUA_API=extern \"C\" __declspec(dllexport)")
target_compile_definitions(Luau.VM PRIVATE "LUAI_FUNC=extern \"C\" __declspec(dllexport)")
target_compile_definitions(Luau.CodeGen PRIVATE "LUACODEGEN_API=extern \"C\" __declspec(dllexport)")
target_compile_definitions(Luau.CodeGen PRIVATE "LUAI_FUNC=extern \"C\" __declspec(dllexport)")
target_compile_definitions(uv_a PRIVATE "UV_EXTERN=__declspec(dllexport)")
else()
target_compile_definitions(Luau.VM PRIVATE "LUA_API=extern \"C\" __attribute__((visibility(\"default\")))")
target_compile_definitions(Luau.VM PRIVATE "LUAI_FUNC=extern \"C\" __attribute__((visibility(\"default\")))")
target_compile_definitions(Luau.CodeGen PRIVATE "LUACODEGEN_API=extern \"C\" __attribute__((visibility(\"default\")))")
target_compile_definitions(Luau.CodeGen PRIVATE "LUAI_FUNC=extern \"C\" __attribute__((visibility(\"default\")))")
endif()
endif()
add_library(EryxShared ${_ERYX_LIB_TYPE}
src/runtime/_wrapper_lib.cpp
src/runtime/runtime_host.cpp
src/runtime/lexception.cpp
src/runtime/lconfig.cpp
src/runtime/lrequire.cpp
src/runtime/lresolve.cpp
src/runtime/lprint.cpp
src/runtime/lmarshall.cpp
src/runtime/embedded_registry.cpp
src/vfs.cpp # So lexception can resolve VFS files
)
set_target_properties(EryxShared PROPERTIES CXX_STANDARD 23)
# PUBLIC in static mode so consumers transitively get Luau libs.
# PRIVATE in shared mode (WHOLEARCHIVE re-exports everything).
target_link_libraries(EryxShared ${_ERYX_LINK_VISIBILITY}
Luau.VM
Luau.CodeGen
Luau.Config
Luau.Analysis
Luau.Compiler
Luau.Ast
Luau.Common
uv_a
)
target_include_directories(EryxShared INTERFACE
${LUAU_DIR}/VM/include
${LUAU_DIR}/CodeGen/include
${LUAU_DIR}/Analysis/include
${LUAU_DIR}/Config/include
${LIBUV_DIR}/include
)
# lexception.cpp needs VM-internal headers (lstate.h, ldo.h, etc.)
target_include_directories(EryxShared PRIVATE
${LUAU_DIR}/VM/src
${LUAU_DIR}/Config/include
)
target_compile_definitions(EryxShared PRIVATE
LUAU_GIT_HASH="${LUAU_GIT_HASH}"
LUAU_APPROX_VERSION="${LUAU_APPROX_VERSION}"
)
if(NOT ERYX_EMBED OR ERYX_HYBRID)
# Shared mode (normal or hybrid): re-export all Luau/libuv symbols
if(WIN32)
target_link_options(EryxShared PRIVATE
"/WHOLEARCHIVE:$<TARGET_FILE:Luau.VM>"
"/WHOLEARCHIVE:$<TARGET_FILE:Luau.CodeGen>"
"/WHOLEARCHIVE:$<TARGET_FILE:Luau.Config>"
"/WHOLEARCHIVE:$<TARGET_FILE:Luau.Analysis>"
"/WHOLEARCHIVE:$<TARGET_FILE:uv_a>"
)
set_target_properties(EryxShared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
elseif(APPLE)
target_link_options(EryxShared PRIVATE
"-Wl,-force_load,$<TARGET_FILE:Luau.VM>"
"-Wl,-force_load,$<TARGET_FILE:Luau.CodeGen>"
"-Wl,-force_load,$<TARGET_FILE:Luau.Config>"
"-Wl,-force_load,$<TARGET_FILE:Luau.Analysis>"
"-Wl,-force_load,$<TARGET_FILE:uv_a>"
)
else()
target_link_options(EryxShared PRIVATE
"-Wl,--whole-archive"
"$<TARGET_FILE:Luau.VM>"
"$<TARGET_FILE:Luau.CodeGen>"
"$<TARGET_FILE:Luau.Config>"
"$<TARGET_FILE:Luau.Analysis>"
"$<TARGET_FILE:uv_a>"
"-Wl,--no-whole-archive"
)
endif()
else()
# Full embed: EryxShared is static, compiled with ERYX_EMBED
target_compile_definitions(EryxShared PRIVATE ERYX_EMBED=1)
endif()