-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.plugin.js
More file actions
73 lines (64 loc) · 2.1 KB
/
app.plugin.js
File metadata and controls
73 lines (64 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const { withDangerousMod, withPlugins } = require('@expo/config-plugins')
const path = require('path')
const fs = require('fs')
function getPackageRoot() {
const pkgJson = require.resolve('react-native-qdrant-edge/package.json')
return path.dirname(pkgJson)
}
function buildRustIfMissing(libPath, buildScriptName, platform) {
if (fs.existsSync(libPath)) return
let pkgRoot
try {
pkgRoot = getPackageRoot()
} catch {
console.warn(`[react-native-qdrant-edge] Could not resolve package root.`)
return
}
const buildScript = path.join(pkgRoot, 'scripts', buildScriptName)
if (!fs.existsSync(buildScript)) {
console.warn(
`[react-native-qdrant-edge] ${platform} Rust libs not found and build script missing.`
)
return
}
console.log(
`[react-native-qdrant-edge] ${platform} Rust libraries not found. Building...`
)
const { execSync } = require('child_process')
try {
execSync(`bash "${buildScript}"`, { stdio: 'inherit', cwd: pkgRoot })
} catch {
console.warn(
`[react-native-qdrant-edge] ${platform} Rust build failed. ` +
`Run manually: cd node_modules/react-native-qdrant-edge && npm run rust:build:${platform.toLowerCase()}`
)
}
}
function withQdrantEdgeIOS(config) {
return withDangerousMod(config, [
'ios',
async (config) => {
let pkgRoot
try { pkgRoot = getPackageRoot() } catch { return config }
const libPath = path.join(pkgRoot, 'ios', 'Libs', 'qdrant_edge_ffi.xcframework')
buildRustIfMissing(libPath, 'build-ios.sh', 'iOS')
return config
},
])
}
function withQdrantEdgeAndroid(config) {
return withDangerousMod(config, [
'android',
async (config) => {
let pkgRoot
try { pkgRoot = getPackageRoot() } catch { return config }
const libPath = path.join(pkgRoot, 'android', 'src', 'main', 'jniLibs', 'arm64-v8a', 'libqdrant_edge_ffi.a')
buildRustIfMissing(libPath, 'build-android.sh', 'Android')
return config
},
])
}
function withQdrantEdge(config) {
return withPlugins(config, [withQdrantEdgeIOS, withQdrantEdgeAndroid])
}
module.exports = withQdrantEdge