| author | |
| committer | |
| log | abceb0d034839ddb456c0c38994fdef559276a8b |
| tree | f286663dee7e6aab93103e0dc65ff53883c337d6 |
| parent | 84fd0b9e6011e19d5894be3c039c8ecb875239dd |
5 files changed, 77 insertions(+), 1 deletions(-)
.gitignore+1| ... | @@ -1,2 +1,3 @@ | ... | @@ -1,2 +1,3 @@ |
| 1 | /bin | 1 | /bin |
| 2 | /zigmod* | 2 | /zigmod* |
| 3 | /zig-cache |
build.zig created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const Builder = std.build.Builder; | ||
| 3 | const builtin = @import("builtin"); | ||
| 4 | |||
| 5 | pub fn build(b: *Builder) void { | ||
| 6 | const target = b.standardTargetOptions(.{}); | ||
| 7 | |||
| 8 | b.setPreferredReleaseMode(.ReleaseSafe); | ||
| 9 | const mode = b.standardReleaseOptions(); | ||
| 10 | |||
| 11 | const use_full_name = b.option(bool, "use-full-name", "") orelse false; | ||
| 12 | const with_os_arch = b.fmt("-{}-{}", .{@tagName(target.os_tag orelse builtin.os.tag), @tagName(target.cpu_arch orelse builtin.arch)}); | ||
| 13 | const exe_name = b.fmt("{}{}", .{ "zigmod-zig", if (use_full_name) with_os_arch else "" }); | ||
| 14 | |||
| 15 | const exe = b.addExecutable(exe_name, "src/main.zig"); | ||
| 16 | exe.setTarget(target); | ||
| 17 | exe.setBuildMode(mode); | ||
| 18 | exe.strip = true; | ||
| 19 | |||
| 20 | exe.install(); | ||
| 21 | |||
| 22 | const run_cmd = exe.run(); | ||
| 23 | run_cmd.step.dependOn(b.getInstallStep()); | ||
| 24 | if (b.args) |args| { | ||
| 25 | run_cmd.addArgs(args); | ||
| 26 | } | ||
| 27 | |||
| 28 | const run_step = b.step("run", "Run the app"); | ||
| 29 | run_step.dependOn(&run_cmd.step); | ||
| 30 | } | ||
build_all.sh+1-1| ... | @@ -12,7 +12,7 @@ build_template() { | ... | @@ -12,7 +12,7 @@ build_template() { |
| 12 | version=${CIRCLE_BUILD_NUM-$date} | 12 | version=${CIRCLE_BUILD_NUM-$date} |
| 13 | tag=v$version-$(git log --format=%h -1) | 13 | tag=v$version-$(git log --format=%h -1) |
| 14 | echo $tag-$GOOS-$GOARCH | 14 | echo $tag-$GOOS-$GOARCH |
| 15 | go build -ldflags="-s -w -X main.Version=$tag" -o ./bin/zigmod-$tag-$GOOS-$GOARCH$ext | 15 | go build -ldflags="-s -w -X main.Version=$tag" -o ./bin/zigmod-go-$tag-$GOOS-$GOARCH$ext |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | # go tool dist list | grep amd64 | 18 | # go tool dist list | grep amd64 |
build_all_zig.sh created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | set -e | ||
| 4 | |||
| 5 | for item in $(zig targets | jq --raw-output '.libc[]' | grep gnu$ | grep x86_64) | ||
| 6 | do | ||
| 7 | echo $item | ||
| 8 | zig build -Dtarget=$item -Drelease -Duse-full-name | ||
| 9 | done | ||
src/main.zig created+36| ... | @@ -0,0 +1,36 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | // | ||
| 5 | // | ||
| 6 | |||
| 7 | const commands = struct { | ||
| 8 | }; | ||
| 9 | |||
| 10 | pub fn main() !void { | ||
| 11 | |||
| 12 | const gpa = std.heap.c_allocator; | ||
| 13 | |||
| 14 | const proc_args = try std.process.argsAlloc(gpa); | ||
| 15 | const args = proc_args[1..]; | ||
| 16 | |||
| 17 | u.print("args len: {}", .{args.len}); | ||
| 18 | for (args) |a, i| { | ||
| 19 | u.print("arg {}: {}", .{i, a}); | ||
| 20 | } | ||
| 21 | |||
| 22 | if (args.len == 0) { | ||
| 23 | u.print("zigmod-{}-{}-{}", .{@tagName(builtin.os.tag), @tagName(builtin.arch), @tagName(builtin.abi)}); | ||
| 24 | return; | ||
| 25 | } | ||
| 26 | |||
| 27 | inline for (std.meta.declarations(commands)) |decl| { | ||
| 28 | if (std.mem.eql(u8, args[0], decl.name)) { | ||
| 29 | const cmd = @field(commands, decl.name); | ||
| 30 | try cmd.execute(args[1..]); | ||
| 31 | return; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | std.debug.panic("Error: unknown command \"{}\" for \"zigmod\"", .{args[0]}); | ||
| 36 | } | ||