-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-macros.ts
More file actions
39 lines (34 loc) · 1.2 KB
/
build-macros.ts
File metadata and controls
39 lines (34 loc) · 1.2 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
import { execSync } from 'child_process';
import { existsSync } from 'fs';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
// Bun macro to get the SQLite library path at build time
export function getSQLiteLibPath() {
// Get directory - works in both Bun (import.meta.dir) and Node.js
const currentDir = typeof import.meta.dir !== 'undefined'
? import.meta.dir
: dirname(fileURLToPath(import.meta.url));
// Check if we already have a bundled library
const libDir = resolve(currentDir, 'lib');
// Try platform-specific library names
const candidates = [
resolve(libDir, 'libsqlite3.dylib'), // macOS
resolve(libDir, 'libsqlite3.so'), // Linux
resolve(libDir, 'libsqlite3.0.dylib'), // macOS versioned
];
for (const candidate of candidates) {
if (existsSync(candidate)) {
return candidate;
}
}
// If no bundled lib, try to get it from Nix (dev environment)
try {
const result = execSync('nix run .#print-path', {
encoding: 'utf8',
cwd: currentDir
});
return result.trim();
} catch (error) {
throw new Error('SQLite library not found. Run `bun run bundle-lib` first.');
}
}