Skip to content

Commit

Permalink
build: NixOS
Browse files Browse the repository at this point in the history
  • Loading branch information
fleimgruber committed Sep 28, 2024
1 parent 156119a commit a053cd5
Show file tree
Hide file tree
Showing 7 changed files with 499 additions and 1 deletion.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.zig-cache
.direnv

*.[do]
/*.pb-c.[ch]
/sigbak
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ PKG_LDFLAGS!= ${PKG_CONFIG} --libs ${PKGS}

CFLAGS+= ${PKG_CFLAGS}
LDFLAGS+= ${PKG_LDFLAGS}
DBGCFLAGS = -g -O0 -DDEBUG

PROTOS= backup.proto database.proto
PROTO_HDRS= ${PROTOS:.proto=.pb-c.h}
Expand All @@ -44,7 +45,7 @@ OBJS= cmd-check-backup.o cmd-dump-backup.o cmd-export-attachments.o \
.SUFFIXES: .c .pb-c.o .o .pb-c.c .pb-c.h .proto

.c.o .pb-c.c.pb-c.o:
${CC} ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
${CC} ${CFLAGS} ${CPPFLAGS} ${DBGCFLAGS} -c -o $@ $<

.proto.pb-c.c .proto.pb-c.h:
${PROTOC} --c_out=. $<
Expand Down
109 changes: 109 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const std = @import("std");

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const version = std.SemanticVersion{ .major = 0, .minor = 1, .patch = 0 };

var flags = std.BoundedArray([]const u8, 16){};
flags.appendSliceAssumeCapacity(&EXE_FLAGS);

const protocc_run = b.addSystemCommand(&.{"protoc-c"});
protocc_run.addArgs(&.{"--c_out=."});
protocc_run.addArgs(&PROTO_SOURCES);

const sigbak_exe = b.addExecutable(.{
.name = "sigbak",
.target = target,
.version = version,
.optimize = optimize,
});
sigbak_exe.addCSourceFiles(.{
.files = &EXE_SOURCES,
.flags = flags.constSlice(),
});
sigbak_exe.addCSourceFiles(.{
.files = &COMPAT_SOURCES,
.flags = flags.constSlice(),
});
sigbak_exe.addCSourceFiles(.{
.files = &PROTO_GENERATED_SOURCES,
.flags = flags.constSlice(),
});
sigbak_exe.linkSystemLibrary("libcrypto");
sigbak_exe.linkSystemLibrary("libprotobuf-c");
sigbak_exe.linkSystemLibrary("sqlite3");
sigbak_exe.linkLibC();

sigbak_exe.step.dependOn(&protocc_run.step);

b.installArtifact(sigbak_exe);

const run_cmd = b.addRunArtifact(sigbak_exe);

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);
}

const EXE_FLAGS = .{
"-I.",
"-Icompat",
};

const EXE_SOURCES = .{
"cmd-check-backup.c",
"cmd-dump-backup.c",
"cmd-export-attachments.c",
"cmd-export-avatars.c",
"cmd-export-database.c",
"cmd-export-messages.c",
"mime.c",
"sbk-attachment-tree.c",
"sbk-attachment.c",
"sbk-database.c",
"sbk-edit.c",
"sbk-file.c",
"sbk-frame.c",
"sbk-mention.c",
"sbk-message.c",
"sbk-open.c",
"sbk-quote.c",
"sbk-reaction.c",
"sbk-read.c",
"sbk-recipient-tree.c",
"sbk-recipient.c",
"sbk-sqlite.c",
"sbk-thread.c",
"sigbak.c",
};

const PROTO_SOURCES = .{
"backup.proto",
"database.proto",
};

const PROTO_GENERATED_SOURCES = .{
"backup.pb-c.c",
"database.pb-c.c",
};

const COMPAT_SOURCES = .{
"compat/asprintf.c",
"compat/bs_cbb.c",
"compat/err.c",
"compat/explicit_bzero.c",
"compat/fopen.c",
"compat/getprogname.c",
"compat/hkdf.c",
"compat/hmac_ctx_new.c",
"compat/pledge.c",
"compat/readpassphrase.c",
"compat/reallocarray.c",
"compat/unveil.c",
};
18 changes: 18 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.{
.name = "sigbak",
.version = "0.1.0",
.minimum_zig_version = "0.13.0",
.dependencies = .{
.sigbak = .{
.url = "https://github.com/tbvdm/sigbak/archive/39cdd9199cbd59b0ac54f30352b800bf990a96c3.tar.gz",
.hash = "12209c916f60bf396c4e2dda50993974ef3ac7b79a2c0fae0238b3f8dd84ecc70709",
},
},
.paths = .{
"FailStep.zig",
"build.zig",
"build.zig.zon",
"LICENSE",
"README.md",
},
}
Loading

0 comments on commit a053cd5

Please sign in to comment.