Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ jobs:
run: make test_zig_nightly

#------ zig-0.15 ------
test_zig_015:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest, ubuntu-24.04-arm]
#test_zig_015:
# strategy:
# matrix:
# os: [ubuntu-latest, macos-latest, windows-latest, ubuntu-24.04-arm]

runs-on: ${{matrix.os}}
# runs-on: ${{matrix.os}}

steps:
- name: Clone Ziglua
uses: actions/checkout@v3
# steps:
# - name: Clone Ziglua
# uses: actions/checkout@v3

- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: "0.15.2"
# - name: Setup Zig
# uses: mlugg/setup-zig@v2
# with:
# version: "0.15.2"

- name: Run tests
run: make test_zig_stable
# - name: Run tests
# run: make test_zig_stable

#------ cross compilation ------
test_cross:
Expand Down
5 changes: 2 additions & 3 deletions build/lua.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub fn configure(
const lib = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
});
const library = b.addLibrary(.{
.name = library_name,
Expand Down Expand Up @@ -103,15 +104,13 @@ pub fn configure(
lib.addCSourceFile(.{ .file = patched.output, .flags = &flags });
}

library.linkLibC();

library.installHeader(upstream.path("src/lua.h"), "lua.h");
library.installHeader(upstream.path("src/lualib.h"), "lualib.h");
library.installHeader(upstream.path("src/lauxlib.h"), "lauxlib.h");
library.installHeader(upstream.path("src/luaconf.h"), "luaconf.h");

if (lua_user_h) |user_h| {
library.addIncludePath(user_h.dirname());
library.root_module.addIncludePath(user_h.dirname());
library.installHeader(user_h, user_header);
}

Expand Down
54 changes: 19 additions & 35 deletions build/luajit.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,14 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
const minilua_mod = b.createModule(.{
.target = b.graph.host, // Use host target for cross build
.optimize = .ReleaseSafe,
.link_libc = true,
.sanitize_c = .off,
});
const minilua = b.addExecutable(.{
.name = "minilua",
.root_module = minilua_mod,
});
minilua.linkLibC();
// FIXME: remove branch when zig-0.15 is released and 0.14 can be dropped
const builtin = @import("builtin");
if (builtin.zig_version.major == 0 and builtin.zig_version.minor < 15) {
minilua.root_module.sanitize_c = false;
} else {
minilua.root_module.sanitize_c = .off;
}
minilua.addCSourceFile(.{ .file = upstream.path("src/host/minilua.c") });
minilua.root_module.addCSourceFile(.{ .file = upstream.path("src/host/minilua.c") });

// Generate the buildvm_arch.h file using minilua
const dynasm_run = b.addRunArtifact(minilua);
Expand Down Expand Up @@ -108,18 +102,13 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
const vm_mod = b.createModule(.{
.target = b.graph.host, // Use host target for cross build
.optimize = .ReleaseSafe,
.link_libc = true,
.sanitize_c = .off,
});
const buildvm = b.addExecutable(.{
.name = "buildvm",
.root_module = vm_mod,
});
buildvm.linkLibC();
// FIXME: remove branch when zig-0.15 is released and 0.14 can be dropped
if (builtin.zig_version.major == 0 and builtin.zig_version.minor < 15) {
buildvm.root_module.sanitize_c = false;
} else {
buildvm.root_module.sanitize_c = .off;
}

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

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

buildvm.addIncludePath(upstream.path("src"));
buildvm.addIncludePath(upstream.path("src/host"));
buildvm.addIncludePath(buildvm_arch_h.dirname());
buildvm.addIncludePath(luajit_h.dirname());
buildvm.root_module.addIncludePath(upstream.path("src"));
buildvm.root_module.addIncludePath(upstream.path("src/host"));
buildvm.root_module.addIncludePath(buildvm_arch_h.dirname());
buildvm.root_module.addIncludePath(luajit_h.dirname());

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

library.linkLibC();
library.is_linking_libc = true;

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

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

library.addIncludePath(upstream.path("src"));
library.addIncludePath(luajit_h.dirname());
library.addIncludePath(bcdef_header.dirname());
library.addIncludePath(ffdef_header.dirname());
library.addIncludePath(libdef_header.dirname());
library.addIncludePath(recdef_header.dirname());
library.addIncludePath(folddef_header.dirname());
library.root_module.addIncludePath(upstream.path("src"));
library.root_module.addIncludePath(luajit_h.dirname());
library.root_module.addIncludePath(bcdef_header.dirname());
library.root_module.addIncludePath(ffdef_header.dirname());
library.root_module.addIncludePath(libdef_header.dirname());
library.root_module.addIncludePath(recdef_header.dirname());
library.root_module.addIncludePath(folddef_header.dirname());

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

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

library.installHeader(upstream.path("src/lua.h"), "lua.h");
library.installHeader(upstream.path("src/lualib.h"), "lualib.h");
Expand Down
2 changes: 1 addition & 1 deletion build/luau.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
const lib = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libcpp = true,
});
const library = b.addLibrary(.{
.name = "luau",
Expand Down Expand Up @@ -37,7 +38,6 @@ pub fn configure(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.
.flags = &flags,
});
lib.addCSourceFile(.{ .file = b.path("src/luau.cpp"), .flags = &flags });
library.linkLibCpp();

library.installHeader(upstream.path("VM/include/lua.h"), "lua.h");
library.installHeader(upstream.path("VM/include/lualib.h"), "lualib.h");
Expand Down
26 changes: 15 additions & 11 deletions build/patch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();

const allocator = arena.allocator();

var threaded = Io.Threaded.init(allocator, .{});
defer threaded.deinit();
const io = threaded.io();

const args = try std.process.argsAlloc(allocator);
if (args.len != 4) @panic("Wrong number of arguments");

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

const patch_file = patch_file: {
const patch_file = try std.fs.cwd().openFile(patch_file_path, .{ .mode = .read_only });
defer patch_file.close();
const patch_file = try Io.Dir.cwd().openFile(io, patch_file_path, .{ .mode = .read_only });
defer patch_file.close(io);
var buf: [4096]u8 = undefined;
var reader = patch_file.reader(&buf);
var reader = patch_file.reader(io, &buf);
break :patch_file try reader.interface.allocRemaining(allocator, .unlimited);
};
const chunk_details = Chunk.init(allocator, patch_file, 0) orelse @panic("No chunk data found");

const file = try std.fs.cwd().openFile(file_path, .{ .mode = .read_only });
defer file.close();
const file = try Io.Dir.cwd().openFile(io, file_path, .{ .mode = .read_only });
defer file.close(io);
var in_buf: [4096]u8 = undefined;
var reader = file.reader(&in_buf);
var reader = file.reader(io, &in_buf);

const output = try std.fs.cwd().createFile(output_path, .{});
defer output.close();
const output = try Io.Dir.cwd().createFile(io, output_path, .{});
defer output.close(io);
var out_buf: [4096]u8 = undefined;
var writer = output.writer(&out_buf);
var writer = output.writer(io, &out_buf);

var state: State = .copy;

Expand Down Expand Up @@ -134,4 +137,5 @@ const Chunk = struct {

const std = @import("std");
const Allocator = std.mem.Allocator;
const File = std.fs.File;
const Io = std.Io;
const File = Io.File;
30 changes: 17 additions & 13 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.PHONY: test docs

test_zig_nightly:
zig build test --summary failures -Dlang=lua51
# FIXME: reenable after resolution of https://codeberg.org/ziglang/translate-c/issues/282
# zig build test --summary failures -Dlang=lua51
zig build test --summary failures -Dlang=lua52
zig build test --summary failures -Dlang=lua53
zig build test --summary failures -Dlang=lua54
Expand All @@ -11,7 +12,8 @@ test_zig_nightly:
zig build install-example-zig-function
zig build -Dlang=luau install-example-luau-bytecode

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

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

test_cross:
zig build -Dlang=lua51 -Dtarget=aarch64-linux
zig build -Dlang=lua51 -Dtarget=aarch64-linux-gnu
zig build -Dlang=luajit -Dtarget=aarch64-linux
zig build -Dlang=luajit -Dtarget=aarch64-linux-gnu

zig build -Dlang=lua51 -Dtarget=x86_64-linux
zig build -Dlang=lua51 -Dtarget=x86_64-linux-gnu
zig build -Dlang=luajit -Dtarget=x86_64-linux
zig build -Dlang=luajit -Dtarget=x86_64-linux-gnu

zig build -Dlang=luajit -Dtarget=aarch64-macos
# TODO: audit this; is it expected that cross-compilation should be an issue?
# FIXME: reenable after resolution of https://codeberg.org/ziglang/translate-c/issues/282
# zig build -Dlang=lua51 -Dtarget=aarch64-linux
# zig build -Dlang=lua51 -Dtarget=aarch64-linux-gnu
# zig build -Dlang=luajit -Dtarget=aarch64-linux
# zig build -Dlang=luajit -Dtarget=aarch64-linux-gnu
#
# zig build -Dlang=lua51 -Dtarget=x86_64-linux
# zig build -Dlang=lua51 -Dtarget=x86_64-linux-gnu
# zig build -Dlang=luajit -Dtarget=x86_64-linux
# zig build -Dlang=luajit -Dtarget=x86_64-linux-gnu
#
# zig build -Dlang=luajit -Dtarget=aarch64-macos

docs:
zig build docs
Loading