generated from napi-rs/package-template
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathload-native.cjs
101 lines (93 loc) · 2.5 KB
/
load-native.cjs
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
const fs = require('node:fs');
const { platform, arch } = process;
let nativeBinding = null;
let loadError = null;
switch (platform) {
case 'win32':
switch (arch) {
case 'x64':
try {
nativeBinding = require('./node-web-audio-api.win32-x64-msvc.node');
} catch (e) {
loadError = e;
}
break;
case 'arm64':
try {
nativeBinding = require('./node-web-audio-api.win32-arm64-msvc.node');
} catch (e) {
loadError = e;
}
break;
default:
loadError = new Error(`Unsupported architecture on Windows: ${arch}`);
}
break;
case 'darwin':
switch (arch) {
case 'x64':
try {
nativeBinding = require('./node-web-audio-api.darwin-x64.node');
} catch (e) {
loadError = e;
}
break;
case 'arm64':
try {
nativeBinding = require('./node-web-audio-api.darwin-arm64.node');
} catch (e) {
loadError = e;
}
break;
default:
loadError = new Error(`Unsupported architecture on macOS: ${arch}`);
}
break;
// case 'freebsd': x64 only
case 'linux':
switch (arch) {
// @todo
// - support riscv64 arch
// - support musl C lib
case 'x64':
try {
nativeBinding = require('./node-web-audio-api.linux-x64-gnu.node');
} catch (e) {
loadError = e;
}
break;
case 'arm64':
try {
nativeBinding = require('./node-web-audio-api.linux-arm64-gnu.node');
} catch (e) {
loadError = e;
}
break;
case 'arm':
try {
nativeBinding = require('./node-web-audio-api.linux-arm-gnueabihf.node');
} catch (e) {
loadError = e;
}
break;
default:
loadError = new Error(`Unsupported architecture on Linux: ${arch}`);
}
break;
default:
loadError = new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
}
// use local build if exists
if (fs.existsSync('node-web-audio-api.build-release.node')) {
nativeBinding = require('./node-web-audio-api.build-release.node');
}
if (fs.existsSync('node-web-audio-api.build-debug.node')) {
nativeBinding = require('./node-web-audio-api.build-debug.node');
}
if (!nativeBinding) {
if (loadError) {
throw loadError;
}
throw new Error(`Failed to load native binding for OS: ${platform}, architecture: ${arch}`);
}
module.exports = nativeBinding;