Skip to content

Commit bededde

Browse files
committed
update Zig and ZLS versions
The zls.wasm and zig.tar.gz have also been commited to source control.
1 parent 183a1e1 commit bededde

File tree

13 files changed

+170
-138
lines changed

13 files changed

+170
-138
lines changed

.github/workflows/deploy.yml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Deploy
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches: ["main"]
66
workflow_dispatch:
77

88
permissions:
@@ -15,27 +15,18 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
1919

20-
- run: wget https://zig.pm/zls/downloads/wasm32-wasi/bin/zls.wasm -O src/zls.wasm
20+
- uses: actions/setup-node@v4
21+
with:
22+
node-version: 22
2123

2224
- run: |
23-
mkdir zigarchive
24-
cd zigarchive
25-
curl $(curl https://ziglang.org/download/index.json | jq .master.src.tarball -r) | xz -d | tar -xvf - --strip-components=1
26-
cd ..
27-
tar -cz zigarchive/lib/std > src/zig.tar.gz
28-
29-
- uses: actions/setup-node@v3
30-
with:
31-
node-version: 18
25+
npm ci
26+
npx parcel build 404.html
3227
33-
- run: npm ci
34-
35-
- run: ./node_modules/.bin/parcel build 404.html
36-
37-
- uses: actions/[email protected]
28+
- uses: actions/upload-pages-artifact@v3
3829
with:
3930
path: "dist/"
4031

41-
- uses: actions/deploy-pages@v1.2.3
32+
- uses: actions/deploy-pages@v4

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
node_modules
22
dist
33
.parcel-cache
4-
zig.tar.gz
5-
zls.wasm
6-
zig_debug.wasm
74
.env
5+
repos

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
# zls in the browser
1+
# Zig and ZLS in the browser
22

33
Works pretty well in a bunch of browsers, but note the required security headers.
44

55
## Installing
66

7-
* Compile zls for `wasm32-wasi` and place `zls.wasm` in `src`
8-
* Additionally, place `zig.tar.gz` (make sure that the name matches) from the website in `src`
9-
* If you've downloaded Zig and built from source following `ZIG_WASM.md`, you can also use this command:
10-
```bash
11-
tar -C /path/to/zig -cz lib/std >src/zig.tar.gz
12-
```
7+
You can either:
8+
9+
- Use it online: https://playground.zigtools.org/
10+
- Run it locally:
1311

1412
```bash
1513
npm install
@@ -18,6 +16,24 @@ npm run serve
1816

1917
Enjoy!
2018

19+
### Update artifacts
20+
21+
For the time being, the following artifacts have been commited to source control:
22+
23+
- `src/zls.wasm` - A build of [ZLS](https://github.com/zigtools/zls) (ReleaseSmall, wasm32-wasi, VERSION_TBA)
24+
- `src/zig.wasm` - A build of [Zig](https://github.com/ziglang/zig) (ReleaseSmall, wasm32-wasi, 0.14.0 with `./zig.patch` applied)
25+
- `src/zig.tar.gz` - The source code of [Zig](https://github.com/ziglang/zig). Only the `lib/std` subdirectory is needed.
26+
27+
The `./compile.sh` script can be used to create these artifacts:
28+
29+
```bash
30+
./compile zls
31+
./compile zig
32+
./compile zig_tarball
33+
```
34+
35+
Compiling Zig and ZLS may require different Zig compiler versions.
36+
2137
## TODOs
2238

2339
- [ ] Stop using `SharedArrayBuffer`s (they're awesome but a nightmare to deploy)

ZIG_WASM.md

Lines changed: 0 additions & 101 deletions
This file was deleted.

compile.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env bash
2+
3+
# Requirements:
4+
# - zig
5+
# - jq
6+
# - tar
7+
# - wasm-opt (binaryen)
8+
9+
set -e
10+
11+
ZIG_SOURCE_TAG="0.14.0"
12+
ZIG_REQUIRED_COMPILER_VERSION="0.14.0"
13+
14+
ZLS_SOURCE_COMMIT="f9b97383206c05626a21b0f24f89630aa91c072b"
15+
ZLS_REQUIRED_COMPILER_VERSION="0.15.0-dev.355+206bd1ced"
16+
17+
if command -v zig >/dev/null 2>&1; then
18+
ZIG_VERSION=$(zig version)
19+
echo "Found Zig $ZIG_VERSION"
20+
else
21+
echo "zig is not installed or not in PATH"
22+
exit 1
23+
fi
24+
25+
if command -v jq >/dev/null 2>&1; then
26+
echo "Found jq"
27+
else
28+
echo "jq is not installed or not in PATH"
29+
exit 1
30+
fi
31+
32+
if command -v wasm-opt >/dev/null 2>&1; then
33+
HAS_WASM_OPT=1;
34+
echo "Found $(wasm-opt --version)"
35+
else
36+
echo "wasm-opt is not installed or not in PATH"
37+
fi
38+
39+
compile_zls() {
40+
if [ "$ZIG_VERSION" != "$ZLS_REQUIRED_COMPILER_VERSION" ]; then
41+
echo "ZLS must be compiled with Zig $ZLS_REQUIRED_COMPILER_VERSION but got $ZIG_VERSION"
42+
exit 1
43+
fi
44+
45+
if [ ! -d repos/zls ]; then
46+
git clone https://github.com/zigtools/zls.git repos/zls
47+
git -C repos/zls checkout --detach $ZLS_SOURCE_COMMIT
48+
fi
49+
( cd repos/zls && zig build -Dtarget=wasm32-wasi -Doptimize=ReleaseSmall )
50+
if [ -n "$HAS_WASM_OPT" ]; then
51+
wasm-opt repos/zls/zig-out/bin/zls.wasm -o src/zls.wasm -O --enable-bulk-memory --enable-mutable-globals --enable-nontrapping-float-to-int --enable-sign-ext
52+
else
53+
cp repos/zls/zig-out/bin/zls.wasm src/zls.wasm
54+
fi
55+
56+
echo "Created src/zls.wasm"
57+
}
58+
59+
compile_zig() {
60+
if [ "$ZIG_VERSION" != "$ZIG_REQUIRED_COMPILER_VERSION" ]; then
61+
echo "Zig must be compiled with Zig $ZIG_REQUIRED_COMPILER_VERSION but got $ZIG_VERSION"
62+
exit 1
63+
fi
64+
65+
if [ ! -d repos/zig ]; then
66+
git clone https://github.com/ziglang/zig.git repos/zig --branch $ZIG_SOURCE_TAG --depth 1
67+
git -C repos/zig apply ../../zig.patch
68+
fi
69+
( cd repos/zig && zig build -Dtarget=wasm32-wasi -Doptimize=ReleaseSmall -Dno-lib -Ddev=wasm)
70+
if [ -n "$HAS_WASM_OPT" ]; then
71+
wasm-opt repos/zig/zig-out/bin/zig.wasm -o src/zig.wasm -O --enable-bulk-memory --enable-mutable-globals --enable-nontrapping-float-to-int --enable-sign-ext
72+
else
73+
cp repos/zig/zig-out/bin/zig.wasm src/zig.wasm
74+
fi
75+
76+
echo "Created src/zig.wasm"
77+
}
78+
79+
create_zig_tarball() {
80+
tar -czf src/zig.tar.gz -C $(zig env | jq .lib_dir -r)/.. lib/std
81+
82+
echo "Created src/zig.tar.gz"
83+
}
84+
85+
case $1 in
86+
"zls")
87+
compile_zls
88+
;;
89+
"zig")
90+
compile_zig
91+
;;
92+
"zig_tarball")
93+
create_zig_tarball
94+
;;
95+
96+
*)
97+
exit 1
98+
;;
99+
esac

src/lsp/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ export abstract class LspClient {
227227
public handleMessage(message: JsonRpcMessage) {
228228
if (message.method === "workspace/configuration") {
229229
const configParams = message.params as LSP.ConfigurationParams;
230-
let resp: (string | null)[] = [];
230+
let resp: unknown[] = [];
231231

232232
for (const item of configParams.items) {
233-
if (item.section === "zls.zig_lib_path") {
234-
resp.push("/lib");
233+
if (item.section === "zls.prefer_ast_check_as_child_process") {
234+
resp.push(false);
235235
} else {
236236
resp.push(null);
237237
}

src/workers/zig.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { WASI, PreopenDirectory, Fd, File, ConsoleStdout, OpenFile, Inode } from "@bjorn3/browser_wasi_shim";
22
import { getLatestZigArchive } from "../utils";
33
// @ts-ignore
4-
import zlsWasm from "url:../zig_release.wasm";
4+
import zlsWasm from "url:../zig.wasm";
55

66
let currentlyRunning = false;
77
async function run(source: string) {
@@ -14,7 +14,15 @@ async function run(source: string) {
1414
// -fno-llvm -fno-lld is set explicitly to ensure the native WASM backend is
1515
// used in preference to LLVM. This may be removable once the non-LLVM
1616
// backends become more mature.
17-
let args = ["zig.wasm", "build-exe", "main.zig", "-Dtarget=wasm32-wasi", "-fno-llvm", "-fno-lld"];
17+
let args = [
18+
"zig.wasm",
19+
"build-exe",
20+
"main.zig",
21+
"-fno-llvm",
22+
"-fno-lld",
23+
"-fno-ubsan-rt",
24+
"-fno-entry", // prevent the native webassembly backend from adding a start function to the module
25+
];
1826
let env = [];
1927
let fds = [
2028
new OpenFile(new File([])), // stdin

src/workers/zls.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ onmessage = (event) => {
7474
(async () => {
7575
let libDirectory = await getLatestZigArchive();
7676

77-
let args = ["zls.wasm", "--enable-debug-log"];
77+
let args = ["zls.wasm"];
7878
let env = [];
7979
let fds = [
8080
new Stdio(StdioKind.stdin), // stdin
8181
new Stdio(StdioKind.stdout), // stdout
8282
ConsoleStdout.lineBuffered((line) => postMessage({ stderr: line })), // stderr
83-
new PreopenDirectory(".", new Map([
84-
["lib", new Directory(libDirectory.contents)]
85-
])),
83+
new PreopenDirectory(".", new Map([])),
84+
new PreopenDirectory("/lib", libDirectory.contents),
85+
new PreopenDirectory("/cache", new Map()),
8686
];
8787
let wasi = new WASI(args, env, fds, { debug: false });
8888

src/zig.tar.gz

2.46 MB
Binary file not shown.

src/zig.wasm

2.98 MB
Binary file not shown.

0 commit comments

Comments
 (0)