Rust 製のデスクトップアップフレームワーク Tauri を使ってみる

こんにちは、k-junです。入社して1年ほどがたち、久しぶりに落ち着いて来たのでまた記事を書いています。Rust 関連の Desktop App を見つけたので使ってみたいと思います。

https://github.com/tauri-apps/tauri

Tauri is a framework for building tiny, blazing fast binaries for all major desktop platforms. Developers can integrate any front-end framework that compiles to HTML, JS and CSS for building their user interface. The backend of the application is a rust-sourced binary with an API that the front-end can interact with.

Electron と似ている性質のものですが、メインのプロセスを Rust で起動できるものとのこと。メモリ消費量や性能面で Electron より優れていそうな。

https://www.klab.com/jp/blog/tech/2020/0914-tauri.html

フロントはElectronと同じくWebViewですが、ベースの起動プログラム(Main Process)をRustで書くことができるものです。

setup

ドキュメントを参考に適当にセットアップ。

brew install gcc

mkdir tauri-tutorial
cd tauri-tutorial
yarn add @tauri-apps/cli

yarn tauri init
yarn run v1.22.5
warning package.json: No license field
$ tauri init
Downloading Tauri CLI
Download Complete
 app:spawn Running "/Users/keijun.kumagai/source-code/tauri-tutorial/node_modules/@tauri-apps/cli/bin/tauri-cli tauri init" +0ms

What is your app name?: tauri-tutorial
What should the window title be?: tauri-tutorial
Where are your web assets (HTML/CSS/JS) located, relative to the "<current dir>/src-tauri" folder that will be created?: ./
What is the url of your dev server?: https://localhost:8080
? [YARN]: "Do you want to install @tauri-apps/api ?" Yes

yarn tauri info

activate

起動。

yarn tauri dev

何やら Window が立ち上がった。うおおおお。

どうやら作成途中にて、指定したurl or ディレクトリ経由で得られる html ファイルを用いて、Desktop App を提供できるようですね。 以前作成した Svelte のゲームを用いて設定してみます。

git clone https://github.com/k-jun/talpidae-frontend.git

json:tauri.conf.json

...
  "build": {
    "distDir": "./talpidae-frontend/public",
    "devPath": "http://localhost:5000",
    "beforeDevCommand": "cd talpidae-frontend && yarn dev",
    "beforeBuildCommand": "cd talpidae-frontend && yarn build"
  },
...

Window が立ち上がり、ゲーム画面が!!

f:id:K-jun1221:20210425232856p:plain

ということで、Svelte + Webpack + tauri で Desktop のアプリ開発も行えそうということがわかりました。 Rustの利用範囲がどんどん広がっているようで嬉しいです。今回はこれぐらいで!