Skip to content

Instantly share code, notes, and snippets.

@softprops
Created May 12, 2024 00:14
Show Gist options
  • Save softprops/8061a032f09e5f2de6c3884466fc358b to your computer and use it in GitHub Desktop.
Save softprops/8061a032f09e5f2de6c3884466fc358b to your computer and use it in GitHub Desktop.
in duckdb v0.10.* extensions now require a metadata payload of bytes appended to their binary. if you aren't building with cmake here's a zig program that will do the equiv of https://github.com/duckdb/duckdb/blob/main/scripts/append_metadata.cmake
const std = @import("std");
pub fn main() !void {
var args = std.process.args();
_ = args.next();
const path = args.next() orelse {
bail("expected path argument. this is the path to the file we're appending metadata to");
};
const platform = args.next() orelse {
bail("expected duckdb platform argument. see https://duckdb.org/docs/extensions/working_with_extensions#platforms");
};
const ddbVersion = args.next() orelse {
bail("expected duckdb version argument. this should be set to the version this ext was linked against");
};
const extVersion = args.next() orelse ddbVersion;
std.debug.print(
"\nappending metadata to path {s}\n * platform {s}\n * ddb version {s}\n * ext version {s}\n",
.{
path,
platform,
ddbVersion,
extVersion,
},
);
var payload = std.mem.zeroes([512]u8);
const segments = [_][]const u8{
"", "", "", "",
extVersion, ddbVersion, platform, "4",
};
for (segments, 0..) |segment, i| {
const start = 32 * i;
const end = start + segments[i].len;
@memcpy(payload[start..end], segment);
}
var file = try std.fs.cwd().openFile(path, .{ .mode = .read_write });
try file.seekTo(try file.getEndPos());
try file.writer().writeAll(&payload);
}
fn bail(comptime msg: []const u8) noreturn {
std.debug.print(msg, .{});
std.posix.exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment