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(wasm): support for NPM and Browser #1908

Merged
merged 42 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
efab80c
feat(wasm): support for NPM and Browser
ssddOnTop May 9, 2024
b8914c9
undo accidental change
ssddOnTop May 9, 2024
569b6f1
cleanup example
ssddOnTop May 9, 2024
c7e6af8
fix log
ssddOnTop May 10, 2024
8d10713
add tests
ssddOnTop May 10, 2024
fda4ab8
make WASM test mandatory for release
ssddOnTop May 10, 2024
953046f
miscellaneous
ssddOnTop May 10, 2024
885852d
fix wasm build
ssddOnTop May 10, 2024
36070da
update repo
ssddOnTop May 10, 2024
518e108
Merge branch 'main' into feat/tailcall-web
ssddOnTop May 10, 2024
c186623
clean example
ssddOnTop May 10, 2024
9d79f9f
some cleanups
ssddOnTop May 10, 2024
8a7f9bf
drop using ttl_cache fork
ssddOnTop May 11, 2024
57b0787
add README.md to `tailcall-wasm`
ssddOnTop May 11, 2024
d0f6403
update readme
ssddOnTop May 11, 2024
bb06061
drop unused crate
ssddOnTop May 11, 2024
348d5fd
drop unused crate
ssddOnTop May 11, 2024
a66340b
Merge branch 'main' into feat/tailcall-web
ssddOnTop May 18, 2024
9b4361f
fix tests
ssddOnTop May 18, 2024
4ca4575
Merge branch 'main' into feat/tailcall-web
ssddOnTop May 23, 2024
2362b3d
merge
ssddOnTop May 23, 2024
62de817
change commands
ssddOnTop May 23, 2024
af0b730
test npm publish
ssddOnTop May 23, 2024
85988db
drop if statement
ssddOnTop May 24, 2024
927017b
drop `.cargo/cargo.toml`
ssddOnTop May 24, 2024
ea94de4
fix ci
ssddOnTop May 24, 2024
272a772
Merge branch 'main' into feat/tailcall-web
ssddOnTop May 28, 2024
941f6f5
merge
ssddOnTop May 28, 2024
becb8cf
drop file support
ssddOnTop Jun 3, 2024
6bb4d2b
Merge branch 'main' into feat/tailcall-web
ssddOnTop Jun 3, 2024
f24d336
fix example
ssddOnTop Jun 3, 2024
79afd08
Merge branch 'main' into feat/tailcall-web
ssddOnTop Jun 9, 2024
4622063
fix build
ssddOnTop Jun 9, 2024
f6b5146
merge
ssddOnTop Jul 23, 2024
588eeda
Merge branch 'main' into feat/tailcall-web
ssddOnTop Jul 23, 2024
511c3c8
fix errors
ssddOnTop Jul 23, 2024
749c6bd
Merge branch 'main' into feat/tailcall-web
ssddOnTop Jul 23, 2024
7081e1e
Merge branch 'main' into feat/tailcall-web
tusharmath Jul 27, 2024
a3faa28
update readme
ssddOnTop Jul 27, 2024
7813fc3
lint fixes
ssddOnTop Jul 27, 2024
a29330b
Merge branch 'main' into feat/tailcall-web
tusharmath Jul 28, 2024
4aa8665
fix comment
ssddOnTop Jul 28, 2024
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
39 changes: 30 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,30 @@ jobs:
- name: Build
run: cargo lambda build

test_cf:
test_wasm:
name: Run Tests (WASM)
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./tailcall-wasm
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: wasm32-unknown-unknown

- name: Install Wasm Pack
run: cargo install wasm-bindgen-cli --vers "0.2.92"

- name: Test WASM
run: |
cargo install wasm-pack
wasm-pack test --node

test_cf:
name: Run Tests (Cloudflare)
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./tailcall-cloudflare
Expand All @@ -77,9 +98,6 @@ jobs:
with:
target: wasm32-unknown-unknown

- name: Build WASM
run: cargo check --lib --target wasm32-unknown-unknown
working-directory: ./tailcall-cloudflare
- name: Install Node.js
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -211,7 +229,7 @@ jobs:
# TODO: move to separate file to separate responsibilities
release:
name: Release
needs: [setup_build_matrix, test, draft_release, check_if_build, test_cf]
needs: [setup_build_matrix, test, draft_release, check_if_build, test_cf, test_wasm]
# TODO: put a condition to separate job that other will depend on to remove duplication?
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && (needs.check_if_build.outputs.check_if_build == 'true')
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
Expand Down Expand Up @@ -363,15 +381,18 @@ jobs:
with:
node-version: 20.11.0
registry-url: https://registry.npmjs.org
- name: Setup .npmrc file to publish to npm
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Install dependencies
run: |
cd npm
cd tailcall-wasm
npm install
- name: Run generate-root.js script
- name: Run publish script
env:
APP_VERSION: ${{needs.draft_release.outputs.create_release_name }}
APP_VERSION: ${{ needs.draft_release.outputs.create_release_name }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd npm
cd tailcall-wasm
npm run gen-root -- --version ${{ env.APP_VERSION }} --name @tailcallhq/tailcall
- name: Setup .npmrc file to publish to npm
run: echo "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" > ~/.npmrc
Expand Down
67 changes: 67 additions & 0 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async-std = { version = "1.12.0", features = [
"wasm-bindgen-futures",
"unstable",
] }
ttl_cache = { version = "0.5.1", features = ["stats"] }
ttl_cache = "0.5.1"
protox = "0.6.0"
protox-parse = "0.6.0"
prost-reflect = { version = "0.13.1", features = ["serde"] }
Expand Down Expand Up @@ -237,7 +237,9 @@ members = [
"tailcall-fixtures",
"tailcall-upstream-grpc",
"tailcall-tracker",
"tailcall-hasher",
"tailcall-wasm",
"tailcall-hasher"
,
"tailcall-http-cache",
"tailcall-version",
]
Expand Down
22 changes: 18 additions & 4 deletions src/core/cache.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::hash::Hash;
use std::num::NonZeroU64;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, RwLock};
use std::time::Duration;

Expand All @@ -9,6 +10,8 @@

pub struct InMemoryCache<K: Hash + Eq, V> {
data: Arc<RwLock<TtlCache<K, V>>>,
hits: AtomicUsize,
miss: AtomicUsize,
}

// TODO: take this from the user instead of hardcoding it
Expand All @@ -22,7 +25,11 @@

impl<K: Hash + Eq, V: Clone> InMemoryCache<K, V> {
pub fn new() -> Self {
InMemoryCache { data: Arc::new(RwLock::new(TtlCache::new(CACHE_CAPACITY))) }
InMemoryCache {
data: Arc::new(RwLock::new(TtlCache::new(CACHE_CAPACITY))),
hits: AtomicUsize::new(0),
miss: AtomicUsize::new(0),
}
}
}

Expand All @@ -40,13 +47,20 @@
}

async fn get<'a>(&'a self, key: &'a K) -> cache::Result<Option<Self::Value>> {
Ok(self.data.read().unwrap().get(key).cloned())
let val = self.data.read().unwrap().get(key).cloned();
if val.is_some() {
self.hits.fetch_add(1, Ordering::Relaxed);
} else {
self.miss.fetch_add(1, Ordering::Relaxed);
}
Ok(val)
}

fn hit_rate(&self) -> Option<f64> {
let cache = self.data.read().unwrap();
let hits = cache.hit_count();
let misses = cache.miss_count();
let hits = self.hits.load(Ordering::Relaxed);
let misses = self.miss.load(Ordering::Relaxed);

Check warning on line 63 in src/core/cache.rs

View check run for this annotation

Codecov / codecov/patch

src/core/cache.rs#L61-L63

Added lines #L61 - L63 were not covered by tests
drop(cache);

if hits + misses > 0 {
Expand Down
28 changes: 28 additions & 0 deletions tailcall-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "tailcall-wasm"
version = "0.1.0"
edition = "2021"

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

[dependencies]
tailcall = {path = "..", default-features = false}
wasm-bindgen = "0.2.92"
wasm-bindgen-futures = "0.4.42"
anyhow = "1.0.83"
async-trait = "0.1.80"
console_error_panic_hook = "0.1.7"
reqwest = { version = "0.11", default-features = false }
async-std = "1.12.0"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
tracing-subscriber-wasm = "0.1.0"
hyper = { version = "0.14.28", default-features = false }
dashmap = "5.5.3"
async-graphql-value = "7.0.5"
serde_json = "1.0.117"
url = "2.5.0"

[dev-dependencies]
wasm-bindgen-test = "0.3.42"
Loading
Loading