Skip to content

🎥 Make videos programmatically with React

build script in JS

Jonny Burgera7955af35769
diff --git a/packages/renderer/build.mjs b/packages/renderer/build.mjs
index d5483d9b8a..8006b6ad59 100644
--- a/packages/renderer/build.mjs
+++ b/packages/renderer/build.mjs
@@ -4,6 +4,69 @@ import os from 'os';
const isWin = os.platform() === 'win32';
const where = isWin ? 'where' : 'which';
+function isMusl() {
+ const {glibcVersionRuntime} = process.report.getReport().header;
+ return !glibcVersionRuntime;
+}
+
+const targets = [
+ 'x86_64-pc-windows-gnu',
+ 'x86_64-apple-darwin',
+ 'aarch64-apple-darwin',
+ 'x86_64-unknown-linux-musl',
+ 'x86_64-unknown-linux-gnu',
+ 'aarch64-unknown-linux-musl',
+ 'aarch64-unknown-linux-gnu',
+];
+
+export const getTarget = () => {
+ switch (process.platform) {
+ case 'win32':
+ switch (process.arch) {
+ case 'x64':
+ return 'x86_64-pc-windows-gnu';
+ default:
+ throw new Error(
+ `Unsupported architecture on Windows: ${process.arch}`
+ );
+ }
+
+ case 'darwin':
+ switch (process.arch) {
+ case 'x64':
+ return 'x86_64-apple-darwin';
+ case 'arm64':
+ return 'aarch64-apple-darwin';
+ default:
+ throw new Error(`Unsupported architecture on macOS: ${process.arch}`);
+ }
+
+ case 'linux':
+ switch (process.arch) {
+ case 'x64':
+ if (isMusl()) {
+ return 'x86_64-unknown-linux-musl';
+ }
+
+ return 'x86_64-unknown-linux-gnu';
+ case 'arm64':
+ if (isMusl()) {
+ return 'aarch64-unknown-linux-musl';
+ }
+
+ return 'aarch64-unknown-linux-gnu';
+
+ default:
+ throw new Error(`Unsupported architecture on Linux: ${process.arch}`);
+ }
+
+ default:
+ throw new Error(
+ `Unsupported OS: ${process.platform}, architecture: ${process.arch}`
+ );
+ }
+};
+
const hasCargo = () => {
try {
execSync(`${where} cargo`);
@@ -14,9 +77,25 @@ const hasCargo = () => {
};
if (hasCargo()) {
- execSync('cargo build --release', {
- stdio: 'inherit',
- });
+ const archs = process.argv.includes('--all') ? targets : [getTarget()];
+ for (const arch of archs) {
+ const command = `cargo build --release --target=${arch}`;
+ console.log(command);
+ execSync(command, {
+ stdio: 'inherit',
+ env: {
+ ...process.env,
+ CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER:
+ 'aarch64-unknown-linux-gnu-gcc',
+ CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER:
+ 'aarch64-unknown-linux-gnu-gcc',
+ CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER:
+ 'x86_64-unknown-linux-gnu-gcc',
+ CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER:
+ 'x86_64-unknown-linux-musl-gcc',
+ },
+ });
+ }
} else {
console.log('Environment has no cargo. Skipping Rust builds.');
}
diff --git a/packages/renderer/cross_compile.sh b/packages/renderer/cross_compile.sh
deleted file mode 100644
index 0e0d7afe0b..0000000000
--- a/packages/renderer/cross_compile.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-echo "Linux ARM glibc"
-export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-unknown-linux-gnu-gcc
-cargo build --release --target=aarch64-unknown-linux-gnu
-
-echo "Linux ARM musl"
-export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-unknown-linux-gnu-gcc
-cargo build --release --target=aarch64-unknown-linux-musl
-
-echo "Linux x64 glibc"
-export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc
-cargo build --release --target=x86_64-unknown-linux-gnu
-
-echo "Linux x64 musl"
-export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=x86_64-unknown-linux-musl-gcc
-cargo build --release --target=x86_64-unknown-linux-musl
-
-echo "macOS ARM"
-cargo build --release --target=aarch64-apple-darwin
-
-echo "macOS x64"
-cargo build --release --target=x86_64-apple-darwin
-
-echo "Windows x64"
-cargo build --release --target=x86_64-pc-windows-gnu
diff --git a/packages/renderer/package.json b/packages/renderer/package.json
index 7cc6f6308c..54299af900 100644
--- a/packages/renderer/package.json
+++ b/packages/renderer/package.json
@@ -10,8 +10,8 @@
"test": "vitest --run",
"watch": "tsc -w",
"build": "node build.mjs && tsc -d",
- "build-all": "sh cross_compile.sh && sh copy.sh",
- "prepublishOnly": "sh cross_compile.sh && sh copy.sh"
+ "build-all": "node build.mjs --all && sh copy.sh",
+ "prepublishOnly": "node build.mjs --all && sh copy.sh"
},
"author": "Jonny Burger <[email protected]>",
"license": "SEE LICENSE IN LICENSE.md",