Skip to content

Commit 3d01c20

Browse files
committed
add the http dep type
1 parent a425c07 commit 3d01c20

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ zigmod add <type> <path>
5656
- `system_lib`
5757
- `git`
5858
- `hg`
59+
- `http`
5960

6061
### `fetch` command
6162
```
@@ -103,7 +104,7 @@ pub fn build(b: *Builder) void {
103104
#### Dep object
104105
| Name | Type | Note | Description |
105106
|------|------|------|-------------|
106-
| `type` | `string` | required, enum | One of `system_lib`, `git`, `hg` |
107+
| `type` | `string` | required, enum | One of `system_lib`, `git`, `hg`, `http` |
107108
| `path` | `string` | required | URL/path to this dependency. depends on the type |
108109
| `version` | `string` | only on some types | pin this dependency at a specific version |
109110
| `only_os` | `string` | | comma separated list of OS names to add this Dep to |

src/cmd_fetch.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
130130
_ = try d.type.update(p, d.path);
131131
}
132132
},
133+
.http => {
134+
const file_name = try u.last(try u.split(d.path, "/"));
135+
if (try u.does_file_exist(p)) {
136+
try u.rm_recv(p);
137+
}
138+
_ = try d.type.pull(d.path, p);
139+
},
133140
}
134141
switch (d.type) {
135142
.system_lib => {

src/util/dep_type.zig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const std = @import("std");
2+
const gpa = std.heap.c_allocator;
3+
14
const u = @import("./index.zig");
25

36
//
@@ -7,6 +10,7 @@ pub const DepType = enum {
710
system_lib, // std.build.LibExeObjStep.linkSystemLibrary
811
git, // https://git-scm.com/
912
hg, // https://www.mercurial-scm.org/
13+
http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
1014

1115
pub fn pull(self: DepType, rpath: []const u8, dpath: []const u8) !void {
1216
switch (self) {
@@ -18,6 +22,24 @@ pub const DepType = enum {
1822
.hg => {
1923
_ = try u.run_cmd(null, &[_][]const u8{"hg", "clone", rpath, dpath});
2024
},
25+
.http => {
26+
try u.mkdir_all(dpath);
27+
_ = try u.run_cmd(dpath, &[_][]const u8{"wget", rpath});
28+
const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").?+1..];
29+
if (std.mem.endsWith(u8, f, ".zip")) {
30+
_ = try u.run_cmd(dpath, &[_][]const u8{"unzip", f, "-d", "."});
31+
try std.fs.deleteFileAbsolute(try std.fs.path.join(gpa, &[_][]const u8{dpath, f}));
32+
}
33+
if (
34+
std.mem.endsWith(u8, f, ".tar")
35+
or std.mem.endsWith(u8, f, ".tar.gz")
36+
or std.mem.endsWith(u8, f, ".tar.xz")
37+
or std.mem.endsWith(u8, f, ".tar.zst")
38+
) {
39+
_ = try u.run_cmd(dpath, &[_][]const u8{"tar", "-xf", f, "-C", "."});
40+
try std.fs.deleteFileAbsolute(try std.fs.path.join(gpa, &[_][]const u8{dpath, f}));
41+
}
42+
},
2143
}
2244
}
2345

@@ -31,6 +53,9 @@ pub const DepType = enum {
3153
.hg => {
3254
_ = try u.run_cmd(dpath, &[_][]const u8{"hg", "pull"});
3355
},
56+
.http => {
57+
//
58+
},
3459
}
3560
}
3661
};

0 commit comments

Comments
 (0)