aboutsummaryrefslogtreecommitdiff
path: root/bundle/scripts/prepare-compiler.js
blob: 8568ae952bc805d83e6081c0dfb70472f971bce0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

import { execFileSync } from 'node:child_process';
import { copyFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { gzipSync } from 'node:zlib';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const root = fileURLToPath(new URL('..', import.meta.url));
const target = execFileSync('rustc', ['--print', 'host-tuple'], { encoding: 'utf8' }).trim();
const extension = process.platform === 'win32' ? '.exe' : '';
const source = path.resolve(process.argv[2] || path.join(root, '..', 'build', `cpsc${extension}`));
const destination = path.join(root, 'src-tauri', 'binaries', process.platform === 'win32' ? 'cpsc.exe.gz' : `cpsc-${target}${extension}`);
mkdirSync(path.dirname(destination), { recursive: true });
if (process.platform === 'win32') {
	writeFileSync(destination, gzipSync(readFileSync(source)));
} else {
	copyFileSync(source, destination);
}
console.log(`Bundled compiler: ${source}`);