forked from ziglang/zig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
.unpack = false
and --no-unpack to build.zig.zon and zig fetch
closes ziglang#17895 Enhances zig with the ability to fetch a dependency of any file type.
- Loading branch information
1 parent
f845fa0
commit 6e953cf
Showing
13 changed files
with
195 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.Build) !void { | ||
const test_step = b.step("test", "Test it"); | ||
b.default_step = test_step; | ||
|
||
{ | ||
const codegen_exe = b.addExecutable(.{ | ||
.name = "codegen", | ||
.target = b.host, | ||
.root_source_file = b.path("codegen.zig"), | ||
}); | ||
const run_codegen = b.addRunArtifact(codegen_exe); | ||
const example_dir = run_codegen.addOutputDirectoryArg("example"); | ||
|
||
const run = b.addSystemCommand(&.{ | ||
b.graph.zig_exe, | ||
"build", | ||
"install", | ||
"--build-file", | ||
}); | ||
run.addFileArg(example_dir.path(b, "build.zig")); | ||
run.addArg("--prefix"); | ||
const install_dir = run.addOutputDirectoryArg("install"); | ||
const check_file = b.addCheckFile(install_dir.path(b, "example_dep_file.txt"), .{ | ||
.expected_exact = "This is an example file.\n", | ||
}); | ||
test_step.dependOn(&check_file.step); | ||
} | ||
|
||
{ | ||
const run = b.addSystemCommand(&.{ | ||
b.graph.zig_exe, | ||
"build", | ||
"--build-file", | ||
}); | ||
run.addFileArg(b.path("unpacktrue/build.zig")); | ||
run.addCheck(.{ .expect_stderr_match = "error: unpack cannot be set to true, omit it instead" }); | ||
test_step.dependOn(&run.step); | ||
} | ||
|
||
{ | ||
const run = b.addSystemCommand(&.{ | ||
b.graph.zig_exe, | ||
"fetch", | ||
"--no-unpack", | ||
}); | ||
run.addFileArg(b.path("example/example_dep_file.txt")); | ||
run.expectStdOutEqual("12200f68aca70ebc76057200af436aab5720ec53a780713c5dc614825db42a39dbfb\n"); | ||
test_step.dependOn(&run.step); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const std = @import("std"); | ||
|
||
pub fn main() !void { | ||
var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator); | ||
const arena = arena_instance.allocator(); | ||
const args = try std.process.argsAlloc(arena); | ||
std.debug.assert(args.len == 2); | ||
const out_dir = args[1]; | ||
|
||
if (!std.fs.path.isAbsolute(out_dir)) { | ||
std.log.err("directory '{s}' must be absolute", .{out_dir}); | ||
std.process.exit(0xff); | ||
} | ||
|
||
var dir = try std.fs.openDirAbsolute(out_dir, .{}); | ||
defer dir.close(); | ||
|
||
try writeFile(dir, "build.zig", @embedFile("example/build.zig")); | ||
try writeFile(dir, "example_dep_file.txt", @embedFile("example/example_dep_file.txt")); | ||
|
||
{ | ||
const template = @embedFile("example/build.zig.zon.template"); | ||
const package_path_absolute = try arena.dupe(u8, out_dir); | ||
for (package_path_absolute) |*c| { | ||
c.* = if (c.* == '\\') '/' else c.*; | ||
} | ||
const content = try std.mem.replaceOwned(u8, arena, template, "<PACKAGE_PATH_ABSOLUTE>", package_path_absolute); | ||
try writeFile(dir, "build.zig.zon", content); | ||
} | ||
} | ||
|
||
fn writeFile(dir: std.fs.Dir, name: []const u8, content: []const u8) !void { | ||
const file = try dir.createFile(name, .{}); | ||
defer file.close(); | ||
try file.writer().writeAll(content); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.Build) void { | ||
const dep = b.dependency("somedependency", .{}); | ||
b.getInstallStep().dependOn(&b.addInstallFile( | ||
dep.path("example_dep_file.txt"), | ||
"example_dep_file.txt", | ||
).step); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.{ | ||
.name = "fetch", | ||
.version = "0.0.0", | ||
.dependencies = .{ | ||
.somedependency = .{ | ||
.url = "file://<PACKAGE_PATH_ABSOLUTE>/example_dep_file.txt", | ||
.hash = "12200f68aca70ebc76057200af436aab5720ec53a780713c5dc614825db42a39dbfb", | ||
.unpack = false, | ||
}, | ||
}, | ||
.paths = .{ | ||
"build.zig", | ||
"build.zig.zon", | ||
"example_dep_file.txt", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is an example file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(_: *std.Build) void {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.{ | ||
.name = "unpacktrue", | ||
.version = "0.0.0", | ||
.dependencies = .{ | ||
.somedependency = .{ | ||
.url = "file://localhost/bar", | ||
.hash = "1220f3b02ca452c26a96b48d2912b7fc907bef8d0b85c2e8f7e4a5c8bd95cdbfbae6", | ||
.unpack = true, | ||
}, | ||
}, | ||
.paths = .{ | ||
"build.zig", | ||
"build.zig.zon", | ||
}, | ||
} |