45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import { copyFileSync, existsSync, mkdirSync } from 'fs';
|
|
import { execSync } from 'child_process';
|
|
import { dirname, join } from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import { platform, arch } from 'os';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const projectRoot = join(__dirname, '..');
|
|
const repoRoot = join(projectRoot, '..', '..');
|
|
|
|
function isMusl() {
|
|
if (platform() !== 'linux') return false;
|
|
try {
|
|
const result = execSync('ldd --version 2>&1 || true', { encoding: 'utf8' });
|
|
return result.toLowerCase().includes('musl');
|
|
} catch {
|
|
return existsSync('/lib/ld-musl-x86_64.so.1') || existsSync('/lib/ld-musl-aarch64.so.1');
|
|
}
|
|
}
|
|
|
|
const sourceExt = platform() === 'win32' ? '.exe' : '';
|
|
const sourcePath = join(repoRoot, `zig-out/bin/native${sourceExt}`);
|
|
const binDir = join(projectRoot, 'bin');
|
|
|
|
const osKey = platform() === 'linux' && isMusl() ? 'linux-musl' : platform();
|
|
const platformKey = `${osKey}-${arch()}`;
|
|
const ext = platform() === 'win32' ? '.exe' : '';
|
|
const targetName = `native-sdk-${platformKey}${ext}`;
|
|
const targetPath = join(binDir, targetName);
|
|
|
|
if (!existsSync(sourcePath)) {
|
|
console.error(`Error: Native binary not found at ${sourcePath}`);
|
|
console.error('Run "zig build" from the repo root first');
|
|
process.exit(1);
|
|
}
|
|
|
|
if (!existsSync(binDir)) {
|
|
mkdirSync(binDir, { recursive: true });
|
|
}
|
|
|
|
copyFileSync(sourcePath, targetPath);
|
|
console.log(`✓ Copied native binary to ${targetPath}`);
|