{"id":16114968,"url":"https://github.com/simbleau/abridge-wasm","last_synced_at":"2025-10-08T23:45:55.586Z","repository":{"id":40988173,"uuid":"508101043","full_name":"simbleau/abridge-wasm","owner":"simbleau","description":"A repository for WASM components to be used within Abridge","archived":false,"fork":false,"pushed_at":"2022-08-12T14:17:30.000Z","size":36,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-06T08:19:16.562Z","etag":null,"topics":["abridge","wasm","zola"],"latest_commit_sha":null,"homepage":"https://simbleau.github.io/abridge-wasm/demos/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simbleau.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-28T00:20:37.000Z","updated_at":"2024-02-18T17:58:59.000Z","dependencies_parsed_at":"2022-09-12T08:11:00.983Z","dependency_job_id":null,"html_url":"https://github.com/simbleau/abridge-wasm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/simbleau/abridge-wasm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simbleau%2Fabridge-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simbleau%2Fabridge-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simbleau%2Fabridge-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simbleau%2Fabridge-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simbleau","download_url":"https://codeload.github.com/simbleau/abridge-wasm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simbleau%2Fabridge-wasm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274348655,"owners_count":25268972,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-09T02:00:10.223Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abridge","wasm","zola"],"created_at":"2024-10-09T20:16:50.314Z","updated_at":"2025-10-08T23:45:50.520Z","avatar_url":"https://github.com/simbleau.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🌐 Abridge + WASM\nA monolithic repository for WASM components to be exported for use in [Abridge](https://github.com/Jieiku/abridge).\n\n# ✅ Demos\n- See [demos](https://simbleau.github.io/abridge-wasm/demos/) served by GitHub Pages.\n\n# ⚠️ Status\nCurrently this is all research and experimentation. Please submit pull requests/issues.\n\nAt this time, optimization is not a priority. [There are several ways to optimize the WASM bundle size](https://rustwasm.github.io/book/reference/code-size.html) once Abridge's WASM components are made and algorithms are optimized.\n\n# 🏁 Quickstart\n## Dependencies\n- [Rust](https://www.rust-lang.org/tools/install)\n- [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/)\n\n### Install Rust:\n```shell\ncurl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh\nrustup update\n```\n\n### Install wasm-pack\n```shell\ncurl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh\n```\n\n## Build\n```shell\ngit clone https://github.com/simbleau/abridge-wasm\ncd abridge-wasm\nwasm-pack build --release --target web\n```\n\n## Serve\n```shell\npython3 -m http.server\n```\n\n- View: [http://0.0.0.0:8000/](http://0.0.0.0:8000/)\n- View Demo: [http://0.0.0.0:8000/demos/theme-switch/](http://0.0.0.0:8000/demos/theme-switch/)\n\n# 🟧 Exporting to Abridge\n## Building WASM\n- [lib.rs](src/lib.rs) will export **any** modules that are (privately or publicly) included. When creating a demo, it makes sense to only export the module for the demo itself. However, for Abridge, we should include only everything a certain page needs.\n- [Build](#build) the WASM artifacts.\n- You will only need `abridge_wasm_bg.wasm` and `abridge_wasm.js`. The other files were generated for npm, and serve us no purpose. I am unsure if there is a way to only generate these 2 files.\n\n## Optimizing Bundle Size\n### Release settings\n- I have only optimized the WASM settings `build --release` settings in the [`Cargo.toml`](Cargo.toml).\n### Avoid macros and type conversions\n- *At all costs*. [They add bloat](https://rustwasm.github.io/book/reference/code-size.html#avoid-string-formatting).\n### Avoid panicky code\n- *At all costs*. [Panicking adds bloat, similar to macros](https://rustwasm.github.io/book/reference/code-size.html#avoid-panicking).\n- [`twiggy`](https://github.com/rustwasm/twiggy) can be used to inspect LLVM-IR to determine which functions are panicking. The functions do not need to call `panic()`. Instead, they can arise naturally:\n  - Indexing a slice panics on out of bounds indices: `my_slice[i]`\n  - Division will panic if the divisor is zero: `dividend / divisor`\n  - Unwrapping an `Option` or `Result`: `opt.unwrap()` or `res.unwrap()`\n### Twiggy guide\n- Install twiggy: `cargo install twiggy`\n- Re-build WASM with `--dev` to retain function symbols, e.g. `wasm-pack build --dev --target web`\n- Some things I check:\n  - **Currently a lot more research needs to go into this...**\n  - `twiggy garbase pkg/abridge_wasm_bg.wasm`, for dead functions. I am unsure how to strip these functions right now.\n  - `twiggy top pkg/abridge_wasm_bg.wasm | head`, for the largest functions\n  - `twiggy paths pkg/abridge_wasm_bg.wasm | grep panic -B 1 | grep -v '⬑' | grep -v '\\-\\-'`, A hacky script to check if panics are used in the WASM\n### Minify JavaScript files\n- *Help needed*: steps to minify the javascript file exported\n### No-std?\n- *Help needed*: *I am currently unsure if no-std and [wee_alloc](https://github.com/rustwasm/wee_alloc) will help. \n\n## Linking WASM\n## Method 1: WASM-Glue\n- You may need to make a `wasm-glue.js` wrapper which imports the `abridge_wasm.js` and attaches functionality to certain elements\n  - e.g. [example](demos/theme-switch/wasm-glue.js)\n- Include the WASM glue script in the head of your HTML.\n  - e.g. `\u003cscript defer type=\"module\" src=\"wasm-glue.js\"\u003e\u003c/script\u003e`.\n## Method 2: Pure WASM with light wrapper\n- I need to test which is better still. It is possible to grab the HTML elements outright by ID in Rust and add functionality inline, such as click handlers or changing a class. This would eliminate the need for a `glue` file alltogether. This will be my next experiment.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimbleau%2Fabridge-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimbleau%2Fabridge-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimbleau%2Fabridge-wasm/lists"}