Skip to content

Commit 1aa9f15

Browse files
authored
Update wasm file versioning (#8)
* Remove wasm file versioning * Add wasm dep versions and upgrade to latest releases * Replace sed with jq for parsing wasm version data
1 parent 769c8ec commit 1aa9f15

File tree

9 files changed

+49
-18
lines changed

9 files changed

+49
-18
lines changed

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ NODE_OPTIONS=--openssl-legacy-provider vercel build
6262
vercel deploy --prebuilt
6363
```
6464

65+
> ℹ️ Git Large File Storage (LFS) must be enabled in your Vercel project settings.
66+
6567
### NodeJS
6668

6769
The `build` directory in the project root directory after running `yarn build` will contain an optimized production React application that can be served using your preferred NodeJS hosting method.
6870

69-
> ℹ️ Node v18.x is required.
71+
> ℹ️ Node v18.x is required.
7072
7173
For example:
7274

@@ -84,12 +86,17 @@ Run `yarn install` in the _root_ project directory.
8486

8587
## Updating wasm dependencies
8688

87-
The project contains prebuilt WASM files for versions of both SpiceDB and zed. To update the versions, edit the following script files with the appropriate tag/commit hash and then run from the project root:
89+
The project contains prebuilt WASM files for versions of both SpiceDB and zed. To update the versions, edit the [wasm-config.json] file with the desired tag/commit hash and then run from the project root:
8890

8991
`yarn run update:spicedb`
9092

9193
`yarn run update:zed`
9294

95+
> ℹ️ [jq] is required and must be installed.
96+
97+
[wasm-config.json]: https://github.com/authzed/playground/blob/wasm-caching/spicedb-common/wasm-config.json
98+
[jq]: https://jqlang.github.io/jq/
99+
93100
## Developing your own schema
94101

95102
You can try both [SpiceDB](https://github.com/authzed/spicedb) and [zed](https://github.com/authzed/zed) entirely in your browser on a SpiceDB Playground deployment thanks to the power of [WebAssembly](https://authzed.com/blog/some-assembly-required).

playground/craco.config.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ const resolvePackage = (relativePath) => {
99

1010
module.exports = {
1111
webpack: {
12-
plugins: [
13-
new DefinePlugin({
14-
// Use build timestamp as version id
15-
'process.env.WASM_VERSION': DefinePlugin.runtimeValue(Date.now, true),
16-
}),
17-
],
12+
plugins: [],
1813
configure: (webpackConfig, { env, paths }) => {
1914
return webpackConfig;
2015
},

scripts/update-spicedb.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
#!/usr/bin/env sh
22

33
set -e
4+
5+
VERSION=$(jq -r '.spicedb' ./spicedb-common/wasm-config.json)
6+
if [ -z ${VERSION} ] ; then
7+
echo "SpiceDB version not defined in wasm config" >&2
8+
exit 1
9+
fi
10+
echo "Updating SpiceDB wasm to version: ${VERSION}"
11+
12+
413
if [ ! -d "spicedb" ] ; then
514
git clone https://github.com/authzed/spicedb.git
615
fi
716
cd spicedb
8-
git checkout 3b37d794c689d635f62d94b868abe3cb66e109f0
17+
git fetch
18+
git checkout ${VERSION}
919
cd pkg/development/wasm
1020
GOOS=js GOARCH=wasm go build -o main.wasm
1121
mv main.wasm ../../../../wasm

scripts/update-zed.sh

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
#!/usr/bin/env sh
22

33
set -e
4+
5+
VERSION=$(jq -r '.zed' ./spicedb-common/wasm-config.json)
6+
if [ -z ${VERSION} ] ; then
7+
echo "zed version not defined in wasm config" >&2
8+
exit 1
9+
fi
10+
echo "Updating zed wasm to version: ${VERSION}"
11+
412
if [ ! -d "zed" ] ; then
513
git clone https://github.com/authzed/zed.git
614
fi
715
cd zed
8-
git checkout e4815f1475e320c0b008f7d016db59ee158a965c
16+
git fetch
17+
git checkout ${VERSION}
918
cd pkg/wasm
1019
GOOS=js GOARCH=wasm go build -o zed.wasm
1120
mv zed.wasm ../../../wasm

spicedb-common/src/services/developerservice.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import {
1515
RunValidationParameters,
1616
RunValidationResult,
1717
} from '../protodevdefs/developer/v1/developer';
18+
import wasmConfig from '../../wasm-config.json';
1819

1920
const WASM_FILE = `${process.env.PUBLIC_URL}/static/main.wasm`;
20-
const ESTIMATED_WASM_BINARY_SIZE = 31161196; // bytes
21+
const ESTIMATED_WASM_BINARY_SIZE = 46376012; // bytes
2122
const ENTRYPOINT_FUNCTION = 'runSpiceDBDeveloperRequest';
2223

2324
/**
@@ -210,7 +211,9 @@ class DeveloperServiceRequest {
210211
}
211212
}
212213

213-
const wasmVersion: number | string = Math.random();
214+
const wasmVersion: number | string = wasmConfig?.spicedb
215+
? encodeURIComponent(wasmConfig.spicedb)
216+
: Math.random();
214217

215218
/**
216219
* useDeveloperService returns a reference to the developer service for invoking calls against the WASM-based

spicedb-common/src/services/zedservice.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { RelationTuple as Relationship } from '@code/spicedb-common/src/protodev
22
import { useCallback, useEffect, useState } from 'react';
33
import { parseRelationships } from '../parsing';
44
import { RequestContext } from '../protodevdefs/developer/v1/developer';
5+
import wasmConfig from '../../wasm-config.json';
56

67
const WASM_FILE = `${process.env.PUBLIC_URL}/static/zed.wasm`;
7-
const ESTIMATED_WASM_BINARY_SIZE = 49262480; // bytes
8+
const ESTIMATED_WASM_BINARY_SIZE = 55126053; // bytes
89
const ENTRYPOINT_FUNCTION = 'runZedCommand';
910

1011
/**
@@ -59,7 +60,9 @@ export type ZedServiceState =
5960
progress: number;
6061
};
6162

62-
const wasmVersion: number | string = Math.random();
63+
const wasmVersion: number | string = wasmConfig?.zed
64+
? encodeURIComponent(wasmConfig.zed)
65+
: Math.random();
6366

6467
export function useZedService(): ZedService {
6568
const [state, setState] = useState<ZedServiceState>({

spicedb-common/wasm-config.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"spicedb": "v1.29.5",
3+
"zed": "v0.17.1"
4+
}

wasm/main.wasm

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:af26f81fd57ac5d5573368fa2cf7a1be097a88f1155fae53cfd8b5e8801af1d7
3-
size 45260507
2+
oid sha256:ae5a38d52353841c6b82c373ab8b1a7ce5f80169d4c682e462b3a2e704d037ec
3+
size 46376012

wasm/zed.wasm

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:927d0bd5f6c6d2f2d4962dcde7580c0438f584a5f4f35e7fb471891c4ba598b0
3-
size 52643236
2+
oid sha256:61829b42380be0aefd67068d9ee95b77147002ad843e920d410f9883745f1a05
3+
size 55126053

0 commit comments

Comments
 (0)