-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3749262
commit 4e0c0e1
Showing
44 changed files
with
1,638 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/target | ||
**/*.rs.bk | ||
Cargo.lock | ||
bin/ | ||
pkg/ | ||
wasm-pack.log | ||
tests | ||
LICENSE* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
language: rust | ||
sudo: false | ||
|
||
cache: cargo | ||
|
||
matrix: | ||
include: | ||
|
||
# Builds with wasm-pack. | ||
- rust: beta | ||
env: RUST_BACKTRACE=1 | ||
addons: | ||
firefox: latest | ||
chrome: stable | ||
before_script: | ||
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update) | ||
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate) | ||
- cargo install-update -a | ||
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f | ||
script: | ||
- cargo generate --git . --name testing | ||
# Having a broken Cargo.toml (in that it has curlies in fields) anywhere | ||
# in any of our parent dirs is problematic. | ||
- mv Cargo.toml Cargo.toml.tmpl | ||
- cd testing | ||
- wasm-pack build | ||
- wasm-pack test --chrome --firefox --headless | ||
|
||
# Builds on nightly. | ||
- rust: nightly | ||
env: RUST_BACKTRACE=1 | ||
before_script: | ||
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update) | ||
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate) | ||
- cargo install-update -a | ||
- rustup target add wasm32-unknown-unknown | ||
script: | ||
- cargo generate --git . --name testing | ||
- mv Cargo.toml Cargo.toml.tmpl | ||
- cd testing | ||
- cargo check | ||
- cargo check --target wasm32-unknown-unknown | ||
- cargo check --no-default-features | ||
- cargo check --target wasm32-unknown-unknown --no-default-features | ||
- cargo check --no-default-features --features console_error_panic_hook | ||
- cargo check --target wasm32-unknown-unknown --no-default-features --features console_error_panic_hook | ||
- cargo check --no-default-features --features "console_error_panic_hook wee_alloc" | ||
- cargo check --target wasm32-unknown-unknown --no-default-features --features "console_error_panic_hook wee_alloc" | ||
|
||
# Builds on beta. | ||
- rust: beta | ||
env: RUST_BACKTRACE=1 | ||
before_script: | ||
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update) | ||
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate) | ||
- cargo install-update -a | ||
- rustup target add wasm32-unknown-unknown | ||
script: | ||
- cargo generate --git . --name testing | ||
- mv Cargo.toml Cargo.toml.tmpl | ||
- cd testing | ||
- cargo check | ||
- cargo check --target wasm32-unknown-unknown | ||
- cargo check --no-default-features | ||
- cargo check --target wasm32-unknown-unknown --no-default-features | ||
- cargo check --no-default-features --features console_error_panic_hook | ||
- cargo check --target wasm32-unknown-unknown --no-default-features --features console_error_panic_hook | ||
# Note: no enabling the `wee_alloc` feature here because it requires | ||
# nightly for now. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[package] | ||
name = "test-1-simple-object" | ||
version = "0.1.0" | ||
authors = ["Vlad Chernenko <[email protected]>"] | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[features] | ||
default = ["console_error_panic_hook"] | ||
|
||
[dependencies] | ||
gloo-utils = { version = "0.1", features = ["serde"] } | ||
serde = { version = "1.0", features = ["derive"] } | ||
wasm-bindgen = "0.2.84" | ||
|
||
# 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.6", optional = true } | ||
|
||
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size | ||
# compared to the default allocator's ~10K. It is slower than the default | ||
# allocator, however. | ||
wee_alloc = { version = "0.4.5", optional = true } | ||
|
||
[dev-dependencies] | ||
wasm-bindgen-test = "0.3.13" | ||
|
||
[profile.release] | ||
# Tell `rustc` to optimize for small code size. | ||
opt-level = "s" | ||
lto = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<div align="center"> | ||
|
||
<h1><code>wasm-pack-template</code></h1> | ||
|
||
<strong>A template for kick starting a Rust and WebAssembly project using <a href="https://github.com/rustwasm/wasm-pack">wasm-pack</a>.</strong> | ||
|
||
<p> | ||
<a href="https://travis-ci.org/rustwasm/wasm-pack-template"><img src="https://img.shields.io/travis/rustwasm/wasm-pack-template.svg?style=flat-square" alt="Build Status" /></a> | ||
</p> | ||
|
||
<h3> | ||
<a href="https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html">Tutorial</a> | ||
<span> | </span> | ||
<a href="https://discordapp.com/channels/442252698964721669/443151097398296587">Chat</a> | ||
</h3> | ||
|
||
<sub>Built with 🦀🕸 by <a href="https://rustwasm.github.io/">The Rust and WebAssembly Working Group</a></sub> | ||
</div> | ||
|
||
## About | ||
|
||
[**📚 Read this template tutorial! 📚**][template-docs] | ||
|
||
This template is designed for compiling Rust libraries into WebAssembly and | ||
publishing the resulting package to NPM. | ||
|
||
Be sure to check out [other `wasm-pack` tutorials online][tutorials] for other | ||
templates and usages of `wasm-pack`. | ||
|
||
[tutorials]: https://rustwasm.github.io/docs/wasm-pack/tutorials/index.html | ||
[template-docs]: https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html | ||
|
||
## 🚴 Usage | ||
|
||
### 🐑 Use `cargo generate` to Clone this Template | ||
|
||
[Learn more about `cargo generate` here.](https://github.com/ashleygwilliams/cargo-generate) | ||
|
||
``` | ||
cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project | ||
cd my-project | ||
``` | ||
|
||
### 🛠️ Build with `wasm-pack build` | ||
|
||
``` | ||
wasm-pack build | ||
``` | ||
|
||
### 🔬 Test in Headless Browsers with `wasm-pack test` | ||
|
||
``` | ||
wasm-pack test --headless --firefox | ||
``` | ||
|
||
### 🎁 Publish to NPM with `wasm-pack publish` | ||
|
||
``` | ||
wasm-pack publish | ||
``` | ||
|
||
## 🔋 Batteries Included | ||
|
||
* [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating | ||
between WebAssembly and JavaScript. | ||
* [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook) | ||
for logging panic messages to the developer console. | ||
* [`wee_alloc`](https://github.com/rustwasm/wee_alloc), an allocator optimized | ||
for small code size. | ||
* `LICENSE-APACHE` and `LICENSE-MIT`: most Rust projects are licensed this way, so these are included for you | ||
|
||
## License | ||
|
||
Licensed under either of | ||
|
||
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) | ||
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) | ||
|
||
at your option. | ||
|
||
### Contribution | ||
|
||
Unless you explicitly state otherwise, any contribution intentionally | ||
submitted for inclusion in the work by you, as defined in the Apache-2.0 | ||
license, shall be dual licensed as above, without any additional terms or | ||
conditions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use gloo_utils::format::JsValueSerdeExt; | ||
use serde::{Serialize, Deserialize}; | ||
use std::collections::HashMap; | ||
use wasm_bindgen::prelude::*; | ||
|
||
|
||
|
||
//-------------------- IMPORTS ---------------------- | ||
|
||
|
||
#[wasm_bindgen] | ||
extern "C" { | ||
|
||
#[wasm_bindgen(js_namespace = console)] | ||
fn log(s: &str); | ||
|
||
} | ||
|
||
|
||
|
||
#[derive(Serialize, Deserialize,Debug)] | ||
pub struct Example { | ||
pub field1: HashMap<u32, String>, | ||
pub field2: Vec<Vec<f32>>, | ||
pub field3: [f32; 4], | ||
} | ||
|
||
|
||
|
||
#[wasm_bindgen] | ||
pub fn send_example_to_js() -> JsValue { | ||
|
||
let mut field1 = HashMap::new(); | ||
|
||
field1.insert(0, String::from("ex")); | ||
|
||
let example = Example { | ||
field1, | ||
field2: vec![vec![1., 2.], vec![3., 4.]], | ||
field3: [1., 2., 3., 4.] | ||
}; | ||
|
||
<JsValue as JsValueSerdeExt>::from_serde(&example).unwrap() | ||
|
||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn receive_example_from_js(val: JsValue) { | ||
|
||
let example: Example = val.into_serde().unwrap(); | ||
|
||
log("Object accepted inside WASM"); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/target | ||
**/*.rs.bk | ||
Cargo.lock | ||
bin/ | ||
pkg/ | ||
wasm-pack.log | ||
tests | ||
LICENSE* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
language: rust | ||
sudo: false | ||
|
||
cache: cargo | ||
|
||
matrix: | ||
include: | ||
|
||
# Builds with wasm-pack. | ||
- rust: beta | ||
env: RUST_BACKTRACE=1 | ||
addons: | ||
firefox: latest | ||
chrome: stable | ||
before_script: | ||
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update) | ||
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate) | ||
- cargo install-update -a | ||
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f | ||
script: | ||
- cargo generate --git . --name testing | ||
# Having a broken Cargo.toml (in that it has curlies in fields) anywhere | ||
# in any of our parent dirs is problematic. | ||
- mv Cargo.toml Cargo.toml.tmpl | ||
- cd testing | ||
- wasm-pack build | ||
- wasm-pack test --chrome --firefox --headless | ||
|
||
# Builds on nightly. | ||
- rust: nightly | ||
env: RUST_BACKTRACE=1 | ||
before_script: | ||
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update) | ||
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate) | ||
- cargo install-update -a | ||
- rustup target add wasm32-unknown-unknown | ||
script: | ||
- cargo generate --git . --name testing | ||
- mv Cargo.toml Cargo.toml.tmpl | ||
- cd testing | ||
- cargo check | ||
- cargo check --target wasm32-unknown-unknown | ||
- cargo check --no-default-features | ||
- cargo check --target wasm32-unknown-unknown --no-default-features | ||
- cargo check --no-default-features --features console_error_panic_hook | ||
- cargo check --target wasm32-unknown-unknown --no-default-features --features console_error_panic_hook | ||
- cargo check --no-default-features --features "console_error_panic_hook wee_alloc" | ||
- cargo check --target wasm32-unknown-unknown --no-default-features --features "console_error_panic_hook wee_alloc" | ||
|
||
# Builds on beta. | ||
- rust: beta | ||
env: RUST_BACKTRACE=1 | ||
before_script: | ||
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update) | ||
- (test -x $HOME/.cargo/bin/cargo-generate || cargo install --vers "^0.2" cargo-generate) | ||
- cargo install-update -a | ||
- rustup target add wasm32-unknown-unknown | ||
script: | ||
- cargo generate --git . --name testing | ||
- mv Cargo.toml Cargo.toml.tmpl | ||
- cd testing | ||
- cargo check | ||
- cargo check --target wasm32-unknown-unknown | ||
- cargo check --no-default-features | ||
- cargo check --target wasm32-unknown-unknown --no-default-features | ||
- cargo check --no-default-features --features console_error_panic_hook | ||
- cargo check --target wasm32-unknown-unknown --no-default-features --features console_error_panic_hook | ||
# Note: no enabling the `wee_alloc` feature here because it requires | ||
# nightly for now. |
Oops, something went wrong.