diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..8062727 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,405 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "bitflags" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "fai-studio-plugin-sdk" +version = "0.1.0" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", + "serde", + "serde_core", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "leb128" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cc46bac87ef8093eed6f272babb833b6443374399985ac8ed28471ee0918545" + +[[package]] +name = "log" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616ec5685824bcc94416c6d4a7a446eea774a31efd7062c8480ba6fd06d7a6e5" + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "spdx" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e17e880bafaeb362a7b751ec46bdc5b61445a188f80e0606e68167cd540fa3" +dependencies = [ + "smallvec", +] + +[[package]] +name = "studio_theme_solarized" +version = "0.1.0" +dependencies = [ + "fai-studio-plugin-sdk", +] + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-encoder" +version = "0.220.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e913f9242315ca39eff82aee0e19ee7a372155717ff0eb082c741e435ce25ed1" +dependencies = [ + "leb128", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.220.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "185dfcd27fa5db2e6a23906b54c28199935f71d9a27a1a27b3a88d6fee2afae7" +dependencies = [ + "anyhow", + "indexmap", + "serde", + "serde_derive", + "serde_json", + "spdx", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.220.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d07b6a3b550fefa1a914b6d54fc175dd11c3392da11eee604e6ffc759805d25" +dependencies = [ + "ahash", + "bitflags", + "hashbrown 0.14.5", + "indexmap", + "semver", +] + +[[package]] +name = "wit-bindgen" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a2b3e15cd6068f233926e7d8c7c588b2ec4fb7cc7bf3824115e7c7e2a8485a3" +dependencies = [ + "wit-bindgen-rt", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b632a5a0fa2409489bd49c9e6d99fcc61bb3d4ce9d1907d44662e75a28c71172" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rt" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7947d0131c7c9da3f01dfde0ab8bd4c4cf3c5bd49b6dba0ae640f1fa752572ea" +dependencies = [ + "bitflags", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4329de4186ee30e2ef30a0533f9b3c123c019a237a7c82d692807bf1b3ee2697" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "177fb7ee1484d113b4792cc480b1ba57664bbc951b42a4beebe573502135b1fc" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.220.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b505603761ed400c90ed30261f44a768317348e49f1864e82ecdc3b2744e5627" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.220.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae2a7999ed18efe59be8de2db9cb2b7f84d88b27818c79353dfc53131840fe1a" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "zerocopy" +version = "0.8.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index bf8262e..c6b8bb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,28 +1,16 @@ -# SKELETON — does not yet compile. +# Standalone Cargo.toml — targets wasm32-wasip2. # -# This crate targets the studio-plugin world declared in -# `wit/studio-plugin.wit`. It cannot be built until two -# upstream pieces ship: +# Build: +# cargo build --release --target wasm32-wasip2 # -# 1. The `fai-studio-plugin-sdk` crate that wraps the WIT -# bindings with an ergonomic Rust API (the `#[plugin(theme)]` -# attribute referenced in `src/lib.rs`). -# 2. Studio's plugin-host module that discovers, loads, and -# invokes plugin components at GUI startup. -# -# Both are documented in `docs/advanced/studio-plugin-sdk.md`. -# Until they exist, this directory serves three purposes: -# -# - Validates the WIT-file structure by being a real crate that -# references it (parse-only path). -# - Locks in the exact Solarized colour palette so the -# in-tree first plugin doesn't bike-shed at integration time. -# - Gives the SDK author a concrete consumer to test against. +# Output: target/wasm32-wasip2/release/studio_theme_solarized.wasm [package] name = "studio_theme_solarized" version = "0.1.0" -edition = "2024" +# Track the SDK's edition — wit-bindgen 0.36 codegen does not +# yet support edition 2024. +edition = "2021" authors = ["Dr. Stefan Flemming "] license = "Apache-2.0" publish = false @@ -34,9 +22,10 @@ rust-version = "1.85" crate-type = ["cdylib"] [dependencies] -# Forward-reference: this crate doesn't yet exist. Tracked in -# docs/advanced/studio-plugin-sdk.md. -# fai-studio-plugin-sdk = { git = "https://git.flemming.ai/fai/studio-plugin-sdk", branch = "main" } +# The SDK lives in fai/fai_studio_plugin_sdk during bootstrap; +# in production this will be a git dependency pointing at +# https://git.flemming.ai/fai/studio-plugin-sdk. +fai-studio-plugin-sdk = { path = "../../fai_studio_plugin_sdk" } [package.metadata.component] package = "fai:studio-plugin" diff --git a/README.md b/README.md index 0375947..af1fda0 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,51 @@ # studio-theme-solarized -First in-tree Studio plugin, by way of being the smallest one -the Studio plugin design supports: a theme. +First in-tree Studio plugin. Ships Ethan Schoonover's +Solarized palette as a Material 3 ColorScheme pair through the +WIT `theme` export. ## Status -**Skeleton.** The crate compiles to the Cargo manifest level but -not to a `.wasm` artefact, because the dependency it points at -(`fai-studio-plugin-sdk`) does not exist yet. +**v0.1 builds.** The `target/wasm32-wasip2/release/studio_theme_solarized.wasm` +artefact (~22 KiB stripped) is a valid F∆I Studio plugin +component. What remains for full round-trip: -Why ship the skeleton now: pins the Solarized colour palette so -the in-tree reference doesn't bike-shed at integration time, and -gives the future SDK author a concrete consumer to test the -generated `#[plugin(theme)]` macro output against. +- The Hub side needs an `InvokePlugin` gRPC RPC + a + Component-Model loader path for `studio-plugin`-world + components. Tracked as task #80. +- Studio side needs `plugin_host.dart` + a theme-picker UI + that lists installed `studio.theme.*` capabilities. -Tracked in: -- `docs/advanced/studio-plugin-sdk.md` (SDK design) -- `docs/advanced/studio-plugins.md` (plugin subsystem overview) -- `docs/advanced/system-gaps.md#s-21` +Until those land, this plugin can be inspected with +`wasm-tools component wit` and packed via `fai pack` — +`/tmp/studio-theme-solarized-0.1.0.fai` is sha256 +`e3d5aae44bb97f14f8f84e293ef8742700956b69c7d6fe46bb8b3c97fc1b23a0`. ## Palette Ethan Schoonover's [Solarized](https://ethanschoonover.com/solarized/). -14 Material 3 tokens per brightness, in the order Studio expects -(primary → on-primary → secondary → … → outline-variant). +14 Material 3 tokens per brightness, in the order Studio +expects (primary → on-primary → secondary → … → +outline-variant). Both Light and Dark are explicit consts in +`src/lib.rs`. -The Light and Dark schemes are explicit constants in `src/lib.rs` -so the file's history is a self-contained record of the palette -choice. Bike-shed there if at all. +## Why the source has three Guest impls -## How to finish this plugin +v0.1 of the SDK declares all three plugin hooks (`theme`, +`translate`, `output-view`) in a single WIT world. A plugin +that only cares about one hook still has to declare all three +— the other two return `PluginError::Declined`, and Studio +falls back to its built-in renderer / the `[EN]` badge. -When the SDK lands: +v0.2 will split the WIT into one world per hook so a theme +plugin only writes the theme impl. See +`docs/advanced/studio-plugin-sdk.md` in `fai/platform` for +the design notes. -1. Uncomment the `fai-studio-plugin-sdk` dependency in - `Cargo.toml`. -2. Uncomment the `#[plugin(theme)]` block in `src/lib.rs`. -3. `cargo build --release --target wasm32-wasip2`. -4. `fai pack . -o studio-theme-solarized-0.1.0.fai`. -5. Add to seed.yaml (or to a `studio-plugins/` channel — open - decision; see docs/advanced/studio-plugins.md). +## Build + +```bash +cargo build --release --target wasm32-wasip2 +cp target/wasm32-wasip2/release/studio_theme_solarized.wasm module.wasm +fai pack . +``` diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..32add0c --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "1.86" +targets = ["wasm32-wasip2"] +components = ["rustfmt", "clippy"] diff --git a/src/lib.rs b/src/lib.rs index dc440d8..9d4402e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,24 +1,23 @@ //! `studio.theme.solarized` — first Studio plugin. //! //! Ships Ethan Schoonover's Solarized palette as a Material 3 -//! ColorScheme pair (light + dark). +//! ColorScheme pair (light + dark) through the WIT `theme` +//! export. //! -//! SKELETON: this file does not yet compile. The -//! `#[plugin(theme)]` macro and the `studio_plugin` runtime live -//! in `fai-studio-plugin-sdk`, which is documented in -//! `docs/advanced/studio-plugin-sdk.md` but not yet implemented. -//! Once the SDK ships, switching the file from skeleton to -//! buildable is a matter of uncommenting the dependency in -//! Cargo.toml and the use-line below. -//! -//! Why ship the skeleton now: pins the palette so the in-tree -//! reference plugin doesn't bike-shed at SDK-integration time, -//! and gives the SDK author a concrete consumer to validate -//! their generated macro output against. +//! This is the proof-of-contract plugin for the +//! `fai-studio-plugin-sdk` v0.1 shape: one struct, one +//! `Guest` impl, one `export_plugin!` invocation. -#![allow(dead_code, unused_imports)] +#![allow(clippy::result_large_err)] -// use fai_studio_plugin_sdk::{plugin, theme, ColorScheme}; +use fai_studio_plugin_sdk::{bindings, export_plugin}; + +// Type aliases against the SDK's bindings so the impl block +// reads cleanly. Once the SDK v0.2 ships proper re-exports + +// world-per-hook, these collapse to a single `use` line. +type ColorScheme = bindings::fai::studio_plugin::plugin_types::ColorScheme; +type PluginError = bindings::fai::studio_plugin::plugin_types::PluginError; +type RenderedOutput = bindings::fai::studio_plugin::plugin_types::RenderedOutput; /// 14 ARGB tokens, Material 3 order: /// primary, on_primary, secondary, on_secondary, @@ -26,8 +25,8 @@ /// surface, on_surface, surface_variant, on_surface_variant, /// outline, outline_variant. /// -/// Studio merges any missing slot (we send all 14, so none) with -/// its built-in fallback before applying. +/// Studio merges any missing slot (we send all 14, so none) +/// with its built-in fallback before applying. const SOLARIZED_LIGHT: [u32; 14] = [ 0xFF268BD2, // primary — solarized blue 0xFFFDF6E3, // on_primary — base3 @@ -62,45 +61,54 @@ const SOLARIZED_DARK: [u32; 14] = [ 0xFF073642, // outline_variant — base02 ]; -// ───────────────────────────────────────────────────────────── -// Forward-reference: this is the shape the SDK will generate -// from `#[plugin(theme)]`. Once the SDK exists, the body collapses -// to a return of `Ok(ColorScheme { brightness, tokens: … })`. -// ───────────────────────────────────────────────────────────── -// -// #[plugin(theme)] -// fn theme_for(brightness: &str) -> theme::Result { -// let tokens = match brightness { -// "light" => SOLARIZED_LIGHT.to_vec(), -// "dark" => SOLARIZED_DARK.to_vec(), -// other => { -// return Err(theme::Error::declined(format!( -// "solarized has no scheme for brightness '{other}'", -// ))) -// } -// }; -// Ok(ColorScheme { -// brightness: brightness.to_string(), -// tokens, -// }) -// } +/// The plugin component. Holds no state — every theme-for +/// call computes from the brightness arg alone. +struct SolarizedPlugin; -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn palette_has_14_tokens() { - assert_eq!(SOLARIZED_LIGHT.len(), 14); - assert_eq!(SOLARIZED_DARK.len(), 14); - } - - #[test] - fn solarized_blue_is_the_primary_in_both_modes() { - // Ethan Schoonover's blue is the brand colour of - // Solarized. Sanity-check we kept it as the primary in - // both schemes. - assert_eq!(SOLARIZED_LIGHT[0], 0xFF268BD2); - assert_eq!(SOLARIZED_DARK[0], 0xFF268BD2); +impl bindings::exports::fai::studio_plugin::theme::Guest for SolarizedPlugin { + fn theme_for(brightness: String) -> Result { + let tokens = match brightness.as_str() { + "light" => SOLARIZED_LIGHT.to_vec(), + "dark" => SOLARIZED_DARK.to_vec(), + other => { + return Err(PluginError::Declined(format!( + "solarized has no scheme for brightness '{other}' \ + (supported: light, dark)" + ))); + } + }; + Ok(ColorScheme { brightness, tokens }) } } + +// SDK v0.1 wraps all three hooks in a single WIT world, so a +// plugin that only really cares about `theme` still has to +// declare empty / declined impls for the other two. v0.2 will +// split the WIT into one world per hook; until then these +// `declined` returns are the right answer — Studio falls back +// to its built-in renderer or to the [EN] badge. + +impl bindings::exports::fai::studio_plugin::translate::Guest for SolarizedPlugin { + fn translate( + _text: String, + _from_locale: String, + _to_locale: String, + ) -> Result { + Err(PluginError::Declined( + "solarized is a theme plugin and does not translate".to_string(), + )) + } +} + +impl bindings::exports::fai::studio_plugin::output_view::Guest for SolarizedPlugin { + fn render( + _mime_type: String, + _data: Vec, + ) -> Result { + Err(PluginError::Declined( + "solarized is a theme plugin and does not render outputs".to_string(), + )) + } +} + +export_plugin!(SolarizedPlugin);