0.13 support

Add support for 0.13. For now, we can be compatible with both 0.12 and
0.13. We will drop 0.12 after a while.
This commit is contained in:
Bob Farrell 2024-04-27 22:46:22 +01:00
parent 9d12b5c717
commit 6b940e8a53
9 changed files with 39 additions and 28 deletions

View File

@ -173,7 +173,7 @@ pub fn jetzigInit(b: *std.Build, exe: *std.Build.Step.Compile, options: JetzigIn
if (!std.mem.eql(u8, ".zig", std.fs.path.extension(entry.path))) continue; if (!std.mem.eql(u8, ".zig", std.fs.path.extension(entry.path))) continue;
const stat = try src_dir.statFile(entry.path); const stat = try src_dir.statFile(entry.path);
const src_data = try src_dir.readFileAlloc(b.allocator, entry.path, stat.size); const src_data = try src_dir.readFileAlloc(b.allocator, entry.path, @intCast(stat.size));
defer b.allocator.free(src_data); defer b.allocator.free(src_data);
const relpath = try std.fs.path.join(b.allocator, &[_][]const u8{ "src", entry.path }); const relpath = try std.fs.path.join(b.allocator, &[_][]const u8{ "src", entry.path });
@ -216,7 +216,7 @@ fn generateMarkdownFragments(b: *std.Build) ![]const u8 {
} }
}; };
const stat = try file.stat(); const stat = try file.stat();
const source = try file.readToEndAllocOptions(b.allocator, stat.size, null, @alignOf(u8), 0); const source = try file.readToEndAllocOptions(b.allocator, @intCast(stat.size), null, @alignOf(u8), 0);
if (try getMarkdownFragmentsSource(b.allocator, source)) |markdown_fragments_source| { if (try getMarkdownFragmentsSource(b.allocator, source)) |markdown_fragments_source| {
return try std.fmt.allocPrint(b.allocator, return try std.fmt.allocPrint(b.allocator,
\\const std = @import("std"); \\const std = @import("std");

View File

@ -3,12 +3,12 @@
.version = "0.0.0", .version = "0.0.0",
.dependencies = .{ .dependencies = .{
.zmd = .{ .zmd = .{
.url = "https://github.com/jetzig-framework/zmd/archive/45a9ff0e3a55b4758163abad5a601bd3ef8127a8.tar.gz", .url = "https://github.com/jetzig-framework/zmd/archive/557ab8a29c0f7b5d096070cde2858cf27da8b0f1.tar.gz",
.hash = "122067a3107499e4b561a883a9f1e9f39662c4b87249a2e4e630279bd91ab7840230", .hash = "1220482f07f2bbaef335f20d6890c15a1e14739950b784232bc69182423520e058a5",
}, },
.zmpl = .{ .zmpl = .{
.url = "https://github.com/jetzig-framework/zmpl/archive/9712b85e61f33879f388d5e1829856e326c53822.tar.gz", .url = "https://github.com/jetzig-framework/zmpl/archive/046c05d376a4fe89d86c52596baa18137891cd87.tar.gz",
.hash = "1220b185cf8316ae5ad6dd7d45bea278575391986b7d8233a9d9b2c342e339d65ac0", .hash = "1220d8890b1161e4356d2c59d4b88280566d55480dae840b6f5dae34bf852bef6b56",
}, },
.args = .{ .args = .{
.url = "https://github.com/MasterQ32/zig-args/archive/01d72b9a0128c474aeeb9019edd48605fa6d95f7.tar.gz", .url = "https://github.com/MasterQ32/zig-args/archive/01d72b9a0128c474aeeb9019edd48605fa6d95f7.tar.gz",

View File

@ -42,19 +42,36 @@ pub fn run(
var sub_args = std.ArrayList([]const u8).init(allocator); var sub_args = std.ArrayList([]const u8).init(allocator);
defer sub_args.deinit(); defer sub_args.deinit();
const map = std.ComptimeStringMap(Generator, .{
.{ "view", .view },
.{ "partial", .partial },
.{ "layout", .layout },
.{ "job", .job },
.{ "mailer", .mailer },
.{ "middleware", .middleware },
.{ "secret", .secret },
});
var available_buf = std.ArrayList([]const u8).init(allocator); var available_buf = std.ArrayList([]const u8).init(allocator);
defer available_buf.deinit(); defer available_buf.deinit();
for (map.kvs) |kv| try available_buf.append(kv.key);
// XXX: 0.12 Compatibility
const map = if (@hasDecl(std, "ComptimeStringMap")) blk: {
const inner_map = std.ComptimeStringMap(Generator, .{
.{ "view", .view },
.{ "partial", .partial },
.{ "layout", .layout },
.{ "job", .job },
.{ "mailer", .mailer },
.{ "middleware", .middleware },
.{ "secret", .secret },
});
for (inner_map.kvs) |kv| try available_buf.append(kv.key);
break :blk inner_map;
} else if (@hasDecl(std, "StaticStringMap")) blk: {
const inner_map = std.StaticStringMap(Generator).initComptime(.{
.{ "view", .view },
.{ "partial", .partial },
.{ "layout", .layout },
.{ "job", .job },
.{ "mailer", .mailer },
.{ "middleware", .middleware },
.{ "secret", .secret },
});
for (inner_map.keys()) |key| try available_buf.append(key);
break :blk inner_map;
} else unreachable;
const available_help = try std.mem.join(allocator, "|", available_buf.items); const available_help = try std.mem.join(allocator, "|", available_buf.items);
defer allocator.free(available_help); defer allocator.free(available_help);

View File

@ -45,7 +45,7 @@ pub fn initDataModule(build: *std.Build) !*std.Build.Module {
const stat = try dir.statFile(path); const stat = try dir.statFile(path);
const encoded = base64Encode( const encoded = base64Encode(
build.allocator, build.allocator,
try dir.readFileAlloc(build.allocator, path, stat.size), try dir.readFileAlloc(build.allocator, path, @intCast(stat.size)),
); );
defer build.allocator.free(encoded); defer build.allocator.free(encoded);

View File

@ -37,7 +37,7 @@ const Quote = struct {
fn randomQuote(allocator: std.mem.Allocator) !Quote { fn randomQuote(allocator: std.mem.Allocator) !Quote {
const path = "src/app/config/quotes.json"; const path = "src/app/config/quotes.json";
const stat = try std.fs.cwd().statFile(path); const stat = try std.fs.cwd().statFile(path);
const json = try std.fs.cwd().readFileAlloc(allocator, path, stat.size); const json = try std.fs.cwd().readFileAlloc(allocator, path, @intCast(stat.size));
const quotes = try std.json.parseFromSlice([]Quote, allocator, json, .{}); const quotes = try std.json.parseFromSlice([]Quote, allocator, json, .{});
return quotes.value[std.crypto.random.intRangeLessThan(usize, 0, quotes.value.len)]; return quotes.value[std.crypto.random.intRangeLessThan(usize, 0, quotes.value.len)];
} }

View File

@ -16,9 +16,3 @@
<div>Take a look at the <span class="font-mono">/demo/src/app/</span> directory to see how this application works.</div> <div>Take a look at the <span class="font-mono">/demo/src/app/</span> directory to see how this application works.</div>
<div>Visit <a class="font-bold text-[#39b54a]" href="https://jetzig.dev/">jetzig.dev</a> to get started.</div> <div>Visit <a class="font-bold text-[#39b54a]" href="https://jetzig.dev/">jetzig.dev</a> to get started.</div>
</div> </div>
@markdown {
# Hello
[foobar](https://www.google.com)
}

View File

@ -10,7 +10,7 @@ const JsonMimeType = struct {
pub fn generateMimeModule(build: *std.Build) !*std.Build.Module { pub fn generateMimeModule(build: *std.Build) !*std.Build.Module {
const file = try std.fs.openFileAbsolute(build.pathFromRoot("src/jetzig/http/mime/mimeData.json"), .{}); const file = try std.fs.openFileAbsolute(build.pathFromRoot("src/jetzig/http/mime/mimeData.json"), .{});
const stat = try file.stat(); const stat = try file.stat();
const json = try file.readToEndAlloc(build.allocator, stat.size); const json = try file.readToEndAlloc(build.allocator, @intCast(stat.size));
defer build.allocator.free(json); defer build.allocator.free(json);
const parsed_mime_types = try std.json.parseFromSlice( const parsed_mime_types = try std.json.parseFromSlice(

View File

@ -296,7 +296,7 @@ const RouteSet = struct {
fn generateRoutesForView(self: *Routes, dir: std.fs.Dir, path: []const u8) !RouteSet { fn generateRoutesForView(self: *Routes, dir: std.fs.Dir, path: []const u8) !RouteSet {
const stat = try dir.statFile(path); const stat = try dir.statFile(path);
const source = try dir.readFileAllocOptions(self.allocator, path, stat.size, null, @alignOf(u8), 0); const source = try dir.readFileAllocOptions(self.allocator, path, @intCast(stat.size), null, @alignOf(u8), 0);
defer self.allocator.free(source); defer self.allocator.free(source);
self.ast = try std.zig.Ast.parse(self.allocator, source, .zig); self.ast = try std.zig.Ast.parse(self.allocator, source, .zig);

View File

@ -33,7 +33,7 @@ pub fn render(
else => err, else => err,
}; };
}; };
const markdown_content = std.fs.cwd().readFileAlloc(allocator, full_path, stat.size) catch |err| { const markdown_content = std.fs.cwd().readFileAlloc(allocator, full_path, @intCast(stat.size)) catch |err| {
switch (err) { switch (err) {
error.FileNotFound => return null, error.FileNotFound => return null,
else => return err, else => return err,