Skip to content

Commit

Permalink
chore: move back seperate dir
Browse files Browse the repository at this point in the history
  • Loading branch information
markphelps committed Apr 5, 2024
1 parent 5fb1f43 commit 334b15d
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 25 deletions.
4 changes: 2 additions & 2 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The client SDKs are responsible for the following:

## WebAssembly

[`flipt-engine-wasm`](./flipt-client-browser/src/) is a Rust library that compiles to [WebAssembly](https://webassembly.org/) and is designed to be embedded in the client-side SDKs that run in the browser.
[`flipt-engine-wasm`](./flipt-engine-wasm/) is a Rust library that compiles to [WebAssembly](https://webassembly.org/) and is designed to be embedded in the client-side SDKs that run in the browser.

The client-side SDKs send context to the client engine via the WebAssembly interface and receive the results of the evaluation from the engine.

Expand All @@ -68,7 +68,7 @@ You can refer to the architecture diagram below:

#### WASM Engine

The [`flipt-engine-wasm`](./flipt-client-browser/src/) library is responsible for the following:
The [`flipt-engine-wasm`](./flipt-engine-wasm/) library is responsible for the following:

- Deserializing the evaluation state from JSON to memory.
- Calling the evaluation logic from the [`flipt-evaluation`](./flipt-evaluation) library to evaluate context against the evaluation state and returning the evaluation results.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["./flipt-engine-ffi", "./flipt-client-browser", "./flipt-evaluation"]
members = ["./flipt-engine-ffi", "./flipt-engine-wasm", "./flipt-evaluation"]

[profile.release]
strip = true
Expand Down
14 changes: 6 additions & 8 deletions build/wasm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ func browserBuild(ctx context.Context, client *dagger.Client, hostDirectory *dag
rust := client.Container().From("rust:1.74.0-bookworm").
WithWorkdir("/src").
WithDirectory("/src/flipt-engine-ffi", hostDirectory.Directory("flipt-engine-ffi")).
WithDirectory("/src/flipt-client-browser", hostDirectory.Directory("flipt-client-browser"), dagger.ContainerWithDirectoryOpts{
Exclude: []string{"./node_modules/", "./pkg/"},
}).
WithDirectory("/src/flipt-engine-wasm", hostDirectory.Directory("flipt-engine-wasm")).
WithDirectory("/src/flipt-evaluation", hostDirectory.Directory("flipt-evaluation")).
WithFile("/src/Cargo.toml", hostDirectory.File("Cargo.toml"))

Expand All @@ -83,8 +81,8 @@ func browserBuild(ctx context.Context, client *dagger.Client, hostDirectory *dag

rust, err = rust.
WithExec([]string{"cargo", "install", "wasm-pack"}). // Install wasm-pack
WithWorkdir("/src/flipt-client-browser").
WithExec([]string{"wasm-pack", "build", "--target", "web", "--out-dir", "./pkg"}). // Build the wasm package
WithWorkdir("/src/flipt-engine-wasm").
WithExec([]string{"wasm-pack", "build", "--target", "web"}).
Sync(ctx)

if err != nil {
Expand All @@ -93,12 +91,12 @@ func browserBuild(ctx context.Context, client *dagger.Client, hostDirectory *dag

container := client.Container().From("node:21.2-bookworm").
WithDirectory("/src", hostDirectory.Directory("flipt-client-browser")).
WithDirectory("/src/pkg", rust.Directory("/src/flipt-client-browser/pkg"), dagger.ContainerWithDirectoryOpts{
WithDirectory("/src/pkg", rust.Directory("/src/flipt-engine-wasm/pkg"), dagger.ContainerWithDirectoryOpts{
Exclude: []string{"./node_modules/"},
}).
WithWorkdir("/src").
WithExec([]string{"npm", "install"}). // Install dependencies
WithExec([]string{"npm", "run", "build:typescript"}) // Build the browser package
WithExec([]string{"npm", "install"}). // Install dependencies
WithExec([]string{"npm", "run", "build"}) // Build the browser package

if !push {
_, err = container.Sync(ctx)
Expand Down
12 changes: 1 addition & 11 deletions flipt-client-browser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,9 @@ This allows you to update the flag state in a controlled manner, such as in a po

## Development

### WASM

This library uses a WebAssembly (WASM) layer to interact with the Flipt server. It is written in Rust and exposes a JavaScript API using the `wasm-bindgen` and `wasm-pack` tools. We wrap the built WASM layer in a JavaScript API to make it easier to use in a browser environment.

## Architecture

See [ARCHITECTURE.md](./ARCHITECTURE.md).

### Prerequisites

- [Rust](https://www.rust-lang.org/tools/install)
- [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/)
- [wasm-bindgen](https://rustwasm.github.io/wasm-bindgen/)
- [flipt-engine-wasm](../flipt-engine-wasm/README.md)

### Build

Expand Down
4 changes: 1 addition & 3 deletions flipt-client-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
"fmt": "prettier --config .prettierrc 'lib/**/*.ts' --write",
"lint": "prettier --check lib/**/*.ts",
"test": "jasmine",
"build:typescript": "tsc",
"build:wasm": "wasm-pack build --target web --out-dir ./pkg",
"build": "npm run build:wasm && npm run build:typescript"
"build": "tsc"
},
"devDependencies": {
"@wasm-tool/wasm-pack-plugin": "^1.7.0",
Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions flipt-engine-wasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Flipt Engine WASM

This is the WebAssembly layer for the Flipt client-side SDKs. It is written in Rust and exposes a JavaScript API for the SDKs to use.

## Architecture

See [ARCHITECTURE.md](./ARCHITECTURE.md).

### Prerequisites

- [Rust](https://www.rust-lang.org/tools/install)
- [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/)
- [wasm-bindgen](https://rustwasm.github.io/wasm-bindgen/)

### Build

```bash
wasm-pack build --target web
```
File renamed without changes.

0 comments on commit 334b15d

Please sign in to comment.