| author | |
| committer | |
| log | cd56b80b5f517912286c6e80767f72d950e0de3e |
| tree | 33eab0b752662cc9512859b22bcd56b1f43581a0 |
| parent | 16cef5e32b3f8bbcf1064c599615290a720b6547 |
| signature |
3 files changed, 18 insertions(+), 12 deletions(-)
build.zig+11-7| ... | @@ -3,14 +3,16 @@ const deps = @import("./deps.zig"); | ... | @@ -3,14 +3,16 @@ const deps = @import("./deps.zig"); |
| 3 | 3 | ||
| 4 | pub fn build(b: *std.Build) void { | 4 | pub fn build(b: *std.Build) void { |
| 5 | const target = b.standardTargetOptions(.{}); | 5 | const target = b.standardTargetOptions(.{}); |
| 6 | const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug; | 6 | const mode = b.option(std.builtin.OptimizeMode, "mode", "") orelse .Debug; |
| 7 | const disable_llvm = b.option(bool, "disable_llvm", "use the non-llvm zig codegen") orelse false; | 7 | const disable_llvm = b.option(bool, "disable_llvm", "use the non-llvm zig codegen") orelse false; |
| 8 | 8 | ||
| 9 | const exe2 = b.addExecutable(.{ | 9 | const exe2 = b.addExecutable(.{ |
| 10 | .name = "generate", | 10 | .name = "generate", |
| 11 | .root_source_file = b.path("generate.zig"), | 11 | .root_module = b.createModule(.{ |
| 12 | .target = target, | 12 | .root_source_file = b.path("generate.zig"), |
| 13 | .optimize = mode, | 13 | .target = target, |
| 14 | .optimize = mode, | ||
| 15 | }), | ||
| 14 | }); | 16 | }); |
| 15 | deps.addAllTo(exe2); | 17 | deps.addAllTo(exe2); |
| 16 | exe2.use_llvm = !disable_llvm; | 18 | exe2.use_llvm = !disable_llvm; |
| ... | @@ -27,9 +29,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -27,9 +29,11 @@ pub fn build(b: *std.Build) void { |
| 27 | run_step2.dependOn(&run_cmd2.step); | 29 | run_step2.dependOn(&run_cmd2.step); |
| 28 | 30 | ||
| 29 | const tests = b.addTest(.{ | 31 | const tests = b.addTest(.{ |
| 30 | .root_source_file = b.path("test.zig"), | 32 | .root_module = b.createModule(.{ |
| 31 | .target = target, | 33 | .root_source_file = b.path("test.zig"), |
| 32 | .optimize = mode, | 34 | .target = target, |
| 35 | .optimize = mode, | ||
| 36 | }), | ||
| 33 | }); | 37 | }); |
| 34 | deps.addAllTo(tests); | 38 | deps.addAllTo(tests); |
| 35 | tests.use_llvm = !disable_llvm; | 39 | tests.use_llvm = !disable_llvm; |
generate.zig+6-5| ... | @@ -2,13 +2,14 @@ | ... | @@ -2,13 +2,14 @@ |
| 2 | 2 | ||
| 3 | const std = @import("std"); | 3 | const std = @import("std"); |
| 4 | const json = @import("json"); | 4 | const json = @import("json"); |
| 5 | const nfs = @import("nfs"); | ||
| 5 | 6 | ||
| 6 | pub fn main() !void { | 7 | pub fn main() !void { |
| 7 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | 8 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| 8 | const alloc = gpa.allocator(); | 9 | const alloc = gpa.allocator(); |
| 9 | 10 | ||
| 10 | const f = try std.fs.cwd().createFile("src/lib.zig", .{}); | 11 | const f = try nfs.cwd().createFile("src/lib.zig", .{}); |
| 11 | const w = f.writer(); | 12 | const w = f; |
| 12 | 13 | ||
| 13 | { | 14 | { |
| 14 | std.log.info("spdx", .{}); | 15 | std.log.info("spdx", .{}); |
| ... | @@ -73,16 +74,16 @@ pub fn simple_fetch(alloc: std.mem.Allocator, url: []const u8) !json.Document { | ... | @@ -73,16 +74,16 @@ pub fn simple_fetch(alloc: std.mem.Allocator, url: []const u8) !json.Document { |
| 73 | var client = std.http.Client{ .allocator = alloc }; | 74 | var client = std.http.Client{ .allocator = alloc }; |
| 74 | defer client.deinit(); | 75 | defer client.deinit(); |
| 75 | 76 | ||
| 76 | var list = std.ArrayList(u8).init(alloc); | 77 | var list = std.Io.Writer.Allocating.init(alloc); |
| 77 | defer list.deinit(); | 78 | defer list.deinit(); |
| 78 | 79 | ||
| 79 | const fetch = try client.fetch(.{ | 80 | const fetch = try client.fetch(.{ |
| 80 | .location = .{ .url = url }, | 81 | .location = .{ .url = url }, |
| 81 | .response_storage = .{ .dynamic = &list }, | 82 | .response_writer = &list.writer, |
| 82 | }); | 83 | }); |
| 83 | const opts = json.Parser.Options{ .maximum_depth = 100, .support_trailing_commas = true }; | 84 | const opts = json.Parser.Options{ .maximum_depth = 100, .support_trailing_commas = true }; |
| 84 | if (fetch.status != .ok) return try json.parseFromSlice(alloc, url, "{}", opts); | 85 | if (fetch.status != .ok) return try json.parseFromSlice(alloc, url, "{}", opts); |
| 85 | return try json.parseFromSlice(alloc, url, list.items, opts); | 86 | return try json.parseFromSlice(alloc, url, list.written(), opts); |
| 86 | } | 87 | } |
| 87 | 88 | ||
| 88 | fn spdxlicenseLessThan(context: void, lhs: json.ValueIndex, rhs: json.ValueIndex) bool { | 89 | fn spdxlicenseLessThan(context: void, lhs: json.ValueIndex, rhs: json.ValueIndex) bool { |
zig.mod+1| ... | @@ -4,3 +4,4 @@ main: src/lib.zig | ... | @@ -4,3 +4,4 @@ main: src/lib.zig |
| 4 | license: MIT | 4 | license: MIT |
| 5 | root_dependencies: | 5 | root_dependencies: |
| 6 | - src: git https://github.com/nektro/zig-json | 6 | - src: git https://github.com/nektro/zig-json |
| 7 | - src: git https://github.com/nektro/zig-nfs |