refactor: move complexities to pkg
This commit is contained in:
parent
5f0819c5bd
commit
2b5f1a0024
13 changed files with 114 additions and 155 deletions
66
build.zig
66
build.zig
|
|
@ -5,73 +5,21 @@ pub fn build(b: *std.Build) !void {
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
const is_wasm_freestanding = target.result.cpu.arch.isWasm() and target.result.os.tag == .freestanding;
|
const is_wasm_freestanding = target.result.cpu.arch.isWasm() and target.result.os.tag == .freestanding;
|
||||||
|
|
||||||
|
// --- Rust C ABI & Pre-built via temporal-rs subpackage --- //
|
||||||
|
const libtemporal_src = b.dependency("libtemporal_src", .{
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
|
||||||
// --- Zig Module: temporalz --- //
|
// --- Zig Module: temporalz --- //
|
||||||
const mod = b.addModule("temporalz", .{
|
const mod = b.addModule("temporalz", .{
|
||||||
.root_source_file = b.path("src/root.zig"),
|
.root_source_file = b.path("src/root.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
mod.addIncludePath(b.path("src/stubs/c_headers"));
|
|
||||||
|
|
||||||
// --- Rust C ABI: temporal_capi --- //
|
// Use the comprehensive mod from the package
|
||||||
const temporal_rs_git = b.dependency("temporal_rs", .{
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
});
|
|
||||||
mod.addIncludePath(temporal_rs_git.path("temporal_capi/bindings/c"));
|
|
||||||
|
|
||||||
// -- Pre-built library support for temporal_capi --- //
|
|
||||||
const libtemporal_prebuilt = b.lazyDependency("libtemporal_prebuilt", .{});
|
|
||||||
|
|
||||||
// --- Rust C ABI: Library --- //
|
|
||||||
{
|
|
||||||
// Determine target triple string for pre-built library lookup
|
|
||||||
const arch_str = @tagName(target.result.cpu.arch);
|
|
||||||
const os_str = @tagName(target.result.os.tag);
|
|
||||||
const abi = target.result.abi;
|
|
||||||
const target_triple = if (abi == .none)
|
|
||||||
b.fmt("{s}-{s}", .{ arch_str, os_str })
|
|
||||||
else
|
|
||||||
b.fmt("{s}-{s}-{s}", .{ arch_str, os_str, @tagName(abi) });
|
|
||||||
const lib_name = if (target.result.os.tag == .windows and abi == .msvc)
|
|
||||||
"temporal_capi.lib"
|
|
||||||
else
|
|
||||||
"libtemporal_capi.a";
|
|
||||||
|
|
||||||
// Check if pre-built library exists in downloaded artifact
|
|
||||||
const prebuilt_lib_path = b.fmt("{s}/{s}", .{ target_triple, lib_name });
|
|
||||||
|
|
||||||
var prebuilt_lib_file: ?std.Build.LazyPath = null;
|
|
||||||
if (libtemporal_prebuilt) |dep| {
|
|
||||||
const lib_file_candidate = dep.path(prebuilt_lib_path);
|
|
||||||
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);
|
|
||||||
prebuilt_lib_file = lib_file_candidate;
|
|
||||||
} else |_| {}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prebuilt_lib_file) |lib_file| {
|
|
||||||
// Use pre-built library (no Rust compiler needed)
|
|
||||||
mod.addObjectFile(lib_file);
|
|
||||||
} else {
|
|
||||||
// Build from source using the local temporal-rs package
|
|
||||||
const libtemporal_src = b.dependency("libtemporal_src", .{
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
});
|
|
||||||
mod.addImport("temporal_rs", libtemporal_src.module("temporal_rs"));
|
mod.addImport("temporal_rs", libtemporal_src.module("temporal_rs"));
|
||||||
}
|
|
||||||
|
|
||||||
// --- Rust Misc Deps --- //
|
|
||||||
if (target.result.os.tag == .windows) mod.linkSystemLibrary("userenv", .{});
|
|
||||||
const unwind_stubs = b.addLibrary(.{ .linkage = .static, .name = "unwind_stubs", .root_module = b.createModule(.{
|
|
||||||
.root_source_file = b.path("src/stubs/unwind.zig"),
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
}) });
|
|
||||||
mod.linkLibrary(unwind_stubs);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Zig Executable: temporalz --- //
|
// --- Zig Executable: temporalz --- //
|
||||||
const exe_root = if (is_wasm_freestanding)
|
const exe_root = if (is_wasm_freestanding)
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,9 @@
|
||||||
.fingerprint = 0xd8d79d59acc4faae,
|
.fingerprint = 0xd8d79d59acc4faae,
|
||||||
.minimum_zig_version = "0.16.0-dev.2860+9c5460316",
|
.minimum_zig_version = "0.16.0-dev.2860+9c5460316",
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
.temporal_rs = .{
|
|
||||||
.url = "git+https://github.com/boa-dev/temporal#v0.1.2",
|
|
||||||
.hash = "N-V-__8AANlkNAB77Z946lqp-lgp2qSsOBDADValZC86PhB-",
|
|
||||||
},
|
|
||||||
.libtemporal_src = .{
|
.libtemporal_src = .{
|
||||||
.path = "pkg/temporal-rs",
|
.path = "pkg/temporal-rs",
|
||||||
},
|
},
|
||||||
.libtemporal_prebuilt = .{
|
|
||||||
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.1.2/temporal-rs-libs.tar.gz",
|
|
||||||
.hash = "N-V-__8AALzG2AXNSf7E7iuZWx7SrTN0PICWYwnu2kIDlf-w",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
"build.zig",
|
"build.zig",
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,44 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const build_crab = @import("build_crab");
|
|
||||||
|
|
||||||
pub fn build(b: *std.Build) !void {
|
pub fn build(b: *std.Build) !void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
// --- Rust Crate Build --- //
|
const arch_str = @tagName(target.result.cpu.arch);
|
||||||
|
const os_str = @tagName(target.result.os.tag);
|
||||||
|
const abi = target.result.abi;
|
||||||
|
const target_triple = if (abi == .none)
|
||||||
|
b.fmt("{s}-{s}", .{ arch_str, os_str })
|
||||||
|
else
|
||||||
|
b.fmt("{s}-{s}-{s}", .{ arch_str, os_str, @tagName(abi) });
|
||||||
|
|
||||||
|
const lib_name = if (target.result.os.tag == .windows and abi == .msvc)
|
||||||
|
"temporal_capi.lib"
|
||||||
|
else
|
||||||
|
"libtemporal_capi.a";
|
||||||
|
|
||||||
|
const prebuilt_lib_path = b.fmt("{s}/{s}", .{ target_triple, lib_name });
|
||||||
|
|
||||||
|
// --- Pre-built resolution --- //
|
||||||
|
const libtemporal_prebuilt = b.lazyDependency("libtemporal_prebuilt", .{});
|
||||||
|
var prebuilt_lib_file: ?std.Build.LazyPath = null;
|
||||||
|
|
||||||
|
if (libtemporal_prebuilt) |dep| {
|
||||||
|
const lib_file_candidate = dep.path(prebuilt_lib_path);
|
||||||
|
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);
|
||||||
|
prebuilt_lib_file = lib_file_candidate;
|
||||||
|
} else |_| {}
|
||||||
|
}
|
||||||
|
|
||||||
|
var selected_lib_file: std.Build.LazyPath = undefined;
|
||||||
|
if (prebuilt_lib_file) |lib_file| {
|
||||||
|
// std.debug.print("Using pre-built temporal_capi library from downloaded artifact at: {s}\n", .{prebuilt_lib_path});
|
||||||
|
selected_lib_file = lib_file;
|
||||||
|
} else {
|
||||||
|
// std.debug.print("building from source: {s}\n", .{prebuilt_lib_path});
|
||||||
|
const build_crab = @import("build_crab");
|
||||||
const build_dir = build_crab.addCargoBuild(
|
const build_dir = build_crab.addCargoBuild(
|
||||||
b,
|
b,
|
||||||
.{
|
.{
|
||||||
|
|
@ -17,25 +50,12 @@ pub fn build(b: *std.Build) !void {
|
||||||
.optimize = .ReleaseSafe,
|
.optimize = .ReleaseSafe,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
selected_lib_file = build_dir.path(b, lib_name);
|
||||||
const lib_name = if (target.result.os.tag == .windows and target.result.abi == .msvc)
|
|
||||||
"temporal_capi.lib"
|
|
||||||
else
|
|
||||||
"libtemporal_capi.a";
|
|
||||||
|
|
||||||
const lib_file = build_dir.path(b, lib_name);
|
|
||||||
|
|
||||||
// --- Install Step (for publishing) --- //
|
// --- Install Step (for publishing) --- //
|
||||||
const arch_str = @tagName(target.result.cpu.arch);
|
const install_lib = b.addInstallFile(selected_lib_file, b.fmt("lib/{s}/{s}", .{ target_triple, lib_name }));
|
||||||
const os_str = @tagName(target.result.os.tag);
|
|
||||||
const abi = target.result.abi;
|
|
||||||
const target_triple = if (abi == .none)
|
|
||||||
b.fmt("{s}-{s}", .{ arch_str, os_str })
|
|
||||||
else
|
|
||||||
b.fmt("{s}-{s}-{s}", .{ arch_str, os_str, @tagName(abi) });
|
|
||||||
|
|
||||||
const install_lib = b.addInstallFile(lib_file, b.fmt("lib/{s}/{s}", .{ target_triple, lib_name }));
|
|
||||||
b.getInstallStep().dependOn(&install_lib.step);
|
b.getInstallStep().dependOn(&install_lib.step);
|
||||||
|
}
|
||||||
|
|
||||||
// --- Zig Module --- //
|
// --- Zig Module --- //
|
||||||
const mod = b.addModule("temporal_rs", .{
|
const mod = b.addModule("temporal_rs", .{
|
||||||
|
|
@ -43,48 +63,24 @@ pub fn build(b: *std.Build) !void {
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
mod.addObjectFile(lib_file);
|
|
||||||
|
|
||||||
// --- Steps: Build all platforms --- //
|
// Add Headers
|
||||||
{
|
const temporal_rs_git = b.dependency("temporal_rs", .{
|
||||||
const build_lib_step = b.step("lib", "Build libraries for all common platforms");
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
mod.addIncludePath(temporal_rs_git.path("temporal_capi/bindings/c"));
|
||||||
|
mod.addIncludePath(b.path("src/stubs/c_headers"));
|
||||||
|
|
||||||
inline for (platforms) |p| {
|
// Add Object/Library
|
||||||
const query = try std.Build.parseTargetQuery(.{ .arch_os_abi = p });
|
mod.addObjectFile(selected_lib_file);
|
||||||
const platform_target = b.resolveTargetQuery(query);
|
|
||||||
|
|
||||||
const platform_build_dir = build_crab.addCargoBuild(
|
// --- Rust Misc Deps --- //
|
||||||
b,
|
if (target.result.os.tag == .windows) mod.linkSystemLibrary("userenv", .{});
|
||||||
.{
|
const unwind_stubs = b.addLibrary(.{ .linkage = .static, .name = "unwind_stubs", .root_module = b.createModule(.{
|
||||||
.manifest_path = b.path("Cargo.toml"),
|
.root_source_file = b.path("src/stubs/unwind.zig"),
|
||||||
.cargo_args = &.{"--release"},
|
.target = target,
|
||||||
},
|
.optimize = optimize,
|
||||||
.{
|
}) });
|
||||||
.target = platform_target,
|
mod.linkLibrary(unwind_stubs);
|
||||||
.optimize = .ReleaseSafe,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const platform_lib_name = if (platform_target.result.os.tag == .windows and platform_target.result.abi == .msvc)
|
|
||||||
"temporal_capi.lib"
|
|
||||||
else
|
|
||||||
"libtemporal_capi.a";
|
|
||||||
|
|
||||||
const install_platform_lib = b.addInstallFile(
|
|
||||||
platform_build_dir.path(b, platform_lib_name),
|
|
||||||
b.fmt("lib/{s}/{s}", .{ p, platform_lib_name }),
|
|
||||||
);
|
|
||||||
build_lib_step.dependOn(&install_platform_lib.step);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const platforms = [_][]const u8{
|
|
||||||
"aarch64-macos",
|
|
||||||
"x86_64-macos",
|
|
||||||
"aarch64-linux-gnu",
|
|
||||||
"x86_64-linux-gnu",
|
|
||||||
"x86_64-windows-gnu",
|
|
||||||
"aarch64-windows-gnu",
|
|
||||||
"wasm32-freestanding",
|
|
||||||
};
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,14 @@
|
||||||
.fingerprint = 0x4e9d7c35d5fc40c0,
|
.fingerprint = 0x4e9d7c35d5fc40c0,
|
||||||
.minimum_zig_version = "0.16.0-dev.2565+684032671",
|
.minimum_zig_version = "0.16.0-dev.2565+684032671",
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
|
.temporal_rs = .{
|
||||||
|
.url = "git+https://github.com/boa-dev/temporal#v0.1.2",
|
||||||
|
.hash = "N-V-__8AANlkNAB77Z946lqp-lgp2qSsOBDADValZC86PhB-",
|
||||||
|
},
|
||||||
|
.libtemporal_prebuilt = .{
|
||||||
|
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.1.2/temporal-rs-libs.tar.gz",
|
||||||
|
.hash = "N-V-__8AALzG2AXNSf7E7iuZWx7SrTN0PICWYwnu2kIDlf-w",
|
||||||
|
},
|
||||||
.build_crab = .{
|
.build_crab = .{
|
||||||
.url = "git+https://github.com/nurulhudaapon/build.crab?ref=zig-dev#1aabc836472d318e9756a43b17853aadc4599800",
|
.url = "git+https://github.com/nurulhudaapon/build.crab?ref=zig-dev#1aabc836472d318e9756a43b17853aadc4599800",
|
||||||
.hash = "build_crab-0.2.1-U0id_2LFAABPaq1t9eBZ3p0aA87c-HkKZPYCrCVcgvt6",
|
.hash = "build_crab-0.2.1-U0id_2LFAABPaq1t9eBZ3p0aA87c-HkKZPYCrCVcgvt6",
|
||||||
|
|
|
||||||
|
|
@ -1 +1,20 @@
|
||||||
// Empty root file for zig module
|
pub const c = @cImport({
|
||||||
|
@cInclude("AnyCalendarKind.h");
|
||||||
|
@cInclude("Calendar.h");
|
||||||
|
@cInclude("Duration.h");
|
||||||
|
@cInclude("ErrorKind.h");
|
||||||
|
@cInclude("I128Nanoseconds.h");
|
||||||
|
@cInclude("Instant.h");
|
||||||
|
@cInclude("OwnedRelativeTo.h");
|
||||||
|
@cInclude("ParsedDate.h");
|
||||||
|
@cInclude("ParsedDateTime.h");
|
||||||
|
@cInclude("ParsedZonedDateTime.h");
|
||||||
|
@cInclude("PlainDate.h");
|
||||||
|
@cInclude("PlainDateTime.h");
|
||||||
|
@cInclude("PlainMonthDay.h");
|
||||||
|
@cInclude("PlainTime.h");
|
||||||
|
@cInclude("PlainYearMonth.h");
|
||||||
|
@cInclude("RelativeTo.h");
|
||||||
|
@cInclude("TimeZone.h");
|
||||||
|
@cInclude("ZonedDateTime.h");
|
||||||
|
});
|
||||||
|
|
|
||||||
21
src/abi.zig
21
src/abi.zig
|
|
@ -1,25 +1,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub const c = @cImport({
|
pub const c = @import("temporal_rs").c;
|
||||||
@cInclude("AnyCalendarKind.h");
|
|
||||||
@cInclude("Calendar.h");
|
|
||||||
@cInclude("Duration.h");
|
|
||||||
@cInclude("ErrorKind.h");
|
|
||||||
@cInclude("I128Nanoseconds.h");
|
|
||||||
@cInclude("Instant.h");
|
|
||||||
@cInclude("OwnedRelativeTo.h");
|
|
||||||
@cInclude("ParsedDate.h");
|
|
||||||
@cInclude("ParsedDateTime.h");
|
|
||||||
@cInclude("ParsedZonedDateTime.h");
|
|
||||||
@cInclude("PlainDate.h");
|
|
||||||
@cInclude("PlainDateTime.h");
|
|
||||||
@cInclude("PlainMonthDay.h");
|
|
||||||
@cInclude("PlainTime.h");
|
|
||||||
@cInclude("PlainYearMonth.h");
|
|
||||||
@cInclude("RelativeTo.h");
|
|
||||||
@cInclude("TimeZone.h");
|
|
||||||
@cInclude("ZonedDateTime.h");
|
|
||||||
});
|
|
||||||
|
|
||||||
pub const to_string_rounding_options_auto: c.ToStringRoundingOptions = .{
|
pub const to_string_rounding_options_auto: c.ToStringRoundingOptions = .{
|
||||||
.precision = .{ .is_minute = false, .precision = toOption(c.OptionU8, null) },
|
.precision = .{ .is_minute = false, .precision = toOption(c.OptionU8, null) },
|
||||||
|
|
|
||||||
15
update_zon.js
Normal file
15
update_zon.js
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const app_zon = fs.readFileSync('build.zig.zon', 'utf8');
|
||||||
|
function extractDep(name) {
|
||||||
|
const regex = new RegExp(`\\.${name}\\s*=\\s*\\{([\\s\\S]*?)\\},`);
|
||||||
|
return app_zon.match(regex)[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
const p1 = extractDep('temporal_rs');
|
||||||
|
const p2 = extractDep('libtemporal_prebuilt');
|
||||||
|
|
||||||
|
const pkg_zon = fs.readFileSync('pkg/temporal-rs/build.zig.zon', 'utf8');
|
||||||
|
const new_pkg_zon = pkg_zon.replace(' .dependencies = .{', ` .dependencies = .{\n ${p1}\n ${p2}`);
|
||||||
|
|
||||||
|
fs.writeFileSync('pkg/temporal-rs/build.zig.zon', new_pkg_zon);
|
||||||
Loading…
Add table
Reference in a new issue