forked from vlcn-io/cr-sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-macros.ts
More file actions
38 lines (33 loc) · 1.16 KB
/
build-macros.ts
File metadata and controls
38 lines (33 loc) · 1.16 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
import { execSync } from 'child_process';
import { existsSync } from 'fs';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
// Bun macro to get the CR-SQLite extension path at build time
export function getCRSQLiteExtensionPath() {
// 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 extension
const libDir = resolve(currentDir, 'lib');
// Try platform-specific extension names
const candidates = [
resolve(libDir, 'crsqlite.dylib'), // macOS
resolve(libDir, 'crsqlite.so'), // Linux
];
for (const candidate of candidates) {
if (existsSync(candidate)) {
return candidate;
}
}
// If no bundled extension, 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('CR-SQLite extension not found. Run `bun run bundle-lib` first.');
}
}