partial upgrade of build

This commit is contained in:
Emil Lerch 2023-08-04 16:40:24 -07:00
parent 5be18af930
commit 8760662cf7
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
2 changed files with 32 additions and 77 deletions

View File

@ -1,18 +1,9 @@
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const Builder = @import("std").build.Builder; const Builder = @import("std").build.Builder;
const GitRepoStep = @import("GitRepoStep.zig");
const CopyStep = @import("CopyStep.zig");
const tst = @import("build_test.zig"); const tst = @import("build_test.zig");
const VersionStep = @import("VersionStep.zig");
pub fn build(b: *Builder) !void { 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 // Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which // 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 // 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 // Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions(); const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable("demo", "src/main.zig");
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 // https://github.com/ziglang/zig/issues/855
exe.addPackagePath("smithy", "smithy/src/smithy.zig"); // exe.addModulePath("smithy", "smithy/src/smithy.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
if (target.getOs().tag != .macos) exe.linkage = .static; if (target.getOs().tag != .macos) exe.linkage = .static;
// TODO: Strip doesn't actually fully strip the executable. If we're on // Strip is controlled by optimize options
// linux we can run strip on the result, probably at the expense // exe.strip = b.option(bool, "strip", "strip exe [true]") orelse true;
// 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);
const version = VersionStep.create(b, null); const run_cmd = b.addRunArtifact(exe);
exe.step.dependOn(&version.step);
exe.step.dependOn(&copy_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();
run_cmd.step.dependOn(b.getInstallStep()); run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| { if (b.args) |args| {
run_cmd.addArgs(args); run_cmd.addArgs(args);
@ -64,8 +44,8 @@ pub fn build(b: *Builder) !void {
const run_step = b.step("run", "Run the app"); const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step); run_step.dependOn(&run_cmd.step);
var test_step = try tst.addTestStep(b, mode, exe.packages.items); // TODO: Demo for testing is kind of terrible. Proper testing
test_step.dependOn(&version.step); // var test_step = try tst.addTestStep(b, optimize, exe.packages.items);
var codegen: ?*std.build.Step = null; var codegen: ?*std.build.Step = null;
if (target.getOs().tag == .linux and false) { if (target.getOs().tag == .linux and false) {
@ -96,41 +76,5 @@ pub fn build(b: *Builder) !void {
exe.step.dependOn(cg); exe.step.dependOn(cg);
} }
exe.install(); b.installArtifact(exe);
}
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,
};
} }

11
build.zig.zon Normal file
View File

@ -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",
},
},
}