mirror of
https://github.com/NilsIrl/dockerc.git
synced 2025-09-26 19:11:13 +08:00
Add --version to dockerc and --dockerc-version to runtime
This commit is contained in:
@@ -18,6 +18,10 @@ pub fn build(b: *std.Build) void {
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const skip_crun_build = b.option(bool, "skip_crun_build", "Skip crun build") orelse false;
|
||||
const dockerc_version = b.option([]const u8, "dockerc_version", "Set dockerc version") orelse "HEAD";
|
||||
|
||||
const build_info = b.addOptions();
|
||||
build_info.addOption([]const u8, "dockerc_version", dockerc_version);
|
||||
|
||||
const zstd = b.createModule(.{});
|
||||
zstd.addAssemblyFile(b.path("zstd/lib/decompress/huf_decompress_amd64.S"));
|
||||
@@ -184,6 +188,8 @@ pub fn build(b: *std.Build) void {
|
||||
.link_libc = true,
|
||||
});
|
||||
|
||||
runtime.addOptions("build_info", build_info);
|
||||
|
||||
runtime.addImport("zstd", zstd);
|
||||
runtime.addImport("fuse-overlayfs", fuse_fss);
|
||||
|
||||
@@ -404,6 +410,8 @@ pub fn build(b: *std.Build) void {
|
||||
.link_libc = true,
|
||||
});
|
||||
|
||||
dockerc.root_module.addOptions("build_info", build_info);
|
||||
|
||||
dockerc.addIncludePath(b.path("zstd/lib"));
|
||||
dockerc.root_module.addImport("zstd", zstd);
|
||||
dockerc.addCSourceFiles(.{
|
||||
|
@@ -2,6 +2,7 @@ const builtin = @import("builtin");
|
||||
const std = @import("std");
|
||||
const clap = @import("clap");
|
||||
const common = @import("common.zig");
|
||||
const build_info = @import("build_info");
|
||||
|
||||
const mkdtemp = common.mkdtemp;
|
||||
const extract_file = common.extract_file;
|
||||
@@ -48,6 +49,7 @@ pub fn main() !void {
|
||||
|
||||
const params = comptime clap.parseParamsComptime(
|
||||
\\-h, --help Display this help and exit.
|
||||
\\--version Display dockerc version.
|
||||
\\-i, --image <str> Image to pull.
|
||||
\\-o, --output <str> Output file.
|
||||
\\--arch <str> Architecture (amd64, arm64).
|
||||
@@ -66,6 +68,11 @@ pub fn main() !void {
|
||||
};
|
||||
defer res.deinit();
|
||||
|
||||
if (res.args.version != 0) {
|
||||
std.debug.print("dockerc version: {s}\n", .{build_info.dockerc_version});
|
||||
return;
|
||||
}
|
||||
|
||||
if (res.args.help != 0) {
|
||||
try clap.help(io.getStdErr().writer(), clap.Help, ¶ms, .{});
|
||||
return;
|
||||
|
14
src/main.zig
14
src/main.zig
@@ -1,6 +1,7 @@
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const common = @import("common.zig");
|
||||
const build_info = @import("build_info");
|
||||
|
||||
const mkdtemp = common.mkdtemp;
|
||||
const extract_file = common.extract_file;
|
||||
@@ -356,6 +357,16 @@ fn umount(path: [*:0]const u8) void {
|
||||
}
|
||||
|
||||
pub fn main() !u8 {
|
||||
var args = std.process.args();
|
||||
const executable_path = args.next() orelse @panic("unreachable: there must be a executable name");
|
||||
|
||||
while (args.next()) |arg| {
|
||||
if (eql(u8, arg, "--dockerc-version")) {
|
||||
std.debug.print("dockerc version: {s}\n", .{build_info.dockerc_version});
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
defer _ = gpa.deinit();
|
||||
const allocator = gpa.allocator();
|
||||
@@ -485,9 +496,6 @@ pub fn main() !u8 {
|
||||
std.posix.close(read_fd);
|
||||
}
|
||||
|
||||
var args = std.process.args();
|
||||
const executable_path = args.next() orelse unreachable;
|
||||
|
||||
var temp_dir_path = "/tmp/dockerc-XXXXXX".*;
|
||||
try mkdtemp(&temp_dir_path);
|
||||
|
||||
|
Reference in New Issue
Block a user