Skip to content

Commit 559430c

Browse files
authored
Merge pull request #3 from ianprime0509/update-setup
Update setup for latest Zig version
2 parents 69c4f79 + 2c99955 commit 559430c

File tree

8 files changed

+41
-34
lines changed

8 files changed

+41
-34
lines changed

.proxyrc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ const { createReadStream } = require("fs");
22

33
module.exports = function (app) {
44
app.use((req, res, next) => {
5-
// res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
6-
// res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
7-
// res.setHeader("Cross-Origin-Resource-Policy", "cross-origin");
5+
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
6+
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
7+
res.setHeader("Cross-Origin-Resource-Policy", "cross-origin");
88

99
if (req.url === "/zig.tar") {
1010
res.setHeader("Content-Type", "application/octet-stream");

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ Works pretty well in a bunch of browsers, but note the required security headers
55
## Installing
66

77
* Compile zls for `wasm32-wasi` and place `zls.wasm` in `src`
8-
* Additionally, place `zig.tar` (make sure to un-xz and that the name matches) from the website 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+
```
913

1014
```bash
11-
npm i -g parcel
12-
parcel 404.html
15+
npm install
16+
npm run serve
1317
```
1418

1519
Enjoy!

ZIG_WASM.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ Apply this patch:
66

77
```patch
88
diff --git a/build.zig b/build.zig
9-
index 9926d6e5e..461a0c7af 100644
9+
index 9e6e86386..ec8b6b9bd 100644
1010
--- a/build.zig
1111
+++ b/build.zig
12-
@@ -204,7 +204,7 @@ pub fn build(b: *std.Build) !void {
13-
exe_options.addOption(bool, "llvm_has_arc", llvm_has_arc);
12+
@@ -237,7 +237,7 @@ pub fn build(b: *std.Build) !void {
13+
exe_options.addOption(bool, "llvm_has_xtensa", llvm_has_xtensa);
1414
exe_options.addOption(bool, "force_gpa", force_gpa);
1515
exe_options.addOption(bool, "only_c", only_c);
16-
- exe_options.addOption(bool, "omit_pkg_fetching_code", only_c);
17-
+ exe_options.addOption(bool, "omit_pkg_fetching_code", true);
18-
16+
- exe_options.addOption(bool, "only_core_functionality", only_c);
17+
+ exe_options.addOption(bool, "only_core_functionality", true);
18+
1919
if (link_libc) {
2020
exe.linkLibC();
2121
diff --git a/src/link.zig b/src/link.zig
22-
index 45873fec2..43f4dc7d1 100644
22+
index 703dfb873..3bc4039e7 100644
2323
--- a/src/link.zig
2424
+++ b/src/link.zig
25-
@@ -761,9 +761,9 @@ pub const File = struct {
25+
@@ -765,9 +765,9 @@ pub const File = struct {
2626
/// Commit pending changes and write headers. Takes into account final output mode
2727
/// and `use_lld`, not only `effectiveOutputMode`.
2828
pub fn flush(base: *File, comp: *Compilation, prog_node: *std.Progress.Node) FlushError!void {
@@ -40,7 +40,7 @@ index c4fb9b829..7fdc018ab 100644
4040
--- a/src/link/Wasm/Archive.zig
4141
+++ b/src/link/Wasm/Archive.zig
4242
@@ -208,9 +208,9 @@ pub fn parseObject(archive: Archive, allocator: Allocator, file_offset: u32) !Ob
43-
43+
4444
const object_name = try archive.parseName(header);
4545
const name = name: {
4646
- var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
@@ -51,30 +51,30 @@ index c4fb9b829..7fdc018ab 100644
5151
+ break :name try std.fmt.allocPrint(allocator, "{s}({s})", .{ archive.name, object_name });
5252
};
5353
defer allocator.free(name);
54-
54+
5555
diff --git a/src/main.zig b/src/main.zig
56-
index 76c43476e..05eae6722 100644
56+
index 39a7adc42..616518d15 100644
5757
--- a/src/main.zig
5858
+++ b/src/main.zig
59-
@@ -198,7 +198,7 @@ pub fn main() anyerror!void {
59+
@@ -200,7 +200,7 @@ pub fn main() anyerror!void {
6060
}
61-
61+
6262
// Short circuit some of the other logic for bootstrapping.
6363
- if (build_options.only_c) {
6464
+ if (true) {
6565
if (mem.eql(u8, args[1], "build-exe")) {
6666
return buildOutputType(gpa, arena, args, .{ .build = .Exe });
6767
} else if (mem.eql(u8, args[1], "build-obj")) {
68-
@@ -1522,7 +1522,7 @@ fn buildOutputType(
68+
@@ -1544,7 +1544,7 @@ fn buildOutputType(
6969
}
7070
},
7171
.cc, .cpp => {
7272
- if (build_options.only_c) unreachable;
7373
+ if (true) unreachable;
74-
74+
7575
emit_h = .no;
7676
soname = .no;
77-
@@ -3190,7 +3190,7 @@ fn buildOutputType(
77+
@@ -3238,7 +3238,7 @@ fn buildOutputType(
7878
switch (listen) {
7979
.none => {},
8080
.stdio => {
@@ -83,18 +83,19 @@ index 76c43476e..05eae6722 100644
8383
try serve(
8484
comp,
8585
std.io.getStdIn(),
86-
@@ -3250,7 +3250,7 @@ fn buildOutputType(
86+
@@ -3286,7 +3286,7 @@ fn buildOutputType(
8787
error.SemanticAnalyzeFail => if (listen == .none) process.exit(1),
8888
else => |e| return e,
8989
};
9090
- if (build_options.only_c) return cleanExit();
9191
+ if (true) return cleanExit();
9292
try comp.makeBinFileExecutable();
93-
93+
9494
if (test_exec_args.items.len == 0 and object_format == .c) default_exec_args: {
9595
```
9696

9797
then:
98+
9899
```bash
99-
../zig-from-website/zig build -Dtarget=wasm32-wasi -Drelease=true
100+
../zig-from-website/zig build -Dtarget=wasm32-wasi -Doptimize=ReleaseSmall -Dno-langref -Dno-autodocs -Dno-lib
100101
```

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
2+
"name": "playground",
23
"scripts": {
3-
"bundle": "node_modules\\.bin\\rollup editor.mjs -f iife -o editor.bundle.js -p @rollup\\plugin-node-resolve"
4+
"bundle": "node_modules\\.bin\\rollup editor.mjs -f iife -o editor.bundle.js -p @rollup\\plugin-node-resolve",
5+
"serve": "parcel 404.html"
46
},
57
"dependencies": {
68
"@codemirror/autocomplete": "^6.4.2",

src/editor.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,10 @@ let editor = (async () => {
9191
doc:
9292
(await getPaste()) ?? `const std = @import("std");
9393
94-
pub fn main() u8 {
94+
pub fn main() !void {
9595
std.debug.print("All your {s} are belong to us.\\n", .{"codebase"});
9696
97-
// WASI mains don't support errors (we can fix this with a horrible
98-
// wrapper hack in the future :P)
99-
std.io.getStdOut().writer().writeAll("bruh") catch return 1;
100-
101-
return 0;
97+
try std.io.getStdOut().writer().writeAll("bruh");
10298
}
10399
`,
104100
extensions: [basicSetup, oneDark, indentUnit.of(" "), client.createPlugin("file:///main.zig", "zig", true), keymap.of([indentWithTab]),],

src/workers/zig.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ async function run(source: string) {
7171

7272
const {libStd, wasm} = await wasmData;
7373

74-
let args = ["zig.wasm", "build-exe", "main.zig", "-Dtarget=wasm32-wasi"];
74+
// -fno-llvm -fno-lld is set explicitly to ensure the native WASM backend is
75+
// used in preference to LLVM. This may be removable once the non-LLVM
76+
// backends become more mature.
77+
let args = ["zig.wasm", "build-exe", "main.zig", "-Dtarget=wasm32-wasi", "-fno-llvm", "-fno-lld"];
7578
let env = [];
7679
let fds = [
7780
stdin, // stdin

src/zig_release.wasm

873 KB
Binary file not shown.

0 commit comments

Comments
 (0)