TauriTavern/scripts/tauri-app.mjs
LeenHawk 0077e15241
feat: add experimental OpenHarmony HAP support (#300)
* feat: add experimental OpenHarmony application build

* build(ohos): isolate experimental NAPI dependencies

* ci(ohos): build in this repository with public toolchain image

* ci: run existing checks for OHOS adaptation

* fix(ohos): generate QuickJS bindings for the OHOS target

* fix(ohos): use private caches and exclude desktop migration logs

* feat(ohos): restore native plugins and trusted endpoint confirmation

* ci(ohos): verify native plugin integration with existing checks

* chore(ohos): remove completed one-off validation workflow

* fix(ohos): clean dependency warnings and enable HAP LTO

* fix(ohos): retain shared plugin callbacks for the native bridge

* refactor(ohos): keep the native project and align the framework baseline

* fix(ohos): pin frame authorization and name the launcher entry

* fix(ohos): bind native builds and HAP packaging to the selected ABI

* fix(ohos): pin ordered Tauri bridge initialization

* fix(ohos): compress native libraries in HAP packages

* refactor(ohos): simplify HAP builds and Canary publishing

Build Rust once through the OHOS CLI and derive HAP versions from its merged
configuration. Replace the demo with the application page and remove generated
configuration writes, CMake scaffolding, and redundant preparation steps.

Keep ARM64 HAPs optional for Canary, report unsupported dev-log exports clearly,
and document the current build and host contracts.

Validated with pnpm run check, a local x86_64 HAP build and simulator smoke checks,
and Windows notification smoke checks.

---------

Co-authored-by: Darkatse <39111369+Darkatse@users.noreply.github.com>
2026-10-04 14:09:37 +08:00

64 lines
1.9 KiB
JavaScript

#!/usr/bin/env node
import { spawnSync } from "node:child_process";
import { existsSync } from "node:fs";
import path from "node:path";
import process from "node:process";
import { fileURLToPath } from "node:url";
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.resolve(scriptDir, "..");
const tauriCli = path.join(repoRoot, "node_modules", "@tauri-apps", "cli", "tauri.js");
const frontendBuildHook = path.join(scriptDir, "tauri-before-build.mjs");
if (!existsSync(tauriCli)) {
console.error(`Missing Tauri CLI at ${tauriCli}. Run pnpm install first.`);
process.exit(1);
}
const env = {
...process.env,
TAURI_APP_PATH: path.join(repoRoot, "src-tauri", "crates", "tauritavern"),
TAURI_FRONTEND_PATH: repoRoot,
};
const args = process.argv.slice(2);
if (args[0] === "--") {
args.shift();
}
if (args[0] === "--prepare-frontend") {
args.shift();
const isDev = args[0] === "dev"
|| (["android", "ios", "ohos"].includes(args[0]) && args[1] === "dev");
if (!isDev) {
const frontendResult = spawnSync(process.execPath, [frontendBuildHook], {
cwd: repoRoot,
stdio: "inherit",
env,
});
if (frontendResult.error) {
console.error(frontendResult.error.message);
process.exit(1);
}
if (frontendResult.status !== 0) {
process.exit(frontendResult.status ?? 1);
}
}
env.TAURITAVERN_SKIP_WEB_BUILD = "1";
}
// OpenHarmony uses the toolchain's cargo-tauri; the npm CLI has no ohos command.
const result = spawnSync(args[0] === "ohos" ? "cargo" : process.execPath,
args[0] === "ohos" ? ["tauri", ...args] : [tauriCli, ...args], {
cwd: repoRoot,
stdio: "inherit",
env,
});
if (result.error) {
console.error(result.error.message);
process.exit(1);
}
process.exit(result.status ?? 1);