Skip to content

Commit

Permalink
Refactor dawn build script
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon committed Nov 4, 2024
1 parent f29d1b7 commit 9f353c7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 79 deletions.
2 changes: 0 additions & 2 deletions packages/webgpu/cpp/rnwgpu/api/GPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ namespace m = margelo;
class GPU : public m::HybridObject {
public:
GPU() : HybridObject("GPU") {
// DawnProcTable backendProcs = dawn::native::GetProcs();
// dawnProcSetProcs(&backendProcs);
wgpu::InstanceDescriptor instanceDesc;
instanceDesc.features.timedWaitAnyEnable = true;
instanceDesc.features.timedWaitAnyMaxCount = 64;
Expand Down
9 changes: 4 additions & 5 deletions packages/webgpu/scripts/build/dawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import { chdir } from "process";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";

import type { Platform } from "./util";
import type { Platform } from "./dawn-configuration";
import { $, mapKeys } from "./util";
import {
$,
build,
checkBuildArtifacts,
copyHeaders,
copyLib,
libs,
mapKeys,
projectRoot,
} from "./util";
import { copyHeaders } from "./dawn-configuration";
} from "./dawn-configuration";

const { argv } = yargs(hideBin(process.argv))
.option("exclude", {
Expand Down
72 changes: 0 additions & 72 deletions packages/webgpu/scripts/build/util.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
/* eslint-disable max-len */
import { spawn, execSync } from "child_process";
import { existsSync } from "fs";
import { exit } from "process";

export const libs = ["libwebgpu_dawn"] as const;

export const projectRoot = "packages/webgpu";

export const platforms = [
"arm64",
"x86_64",
"x86",
"armeabi-v7a",
"arm64-v8a",
"universal",
] as const;

export type OS = "apple" | "android";
export type Platform = (typeof platforms)[number];

export const runAsync = (command: string, label: string): Promise<void> => {
return new Promise((resolve, reject) => {
const [cmd, ...args] = command.split(" ");
Expand Down Expand Up @@ -72,58 +55,3 @@ export const $ = (command: string) => {
exit(1);
}
};

const serializeCMakeArgs = (args: Record<string, string>) => {
return Object.keys(args)
.map((key) => `-D${key}=${args[key]}`)
.join(" ");
};

export const build = async (
label: string,
args: Record<string, string>,
debugLabel: string,
) => {
console.log(`🔨 Building ${label}`);
$(`mkdir -p externals/dawn/out/${label}`);
process.chdir(`externals/dawn/out/${label}`);
const cmd = `cmake ../.. -G Ninja ${serializeCMakeArgs(args)}`;
await runAsync(cmd, debugLabel);
await runAsync("ninja", debugLabel);
process.chdir("../../../..");
};

export const copyLib = (os: OS, platform: Platform, sdk?: string) => {
const suffix = `${platform}${sdk ? `_${sdk}` : ""}`;
const out = `${os}_${suffix}`;
const dstPath = `${projectRoot}/libs/${os}/${suffix}/`;
$(`mkdir -p ${dstPath}`);
if (os === "android") {
console.log("Strip debug symbols from libwebgpu_dawn.a...");
$(
`$ANDROID_NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-strip externals/dawn/out/${out}/src/dawn/native/libwebgpu_dawn.so`,
);
}
[
`externals/dawn/out/${out}/src/dawn/native/libwebgpu_dawn.${os === "apple" ? "a" : "so"}`,
].forEach((lib) => {
const libPath = lib;
console.log(`Copying ${libPath} to ${dstPath}`);
$(`cp ${libPath} ${dstPath}`);
});
};

export const checkBuildArtifacts = () => {
console.log("Check build artifacts...");
platforms
.filter((arch) => arch !== "arm64" && arch !== "universal")
.forEach((platform) => {
libs.forEach((lib) => {
checkFileExists(`libs/android/${platform}/${lib}.so`);
});
});
libs.forEach((lib) => {
checkFileExists(`libs/apple/${lib}.xcframework`);
});
checkFileExists("libs/dawn.json");
};

0 comments on commit 9f353c7

Please sign in to comment.