This experiment shows connecting wasm-bindgen generated code to a good-web-game application.

Overview

GWG + wasm-bindgen example

This experiment shows connecting wasm-bindgen generated code to a good-web-game application.

It uses simple_logger crate to log! in native mode and console_log in WASM mode. Both versions build from the same codebase. You should see gwg main-loop lifecycle methods calls in console.

It requires a modification in the bindgen generated .js file (see sed call below) and a boilerplate plugin for miniquad wasm loader - see index.html.

Building

Native

$ cargo run
    Finished dev [unoptimized + debuginfo] target(s)
     Running `target/debug/gwg_bindgen`

WASM

pre-req

$ rustup target add wasm32-unknown-unknown
info: downloading component 'rust-std' for 'wasm32-unknown-unknown'
info: installing component 'rust-std' for 'wasm32-unknown-unknown'
$ cargo install wasm-bindgen-cli

build & run

$ cargo build --release --target wasm32-unknown-unknown
   Compiling gwg_bindgen v0.1.0 (gwg_bindgen)
    Finished release [optimized] target(s)
$ wasm-bindgen --out-dir target --target web target/wasm32-unknown-unknown/release/gwg_bindgen.wasm
$ sed -i 's/import.*from .env.;/init.set_wasm = w => wasm = w;/;s/imports\[.env.\] =.*/return imports;/' target/gwg_bindgen.js

Then serve project dir to browser. i.e.

$ basic-http-server .
[INFO ] basic-http-server 0.8.1
[INFO ] addr: http://127.0.0.1:4000
[INFO ] root dir: .
You might also like...
A tray application for Windows that gives you push notifications and instant downloads of new posts, messages and stories posted by models you subscribe to on Onlyfans.

OF-notifier A tray application for Windows that gives you push notifications and instant downloads of new posts, messages and stories posted by models

A relatively simple puzzle generator application written in Rust and used via Javascript
A relatively simple puzzle generator application written in Rust and used via Javascript

Puzzlip Basic Overview This is a relatively simple puzzle generator application written in Rust and used via Javascript in https://puzzlip.com. If you

A Domain Driven Design example application in Rust.

Rust Domain Driven Design Example rust-ddd Rust Domain-Driven-Design (DDD) Summery This repository is used to present how I find implementing DDD in R

A mobile application platform for tertiary students to communicate, collaborate and share ideas with each other

Qreeket (pronounced "cricket") A mobile application platform for tertiary students to communicate, collaborate and share ideas with each other. As the

My journey of learning rust as a web developer.

My journey of learning rust Low-level languages seem very interesting to me. I always wanted to learn a low-level language but never had the chance. T

Roadmap to becoming a Rust Web Developer in 2021

Roadmap to becoming a Rust Web Developer in 2021

Simple RESTful API in rust created with actix-web. (Routing, models, JWT auth).

rust-simple-api Simple RESTful API created with rust, actix-web, Diesel, JWT. Running application Manual Firstly generate a secret.key which will be u

Diosic is an open source web-based music collection server and streamer

Diosic is an open source web-based music collection server and streamer. Mainly suitable for users who need to deploy on servers with low hardware specifications.

Comments
  • Wasm build fails

    Wasm build fails

    The Wasm build steps currently don't produce a working example here.. I think its due to a dependency in web_logger ?

    Uncaught RuntimeError: unreachable
        at std::panicking::rust_panic_with_hook::h894f2bdeea4d0ce8 (wasm-function[248]:237)
        at std::panicking::begin_panic_handler::{{closure}}::he30feeb51ae9f99b (wasm-function[282]:122)
        at std::sys_common::backtrace::__rust_end_short_backtrace::h83a4032c6b997446 (wasm-function[418]:40)
        at rust_begin_unwind (wasm-function[378]:60)
        at core::panicking::panic_fmt::h0dfe153eb0ef456a (wasm-function[420]:48)
        at core::panicking::panic::ha2f229d777a180c9 (wasm-function[365]:67)
        at <stdweb::webcore::serialization::SerializedValue as core::convert::From<stdweb::webcore::serialization::SerializedUntaggedString>>::from::hcfdb9c44d50c7c03 (wasm-function[540]:14)
        at <web_logger::WebLogger as log::Log>::log::h56c1faa1e2233630 (wasm-function[222]:247)
        at log::__private_api_log::h03964bce5c393e83 (wasm-function[255]:201)
        at <gwg_bindgen::MainState as good_web_game::event::EventHandler>::resize_event::hd065a6b06379f15a (wasm-function[216]:207)
    
    opened by ghost 0
Owner
Tomasz Sterna
dreamin' in code
Tomasz Sterna
A typesafe, flexible, simple, and user-friendly unit system library for Rust that has good error messages.

uy A typesafe, flexible, simple, and user-friendly unit system library for Rust that has good error messages. Usage uy not only stores the unit of a v

Lachlan Sneff 19 Aug 8, 2023
A learning project/fun experiment in internet protocol

Piper a learning project/fun experiment in internet protocol Version 0.4.0 (SEMVER) Goals Piper is Simple. A page is a page. There are no secondary re

null 13 Oct 27, 2022
Shows how to implement USB device on RP2040 in Rust, in a single file, with no hidden parts.

Rust RP2040 USB Device Example This is a worked example of implementing a USB device on the RP2040 microcontroller, in Rust. It is designed to be easy

Cliff L. Biffle 9 Dec 7, 2022
Safe, comp time generated queries in rust

query_builder For each struct field following methods will be generated. All fields where_FIELDNAME_eq Numeric fields where_FIELDNAME_le where_FIELDNA

Amirreza Askarpour 2 Oct 31, 2021
The source code that accompanies Hands-on Rust: Effective Learning through 2D Game Development and Play by Herbert Wolverson

Hands-on Rust Source Code This repository contains the source code for the examples found in Hands-on Rust. These are also available from my publisher

Herbert 261 Dec 14, 2022
Bad Apple!! music video on WASM-4

w4-bad-apple Bad Apple!! music video on the WASM-4 fantasy console. Building First, you need to create a frames directory containing an image for each

Mark Carlson 7 Jul 2, 2022
A minimal boilerplate for Astro / Vite with the Nannou creative framework (Rust → WASM). Supports multiple sketches + hot-reload.

Astro x Nannou Starter astro-nannou-demo-1c.mov ?? Try it online! # 0a. Rust language tools open https://www.rust-lang.org/tools/install # 0b. wasm-p

Julian Cataldo 4 Jan 4, 2023
Operating system based off of blog_os, with the goal of running wasm modules as executables

yavkOS - A OS that attempts at running WASM modules as userspace programs Recommended Development Environment You need nix with the flakes, and nix-co

Yavor Kolev 12 Apr 1, 2023
ARM TrustZone-M example application in Rust, both secure world side and non-secure world side

ARM TrustZone-M example application in Rust, both secure world side and non-secure world side; projects are modified from generated result of cortex-m-quickstart.

null 44 Dec 4, 2022
A sample Rust application modeled after Spring PetClinic.

Rust PetClinic Sample Application A sample Rust application modeled after Spring PetClinic. Overview This application uses axum and SeaORM on the serv

Eleftheria Stein-Kousathana 9 Sep 15, 2022