Skip to content

Commit 2f9f015

Browse files
committed
[unity]直接把backend-quickjs源码编译进plugin
1 parent 06fc16c commit 2f9f015

37 files changed

+82618
-17
lines changed

unity/cli/backends.json

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,72 +8,56 @@
88
"WITHOUT_INSPECTOR"
99
],
1010
"include": [
11-
"/Inc"
1211
],
1312
"link-libraries": {
1413
"win": {
1514
"ia32": [
16-
"/Lib/Win32/quickjs.dll.lib"
1715
],
1816
"x64": [
19-
"/Lib/Win64/quickjs.dll.lib"
2017
]
2118
},
2219
"osx": {
2320
"x64": [
24-
"/Lib/macOS/libquickjs.a"
2521
],
2622
"arm64": [
27-
"/Lib/macOS_arm64/libquickjs.a"
2823
]
2924
},
3025
"android": {
3126
"armv7": [
32-
"/Lib/Android/armeabi-v7a/libquickjs.a"
3327
],
3428
"arm64": [
35-
"/Lib/Android/arm64-v8a/libquickjs.a"
3629
],
3730
"x64": [
38-
"/Lib/Android/x86_64/libquickjs.a"
3931
]
4032
},
4133
"ohos": {
4234
"armv7": [
43-
"/Lib/OHOS/armeabi-v7a/libquickjs.a"
4435
],
4536
"arm64": [
46-
"/Lib/OHOS/arm64-v8a/libquickjs.a"
4737
]
4838
},
4939
"linux": {
5040
"x64": [
51-
"/Lib/Linux/libquickjs.a"
5241
]
5342
},
5443
"ns":{
5544
"arm64": [
56-
"/Lib/ns/arm64-v8a/libquickjs.a"
5745
]
5846
}
5947
},
6048
"copy-libraries": {
6149
"win": {
6250
"ia32": [
63-
"/Lib/Win32/*.dll"
6451
],
6552
"x64": [
66-
"/Lib/Win64/*.dll"
6753
]
6854
},
6955
"ios": {
7056
"arm64": [
71-
"/Lib/iOS/arm64/libquickjs.a"
7257
]
7358
},
7459
"wasm": {
7560
"wasm32": [
76-
"/Lib/wasm/wasm32/libquickjs.a"
7761
]
7862
}
7963
}

unity/native_src/CMakeLists.txt

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
cmake_minimum_required(VERSION 3.15)
88
cmake_policy(SET CMP0091 NEW)
99

10-
project(PuertsPlugin)
10+
project(PuertsPlugin LANGUAGES C CXX)
11+
12+
include(CheckCCompilerFlag)
1113

1214
if("${JS_ENGINE}" MATCHES "^v8_10.6.194")
1315
set(CMAKE_CXX_STANDARD 17)
@@ -109,6 +111,104 @@ else ()
109111
)
110112
endif()
111113

114+
if("${JS_ENGINE}" STREQUAL "quickjs")
115+
set(CMAKE_C_STANDARD_REQUIRED ON)
116+
set(CMAKE_C_EXTENSIONS ON)
117+
set(CMAKE_C_STANDARD 11)
118+
119+
macro(xcheck_add_c_compiler_flag FLAG)
120+
string(REPLACE "-" "" FLAG_NO_HYPHEN ${FLAG})
121+
check_c_compiler_flag(${FLAG} COMPILER_SUPPORTS_${FLAG_NO_HYPHEN})
122+
if(COMPILER_SUPPORTS_${FLAG_NO_HYPHEN})
123+
add_compile_options(${FLAG})
124+
endif()
125+
endmacro()
126+
127+
xcheck_add_c_compiler_flag(-Wno-implicit-fallthrough)
128+
xcheck_add_c_compiler_flag(-Wno-sign-compare)
129+
xcheck_add_c_compiler_flag(-Wno-missing-field-initializers)
130+
xcheck_add_c_compiler_flag(-Wno-unused-parameter)
131+
xcheck_add_c_compiler_flag(-Wno-unused-but-set-variable)
132+
xcheck_add_c_compiler_flag(-Wno-array-bounds)
133+
xcheck_add_c_compiler_flag(-Wno-format-truncation)
134+
xcheck_add_c_compiler_flag(-funsigned-char)
135+
136+
# ClangCL is command line compatible with MSVC, so 'MSVC' is set.
137+
if(MSVC)
138+
xcheck_add_c_compiler_flag(-Wno-unsafe-buffer-usage)
139+
xcheck_add_c_compiler_flag(-Wno-sign-conversion)
140+
xcheck_add_c_compiler_flag(-Wno-nonportable-system-include-path)
141+
xcheck_add_c_compiler_flag(-Wno-implicit-int-conversion)
142+
xcheck_add_c_compiler_flag(-Wno-shorten-64-to-32)
143+
xcheck_add_c_compiler_flag(-Wno-reserved-macro-identifier)
144+
xcheck_add_c_compiler_flag(-Wno-reserved-identifier)
145+
xcheck_add_c_compiler_flag(-Wdeprecated-declarations)
146+
xcheck_add_c_compiler_flag(/experimental:c11atomics)
147+
xcheck_add_c_compiler_flag(/wd4018) # -Wno-sign-conversion
148+
xcheck_add_c_compiler_flag(/wd4061) # -Wno-implicit-fallthrough
149+
xcheck_add_c_compiler_flag(/wd4100) # -Wno-unused-parameter
150+
xcheck_add_c_compiler_flag(/wd4200) # -Wno-zero-length-array
151+
xcheck_add_c_compiler_flag(/wd4242) # -Wno-shorten-64-to-32
152+
xcheck_add_c_compiler_flag(/wd4244) # -Wno-shorten-64-to-32
153+
xcheck_add_c_compiler_flag(/wd4245) # -Wno-sign-compare
154+
xcheck_add_c_compiler_flag(/wd4267) # -Wno-shorten-64-to-32
155+
xcheck_add_c_compiler_flag(/wd4388) # -Wno-sign-compare
156+
xcheck_add_c_compiler_flag(/wd4389) # -Wno-sign-compare
157+
xcheck_add_c_compiler_flag(/wd4710) # Function not inlined
158+
xcheck_add_c_compiler_flag(/wd4711) # Function was inlined
159+
xcheck_add_c_compiler_flag(/wd4820) # Padding added after construct
160+
xcheck_add_c_compiler_flag(/wd4996) # -Wdeprecated-declarations
161+
xcheck_add_c_compiler_flag(/wd5045) # Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
162+
xcheck_add_c_compiler_flag(/wd4514)
163+
xcheck_add_c_compiler_flag(/wd4146)
164+
xcheck_add_c_compiler_flag(/wd4334)
165+
xcheck_add_c_compiler_flag(-fchar8_t)
166+
xcheck_add_c_compiler_flag(/Zc:char8_t)
167+
endif()
168+
169+
xcheck_add_c_compiler_flag(-fno-strict-aliasing)
170+
171+
if ( APPLE )
172+
xcheck_add_c_compiler_flag(-Wno-shorten-64-to-32)
173+
endif()
174+
175+
xcheck_add_c_compiler_flag(-Wno-unused-variable)
176+
177+
if(APPLE AND CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 11)
178+
xcheck_add_c_compiler_flag(-Wno-maybe-uninitialized)
179+
endif()
180+
181+
if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
182+
add_compile_definitions(
183+
_WASI_EMULATED_PROCESS_CLOCKS
184+
_WASI_EMULATED_SIGNAL
185+
)
186+
add_link_options(
187+
-lwasi-emulated-process-clocks
188+
-lwasi-emulated-signal
189+
)
190+
endif()
191+
192+
if(CMAKE_BUILD_TYPE MATCHES "Debug")
193+
add_compile_options(-O0)
194+
xcheck_add_c_compiler_flag(-ggdb)
195+
xcheck_add_c_compiler_flag(-fno-omit-frame-pointer)
196+
endif()
197+
198+
include_directories(${PROJECT_SOURCE_DIR}/backend-quickjs/include
199+
${PROJECT_SOURCE_DIR}/backend-quickjs/quickjs
200+
)
201+
202+
list(APPEND PUERTS_SRC
203+
${PROJECT_SOURCE_DIR}/backend-quickjs/src/v8-impl.cc
204+
${PROJECT_SOURCE_DIR}/backend-quickjs/quickjs/cutils.c
205+
${PROJECT_SOURCE_DIR}/backend-quickjs/quickjs/libbf.c
206+
${PROJECT_SOURCE_DIR}/backend-quickjs/quickjs/libregexp.c
207+
${PROJECT_SOURCE_DIR}/backend-quickjs/quickjs/libunicode.c
208+
${PROJECT_SOURCE_DIR}/backend-quickjs/quickjs/quickjs.c
209+
)
210+
endif()
211+
112212
set(PUERTS_COMPILE_DEFINITIONS)
113213
set(PUERTS_BACKEND_SRC)
114214

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//android arm64
2+
#pragma once
3+
4+
#include <cstdint>
5+
6+
static const uint8_t SnapshotBlobCode[] = {
7+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//android armv7
2+
#pragma once
3+
4+
#include <cstdint>
5+
6+
static const uint8_t SnapshotBlobCode[] = {
7+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//android x64
2+
#pragma once
3+
4+
#include <cstdint>
5+
6+
static const uint8_t SnapshotBlobCode[] = {
7+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//osx 64
2+
#pragma once
3+
4+
#include <cstdint>
5+
6+
static const uint8_t SnapshotBlobCode[] = {
7+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//window x86
2+
#pragma once
3+
4+
#include <cstdint>
5+
6+
static const uint8_t SnapshotBlobCode[] = {0};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//window x64
2+
#pragma once
3+
4+
#include <cstdint>
5+
6+
static const uint8_t SnapshotBlobCode[] = {0};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//window x64
2+
#pragma once
3+
4+
#include <cstdint>
5+
6+
static const uint8_t SnapshotBlobCode[] = {0};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//ios arm64
2+
#pragma once
3+
4+
#include <cstdint>
5+
6+
static const uint8_t SnapshotBlobCode[] = {
7+
};

0 commit comments

Comments
 (0)