@bennyblader/ddk-rn 0.3.42 → 0.4.0

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.
Files changed (46) hide show
  1. package/DdkRn.podspec +1 -1
  2. package/README.md +14 -0
  3. package/android/CMakeLists.txt +6 -3
  4. package/android/build.gradle +0 -1
  5. package/android/cpp-adapter.cpp +6 -26
  6. package/android/src/main/jniLibs/arm64-v8a/libddk_ffi.so +0 -0
  7. package/android/src/main/jniLibs/armeabi-v7a/libddk_ffi.so +0 -0
  8. package/android/src/main/jniLibs/x86/libddk_ffi.so +0 -0
  9. package/android/src/main/jniLibs/x86_64/libddk_ffi.so +0 -0
  10. package/cpp/bennyblader-ddk-rn.cpp +1 -1
  11. package/cpp/ddk_ffi.cpp +2361 -2671
  12. package/cpp/ddk_ffi.hpp +86 -255
  13. package/ios/DdkRn.xcframework/Info.plist +43 -0
  14. package/ios/DdkRn.xcframework/ios-arm64/libddk_ffi.a +0 -0
  15. package/ios/DdkRn.xcframework/ios-arm64-simulator/libddk_ffi.a +0 -0
  16. package/lib/commonjs/ddk_ffi-ffi.js +6 -29
  17. package/lib/commonjs/ddk_ffi-ffi.js.map +1 -1
  18. package/lib/commonjs/ddk_ffi.js +961 -944
  19. package/lib/commonjs/ddk_ffi.js.map +1 -1
  20. package/lib/module/ddk_ffi-ffi.js +6 -29
  21. package/lib/module/ddk_ffi-ffi.js.map +1 -1
  22. package/lib/module/ddk_ffi.js +924 -896
  23. package/lib/module/ddk_ffi.js.map +1 -1
  24. package/lib/typescript/commonjs/src/ddk_ffi-ffi.d.ts +71 -96
  25. package/lib/typescript/commonjs/src/ddk_ffi-ffi.d.ts.map +1 -1
  26. package/lib/typescript/commonjs/src/ddk_ffi.d.ts +500 -471
  27. package/lib/typescript/commonjs/src/ddk_ffi.d.ts.map +1 -1
  28. package/lib/typescript/module/src/ddk_ffi-ffi.d.ts +71 -96
  29. package/lib/typescript/module/src/ddk_ffi-ffi.d.ts.map +1 -1
  30. package/lib/typescript/module/src/ddk_ffi.d.ts +500 -471
  31. package/lib/typescript/module/src/ddk_ffi.d.ts.map +1 -1
  32. package/package.json +8 -38
  33. package/src/ddk_ffi-ffi.ts +419 -170
  34. package/src/ddk_ffi.ts +2648 -1939
  35. package/ubrn.config.yaml +18 -1
  36. package/ddk-ffi/Cargo.lock +0 -1013
  37. package/ddk-ffi/Cargo.toml +0 -36
  38. package/ddk-ffi/build.rs +0 -3
  39. package/ddk-ffi/rust-toolchain.toml +0 -10
  40. package/ddk-ffi/src/ddk_ffi.udl +0 -376
  41. package/ddk-ffi/src/lib.rs +0 -2509
  42. package/ddk-ffi/src/uniffi-bindgen.rs +0 -3
  43. package/ddk-ffi/uniffi.toml +0 -18
  44. package/scripts/apply-hotfix.js +0 -96
  45. package/scripts/postinstall.js +0 -298
  46. package/scripts/prepare-rust-src.js +0 -51
@@ -1,3 +0,0 @@
1
- fn main() {
2
- uniffi::uniffi_bindgen_main()
3
- }
@@ -1,18 +0,0 @@
1
- # uniffi.toml
2
- [bindings.typescript]
3
- logLevel = "verbose"
4
-
5
- [bindings.cpp]
6
-
7
- [turbo_module]
8
- # The name of your Turbo Module as it appears in React Native
9
- name = "Ddk"
10
- # The iOS framework name
11
- ios_framework = "Ddk"
12
- # The Android package name
13
- android_package = "dev.bennyblader.ddk"
14
-
15
- [namespace.ddk_ffi]
16
- # Configuration specific to your ddk_ffi namespace
17
- # This tells the generator how to handle this particular namespace
18
- js_module_name = "Ddk"
@@ -1,96 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { execSync } = require('child_process');
6
-
7
- const ddkRnRoot = path.join(__dirname, '..');
8
- const projectRoot = path.join(ddkRnRoot, '..');
9
-
10
- function runCommand(command, cwd = projectRoot, options = {}) {
11
- const { silent = false } = options;
12
- try {
13
- const result = execSync(command, {
14
- cwd,
15
- stdio: silent ? 'pipe' : 'inherit',
16
- encoding: 'utf8',
17
- });
18
- return result;
19
- } catch (error) {
20
- if (!silent) {
21
- console.error(`āŒ Command failed: ${command}`);
22
- }
23
- throw error;
24
- }
25
- }
26
-
27
- function applyHotFix() {
28
- console.log('šŸ”§ Applying post-build hot fixes...');
29
-
30
- const cppFile = path.join(ddkRnRoot, 'cpp', 'bennyblader-ddk-rn.cpp');
31
- const podspecFile = path.join(ddkRnRoot, 'DdkRn.podspec');
32
-
33
- // Fix 1: C++ include path
34
- if (fs.existsSync(cppFile)) {
35
- let cppContent = fs.readFileSync(cppFile, 'utf8');
36
- if (cppContent.includes('#include "/ddk_ffi.hpp"')) {
37
- cppContent = cppContent.replace(
38
- '#include "/ddk_ffi.hpp"',
39
- '#include "ddk_ffi.hpp"'
40
- );
41
- fs.writeFileSync(cppFile, cppContent);
42
- console.log(' āœ… Fixed include path in bennyblader-ddk-rn.cpp');
43
- } else {
44
- console.log(' āœ… Include path already correct');
45
- }
46
- }
47
-
48
- // Fix 2: Add back xcconfig LIBRARY_SEARCH_PATHS to podspec (gets removed by uniffi build)
49
- if (fs.existsSync(podspecFile)) {
50
- let podspecContent = fs.readFileSync(podspecFile, 'utf8');
51
-
52
- // Check if xcconfig is missing
53
- if (
54
- !podspecContent.includes('s.xcconfig = {') &&
55
- !podspecContent.includes('LIBRARY_SEARCH_PATHS')
56
- ) {
57
- // Find the line with s.vendored_frameworks and add xcconfig after it
58
- const vendoredFrameworksLine =
59
- 's.vendored_frameworks = "ios/DdkRn.xcframework"';
60
- if (podspecContent.includes(vendoredFrameworksLine)) {
61
- const xconfigBlock = ` s.xcconfig = {
62
- 'LIBRARY_SEARCH_PATHS' => '$(SRCROOT)/../node_modules/@bennyblader/ddk-rn/ios/DdkRn.xcframework/ios-arm64-simulator $(SRCROOT)/../node_modules/@bennyblader/ddk-rn/ios/DdkRn.xcframework/ios-arm64 $(SRCROOT)/../node_modules/@bennyblader/ddk-rn/ios/DdkRn.xcframework/ios-x86_64-simulator $(SRCROOT)/../node_modules/@bennyblader/ddk-rn/ios/DdkRn.xcframework/ios-x86_64'
63
- }`;
64
-
65
- podspecContent = podspecContent.replace(
66
- vendoredFrameworksLine,
67
- vendoredFrameworksLine + '\n' + xconfigBlock
68
- );
69
-
70
- fs.writeFileSync(podspecFile, podspecContent);
71
- console.log(
72
- ' āœ… Added back xcconfig LIBRARY_SEARCH_PATHS to DdkRn.podspec'
73
- );
74
- } else {
75
- console.log(
76
- ' āš ļø Could not find vendored_frameworks line in podspec'
77
- );
78
- }
79
- } else {
80
- console.log(' āœ… DdkRn.podspec already has xcconfig');
81
- }
82
- }
83
-
84
- console.log(' āœ… Hot fixes applied and files unstaged');
85
- console.log();
86
- }
87
-
88
- // Export for use in other scripts
89
- module.exports = { applyHotFix };
90
-
91
- // Allow running directly
92
- if (require.main === module) {
93
- console.log('šŸ”§ Running hot fix script...\n');
94
- applyHotFix();
95
- console.log('āœ… Hot fix completed!\n');
96
- }
@@ -1,298 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { execSync } = require('child_process');
6
-
7
- const packageRoot = path.join(__dirname, '..');
8
- const ddkFfiRoot = path.join(packageRoot, 'ddk-ffi');
9
-
10
- console.log('šŸ“¦ DDK-RN Post-install: Building native libraries...');
11
-
12
- // Check if uniffi-bindgen-react-native is available (prefer npx)
13
- function hasUniffiBingen() {
14
- try {
15
- execSync('npx uniffi-bindgen-react-native --help', { stdio: 'ignore' });
16
- return true;
17
- } catch (error) {
18
- try {
19
- execSync('uniffi-bindgen-react-native --help', { stdio: 'ignore' });
20
- return true;
21
- } catch (error2) {
22
- return false;
23
- }
24
- }
25
- }
26
-
27
- // Get the uniffi command (prefer npx)
28
- function getUniffiCommand() {
29
- try {
30
- execSync('npx uniffi-bindgen-react-native --help', { stdio: 'ignore' });
31
- return 'npx uniffi-bindgen-react-native';
32
- } catch (error) {
33
- return 'uniffi-bindgen-react-native';
34
- }
35
- }
36
-
37
- // Create directories if they don't exist
38
- function ensureDir(dir) {
39
- if (!fs.existsSync(dir)) {
40
- fs.mkdirSync(dir, { recursive: true });
41
- }
42
- }
43
-
44
- // Build iOS libraries and create XCFramework
45
- function buildIOS() {
46
- const platform = process.platform;
47
-
48
- if (platform !== 'darwin') {
49
- console.log('\nāš ļø Skipping iOS build (not on macOS)');
50
- return;
51
- }
52
-
53
- console.log('\nšŸŽ Building iOS libraries...');
54
- const uniffiCmd = getUniffiCommand();
55
-
56
- // Update ubrn.config.yaml to point to the included Rust source
57
- updateConfigFile();
58
-
59
- try {
60
- const cmd = `${uniffiCmd} build ios --and-generate`;
61
- console.log(`Running: ${cmd}`);
62
- execSync(cmd, {
63
- stdio: 'inherit',
64
- cwd: packageRoot
65
- });
66
- console.log('āœ… iOS libraries built');
67
- } catch (error) {
68
- throw new Error(`Failed to build iOS libraries: ${error.message}`);
69
- }
70
- }
71
-
72
- // Build Android libraries
73
- function buildAndroid() {
74
- console.log('\nšŸ“± Building Android libraries...');
75
-
76
- // Check if Android NDK is available
77
- if (!process.env.ANDROID_NDK_ROOT && !process.env.NDK_HOME) {
78
- console.log('āš ļø Android NDK not found. Skipping Android build.');
79
- console.log(' Set ANDROID_NDK_ROOT or NDK_HOME to build Android libraries.');
80
- return;
81
- }
82
-
83
- const uniffiCmd = getUniffiCommand();
84
-
85
- // Update ubrn.config.yaml to point to the included Rust source
86
- updateConfigFile();
87
-
88
- try {
89
- const cmd = `${uniffiCmd} build android --and-generate`;
90
- console.log(`Running: ${cmd}`);
91
- execSync(cmd, {
92
- stdio: 'inherit',
93
- cwd: packageRoot
94
- });
95
- console.log('āœ… Android libraries built');
96
- } catch (error) {
97
- console.warn(`āš ļø Android build failed: ${error.message}`);
98
- console.warn(' This may be due to missing Android NDK or Rust toolchains.');
99
- }
100
- }
101
-
102
- // Update the ubrn.config.yaml to use the local Rust source
103
- function updateConfigFile() {
104
- const configPath = path.join(packageRoot, 'ubrn.config.yaml');
105
-
106
- if (fs.existsSync(configPath)) {
107
- let config = fs.readFileSync(configPath, 'utf8');
108
-
109
- // Update the Rust directory to point to the included ddk-ffi
110
- if (!config.includes('directory: ddk-ffi')) {
111
- config = config.replace(
112
- /rust:\s*\n\s*directory:\s*[^\n]+/,
113
- 'rust:\n directory: ddk-ffi'
114
- );
115
- fs.writeFileSync(configPath, config);
116
- console.log('šŸ“ Updated config to use included Rust source');
117
- }
118
- }
119
- }
120
-
121
- // Fix the C++ include path issue if needed
122
- function fixCppIncludePath() {
123
- const cppFile = path.join(packageRoot, 'cpp', 'bennyblader-ddk-rn.cpp');
124
- if (fs.existsSync(cppFile)) {
125
- let content = fs.readFileSync(cppFile, 'utf8');
126
- if (content.includes('#include "/ddk_ffi.hpp"')) {
127
- content = content.replace('#include "/ddk_ffi.hpp"', '#include "ddk_ffi.hpp"');
128
- fs.writeFileSync(cppFile, content);
129
- console.log('šŸ”§ Fixed include path in C++ bindings');
130
- }
131
- }
132
- }
133
-
134
- // Verify all required files are present
135
- function verifyAllFiles() {
136
- console.log('\nšŸ” Verifying installation...');
137
-
138
- const requiredFiles = [
139
- // Core JSI bindings (shipped with package)
140
- 'src/ddk_ffi.ts',
141
- 'src/ddk_ffi-ffi.ts',
142
- 'cpp/ddk_ffi.hpp',
143
- 'cpp/ddk_ffi.cpp',
144
- // Generated turbo module files (shipped with package)
145
- 'src/NativeDdkRn.ts',
146
- 'src/index.tsx',
147
- 'cpp/bennyblader-ddk-rn.cpp',
148
- 'cpp/bennyblader-ddk-rn.h',
149
- // Rust source (shipped with package)
150
- 'ddk-ffi/Cargo.toml',
151
- 'ddk-ffi/src/lib.rs',
152
- 'ddk-ffi/src/ddk_ffi.udl'
153
- ];
154
-
155
- const platform = process.platform;
156
- let allFilesPresent = true;
157
-
158
- // Check required files
159
- console.log('šŸ“‹ Checking required files...');
160
- for (const file of requiredFiles) {
161
- const filePath = path.join(packageRoot, file);
162
- if (fs.existsSync(filePath)) {
163
- console.log(` āœ… ${file}`);
164
- } else {
165
- console.error(` āŒ Missing: ${file}`);
166
- allFilesPresent = false;
167
- }
168
- }
169
-
170
- // Check platform-specific files (generated during postinstall)
171
- if (platform === 'darwin') {
172
- console.log('šŸ“‹ Checking iOS framework...');
173
- const iosFramework = path.join(packageRoot, 'ios', 'DdkRn.xcframework', 'Info.plist');
174
- if (fs.existsSync(iosFramework)) {
175
- console.log(` āœ… ios/DdkRn.xcframework`);
176
- } else {
177
- console.log(` āš ļø iOS framework not built yet (will be built now)`);
178
- }
179
- }
180
-
181
- console.log('šŸ“‹ Checking Android libraries...');
182
- const androidLibs = [
183
- 'android/src/main/arm64-v8a/libddk_ffi.a',
184
- 'android/src/main/armeabi-v7a/libddk_ffi.a',
185
- 'android/src/main/x86/libddk_ffi.a',
186
- 'android/src/main/x86_64/libddk_ffi.a'
187
- ];
188
-
189
- let androidLibsPresent = 0;
190
- for (const lib of androidLibs) {
191
- const libPath = path.join(packageRoot, lib);
192
- if (fs.existsSync(libPath)) {
193
- androidLibsPresent++;
194
- }
195
- }
196
-
197
- if (androidLibsPresent === 0) {
198
- console.log(' āš ļø Android libraries not built yet (may be due to missing NDK)');
199
- } else {
200
- console.log(` āœ… Found ${androidLibsPresent}/${androidLibs.length} Android libraries`);
201
- }
202
-
203
- return allFilesPresent;
204
- }
205
-
206
- async function main() {
207
- // Skip in CI unless explicitly requested
208
- if (process.env.CI && !process.env.BUILD_NATIVE_LIBS) {
209
- console.log('āš ļø Skipping native library builds in CI environment.');
210
- console.log(' Set BUILD_NATIVE_LIBS=1 to force builds in CI.');
211
- process.exit(0);
212
- }
213
-
214
- // Check prerequisites
215
- if (!hasUniffiBingen()) {
216
- console.error('āŒ uniffi-bindgen-react-native not found!');
217
- console.error(' Install it with: npm install -g uniffi-bindgen-react-native');
218
- console.error(' Or add it as a dependency in your project.');
219
- process.exit(1);
220
- }
221
-
222
- // Check if Rust source is included
223
- if (!fs.existsSync(ddkFfiRoot)) {
224
- console.error('āŒ Rust source not found in package!');
225
- console.error(` Expected at: ${ddkFfiRoot}`);
226
- console.error(' This indicates a problem with the NPM package.');
227
- process.exit(1);
228
- }
229
-
230
- // Verify source files are present (should be included in NPM package)
231
- const sourceFiles = [
232
- 'src/ddk_ffi.ts',
233
- 'src/ddk_ffi-ffi.ts',
234
- 'src/NativeDdkRn.ts',
235
- 'src/index.tsx',
236
- 'cpp/ddk_ffi.hpp',
237
- 'cpp/ddk_ffi.cpp',
238
- 'cpp/bennyblader-ddk-rn.cpp',
239
- 'cpp/bennyblader-ddk-rn.h',
240
- 'ddk-ffi/Cargo.toml',
241
- 'ddk-ffi/src/lib.rs',
242
- 'ddk-ffi/src/ddk_ffi.udl'
243
- ];
244
-
245
- console.log('šŸ” Checking source files...');
246
- for (const file of sourceFiles) {
247
- const filePath = path.join(packageRoot, file);
248
- if (!fs.existsSync(filePath)) {
249
- console.error(`āŒ Missing source file: ${file}`);
250
- console.error(' This indicates a problem with the NPM package.');
251
- process.exit(1);
252
- }
253
- }
254
- console.log('āœ… All source files present');
255
-
256
- try {
257
- // Fix include path if needed
258
- fixCppIncludePath();
259
-
260
- // Build native libraries only (turbo module already generated)
261
- buildIOS();
262
- buildAndroid();
263
-
264
- // Apply hot fixes after all generation steps
265
- const { applyHotFix } = require('./apply-hotfix.js');
266
- applyHotFix();
267
-
268
- // Verify all files are present
269
- const allFilesPresent = verifyAllFiles();
270
-
271
- if (!allFilesPresent) {
272
- console.error('\nāŒ Some required files are missing!');
273
- console.error('The installation may have failed.');
274
- process.exit(1);
275
- }
276
-
277
- console.log('\nāœ… Installation completed successfully!');
278
- console.log('šŸŽ‰ DDK-RN is ready to use!\n');
279
-
280
- } catch (error) {
281
- console.error('\nāŒ Failed to complete installation:', error.message);
282
- console.error('');
283
- console.error('šŸ“‹ This may be due to:');
284
- console.error(' - Missing uniffi-bindgen-react-native (install globally)');
285
- console.error(' - Missing Android NDK (for Android builds)');
286
- console.error(' - Missing Xcode/iOS toolchain (for iOS builds on macOS)');
287
- console.error(' - Missing Rust toolchain');
288
- console.error('');
289
- console.error('Report issues at: https://github.com/bennyhodl/ddk-ffi/issues');
290
- process.exit(1);
291
- }
292
- }
293
-
294
- // Run the main function
295
- main().catch(error => {
296
- console.error('āŒ Unexpected error:', error);
297
- process.exit(1);
298
- });
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { execSync } = require('child_process');
6
-
7
- const ddkRnRoot = path.join(__dirname, '..');
8
- const projectRoot = path.join(ddkRnRoot, '..');
9
- const ddkFfiSource = path.join(projectRoot, 'ddk-ffi');
10
- const ddkFfiDest = path.join(ddkRnRoot, 'ddk-ffi');
11
-
12
- console.log('šŸ“¦ Preparing Rust source for npm package...');
13
-
14
- function copyDirectory(src, dest) {
15
- // Remove existing destination if it exists
16
- if (fs.existsSync(dest)) {
17
- console.log(`šŸ—‘ļø Removing existing ${path.basename(dest)}...`);
18
- execSync(`rm -rf "${dest}"`, { stdio: 'inherit' });
19
- }
20
-
21
- // Create destination directory
22
- fs.mkdirSync(dest, { recursive: true });
23
-
24
- // Copy all files except target directory
25
- console.log(`šŸ“‹ Copying ${path.basename(src)} to ${path.basename(dest)}...`);
26
- execSync(`rsync -av --exclude=target/ --exclude=.git/ "${src}/" "${dest}/"`, {
27
- stdio: 'inherit'
28
- });
29
- }
30
-
31
- function main() {
32
- try {
33
- // Check if source exists
34
- if (!fs.existsSync(ddkFfiSource)) {
35
- console.error(`āŒ Source directory not found: ${ddkFfiSource}`);
36
- process.exit(1);
37
- }
38
-
39
- // Copy the Rust source
40
- copyDirectory(ddkFfiSource, ddkFfiDest);
41
-
42
- console.log('āœ… Rust source prepared for npm package');
43
- console.log(`šŸ“ Location: ${ddkFfiDest}`);
44
-
45
- } catch (error) {
46
- console.error('āŒ Failed to prepare Rust source:', error.message);
47
- process.exit(1);
48
- }
49
- }
50
-
51
- main();