Skip to content

Commit f18b20e

Browse files
committed
Add index page for the gh-pages
Add GitHub Actions workflow for deploying to GitHub Pages and update project for WebAssembly. * **GitHub Actions Workflow** - Create `.github/workflows/deploy-gh-pages.yml` to deploy static content to GitHub Pages on push to `main` branch. - Add steps to check out the repository, set up Rust, build the project, install `wasm-bindgen-cli`, generate `wasm-bindgen` output, copy `index.html` to deploy directory, set up Pages, upload artifact, and deploy to GitHub Pages. * **Project Configuration** - Modify `Cargo.toml` to add dependencies for `wasm-bindgen` and `wasm-server-runner`. * **Main Function** - Modify `src/main.rs` to add `wasm_bindgen::prelude::*` to imports. - Add `#[wasm_bindgen(start)]` attribute to the `main` function. * **Index Page** - Add `index.html` to load the WebAssembly module and generated JavaScript glue code. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/cabrownlie/random-shader-window?shareId=XXXX-XXXX-XXXX-XXXX).
1 parent 6953b8e commit f18b20e

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

.github/workflows/deploy-gh-pages.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Simple workflow for deploying static content to GitHub Pages
2+
name: Deploy static content to Pages
3+
4+
on:
5+
# Runs on main when a release is published
6+
release:
7+
types: [published]
8+
branches: ["main"]
9+
push:
10+
branches: ["main"]
11+
12+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
concurrency:
19+
group: "pages"
20+
cancel-in-progress: false
21+
22+
jobs:
23+
# Single deploy job since we're just deploying
24+
deploy:
25+
environment:
26+
name: github-pages
27+
url: ${{ steps.deployment.outputs.page_url }}
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
- name: Set up Rust
33+
uses: actions-rs/toolchain@v1
34+
with:
35+
toolchain: stable
36+
- name: Build the project
37+
run: cargo build --release --target wasm32-unknown-unknown
38+
- name: Install wasm-bindgen-cli
39+
run: cargo install wasm-bindgen-cli
40+
- name: Generate wasm-bindgen output
41+
run: wasm-bindgen target/wasm32-unknown-unknown/release/random_shader_window.wasm --out-dir ./out --web
42+
- name: Copy index.html to deploy directory
43+
run: cp index.html ./out
44+
- name: Setup Pages
45+
uses: actions/configure-pages@v4
46+
- name: Upload artifact
47+
uses: actions/upload-pages-artifact@v3
48+
with:
49+
# Upload entire repository
50+
path: ./out
51+
- name: Deploy to GitHub Pages
52+
id: deployment
53+
uses: actions/deploy-pages@v4

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ wgpu = { version = "24.0.1", features = ["webgl"] }
1414
bytemuck = "1.22.0"
1515
pollster = "0.4.0"
1616
wasm-bindgen-futures = "0.4.50"
17+
wasm-bindgen = "0.2.78"
18+
wasm-server-runner = "0.1.0"

index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Random Shader Window</title>
7+
</head>
8+
<body>
9+
<script type="module">
10+
import init from "./random_shader_window.js";
11+
init();
12+
</script>
13+
</body>
14+
</html>

src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use std::sync::Arc;
2+
use wasm_bindgen::prelude::*;
23

34
use random_shader_window::app::App;
45
use winit::{event_loop::EventLoop, window::Window};
56

6-
fn main() {
7+
#[wasm_bindgen(start)]
8+
pub fn main() {
79
let event_loop = EventLoop::new().unwrap();
810

911
let window = Arc::new(

0 commit comments

Comments
 (0)