1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-29 02:29:06 -05:00
denoland-deno/tools/wgpu_sync.js

116 lines
2.9 KiB
JavaScript
Raw Normal View History

2022-01-24 17:47:05 -05:00
#!/usr/bin/env -S deno run --unstable --allow-read --allow-write --allow-run
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2022-01-24 17:47:05 -05:00
2022-11-22 15:07:35 -05:00
import { join, ROOT_PATH } from "./util.js";
2022-01-24 17:47:05 -05:00
2023-01-30 09:14:16 -05:00
const COMMIT = "659f6977051345e4e06ab4832c6f7d268f25a1ad";
2022-07-19 20:22:26 -04:00
const REPO = "gfx-rs/wgpu";
2023-01-30 09:14:16 -05:00
const V_WGPU = "0.15";
2022-01-24 17:47:05 -05:00
const TARGET_DIR = join(ROOT_PATH, "ext", "webgpu");
async function bash(subcmd, opts = {}) {
const { success, code } = await new Deno.Command("bash", {
...opts,
args: ["-c", subcmd],
stdout: "inherit",
sdterr: "inherit",
}).output();
2022-01-24 17:47:05 -05:00
// Exit process on failure
if (!success) {
Deno.exit(code);
2022-01-24 17:47:05 -05:00
}
}
async function clearTargetDir() {
await bash(`rm -r ${TARGET_DIR}/*`);
}
async function checkoutUpstream() {
// Path of deno_webgpu inside the TAR
const tarPrefix = `${REPO.replace("/", "-")}-${
COMMIT.slice(0, 7)
}/deno_webgpu/`;
const cmd =
`curl -L https://api.github.com/repos/${REPO}/tarball/${COMMIT} | tar -C '${TARGET_DIR}' -xzvf - --strip=2 '${tarPrefix}'`;
// console.log(cmd);
await bash(cmd);
}
async function denoWebgpuVersion() {
2022-11-22 15:07:35 -05:00
const coreCargo = join(ROOT_PATH, "Cargo.toml");
2022-01-24 17:47:05 -05:00
const contents = await Deno.readTextFile(coreCargo);
return contents.match(
2022-11-22 15:07:35 -05:00
/^deno_webgpu = { version = "(\d+\.\d+\.\d+)", path = ".\/ext\/webgpu" }$/m,
2022-01-24 17:47:05 -05:00
)[1];
}
async function patchFile(path, patcher) {
const data = await Deno.readTextFile(path);
const patched = patcher(data);
await Deno.writeTextFile(path, patched);
}
async function patchCargo() {
const vDenoWebgpu = await denoWebgpuVersion();
await patchFile(
join(TARGET_DIR, "Cargo.toml"),
(data) =>
data
.replace(/^version = .*/m, `version = "${vDenoWebgpu}"`)
.replace(
2023-01-30 09:14:16 -05:00
/^repository.workspace = true/m,
`repository = "https://github.com/gfx-rs/wgpu"`,
2022-01-24 17:47:05 -05:00
)
.replace(
2023-01-30 09:14:16 -05:00
/^serde = { workspace = true, features = ["derive"] }/m,
`serde.workspace = true`,
)
.replace(
/^tokio = { workspace = true, features = ["full"] }/m,
`tokio.workspace = true`,
2022-01-24 17:47:05 -05:00
),
2023-01-30 09:14:16 -05:00
);
await patchFile(
join(ROOT_PATH, "Cargo.toml"),
(data) =>
data
.replace(/^wgpu-core = .*/m, `wgpu-core = "${V_WGPU}"`)
.replace(/^wgpu-types = .*/m, `wgpu-types = "${V_WGPU}"`),
2022-01-24 17:47:05 -05:00
);
}
async function patchSrcLib() {
await patchFile(
join(TARGET_DIR, "src", "lib.rs"),
(data) =>
data.replace(
`prefix "internal:deno_webgpu",`,
`prefix "internal:deno_webgpu",`,
),
2022-01-24 17:47:05 -05:00
);
}
async function patchSurface() {
await patchFile(
join(TARGET_DIR, "src", "surface.rs"),
(data) =>
data.replace(
`prefix "internal:deno_webgpu",`,
`prefix "internal:deno_webgpu",`,
),
);
}
2022-01-24 17:47:05 -05:00
async function main() {
await clearTargetDir();
await checkoutUpstream();
await patchCargo();
await patchSrcLib();
await patchSurface();
2022-01-24 17:47:05 -05:00
await bash(join(ROOT_PATH, "tools", "format.js"));
}
await main();