Jonathan Marler hace 3 años
padre
commit
08f73f81ed
Se han modificado 4 ficheros con 50 adiciones y 7 borrados
  1. 2 0
      .github/workflows/artifact.yml
  2. 20 0
      build.zig
  3. 1 0
      zarcsha
  4. 27 7
      zigup.zig

+ 2 - 0
.github/workflows/artifact.yml

@@ -17,6 +17,8 @@ jobs:
           git -C ./dep/ziget checkout $(cat zigetsha) -b for_zigup
           git clone https://github.com/marler8997/iguanaTLS ./dep/iguanaTLS
           git -C ./dep/iguanaTLS checkout $(cat ziget-build-files-copy/iguanasha) -b for_ziget
+          git clone https://github.com/SuperAuguste/zarc ./dep/zarc
+          git -C ./dep/zarc checkout $(cat zarcsha) -b for_zigup
           zig build test -Diguana -Dcpu=baseline
         shell: bash
       - uses: actions/upload-artifact@v2

+ 20 - 0
build.zig

@@ -1,4 +1,5 @@
 const std = @import("std");
+const builtin = @import("builtin");
 const Builder = std.build.Builder;
 const Pkg = std.build.Pkg;
 
@@ -89,10 +90,29 @@ fn addZigupExe(b: *Builder, ziget_repo: []const u8, target: std.zig.CrossTarget,
         .path = .{ .path = try join(b, &[_][]const u8 { ziget_repo, "ziget.zig" }) },
         .dependencies = &[_]Pkg {ziget_ssl_pkg},
     });
+
+    if (targetIsWindows(target)) {
+        const zarc_repo = try (GitRepo {
+            .url = "https://github.com/SuperAuguste/zarc",
+            .branch = null,
+            .sha = @embedFile("zarcsha"),
+        }).resolve(b.allocator);
+        exe.addPackage(Pkg {
+            .name = "zarc",
+            .path = .{ .path = try join(b, &[_][]const u8 { zarc_repo, "src", "main.zig" }) },
+        });
+    }
+
     exe.step.dependOn(&require_ssl_backend.step);
     return exe;
 }
 
+fn targetIsWindows(target: std.zig.CrossTarget) bool {
+    if (target.os_tag) |tag|
+        return tag == .windows;
+    return builtin.target.os.tag == .windows;
+}
+
 const SslBackendFailedStep = struct {
     step: std.build.Step,
     context: []const u8,

+ 1 - 0
zarcsha

@@ -0,0 +1 @@
+accc35c0bf190d55133cc689cf989c03bf853349

+ 27 - 7
zigup.zig

@@ -6,6 +6,7 @@ const ArrayList = std.ArrayList;
 const Allocator = mem.Allocator;
 
 const ziget = @import("ziget");
+const zarc = @import("zarc");
 
 const fixdeletetree = @import("fixdeletetree.zig");
 
@@ -673,14 +674,33 @@ fn installCompiler(allocator: *Allocator, compiler_dir: []const u8, url: []const
         if (std.mem.endsWith(u8, archive_basename, ".tar.xz")) {
             archive_root_dir = archive_basename[0 .. archive_basename.len - ".tar.xz".len];
             _ = try run(allocator, &[_][]const u8{ "tar", "xf", archive_absolute, "-C", installing_dir });
-        } else if (std.mem.endsWith(u8, archive_basename, ".zip")) {
-            // for now we'll use "tar" which seems to exist on windows 10, but we should switch
-            // to a zig implementation (i.e. https://github.com/SuperAuguste/zzip)
-            archive_root_dir = archive_basename[0 .. archive_basename.len - ".zip".len];
-            _ = try run(allocator, &[_][]const u8{ "tar", "-xf", archive_absolute, "-C", installing_dir });
         } else {
-            std.debug.print("Error: unknown archive extension '{s}'\n", .{archive_basename});
-            return error.UnknownArchiveExtension;
+            var recognized = false;
+            if (builtin.os.tag == .windows) {
+                if (std.mem.endsWith(u8, archive_basename, ".zip")) {
+                    recognized = true;
+                    archive_root_dir = archive_basename[0 .. archive_basename.len - ".zip".len];
+
+                    var installing_dir_opened = try std.fs.openDirAbsolute(installing_dir, .{});
+                    defer installing_dir_opened.close();
+
+                    var archive_file = try std.fs.openFileAbsolute(archive_absolute, .{});
+                    defer archive_file.close();
+                    var archive = zarc.zip.Parser(std.fs.File.Reader).init(allocator, archive_file.reader());
+                    defer archive.deinit();
+                    std.debug.print("extracting archive to \"{s}\"\n", .{installing_dir});
+                    var timer = try std.time.Timer.start();
+                    try archive.load();
+                    _ = try archive.extract(installing_dir_opened, .{});
+                    const time = timer.read();
+                    std.debug.print("extracted archive in {d:.2} s\n", .{@intToFloat(f32, time) / @intToFloat(f32, std.time.ns_per_s)});
+                }
+            }
+
+            if (!recognized) {
+                std.debug.print("Error: unknown archive extension '{s}'\n", .{archive_basename});
+                return error.UnknownArchiveExtension;
+            }
         }
         try loggyDeleteTreeAbsolute(archive_absolute);
     }