diff --git a/.gitignore b/.gitignore index f8016ebc983a919ac20ab34980ac3f5d1fd9e275..ddcd0a44ffc28e4f83e72934703d4a727e3d91de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /bin /zigmod* +/zig-cache diff --git a/build.zig b/build.zig new file mode 100644 index 0000000000000000000000000000000000000000..9b49657093419ba294ee615c37ba943248a751d7 --- /dev/null +++ b/build.zig @@ -0,0 +1,30 @@ +const std = @import("std"); +const Builder = std.build.Builder; +const builtin = @import("builtin"); + +pub fn build(b: *Builder) void { + const target = b.standardTargetOptions(.{}); + + b.setPreferredReleaseMode(.ReleaseSafe); + const mode = b.standardReleaseOptions(); + + const use_full_name = b.option(bool, "use-full-name", "") orelse false; + const with_os_arch = b.fmt("-{}-{}", .{@tagName(target.os_tag orelse builtin.os.tag), @tagName(target.cpu_arch orelse builtin.arch)}); + const exe_name = b.fmt("{}{}", .{ "zigmod-zig", if (use_full_name) with_os_arch else "" }); + + const exe = b.addExecutable(exe_name, "src/main.zig"); + exe.setTarget(target); + exe.setBuildMode(mode); + exe.strip = true; + + exe.install(); + + const run_cmd = exe.run(); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/build_all.sh b/build_all.sh index fde240d8e619540955fbccbe535d2aa04f4ff1d3..955bda05d62928f34bf44f787f6cbe52cc828241 100755 --- a/build_all.sh +++ b/build_all.sh @@ -12,7 +12,7 @@ build_template() { version=${CIRCLE_BUILD_NUM-$date} tag=v$version-$(git log --format=%h -1) echo $tag-$GOOS-$GOARCH - go build -ldflags="-s -w -X main.Version=$tag" -o ./bin/zigmod-$tag-$GOOS-$GOARCH$ext + go build -ldflags="-s -w -X main.Version=$tag" -o ./bin/zigmod-go-$tag-$GOOS-$GOARCH$ext } # go tool dist list | grep amd64 diff --git a/build_all_zig.sh b/build_all_zig.sh new file mode 100755 index 0000000000000000000000000000000000000000..42c6f5ed2dc16213e532127564d96800dfea00ca --- /dev/null +++ b/build_all_zig.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +for item in $(zig targets | jq --raw-output '.libc[]' | grep gnu$ | grep x86_64) +do + echo $item + zig build -Dtarget=$item -Drelease -Duse-full-name +done diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000000000000000000000000000000000000..c18574df9ac7ed01b09357123195153c16a1152b --- /dev/null +++ b/src/main.zig @@ -0,0 +1,36 @@ +const std = @import("std"); +const builtin = @import("builtin"); + +// +// + +const commands = struct { +}; + +pub fn main() !void { + + const gpa = std.heap.c_allocator; + + const proc_args = try std.process.argsAlloc(gpa); + const args = proc_args[1..]; + + u.print("args len: {}", .{args.len}); + for (args) |a, i| { + u.print("arg {}: {}", .{i, a}); + } + + if (args.len == 0) { + u.print("zigmod-{}-{}-{}", .{@tagName(builtin.os.tag), @tagName(builtin.arch), @tagName(builtin.abi)}); + return; + } + + inline for (std.meta.declarations(commands)) |decl| { + if (std.mem.eql(u8, args[0], decl.name)) { + const cmd = @field(commands, decl.name); + try cmd.execute(args[1..]); + return; + } + } + + std.debug.panic("Error: unknown command \"{}\" for \"zigmod\"", .{args[0]}); +}