Skip to content

Commit e7f0b39

Browse files
authored
Merge pull request #188 from e0328eric/main
support zig version 0.16.0-dev.1888+9d497d0d7
2 parents 315b7f2 + e4913d3 commit e7f0b39

File tree

7 files changed

+81
-86
lines changed

7 files changed

+81
-86
lines changed

.github/workflows/tests.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,24 @@ jobs:
2828
run: make test_zig_nightly
2929

3030
#------ zig-0.15 ------
31-
test_zig_015:
32-
strategy:
33-
matrix:
34-
os: [ubuntu-latest, macos-latest, windows-latest, ubuntu-24.04-arm]
31+
#test_zig_015:
32+
# strategy:
33+
# matrix:
34+
# os: [ubuntu-latest, macos-latest, windows-latest, ubuntu-24.04-arm]
3535

36-
runs-on: ${{matrix.os}}
36+
# runs-on: ${{matrix.os}}
3737

38-
steps:
39-
- name: Clone Ziglua
40-
uses: actions/checkout@v3
38+
# steps:
39+
# - name: Clone Ziglua
40+
# uses: actions/checkout@v3
4141

42-
- name: Setup Zig
43-
uses: mlugg/setup-zig@v2
44-
with:
45-
version: "0.15.2"
42+
# - name: Setup Zig
43+
# uses: mlugg/setup-zig@v2
44+
# with:
45+
# version: "0.15.2"
4646

47-
- name: Run tests
48-
run: make test_zig_stable
47+
# - name: Run tests
48+
# run: make test_zig_stable
4949

5050
#------ cross compilation ------
5151
test_cross:

build/lua.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub fn configure(
4444
const lib = b.createModule(.{
4545
.target = target,
4646
.optimize = optimize,
47+
.link_libc = true,
4748
});
4849
const library = b.addLibrary(.{
4950
.name = library_name,
@@ -103,15 +104,13 @@ pub fn configure(
103104
lib.addCSourceFile(.{ .file = patched.output, .flags = &flags });
104105
}
105106

106-
library.linkLibC();
107-
108107
library.installHeader(upstream.path("src/lua.h"), "lua.h");
109108
library.installHeader(upstream.path("src/lualib.h"), "lualib.h");
110109
library.installHeader(upstream.path("src/lauxlib.h"), "lauxlib.h");
111110
library.installHeader(upstream.path("src/luaconf.h"), "luaconf.h");
112111

113112
if (lua_user_h) |user_h| {
114-
library.addIncludePath(user_h.dirname());
113+
library.root_module.addIncludePath(user_h.dirname());
115114
library.installHeader(user_h, user_header);
116115
}
117116

build/luajit.zig

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,14 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
2323
const minilua_mod = b.createModule(.{
2424
.target = b.graph.host, // Use host target for cross build
2525
.optimize = .ReleaseSafe,
26+
.link_libc = true,
27+
.sanitize_c = .off,
2628
});
2729
const minilua = b.addExecutable(.{
2830
.name = "minilua",
2931
.root_module = minilua_mod,
3032
});
31-
minilua.linkLibC();
32-
// FIXME: remove branch when zig-0.15 is released and 0.14 can be dropped
33-
const builtin = @import("builtin");
34-
if (builtin.zig_version.major == 0 and builtin.zig_version.minor < 15) {
35-
minilua.root_module.sanitize_c = false;
36-
} else {
37-
minilua.root_module.sanitize_c = .off;
38-
}
39-
minilua.addCSourceFile(.{ .file = upstream.path("src/host/minilua.c") });
33+
minilua.root_module.addCSourceFile(.{ .file = upstream.path("src/host/minilua.c") });
4034

4135
// Generate the buildvm_arch.h file using minilua
4236
const dynasm_run = b.addRunArtifact(minilua);
@@ -108,18 +102,13 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
108102
const vm_mod = b.createModule(.{
109103
.target = b.graph.host, // Use host target for cross build
110104
.optimize = .ReleaseSafe,
105+
.link_libc = true,
106+
.sanitize_c = .off,
111107
});
112108
const buildvm = b.addExecutable(.{
113109
.name = "buildvm",
114110
.root_module = vm_mod,
115111
});
116-
buildvm.linkLibC();
117-
// FIXME: remove branch when zig-0.15 is released and 0.14 can be dropped
118-
if (builtin.zig_version.major == 0 and builtin.zig_version.minor < 15) {
119-
buildvm.root_module.sanitize_c = false;
120-
} else {
121-
buildvm.root_module.sanitize_c = .off;
122-
}
123112

124113
// Needs to run after the buildvm_arch.h and luajit.h files are generated
125114
buildvm.step.dependOn(&dynasm_run.step);
@@ -136,7 +125,7 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
136125
else
137126
&.{};
138127

139-
buildvm.addCSourceFiles(.{
128+
buildvm.root_module.addCSourceFiles(.{
140129
.root = .{ .dependency = .{
141130
.dependency = upstream,
142131
.sub_path = "",
@@ -145,10 +134,10 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
145134
.flags = std.mem.concat(b.allocator, []const u8, &.{ buildvm_c_flags, buildvm_windows_c_flags }) catch @panic("OOM!"),
146135
});
147136

148-
buildvm.addIncludePath(upstream.path("src"));
149-
buildvm.addIncludePath(upstream.path("src/host"));
150-
buildvm.addIncludePath(buildvm_arch_h.dirname());
151-
buildvm.addIncludePath(luajit_h.dirname());
137+
buildvm.root_module.addIncludePath(upstream.path("src"));
138+
buildvm.root_module.addIncludePath(upstream.path("src/host"));
139+
buildvm.root_module.addIncludePath(buildvm_arch_h.dirname());
140+
buildvm.root_module.addIncludePath(luajit_h.dirname());
152141

153142
// Use buildvm to generate files and headers used in the final vm
154143
const buildvm_bcdef = b.addRunArtifact(buildvm);
@@ -213,19 +202,19 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
213202
library.step.dependOn(&buildvm_folddef.step);
214203
library.step.dependOn(&buildvm_ljvm.step);
215204

216-
library.linkLibC();
205+
library.is_linking_libc = true;
217206

218207
lib.addCMacro("LUAJIT_UNWIND_EXTERNAL", "");
219208

220209
lib.linkSystemLibrary("unwind", .{});
221210

222-
library.addIncludePath(upstream.path("src"));
223-
library.addIncludePath(luajit_h.dirname());
224-
library.addIncludePath(bcdef_header.dirname());
225-
library.addIncludePath(ffdef_header.dirname());
226-
library.addIncludePath(libdef_header.dirname());
227-
library.addIncludePath(recdef_header.dirname());
228-
library.addIncludePath(folddef_header.dirname());
211+
library.root_module.addIncludePath(upstream.path("src"));
212+
library.root_module.addIncludePath(luajit_h.dirname());
213+
library.root_module.addIncludePath(bcdef_header.dirname());
214+
library.root_module.addIncludePath(ffdef_header.dirname());
215+
library.root_module.addIncludePath(libdef_header.dirname());
216+
library.root_module.addIncludePath(recdef_header.dirname());
217+
library.root_module.addIncludePath(folddef_header.dirname());
229218

230219
lib.addCSourceFiles(.{
231220
.root = .{ .dependency = .{
@@ -235,12 +224,7 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
235224
.files = &luajit_vm,
236225
});
237226

238-
// FIXME: remove branch when zig-0.15 is released and 0.14 can be dropped
239-
if (builtin.zig_version.major == 0 and builtin.zig_version.minor < 15) {
240-
lib.sanitize_c = false;
241-
} else {
242-
lib.sanitize_c = .off;
243-
}
227+
lib.sanitize_c = .off;
244228

245229
library.installHeader(upstream.path("src/lua.h"), "lua.h");
246230
library.installHeader(upstream.path("src/lualib.h"), "lualib.h");

build/luau.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
77
const lib = b.createModule(.{
88
.target = target,
99
.optimize = optimize,
10+
.link_libcpp = true,
1011
});
1112
const library = b.addLibrary(.{
1213
.name = "luau",
@@ -37,7 +38,6 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
3738
.flags = &flags,
3839
});
3940
lib.addCSourceFile(.{ .file = b.path("src/luau.cpp"), .flags = &flags });
40-
library.linkLibCpp();
4141

4242
library.installHeader(upstream.path("VM/include/lua.h"), "lua.h");
4343
library.installHeader(upstream.path("VM/include/lualib.h"), "lualib.h");

build/patch.zig

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
pub fn main() !void {
55
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
66
defer arena.deinit();
7-
87
const allocator = arena.allocator();
98

9+
var threaded = Io.Threaded.init(allocator, .{});
10+
defer threaded.deinit();
11+
const io = threaded.io();
12+
1013
const args = try std.process.argsAlloc(allocator);
1114
if (args.len != 4) @panic("Wrong number of arguments");
1215

@@ -15,23 +18,23 @@ pub fn main() !void {
1518
const output_path = args[3];
1619

1720
const patch_file = patch_file: {
18-
const patch_file = try std.fs.cwd().openFile(patch_file_path, .{ .mode = .read_only });
19-
defer patch_file.close();
21+
const patch_file = try Io.Dir.cwd().openFile(io, patch_file_path, .{ .mode = .read_only });
22+
defer patch_file.close(io);
2023
var buf: [4096]u8 = undefined;
21-
var reader = patch_file.reader(&buf);
24+
var reader = patch_file.reader(io, &buf);
2225
break :patch_file try reader.interface.allocRemaining(allocator, .unlimited);
2326
};
2427
const chunk_details = Chunk.init(allocator, patch_file, 0) orelse @panic("No chunk data found");
2528

26-
const file = try std.fs.cwd().openFile(file_path, .{ .mode = .read_only });
27-
defer file.close();
29+
const file = try Io.Dir.cwd().openFile(io, file_path, .{ .mode = .read_only });
30+
defer file.close(io);
2831
var in_buf: [4096]u8 = undefined;
29-
var reader = file.reader(&in_buf);
32+
var reader = file.reader(io, &in_buf);
3033

31-
const output = try std.fs.cwd().createFile(output_path, .{});
32-
defer output.close();
34+
const output = try Io.Dir.cwd().createFile(io, output_path, .{});
35+
defer output.close(io);
3336
var out_buf: [4096]u8 = undefined;
34-
var writer = output.writer(&out_buf);
37+
var writer = output.writer(io, &out_buf);
3538

3639
var state: State = .copy;
3740

@@ -134,4 +137,5 @@ const Chunk = struct {
134137

135138
const std = @import("std");
136139
const Allocator = std.mem.Allocator;
137-
const File = std.fs.File;
140+
const Io = std.Io;
141+
const File = Io.File;

examples/interpreter.zig

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const zlua = @import("zlua");
88

99
const ReadError = error{BufferTooSmall};
1010

11-
fn readlineStdin(out_buf: []u8) anyerror!usize {
11+
fn readlineStdin(io: std.Io, out_buf: []u8) anyerror!usize {
1212
var in_buf: [4096]u8 = undefined;
13-
var stdin_file = std.fs.File.stdin().reader(&in_buf);
13+
var stdin_file = std.Io.File.stdin().reader(io, &in_buf);
1414
const stdin = &stdin_file.interface;
1515
const s = try stdin.takeDelimiterExclusive('\n');
1616
if (s.len < out_buf.len) {
@@ -20,9 +20,9 @@ fn readlineStdin(out_buf: []u8) anyerror!usize {
2020
return error.BufferTooSmall;
2121
}
2222

23-
fn flushedStdoutPrint(comptime fmt: []const u8, args: anytype) !void {
23+
fn flushedStdoutPrint(io: std.Io, comptime fmt: []const u8, args: anytype) !void {
2424
var out_buf: [4096]u8 = undefined;
25-
var w = std.fs.File.stdout().writer(&out_buf);
25+
var w = std.Io.File.stdout().writer(io, &out_buf);
2626
const stdout = &w.interface;
2727
try stdout.print(fmt, args);
2828
try stdout.flush();
@@ -33,6 +33,10 @@ pub fn main() anyerror!void {
3333
const allocator = gpa.allocator();
3434
defer _ = gpa.deinit();
3535

36+
var threaded: std.Io.Threaded = .init_single_threaded;
37+
defer threaded.deinit();
38+
const io = threaded.io();
39+
3640
// Initialize The Lua vm and get a reference to the main thread
3741
//
3842
// Passing a Zig allocator to the Lua state requires a stable pointer
@@ -43,14 +47,14 @@ pub fn main() anyerror!void {
4347
lua.openLibs();
4448

4549
while (true) {
46-
try flushedStdoutPrint("> ", .{});
50+
try flushedStdoutPrint(io, "> ", .{});
4751

4852
// Read a line of input
4953
var buffer: [256]u8 = undefined;
50-
const len = readlineStdin(buffer[0 .. buffer.len - 1]) catch |err| {
54+
const len = readlineStdin(io, buffer[0 .. buffer.len - 1]) catch |err| {
5155
switch (err) {
5256
error.BufferTooSmall => {
53-
try flushedStdoutPrint("error: line too long!\n", .{});
57+
try flushedStdoutPrint(io, "error: line too long!\n", .{});
5458
continue;
5559
},
5660
error.EndOfStream => break,
@@ -65,7 +69,7 @@ pub fn main() anyerror!void {
6569
lua.loadString(buffer[0..len :0]) catch {
6670
// If there was an error, Lua will place an error string on the top of the stack.
6771
// Here we print out the string to inform the user of the issue.
68-
try flushedStdoutPrint("{s}\n", .{lua.toString(-1) catch unreachable});
72+
try flushedStdoutPrint(io, "{s}\n", .{lua.toString(-1) catch unreachable});
6973

7074
// Remove the error from the stack and go back to the prompt
7175
lua.pop(1);
@@ -75,7 +79,7 @@ pub fn main() anyerror!void {
7579
// Execute a line of Lua code
7680
lua.protectedCall(.{}) catch {
7781
// Error handling here is the same as above.
78-
try flushedStdoutPrint("{s}\n", .{lua.toString(-1) catch unreachable});
82+
try flushedStdoutPrint(io, "{s}\n", .{lua.toString(-1) catch unreachable});
7983
lua.pop(1);
8084
};
8185
}

makefile

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
.PHONY: test docs
22

33
test_zig_nightly:
4-
zig build test --summary failures -Dlang=lua51
4+
# FIXME: reenable after resolution of https://codeberg.org/ziglang/translate-c/issues/282
5+
# zig build test --summary failures -Dlang=lua51
56
zig build test --summary failures -Dlang=lua52
67
zig build test --summary failures -Dlang=lua53
78
zig build test --summary failures -Dlang=lua54
@@ -11,7 +12,8 @@ test_zig_nightly:
1112
zig build install-example-zig-function
1213
zig build -Dlang=luau install-example-luau-bytecode
1314

14-
zig build -Dlang=luajit
15+
# FIXME: reenable after resolution of https://codeberg.org/ziglang/translate-c/issues/282
16+
# zig build -Dlang=luajit
1517

1618
# A subset of tests that are expected to work also on stable builds of zig
1719
test_zig_stable:
@@ -26,17 +28,19 @@ test_zig_stable:
2628
zig build -Dlang=luau install-example-luau-bytecode
2729

2830
test_cross:
29-
zig build -Dlang=lua51 -Dtarget=aarch64-linux
30-
zig build -Dlang=lua51 -Dtarget=aarch64-linux-gnu
31-
zig build -Dlang=luajit -Dtarget=aarch64-linux
32-
zig build -Dlang=luajit -Dtarget=aarch64-linux-gnu
33-
34-
zig build -Dlang=lua51 -Dtarget=x86_64-linux
35-
zig build -Dlang=lua51 -Dtarget=x86_64-linux-gnu
36-
zig build -Dlang=luajit -Dtarget=x86_64-linux
37-
zig build -Dlang=luajit -Dtarget=x86_64-linux-gnu
38-
39-
zig build -Dlang=luajit -Dtarget=aarch64-macos
31+
# TODO: audit this; is it expected that cross-compilation should be an issue?
32+
# FIXME: reenable after resolution of https://codeberg.org/ziglang/translate-c/issues/282
33+
# zig build -Dlang=lua51 -Dtarget=aarch64-linux
34+
# zig build -Dlang=lua51 -Dtarget=aarch64-linux-gnu
35+
# zig build -Dlang=luajit -Dtarget=aarch64-linux
36+
# zig build -Dlang=luajit -Dtarget=aarch64-linux-gnu
37+
#
38+
# zig build -Dlang=lua51 -Dtarget=x86_64-linux
39+
# zig build -Dlang=lua51 -Dtarget=x86_64-linux-gnu
40+
# zig build -Dlang=luajit -Dtarget=x86_64-linux
41+
# zig build -Dlang=luajit -Dtarget=x86_64-linux-gnu
42+
#
43+
# zig build -Dlang=luajit -Dtarget=aarch64-macos
4044

4145
docs:
4246
zig build docs

0 commit comments

Comments
 (0)