feat: package static lib (#1)
This commit is contained in:
parent
1e56d28ada
commit
682c51fd03
10 changed files with 285 additions and 80 deletions
110
.github/workflows/pkg-release.yml
vendored
Normal file
110
.github/workflows/pkg-release.yml
vendored
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
name: Release Package Artifacts
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build ${{ matrix.target }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- target: x86_64-macos
|
||||
os: macos-latest
|
||||
rust-target: x86_64-apple-darwin
|
||||
- target: aarch64-macos
|
||||
os: macos-latest
|
||||
rust-target: aarch64-apple-darwin
|
||||
- target: x86_64-linux-gnu
|
||||
os: ubuntu-latest
|
||||
rust-target: x86_64-unknown-linux-gnu
|
||||
- target: aarch64-linux-gnu
|
||||
os: ubuntu-latest
|
||||
rust-target: aarch64-unknown-linux-gnu
|
||||
- target: x86_64-windows-gnu
|
||||
os: ubuntu-latest
|
||||
rust-target: x86_64-pc-windows-gnu
|
||||
- target: aarch64-windows-gnu
|
||||
os: ubuntu-latest
|
||||
rust-target: aarch64-pc-windows-gnu
|
||||
- target: wasm32-freestanding
|
||||
os: ubuntu-latest
|
||||
rust-target: wasm32-unknown-unknown
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Zig
|
||||
uses: mlugg/setup-zig@v2
|
||||
with:
|
||||
version: 0.16.0-dev.2535+b5bd49460
|
||||
|
||||
- name: Setup Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
targets: ${{ matrix.rust-target }}
|
||||
|
||||
- name: Install cross-compilers (Linux-aarch64)
|
||||
if: matrix.target == 'aarch64-linux-gnu'
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y gcc-aarch64-linux-gnu
|
||||
|
||||
- name: Install cross-compilers (Windows-mingw)
|
||||
if: contains(matrix.target, 'windows-gnu')
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y mingw-w64
|
||||
|
||||
- name: Build Package
|
||||
run: |
|
||||
cd pkg/temporal-rs
|
||||
zig build -Dtarget=${{ matrix.target }} -Doptimize=ReleaseSafe
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: lib-${{ matrix.target }}
|
||||
path: pkg/temporal-rs/zig-out/lib/
|
||||
retention-days: 1
|
||||
|
||||
release:
|
||||
name: Create Release
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Download all artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: all-libs
|
||||
pattern: lib-*
|
||||
merge-multiple: true
|
||||
|
||||
- name: Prepare Release Artifact
|
||||
run: |
|
||||
mkdir -p release/lib
|
||||
cp -r all-libs/* release/lib/
|
||||
cd release
|
||||
tar -czf ../temporal-rs-libs.tar.gz lib/
|
||||
zip -r ../temporal-rs-libs.zip lib/
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: |
|
||||
temporal-rs-libs.tar.gz
|
||||
temporal-rs-libs.zip
|
||||
generate_release_notes: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
82
build.zig
82
build.zig
|
|
@ -1,5 +1,4 @@
|
|||
const std = @import("std");
|
||||
const build_crab = @import("build_crab");
|
||||
|
||||
pub fn build(b: *std.Build) !void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
|
|
@ -15,23 +14,22 @@ pub fn build(b: *std.Build) !void {
|
|||
mod.addIncludePath(b.path("src/stubs/c_headers"));
|
||||
|
||||
// --- Rust C ABI: temporal_capi --- //
|
||||
const temporal_rs = b.dependency("temporal_rs", .{
|
||||
const temporal_rs_git = b.dependency("temporal_rs", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
mod.addIncludePath(temporal_rs.path("temporal_capi/bindings/c"));
|
||||
mod.addIncludePath(temporal_rs_git.path("temporal_capi/bindings/c"));
|
||||
|
||||
// --- Rust Crate: temporal_rs --- //
|
||||
// --- 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 abi_str = @tagName(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, abi_str });
|
||||
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
|
||||
|
|
@ -43,7 +41,6 @@ pub fn build(b: *std.Build) !void {
|
|||
|
||||
// Try to use pre-built library if it exists by checking the path object
|
||||
const use_prebuilt = blk: {
|
||||
// Use the LazyPath to check if the library exists
|
||||
const lib_full_path = prebuilt_lib_file.getPath(b);
|
||||
const lib_check_file = std.Io.Dir.cwd().openFile(b.graph.io, lib_full_path, .{}) catch break :blk false;
|
||||
lib_check_file.close(b.graph.io);
|
||||
|
|
@ -52,43 +49,23 @@ pub fn build(b: *std.Build) !void {
|
|||
|
||||
if (use_prebuilt) {
|
||||
// Use pre-built library (no Rust compiler needed)
|
||||
// std.debug.print("Using pre-built temporal_capi library: {s}\n", .{prebuilt_lib_path});
|
||||
mod.addObjectFile(prebuilt_lib_file);
|
||||
} else {
|
||||
// Build from source using Cargo
|
||||
const build_dir = build_crab.addCargoBuild(
|
||||
b,
|
||||
.{
|
||||
.manifest_path = b.path("Cargo.toml"),
|
||||
.cargo_args = if (optimize == .Debug) &.{} else &.{"--release"},
|
||||
},
|
||||
.{
|
||||
// Build from source using the local temporal-rs package
|
||||
const temporal_rs_local = b.dependency("temporal_rs_local", .{
|
||||
.target = target,
|
||||
.optimize = .ReleaseSafe,
|
||||
},
|
||||
);
|
||||
|
||||
// Install .a/.lib to lib/<target>/libtemporal_capi.a/temporal_capi.lib
|
||||
const install_lib = b.addInstallDirectory(.{
|
||||
.source_dir = build_dir,
|
||||
.install_dir = .{ .custom = "../lib" },
|
||||
.install_subdir = target_triple,
|
||||
.optimize = optimize,
|
||||
});
|
||||
b.getInstallStep().dependOn(&install_lib.step);
|
||||
mod.addObjectFile(build_dir.path(b, lib_name));
|
||||
mod.linkLibrary(temporal_rs_local.artifact("temporal_rs_lib"));
|
||||
}
|
||||
|
||||
// --- 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(.{
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -175,43 +152,4 @@ pub fn build(b: *std.Build) !void {
|
|||
run_cmd.step.dependOn(b.getInstallStep());
|
||||
test262_step.dependOn(&run_cmd.step);
|
||||
}
|
||||
|
||||
// --- Steps: Build all platforms --- //
|
||||
{
|
||||
const build_lib_step = b.step("lib", "Build libraries for all common platforms");
|
||||
|
||||
inline for (platforms) |p| {
|
||||
const query = try std.Build.parseTargetQuery(.{ .arch_os_abi = p });
|
||||
const platform_target = b.resolveTargetQuery(query);
|
||||
|
||||
const build_dir = build_crab.addCargoBuild(
|
||||
b,
|
||||
.{
|
||||
.manifest_path = b.path("Cargo.toml"),
|
||||
.cargo_args = &.{"--release"},
|
||||
},
|
||||
.{
|
||||
.target = platform_target,
|
||||
.optimize = .ReleaseSafe,
|
||||
},
|
||||
);
|
||||
|
||||
const install_lib = b.addInstallDirectory(.{
|
||||
.source_dir = build_dir,
|
||||
.install_dir = .{ .custom = "../lib" },
|
||||
.install_subdir = p,
|
||||
});
|
||||
build_lib_step.dependOn(&install_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",
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,9 +8,8 @@
|
|||
.url = "git+https://github.com/boa-dev/temporal#v0.1.2",
|
||||
.hash = "N-V-__8AANlkNAB77Z946lqp-lgp2qSsOBDADValZC86PhB-",
|
||||
},
|
||||
.build_crab = .{
|
||||
.url = "git+https://github.com/nurulhudaapon/build.crab?ref=zig-dev#658db72f1695987612e9356c023575ff8dc753a2",
|
||||
.hash = "build_crab-0.2.1-U0id__PFAACr0518VaPmWuEJDMJezJhmAsFRY6d49v6e",
|
||||
.temporal_rs_local = .{
|
||||
.path = "pkg/temporal-rs",
|
||||
},
|
||||
},
|
||||
.paths = .{
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ const program = @import("root.zig");
|
|||
const Temporal = @import("temporalz");
|
||||
|
||||
export fn _start() void {
|
||||
const allocator = std.heap.wasm_allocator;
|
||||
const allocator = std.heap.page_allocator;
|
||||
program.run(allocator, null) catch {};
|
||||
}
|
||||
|
||||
|
|
|
|||
0
Cargo.lock → pkg/temporal-rs/Cargo.lock
generated
0
Cargo.lock → pkg/temporal-rs/Cargo.lock
generated
101
pkg/temporal-rs/build.zig
Normal file
101
pkg/temporal-rs/build.zig
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
const std = @import("std");
|
||||
const build_crab = @import("build_crab");
|
||||
|
||||
pub fn build(b: *std.Build) !void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
// --- Rust Crate Build --- //
|
||||
const build_dir = build_crab.addCargoBuild(
|
||||
b,
|
||||
.{
|
||||
.manifest_path = b.path("Cargo.toml"),
|
||||
.cargo_args = if (optimize == .Debug) &.{} else &.{"--release"},
|
||||
},
|
||||
.{
|
||||
.target = target,
|
||||
.optimize = .ReleaseSafe,
|
||||
},
|
||||
);
|
||||
|
||||
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) --- //
|
||||
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 install_lib = b.addInstallFile(lib_file, b.fmt("lib/{s}/{s}", .{ target_triple, lib_name }));
|
||||
b.getInstallStep().dependOn(&install_lib.step);
|
||||
|
||||
// --- Zig Module --- //
|
||||
const mod = b.addModule("temporal_rs", .{
|
||||
.root_source_file = b.path("src/root.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
mod.addObjectFile(lib_file);
|
||||
|
||||
// --- Library Artifact (for explicit linking) --- //
|
||||
const lib_artifact = b.addLibrary(.{
|
||||
.name = "temporal_rs_lib",
|
||||
.root_module = b.createModule(.{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
}),
|
||||
});
|
||||
lib_artifact.root_module.addObjectFile(lib_file);
|
||||
b.installArtifact(lib_artifact);
|
||||
|
||||
// --- Steps: Build all platforms --- //
|
||||
{
|
||||
const build_lib_step = b.step("lib", "Build libraries for all common platforms");
|
||||
|
||||
inline for (platforms) |p| {
|
||||
const query = try std.Build.parseTargetQuery(.{ .arch_os_abi = p });
|
||||
const platform_target = b.resolveTargetQuery(query);
|
||||
|
||||
const platform_build_dir = build_crab.addCargoBuild(
|
||||
b,
|
||||
.{
|
||||
.manifest_path = b.path("Cargo.toml"),
|
||||
.cargo_args = &.{"--release"},
|
||||
},
|
||||
.{
|
||||
.target = platform_target,
|
||||
.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",
|
||||
};
|
||||
56
pkg/temporal-rs/build.zig.zon
Normal file
56
pkg/temporal-rs/build.zig.zon
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
.{
|
||||
// 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,
|
||||
// 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",
|
||||
// Together with name, this represents a globally unique package
|
||||
// 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",
|
||||
// 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 = .{
|
||||
.build_crab = .{
|
||||
.url = "git+https://github.com/nurulhudaapon/build.crab?ref=zig-dev#658db72f1695987612e9356c023575ff8dc753a2",
|
||||
.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 = .{
|
||||
"build.zig",
|
||||
"build.zig.zon",
|
||||
"src",
|
||||
// For example...
|
||||
//"LICENSE",
|
||||
//"README.md",
|
||||
},
|
||||
}
|
||||
1
test/temporal-test262-runner
Submodule
1
test/temporal-test262-runner
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 80286aa081b04bb9c9881615af62ae0d47912791
|
||||
Loading…
Add table
Reference in a new issue