Skip to content

Commit 4e5b3cd

Browse files
authored
works
1 parent 2dc070b commit 4e5b3cd

File tree

3 files changed

+30
-69
lines changed

3 files changed

+30
-69
lines changed

README.md

Lines changed: 27 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# JavaScript bindings for "Hello world!" Rust WebAssembly component library
22

3-
🟪 Rust library compiled to WASM and distributed as a [WASM component]
3+
🔗 JavaScript bindings for [jcbhmr/hello-world-rust-wasm-component-lib]
44

55
<table align=center><td>
66

@@ -26,82 +26,43 @@ console.log(greetMany(["Alan Turing", "Ada Lovelace"]));
2626

2727
</table>
2828

29-
🦀 Written in Rust \
30-
[🟨 Usable in JavaScript](./hello-world-rust-wasm-component-lib.js/) \
31-
🌎 Runs on any [WebAssembly Component Runtime]
29+
<p align=center>
30+
<a href="https://tsdocs.dev/docs/hello-world-rust-wasm-component-lib">Docs</a>
31+
| <a href="https://github.com/jcbhmr/hello-world-rust-wasm-component-lib">WASM project</a>
32+
</p>
3233

3334
## Installation
3435

35-
![WebAssembly](https://img.shields.io/static/v1?style=for-the-badge&message=WebAssembly&color=654FF0&logo=WebAssembly&logoColor=FFFFFF&label=)
36-
![JavaScript](https://img.shields.io/static/v1?style=for-the-badge&message=JavaScript&color=222222&logo=JavaScript&logoColor=F7DF1E&label=)
37-
38-
The easiest way to get started is by using one of these wrapper libraries that
39-
already have all of the WASM host imports resolved.
40-
41-
For JavaScript users, you can use npm, [pnpm], [Yarn], or your other favorite
42-
npm package manager to install [`hello-world-rust-wasm-component-lib` from npm].
43-
4436
```sh
4537
npm install hello-world-rust-wasm-component-lib
4638
```
4739

48-
If you prefer to customize the Javascript ↔ WASM component bindings, you can
49-
use [bytecodealliance/jco] to generate your own bindings.
50-
5140
## Usage
5241

53-
![WebAssembly](https://img.shields.io/static/v1?style=for-the-badge&message=WebAssembly&color=654FF0&logo=WebAssembly&logoColor=FFFFFF&label=)
54-
![JavaScript](https://img.shields.io/static/v1?style=for-the-badge&message=JavaScript&color=222222&logo=JavaScript&logoColor=F7DF1E&label=)
55-
56-
You can use any [WASM host runtime for components]. You can find the API surface
57-
and any imports you need to provide in [`wit/world.wit`](wit/world.wit).
42+
```js
43+
import {
44+
greet,
45+
greetMany,
46+
run,
47+
getReport,
48+
computeArea,
49+
} from "./dist/hello_world_rust_wasm_component_lib.js";
5850

59-
For language-specific binding documentation, check out
60-
[hello-world-rust-wasm-component-lib.js].
51+
run();
52+
//=> Hello Alan Turing!
6153

62-
## Development
54+
console.log(getReport());
55+
//=> {
56+
// bouncyCastles: 100,
57+
// funPercent: 0.9,
58+
// catCount: 8,
59+
// unicornNames: [ 'Fluffy', 'Marshmallow', 'Sparkles' ]
60+
// }
6361

64-
![Rust](https://img.shields.io/static/v1?style=for-the-badge&message=Rust&color=000000&logo=Rust&logoColor=FFFFFF&label=)
65-
![WebAssembly](https://img.shields.io/static/v1?style=for-the-badge&message=WebAssembly&color=654FF0&logo=WebAssembly&logoColor=FFFFFF&label=)
62+
console.log(computeArea({ center: { x: 0, y: 0 }, radius: 6 }));
63+
//=> 113.09733552923255
6664

67-
```sh
68-
wget https://github.com/jcbhmr/hello-world-rust-wasm-component-lib/releases/download/v1.0.0/hello_world_rust_wasm_component_lib.wasm \
69-
-O /tmp/hello_world_rust_wasm_component_lib.wasm
70-
jco transpile /tmp/hello_world_rust_wasm_component_lib.wasm -o . \
71-
--map print=./print.js
65+
console.log(greetMany(["Alan Turing", "Ada Lovelace"]));
66+
//=> Hello, Alan Turing!
67+
// Hello, Ada Lovelace!
7268
```
73-
74-
ℹ You'll need [`wasm-tools`] installed which you can get via
75-
`cargo install wasm-tools`.
76-
77-
The `wasi_snapshot_preview1.reactor.wasm` is the adapter module to shim the
78-
component API over top of the existing WASI API. Keep it updated from
79-
[bytecodealliance/wasmtime releases]. Since this is a library we want the
80-
"reactor" version.
81-
82-
🚚 To create a new release, don't use the GitHub UI directly; use the [draft
83-
release] GitHub Actions workflow to create the initial draft release with the
84-
compiled WASM artifact. Then you can edit that release and publish it as normal.
85-
Make sure the `version` fields are correct before drafting the release; it's
86-
used to choose the `v${version}` tag name for the release and in publishing.
87-
Also try not to change the artifacts attached to the draft release; they were
88-
generated by GitHub Actions.
89-
90-
<!-- prettier-ignore -->
91-
✅ JavaScript: [jcbhmr/hello-world-rust-wasm-component-lib/hello-world-rust-wasm-component-lib.js](https://github.com/jcbhmr/hello-world-rust-wasm-component-lib/tree/main/hello-world-rust-wasm-component-lib.js) \
92-
❌ Python \
93-
❌ Rust
94-
95-
<!-- prettier-ignore-start -->
96-
[WASM host runtime for components]: https://github.com/bytecodealliance/wit-bindgen#host-runtimes-for-components
97-
[webassembly component runtime]: https://github.com/bytecodealliance/wit-bindgen#host-runtimes-for-components
98-
[bytecodealliance/jco]: https://github.com/bytecodealliance/jco
99-
[wasm component]: https://github.com/WebAssembly/component-model
100-
[`wasm-tools`]: https://github.com/bytecodealliance/wasm-tools
101-
[bytecodealliance/wasmtime releases]: https://github.com/bytecodealliance/wasmtime/releases
102-
[draft release]: https://github.com/jcbhmr/hello-world-wasm-component/actions/workflows/draft-release.yml
103-
[hello-world-rust-wasm-component-lib.js]: https://github.com/jcbhmr/hello-world-rust-wasm-component-lib/tree/main/hello-world-rust-wasm-component-lib.js
104-
[yarn]: https://yarnpkg.com/
105-
[pnpm]: https://pnpm.io/
106-
[`hello-world-rust-wasm-component-lib` from npm]: https://www.npmjs.com/package/hello-world-rust-wasm-component-lib
107-
<!-- prettier-ignore-end -->

index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test("computeArea() works", () => {
3232
computeArea({
3333
center: { x: 0, y: 0 },
3434
radius: 6,
35-
})
35+
}),
3636
);
3737
console.log("from JS", Math.PI * 6 * 6);
3838
});

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
"component",
1212
"webassembly-component"
1313
],
14-
"homepage": "https://github.com/jcbhmr/hello-world-rust-wasm-component-lib.js",
14+
"homepage": "https://tsdocs.dev/docs/hello-world-rust-wasm-component-lib",
1515
"repository": "github:jcbhmr/hello-world-rust-wasm-component-lib.js",
1616
"type": "module",
17-
"exports": "./hello_world_rust_wasm_component_lib.js",
17+
"exports": "./dist/hello_world_rust_wasm_component_lib.js",
1818
"files": [
1919
"dist",
2020
"print.js"

0 commit comments

Comments
 (0)