Chapter 2 of 15

rata new and the first window

Every Elyra app starts the same way: rata new, a frontend build, rata codegen, and cargo run. Freddy does all four and then looks at what he got.

Getting rata

The guide starts after this step: it does not say how to install rata. What the repository does say is that rata is the binary of the ratatosk crate in the framework's repository, and since nothing is published to a registry, Cargo can install it straight from a release tag. This is plain Cargo, not a command from the guide, and it was run for this course against v0.16.0:

cargo install --locked --git https://github.com/kwhorne/elyra-framework --tag v0.16.0 ratatosk

You need a Rust toolchain for that, and Node with npm for the frontend. rata help lists the commands.

rata new

rata new freddy-notes
cd freddy-notes

That generates a self-contained workspace. Freddy's has these files, which is what rata new 0.16.0 wrote when this course was made:

Cargo.toml          # depends on the framework's release tag
elyra.toml          # rata's configuration
src/main.rs         # the app: App::new(), commands, providers
app/                # the Svelte 5 frontend (Vite)
  index.html
  package.json      # @elyra/runtime from the release
  src/main.js
  src/App.svelte
  src/Router.svelte
  src/routes.js
  src/pages/Home.svelte
  src/pages/NotFound.svelte
  src/resources/index.js
  src/theme.js
  src/app.css

Two lines in it matter more than they look. Cargo.toml depends on the framework by tag, and app/package.json points @elyra/runtime at the tarball attached to the same release, because npm cannot install a subdirectory of a git repository:

elyra = { git = "https://github.com/kwhorne/elyra-framework", tag = "v0.16.0" }

"@elyra/runtime": "https://github.com/kwhorne/elyra-framework/releases/download/v0.16.0/elyra-runtime-0.16.0.tgz"

Upgrading the framework later means moving both to the new tag. rata new --elyra <path> instead wires a project to a local checkout of the framework, for working on the framework itself.

The first run

rata new prints the next steps, and they are the guide's quick start:

(cd app && npm install && npm run build)   # build the frontend
rata codegen                                # generate typed bindings
cargo run                                   # launch

For this course the first three steps were run on a fresh project: the frontend built, rata codegen wrote app/src/bindings.ts, and the app compiled. cargo run then opens the window: titled freddy-notes, as src/main.rs sets it, with a Svelte page inside it and a single binary behind it.

While he works, Freddy does not want to rebuild the frontend for every change. rata dev runs the frontend's dev server next to the app, so a change to a Svelte file shows at once; the CLI page has the details. The getting started guide walks through the same steps.

What runs where

The architecture page explains what Freddy just started. The event loop and the webview live on the main thread, which macOS requires. Commands run on an async runtime, each on its own task, so a slow one never freezes the window. The page talks to Rust only through the bridge, and Rust pushes to the page through an event bus whose batches the frontend collects over a long-poll it holds open.

Why it feels fast. There is no interpreter between Freddy's code and the machine, and nothing on the bridge is JSON: arguments go over as a compact MessagePack array and results come back as MessagePack maps. Chapter 3 is about writing the code on both ends of that bridge.

What you learned

  • rata is the ratatosk crate's binary; the guide does not document installing it, and plain Cargo can install it from a release tag.
  • rata new scaffolds a Rust app and a Svelte 5 frontend that depend on one release, by tag and by tarball.
  • The first run is: build the frontend, rata codegen, cargo run; rata dev keeps the frontend live while you work.
  • The window lives on the main thread, and each command on its own task.
Next: in Chapter 3 Freddy writes his first command and calls it from Svelte.