Skip to content

Commit 0524b48

Browse files
authored
Merge pull request #53 from mjbvz/add-wasm-package
Add wasm package
2 parents 0600265 + 83c5fac commit 0524b48

File tree

11 files changed

+4048
-44
lines changed

11 files changed

+4048
-44
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ jobs:
2828
- name: Build
2929
run: make build
3030

31+
- name: Build JS
32+
run: make build-js
33+
3134
lint:
3235
name: Lint
3336
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Cargo.lock
33
/crates/*/target/
44
/crates/*/Cargo.lock
55
.vscode/
6+
.DS_Store

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.PHONY: all
2-
all: build lint test
2+
all: build build-js lint test
33

44
.PHONY: clean
55
clean:
@@ -22,6 +22,11 @@ build:
2222
# Use --all-targets to ensure that all of the benchmarks compile.
2323
cargo build --all-targets --all-features
2424

25+
.PHONY: build-js
26+
build-js:
27+
npm --prefix crates/string-offsets/js install
28+
npm --prefix crates/string-offsets/js run compile
29+
2530
.PHONY: test
2631
test:
2732
RUST_BACKTRACE=1 cargo test

crates/string-offsets/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
pkg
3+
.tgz

crates/string-offsets/CONTRIBUTING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Contributing
2+
3+
## Building the WASM/JS package
4+
5+
The code for the wasm + js wrapper package is stored in the `js` directory. To build it:
6+
7+
```sh
8+
cd js
9+
npm i
10+
npm run compile
11+
```
12+
13+
The js code will be output to `js/pkg`.
14+
15+
To run a quick sanity check of the JS package:
16+
17+
```sh
18+
npm test
19+
```
20+
21+
To publish the package to npm, run:
22+
23+
```sh
24+
cd js
25+
npm publish
26+
```

crates/string-offsets/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ repository = "https://github.com/github/rust-gems"
88
license = "MIT"
99
keywords = ["unicode", "positions", "utf16", "characters", "lines"]
1010
categories = ["algorithms", "data-structures", "text-processing", "development-tools::ffi"]
11+
exclude = ["/js"]
12+
13+
[lib]
14+
crate-type = ["cdylib", "rlib"]
15+
16+
[features]
17+
wasm = ["wasm-bindgen"]
18+
19+
[dependencies]
20+
wasm-bindgen = { version = "0.2", optional = true }
1121

1222
[dev-dependencies]
1323
rand = "0.9"

crates/string-offsets/js/.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/*
2+
!/pkg
3+
pkg/*/package.json
4+
pkg/*/README.md

0 commit comments

Comments
 (0)