@lucent-lang/lucent 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.plugin.js +92 -0
- package/bin/lucent.cjs +16 -0
- package/core/index.cjs +11 -0
- package/dist/bench-CR3E7e2e.js +304 -0
- package/dist/build-CAIrRSYA.js +7 -0
- package/dist/build-check-QozuNJm5.js +92 -0
- package/dist/check-1SCmYlqA.js +7 -0
- package/dist/clean-BVwpbJ5K.js +35 -0
- package/dist/cli.js +406 -0
- package/dist/codes-CIuwXt1S.js +260 -0
- package/dist/compiler.js +4 -0
- package/dist/confirm-BYF5eY3q.js +34 -0
- package/dist/dashboard-B-NzjjaN.js +91 -0
- package/dist/dev-BYWMP7oC.js +221 -0
- package/dist/diagnostic-BM9sXmwl.js +30 -0
- package/dist/diff-BTDo3Sro.js +44 -0
- package/dist/doctor-C0PrfWT6.js +230 -0
- package/dist/doctor-DdR4JnVc.js +30 -0
- package/dist/explain--vV1oaRl.js +35 -0
- package/dist/format-D9fnIMEx.js +53 -0
- package/dist/init-gIabu1S_.js +207 -0
- package/dist/live-steps-BGcWFM9M.js +79 -0
- package/dist/new-module-C2mtb0op.js +66 -0
- package/dist/package-manager-BnxwCySi.js +30 -0
- package/dist/package.json +3 -0
- package/dist/packages-HyskKIsY.js +150 -0
- package/dist/pipeline-CH7-2cxu.js +232 -0
- package/dist/project-D8tEet0k.js +150 -0
- package/dist/sdk-coverage-BoW_3Efd.js +64 -0
- package/dist/sdk-prefetch-mo04JDZV.js +89 -0
- package/dist/sdk-search-Iv4K3-8a.js +124 -0
- package/dist/sdk-show-CkrdlqlP.js +74 -0
- package/dist/sdks-Xoyiy2E4.js +28 -0
- package/dist/src-BD7f1_aZ.js +11493 -0
- package/dist/steps--_h-FFS7.js +24 -0
- package/dist/theme-uv5bc0aK.js +134 -0
- package/dist/tsconfig-S4uyLNzf.js +59 -0
- package/dist/version-bqpIO5sP.js +26 -0
- package/gradle/lucent-classpath.gradle +38 -0
- package/gradle/lucent-classpath.init.gradle +6 -0
- package/gradle/lucent.gradle +24 -0
- package/lib/core.cjs +106 -0
- package/lib/globals.d.ts +36 -0
- package/lib/sdk/android.d.ts +8 -0
- package/lib/sdk/core.d.ts +23 -0
- package/lib/sdk/ios.d.ts +33 -0
- package/lib/sdk/platform.d.ts +8 -0
- package/lib/sdk/thread.d.ts +8 -0
- package/metro/index.cjs +72 -0
- package/metro/index.d.ts +6 -0
- package/metro/transformer.cjs +70 -0
- package/package.json +61 -0
- package/runtime/cpp/lucent/abort.cpp +61 -0
- package/runtime/cpp/lucent/abort.h +54 -0
- package/runtime/cpp/lucent/array.h +442 -0
- package/runtime/cpp/lucent/async.h +236 -0
- package/runtime/cpp/lucent/builtins.cpp +163 -0
- package/runtime/cpp/lucent/bytes.h +129 -0
- package/runtime/cpp/lucent/console.h +17 -0
- package/runtime/cpp/lucent/core.h +129 -0
- package/runtime/cpp/lucent/date.cpp +441 -0
- package/runtime/cpp/lucent/date.h +82 -0
- package/runtime/cpp/lucent/equality.h +87 -0
- package/runtime/cpp/lucent/function.h +61 -0
- package/runtime/cpp/lucent/generator.h +244 -0
- package/runtime/cpp/lucent/helpers.h +226 -0
- package/runtime/cpp/lucent/jserror.cpp +51 -0
- package/runtime/cpp/lucent/jserror.h +66 -0
- package/runtime/cpp/lucent/jsi/convert.cpp +202 -0
- package/runtime/cpp/lucent/jsi/convert.h +612 -0
- package/runtime/cpp/lucent/jsi/host.cpp +322 -0
- package/runtime/cpp/lucent/jsi/host.h +166 -0
- package/runtime/cpp/lucent/json.cpp +243 -0
- package/runtime/cpp/lucent/json.h +164 -0
- package/runtime/cpp/lucent/json_parse.h +138 -0
- package/runtime/cpp/lucent/jsstring.cpp +874 -0
- package/runtime/cpp/lucent/jsstring.h +152 -0
- package/runtime/cpp/lucent/lucent.h +24 -0
- package/runtime/cpp/lucent/map.h +344 -0
- package/runtime/cpp/lucent/native.cpp +76 -0
- package/runtime/cpp/lucent/native.h +116 -0
- package/runtime/cpp/lucent/number.cpp +545 -0
- package/runtime/cpp/lucent/number.h +190 -0
- package/runtime/cpp/lucent/ops.h +165 -0
- package/runtime/cpp/lucent/platform/android.cpp +437 -0
- package/runtime/cpp/lucent/platform/android.h +117 -0
- package/runtime/cpp/lucent/platform/ios.h +297 -0
- package/runtime/cpp/lucent/platform/ios.mm +31 -0
- package/runtime/cpp/lucent/regexp.cpp +440 -0
- package/runtime/cpp/lucent/regexp.h +107 -0
- package/runtime/cpp/lucent/scheduler.cpp +153 -0
- package/runtime/cpp/lucent/scheduler.h +160 -0
- package/runtime/cpp/lucent/unicode_data.inc +4051 -0
- package/runtime/cpp/rn/LucentModule.cpp +35 -0
- package/runtime/cpp/rn/LucentModule.h +37 -0
- package/runtime/cpp/third_party/quickjs/LICENSE +22 -0
- package/runtime/cpp/third_party/quickjs/README.md +11 -0
- package/runtime/cpp/third_party/quickjs/cutils.c +641 -0
- package/runtime/cpp/third_party/quickjs/cutils.h +457 -0
- package/runtime/cpp/third_party/quickjs/libregexp-opcode.h +73 -0
- package/runtime/cpp/third_party/quickjs/libregexp.c +3448 -0
- package/runtime/cpp/third_party/quickjs/libregexp.h +65 -0
- package/runtime/cpp/third_party/quickjs/libunicode-table.h +5206 -0
- package/runtime/cpp/third_party/quickjs/libunicode.c +2124 -0
- package/runtime/cpp/third_party/quickjs/libunicode.h +196 -0
- package/runtime/js/index.d.ts +7 -0
- package/runtime/js/index.js +60 -0
- package/runtime/native/LucentNative.podspec +28 -0
- package/runtime/native/android/CMakeLists.txt +51 -0
- package/runtime/native/android/build.gradle +22 -0
- package/runtime/native/android/include/lucentnative.h +16 -0
- package/runtime/native/android/src/main/java/dev/lucent/LucentPackage.java +25 -0
- package/runtime/native/android/src/main/java/dev/lucent/NativeProxy.java +132 -0
- package/runtime/native/ios/LucentRegistration.mm +23 -0
- package/runtime/native/package.json +6 -0
- package/runtime/native/react-native.config.js +19 -0
- package/runtime/test/jsi/harness.cpp +181 -0
- package/schemas/build.schema.json +152 -0
- package/schemas/check.schema.json +74 -0
- package/schemas/doctor.schema.json +40 -0
- package/schemas/lucent.schema.json +43 -0
- package/schemas/sdk-prefetch.schema.json +37 -0
- package/schemas/sdk-search.schema.json +54 -0
- package/ts-plugin/index.d.ts +4 -0
- package/ts-plugin/index.js +99 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unicode utilities
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2017-2018 Fabrice Bellard
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
19
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
* THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
#ifndef LIBUNICODE_H
|
|
25
|
+
#define LIBUNICODE_H
|
|
26
|
+
|
|
27
|
+
#include <stdint.h>
|
|
28
|
+
|
|
29
|
+
/* unicode standard version */
|
|
30
|
+
#define LIBUNICODE_UNICODE_VERSION_MAJOR 17
|
|
31
|
+
#define LIBUNICODE_UNICODE_VERSION_MINOR 0
|
|
32
|
+
#define LIBUNICODE_UNICODE_VERSION_PATCH 0
|
|
33
|
+
|
|
34
|
+
/* define it to include all the unicode tables (40KB larger) */
|
|
35
|
+
#define CONFIG_ALL_UNICODE
|
|
36
|
+
|
|
37
|
+
#define LRE_CC_RES_LEN_MAX 3
|
|
38
|
+
|
|
39
|
+
/* char ranges */
|
|
40
|
+
|
|
41
|
+
typedef struct {
|
|
42
|
+
int len; /* in points, always even */
|
|
43
|
+
int size;
|
|
44
|
+
uint32_t *points; /* points sorted by increasing value */
|
|
45
|
+
void *mem_opaque;
|
|
46
|
+
void *(*realloc_func)(void *opaque, void *ptr, size_t size);
|
|
47
|
+
} CharRange;
|
|
48
|
+
|
|
49
|
+
typedef enum {
|
|
50
|
+
CR_OP_UNION,
|
|
51
|
+
CR_OP_INTER,
|
|
52
|
+
CR_OP_XOR,
|
|
53
|
+
CR_OP_SUB,
|
|
54
|
+
} CharRangeOpEnum;
|
|
55
|
+
|
|
56
|
+
void cr_init(CharRange *cr, void *mem_opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size));
|
|
57
|
+
void cr_free(CharRange *cr);
|
|
58
|
+
int cr_realloc(CharRange *cr, int size);
|
|
59
|
+
int cr_copy(CharRange *cr, const CharRange *cr1);
|
|
60
|
+
|
|
61
|
+
static inline int cr_add_point(CharRange *cr, uint32_t v)
|
|
62
|
+
{
|
|
63
|
+
if (cr->len >= cr->size) {
|
|
64
|
+
if (cr_realloc(cr, cr->len + 1))
|
|
65
|
+
return -1;
|
|
66
|
+
}
|
|
67
|
+
cr->points[cr->len++] = v;
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static inline int cr_add_interval(CharRange *cr, uint32_t c1, uint32_t c2)
|
|
72
|
+
{
|
|
73
|
+
if ((cr->len + 2) > cr->size) {
|
|
74
|
+
if (cr_realloc(cr, cr->len + 2))
|
|
75
|
+
return -1;
|
|
76
|
+
}
|
|
77
|
+
cr->points[cr->len++] = c1;
|
|
78
|
+
cr->points[cr->len++] = c2;
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
int cr_op(CharRange *cr, const uint32_t *a_pt, int a_len,
|
|
83
|
+
const uint32_t *b_pt, int b_len, int op);
|
|
84
|
+
int cr_op1(CharRange *cr, const uint32_t *b_pt, int b_len, int op);
|
|
85
|
+
|
|
86
|
+
static inline int cr_union_interval(CharRange *cr, uint32_t c1, uint32_t c2)
|
|
87
|
+
{
|
|
88
|
+
uint32_t b_pt[2];
|
|
89
|
+
b_pt[0] = c1;
|
|
90
|
+
b_pt[1] = c2 + 1;
|
|
91
|
+
return cr_op1(cr, b_pt, 2, CR_OP_UNION);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
int cr_invert(CharRange *cr);
|
|
95
|
+
|
|
96
|
+
int cr_regexp_canonicalize(CharRange *cr, int is_unicode);
|
|
97
|
+
|
|
98
|
+
typedef enum {
|
|
99
|
+
UNICODE_NFC,
|
|
100
|
+
UNICODE_NFD,
|
|
101
|
+
UNICODE_NFKC,
|
|
102
|
+
UNICODE_NFKD,
|
|
103
|
+
} UnicodeNormalizationEnum;
|
|
104
|
+
|
|
105
|
+
int unicode_normalize(uint32_t **pdst, const uint32_t *src, int src_len,
|
|
106
|
+
UnicodeNormalizationEnum n_type,
|
|
107
|
+
void *opaque, void *(*realloc_func)(void *opaque, void *ptr, size_t size));
|
|
108
|
+
|
|
109
|
+
/* Unicode character range functions */
|
|
110
|
+
|
|
111
|
+
int unicode_script(CharRange *cr, const char *script_name, int is_ext);
|
|
112
|
+
int unicode_general_category(CharRange *cr, const char *gc_name);
|
|
113
|
+
int unicode_prop(CharRange *cr, const char *prop_name);
|
|
114
|
+
|
|
115
|
+
typedef void UnicodeSequencePropCB(void *opaque, const uint32_t *buf, int len);
|
|
116
|
+
int unicode_sequence_prop(const char *prop_name, UnicodeSequencePropCB *cb, void *opaque,
|
|
117
|
+
CharRange *cr);
|
|
118
|
+
|
|
119
|
+
int lre_case_conv(uint32_t *res, uint32_t c, int conv_type);
|
|
120
|
+
int lre_canonicalize(uint32_t c, int is_unicode);
|
|
121
|
+
|
|
122
|
+
/* Code point type categories */
|
|
123
|
+
enum {
|
|
124
|
+
UNICODE_C_SPACE = (1 << 0),
|
|
125
|
+
UNICODE_C_DIGIT = (1 << 1),
|
|
126
|
+
UNICODE_C_UPPER = (1 << 2),
|
|
127
|
+
UNICODE_C_LOWER = (1 << 3),
|
|
128
|
+
UNICODE_C_UNDER = (1 << 4),
|
|
129
|
+
UNICODE_C_DOLLAR = (1 << 5),
|
|
130
|
+
UNICODE_C_XDIGIT = (1 << 6),
|
|
131
|
+
};
|
|
132
|
+
extern uint8_t const lre_ctype_bits[256];
|
|
133
|
+
|
|
134
|
+
/* zero or non-zero return value */
|
|
135
|
+
int lre_is_cased(uint32_t c);
|
|
136
|
+
int lre_is_case_ignorable(uint32_t c);
|
|
137
|
+
int lre_is_id_start(uint32_t c);
|
|
138
|
+
int lre_is_id_continue(uint32_t c);
|
|
139
|
+
|
|
140
|
+
static inline int lre_is_space_byte(uint8_t c) {
|
|
141
|
+
return lre_ctype_bits[c] & UNICODE_C_SPACE;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
static inline int lre_is_id_start_byte(uint8_t c) {
|
|
145
|
+
return lre_ctype_bits[c] & (UNICODE_C_UPPER | UNICODE_C_LOWER |
|
|
146
|
+
UNICODE_C_UNDER | UNICODE_C_DOLLAR);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
static inline int lre_is_id_continue_byte(uint8_t c) {
|
|
150
|
+
return lre_ctype_bits[c] & (UNICODE_C_UPPER | UNICODE_C_LOWER |
|
|
151
|
+
UNICODE_C_UNDER | UNICODE_C_DOLLAR |
|
|
152
|
+
UNICODE_C_DIGIT);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static inline int lre_is_word_byte(uint8_t c) {
|
|
156
|
+
return lre_ctype_bits[c] & (UNICODE_C_UPPER | UNICODE_C_LOWER |
|
|
157
|
+
UNICODE_C_UNDER | UNICODE_C_DIGIT);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
int lre_is_space_non_ascii(uint32_t c);
|
|
161
|
+
|
|
162
|
+
static inline int lre_is_space(uint32_t c) {
|
|
163
|
+
if (c < 256)
|
|
164
|
+
return lre_is_space_byte(c);
|
|
165
|
+
else
|
|
166
|
+
return lre_is_space_non_ascii(c);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
static inline int lre_js_is_ident_first(uint32_t c) {
|
|
170
|
+
if (c < 128) {
|
|
171
|
+
return lre_is_id_start_byte(c);
|
|
172
|
+
} else {
|
|
173
|
+
#ifdef CONFIG_ALL_UNICODE
|
|
174
|
+
return lre_is_id_start(c);
|
|
175
|
+
#else
|
|
176
|
+
return !lre_is_space_non_ascii(c);
|
|
177
|
+
#endif
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
static inline int lre_js_is_ident_next(uint32_t c) {
|
|
182
|
+
if (c < 128) {
|
|
183
|
+
return lre_is_id_continue_byte(c);
|
|
184
|
+
} else {
|
|
185
|
+
/* ZWNJ and ZWJ are accepted in identifiers */
|
|
186
|
+
if (c >= 0x200C && c <= 0x200D)
|
|
187
|
+
return TRUE;
|
|
188
|
+
#ifdef CONFIG_ALL_UNICODE
|
|
189
|
+
return lre_is_id_continue(c);
|
|
190
|
+
#else
|
|
191
|
+
return !lre_is_space_non_ascii(c);
|
|
192
|
+
#endif
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
#endif /* LIBUNICODE_H */
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Returns the exports object of a compiled Lucent module. */
|
|
2
|
+
export declare function loadModule(
|
|
3
|
+
name: string,
|
|
4
|
+
registry: () => { get(name: string): unknown },
|
|
5
|
+
): Record<string, unknown>;
|
|
6
|
+
/** Wraps a native class factory in a constructor usable with `new`. */
|
|
7
|
+
export declare function lucentClass<T>(factory: T): T;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Loads Lucent modules from the native "Lucent" TurboModule. `lucent build`
|
|
3
|
+
// copies it into the native package (js/_lucent/runtime.js), and the generated
|
|
4
|
+
// proxies (what Metro bundles in place of each *.lucent.ts file) require it
|
|
5
|
+
// from there and call loadModule().
|
|
6
|
+
// This file must not require "react-native" itself: the proxy passes the
|
|
7
|
+
// app's own TurboModuleRegistry in.
|
|
8
|
+
|
|
9
|
+
let native;
|
|
10
|
+
|
|
11
|
+
function getNative(registry) {
|
|
12
|
+
if (native) return native;
|
|
13
|
+
// Test hosts install modules directly.
|
|
14
|
+
if (typeof globalThis.__lucentModules === "object" && globalThis.__lucentModules) {
|
|
15
|
+
native = globalThis.__lucentModules;
|
|
16
|
+
return native;
|
|
17
|
+
}
|
|
18
|
+
native = registry().get("Lucent");
|
|
19
|
+
if (!native) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
"Lucent: the native module is not linked. Run `lucent build`, then rebuild the app " +
|
|
22
|
+
"(iOS: `pod install` first).",
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return native;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The exports of a compiled Lucent module.
|
|
30
|
+
* @param {string} name module name (the file name without .lucent.ts)
|
|
31
|
+
* @param {() => { get(name: string): any }} registry returns React Native's TurboModuleRegistry
|
|
32
|
+
*/
|
|
33
|
+
function loadModule(name, registry) {
|
|
34
|
+
const m = getNative(registry)[name];
|
|
35
|
+
if (!m) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Lucent: module "${name}" is not in the native build. Run \`lucent build\` and rebuild the app.`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return m;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Wraps a native class factory in a real constructor so `new` and `instanceof` work. */
|
|
44
|
+
function lucentClass(factory) {
|
|
45
|
+
function LucentClass() {
|
|
46
|
+
if (!new.target) throw new TypeError("Class constructor cannot be invoked without 'new'");
|
|
47
|
+
return factory.apply(undefined, arguments);
|
|
48
|
+
}
|
|
49
|
+
LucentClass.prototype = factory.prototype;
|
|
50
|
+
Object.defineProperty(LucentClass.prototype, "constructor", {
|
|
51
|
+
value: LucentClass,
|
|
52
|
+
configurable: true,
|
|
53
|
+
writable: true,
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(LucentClass, "name", { value: factory.name });
|
|
56
|
+
for (const key of Object.keys(factory)) LucentClass[key] = factory[key];
|
|
57
|
+
return LucentClass;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = { loadModule, lucentClass };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Generated by Lucent. Do not edit.
|
|
2
|
+
Pod::Spec.new do |s|
|
|
3
|
+
s.name = "LucentNative"
|
|
4
|
+
s.version = "0.1.0"
|
|
5
|
+
s.summary = "Native modules compiled by Lucent from *.lucent.ts"
|
|
6
|
+
s.homepage = "https://github.com/Fausto95/lucent"
|
|
7
|
+
s.license = "MIT"
|
|
8
|
+
s.authors = "Lucent"
|
|
9
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
10
|
+
s.source = { :git => "https://github.com/Fausto95/lucent.git", :tag => s.version.to_s }
|
|
11
|
+
|
|
12
|
+
# Projects with platform modules generate one set of files per target
|
|
13
|
+
# (cpp/generated/ios, cpp/generated/android); iOS builds its own. The
|
|
14
|
+
# runtime's Android glue is guarded by __ANDROID__.
|
|
15
|
+
s.source_files = ["cpp/**/*.{h,cpp,inc,c,mm}", "ios/**/*.{h,mm}"]
|
|
16
|
+
s.exclude_files = ["cpp/generated/android/**", "cpp/generated/host/**"]
|
|
17
|
+
s.frameworks = "CoreFoundation"
|
|
18
|
+
s.header_mappings_dir = "cpp"
|
|
19
|
+
s.pod_target_xcconfig = {
|
|
20
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
|
21
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/cpp\" \"$(PODS_TARGET_SRCROOT)/cpp/generated/ios\" \"$(PODS_TARGET_SRCROOT)/cpp/generated\" \"$(PODS_TARGET_SRCROOT)/cpp/rn\"",
|
|
22
|
+
# The vendored regular expression engine (third_party/quickjs) is C.
|
|
23
|
+
"OTHER_CFLAGS" => "$(inherited) -w",
|
|
24
|
+
"OTHER_CPLUSPLUSFLAGS" => "$(inherited) -ffp-contract=off -fexceptions -frtti -Wno-gnu-statement-expression -Wno-unused-label -Wno-parentheses-equality -Wno-comma",
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
install_modules_dependencies(s)
|
|
28
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Built as part of the app's `appmodules` library through React Native's C++
|
|
2
|
+
# module autolinking (see react-native.config.js).
|
|
3
|
+
cmake_minimum_required(VERSION 3.13)
|
|
4
|
+
set(CMAKE_VERBOSE_MAKEFILE on)
|
|
5
|
+
|
|
6
|
+
set(LUCENT_ROOT ${CMAKE_CURRENT_LIST_DIR}/..)
|
|
7
|
+
file(GLOB_RECURSE LUCENT_SOURCES CONFIGURE_DEPENDS ${LUCENT_ROOT}/cpp/*.cpp)
|
|
8
|
+
# Projects with platform modules generate one set of files per target
|
|
9
|
+
# (cpp/generated/ios, cpp/generated/android); Android builds its own.
|
|
10
|
+
list(FILTER LUCENT_SOURCES EXCLUDE REGEX "/cpp/generated/(ios|host)/")
|
|
11
|
+
|
|
12
|
+
# The vendored regular expression engine is C. It is a library of its own so
|
|
13
|
+
# that React Native's C++ compile options never reach it.
|
|
14
|
+
file(GLOB LUCENT_C_SOURCES CONFIGURE_DEPENDS ${LUCENT_ROOT}/cpp/third_party/quickjs/*.c)
|
|
15
|
+
add_library(lucentregexp STATIC ${LUCENT_C_SOURCES})
|
|
16
|
+
set_target_properties(lucentregexp PROPERTIES POSITION_INDEPENDENT_CODE ON C_STANDARD 11)
|
|
17
|
+
target_compile_options(lucentregexp PRIVATE -w -O2)
|
|
18
|
+
|
|
19
|
+
add_library(lucentnative OBJECT ${LUCENT_SOURCES})
|
|
20
|
+
|
|
21
|
+
target_include_directories(lucentnative PUBLIC
|
|
22
|
+
${LUCENT_ROOT}/cpp
|
|
23
|
+
${LUCENT_ROOT}/cpp/generated/android
|
|
24
|
+
${LUCENT_ROOT}/cpp/generated
|
|
25
|
+
${LUCENT_ROOT}/cpp/rn
|
|
26
|
+
${CMAKE_CURRENT_LIST_DIR}/include
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
if(COMMAND target_compile_reactnative_options)
|
|
30
|
+
target_compile_reactnative_options(lucentnative PRIVATE)
|
|
31
|
+
endif()
|
|
32
|
+
# Hidden: calls between the runtime's files are direct instead of through the
|
|
33
|
+
# PLT of the app's shared library (a string argument made three such calls).
|
|
34
|
+
# Natives are bound with RegisterNatives, so nothing is looked up by name.
|
|
35
|
+
target_compile_options(lucentnative PRIVATE
|
|
36
|
+
-fvisibility=hidden
|
|
37
|
+
$<$<COMPILE_LANGUAGE:CXX>:-fvisibility-inlines-hidden>
|
|
38
|
+
$<$<COMPILE_LANGUAGE:CXX>:-std=c++20>
|
|
39
|
+
$<$<COMPILE_LANGUAGE:CXX>:-ffp-contract=off>
|
|
40
|
+
$<$<COMPILE_LANGUAGE:CXX>:-fexceptions>
|
|
41
|
+
$<$<COMPILE_LANGUAGE:CXX>:-frtti>
|
|
42
|
+
$<$<COMPILE_LANGUAGE:CXX>:-O2>
|
|
43
|
+
$<$<COMPILE_LANGUAGE:CXX>:-Wno-unused-parameter>
|
|
44
|
+
$<$<COMPILE_LANGUAGE:CXX>:-Wno-unused-variable>
|
|
45
|
+
$<$<COMPILE_LANGUAGE:CXX>:-Wno-unused-label>
|
|
46
|
+
$<$<COMPILE_LANGUAGE:CXX>:-Wno-gnu-statement-expression>
|
|
47
|
+
$<$<COMPILE_LANGUAGE:CXX>:-Wno-parentheses-equality>
|
|
48
|
+
$<$<COMPILE_LANGUAGE:CXX>:-Wno-comma>
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
target_link_libraries(lucentnative jsi reactnative fbjni log lucentregexp)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Generated by Lucent. Do not edit.
|
|
2
|
+
// The Java Lucent's Android platform code needs (dev.lucent.NativeProxy); the
|
|
3
|
+
// C++ is built into the app's appmodules library (CMakeLists.txt).
|
|
4
|
+
apply plugin: "com.android.library"
|
|
5
|
+
|
|
6
|
+
def safeExtGet(prop, fallback) {
|
|
7
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
android {
|
|
11
|
+
namespace "dev.lucent"
|
|
12
|
+
compileSdk safeExtGet("compileSdkVersion", 36)
|
|
13
|
+
defaultConfig {
|
|
14
|
+
minSdk safeExtGet("minSdkVersion", 24)
|
|
15
|
+
// Written by lucent build: what the JNI glue finds by name, kept from the app's shrinker.
|
|
16
|
+
consumerProguardFiles "consumer-rules.pro"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
dependencies {
|
|
21
|
+
implementation("com.facebook.react:react-android")
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// React Native's autolinking calls <libraryName>_ModuleProvider for Java
|
|
2
|
+
// TurboModules. Lucent has none (its module is pure C++), so this returns null.
|
|
3
|
+
#pragma once
|
|
4
|
+
|
|
5
|
+
#include <ReactCommon/JavaTurboModule.h>
|
|
6
|
+
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <string>
|
|
9
|
+
|
|
10
|
+
namespace facebook::react {
|
|
11
|
+
|
|
12
|
+
inline std::shared_ptr<TurboModule> lucentnative_ModuleProvider(const std::string&, const JavaTurboModule::InitParams&) {
|
|
13
|
+
return nullptr;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Generated by Lucent. Do not edit.
|
|
2
|
+
package dev.lucent;
|
|
3
|
+
|
|
4
|
+
import com.facebook.react.ReactPackage;
|
|
5
|
+
import com.facebook.react.bridge.NativeModule;
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
8
|
+
import java.util.Collections;
|
|
9
|
+
import java.util.List;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Lucent's module is C++ (autolinked through CMake). This package only lets
|
|
13
|
+
* autolinking include the Java Lucent's platform code needs (NativeProxy).
|
|
14
|
+
*/
|
|
15
|
+
public final class LucentPackage implements ReactPackage {
|
|
16
|
+
@Override
|
|
17
|
+
public List<NativeModule> createNativeModules(ReactApplicationContext context) {
|
|
18
|
+
return Collections.emptyList();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Override
|
|
22
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext context) {
|
|
23
|
+
return Collections.emptyList();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Generated by Lucent. Do not edit.
|
|
2
|
+
package dev.lucent;
|
|
3
|
+
|
|
4
|
+
import android.os.Build;
|
|
5
|
+
import android.util.Log;
|
|
6
|
+
import java.lang.invoke.MethodHandles;
|
|
7
|
+
import java.lang.reflect.Constructor;
|
|
8
|
+
import java.lang.reflect.InvocationHandler;
|
|
9
|
+
import java.lang.reflect.Method;
|
|
10
|
+
import java.lang.reflect.Proxy;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Java interfaces implemented by Lucent code: a java.lang.reflect.Proxy whose
|
|
14
|
+
* calls go to C++. One class serves every interface, so no Java is generated
|
|
15
|
+
* per interface. Methods are keyed by name and parameter descriptor
|
|
16
|
+
* (`onLocationChanged(Landroid/location/Location;)`), so overloads stay
|
|
17
|
+
* apart; default methods Lucent does not implement keep their Java body. The
|
|
18
|
+
* handle is a C++ object released when the proxy is collected.
|
|
19
|
+
*/
|
|
20
|
+
public final class NativeProxy implements InvocationHandler {
|
|
21
|
+
private final long handle;
|
|
22
|
+
|
|
23
|
+
private NativeProxy(long handle) {
|
|
24
|
+
this.handle = handle;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public static Object create(Class<?> iface, long handle) {
|
|
28
|
+
return Proxy.newProxyInstance(iface.getClassLoader(), new Class<?>[] {iface}, new NativeProxy(handle));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@Override
|
|
32
|
+
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
|
33
|
+
if (method.getDeclaringClass() == Object.class) {
|
|
34
|
+
switch (method.getName()) {
|
|
35
|
+
case "equals":
|
|
36
|
+
return proxy == args[0];
|
|
37
|
+
case "hashCode":
|
|
38
|
+
return System.identityHashCode(proxy);
|
|
39
|
+
default:
|
|
40
|
+
return "Lucent " + proxy.getClass().getInterfaces()[0].getName();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
String key = key(method);
|
|
44
|
+
Object[] a = args == null ? new Object[0] : args;
|
|
45
|
+
if (!has(handle, key) && method.isDefault()) return invokeDefault(proxy, method, a);
|
|
46
|
+
return call(handle, key, a);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Name and parameter descriptor, as JNI writes them. */
|
|
50
|
+
static String key(Method method) {
|
|
51
|
+
StringBuilder b = new StringBuilder(method.getName()).append('(');
|
|
52
|
+
for (Class<?> p : method.getParameterTypes()) b.append(descriptor(p));
|
|
53
|
+
return b.append(')').toString();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private static String descriptor(Class<?> c) {
|
|
57
|
+
if (c.isArray()) return "[" + descriptor(c.getComponentType());
|
|
58
|
+
if (c == int.class) return "I";
|
|
59
|
+
if (c == long.class) return "J";
|
|
60
|
+
if (c == boolean.class) return "Z";
|
|
61
|
+
if (c == double.class) return "D";
|
|
62
|
+
if (c == float.class) return "F";
|
|
63
|
+
if (c == short.class) return "S";
|
|
64
|
+
if (c == byte.class) return "B";
|
|
65
|
+
if (c == char.class) return "C";
|
|
66
|
+
if (c == void.class) return "V";
|
|
67
|
+
return "L" + c.getName().replace('.', '/') + ";";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A default method's own body: LocationListener's onLocationChanged(List),
|
|
72
|
+
* which the platform calls from API 31, loops over onLocationChanged(Location).
|
|
73
|
+
* A private lookup in the interface (API 33); the Lookup constructor Java 8
|
|
74
|
+
* code used (API 26 to 32); where neither works, the type's zero value, and
|
|
75
|
+
* the error is logged.
|
|
76
|
+
*/
|
|
77
|
+
private static Object invokeDefault(Object proxy, Method method, Object[] args) throws Throwable {
|
|
78
|
+
Class<?> declaring = method.getDeclaringClass();
|
|
79
|
+
try {
|
|
80
|
+
MethodHandles.Lookup lookup;
|
|
81
|
+
if (Build.VERSION.SDK_INT >= 33) {
|
|
82
|
+
lookup = MethodHandles.privateLookupIn(declaring, MethodHandles.lookup());
|
|
83
|
+
} else {
|
|
84
|
+
Constructor<MethodHandles.Lookup> ctor = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, int.class);
|
|
85
|
+
ctor.setAccessible(true);
|
|
86
|
+
lookup = ctor.newInstance(declaring, -1);
|
|
87
|
+
}
|
|
88
|
+
return lookup.unreflectSpecial(method, declaring).bindTo(proxy).invokeWithArguments(args);
|
|
89
|
+
} catch (ReflectiveOperationException | UnsupportedOperationException e) {
|
|
90
|
+
Log.e("Lucent", "cannot run the default body of " + method + " on this Android version", e);
|
|
91
|
+
return zero(method.getReturnType());
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private static Object zero(Class<?> type) {
|
|
96
|
+
if (type == boolean.class) return false;
|
|
97
|
+
if (type == int.class) return 0;
|
|
98
|
+
if (type == long.class) return 0L;
|
|
99
|
+
if (type == double.class) return 0.0;
|
|
100
|
+
if (type == float.class) return 0f;
|
|
101
|
+
if (type == short.class) return (short) 0;
|
|
102
|
+
if (type == byte.class) return (byte) 0;
|
|
103
|
+
if (type == char.class) return (char) 0;
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@Override
|
|
108
|
+
@SuppressWarnings({"deprecation", "removal"})
|
|
109
|
+
protected void finalize() throws Throwable {
|
|
110
|
+
try {
|
|
111
|
+
release(handle);
|
|
112
|
+
} finally {
|
|
113
|
+
super.finalize();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** For generated subclasses of SDK classes: a call of their Lucent side. */
|
|
118
|
+
public static Object dispatch(long handle, String key, Object[] args) {
|
|
119
|
+
return call(handle, key, args);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** For generated subclasses: their Lucent side is released with them. */
|
|
123
|
+
public static void releaseHandle(long handle) {
|
|
124
|
+
release(handle);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private static native boolean has(long handle, String key);
|
|
128
|
+
|
|
129
|
+
private static native Object call(long handle, String key, Object[] args);
|
|
130
|
+
|
|
131
|
+
private static native void release(long handle);
|
|
132
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Registers the Lucent C++ TurboModule when the binary loads, so React Native
|
|
2
|
+
// finds it without codegen or any change to the app delegate.
|
|
3
|
+
#import <Foundation/Foundation.h>
|
|
4
|
+
|
|
5
|
+
#include <ReactCommon/CxxTurboModuleUtils.h>
|
|
6
|
+
|
|
7
|
+
#include "LucentModule.h"
|
|
8
|
+
|
|
9
|
+
@interface LucentRegistration : NSObject
|
|
10
|
+
@end
|
|
11
|
+
|
|
12
|
+
@implementation LucentRegistration
|
|
13
|
+
|
|
14
|
+
+ (void)load
|
|
15
|
+
{
|
|
16
|
+
facebook::react::registerCxxModuleToGlobalModuleMap(
|
|
17
|
+
std::string(facebook::react::LucentModule::kModuleName),
|
|
18
|
+
[](std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
|
|
19
|
+
return std::make_shared<facebook::react::LucentModule>(std::move(jsInvoker));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Generated by Lucent. Do not edit.
|
|
2
|
+
// Android builds cpp/ through CMake autolinking (C++ module), and the Java in
|
|
3
|
+
// android/ (dev.lucent.NativeProxy) as a library; iOS builds through the podspec.
|
|
4
|
+
module.exports = {
|
|
5
|
+
dependency: {
|
|
6
|
+
platforms: {
|
|
7
|
+
android: {
|
|
8
|
+
sourceDir: "android",
|
|
9
|
+
packageImportPath: "import dev.lucent.LucentPackage;",
|
|
10
|
+
packageInstance: "new LucentPackage()",
|
|
11
|
+
libraryName: "lucentnative",
|
|
12
|
+
cxxModuleCMakeListsModuleName: "lucentnative",
|
|
13
|
+
cxxModuleCMakeListsPath: "CMakeLists.txt",
|
|
14
|
+
cxxModuleHeaderName: "LucentModule",
|
|
15
|
+
},
|
|
16
|
+
ios: {},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
};
|