Skip to content

Commit

Permalink
Fix wasm-pack build error (#141)
Browse files Browse the repository at this point in the history
* Fix wasm-pack build error

* Added sample apps for nodejs and web

---------

Co-authored-by: Artemkaaas <[email protected]>
  • Loading branch information
DmitryKuzmenko and Artemkaaas authored Apr 14, 2023
1 parent 1875bf0 commit e71400f
Show file tree
Hide file tree
Showing 15 changed files with 4,265 additions and 50 deletions.
2 changes: 1 addition & 1 deletion wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ crate-type = ["cdylib", "rlib"]
[features]
tmp_dev = []

[dev-dependencies.getrandom]
[dependencies.getrandom]
version = '0.2'
features = ['js']

Expand Down
29 changes: 26 additions & 3 deletions wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,33 @@ You can build the FFI with
$ wasm-pack build
```

You can run an PoC test with
### How to build
Install wasm-pack from https://rustwasm.github.io/wasm-pack/installer/ and then
```
make # Will output modules best-suited to be bundled with webpack
WASM_TARGET=nodejs make # Will output modules that can be directly consumed by NodeJS
WASM_TARGET=web make # Will output modules that can be directly consumed in browser without bundler usage
```

### How to build with wasm-pack build
```
wasm-pack build # Will output modules best-suited to be bundled with webpack
wasm-pack build --target=nodejs # Will output modules that can be directly consumed by NodeJS
wasm-pack build --target=web # Will output modules that can be directly consumed in browser without bundler usage
```

### Run NodeJS demo
```
cd demo/node
yarn install
yarn start
```

### Run demo шт Browser
```
$ npm run serve
cd demo/web
yarn install
yarn serve
```

and then visiting http://localhost:8080 in a browser should run the example!
and then visit http://localhost:8080 in a browser should run the example!
1 change: 1 addition & 0 deletions wasm/demo/node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
20 changes: 20 additions & 0 deletions wasm/demo/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "cesride-wasm-demo",
"version": "0.1.0",
"description": "JS demo for cesride wasm bindings",
"scripts": {
"start": "ts-node src/main.ts",
"check": "tslint -c tslint.json 'src/**/*.ts'"
},
"author": "",
"license": "Apache-2.0",
"dependencies": {
"cesride-wasm": "file:../../pkg",
"typescript": "^4.5.2"
},
"devDependencies": {
"@types/node": "^16.11.10",
"ts-node": "^10.4.0",
"tslint": "^6.1.3"
}
}
16 changes: 16 additions & 0 deletions wasm/demo/node/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Dater } from "cesride-wasm";

function main() {
const date = Dater.new_with_dts("2020-08-22T17:50:09.988921+00:00");
console.log("<p>Date:</p>");
console.log("dts: " + date.dts() + "<br/>");
console.log("dtsb: " + date.dtsb() + "<br/>");
console.log("code: " + date.code() + "<br/>");
console.log("size: " + date.size() + "<br/>");
console.log("raw: " + date.raw() + "<br/>");
console.log("qb64: " + date.qb64() + "<br/>");
console.log("qb64b: " + date.qb64b() + "<br/>");
console.log("qb2: " + date.qb2() + "<br/>");
}

main()
12 changes: 12 additions & 0 deletions wasm/demo/node/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {
"no-console": false,
"max-classes-per-file": false
},
"rulesDirectory": []
}
Loading

0 comments on commit e71400f

Please sign in to comment.