@bennyblader/ddk-rn 0.2.2 ā 0.2.3
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/cpp/ddk_ffi.cpp +36 -0
- package/cpp/ddk_ffi.hpp +2 -0
- package/lib/commonjs/ddk_ffi-ffi.js.map +1 -1
- package/lib/commonjs/ddk_ffi.js +47 -47
- package/lib/commonjs/ddk_ffi.js.map +1 -1
- package/lib/module/ddk_ffi-ffi.js.map +1 -1
- package/lib/module/ddk_ffi.js +47 -48
- package/lib/module/ddk_ffi.js.map +1 -1
- package/lib/typescript/commonjs/src/ddk_ffi-ffi.d.ts +2 -0
- package/lib/typescript/commonjs/src/ddk_ffi-ffi.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/ddk_ffi.d.ts +3 -2
- package/lib/typescript/commonjs/src/ddk_ffi.d.ts.map +1 -1
- package/lib/typescript/module/src/ddk_ffi-ffi.d.ts +2 -0
- package/lib/typescript/module/src/ddk_ffi-ffi.d.ts.map +1 -1
- package/lib/typescript/module/src/ddk_ffi.d.ts +3 -2
- package/lib/typescript/module/src/ddk_ffi.d.ts.map +1 -1
- package/package.json +7 -4
- package/react-native.config.js +13 -0
- package/scripts/postinstall.js +226 -173
- package/src/ddk_ffi-ffi.ts +199 -49
- package/src/ddk_ffi.ts +1509 -1303
- package/ubrn.config.yaml +23 -0
- package/cpp/bennyblader-ddk-rn.cpp +0 -16
- package/cpp/bennyblader-ddk-rn.h +0 -15
- package/src/NativeDdkRn.ts +0 -10
- package/src/index.tsx +0 -41
package/scripts/postinstall.js
CHANGED
|
@@ -2,48 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
-
const https = require('https');
|
|
6
5
|
const { execSync } = require('child_process');
|
|
7
6
|
|
|
8
7
|
const packageRoot = path.join(__dirname, '..');
|
|
9
|
-
const packageJson = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'));
|
|
10
|
-
const version = packageJson.version;
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
const RELEASE_TAG = `v${version}`;
|
|
9
|
+
console.log('š¦ DDK-RN Post-install: Generating turbo modules and building native libraries...');
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
// Check if uniffi-bindgen-react-native is available (prefer npx)
|
|
12
|
+
function hasUniffiBingen() {
|
|
13
|
+
try {
|
|
14
|
+
execSync('npx uniffi-bindgen-react-native --help', { stdio: 'ignore' });
|
|
15
|
+
return true;
|
|
16
|
+
} catch (error) {
|
|
17
|
+
try {
|
|
18
|
+
execSync('uniffi-bindgen-react-native --help', { stdio: 'ignore' });
|
|
19
|
+
return true;
|
|
20
|
+
} catch (error2) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
16
25
|
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
|
|
23
|
-
'
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
'cpp/ddk_ffi.hpp',
|
|
27
|
-
'cpp/ddk_ffi.cpp',
|
|
28
|
-
'cpp/bennyblader-ddk-rn.h',
|
|
29
|
-
'cpp/bennyblader-ddk-rn.cpp'
|
|
30
|
-
],
|
|
31
|
-
'Android libraries': [
|
|
32
|
-
'android/src/main/arm64-v8a/libddk_ffi.a',
|
|
33
|
-
'android/src/main/armeabi-v7a/libddk_ffi.a',
|
|
34
|
-
'android/src/main/x86/libddk_ffi.a',
|
|
35
|
-
'android/src/main/x86_64/libddk_ffi.a'
|
|
36
|
-
],
|
|
37
|
-
'iOS framework': [
|
|
38
|
-
'ios/DdkRn.xcframework/Info.plist',
|
|
39
|
-
'ios/DdkRn.xcframework/ios-arm64/libddk_ffi.a',
|
|
40
|
-
'ios/DdkRn.xcframework/ios-arm64-simulator/libddk_ffi.a'
|
|
41
|
-
],
|
|
42
|
-
'JavaScript modules': [
|
|
43
|
-
'lib/commonjs/index.js',
|
|
44
|
-
'lib/module/index.js'
|
|
45
|
-
]
|
|
46
|
-
};
|
|
26
|
+
// Get the uniffi command (prefer npx)
|
|
27
|
+
function getUniffiCommand() {
|
|
28
|
+
try {
|
|
29
|
+
execSync('npx uniffi-bindgen-react-native --help', { stdio: 'ignore' });
|
|
30
|
+
return 'npx uniffi-bindgen-react-native';
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return 'uniffi-bindgen-react-native';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
47
35
|
|
|
48
36
|
// Create directories if they don't exist
|
|
49
37
|
function ensureDir(dir) {
|
|
@@ -52,178 +40,243 @@ function ensureDir(dir) {
|
|
|
52
40
|
}
|
|
53
41
|
}
|
|
54
42
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
63
|
-
// Follow redirect
|
|
64
|
-
return downloadFile(response.headers.location, dest).then(resolve).catch(reject);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (response.statusCode !== 200) {
|
|
68
|
-
reject(new Error(`Failed to download: ${response.statusCode} ${response.statusMessage}`));
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
response.pipe(file);
|
|
73
|
-
|
|
74
|
-
file.on('finish', () => {
|
|
75
|
-
file.close();
|
|
76
|
-
console.log(`ā
Downloaded ${path.basename(dest)}`);
|
|
77
|
-
resolve();
|
|
78
|
-
});
|
|
79
|
-
}).on('error', (err) => {
|
|
80
|
-
fs.unlink(dest, () => {}); // Delete partial file
|
|
81
|
-
reject(err);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function extractTarGz(tarPath, extractDir) {
|
|
43
|
+
// Generate turbo module specifications from existing JSI bindings
|
|
44
|
+
function generateTurboModule() {
|
|
45
|
+
console.log('\nā” Generating turbo module from existing bindings...');
|
|
46
|
+
|
|
47
|
+
const configFile = path.join(packageRoot, 'ubrn.config.yaml');
|
|
48
|
+
const uniffiCmd = getUniffiCommand();
|
|
49
|
+
|
|
87
50
|
try {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
51
|
+
const cmd = `${uniffiCmd} generate jsi turbo-module ddk_ffi --config "${configFile}" --native-bindings`;
|
|
52
|
+
console.log(`Running: ${cmd}`);
|
|
53
|
+
execSync(cmd, {
|
|
54
|
+
stdio: 'inherit',
|
|
55
|
+
cwd: packageRoot
|
|
56
|
+
});
|
|
57
|
+
console.log('ā
Turbo module generated');
|
|
91
58
|
} catch (error) {
|
|
92
|
-
throw new Error(`Failed to
|
|
59
|
+
throw new Error(`Failed to generate turbo module: ${error.message}`);
|
|
93
60
|
}
|
|
94
61
|
}
|
|
95
62
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
let allFilesPresent = true;
|
|
63
|
+
// Build iOS libraries and create XCFramework
|
|
64
|
+
function buildIOS() {
|
|
100
65
|
const platform = process.platform;
|
|
101
66
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
console.log(`\nā ļø Skipping ${category} verification (not on macOS)`);
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
console.log(`\nš Checking ${category}...`);
|
|
110
|
-
|
|
111
|
-
for (const file of files) {
|
|
112
|
-
const filePath = path.join(packageRoot, file);
|
|
113
|
-
if (fs.existsSync(filePath)) {
|
|
114
|
-
console.log(` ā
${file}`);
|
|
115
|
-
} else {
|
|
116
|
-
console.error(` ā Missing: ${file}`);
|
|
117
|
-
allFilesPresent = false;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
67
|
+
if (platform !== 'darwin') {
|
|
68
|
+
console.log('\nā ļø Skipping iOS build (not on macOS)');
|
|
69
|
+
return;
|
|
120
70
|
}
|
|
121
71
|
|
|
122
|
-
|
|
72
|
+
console.log('\nš Building iOS libraries...');
|
|
73
|
+
const uniffiCmd = getUniffiCommand();
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const cmd = `${uniffiCmd} build ios --and-generate`;
|
|
77
|
+
console.log(`Running: ${cmd}`);
|
|
78
|
+
execSync(cmd, {
|
|
79
|
+
stdio: 'inherit',
|
|
80
|
+
cwd: packageRoot
|
|
81
|
+
});
|
|
82
|
+
console.log('ā
iOS libraries built');
|
|
83
|
+
} catch (error) {
|
|
84
|
+
throw new Error(`Failed to build iOS libraries: ${error.message}`);
|
|
85
|
+
}
|
|
123
86
|
}
|
|
124
87
|
|
|
125
|
-
|
|
126
|
-
|
|
88
|
+
// Build Android libraries
|
|
89
|
+
function buildAndroid() {
|
|
90
|
+
console.log('\nš± Building Android libraries...');
|
|
91
|
+
|
|
92
|
+
// Check if Android NDK is available
|
|
93
|
+
if (!process.env.ANDROID_NDK_ROOT && !process.env.NDK_HOME) {
|
|
94
|
+
console.log('ā ļø Android NDK not found. Skipping Android build.');
|
|
95
|
+
console.log(' Set ANDROID_NDK_ROOT or NDK_HOME to build Android libraries.');
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const uniffiCmd = getUniffiCommand();
|
|
127
100
|
|
|
128
101
|
try {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
console.log('\nš± Setting up Android native libraries...');
|
|
137
|
-
await downloadFile(androidArchiveUrl, androidTarPath);
|
|
138
|
-
extractTarGz(androidTarPath, androidLibsDir);
|
|
139
|
-
fs.unlinkSync(androidTarPath); // Clean up tar file
|
|
140
|
-
|
|
141
|
-
// Download iOS XCFramework (only on macOS)
|
|
142
|
-
if (platform === 'darwin') {
|
|
143
|
-
const iosFrameworksDir = path.join(packageRoot, 'ios');
|
|
144
|
-
ensureDir(iosFrameworksDir);
|
|
145
|
-
|
|
146
|
-
const iosArchiveUrl = `https://github.com/${GITHUB_REPO}/releases/download/${RELEASE_TAG}/ios-xcframeworks.tar.gz`;
|
|
147
|
-
const iosTarPath = path.join(packageRoot, 'ios-xcframeworks.tar.gz');
|
|
148
|
-
|
|
149
|
-
console.log('\nš Setting up iOS framework...');
|
|
150
|
-
await downloadFile(iosArchiveUrl, iosTarPath);
|
|
151
|
-
extractTarGz(iosTarPath, iosFrameworksDir);
|
|
152
|
-
fs.unlinkSync(iosTarPath); // Clean up tar file
|
|
153
|
-
} else {
|
|
154
|
-
console.log('\nā ļø Skipping iOS framework (not on macOS)');
|
|
155
|
-
}
|
|
156
|
-
|
|
102
|
+
const cmd = `${uniffiCmd} build android --and-generate`;
|
|
103
|
+
console.log(`Running: ${cmd}`);
|
|
104
|
+
execSync(cmd, {
|
|
105
|
+
stdio: 'inherit',
|
|
106
|
+
cwd: packageRoot
|
|
107
|
+
});
|
|
108
|
+
console.log('ā
Android libraries built');
|
|
157
109
|
} catch (error) {
|
|
158
|
-
console.
|
|
159
|
-
console.
|
|
160
|
-
console.error('š Manual installation instructions:');
|
|
161
|
-
console.error(` 1. Download binaries from: https://github.com/${GITHUB_REPO}/releases/tag/${RELEASE_TAG}`);
|
|
162
|
-
console.error(' 2. Extract android-jni-libs.tar.gz to android/src/main/');
|
|
163
|
-
console.error(' 3. Extract ios-xcframeworks.tar.gz to ios/ (macOS only)');
|
|
164
|
-
console.error('');
|
|
165
|
-
console.error('Or report this issue at: https://github.com/bennyhodl/ddk-ffi/issues');
|
|
166
|
-
|
|
167
|
-
// Don't fail the installation completely
|
|
168
|
-
process.exit(0);
|
|
110
|
+
console.warn(`ā ļø Android build failed: ${error.message}`);
|
|
111
|
+
console.warn(' This may be due to missing Android NDK or Rust toolchains.');
|
|
169
112
|
}
|
|
170
113
|
}
|
|
171
114
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
115
|
+
// Fix the C++ include path issue
|
|
116
|
+
function fixCppIncludePath() {
|
|
117
|
+
const cppFile = path.join(packageRoot, 'cpp', 'bennyblader-ddk-rn.cpp');
|
|
118
|
+
if (fs.existsSync(cppFile)) {
|
|
119
|
+
let content = fs.readFileSync(cppFile, 'utf8');
|
|
120
|
+
if (content.includes('#include "/ddk_ffi.hpp"')) {
|
|
121
|
+
content = content.replace('#include "/ddk_ffi.hpp"', '#include "ddk_ffi.hpp"');
|
|
122
|
+
fs.writeFileSync(cppFile, content);
|
|
123
|
+
console.log('š§ Fixed include path in C++ bindings');
|
|
124
|
+
}
|
|
180
125
|
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Verify all required files are present
|
|
129
|
+
function verifyAllFiles() {
|
|
130
|
+
console.log('\nš Verifying installation...');
|
|
181
131
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
132
|
+
const sourceFiles = [
|
|
133
|
+
'src/ddk_ffi.ts',
|
|
134
|
+
'src/ddk_ffi-ffi.ts',
|
|
135
|
+
'cpp/ddk_ffi.hpp',
|
|
136
|
+
'cpp/ddk_ffi.cpp'
|
|
137
|
+
];
|
|
185
138
|
|
|
186
|
-
|
|
139
|
+
const generatedFiles = [
|
|
140
|
+
'src/NativeDdkRn.ts',
|
|
141
|
+
'src/index.tsx',
|
|
142
|
+
'cpp/bennyblader-ddk-rn.cpp',
|
|
143
|
+
'cpp/bennyblader-ddk-rn.h'
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
const platform = process.platform;
|
|
147
|
+
let allFilesPresent = true;
|
|
187
148
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
149
|
+
// Check source files (should be included in NPM package)
|
|
150
|
+
console.log('š Checking source files...');
|
|
151
|
+
for (const file of sourceFiles) {
|
|
152
|
+
const filePath = path.join(packageRoot, file);
|
|
153
|
+
if (fs.existsSync(filePath)) {
|
|
154
|
+
console.log(` ā
${file}`);
|
|
155
|
+
} else {
|
|
156
|
+
console.error(` ā Missing: ${file}`);
|
|
157
|
+
allFilesPresent = false;
|
|
158
|
+
}
|
|
191
159
|
}
|
|
192
160
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
161
|
+
// Check generated files (created by postinstall)
|
|
162
|
+
console.log('š Checking generated files...');
|
|
163
|
+
for (const file of generatedFiles) {
|
|
164
|
+
const filePath = path.join(packageRoot, file);
|
|
165
|
+
if (fs.existsSync(filePath)) {
|
|
166
|
+
console.log(` ā
${file}`);
|
|
167
|
+
} else {
|
|
168
|
+
console.error(` ā Missing: ${file}`);
|
|
169
|
+
allFilesPresent = false;
|
|
170
|
+
}
|
|
196
171
|
}
|
|
197
172
|
|
|
198
|
-
|
|
199
|
-
|
|
173
|
+
// Check platform-specific files
|
|
174
|
+
if (platform === 'darwin') {
|
|
175
|
+
console.log('š Checking iOS framework...');
|
|
176
|
+
const iosFramework = path.join(packageRoot, 'ios', 'DdkRn.xcframework', 'Info.plist');
|
|
177
|
+
if (fs.existsSync(iosFramework)) {
|
|
178
|
+
console.log(` ā
ios/DdkRn.xcframework`);
|
|
179
|
+
} else {
|
|
180
|
+
console.error(` ā Missing: ios/DdkRn.xcframework`);
|
|
181
|
+
allFilesPresent = false;
|
|
182
|
+
}
|
|
200
183
|
} else {
|
|
201
|
-
console.log('
|
|
184
|
+
console.log('š Skipping iOS framework check (not on macOS)');
|
|
202
185
|
}
|
|
203
186
|
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
187
|
+
console.log('š Checking Android libraries...');
|
|
188
|
+
const androidLibs = [
|
|
189
|
+
'android/src/main/arm64-v8a/libddk_ffi.a',
|
|
190
|
+
'android/src/main/armeabi-v7a/libddk_ffi.a',
|
|
191
|
+
'android/src/main/x86/libddk_ffi.a',
|
|
192
|
+
'android/src/main/x86_64/libddk_ffi.a'
|
|
193
|
+
];
|
|
194
|
+
|
|
195
|
+
let androidLibsPresent = 0;
|
|
196
|
+
for (const lib of androidLibs) {
|
|
197
|
+
const libPath = path.join(packageRoot, lib);
|
|
198
|
+
if (fs.existsSync(libPath)) {
|
|
199
|
+
console.log(` ā
${lib}`);
|
|
200
|
+
androidLibsPresent++;
|
|
201
|
+
} else {
|
|
202
|
+
console.log(` ā ļø Missing: ${lib}`);
|
|
212
203
|
}
|
|
213
204
|
}
|
|
214
205
|
|
|
215
|
-
|
|
216
|
-
|
|
206
|
+
if (androidLibsPresent === 0) {
|
|
207
|
+
console.log(' ā ļø No Android libraries found (may be due to missing NDK)');
|
|
208
|
+
} else {
|
|
209
|
+
console.log(` ā
Found ${androidLibsPresent}/${androidLibs.length} Android libraries`);
|
|
210
|
+
}
|
|
217
211
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
212
|
+
return allFilesPresent;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function main() {
|
|
216
|
+
// Skip in CI unless explicitly requested
|
|
217
|
+
if (process.env.CI && !process.env.GENERATE_BINDINGS) {
|
|
218
|
+
console.log('ā ļø Skipping binding generation in CI environment.');
|
|
219
|
+
console.log(' Set GENERATE_BINDINGS=1 to force generation in CI.');
|
|
220
|
+
process.exit(0);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Check prerequisites
|
|
224
|
+
if (!hasUniffiBingen()) {
|
|
225
|
+
console.error('ā uniffi-bindgen-react-native not found!');
|
|
226
|
+
console.error(' Install it with: npm install -g uniffi-bindgen-react-native');
|
|
227
|
+
console.error(' Or add it as a dependency in your project.');
|
|
222
228
|
process.exit(1);
|
|
223
229
|
}
|
|
224
230
|
|
|
225
|
-
|
|
226
|
-
|
|
231
|
+
// Verify source files are present (should be included in NPM package)
|
|
232
|
+
const sourceFiles = [
|
|
233
|
+
'src/ddk_ffi.ts',
|
|
234
|
+
'src/ddk_ffi-ffi.ts',
|
|
235
|
+
'cpp/ddk_ffi.hpp',
|
|
236
|
+
'cpp/ddk_ffi.cpp'
|
|
237
|
+
];
|
|
238
|
+
|
|
239
|
+
console.log('š Checking source files...');
|
|
240
|
+
for (const file of sourceFiles) {
|
|
241
|
+
const filePath = path.join(packageRoot, file);
|
|
242
|
+
if (!fs.existsSync(filePath)) {
|
|
243
|
+
console.error(`ā Missing source file: ${file}`);
|
|
244
|
+
console.error(' This indicates a problem with the NPM package.');
|
|
245
|
+
process.exit(1);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
console.log('ā
All source files present');
|
|
249
|
+
|
|
250
|
+
try {
|
|
251
|
+
// Generate turbo module and build native libraries from existing JSI bindings
|
|
252
|
+
generateTurboModule();
|
|
253
|
+
fixCppIncludePath();
|
|
254
|
+
buildIOS();
|
|
255
|
+
buildAndroid();
|
|
256
|
+
|
|
257
|
+
// Verify all files are present
|
|
258
|
+
const allFilesPresent = verifyAllFiles();
|
|
259
|
+
|
|
260
|
+
if (!allFilesPresent) {
|
|
261
|
+
console.error('\nā Some required files are missing!');
|
|
262
|
+
console.error('The installation may have failed.');
|
|
263
|
+
process.exit(1);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
console.log('\nā
All files installed successfully!');
|
|
267
|
+
console.log('š DDK-RN is ready to use!\n');
|
|
268
|
+
|
|
269
|
+
} catch (error) {
|
|
270
|
+
console.error('\nā Failed to complete installation:', error.message);
|
|
271
|
+
console.error('');
|
|
272
|
+
console.error('š This may be due to:');
|
|
273
|
+
console.error(' - Missing uniffi-bindgen-react-native (install globally)');
|
|
274
|
+
console.error(' - Missing Android NDK (for Android builds)');
|
|
275
|
+
console.error(' - Missing Xcode/iOS toolchain (for iOS builds on macOS)');
|
|
276
|
+
console.error('');
|
|
277
|
+
console.error('Report issues at: https://github.com/bennyhodl/ddk-ffi/issues');
|
|
278
|
+
process.exit(1);
|
|
279
|
+
}
|
|
227
280
|
}
|
|
228
281
|
|
|
229
282
|
// Run the main function
|