jetzig-framework / jetzig

Jetzig is a web framework written in Zig
MIT License
308 stars 15 forks source link

error: runtime value contains reference to comptime var #48

Closed mitteneer closed 2 months ago

mitteneer commented 2 months ago

On latest jetzig version, and zig 0.12.0-dev.3508+a6ed3e6d2:

  1. Run jetzig init.
  2. Accept default values for prompts.
  3. Run zig build run
  4. Receive error:
    src\main.zig:95:19: error: runtime value contains reference to comptime var
    try app.start(comptime jetzig.route(routes));
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    src\main.zig:95:19: note: comptime var pointers are not available at runtime

I see a somewhat similar issue in Zig regarding globals, not sure if that related though (still very much a small fish in a big pond haha).

bobf commented 2 months ago

@mitteneer Thanks for reporting - just replicated with latest Zig on my local setup. Will try to get this fixed this evening !

bobf commented 2 months ago

@mitteneer Thanks a lot for reporting this ! Latest Zig introduced a change to remove some usage of comptime pointers at runtime, so I've done an overhaul of how we generate our routes file and it is much, much simpler now - no more comptime needed.

You can get this working one of two ways:

  1. Download the latest Jetzig CLI tool here and run jetzig init to create a new project - this will pull latest main automatically for you.
  2. Run jetzig update inside your project directory to update to latest Jetzig and then make these changes to your src/main.zig:

    
    @@ -2,7 +2,7 @@ const std = @import("std");
    
    pub const jetzig = @import("jetzig");

-pub const routes = @import("routes").routes; +pub const routes = @import("routes");

// Override default settings in jetzig.config here: pub const jetzig_options = struct { @@ -92,5 +92,5 @@ pub fn main() !void { const app = try jetzig.init(allocator); defer app.deinit();

Since I couldn't avoid breaking backward-compatibility here I took the opportunity to add a second arg to app.start - this will help us a lot in future if we want to add any extra optional arguments, so you did Jetzig a favour here, as much as I hate breaking backward compatibility. :-)

mitteneer commented 2 months ago

If it wasn't me, it would have been someone else, but I'm glad I could help!