Skip to content

Commit 14dd828

Browse files
committed
improve build workflow, fix issue with quickjs
1 parent 62032ca commit 14dd828

File tree

155 files changed

+175404
-1625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+175404
-1625
lines changed

NativeScript/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ set(CMAKE_CXX_STANDARD 20)
1414

1515
set(BUILD_FRAMEWORK TRUE)
1616

17+
set(COMMON_FLAGS "-O3 -Wno-shorten-64-to-32")
18+
19+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}")
20+
1721
# Arguments
1822

1923
set(TARGET_PLATFORM "macos" CACHE STRING "Target platform for the Objective-C bridge")
@@ -274,7 +278,11 @@ if(TARGET_PLATFORM_MACOS)
274278

275279
set(METADATA_FILE "metadata.macos.nsmd")
276280
elseif(TARGET_PLATFORM_IOS)
277-
set(METADATA_FILE "metadata.ios.nsmd")
281+
if(TARGET_PLATFORM_SIM)
282+
set(METADATA_FILE "metadata.ios-sim.nsmd")
283+
else()
284+
set(METADATA_FILE "metadata.ios.nsmd")
285+
endif()
278286
endif()
279287

280288
if(NOT METADATA_SIZE EQUAL 0)

NativeScript/ffi/CFunction.mm

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,26 @@
1515

1616
napi_property_descriptor prop = {
1717
.utf8name = name,
18-
.attributes =
19-
(napi_property_attributes)(napi_enumerable | napi_configurable),
18+
.method = CFunction::jsCall,
2019
.getter = nullptr,
2120
.setter = nullptr,
2221
.value = nullptr,
23-
.data = (void *)((size_t)originalOffset),
24-
.method = CFunction::jsCall,
22+
.attributes = (napi_property_attributes)(napi_enumerable | napi_configurable),
23+
.data = (void*)((size_t)originalOffset),
2524
};
2625

2726
napi_define_properties(env, global, 1, &prop);
2827
}
2928
}
3029

31-
CFunction *ObjCBridgeState::getCFunction(napi_env env, MDSectionOffset offset) {
30+
CFunction* ObjCBridgeState::getCFunction(napi_env env, MDSectionOffset offset) {
3231
auto cached = cFunctionCache.find(offset);
3332
if (cached != cFunctionCache.end()) {
3433
return cached->second;
3534
}
3635

37-
auto sigOffset = metadata->signaturesOffset +
38-
metadata->getOffset(offset + sizeof(MDSectionOffset));
36+
auto sigOffset =
37+
metadata->signaturesOffset + metadata->getOffset(offset + sizeof(MDSectionOffset));
3938

4039
auto cFunction = new CFunction(dlsym(self_dl, metadata->getString(offset)));
4140
cFunction->cif = getCFunctionCif(env, sigOffset);
@@ -45,7 +44,7 @@
4544
}
4645

4746
napi_value CFunction::jsCall(napi_env env, napi_callback_info cbinfo) {
48-
void *_offset;
47+
void* _offset;
4948

5049
napi_get_cb_info(env, cbinfo, nullptr, nullptr, nullptr, &_offset);
5150

@@ -58,8 +57,8 @@
5857
size_t argc = cif->argc;
5958
napi_get_cb_info(env, cbinfo, &argc, cif->argv, nullptr, nullptr);
6059

61-
void *avalues[cif->argc];
62-
void *rvalue = cif->rvalue;
60+
void* avalues[cif->argc];
61+
void* rvalue = cif->rvalue;
6362

6463
bool shouldFreeAny = false;
6564
bool shouldFree[cif->argc];
@@ -68,8 +67,7 @@
6867
for (unsigned int i = 0; i < cif->argc; i++) {
6968
shouldFree[i] = false;
7069
avalues[i] = cif->avalues[i];
71-
cif->argTypes[i]->toNative(env, cif->argv[i], avalues[i], &shouldFree[i],
72-
&shouldFreeAny);
70+
cif->argTypes[i]->toNative(env, cif->argv[i], avalues[i], &shouldFree[i], &shouldFreeAny);
7371
}
7472
}
7573

@@ -78,7 +76,7 @@
7876
if (shouldFreeAny) {
7977
for (unsigned int i = 0; i < cif->argc; i++) {
8078
if (shouldFree[i]) {
81-
cif->argTypes[i]->free(env, *((void **)avalues[i]));
79+
cif->argTypes[i]->free(env, *((void**)avalues[i]));
8280
}
8381
}
8482
}
@@ -92,4 +90,4 @@
9290
}
9391
}
9492

95-
} // namespace objc_bridge
93+
} // namespace objc_bridge

NativeScript/ffi/Cif.mm

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
#include "Cif.h"
2+
#include <Foundation/Foundation.h>
3+
#include <iostream>
4+
#include <vector>
5+
#include "Metadata.h"
26
#include "MetadataReader.h"
37
#include "ObjCBridge.h"
48
#include "TypeConv.h"
59
#include "Util.h"
6-
#include <Foundation/Foundation.h>
7-
#include <iostream>
8-
#include <vector>
910

1011
namespace objc_bridge {
1112

1213
// Essentially, we cache libffi structures per unique method signature,
1314
// this helps us avoid the overhead of creating them on the fly for each
1415
// invocation.
15-
Cif *ObjCBridgeState::getMethodCif(napi_env env, Method method) {
16+
Cif* ObjCBridgeState::getMethodCif(napi_env env, Method method) {
1617
auto encoding = std::string(method_getTypeEncoding(method));
1718
auto find = this->cifs[encoding];
1819
if (find != nullptr) {
@@ -25,7 +26,7 @@
2526
return cif;
2627
}
2728

28-
Cif *ObjCBridgeState::getMethodCif(napi_env env, MDSectionOffset offset) {
29+
Cif* ObjCBridgeState::getMethodCif(napi_env env, MDSectionOffset offset) {
2930
auto find = this->mdMethodSignatureCache[offset];
3031
if (find != nullptr) {
3132
return find;
@@ -37,7 +38,7 @@
3738
return cif;
3839
}
3940

40-
Cif *ObjCBridgeState::getBlockCif(napi_env env, MDSectionOffset offset) {
41+
Cif* ObjCBridgeState::getBlockCif(napi_env env, MDSectionOffset offset) {
4142
auto find = this->mdBlockSignatureCache[offset];
4243
if (find != nullptr) {
4344
return find;
@@ -49,7 +50,7 @@
4950
return cif;
5051
}
5152

52-
Cif *ObjCBridgeState::getCFunctionCif(napi_env env, MDSectionOffset offset) {
53+
Cif* ObjCBridgeState::getCFunctionCif(napi_env env, MDSectionOffset offset) {
5354
auto find = this->mdFunctionSignatureCache[offset];
5455
if (find != nullptr) {
5556
return find;
@@ -65,15 +66,15 @@
6566
auto signature = [NSMethodSignature signatureWithObjCTypes:encoding.c_str()];
6667
unsigned long numberOfArguments = signature.numberOfArguments;
6768
this->argc = (int)numberOfArguments - 2;
68-
this->argv = (napi_value *)malloc(sizeof(napi_value) * this->argc);
69+
this->argv = (napi_value*)malloc(sizeof(napi_value) * this->argc);
6970

7071
unsigned int argc = (unsigned int)numberOfArguments;
7172

72-
const char *returnType = signature.methodReturnType;
73+
const char* returnType = signature.methodReturnType;
7374
this->returnType = TypeConv::Make(env, &returnType);
7475

75-
ffi_type *rtype = this->returnType->type;
76-
ffi_type **atypes = (ffi_type **)malloc(sizeof(ffi_type *) * argc);
76+
ffi_type* rtype = this->returnType->type;
77+
ffi_type** atypes = (ffi_type**)malloc(sizeof(ffi_type*) * argc);
7778

7879
unsigned long methodReturnLength = signature.methodReturnLength;
7980
unsigned long frameLength = signature.frameLength;
@@ -82,13 +83,13 @@
8283
this->rvalueLength = methodReturnLength;
8384
this->frameLength = frameLength;
8485

85-
this->avalues = (void **)malloc(sizeof(void *) * argc);
86-
this->shouldFree = (bool *)malloc(sizeof(bool) * this->argc);
86+
this->avalues = (void**)malloc(sizeof(void*) * argc);
87+
this->shouldFree = (bool*)malloc(sizeof(bool) * this->argc);
8788
memset(this->shouldFree, false, sizeof(bool) * this->argc);
8889
this->shouldFreeAny = false;
8990

9091
for (int i = 0; i < numberOfArguments; i++) {
91-
const char *argenc = [signature getArgumentTypeAtIndex:i];
92+
const char* argenc = [signature getArgumentTypeAtIndex:i];
9293

9394
auto argTypeInfo = TypeConv::Make(env, &argenc);
9495
atypes[i] = argTypeInfo->type;
@@ -107,21 +108,20 @@
107108
}
108109

109110
if (status != FFI_OK) {
110-
std::cout << "Failed to prepare CIF, libffi returned error:" << status
111-
<< std::endl;
111+
std::cout << "Failed to prepare CIF, libffi returned error:" << status << std::endl;
112112
return;
113113
}
114114
}
115115

116-
Cif::Cif(napi_env env, MDMetadataReader *reader, MDSectionOffset offset,
117-
bool isMethod, bool isBlock) {
116+
Cif::Cif(napi_env env, MDMetadataReader* reader, MDSectionOffset offset, bool isMethod,
117+
bool isBlock) {
118118
auto returnTypeKind = reader->getTypeKind(offset);
119-
bool next = (returnTypeKind & mdTypeFlagNext) != 0;
120-
isVariadic = (returnTypeKind & mdTypeFlagVariadic) != 0;
119+
bool next = ((MDTypeFlag)returnTypeKind & mdTypeFlagNext) != 0;
120+
isVariadic = ((MDTypeFlag)returnTypeKind & mdTypeFlagVariadic) != 0;
121121

122122
returnType = TypeConv::Make(env, reader, &offset);
123123

124-
ffi_type **atypes = nullptr;
124+
ffi_type** atypes = nullptr;
125125

126126
auto implicitArgs = isMethod ? 2 : isBlock ? 1 : 0;
127127

@@ -130,7 +130,7 @@
130130
if (next || isMethod || isBlock) {
131131
while (next) {
132132
auto argTypeKind = reader->getTypeKind(offset);
133-
next = (argTypeKind & mdTypeFlagNext) != 0;
133+
next = ((MDTypeFlag)argTypeKind & mdTypeFlagNext) != 0;
134134
auto argTypeInfo = TypeConv::Make(env, reader, &offset);
135135
std::string enc;
136136
argTypeInfo->encode(&enc);
@@ -141,11 +141,11 @@
141141

142142
auto totalArgc = argc + implicitArgs;
143143

144-
argv = (napi_value *)malloc(sizeof(napi_value) * argc);
145-
shouldFree = (bool *)malloc(sizeof(bool) * argc);
144+
argv = (napi_value*)malloc(sizeof(napi_value) * argc);
145+
shouldFree = (bool*)malloc(sizeof(bool) * argc);
146146

147-
atypes = (ffi_type **)malloc(sizeof(ffi_type *) * totalArgc);
148-
avalues = (void **)malloc(sizeof(void *) * argc);
147+
atypes = (ffi_type**)malloc(sizeof(ffi_type*) * totalArgc);
148+
avalues = (void**)malloc(sizeof(void*) * argc);
149149

150150
if (isMethod) {
151151
atypes[0] = &ffi_type_pointer;
@@ -167,12 +167,11 @@
167167
shouldFree = nullptr;
168168
}
169169

170-
ffi_status status = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, argc + implicitArgs,
171-
returnType->type, atypes);
170+
ffi_status status =
171+
ffi_prep_cif(&cif, FFI_DEFAULT_ABI, argc + implicitArgs, returnType->type, atypes);
172172

173173
if (status != FFI_OK) {
174-
std::cout << "Failed to prepare CIF, libffi returned error: " << status
175-
<< std::endl;
174+
std::cout << "Failed to prepare CIF, libffi returned error: " << status << std::endl;
176175
return;
177176
}
178177

@@ -184,4 +183,4 @@
184183
rvalueLength = cif.rtype->size;
185184
}
186185

187-
} // namespace objc_bridge
186+
} // namespace objc_bridge

0 commit comments

Comments
 (0)