Skip to content

Commit 877c4d6

Browse files
committed
fix(integration): add Ruby and Zig to run-all.sh, use native Zig compiler
- Add Ruby and Zig sections to integration/run-all.sh so all six language suites are exercised by the local runner - Switch Zig integration tests from .runar.ts (shelled out to the Go compiler) to .runar.zig contracts compiled natively by the Zig frontend — removes the Go compiler build dependency from Zig tests - Remove compileViaGoCompiler and compileViaNpx fallbacks from integration/zig/src/compile.zig; the Zig integration suite now tests the Zig compiler end-to-end - Drop the `go build` pre-step from the CI Zig integration job
1 parent 44957a4 commit 877c4d6

File tree

6 files changed

+38
-87
lines changed

6 files changed

+38
-87
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,7 @@ jobs:
328328
run: cd integration/ruby && bundle exec rspec --format documentation
329329

330330
- name: Zig integration tests
331-
run: |
332-
cd compilers/go && go build -o runar-go .
333-
cd ../../integration/zig && zig build test
331+
run: cd integration/zig && zig build test
334332
timeout-minutes: 5
335333

336334
- name: Ruby end-to-end example tests

integration/run-all.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ else
6666
FAILED=$((FAILED + 1))
6767
fi
6868

69+
echo ""
70+
echo "=== Ruby integration tests ==="
71+
# Ensure gems are installed
72+
if [ ! -d ruby/vendor ]; then
73+
(cd ruby && bundle install --quiet)
74+
fi
75+
if (cd ruby && bundle exec rspec --format documentation); then
76+
echo "--- Ruby: PASSED ---"
77+
else
78+
echo "--- Ruby: FAILED ---"
79+
FAILED=$((FAILED + 1))
80+
fi
81+
82+
echo ""
83+
echo "=== Zig integration tests ==="
84+
if (cd zig && zig build test); then
85+
echo "--- Zig: PASSED ---"
86+
else
87+
echo "--- Zig: FAILED ---"
88+
FAILED=$((FAILED + 1))
89+
fi
90+
6991
if $STOP_NODE; then
7092
echo ""
7193
echo "=== Stopping regtest node ==="

integration/zig/src/compile.zig

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,11 @@ const std = @import("std");
22
const runar = @import("runar");
33
const runar_frontend = @import("runar_frontend");
44

5-
/// Compile a contract source file and return a parsed RunarArtifact.
6-
/// Uses the Zig compiler frontend directly (parse -> validate -> typecheck -> ANF -> stack -> emit).
7-
///
8-
/// For .runar.ts sources, shells out to the Go compiler binary since the Zig
9-
/// frontend only supports .runar.zig files. If the Go compiler is not available,
10-
/// falls back to reading a pre-compiled JSON artifact from disk.
5+
/// Compile a .runar.zig contract source file and return a parsed RunarArtifact.
6+
/// Uses the native Zig compiler frontend (parse -> validate -> typecheck -> ANF -> stack -> emit).
117
pub fn compileContract(allocator: std.mem.Allocator, source_path: []const u8) !runar.RunarArtifact {
12-
// Determine the project root (integration/zig -> project root is ../.. )
138
const project_root = projectRoot();
149

15-
// Check file extension
16-
if (std.mem.endsWith(u8, source_path, ".runar.zig")) {
17-
return compileZigContract(allocator, project_root, source_path);
18-
}
19-
20-
// For .runar.ts (and other formats), shell out to the Go compiler
21-
return compileViaGoCompiler(allocator, project_root, source_path);
22-
}
23-
24-
/// Compile a .runar.zig contract using the native Zig compiler frontend.
25-
fn compileZigContract(allocator: std.mem.Allocator, project_root: []const u8, source_path: []const u8) !runar.RunarArtifact {
2610
const abs_path = try std.fs.path.join(allocator, &.{ project_root, source_path });
2711
defer allocator.free(abs_path);
2812

@@ -42,59 +26,6 @@ fn compileZigContract(allocator: std.mem.Allocator, project_root: []const u8, so
4226
return error.OutOfMemory;
4327
}
4428

45-
/// Compile via the Go compiler binary, which supports .runar.ts, .runar.sol, etc.
46-
fn compileViaGoCompiler(allocator: std.mem.Allocator, project_root: []const u8, source_path: []const u8) !runar.RunarArtifact {
47-
const abs_source = try std.fs.path.join(allocator, &.{ project_root, source_path });
48-
defer allocator.free(abs_source);
49-
50-
// Try the Go compiler binary
51-
const go_compiler = try std.fs.path.join(allocator, &.{ project_root, "compilers/go/runar-go" });
52-
defer allocator.free(go_compiler);
53-
54-
const result = std.process.Child.run(.{
55-
.allocator = allocator,
56-
.argv = &.{ go_compiler, "-source", abs_source },
57-
}) catch |err| {
58-
// Go binary not found; try building it first, or fall back to npx
59-
std.log.warn("Go compiler not found ({any}), trying npx...", .{err});
60-
return compileViaNpx(allocator, project_root, abs_source);
61-
};
62-
defer {
63-
allocator.free(result.stdout);
64-
allocator.free(result.stderr);
65-
}
66-
67-
const exit_code: u8 = if (result.term == .Exited) result.term.Exited else 255;
68-
if (exit_code != 0) {
69-
std.log.err("Go compiler exited with code {d}: {s}", .{ exit_code, result.stderr });
70-
// Fall back to npx
71-
return compileViaNpx(allocator, project_root, abs_source);
72-
}
73-
74-
return runar.RunarArtifact.fromJson(allocator, result.stdout);
75-
}
76-
77-
/// Compile via npx runar-compiler (Node.js).
78-
fn compileViaNpx(allocator: std.mem.Allocator, project_root: []const u8, abs_source: []const u8) !runar.RunarArtifact {
79-
const result = std.process.Child.run(.{
80-
.allocator = allocator,
81-
.argv = &.{ "npx", "runar-compiler", "--source", abs_source },
82-
.cwd = project_root,
83-
}) catch return error.OutOfMemory;
84-
defer {
85-
allocator.free(result.stdout);
86-
allocator.free(result.stderr);
87-
}
88-
89-
const npx_exit: u8 = if (result.term == .Exited) result.term.Exited else 255;
90-
if (npx_exit != 0) {
91-
std.log.err("npx compiler exited with code {d}: {s}", .{ npx_exit, result.stderr });
92-
return error.OutOfMemory;
93-
}
94-
95-
return runar.RunarArtifact.fromJson(allocator, result.stdout);
96-
}
97-
9829
/// Get the project root directory (relative from integration/zig/).
9930
fn projectRoot() []const u8 {
10031
return "../..";

integration/zig/src/counter_test.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn deployCounter(
1515
wallet: helpers.Wallet,
1616
artifact: runar.RunarArtifact,
1717
} {
18-
var artifact = try compile.compileContract(allocator, "examples/ts/stateful-counter/Counter.runar.ts");
18+
var artifact = try compile.compileContract(allocator, "examples/zig/stateful-counter/Counter.runar.zig");
1919
errdefer artifact.deinit();
2020

2121
var contract = try runar.RunarContract.init(allocator, &artifact, &[_]runar.StateValue{
@@ -53,7 +53,7 @@ test "Counter_Increment" {
5353
return;
5454
}
5555

56-
var artifact = compile.compileContract(allocator, "examples/ts/stateful-counter/Counter.runar.ts") catch |err| {
56+
var artifact = compile.compileContract(allocator, "examples/zig/stateful-counter/Counter.runar.zig") catch |err| {
5757
std.log.warn("Could not compile Counter contract: {any}, skipping test", .{err});
5858
return;
5959
};
@@ -97,7 +97,7 @@ test "Counter_Deploy_WithInitialValue" {
9797
return;
9898
}
9999

100-
var artifact = compile.compileContract(allocator, "examples/ts/stateful-counter/Counter.runar.ts") catch |err| {
100+
var artifact = compile.compileContract(allocator, "examples/zig/stateful-counter/Counter.runar.zig") catch |err| {
101101
std.log.warn("Could not compile Counter contract: {any}, skipping test", .{err});
102102
return;
103103
};
@@ -128,7 +128,7 @@ test "Counter_Deploy_WithInitialValue" {
128128
test "Counter_LockingScript_Includes_OpReturn" {
129129
const allocator = std.testing.allocator;
130130

131-
var artifact = compile.compileContract(allocator, "examples/ts/stateful-counter/Counter.runar.ts") catch |err| {
131+
var artifact = compile.compileContract(allocator, "examples/zig/stateful-counter/Counter.runar.zig") catch |err| {
132132
std.log.warn("Could not compile Counter contract: {any}, skipping test", .{err});
133133
return;
134134
};
@@ -150,7 +150,7 @@ test "Counter_LockingScript_Includes_OpReturn" {
150150
test "Counter_StateField_Metadata" {
151151
const allocator = std.testing.allocator;
152152

153-
var artifact = compile.compileContract(allocator, "examples/ts/stateful-counter/Counter.runar.ts") catch |err| {
153+
var artifact = compile.compileContract(allocator, "examples/zig/stateful-counter/Counter.runar.zig") catch |err| {
154154
std.log.warn("Could not compile Counter contract: {any}, skipping test", .{err});
155155
return;
156156
};

integration/zig/src/escrow_test.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const compile = @import("compile.zig");
77
test "Escrow_Compile" {
88
const allocator = std.testing.allocator;
99

10-
var artifact = compile.compileContract(allocator, "examples/ts/escrow/Escrow.runar.ts") catch |err| {
10+
var artifact = compile.compileContract(allocator, "examples/zig/escrow/Escrow.runar.zig") catch |err| {
1111
std.log.warn("Could not compile Escrow contract: {any}, skipping test", .{err});
1212
return;
1313
};
@@ -25,7 +25,7 @@ test "Escrow_DeployThreePubKeys" {
2525
return;
2626
}
2727

28-
var artifact = compile.compileContract(allocator, "examples/ts/escrow/Escrow.runar.ts") catch |err| {
28+
var artifact = compile.compileContract(allocator, "examples/zig/escrow/Escrow.runar.zig") catch |err| {
2929
std.log.warn("Could not compile Escrow contract: {any}, skipping test", .{err});
3030
return;
3131
};
@@ -76,7 +76,7 @@ test "Escrow_DeploySameKey" {
7676
return;
7777
}
7878

79-
var artifact = compile.compileContract(allocator, "examples/ts/escrow/Escrow.runar.ts") catch |err| {
79+
var artifact = compile.compileContract(allocator, "examples/zig/escrow/Escrow.runar.zig") catch |err| {
8080
std.log.warn("Could not compile Escrow contract: {any}, skipping test", .{err});
8181
return;
8282
};
@@ -113,7 +113,7 @@ test "Escrow_DeploySameKey" {
113113
test "Escrow_ABI_Methods" {
114114
const allocator = std.testing.allocator;
115115

116-
var artifact = compile.compileContract(allocator, "examples/ts/escrow/Escrow.runar.ts") catch |err| {
116+
var artifact = compile.compileContract(allocator, "examples/zig/escrow/Escrow.runar.zig") catch |err| {
117117
std.log.warn("Could not compile Escrow contract: {any}, skipping test", .{err});
118118
return;
119119
};
@@ -138,7 +138,7 @@ test "Escrow_ABI_Methods" {
138138
test "Escrow_NotStateful" {
139139
const allocator = std.testing.allocator;
140140

141-
var artifact = compile.compileContract(allocator, "examples/ts/escrow/Escrow.runar.ts") catch |err| {
141+
var artifact = compile.compileContract(allocator, "examples/zig/escrow/Escrow.runar.zig") catch |err| {
142142
std.log.warn("Could not compile Escrow contract: {any}, skipping test", .{err});
143143
return;
144144
};

integration/zig/src/p2pkh_test.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const compile = @import("compile.zig");
66

77
/// Deploy a P2PKH contract locked to the given owner wallet.
88
fn deployP2PKH(allocator: std.mem.Allocator, owner: *helpers.Wallet) !struct { contract: runar.RunarContract, provider: helpers.RPCProvider, signer: runar.LocalSigner } {
9-
var artifact = try compile.compileContract(allocator, "examples/ts/p2pkh/P2PKH.runar.ts");
9+
var artifact = try compile.compileContract(allocator, "examples/zig/p2pkh/P2PKH.runar.zig");
1010
errdefer artifact.deinit();
1111

1212
const pkh_hex = try owner.pubKeyHashHex(allocator);
@@ -43,7 +43,7 @@ test "P2PKH_ValidUnlock" {
4343
var owner = try helpers.newWallet(allocator);
4444
defer owner.deinit();
4545

46-
var artifact = compile.compileContract(allocator, "examples/ts/p2pkh/P2PKH.runar.ts") catch |err| {
46+
var artifact = compile.compileContract(allocator, "examples/zig/p2pkh/P2PKH.runar.zig") catch |err| {
4747
std.log.warn("Could not compile P2PKH contract: {any}, skipping test", .{err});
4848
return;
4949
};
@@ -89,7 +89,7 @@ test "P2PKH_DeployDifferentPubKeyHash" {
8989
return;
9090
}
9191

92-
var artifact = compile.compileContract(allocator, "examples/ts/p2pkh/P2PKH.runar.ts") catch |err| {
92+
var artifact = compile.compileContract(allocator, "examples/zig/p2pkh/P2PKH.runar.zig") catch |err| {
9393
std.log.warn("Could not compile P2PKH contract: {any}, skipping test", .{err});
9494
return;
9595
};

0 commit comments

Comments
 (0)