From 25da26e5d2dbce5931d27988fcf28b79deb66983 Mon Sep 17 00:00:00 2001 From: ivansantiagojr Date: Sun, 25 Aug 2024 22:12:25 -0300 Subject: [PATCH] update to zig 0.13 --- .github/workflows/cd.yml | 2 +- .github/workflows/ci.yml | 2 +- .gitignore | 2 +- build.zig | 18 +----------------- src/main.zig | 27 ++++++++------------------- 5 files changed, 12 insertions(+), 39 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index ad84968..68f8d45 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -29,7 +29,7 @@ jobs: - name: Install Zig uses: goto-bus-stop/setup-zig@v2 with: - version: 0.11.0 + version: 0.13.0 - name: Build run: zig build -Dtarget=${{ matrix.TARGET }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 476133a..16d346d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: - name: Install Zig uses: goto-bus-stop/setup-zig@v2 with: - version: 0.11.0 + version: 0.13.0 - name: Build run: zig build ${{ matrix.OPTIMIZE }} diff --git a/.gitignore b/.gitignore index 9699cc7..8e44b40 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ ### zig ### # Zig programming language -zig-cache/ +.zig-cache/ zig-out/ build/ build-*/ diff --git a/build.zig b/build.zig index a16da37..ba3a109 100644 --- a/build.zig +++ b/build.zig @@ -19,7 +19,7 @@ pub fn build(b: *std.Build) void { .name = "zignr", // In this case the main source file is merely a path, however, in more // complicated build scripts, this could be a generated file. - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); @@ -51,20 +51,4 @@ pub fn build(b: *std.Build) void { // This will evaluate the `run` step rather than the default, which is "install". const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); - - // Creates a step for unit testing. This only builds the test executable - // but does not run it. - const unit_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/main.zig" }, - .target = target, - .optimize = optimize, - }); - - const run_unit_tests = b.addRunArtifact(unit_tests); - - // Similar to creating the run step earlier, this exposes a `test` step to - // the `zig build --help` menu, providing a way for the user to request - // running the unit tests. - const test_step = b.step("test", "Run unit tests"); - test_step.dependOn(&run_unit_tests.step); } diff --git a/src/main.zig b/src/main.zig index 3edd660..87d4b35 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,14 +1,13 @@ const std = @import("std"); const print = std.io.getStdOut().writer(); const http = std.http; -const is_zig_11 = @import("builtin").zig_version.minor == 11; pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); const allocator = gpa.allocator(); - var args = try std.process.argsAlloc(allocator); + const args = try std.process.argsAlloc(allocator); defer std.process.argsFree(allocator, args); if (args.len != 2) { @@ -22,31 +21,21 @@ pub fn main() !void { } const language = std.mem.sliceTo(args[1], 0); - var headers = http.Headers{ .allocator = allocator }; - defer headers.deinit(); - var client = http.Client{ .allocator = allocator }; defer client.deinit(); - var base_url = "https://www.toptal.com/developers/gitignore/api/"; + const base_url = "https://www.toptal.com/developers/gitignore/api/"; var url_buffer: [256]u8 = undefined; const url_to_request = try std.fmt.bufPrint(&url_buffer, "{s}{s}", .{ base_url, language }); const uri = try std.Uri.parse(url_to_request); - var req = if (is_zig_11) blk: { - var req = try client.request(.GET, uri, headers, .{}); - errdefer req.deinit(); - - try req.start(); - break :blk req; - } else blk: { - var req = try client.open(.GET, uri, headers, .{}); - errdefer req.deinit(); - - try req.send(.{}); - break :blk req; - }; + const buf = try allocator.alloc(u8, 1024 * 1014 * 4); + defer allocator.free(buf); + + var req = try client.open(.GET, uri, .{ .server_header_buffer = buf }); defer req.deinit(); + try req.send(); + try req.finish(); try req.wait(); if (req.response.status != .ok) {