Skip to content
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

feat: add wasm-pack to allow publishing to npm #351

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target

.DS_Store
146 changes: 115 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,18 @@ schemars = ["alloc", "serde", "serde_json", "dep:schemars"]
arbitrary = ["std", "dep:arbitrary"]
hex = []

wasm = ["std", "curr", "base64", "serde", "serde_json", "schemars", "dep:thiserror"]
# can also be compiled with --wasm32-wasi
cli = ["dep:clap", "wasm"]
# Features for the CLI.
cli = ["std", "curr", "next", "base64", "serde", "serde_json", "schemars", "dep:clap", "dep:thiserror"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docs"]

[workspace]
members = ["crates/*"]

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"
Comment on lines +63 to +66
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may not want to use the same profile for the stellar-xdr CLI and the wasm crate, so having them in a shared workspace may not be ideal. Let's not change this now, but we might need to change this before we merge.

24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,28 @@ Parse a `BucketEntry` framed stream from a bucket file:
stellar-xdr decode --type BucketEntry --input stream-framed --output json-formatted bucket.xdr
```

## Wasm pack

`wasm-pack.sh` will use [`wasm-pack`](https://rustwasm.github.io/wasm-pack/installer/) to build a npm package and use [yalc](https://github.com/wclr/yalc) pubilsh it locally. It uses the following environment variables:
- `PROFILE` - default `dev`
- `TARGETS` - default `bundler nodejs web no-modules`

After running the script you can install the package corresponding target with yalc:

```
yalc add stellar-xdr-wasm-web
yalc link stellar-xdr-wasm-web
```

Then you can import package as normal

```ts
import * as xdr from "stellar-xdr-wasm-web";
```

#### cargo watch for changes

```
cargo watch -s "TARGETS=web ./wasm-pack.sh"
```
License: Apache-2.0
11 changes: 11 additions & 0 deletions crates/stellar-xdr-wasm/.appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
install:
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
- if not defined RUSTFLAGS rustup-init.exe -y --default-host x86_64-pc-windows-msvc --default-toolchain nightly
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
- rustc -V
- cargo -V

build: false

test_script:
- cargo test --locked
6 changes: 6 additions & 0 deletions crates/stellar-xdr-wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/target
**/*.rs.bk
Cargo.lock
bin/
pkg/
wasm-pack.log
28 changes: 28 additions & 0 deletions crates/stellar-xdr-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "stellar-xdr-wasm"
version = "0.1.0"
authors = ["Willem Wyndham <[email protected]>"]
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["console_error_panic_hook"]
schema = []

[dependencies]
wasm-bindgen = "0.2.84"
stellar-xdr = { path = "../..", package = "stellar-xdr", features = ["wasm"]}

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.7", optional = true }
serde-json-wasm = "1.0.1"
serde_json = "1.0.114"

[dev-dependencies]
wasm-bindgen-test = "0.3.34"

Loading
Loading