Skip to content

Commit 9e43844

Browse files
authored
build: generate native Canvas resources on demand (#117424)
1 parent 71a5951 commit 9e43844

19 files changed

Lines changed: 327 additions & 13081 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3447,6 +3447,12 @@ jobs:
34473447
# workflow-owned as before. Load them from the workflow revision so old targets work.
34483448
uses: ./.ci-workflow/.github/actions/setup-android-toolchain
34493449

3450+
- name: Setup Node environment for native resources
3451+
if: needs.preflight.outputs.compatibility_target != 'true'
3452+
uses: ./.github/actions/setup-node-env
3453+
with:
3454+
install-bun: "false"
3455+
34503456
# Same-repo runs carry the Gradle user home (dependency, wrapper, and
34513457
# build caches) on a Blacksmith sticky disk: the setup-java gradle cache
34523458
# above is evicted so quickly under the repo quota that it rarely

‎.github/workflows/codeql-android-critical-security.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ jobs:
3434
distribution: temurin
3535
java-version: "21"
3636

37+
- name: Setup Node environment
38+
uses: ./.github/actions/setup-node-env
39+
with:
40+
install-bun: "false"
41+
3742
- name: Initialize CodeQL
3843
uses: github/codeql-action/init@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1
3944
with:

‎.github/workflows/linux-app-release.yml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ jobs:
110110
uses: ./.github/actions/setup-node-env
111111
with:
112112
install-bun: "false"
113-
install-deps: "false"
114113

115114
- name: Build Linux companion bundles
116115
working-directory: apps/linux/src-tauri
@@ -185,7 +184,6 @@ jobs:
185184
uses: ./.github/actions/setup-node-env
186185
with:
187186
install-bun: "false"
188-
install-deps: "false"
189187

190188
- name: Build macOS test bundles
191189
working-directory: apps/linux/src-tauri
@@ -253,7 +251,6 @@ jobs:
253251
uses: ./.github/actions/setup-node-env
254252
with:
255253
install-bun: "false"
256-
install-deps: "false"
257254

258255
- name: Build Windows test bundle
259256
working-directory: apps/linux/src-tauri

‎.github/workflows/linux-app.yml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ jobs:
6767
uses: ./.github/actions/setup-node-env
6868
with:
6969
install-bun: "false"
70-
install-deps: "false"
7170

7271
- name: Check Rust formatting
7372
working-directory: apps/linux/src-tauri
@@ -122,6 +121,11 @@ jobs:
122121
- name: Install Rust
123122
run: rustup toolchain install stable --profile minimal
124123

124+
- name: Setup Node environment
125+
uses: ./.github/actions/setup-node-env
126+
with:
127+
install-bun: "false"
128+
125129
- name: Cache Cargo
126130
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
127131
with:

‎apps/android/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ OpenClaw Android is the officially released Google Play app. It connects to an O
2828

2929
## Open in Android Studio
3030

31+
- Run `pnpm install` from the repository root so native Canvas resources can be generated.
3132
- Open the folder `apps/android`.
3233

3334
## Wear OS companion

‎apps/android/app/build.gradle.kts‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
import com.android.build.api.variant.impl.VariantOutputImpl
2+
import org.gradle.api.DefaultTask
3+
import org.gradle.api.file.ConfigurableFileCollection
4+
import org.gradle.api.file.DirectoryProperty
5+
import org.gradle.api.tasks.InputFiles
6+
import org.gradle.api.tasks.Internal
7+
import org.gradle.api.tasks.OutputDirectory
8+
import org.gradle.api.tasks.PathSensitive
9+
import org.gradle.api.tasks.PathSensitivity
10+
import org.gradle.api.tasks.TaskAction
11+
import org.gradle.process.ExecOperations
212
import java.time.Instant
313
import java.time.ZoneOffset
414
import java.time.format.DateTimeFormatter
515
import java.util.Properties
16+
import javax.inject.Inject
617

718
val dnsjavaInetAddressResolverService = "META-INF/services/java.net.spi.InetAddressResolverProvider"
819
val openClawAndroidVersionFile = rootProject.file("Config/Version.properties")
920
val thirdPartyLicensesDir = rootProject.file("THIRD_PARTY_LICENSES")
21+
val openClawRepositoryRoot = rootProject.projectDir.resolve("../..").canonicalFile
22+
val canvasA2uiAssetsDir = layout.buildDirectory.dir("generated/canvasA2uiAssets")
1023
val openClawAndroidVersionProperties =
1124
Properties().apply {
1225
if (!openClawAndroidVersionFile.isFile) {
@@ -119,6 +132,56 @@ plugins {
119132
alias(libs.plugins.ksp)
120133
}
121134

135+
abstract class StageCanvasA2uiTask
136+
@Inject
137+
constructor(
138+
private val execOperations: ExecOperations,
139+
) : DefaultTask() {
140+
@get:Internal abstract val repoRoot: DirectoryProperty
141+
142+
@get:InputFiles
143+
@get:PathSensitive(PathSensitivity.RELATIVE)
144+
abstract val sourceFiles: ConfigurableFileCollection
145+
146+
@get:OutputDirectory abstract val outputDirectory: DirectoryProperty
147+
148+
@TaskAction
149+
fun stage() {
150+
val root = repoRoot.get().asFile
151+
execOperations.exec {
152+
workingDir(root)
153+
commandLine(
154+
"node",
155+
"scripts/sync-native-a2ui.mjs",
156+
"--write",
157+
"--output",
158+
outputDirectory
159+
.get()
160+
.dir("CanvasA2UI")
161+
.asFile.absolutePath,
162+
)
163+
}
164+
}
165+
}
166+
167+
val stageCanvasA2ui =
168+
tasks.register<StageCanvasA2uiTask>("stageCanvasA2ui") {
169+
group = "build"
170+
description = "Stages the plugin-owned Canvas A2UI renderer for native apps."
171+
repoRoot.set(openClawRepositoryRoot)
172+
sourceFiles.from(
173+
openClawRepositoryRoot.resolve("package.json"),
174+
openClawRepositoryRoot.resolve("pnpm-lock.yaml"),
175+
openClawRepositoryRoot.resolve("scripts/bundle-a2ui.mjs"),
176+
openClawRepositoryRoot.resolve("scripts/sync-native-a2ui.mjs"),
177+
openClawRepositoryRoot.resolve("extensions/canvas/package.json"),
178+
openClawRepositoryRoot.resolve("extensions/canvas/scripts/bundle-a2ui.mjs"),
179+
openClawRepositoryRoot.resolve("extensions/canvas/src/host/a2ui/index.html"),
180+
)
181+
sourceFiles.from(openClawRepositoryRoot.resolve("extensions/canvas/src/host/a2ui-app"))
182+
outputDirectory.set(canvasA2uiAssetsDir)
183+
}
184+
122185
ksp {
123186
arg("room.schemaLocation", "$projectDir/schemas")
124187
}
@@ -269,6 +332,10 @@ android {
269332

270333
androidComponents {
271334
onVariants { variant ->
335+
variant.sources.assets?.addGeneratedSourceDirectory(
336+
stageCanvasA2ui,
337+
StageCanvasA2uiTask::outputDirectory,
338+
)
272339
variant.outputs
273340
.filterIsInstance<VariantOutputImpl>()
274341
.forEach { output ->

‎apps/ios/project.yml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ targets:
106106
export PATH="$PATH:/opt/homebrew/bin:/usr/local/bin"
107107
"$SRCROOT/../../scripts/check-swift-tools.sh" swiftlint
108108
swiftlint lint --strict --config "$SRCROOT/.swiftlint.yml" --use-script-input-file-lists
109+
postBuildScripts:
110+
- name: Stage Canvas A2UI resources
111+
basedOnDependencyAnalysis: false
112+
script: |
113+
set -euo pipefail
114+
export PATH="$PATH:/opt/homebrew/bin:/usr/local/bin"
115+
repo_root="$(cd "$SRCROOT/../.." && pwd -P)"
116+
resource_product="$BUILT_PRODUCTS_DIR/OpenClawKit_OpenClawKit.bundle"
117+
resource_bundle="$TARGET_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/OpenClawKit_OpenClawKit.bundle"
118+
test -d "$resource_product"
119+
test -d "$resource_bundle"
120+
node "$repo_root/scripts/sync-native-a2ui.mjs" \
121+
--write \
122+
--output "$resource_product/CanvasA2UI"
123+
rm -rf "$resource_bundle/CanvasA2UI"
124+
cp -R "$resource_product/CanvasA2UI" "$resource_bundle/CanvasA2UI"
109125
settings:
110126
base:
111127
ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon

‎apps/linux/README.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ workflow instead of relying on GStreamer packages from the user's system.
3333

3434
## Develop and build
3535

36-
The frontend is static HTML, CSS, and JavaScript. It has no package install or build step.
36+
The companion frontend is static HTML, CSS, and JavaScript. The shared Canvas A2UI renderer is
37+
generated from the Canvas plugin, so install repository dependencies once before building:
3738

3839
```bash
40+
pnpm install
3941
cd apps/linux/src-tauri
4042
cargo run
4143
cargo build
@@ -55,7 +57,10 @@ The companion checks the latest GitHub release shortly after launch and from **C
5557

5658
The running app gives the headless `openclaw node run` host a single Canvas WebView. The bundled `linux-canvas` plugin advertises `canvas.*` only while the app socket exists. The app listens at `$XDG_RUNTIME_DIR/openclaw-canvas.sock` (or `/tmp/openclaw-canvas-$UID.sock`) with mode `0600`; a headless Linux node without the app does not advertise Canvas.
5759

58-
The plugin-generated A2UI renderer in `extensions/canvas/src/host/a2ui/` remains the source of truth. The app embeds its committed, synced OpenClawKit mirror from `apps/shared/OpenClawKit/Sources/OpenClawKit/Resources/CanvasA2UI/`. Run `node scripts/sync-native-a2ui.mjs --check` from the repository root after changing those assets.
60+
The Canvas plugin sources remain the source of truth for the A2UI renderer. Each native build
61+
generates `index.html` and `a2ui.bundle.js` into its isolated build output before compiling. Run
62+
`node scripts/sync-native-a2ui.mjs --check` from the repository root to verify fresh bundles are
63+
byte-identical and every native build owner is wired.
5964

6065
## Quick Chat widgets
6166

‎apps/linux/src-tauri/build.rs‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
use std::path::PathBuf;
2+
use std::process::Command;
3+
14
fn main() {
5+
stage_canvas_a2ui();
26
link_macos_swift_runtime();
37
// Command metadata generates capability permissions independently of the
48
// target's invoke handler, so keep the Linux-only command permission known.
@@ -22,6 +26,43 @@ fn main() {
2226
.expect("Tauri build configuration should be valid");
2327
}
2428

29+
fn stage_canvas_a2ui() {
30+
let repo_root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../..");
31+
let output_dir = PathBuf::from(std::env::var_os("OUT_DIR").expect("Cargo must set OUT_DIR"))
32+
.join("canvas-a2ui");
33+
for input in [
34+
"package.json",
35+
"pnpm-lock.yaml",
36+
"scripts/bundle-a2ui.mjs",
37+
"scripts/sync-native-a2ui.mjs",
38+
"extensions/canvas/package.json",
39+
"extensions/canvas/scripts/bundle-a2ui.mjs",
40+
"extensions/canvas/src/host/a2ui/index.html",
41+
"extensions/canvas/src/host/a2ui-app",
42+
] {
43+
println!("cargo:rerun-if-changed={}", repo_root.join(input).display());
44+
}
45+
46+
let status = Command::new("node")
47+
.args(["scripts/sync-native-a2ui.mjs", "--write", "--output"])
48+
.arg(&output_dir)
49+
.current_dir(&repo_root)
50+
.status()
51+
.expect("Canvas A2UI staging requires Node.js; run pnpm install from the repository root");
52+
assert!(
53+
status.success(),
54+
"Canvas A2UI resource staging failed; run pnpm install from the repository root"
55+
);
56+
println!(
57+
"cargo:rustc-env=OPENCLAW_CANVAS_A2UI_INDEX_HTML={}",
58+
output_dir.join("index.html").display()
59+
);
60+
println!(
61+
"cargo:rustc-env=OPENCLAW_CANVAS_A2UI_BUNDLE_JS={}",
62+
output_dir.join("a2ui.bundle.js").display()
63+
);
64+
}
65+
2566
/// tauri-plugin-notifications links a Swift static library into us, but nothing
2667
/// adds an rpath for the Swift runtime it pulls in. Bundled apps get one from
2768
/// the bundler; plain `cargo run` and `cargo test` binaries do not, so they die

‎apps/linux/src-tauri/src/canvas.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@ const A2UI_READY_TIMEOUT: Duration = Duration::from_secs(6);
3030
const A2UI_READY_INTERVAL: Duration = Duration::from_millis(100);
3131
const A2UI_READY_EVAL_TIMEOUT: Duration = Duration::from_millis(100);
3232

33-
const A2UI_INDEX: &[u8] = include_bytes!(
34-
"../../../../apps/shared/OpenClawKit/Sources/OpenClawKit/Resources/CanvasA2UI/index.html"
35-
);
36-
const A2UI_BUNDLE: &[u8] = include_bytes!(
37-
"../../../../apps/shared/OpenClawKit/Sources/OpenClawKit/Resources/CanvasA2UI/a2ui.bundle.js"
38-
);
33+
const A2UI_INDEX: &[u8] = include_bytes!(env!("OPENCLAW_CANVAS_A2UI_INDEX_HTML"));
34+
const A2UI_BUNDLE: &[u8] = include_bytes!(env!("OPENCLAW_CANVAS_A2UI_BUNDLE_JS"));
3935

4036
const ACTION_BRIDGE_SCRIPT: &str = r#"
4137
(() => {

0 commit comments

Comments
 (0)