fix: use prebuilt artifact from published lib
This commit is contained in:
parent
8240207e7b
commit
7444a51dec
4 changed files with 35 additions and 63 deletions
29
build.zig
29
build.zig
|
|
@ -20,6 +20,9 @@ pub fn build(b: *std.Build) !void {
|
||||||
});
|
});
|
||||||
mod.addIncludePath(temporal_rs_git.path("temporal_capi/bindings/c"));
|
mod.addIncludePath(temporal_rs_git.path("temporal_capi/bindings/c"));
|
||||||
|
|
||||||
|
// -- Pre-built library support for temporal_capi --- //
|
||||||
|
const libtemporal = b.lazyDependency("libtemporal", .{});
|
||||||
|
|
||||||
// --- Rust C ABI: Library --- //
|
// --- Rust C ABI: Library --- //
|
||||||
{
|
{
|
||||||
// Determine target triple string for pre-built library lookup
|
// Determine target triple string for pre-built library lookup
|
||||||
|
|
@ -35,22 +38,26 @@ pub fn build(b: *std.Build) !void {
|
||||||
else
|
else
|
||||||
"libtemporal_capi.a";
|
"libtemporal_capi.a";
|
||||||
|
|
||||||
// Check if pre-built library exists in lib/<target>/
|
// Check if pre-built library exists in downloaded artifact
|
||||||
const prebuilt_lib_path = b.fmt("lib/{s}/{s}", .{ target_triple, lib_name });
|
const prebuilt_lib_path = b.fmt("{s}/{s}", .{ target_triple, lib_name });
|
||||||
const prebuilt_lib_file = b.path(prebuilt_lib_path);
|
|
||||||
|
|
||||||
// Try to use pre-built library if it exists by checking the path object
|
var prebuilt_lib_file: ?std.Build.LazyPath = null;
|
||||||
const use_prebuilt = blk: {
|
if (libtemporal) |dep| {
|
||||||
const lib_full_path = prebuilt_lib_file.getPath(b);
|
const lib_file_candidate = dep.path(prebuilt_lib_path);
|
||||||
const lib_check_file = std.Io.Dir.cwd().openFile(b.graph.io, lib_full_path, .{}) catch break :blk false;
|
const lib_full_path = lib_file_candidate.getPath(b);
|
||||||
|
if (std.Io.Dir.cwd().openFile(b.graph.io, lib_full_path, .{})) |lib_check_file| {
|
||||||
lib_check_file.close(b.graph.io);
|
lib_check_file.close(b.graph.io);
|
||||||
break :blk true;
|
prebuilt_lib_file = lib_file_candidate;
|
||||||
};
|
} else |_| {}
|
||||||
|
}
|
||||||
|
|
||||||
if (use_prebuilt) {
|
if (prebuilt_lib_file) |lib_file| {
|
||||||
// Use pre-built library (no Rust compiler needed)
|
// Use pre-built library (no Rust compiler needed)
|
||||||
mod.addObjectFile(prebuilt_lib_file);
|
std.debug.print("Using pre-built temporal_capi library from downloaded artifact at: {s}\n", .{prebuilt_lib_path});
|
||||||
|
mod.addObjectFile(lib_file);
|
||||||
} else {
|
} else {
|
||||||
|
std.debug.print("building from source: {s}\n", .{prebuilt_lib_path});
|
||||||
|
|
||||||
// Build from source using the local temporal-rs package
|
// Build from source using the local temporal-rs package
|
||||||
const temporal_rs_local = b.dependency("temporal_rs_local", .{
|
const temporal_rs_local = b.dependency("temporal_rs_local", .{
|
||||||
.target = target,
|
.target = target,
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@
|
||||||
.temporal_rs_local = .{
|
.temporal_rs_local = .{
|
||||||
.path = "pkg/temporal-rs",
|
.path = "pkg/temporal-rs",
|
||||||
},
|
},
|
||||||
|
.libtemporal = .{
|
||||||
|
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.0.1/temporal-rs-libs.tar.gz",
|
||||||
|
.hash = "N-V-__8AAPJZzwPipYB8PoJ0LhTO9ipHbtbXbTfRuSYbJFtD",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
"build.zig",
|
"build.zig",
|
||||||
|
|
|
||||||
|
|
@ -1,56 +1,17 @@
|
||||||
.{
|
.{
|
||||||
// This is the default name used by packages depending on this one. For
|
|
||||||
// example, when a user runs `zig fetch --save <url>`, this field is used
|
|
||||||
// as the key in the `dependencies` table. Although the user can choose a
|
|
||||||
// different name, most users will stick with this provided value.
|
|
||||||
//
|
|
||||||
// It is redundant to include "zig" in this name because it is already
|
|
||||||
// within the Zig package namespace.
|
|
||||||
.name = .temporal_rs,
|
.name = .temporal_rs,
|
||||||
// This is a [Semantic Version](https://semver.org/).
|
|
||||||
// In a future version of Zig it will be used for package deduplication.
|
|
||||||
.version = "0.0.0",
|
.version = "0.0.0",
|
||||||
// Together with name, this represents a globally unique package
|
.fingerprint = 0x4e9d7c35d5fc40c0,
|
||||||
// identifier. This field is generated by the Zig toolchain when the
|
|
||||||
// package is first created, and then *never changes*. This allows
|
|
||||||
// unambiguous detection of one package being an updated version of
|
|
||||||
// another.
|
|
||||||
//
|
|
||||||
// When forking a Zig project, this id should be regenerated (delete the
|
|
||||||
// field and run `zig build`) if the upstream project is still maintained.
|
|
||||||
// Otherwise, the fork is *hostile*, attempting to take control over the
|
|
||||||
// original project's identity. Thus it is recommended to leave the comment
|
|
||||||
// on the following line intact, so that it shows up in code reviews that
|
|
||||||
// modify the field.
|
|
||||||
.fingerprint = 0x4e9d7c35d5fc40c0, // Changing this has security and trust implications.
|
|
||||||
// Tracks the earliest Zig version that the package considers to be a
|
|
||||||
// supported use case.
|
|
||||||
.minimum_zig_version = "0.16.0-dev.2565+684032671",
|
.minimum_zig_version = "0.16.0-dev.2565+684032671",
|
||||||
// This field is optional.
|
|
||||||
// Each dependency must either provide a `url` and `hash`, or a `path`.
|
|
||||||
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
|
|
||||||
// Once all dependencies are fetched, `zig build` no longer requires
|
|
||||||
// internet connectivity.
|
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
.build_crab = .{
|
.build_crab = .{
|
||||||
.url = "git+https://github.com/nurulhudaapon/build.crab?ref=zig-dev#658db72f1695987612e9356c023575ff8dc753a2",
|
.url = "git+https://github.com/nurulhudaapon/build.crab?ref=zig-dev#658db72f1695987612e9356c023575ff8dc753a2",
|
||||||
.hash = "build_crab-0.2.1-U0id__PFAACr0518VaPmWuEJDMJezJhmAsFRY6d49v6e",
|
.hash = "build_crab-0.2.1-U0id__PFAACr0518VaPmWuEJDMJezJhmAsFRY6d49v6e",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Specifies the set of files and directories that are included in this package.
|
|
||||||
// Only files and directories listed here are included in the `hash` that
|
|
||||||
// is computed for this package. Only files listed here will remain on disk
|
|
||||||
// when using the zig package manager. As a rule of thumb, one should list
|
|
||||||
// files required for compilation plus any license(s).
|
|
||||||
// Paths are relative to the build root. Use the empty string (`""`) to refer to
|
|
||||||
// the build root itself.
|
|
||||||
// A directory listed here means that all files within, recursively, are included.
|
|
||||||
.paths = .{
|
.paths = .{
|
||||||
"build.zig",
|
"build.zig",
|
||||||
"build.zig.zon",
|
"build.zig.zon",
|
||||||
"src",
|
"src",
|
||||||
// For example...
|
|
||||||
//"LICENSE",
|
|
||||||
//"README.md",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ pub fn main(init: std.process.Init) !void {
|
||||||
defer env.deinit(allocator);
|
defer env.deinit(allocator);
|
||||||
|
|
||||||
var slowest = SlowTracker.init(allocator, io, 15);
|
var slowest = SlowTracker.init(allocator, io, 15);
|
||||||
defer slowest.deinit();
|
defer slowest.deinit(allocator);
|
||||||
|
|
||||||
var pass: usize = 0;
|
var pass: usize = 0;
|
||||||
var fail: usize = 0;
|
var fail: usize = 0;
|
||||||
|
|
@ -103,7 +103,7 @@ pub fn main(init: std.process.Init) !void {
|
||||||
final_result = t.func();
|
final_result = t.func();
|
||||||
current_test = null;
|
current_test = null;
|
||||||
|
|
||||||
final_ns_taken = slowest.endTiming(scope_name, friendly_name);
|
final_ns_taken = slowest.endTiming(allocator, scope_name, friendly_name);
|
||||||
|
|
||||||
if (std.testing.allocator_instance.deinit() == .leak) {
|
if (std.testing.allocator_instance.deinit() == .leak) {
|
||||||
leak += 1;
|
leak += 1;
|
||||||
|
|
@ -256,8 +256,8 @@ const SlowTracker = struct {
|
||||||
start_ts: std.Io.Timestamp,
|
start_ts: std.Io.Timestamp,
|
||||||
|
|
||||||
fn init(allocator: Allocator, io: std.Io, count: u32) SlowTracker {
|
fn init(allocator: Allocator, io: std.Io, count: u32) SlowTracker {
|
||||||
var slowest = SlowestQueue.init(allocator, {});
|
var slowest = SlowestQueue.empty;
|
||||||
slowest.ensureTotalCapacity(count) catch @panic("OOM");
|
slowest.ensureTotalCapacity(allocator, count) catch @panic("OOM");
|
||||||
return .{
|
return .{
|
||||||
.max = count,
|
.max = count,
|
||||||
.io = io,
|
.io = io,
|
||||||
|
|
@ -272,15 +272,15 @@ const SlowTracker = struct {
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn deinit(self: SlowTracker) void {
|
fn deinit(self: SlowTracker, allocator: Allocator) void {
|
||||||
self.slowest.deinit();
|
self.slowest.deinit(allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn startTiming(self: *SlowTracker) void {
|
fn startTiming(self: *SlowTracker) void {
|
||||||
self.start_ts = std.Io.Timestamp.now(self.io, .awake);
|
self.start_ts = std.Io.Timestamp.now(self.io, .awake);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn endTiming(self: *SlowTracker, scope_name: []const u8, test_name: []const u8) u64 {
|
fn endTiming(self: *SlowTracker, allocator: Allocator, scope_name: []const u8, test_name: []const u8) u64 {
|
||||||
const now = std.Io.Timestamp.now(self.io, .awake);
|
const now = std.Io.Timestamp.now(self.io, .awake);
|
||||||
const ns: u64 = @intCast(now.nanoseconds -| self.start_ts.nanoseconds);
|
const ns: u64 = @intCast(now.nanoseconds -| self.start_ts.nanoseconds);
|
||||||
|
|
||||||
|
|
@ -289,7 +289,7 @@ const SlowTracker = struct {
|
||||||
if (slowest.count() < self.max) {
|
if (slowest.count() < self.max) {
|
||||||
// Capacity is fixed to the # of slow tests we want to track
|
// Capacity is fixed to the # of slow tests we want to track
|
||||||
// If we've tracked fewer tests than this capacity, than always add
|
// If we've tracked fewer tests than this capacity, than always add
|
||||||
slowest.add(TestInfo{ .ns = ns, .scope = scope_name, .name = test_name }) catch @panic("failed to track test timing");
|
slowest.push(allocator, TestInfo{ .ns = ns, .scope = scope_name, .name = test_name }) catch @panic("failed to track test timing");
|
||||||
return ns;
|
return ns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -304,8 +304,8 @@ const SlowTracker = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// the previous fastest of our slow tests, has been pushed off.
|
// the previous fastest of our slow tests, has been pushed off.
|
||||||
_ = slowest.removeMin();
|
_ = slowest.popMin();
|
||||||
slowest.add(TestInfo{ .ns = ns, .scope = scope_name, .name = test_name }) catch @panic("failed to track test timing");
|
slowest.push(allocator, TestInfo{ .ns = ns, .scope = scope_name, .name = test_name }) catch @panic("failed to track test timing");
|
||||||
return ns;
|
return ns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -313,7 +313,7 @@ const SlowTracker = struct {
|
||||||
var slowest = self.slowest;
|
var slowest = self.slowest;
|
||||||
const count = slowest.count();
|
const count = slowest.count();
|
||||||
Printer.fmt("\x1b[1mSlowest\x1b[0m \x1b[90m({d})\x1b[0m:\n", .{count});
|
Printer.fmt("\x1b[1mSlowest\x1b[0m \x1b[90m({d})\x1b[0m:\n", .{count});
|
||||||
while (slowest.removeMaxOrNull()) |info| {
|
while (slowest.popMax()) |info| {
|
||||||
const ms = @as(f64, @floatFromInt(info.ns)) / 1_000_000.0;
|
const ms = @as(f64, @floatFromInt(info.ns)) / 1_000_000.0;
|
||||||
if (info.scope.len > 0) {
|
if (info.scope.len > 0) {
|
||||||
Printer.fmt(" {d:.2}ms\t\x1b[90m{s} > {s}\x1b[0m\n", .{ ms, info.scope, info.name });
|
Printer.fmt(" {d:.2}ms\t\x1b[90m{s} > {s}\x1b[0m\n", .{ ms, info.scope, info.name });
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue