Skip to content

Commit f4f78ac

Browse files
authored
Merge pull request #36 from rust-amplify/wasm
WASM support
2 parents 4016b9d + 34a5bd4 commit f4f78ac

File tree

7 files changed

+198
-9
lines changed

7 files changed

+198
-9
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,18 @@ jobs:
4040
run: rustup target add wasm32-unknown-unknown
4141
- name: Test in headless Chrome
4242
run: wasm-pack test --headless --chrome
43+
wasm-dependency:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v2
47+
- name: Install rust stable
48+
uses: actions-rs/toolchain@v1
49+
with:
50+
toolchain: stable
51+
override: true
52+
- uses: Swatinem/rust-cache@v2
53+
- uses: jetli/wasm-pack-action@v0.3.0
54+
- name: Add wasm32 target
55+
run: rustup target add wasm32-unknown-unknown
56+
- name: Test building dependency
57+
run: cd test/wasm && wasm-pack build

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Generated by Cargo
22
# will have compiled files and executables
3-
/target
3+
target/
44

55
# These are backup files generated by rustfmt
66
**/*.rs.bk

syn/src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ impl ParametrizedAttr {
538538
/// fusion takes a nested meta data.
539539
#[inline]
540540
pub fn fuse(&mut self, attr: &Attribute) -> Result<(), Error> {
541-
let args = MetaArgList::parse.parse(attr.tokens.clone().into())?;
541+
let args = MetaArgList::parse.parse2(attr.tokens.clone().into())?;
542542
for arg in args.list {
543543
match arg {
544544
// `#[ident("literal", ...)]`

syn/src/val.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl From<Option<LitStr>> for ArgValue {
118118

119119
impl From<Ident> for ArgValue {
120120
fn from(ident: Ident) -> Self {
121-
Path::from(PathSegment::parse.parse(quote! { #ident }.into()).unwrap()).into()
121+
Path::from(PathSegment::parse.parse2(quote! { #ident }.into()).unwrap()).into()
122122
}
123123
}
124124

@@ -304,7 +304,7 @@ impl TryFrom<ArgValue> for Path {
304304
fn try_from(value: ArgValue) -> Result<Self, Self::Error> {
305305
match value {
306306
ArgValue::Expr(expr) => Path::parse
307-
.parse(expr.to_token_stream().into())
307+
.parse2(expr.to_token_stream().into())
308308
.map_err(Error::from),
309309
ArgValue::Type(Type::Path(ty)) => Ok(ty.path),
310310
_ => Err(Error::ArgValueMustBeType),
@@ -318,10 +318,10 @@ impl TryFrom<ArgValue> for Expr {
318318
fn try_from(value: ArgValue) -> Result<Self, Self::Error> {
319319
match value {
320320
ArgValue::Literal(lit) => Expr::parse
321-
.parse(lit.to_token_stream().into())
321+
.parse2(lit.to_token_stream().into())
322322
.map_err(Error::from),
323323
ArgValue::Type(ty) => Expr::parse
324-
.parse(ty.to_token_stream().into())
324+
.parse2(ty.to_token_stream().into())
325325
.map_err(Error::from),
326326
ArgValue::Expr(expr) => Ok(expr),
327327
ArgValue::None => Err(Error::ArgValueMustBeExpr),
@@ -427,7 +427,7 @@ impl TryFrom<ArgValue> for Option<Path> {
427427
ArgValue::Type(Type::Path(ty)) => Ok(Some(ty.path)),
428428
ArgValue::Expr(expr) => Some(
429429
Path::parse
430-
.parse(expr.into_token_stream().into())
430+
.parse2(expr.into_token_stream().into())
431431
.map_err(Error::from),
432432
)
433433
.transpose(),
@@ -445,13 +445,13 @@ impl TryFrom<ArgValue> for Option<Expr> {
445445
ArgValue::Expr(expr) => Ok(Some(expr)),
446446
ArgValue::Type(ty) => Some(
447447
Expr::parse
448-
.parse(ty.into_token_stream().into())
448+
.parse2(ty.into_token_stream().into())
449449
.map_err(Error::from),
450450
)
451451
.transpose(),
452452
ArgValue::Literal(lit) => Some(
453453
Expr::parse
454-
.parse(lit.into_token_stream().into())
454+
.parse2(lit.into_token_stream().into())
455455
.map_err(Error::from),
456456
)
457457
.transpose(),

test/wasm/Cargo.lock

Lines changed: 146 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/wasm/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[workspace]
2+
members = ["."]
3+
4+
[package]
5+
name = "amplify_derive_wasm_test"
6+
version = "0.1.0"
7+
edition = "2021"
8+
9+
[lib]
10+
crate-type = ["cdylib", "rlib"]
11+
12+
[dependencies]
13+
amplify_derive = { path = "../.." }
14+
wasm-bindgen = "0.2.84"

test/wasm/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub fn add(left: usize, right: usize) -> usize {
2+
left + right
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use super::*;
8+
9+
#[test]
10+
fn it_works() {
11+
let result = add(2, 2);
12+
assert_eq!(result, 4);
13+
}
14+
}

0 commit comments

Comments
 (0)