-
Notifications
You must be signed in to change notification settings - Fork 3
/
generate-bindings.mjs
47 lines (43 loc) · 1.32 KB
/
generate-bindings.mjs
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
40
41
42
43
44
45
46
47
import { execSync } from "child_process";
import path from "path";
import fs from "fs";
import { PREFIX } from "./const.mjs";
const isWindows = process.argv[2] === "windows";
const isMusl = process.argv[2] === "musl";
execSync(
`cargo build --release ${isWindows ? "--target=x86_64-pc-windows-gnu" : ""}`,
{
env: {
...process.env,
FFMPEG_DIR: path.join(process.cwd(), PREFIX),
CPATH:
process.platform === "darwin"
? "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include"
: undefined,
RUSTFLAGS: isMusl ? "-Ctarget-feature=-crt-static" : undefined,
},
stdio: "inherit",
}
);
const bindings = isWindows
? path.join(
process.cwd(),
"target",
"x86_64-pc-windows-gnu",
"release",
"build"
)
: path.join(process.cwd(), "target", "release", "build");
const folders = fs.readdirSync(bindings);
const sysFolders = folders.filter((folder) => {
return folder.startsWith("ffmpeg-sys-");
});
for (const folder of sysFolders) {
const abs = path.join(bindings, folder);
const files = fs.readdirSync(abs);
if (files.includes("out")) {
const outDir = path.join(abs, "out", "bindings.rs");
fs.copyFileSync(outDir, path.join(process.cwd(), "bindings.rs"));
console.log(outDir);
}
}