From 8760662cf7ed6f3d13263e58d216b2f81754c02b Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Fri, 4 Aug 2023 16:40:24 -0700 Subject: [PATCH] partial upgrade of build --- build.zig | 98 +++++++++++---------------------------------------- build.zig.zon | 11 ++++++ 2 files changed, 32 insertions(+), 77 deletions(-) create mode 100644 build.zig.zon diff --git a/build.zig b/build.zig index c5588b1..c4ba57f 100644 --- a/build.zig +++ b/build.zig @@ -1,18 +1,9 @@ const std = @import("std"); const builtin = @import("builtin"); const Builder = @import("std").build.Builder; -const GitRepoStep = @import("GitRepoStep.zig"); -const CopyStep = @import("CopyStep.zig"); const tst = @import("build_test.zig"); -const VersionStep = @import("VersionStep.zig"); pub fn build(b: *Builder) !void { - const zfetch_repo = GitRepoStep.create(b, .{ - .url = "https://github.com/truemedian/zfetch", - // .branch = "0.1.10", // branch also takes tags. Tag 0.1.10 isn't quite new enough - .sha = "271cab5da4d12c8f08e67aa0cd5268da100e52f1", - }); - // Standard target options allows the person running `zig build` to choose // what target to build for. Here we do not override the defaults, which // means any target is allowed, and the default is native. Other options @@ -21,41 +12,30 @@ pub fn build(b: *Builder) !void { // Standard release options allow the person running `zig build` to select // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. - const mode = b.standardReleaseOptions(); - const exe = b.addExecutable("demo", "src/main.zig"); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "demo", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + const smithy_dep = b.dependency("smithy", .{ + // These are the arguments to the dependency. It expects a target and optimization level. + .target = target, + .optimize = optimize, + }); + exe.addModule("smithy", smithy_dep.module("smithy")); + // TODO: Smithy needs to be in a different repo // https://github.com/ziglang/zig/issues/855 - exe.addPackagePath("smithy", "smithy/src/smithy.zig"); - - exe.setTarget(target); - exe.setBuildMode(mode); + // exe.addModulePath("smithy", "smithy/src/smithy.zig"); if (target.getOs().tag != .macos) exe.linkage = .static; - // TODO: Strip doesn't actually fully strip the executable. If we're on - // linux we can run strip on the result, probably at the expense - // of busting cache logic - exe.strip = b.option(bool, "strip", "strip exe [true]") orelse true; - const copy_deps = CopyStep.create( - b, - "zfetch_deps.zig", - "libs/zfetch/deps.zig", - ); - copy_deps.step.dependOn(&zfetch_repo.step); + // Strip is controlled by optimize options + // exe.strip = b.option(bool, "strip", "strip exe [true]") orelse true; - const version = VersionStep.create(b, null); - exe.step.dependOn(&version.step); - exe.step.dependOn(©_deps.step); - - // This import won't work unless we're already cloned. The way around - // this is to have a multi-stage build process, but that's a lot of work. - // Instead, I've copied the addPackage and tweaked it for the build prefix - // so we'll have to keep that in sync with upstream - // const zfetch = @import("libs/zfetch/build.zig"); - exe.addPackage(getZfetchPackage(b, "libs/zfetch") catch unreachable); - exe.addPackagePath("iguanaTLS", "libs/zfetch/libs/iguanaTLS/src/main.zig"); - - const run_cmd = exe.run(); + const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); @@ -64,8 +44,8 @@ pub fn build(b: *Builder) !void { const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); - var test_step = try tst.addTestStep(b, mode, exe.packages.items); - test_step.dependOn(&version.step); + // TODO: Demo for testing is kind of terrible. Proper testing + // var test_step = try tst.addTestStep(b, optimize, exe.packages.items); var codegen: ?*std.build.Step = null; if (target.getOs().tag == .linux and false) { @@ -96,41 +76,5 @@ pub fn build(b: *Builder) !void { exe.step.dependOn(cg); } - exe.install(); -} - -fn getDependency(comptime lib_prefix: []const u8, comptime name: []const u8, comptime root: []const u8) !std.build.Pkg { - const path = lib_prefix ++ "/libs/" ++ name ++ "/" ++ root; - - // We don't actually care if the dependency has been checked out, as - // GitRepoStep will handle that for us - // Make sure that the dependency has been checked out. - // std.fs.cwd().access(path, .{}) catch |err| switch (err) { - // error.FileNotFound => { - // std.log.err("zfetch: dependency '{s}' not checked out", .{name}); - // - // return err; - // }, - // else => return err, - // }; - - return std.build.Pkg{ - .name = name, - .source = .{ .path = path }, - }; -} - -pub fn getZfetchPackage(b: *std.build.Builder, comptime lib_prefix: []const u8) !std.build.Pkg { - var dependencies = b.allocator.alloc(std.build.Pkg, 4) catch unreachable; - - dependencies[0] = try getDependency(lib_prefix, "iguanaTLS", "src/main.zig"); - dependencies[1] = try getDependency(lib_prefix, "network", "network.zig"); - dependencies[2] = try getDependency(lib_prefix, "uri", "uri.zig"); - dependencies[3] = try getDependency(lib_prefix, "hzzp", "src/main.zig"); - - return std.build.Pkg{ - .name = "zfetch", - .source = .{ .path = lib_prefix ++ "/src/main.zig" }, - .dependencies = dependencies, - }; + b.installArtifact(exe); } diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..f025b01 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,11 @@ +.{ + .name = "aws-zig", + .version = "0.0.1", + + .dependencies = .{ + .smithy = .{ + .url = "https://git.lerch.org/lobo/smithy/archive/41b61745d25a65817209dd5dddbb5f9b66896a99.tar.gz", + .hash = "122087deb0ae309b2258d59b40d82fe5921fdfc35b420bb59033244851f7f276fa34", + }, + }, +}