-
Notifications
You must be signed in to change notification settings - Fork 66
feature(examples): bundle-wry #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
RandyMcMillan
wants to merge
1
commit into
ratatui:main
Choose a base branch
from
RandyMcMillan:1862/958034/189385/c07436d/000271d-examples-bundle-wry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| dist |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| [package] | ||
| name = "bundle-wry" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| description = "Ratzilla web and wry desktop app example" | ||
| publish = false | ||
|
|
||
| [package.metadata.bundle] | ||
| name = "bundle-wry" | ||
| identifier = "rs.ratatui.bundle-wry" | ||
| icon = ["icons/icon.png"] | ||
| category = "Utility" | ||
| short_description = "ratatui-ratzilla bundle wry example" | ||
|
|
||
| [package.metadata.bundle.bin.bundle-wry] | ||
| name = "bundle-wry" | ||
| identifier = "rs.ratatui.bundle-wry" | ||
| icon = ["icons/icon.png"] | ||
| category = "Utility" | ||
| short_description = "bundle-wry" | ||
| resources = ["dist"] | ||
|
|
||
| [features] | ||
| default = ["bundle-wry"] | ||
| bundle-wry = ["dep:tao", "dep:wry", "dep:muda"] | ||
|
|
||
| [dependencies] | ||
| critical-section = { workspace = true, features = ["std"] } | ||
| muda = { version = "0.19", optional = true } | ||
| rand = { version = "0.9.2", default-features = false, features = ["small_rng"] } | ||
| ratzilla = { workspace = true } | ||
| tachyonfx = { version = "0.23.0", default-features = false, features = ["wasm"] } | ||
| tao = { version = "0.35.3", optional = true } | ||
| wasm-bindgen = "0.2.108" | ||
| ## web-sys = { version = "0.3.81", features = [ | ||
| ## "Window", | ||
| ## "Document", | ||
| ## "Element", | ||
| ## "HtmlElement", | ||
| ## "Location", | ||
| ## "Url", | ||
| ## "UrlSearchParams", | ||
| ## ], optional = true } | ||
| web-time = "1.1.0" | ||
| wry = { version = "0.55.1", optional = true } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| [build] | ||
| # The index HTML file to drive the bundling process. | ||
| target = "index.html" | ||
| # Build in release mode (equivalent to --release). | ||
| release = false | ||
| # The output directory for all final assets. | ||
| dist = "dist" | ||
| # The public URL from which assets are to be served. | ||
| public_url = "./" | ||
| # Whether to include hash values in the output file names. | ||
| filehash = true | ||
|
|
||
| [watch] | ||
| # Paths to watch for changes (beyond the build.target parent folder). | ||
| watch = ["src"]#, "assets"] | ||
| # Paths to ignore. | ||
| ignore = [] | ||
|
|
||
| [serve] | ||
| addresses = ["127.0.0.1"] | ||
| aliases = ["rs.ratatui.bundle-wry", "localhost"] | ||
| # The port to serve on. | ||
| port = 8080 | ||
| # Open a browser tab once the initial build is complete. | ||
| open = true | ||
| # Disable auto-reload of the web app. | ||
| no_autoreload = true | ||
|
|
||
| [clean] | ||
| # The output directory to clean. | ||
| dist = "dist" | ||
| # Whether to perform a cargo clean as well. | ||
| cargo = false | ||
|
|
||
| [tools] | ||
| # Versions of tools to download if not present in the system. | ||
| sass = "1.69.5" | ||
| wasm_bindgen = "0.2.126" | ||
| wasm_opt = "version_126" | ||
|
|
||
| # --- Proxies --- | ||
| # Proxy requests from the development server to a backend. | ||
| [[proxy]] | ||
| # Requests to /api/ will be proxied to the backend. | ||
| backend = "http://localhost:9000/api/" | ||
| # The prefix to strip from the incoming request URI before sending it to the backend. | ||
| rewrite = "/api/" | ||
|
|
||
| # --- Hooks --- | ||
| # Hooks are executed as part of the Trunk pipeline. | ||
| [[hooks]] | ||
| stage = "pre_build" | ||
| command = "echo" | ||
| command_arguments = ["Starting build process..."] | ||
|
|
||
| [[hooks]] | ||
| stage = "build" | ||
| command = "sh" | ||
| command_arguments = ["-c", "echo Staging directory: $TRUNK_STAGING_DIR"] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Ratzilla Demo</title> | ||
| <link data-trunk rel="rust" data-bin="bundle-wry" data-cargo-no-default-features /> | ||
| <style> | ||
| html { | ||
| height: 100%; | ||
| } | ||
| body { | ||
| position: relative; | ||
| height: calc(100% - 40px); | ||
| margin: 20px; | ||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: center; | ||
| align-items: center; | ||
| align-content: center; | ||
| background-color: #121212; | ||
| } | ||
| canvas { | ||
| display: block; | ||
| width: calc(100vw - 40px); | ||
| height: 100%; | ||
| } | ||
| pre { | ||
| font-family: "Fira Code", monospace; | ||
| font-size: 16px; | ||
| margin: 0px; | ||
| } | ||
| .topbar { | ||
| width: 100%; | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(dirname "${BASH_SOURCE[0]}")/common.sh" | ||
|
|
||
| usage() { | ||
| cat <<'EOF' | ||
| Usage: scripts/bundle.sh [--build] [--run] [--test] | ||
|
|
||
| Builds the macOS app bundle for bundle-wry. | ||
| --run opens the bundled macOS app. | ||
| --test opens the bundled macOS app, curls the bundled index.html, and verifies the HTML. | ||
| EOF | ||
| } | ||
|
|
||
| build=false | ||
| run=false | ||
| test=false | ||
|
|
||
| while [[ $# -gt 0 ]]; do | ||
| case "$1" in | ||
| --build) | ||
| build=true | ||
| shift | ||
| ;; | ||
| --run) | ||
| run=true | ||
| shift | ||
| ;; | ||
| --test) | ||
| test=true | ||
| shift | ||
| ;; | ||
| -h|--help) | ||
| usage | ||
| exit 0 | ||
| ;; | ||
| *) | ||
| echo "Unknown argument: $1" >&2 | ||
| usage >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| if [[ "$build" == false && "$run" == false && "$test" == false ]]; then | ||
| usage | ||
| exit 1 | ||
| fi | ||
|
|
||
| root="$(repo_root)" | ||
| cd "$root" | ||
|
|
||
| bundle_root="$(cargo_target_dir)/release/bundle" | ||
| bundle_name="bundle-wry" | ||
| bundle_app_path() { | ||
| find "$bundle_root" -type d -name "${bundle_name}.app" -print -quit | ||
| } | ||
|
|
||
| build_bundle() { | ||
| ensure_wasm_target | ||
| ensure_cargo_bundle | ||
| ensure_trunk | ||
|
|
||
| trunk build --release --dist dist | ||
| cargo bundle --bin bundle-wry --release | ||
| } | ||
|
|
||
| ensure_bundle() { | ||
| if [[ -z "$(bundle_app_path)" ]]; then | ||
| build_bundle | ||
| fi | ||
| } | ||
|
|
||
| run_bundle() { | ||
| local app_path | ||
| app_path="$(bundle_app_path)" | ||
| if [[ -z "$app_path" ]]; then | ||
| echo "Missing bundled app; run scripts/bundle.sh --build first." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| open "$app_path" | ||
| } | ||
|
|
||
| test_bundle() { | ||
| local app_path | ||
| local html | ||
| local app_pid="" | ||
| local url="http://127.0.0.1:8080" | ||
|
|
||
| app_path="$(bundle_app_path)" | ||
| if [[ -z "$app_path" ]]; then | ||
| echo "Missing bundled app; run scripts/bundle.sh --build first." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if lsof -nP -iTCP:8080 -sTCP:LISTEN >/dev/null 2>&1; then | ||
| echo "Port 8080 is already in use; stop the existing listener first." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| cleanup() { | ||
| if [[ -n "$app_pid" ]] && kill -0 "$app_pid" >/dev/null 2>&1; then | ||
| kill "$app_pid" >/dev/null 2>&1 || true | ||
| wait "$app_pid" >/dev/null 2>&1 || true | ||
| fi | ||
| } | ||
|
|
||
| trap cleanup EXIT | ||
|
|
||
| open "$app_path" | ||
|
|
||
| for _ in $(seq 1 60); do | ||
| app_pid="$(pgrep -n -f "${bundle_name}.app/Contents/MacOS/${bundle_name}" || true)" | ||
| if [[ -n "$app_pid" ]]; then | ||
| break | ||
| fi | ||
| sleep 1 | ||
| done | ||
|
|
||
| if [[ -z "$app_pid" ]]; then | ||
| echo "Timed out waiting for bundled app process to start." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| for _ in $(seq 1 60); do | ||
| if html="$(curl -fsS "$url" 2>/dev/null)"; then | ||
| break | ||
| fi | ||
| sleep 1 | ||
| done | ||
|
|
||
| if [[ -z "${html:-}" ]]; then | ||
| echo "Timed out waiting for $url" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| printf '%s' "$html" | grep -F '<title>Ratzilla Demo</title>' | ||
| js_path="$(printf '%s' "$html" | grep -oE "./[^']+\.js" | head -n 1)" | ||
| wasm_path="$(printf '%s' "$html" | grep -oE "./[^']+_bg\.wasm" | head -n 1)" | ||
| curl -fsS "$url/${js_path#./}" >/dev/null | ||
| curl -fsS "$url/${wasm_path#./}" >/dev/null | ||
|
|
||
| cleanup | ||
| trap - EXIT | ||
| printf 'Verified %s\n' "$url" | ||
| } | ||
|
|
||
| if [[ "$build" == true ]]; then | ||
| build_bundle | ||
| fi | ||
|
|
||
| if [[ "$run" == true ]]; then | ||
| ensure_bundle | ||
| run_bundle | ||
| fi | ||
|
|
||
| if [[ "$test" == true ]]; then | ||
| ensure_bundle | ||
| test_bundle | ||
| fi |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not prefer to have custom scripts for each example. I think we should somehow unify them either in a justfile or in the top-level
scripts/directory.