Skip to content

Commit 9476935

Browse files
committed
WIP
1 parent a7b03f3 commit 9476935

File tree

4 files changed

+13
-21
lines changed

4 files changed

+13
-21
lines changed

build.zig

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ pub const Cart = struct {
138138
watch_run.addArgs(&.{"--input-dir"});
139139
watch_run.addFileArg(c.options.root_source_file.dirname());
140140
}
141-
watch_run.addArgs(&.{ "--cart", b.getInstallPath(install_artifact_step.dest_dir.?, install_artifact_step.dest_sub_path) });
142141

142+
watch_run.addArgs(&.{ "--cart", b.getInstallPath(install_artifact_step.dest_dir.?, install_artifact_step.dest_sub_path) });
143143
return watch_run;
144144
}
145145
};
@@ -183,22 +183,18 @@ pub fn add_cart(
183183
.target = wasm_target,
184184
.optimize = options.optimize,
185185
});
186-
187186
wasm.entry = .disabled;
188187
wasm.import_memory = true;
189188
wasm.initial_memory = 64 * 65536;
190189
wasm.max_memory = 64 * 65536;
191190
wasm.stack_size = 14752;
192191
wasm.global_base = 160 * 128 * 2 + 0x1e;
193-
194192
wasm.rdynamic = true;
195193
wasm.root_module.addImport("cart-api", d.module("cart-api"));
196194

197195
const microzig_dep = d.builder.dependency("microzig", .{});
198196
const mb = MicroBuild.init(d.builder, microzig_dep) orelse return null;
199-
200197
const sycl_badge_target = sycl_badge_microzig_target(mb);
201-
202198
const cart_lib = b.addStaticLibrary(.{
203199
.name = "cart",
204200
.root_source_file = options.root_source_file,
@@ -232,6 +228,7 @@ pub fn add_cart(
232228
.cart_lib = cart_lib,
233229
.options = options,
234230
};
231+
235232
return cart;
236233
}
237234

build.zig.zon

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
.hash = "zigimg-0.1.0-8_eo2lrXEgBlEihqJdiw_ZtxgL-vO72ajJpmOdO59qxp",
2020
},
2121
.microzig = .{
22-
//.url = "git+https://github.com/zigEmbeddedGroup/microzig#ec738a03fe0000c9cba1e3633aac5e2fc8024875",
23-
//.hash = "microzig-0.14.2-D20YSac--gD-H2ujNAL4m5IvkYOWYlgO7SlU1j8fJbeX",
24-
.path = "../microzig",
22+
.url = "git+https://github.com/ZigEmbeddedGroup/microzig#cbbe44943a1f877329214c5697b482d9f3c3b57a",
23+
.hash = "microzig-0.14.2-D20YScPb-gAGfmER_MCmiyaGjAdhSL-zll6VWvUm_Vz8",
2524
},
2625
.ws = .{
2726
.url = "git+https://github.com/karlseguin/websocket.zig#7240830dc8d1ab426d408cb76144794169943aa9",

src/watch/Reloader.zig

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Watcher = switch (builtin.target.os.tag) {
1212
};
1313

1414
gpa: std.mem.Allocator,
15-
//ws_server: ws.Server(WsHandler),
15+
ws_server: ws.Server,
1616
zig_exe: []const u8,
1717
watcher: Watcher,
1818
output_dir_index: usize,
@@ -25,12 +25,12 @@ pub fn init(
2525
zig_exe: []const u8,
2626
dirs_to_watch: []const []const u8,
2727
) !Reloader {
28-
//const ws_server = try ws.Server.init(gpa, .{});
28+
const ws_server = try ws.Server.init(gpa, .{});
2929

3030
return .{
3131
.gpa = gpa,
3232
.zig_exe = zig_exe,
33-
// .ws_server = ws_server,
33+
.ws_server = ws_server,
3434
.watcher = try Watcher.init(gpa, dirs_to_watch),
3535
.output_dir_index = dirs_to_watch.len - 1,
3636
};
@@ -121,10 +121,7 @@ pub fn onChange(reloader: *Reloader, dir_that_changed: usize) void {
121121
}
122122
}
123123

124-
const WsHandler = struct {};
125-
126124
pub fn handleWs(reloader: *Reloader, stream: std.net.Stream, h: [20]u8) void {
127-
_ = reloader;
128125
var buf =
129126
("HTTP/1.1 101 Switching Protocols\r\n" ++
130127
"Access-Control-Allow-Origin: *\r\n" ++
@@ -137,13 +134,12 @@ pub fn handleWs(reloader: *Reloader, stream: std.net.Stream, h: [20]u8) void {
137134

138135
stream.writeAll(&buf) catch @panic("bad");
139136

140-
// var conn = reloader.ws_server.newConn(stream);
141-
// const conn = reloader.gpa.create(ws.Conn) catch @panic("bad");
142-
// conn.* = reloader.ws_server.newConn(stream);
137+
const conn = reloader.gpa.create(ws.Conn) catch @panic("bad");
138+
conn.* = reloader.ws_server.newConn(stream);
143139

144-
// var context: Handler.Context = .{ .watcher = reloader };
145-
// var handler = Handler.init(undefined, conn, &context) catch @panic("bad");
146-
// reloader.ws_server.handle(Handler, &handler, conn);
140+
var context: Handler.Context = .{ .watcher = reloader };
141+
var handler = Handler.init(undefined, conn, &context) catch @panic("bad");
142+
reloader.ws_server.handle(Handler, &handler, conn);
147143
}
148144

149145
const Handler = struct {

src/watch/main.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ fn serve(s: *Server, cart_path: []const u8, listen_port: u16) !void {
237237
const server_port = tcp_server.listen_address.in.getPort();
238238
std.debug.assert(server_port == listen_port);
239239

240-
std.debug.print("\x1b[2K\rSimulator live! Go to https://badgesim.microzig.tech/ to test your cartridge.\n", .{});
240+
std.debug.print("\x1b[2K\rSimulator live! Go to https://zigembeddedgroup.github.io/sycl-badge/ to test your cartridge.\n", .{});
241241

242242
var buffer: [1024]u8 = undefined;
243243
accept: while (true) {

0 commit comments

Comments
 (0)