-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
104 lines (97 loc) · 2.45 KB
/
index.js
File metadata and controls
104 lines (97 loc) · 2.45 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* index.js */
const { existsSync, readFileSync } = require('fs')
const { join } = require('path')
const { platform, arch } = process
let nativeBinding = null
let localFileExisted = false
let loadError = null
function isMusl() {
// Simple check for Musl/Alpine Linux
try {
return readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
} catch (e) {
return true
}
}
switch (platform) {
case 'android':
if (arch === 'arm64') {
try {
nativeBinding = require('./iris.android-arm64.node')
} catch (e) {
loadError = e
}
} else if (arch === 'arm') {
try {
nativeBinding = require('./iris.android-arm-eabi.node')
} catch (e) {
loadError = e
}
}
break
case 'win32':
if (arch === 'x64') {
try {
nativeBinding = require('./iris.win32-x64-msvc.node')
} catch (e) {
loadError = e
}
}
break
case 'darwin':
try {
nativeBinding = require('./iris.darwin-universal.node')
} catch (e) {
// Fallback for specific archs if universal not found
if (arch === 'x64') {
nativeBinding = require('./iris.darwin-x64.node')
} else if (arch === 'arm64') {
nativeBinding = require('./iris.darwin-arm64.node')
}
}
break
case 'linux':
if (arch === 'x64') {
if (isMusl()) {
try {
nativeBinding = require('./iris.linux-x64-musl.node')
} catch (e) {
loadError = e
}
} else {
try {
nativeBinding = require('./iris.linux-x64-gnu.node')
} catch (e) {
loadError = e
}
}
} else if (arch === 'arm64') {
if (isMusl()) {
try {
nativeBinding = require('./iris.linux-arm64-musl.node')
} catch (e) {
loadError = e
}
} else {
try {
nativeBinding = require('./iris.linux-arm64-gnu.node')
} catch (e) {
loadError = e
}
}
}
break
default:
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
}
if (!nativeBinding) {
if (loadError) {
throw loadError
}
throw new Error(`Failed to load native binding`)
}
const { NodeRuntime, JsMailbox, WrappedMessage, JsSystemMessage } = nativeBinding
module.exports.NodeRuntime = NodeRuntime
module.exports.JsMailbox = JsMailbox
module.exports.WrappedMessage = WrappedMessage
module.exports.JsSystemMessage = JsSystemMessage