Compare commits

..

14 commits
v0.2.4 ... main

Author SHA1 Message Date
Nurul Huda (Apon)
06ce040347
refactor: cleanup to have single entrypoints 2026-07-16 15:01:12 +06:00
Nurul Huda (Apon)
126777caea
chore: remove test262 link from readme 2026-07-16 12:51:57 +06:00
Nurul Huda (Apon)
b4b0aac7da
fix: missed linking libc 2026-07-16 07:07:12 +06:00
Nurul Huda (Apon)
5b3cacdb3b
fix: link libc in test 2026-07-16 07:01:19 +06:00
Nurul Huda (Apon)
e63cc5ba5a
ci: add more deps paths 2026-07-16 06:55:24 +06:00
Nurul Huda (Apon)
599dd9e224
fix: make build-rust false by default 2026-07-16 06:54:24 +06:00
Nurul Huda (Apon)
133b2be3fc
refactor: mv example to test 2026-07-16 06:46:07 +06:00
Nurul Huda (Apon)
37c8ac5b2e
chore: sync version 2026-07-16 06:18:36 +06:00
Nurul Huda (Apon)
25282ad6af
ci: run example from example dir 2026-07-16 04:55:59 +06:00
Nurul Huda (Apon)
40b6332499
ci: rm exe verification 2026-07-16 04:52:01 +06:00
Nurul Huda (Apon)
aab32053ae
ci: update paths 2026-07-16 04:49:13 +06:00
Nurul Huda (Apon)
f58d2efda7
ci: rm upload and download of artifacts 2026-07-16 04:47:52 +06:00
Nurul Huda (Apon)
19525f12a1
ci: rm build requirment for running test 2026-07-16 04:42:34 +06:00
Nurul Huda (Apon)
65cfa18d63
refactor: use isolated package per targets 2026-07-16 04:33:16 +06:00
17 changed files with 329 additions and 471 deletions

View file

@ -184,7 +184,7 @@ jobs:
run: | run: |
cd lib cd lib
mkdir -p dist mkdir -p dist
tar -czf "dist/${{ matrix.target }}.tar.gz" -C zig-out/lib . tar -czf "dist/${{ matrix.target }}.tar.gz" -C "zig-out/lib/${{ matrix.target }}" .
- name: Upload Artifact - name: Upload Artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4

View file

@ -3,6 +3,14 @@ name: CI
on: on:
push: push:
branches: [main] branches: [main]
paths:
- 'src/**'
- 'lib/**'
- 'test/**'
- 'build.zig'
- 'build.zig.zon'
- '.github/workflows/ci.yml'
pull_request: pull_request:
branches: [main] branches: [main]
@ -13,7 +21,6 @@ jobs:
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-latest]
# os: [ubuntu-latest, macos-latest]
steps: steps:
- name: Checkout code - name: Checkout code
@ -24,29 +31,15 @@ jobs:
with: with:
version: 0.17.0-dev.1398+cb5635714 version: 0.17.0-dev.1398+cb5635714
- name: Build project - name: Build and run project
run: zig build run: cd test && zig build run
- name: Verify executable
run: |
./zig-out/bin/zx --help || echo "Executable built successfully"
shell: bash
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: temporalz-${{ matrix.os }}
path: zig-out/
retention-days: 1
test: test:
name: Test (${{ matrix.os }}) name: Test (${{ matrix.os }})
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
needs: build
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-latest]
# os: [ubuntu-latest, macos-latest]
steps: steps:
- name: Checkout code - name: Checkout code
@ -57,15 +50,5 @@ jobs:
with: with:
version: 0.17.0-dev.1398+cb5635714 version: 0.17.0-dev.1398+cb5635714
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: temporalz-${{ matrix.os }}
path: zig-out/
- name: Make executable (Unix)
if: runner.os != 'Windows'
run: chmod +x zig-out/bin/temporalz
- name: Run tests - name: Run tests
run: zig build test run: zig build test

View file

@ -4,6 +4,10 @@ on:
push: push:
branches: branches:
- main - main
paths:
- 'src/**'
- 'lib/**'
- '.github/workflows/docs.yml'
workflow_dispatch: workflow_dispatch:

View file

@ -34,7 +34,7 @@ const exe = b.addExecutable(.{...});
exe.root_module.addImport("temporalz", temporalz.module("temporalz")); exe.root_module.addImport("temporalz", temporalz.module("temporalz"));
``` ```
## Checklist ([Test262](https://github.com/tc39/test262/tree/main/test/built-ins/Temporal)) ## Checklist
| Namespace | Status | | Namespace | Status |
| -------------- | ------ | | -------------- | ------ |
@ -51,18 +51,14 @@ exe.root_module.addImport("temporalz", temporalz.module("temporalz"));
Prebuilt libraries are included for the following platforms: Prebuilt libraries are included for the following platforms:
- `x86_64-macos` - `x86_64-macos`, `aarch64-macos`
- `aarch64-macos` - `x86_64-linux-gnu`, `aarch64-linux-gnu`, `x86-linux-gnu`, `arm-linux-gnueabihf`
- `x86_64-linux-gnu` - `loongarch64-linux-gnu`, `powerpc64le-linux-gnu`, `riscv64-linux-gnu`, `s390x-linux-gnu`
- `aarch64-linux-gnu` - `x86_64-windows-gnu`, `aarch64-windows-gnu`, `x86-windows-gnu`
- `x86_64-windows-gnu` - `x86_64-freebsd`, `x86_64-netbsd`
- `aarch64-windows-gnu` - `wasm32-freestanding`, `wasm32-wasi`
- `wasm32-freestanding` - `x86_64-linux-musl`, `aarch64-linux-musl`
- `wasm32-wasi` - `aarch64-linux-android`, `aarch64-ios`
- `x86_64-linux-musl`
- `aarch64-linux-musl`
- `aarch64-linux-android`
- `aarch64-ios`
For other platforms, the library will build from source; you need the Rust toolchain installed. For other platforms, the library will build from source; you need the Rust toolchain installed.

View file

@ -3,17 +3,16 @@ const std = @import("std");
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(.{});
const is_freestanding = target.result.os.tag == .freestanding;
const force_build_rust = b.option(bool, "build-rust", "Always build Rust library from source") orelse false;
// --- Rust C ABI & Pre-built via temporal-rs subpackage --- // // --- Rust C ABI & Pre-built via temporal-rs subpackage --- //
const build_rust = b.option(bool, "build-rust", "Build Rust library from source") orelse false;
const libtemporal = b.dependency("libtemporal", .{ const libtemporal = b.dependency("libtemporal", .{
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
.@"build-rust" = force_build_rust, .@"build-rust" = build_rust,
}); });
// --- Zig Module: temporalz --- // // --- 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,
@ -21,40 +20,21 @@ pub fn build(b: *std.Build) !void {
}); });
mod.addImport("libtemporal", libtemporal.module("libtemporal")); mod.addImport("libtemporal", libtemporal.module("libtemporal"));
// --- Zig Executable: temporalz --- // // --- Step: run --- //
const exe = b.addExecutable(.{
.name = "temporalz",
.root_module = b.createModule(.{
.root_source_file = if (is_freestanding)
b.path("example/src/wasm.zig")
else
b.path("example/src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "temporalz", .module = mod },
},
}),
});
exe.root_module.link_libc = !is_freestanding;
exe.rdynamic = is_freestanding;
b.installArtifact(exe);
// --- Steps: Run --- //
{ {
const run_step = b.step("run", "Run the example project"); const run_step = b.step("run", "Run the test project");
const run_cmd = b.addSystemCommand(&.{ const run_cmd = b.addSystemCommand(&.{
b.graph.zig_exe, b.graph.zig_exe,
"build", "build",
"run", "run",
b.fmt("-Dtarget={s}", .{try target.result.zigTriple(b.allocator)}), b.fmt("-Dtarget={s}", .{try target.result.zigTriple(b.allocator)}),
}); });
run_cmd.setCwd(b.path("example")); run_cmd.setCwd(b.path("test"));
run_cmd.addPassthruArgs(); run_cmd.addPassthruArgs();
run_step.dependOn(&run_cmd.step); run_step.dependOn(&run_cmd.step);
} }
// --- Steps: Docs --- // // --- Step: docs --- //
{ {
const docs_step = b.step("docs", "Build the temporalz docs"); const docs_step = b.step("docs", "Build the temporalz docs");
const docs_obj = b.addObject(.{ .name = "temporalz", .root_module = mod }); const docs_obj = b.addObject(.{ .name = "temporalz", .root_module = mod });
@ -67,7 +47,7 @@ pub fn build(b: *std.Build) !void {
}).step); }).step);
} }
// --- Steps: Test --- // // --- Step: test --- //
{ {
const test_step = b.step("test", "Run tests"); const test_step = b.step("test", "Run tests");
const mod_tests = b.addTest(.{ const mod_tests = b.addTest(.{
@ -77,20 +57,7 @@ pub fn build(b: *std.Build) !void {
.mode = .simple, .mode = .simple,
}, },
}); });
mod_tests.root_module.link_libc = !is_freestanding; mod_tests.root_module.link_libc = target.result.os.tag != .freestanding;
test_step.dependOn(&b.addRunArtifact(mod_tests).step); test_step.dependOn(&b.addRunArtifact(mod_tests).step);
if (!is_freestanding) {
const exe_tests = b.addTest(.{ .root_module = exe.root_module });
test_step.dependOn(&b.addRunArtifact(exe_tests).step);
}
}
// --- Steps: test-262 --- //
{
const test262_step = b.step("test262", "Run test-262 tests");
const run_cmd = b.addSystemCommand(&.{ "node", "test/test262/runner.mjs" });
run_cmd.addPassthruArgs();
run_cmd.step.dependOn(b.getInstallStep());
test262_step.dependOn(&run_cmd.step);
} }
} }

View file

@ -1,6 +1,6 @@
.{ .{
.name = .temporalz, .name = .temporalz,
.version = "0.2.0", .version = "0.2.4",
.fingerprint = 0xd8d79d59acc4faae, .fingerprint = 0xd8d79d59acc4faae,
.minimum_zig_version = "0.17.0-dev.1398+cb5635714", .minimum_zig_version = "0.17.0-dev.1398+cb5635714",
.dependencies = .{ .dependencies = .{

View file

@ -1,9 +0,0 @@
const std = @import("std");
const program = @import("root.zig");
pub fn main(init: std.process.Init) !void {
const allocator = init.arena.allocator();
const io = init.io;
try program.run(allocator, io);
}

View file

@ -1,4 +1,5 @@
const std = @import("std"); const std = @import("std");
const targets = @import("targets.zig");
pub fn build(b: *std.Build) !void { pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
@ -12,38 +13,67 @@ pub fn build(b: *std.Build) !void {
b.fmt("{s}-{s}", .{ arch_str, os_str }) b.fmt("{s}-{s}", .{ arch_str, os_str })
else else
b.fmt("{s}-{s}-{s}", .{ arch_str, os_str, @tagName(abi) }); b.fmt("{s}-{s}-{s}", .{ arch_str, os_str, @tagName(abi) });
const prebuilt_name = targets.prebuiltName(b, target);
const lib_name = if (target.result.os.tag == .windows and abi == .msvc) const lib_name = if (target.result.os.tag == .windows and abi == .msvc)
"temporal_capi.lib" "temporal_capi.lib"
else else
"libtemporal_capi.a"; "libtemporal_capi.a";
const prebuilt_lib_path = b.fmt("{s}/{s}", .{ target_triple, lib_name }); // --- Module --- //
const is_freestanding = target.result.os.tag == .freestanding;
const mod = b.addModule("libtemporal", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.link_libc = !is_freestanding,
});
// --- Pre-built resolution --- // const temporal_rs = b.dependency("temporal_rs", .{
var prebuilt_lib_file: ?std.Build.LazyPath = null; .target = target,
var selected_lib_file: std.Build.LazyPath = undefined; .optimize = optimize,
});
if (!force_build_rust) { const translated = b.addTranslateC(.{
const libtemporal_dep = b.lazyDependency("prebuilt_libtemporal", .{}); .root_source_file = b.path("src/lib.h"),
if (libtemporal_dep) |dep| { .target = target,
const lib_file_candidate = dep.path(prebuilt_lib_path); .optimize = optimize,
if (dep.builder.root.access(b.graph.io, prebuilt_lib_path, .{})) { .link_libc = false,
prebuilt_lib_file = lib_file_candidate; });
} else |_| {} translated.addIncludePath(temporal_rs.path("temporal_capi/bindings/c"));
} translated.addIncludePath(b.path("src/stubs/c_headers"));
mod.addImport("lib", translated.createModule());
// --- 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);
// --- Steps: update prebuilt dependency hashes --- //
{
const update_step = b.step("update", "Fetch prebuilt packages and update build.zig.zon");
addPrebuiltDependencyFetches(b, update_step);
} }
if (prebuilt_lib_file) |plf| { // --- Static lib resolution (prebuilt or source) --- //
// std.debug.print("Using pre-built temporal_capi library from downloaded artifact at: {s}\n", .{prebuilt_lib_path}); var selected_lib_file: std.Build.LazyPath = undefined;
selected_lib_file = plf;
if (!force_build_rust and targets.isDeclared(prebuilt_name)) {
const prebuilt_dep = b.lazyDependency(prebuilt_name, .{}) orelse {
return;
};
// std.log.info("using prebuilt libtemporal for {s}", .{prebuilt_name});
selected_lib_file = prebuilt_dep.path(lib_name);
} else { } else {
// std.debug.print("building from source: {s}\n searched for prebuild at: {s}\n", .{ prebuilt_lib_path, prebuilt_lib_path }); std.log.info("building libtemporal from source for {s}, requires Rust toolchain", .{target_triple});
const build_crab = @import("build_crab"); const build_crab = @import("build_crab");
var zig_target = target.result; var zig_target = target.result;
if (zig_target.os.tag == .windows) zig_target.abi = .gnu; if (zig_target.os.tag == .windows) zig_target.abi = .gnu;
// Zig's baseline `.arm` maps to Rust `arm-*`, but rustup ships `armv7-*`.
const rust_target_str: []const u8 = if (zig_target.cpu.arch == .arm and zig_target.os.tag == .linux) const rust_target_str: []const u8 = if (zig_target.cpu.arch == .arm and zig_target.os.tag == .linux)
switch (zig_target.abi) { switch (zig_target.abi) {
.gnueabihf, .eabihf => "armv7-unknown-linux-gnueabihf", .gnueabihf, .eabihf => "armv7-unknown-linux-gnueabihf",
@ -71,39 +101,44 @@ pub fn build(b: *std.Build) !void {
selected_lib_file = build_dir.path(b, lib_name); selected_lib_file = build_dir.path(b, lib_name);
} }
// --- Install Step (for publishing) --- //
const install_lib = b.addInstallFile(selected_lib_file, b.fmt("lib/{s}/{s}", .{ target_triple, lib_name }));
b.getInstallStep().dependOn(&install_lib.step);
// --- Zig Module --- //
const mod = b.addModule("libtemporal", .{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
const temporal_rs = b.dependency("temporal_rs", .{
.target = target,
.optimize = optimize,
});
const translated = b.addTranslateC(.{
.root_source_file = b.path("src/lib.h"),
.target = target,
.optimize = optimize,
.link_libc = false,
});
translated.addIncludePath(temporal_rs.path("temporal_capi/bindings/c"));
translated.addIncludePath(b.path("src/stubs/c_headers"));
mod.addImport("lib", translated.createModule());
mod.addObjectFile(selected_lib_file); mod.addObjectFile(selected_lib_file);
// --- Rust Misc Deps --- // // --- Install Step (for publishing) --- //
if (target.result.os.tag == .windows) mod.linkSystemLibrary("userenv", .{}); const install_lib = b.addInstallFile(selected_lib_file, b.fmt("lib/{s}/{s}", .{ prebuilt_name, lib_name }));
const unwind_stubs = b.addLibrary(.{ .linkage = .static, .name = "unwind_stubs", .root_module = b.createModule(.{ b.getInstallStep().dependOn(&install_lib.step);
.root_source_file = b.path("src/stubs/unwind.zig"), }
.target = target,
.optimize = optimize, fn addPrebuiltDependencyFetches(b: *std.Build, parent: *std.Build.Step) void {
}) }); var prev_save: ?*std.Build.Step = null;
mod.linkLibrary(unwind_stubs);
inline for (targets.config.targets) |target_triple| {
const url = targets.releaseUrl(b, target_triple);
const fetch = b.addSystemCommand(&.{ b.graph.zig_exe, "fetch", url });
fetch.setName(b.fmt("fetch {s}", .{target_triple}));
fetch.setCwd(b.path("."));
fetch.has_side_effects = true;
fetch.expectExitCode(0);
_ = fetch.captureStdErr(.{});
const save = b.addSystemCommand(&.{
b.graph.zig_exe,
"fetch",
b.fmt("--save={s}", .{target_triple}),
url,
});
save.setName(b.fmt("save {s}", .{target_triple}));
save.setCwd(b.path("."));
save.has_side_effects = true;
save.expectExitCode(0);
_ = save.captureStdErr(.{});
save.step.dependOn(&fetch.step);
if (prev_save) |prev| {
save.step.dependOn(prev);
}
parent.dependOn(&save.step);
prev_save = &save.step;
}
} }

View file

@ -1,25 +1,127 @@
.{ .{
.name = .libtemporal, .name = .libtemporal,
.version = "0.2.0", .version = "0.2.4",
.fingerprint = 0xded01f16f20c2a64, .fingerprint = 0xded01f16f20c2a64,
.dependencies = .{ .dependencies = .{
.temporal_rs = .{ .temporal_rs = .{
.url = "git+https://github.com/boa-dev/temporal?ref=v0.2.4#a5cebbcce231552bf6ed985d7ea13b0c7b195f02", .url = "git+https://github.com/boa-dev/temporal?ref=v0.2.4#a5cebbcce231552bf6ed985d7ea13b0c7b195f02",
.hash = "N-V-__8AALjnOQBiCk4NffYgEewZ5v9qlLlDyXO22FIyzNdf", .hash = "N-V-__8AALjnOQBiCk4NffYgEewZ5v9qlLlDyXO22FIyzNdf",
}, },
.prebuilt_libtemporal = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.3/libtemporal.tar.gz",
.hash = "N-V-__8AADYZ_AXnqpmkTa49ZQ6lEQlDXWRLthyxEbgse3Hi",
.lazy = true,
},
.build_crab = .{ .build_crab = .{
.url = "git+https://github.com/nurulhudaapon/build.crab?ref=zig-dev#69a630f8fa9ccca37a8ba2e898e7934e3b5b8fe2", .url = "git+https://github.com/nurulhudaapon/build.crab?ref=zig-dev#69a630f8fa9ccca37a8ba2e898e7934e3b5b8fe2",
.hash = "build_crab-0.2.1-U0id_zfKAAAvOuam-kPYKMuEQpHuEBjrP96uQCVj94yr", .hash = "build_crab-0.2.1-U0id_zfKAAAvOuam-kPYKMuEQpHuEBjrP96uQCVj94yr",
}, },
.@"aarch64-ios" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/aarch64-ios.tar.gz",
.hash = "N-V-__8AAJAyaADZvWvrmaGR5reVCH4y8JZ3-Gfxu_9-pcHB",
.lazy = true,
},
.@"aarch64-linux-android" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/aarch64-linux-android.tar.gz",
.hash = "N-V-__8AAKYEkwCQonhHp5MAYaRE8IFcWN493Y2a5nqWJmF7",
.lazy = true,
},
.@"aarch64-linux-gnu" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/aarch64-linux-gnu.tar.gz",
.hash = "N-V-__8AAGSQjQDYfN0voDb4c1sCM374u570U8hcEJYoAoTc",
.lazy = true,
},
.@"aarch64-linux-musl" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/aarch64-linux-musl.tar.gz",
.hash = "N-V-__8AAE7bjwA2arkXXgbgaMe8oHdmJEez8y2XFeCUvSnn",
.lazy = true,
},
.@"aarch64-macos" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/aarch64-macos.tar.gz",
.hash = "N-V-__8AAFBxZwC9MEuiOD8EihBoSl_00IDUJnpQsjmnpkmK",
.lazy = true,
},
.@"aarch64-windows-gnu" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/aarch64-windows-gnu.tar.gz",
.hash = "N-V-__8AADKDagD1bmYDywq4IZPBo2la8m1xzSObPCsxyfmW",
.lazy = true,
},
.@"arm-linux-gnueabihf" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/arm-linux-gnueabihf.tar.gz",
.hash = "N-V-__8AAIAAfgDYWro4rWudgosfdPK1tzxLe77uoRBtL4rl",
.lazy = true,
},
.@"loongarch64-linux-gnu" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/loongarch64-linux-gnu.tar.gz",
.hash = "N-V-__8AAEKptADVBZFKw7ZKvLurwzp_WA-FD-OwZFgEMf4q",
.lazy = true,
},
.@"powerpc64le-linux-gnu" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/powerpc64le-linux-gnu.tar.gz",
.hash = "N-V-__8AAKwdfQDZIHVuhOtUOs9tKx-RJCM_1HnX-FwGA0l2",
.lazy = true,
},
.@"riscv64-linux-gnu" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/riscv64-linux-gnu.tar.gz",
.hash = "N-V-__8AAPBiogBQe_5VZhzDgpZrfwuzfj_54IyUFK2igsQo",
.lazy = true,
},
.@"s390x-linux-gnu" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/s390x-linux-gnu.tar.gz",
.hash = "N-V-__8AAEiKkwC4qkNJoOuzgxHuS_q46SIbqITuODu9Hz3Q",
.lazy = true,
},
.@"wasm32-freestanding" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/wasm32-freestanding.tar.gz",
.hash = "N-V-__8AACjsTwB3jX1mva0svtTn39kCz5aabikQbczLJlp9",
.lazy = true,
},
.@"wasm32-wasi" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/wasm32-wasi.tar.gz",
.hash = "N-V-__8AAPbTQADoTDaLXmk3KlebN5pZWX-eXhD6BLPJuxpt",
.lazy = true,
},
.@"x86-linux-gnu" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/x86-linux-gnu.tar.gz",
.hash = "N-V-__8AALzUbwBdOV8TmU7vPbofrSgkCz70GG0SwvHZGWEZ",
.lazy = true,
},
.@"x86-windows-gnu" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/x86-windows-gnu.tar.gz",
.hash = "N-V-__8AAAgSYQAjy_QNLkxQurUPnbT8s4fNjunaYgPQjiwB",
.lazy = true,
},
.@"x86_64-freebsd" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/x86_64-freebsd.tar.gz",
.hash = "N-V-__8AAJAFkQCAz3khARx91vZb6HMPqV3oBdmJM8kaxd9Y",
.lazy = true,
},
.@"x86_64-linux-gnu" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/x86_64-linux-gnu.tar.gz",
.hash = "N-V-__8AACAdiQB3WUysJXS42gsJZdpzna_04l6omEQGzJZa",
.lazy = true,
},
.@"x86_64-linux-musl" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/x86_64-linux-musl.tar.gz",
.hash = "N-V-__8AAGhKiwDlW7Ecy5CJf7-PEGSdDgr4VnCNLkl9cery",
.lazy = true,
},
.@"x86_64-macos" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/x86_64-macos.tar.gz",
.hash = "N-V-__8AAHDyZwCPo6HVOYeFWas2bcTqi67vJuxoL2huROlC",
.lazy = true,
},
.@"x86_64-netbsd" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/x86_64-netbsd.tar.gz",
.hash = "N-V-__8AAL7_lgBmD0lfXqzAxRdjDiPLi6bgLvnVVbQszw3p",
.lazy = true,
},
.@"x86_64-windows-gnu" = .{
.url = "https://github.com/nurulhudaapon/temporalz/releases/download/v0.2.4/x86_64-windows-gnu.tar.gz",
.hash = "N-V-__8AAD5eTQDfQ9ddNZh3g8e6SaA9CnVSQRMozhHs_jWt",
.lazy = true,
},
}, },
.paths = .{ .paths = .{
"build.zig", "build.zig",
"build.zig.zon", "build.zig.zon",
"targets.zon",
"targets.zig",
"src", "src",
}, },
} }

57
lib/targets.zig Normal file
View file

@ -0,0 +1,57 @@
const std = @import("std");
const builtin = @import("builtin");
pub const config = @import("targets.zon");
const manifest = @import("build.zig.zon");
/// Zig `-Dtarget` triple for the host platform's prebuilt dependency name.
pub fn depName() []const u8 {
const triple = targetTripleFromBuiltin();
if (!isDeclared(triple)) {
@compileError(std.fmt.comptimePrint(
"no prebuilt libtemporal for host {s}",
.{triple},
));
}
return triple;
}
pub fn prebuiltName(b: *std.Build, target: std.Build.ResolvedTarget) []const u8 {
const arch = @tagName(target.result.cpu.arch);
const os = target.result.os.tag;
const abi = target.result.abi;
if (os == .wasi and (abi == .musl or abi == .none))
return b.fmt("{s}-wasi", .{arch});
if (abi == .none)
return b.fmt("{s}-{s}", .{ arch, @tagName(os) });
return b.fmt("{s}-{s}-{s}", .{ arch, @tagName(os), @tagName(abi) });
}
pub fn isDeclared(target_triple: []const u8) bool {
inline for (config.targets) |supported| {
if (std.mem.eql(u8, supported, target_triple)) {
return comptime @hasField(@TypeOf(manifest.dependencies), supported);
}
}
return false;
}
pub fn releaseUrl(b: *std.Build, target_triple: []const u8) []const u8 {
return b.fmt(
"https://github.com/nurulhudaapon/temporalz/releases/download/v{s}/{s}.tar.gz",
.{ config.version, target_triple },
);
}
fn targetTripleFromBuiltin() []const u8 {
if (builtin.os.tag == .wasi and (builtin.abi == .musl or builtin.abi == .none))
return std.fmt.comptimePrint("{s}-wasi", .{@tagName(builtin.cpu.arch)});
const abi = builtin.abi;
return if (abi == .none)
std.fmt.comptimePrint("{s}-{s}", .{ @tagName(builtin.cpu.arch), @tagName(builtin.os.tag) })
else
std.fmt.comptimePrint("{s}-{s}-{s}", .{ @tagName(builtin.cpu.arch), @tagName(builtin.os.tag), @tagName(abi) });
}

26
lib/targets.zon Normal file
View file

@ -0,0 +1,26 @@
.{
.version = "0.2.4",
.targets = .{
"x86_64-macos",
"aarch64-macos",
"x86_64-linux-gnu",
"aarch64-linux-gnu",
"x86-linux-gnu",
"arm-linux-gnueabihf",
"loongarch64-linux-gnu",
"powerpc64le-linux-gnu",
"riscv64-linux-gnu",
"s390x-linux-gnu",
"x86_64-windows-gnu",
"aarch64-windows-gnu",
"x86-windows-gnu",
"x86_64-freebsd",
"x86_64-netbsd",
"wasm32-freestanding",
"wasm32-wasi",
"x86_64-linux-musl",
"aarch64-linux-musl",
"aarch64-linux-android",
"aarch64-ios",
},
}

View file

@ -1,298 +0,0 @@
Temporal.Duration
Temporal.Instant
Temporal.Now
Temporal.PlainDate
Temporal.PlainDateTime
Temporal.PlainMonthDay
Temporal.PlainTime
Temporal.PlainYearMonth
Temporal.ZonedDateTime
Temporal.Duration
Constructor
Temporal.Duration()
Static methods
compare()
from()
Instance methods
abs()
add()
negated()
round()
subtract()
toJSON()
toLocaleString()
toString()
total()
valueOf()
with()
Instance properties
blank
days
hours
microseconds
milliseconds
minutes
months
nanoseconds
seconds
sign
weeks
years
Temporal.Instant
Constructor
Temporal.Instant()
Experimental
Static methods
compare()
from()
fromEpochMilliseconds()
fromEpochNanoseconds()
Instance methods
add()
equals()
round()
since()
subtract()
toJSON()
toLocaleString()
toString()
toZonedDateTimeISO()
until()
valueOf()
Instance properties
epochMilliseconds
epochNanoseconds
Temporal.Now
Static methods
instant()
plainDateISO()
plainDateTimeISO()
plainTimeISO()
timeZoneId()
zonedDateTimeISO()
Temporal.PlainDate
Constructor
Temporal.PlainDate()
Experimental
Static methods
compare()
from()
Instance methods
add()
equals()
since()
subtract()
toJSON()
toLocaleString()
toPlainDateTime()
toPlainMonthDay()
toPlainYearMonth()
toString()
toZonedDateTime()
until()
valueOf()
with()
withCalendar()
Instance properties
calendarId
day
dayOfWeek
dayOfYear
daysInMonth
daysInWeek
daysInYear
era
eraYear
inLeapYear
month
monthCode
monthsInYear
weekOfYear
year
yearOfWeek
Temporal.PlainDateTime
Constructor
Temporal.PlainDateTime()
Experimental
Static methods
compare()
from()
Instance methods
add()
equals()
round()
since()
subtract()
toJSON()
toLocaleString()
toPlainDate()
toPlainTime()
toString()
toZonedDateTime()
until()
valueOf()
with()
withCalendar()
withPlainTime()
Instance properties
calendarId
day
dayOfWeek
dayOfYear
daysInMonth
daysInWeek
daysInYear
era
eraYear
hour
inLeapYear
microsecond
millisecond
minute
month
monthCode
monthsInYear
nanosecond
second
weekOfYear
year
yearOfWeek
Temporal.PlainMonthDay
Constructor
Temporal.PlainMonthDay()
Experimental
Static methods
from()
Instance methods
equals()
toJSON()
toLocaleString()
toPlainDate()
toString()
valueOf()
with()
Instance properties
calendarId
day
monthCode
Temporal.PlainTime
Constructor
Temporal.PlainTime()
Static methods
compare()
from()
Instance methods
add()
equals()
round()
since()
subtract()
toJSON()
toLocaleString()
toString()
until()
valueOf()
with()
Instance properties
hour
microsecond
millisecond
minute
nanosecond
second
Temporal.PlainYearMonth
Constructor
Temporal.PlainYearMonth()
Experimental
Static methods
compare()
from()
Instance methods
add()
equals()
since()
subtract()
toJSON()
toLocaleString()
toPlainDate()
toString()
until()
valueOf()
with()
Instance properties
calendarId
daysInMonth
daysInYear
era
eraYear
inLeapYear
month
monthCode
monthsInYear
year
Temporal.ZonedDateTime
Constructor
Temporal.ZonedDateTime()
Experimental
Static methods
compare()
from()
Instance methods
add()
equals()
getTimeZoneTransition()
round()
since()
startOfDay()
subtract()
toInstant()
toJSON()
toLocaleString()
toPlainDate()
toPlainDateTime()
toPlainTime()
toString()
until()
valueOf()
with()
withCalendar()
withPlainTime()
withTimeZone()
Instance properties
calendarId
day
dayOfWeek
dayOfYear
daysInMonth
daysInWeek
daysInYear
epochMilliseconds
epochNanoseconds
era
eraYear
hour
hoursInDay
inLeapYear
microsecond
millisecond
minute
month
monthCode
monthsInYear
nanosecond
offset
offsetNanoseconds
second
timeZoneId
weekOfYear
year
yearOfWeek

View file

@ -12,13 +12,16 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "temporalz", .name = "temporalz",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.root_source_file = b.path(if (is_freestanding) "src/wasm.zig" else "src/main.zig"), .root_source_file = b.path("src/main.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
.link_libc = !is_freestanding,
.imports = &.{}, .imports = &.{},
}), }),
}); });
exe.root_module.addImport("temporalz", temporalz.module("temporalz")); exe.root_module.addImport("temporalz", temporalz.module("temporalz"));
exe.rdynamic = is_freestanding;
if (is_freestanding) exe.entry = .disabled;
b.installArtifact(exe); b.installArtifact(exe);
b.enable_wasmtime = true; // This doesn't work since Zig 0.17.0 release b.enable_wasmtime = true; // This doesn't work since Zig 0.17.0 release

View file

@ -1,6 +1,6 @@
.{ .{
.name = .temporalz_example, .name = .temporalz_example,
.version = "0.1.2", .version = "0.0.0",
.fingerprint = 0x686c9dfc777f9593, .fingerprint = 0x686c9dfc777f9593,
.dependencies = .{ .dependencies = .{
.temporalz = .{ .temporalz = .{

View file

@ -1,17 +1,24 @@
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin");
const program = @import("root.zig"); const program = @import("root.zig");
const Temporal = @import("temporalz");
export fn _start() void { const freestanding = builtin.os.tag == .freestanding;
pub fn main(init: Init) !void {
const allocator = std.heap.page_allocator; const allocator = std.heap.page_allocator;
program.run(allocator, null) catch {}; const io = if (freestanding) null else init.io;
try program.run(allocator, io);
} }
extern fn console(ptr: [*]u8, len: u32) void; // -- //
const Init = if (freestanding) std.process.Init.Minimal else std.process.Init;
pub const std_options: std.Options = .{
.logFn = if (freestanding) logFn else std.log.defaultLog,
};
extern fn console(ptr: [*]u8, len: u32) void;
fn logFn(comptime _: anytype, comptime _: anytype, comptime format: []const u8, args: anytype) void { fn logFn(comptime _: anytype, comptime _: anytype, comptime format: []const u8, args: anytype) void {
const formatted = std.fmt.allocPrint(std.heap.wasm_allocator, format, args) catch return; const formatted = std.fmt.allocPrint(std.heap.wasm_allocator, format, args) catch return;
console(formatted.ptr, formatted.len); console(formatted.ptr, formatted.len);
} }
pub const std_options: std.Options = .{ .logFn = logFn };

View file

@ -911,18 +911,3 @@ pub fn runTimeZoneExamples(
}); });
} }
} }
extern fn consoleLog(ptr: [*]u8, len: u32) void;
pub fn logFn(comptime message_level: std.log.Level, comptime scope: @TypeOf(.enum_literal), comptime format: []const u8, args: anytype) void {
if (builtin.os.tag == .freestanding) {
const prefix = if (scope == .default) "" else "(" ++ @tagName(scope) ++ ") ";
const formatted = std.fmt.allocPrint(std.heap.wasm_allocator, prefix ++ format, args) catch return;
consoleLog(formatted.ptr, formatted.len);
}
std.log.defaultLog(message_level, scope, format, args);
}
pub const std_options: std.Options = .{
.logFn = logFn,
};