mirror of
https://github.com/allyourcodebase/lua.git
synced 2026-05-01 11:17:58 +02:00
Merge e725cba50c into 5a5a4135cb
This commit is contained in:
commit
03fcffe53c
2 changed files with 120 additions and 173 deletions
285
build.zig
285
build.zig
|
|
@ -6,11 +6,8 @@ const OptimizeMode = std.builtin.OptimizeMode;
|
||||||
const version = std.SemanticVersion{
|
const version = std.SemanticVersion{
|
||||||
.major = 5,
|
.major = 5,
|
||||||
.minor = 4,
|
.minor = 4,
|
||||||
.patch = 7,
|
.patch = 8,
|
||||||
};
|
};
|
||||||
const lib_name = "lua";
|
|
||||||
const exe_name = lib_name ++ "_exe";
|
|
||||||
const compiler_name = "luac";
|
|
||||||
|
|
||||||
pub fn build(b: *Build) !void {
|
pub fn build(b: *Build) !void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
|
|
@ -25,132 +22,139 @@ pub fn build(b: *Build) !void {
|
||||||
|
|
||||||
const lua_src = b.dependency("lua", .{});
|
const lua_src = b.dependency("lua", .{});
|
||||||
|
|
||||||
const lib =
|
const static = b.addModule("staticlib", .{
|
||||||
b.addStaticLibrary(artifactOptions(
|
.link_libc = true,
|
||||||
.{ .shared = false },
|
|
||||||
.{ .target = target, .optimize = optimize },
|
|
||||||
));
|
|
||||||
const shared = if (build_shared)
|
|
||||||
b.addSharedLibrary(artifactOptions(
|
|
||||||
.{ .shared = true },
|
|
||||||
.{ .target = target, .optimize = optimize },
|
|
||||||
))
|
|
||||||
else
|
|
||||||
null;
|
|
||||||
const exe = b.addExecutable(artifactOptions(.exe, .{
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
}));
|
|
||||||
const exec = b.addExecutable(artifactOptions(.exec, .{
|
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
});
|
||||||
}));
|
static.addCSourceFiles(.{
|
||||||
if (!target.result.isMinGW()) {
|
|
||||||
lib.linkSystemLibrary("m");
|
|
||||||
exe.linkSystemLibrary("m");
|
|
||||||
exec.linkSystemLibrary("m");
|
|
||||||
}
|
|
||||||
const build_targets = [_]?*Build.Step.Compile{
|
|
||||||
lib,
|
|
||||||
exe,
|
|
||||||
exec,
|
|
||||||
shared,
|
|
||||||
};
|
|
||||||
// Common compile flags
|
|
||||||
for (&build_targets) |tr| {
|
|
||||||
if (tr == null)
|
|
||||||
continue;
|
|
||||||
const t = tr.?;
|
|
||||||
t.linkLibC();
|
|
||||||
t.addIncludePath(lua_src.path("src"));
|
|
||||||
switch (target.result.os.tag) {
|
|
||||||
.aix => {
|
|
||||||
t.root_module.addCMacro("LUA_USE_POSIX", "");
|
|
||||||
t.root_module.addCMacro("LUA_USE_DLOPEN", "");
|
|
||||||
t.linkSystemLibrary("dl");
|
|
||||||
},
|
|
||||||
.freebsd, .netbsd, .openbsd => {
|
|
||||||
t.root_module.addCMacro("LUA_USE_LINUX", "");
|
|
||||||
t.root_module.addCMacro("LUA_USE_READLINE", "");
|
|
||||||
t.addIncludePath(.{ .cwd_relative = "/usr/include/edit" });
|
|
||||||
t.linkSystemLibrary("edit");
|
|
||||||
},
|
|
||||||
.ios => {
|
|
||||||
t.root_module.addCMacro("LUA_USE_IOS", "");
|
|
||||||
},
|
|
||||||
.linux => {
|
|
||||||
t.root_module.addCMacro("LUA_USE_LINUX", "");
|
|
||||||
t.linkSystemLibrary("dl");
|
|
||||||
if (use_readline.?) {
|
|
||||||
t.root_module.addCMacro("LUA_USE_READLINE", "");
|
|
||||||
t.linkSystemLibrary("readline");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
.macos => {
|
|
||||||
t.root_module.addCMacro("LUA_USE_MACOSX", "");
|
|
||||||
t.root_module.addCMacro("LUA_USE_READLINE", "");
|
|
||||||
t.linkSystemLibrary("readline");
|
|
||||||
},
|
|
||||||
.solaris => {
|
|
||||||
t.root_module.addCMacro("LUA_USE_POSIX", "");
|
|
||||||
t.root_module.addCMacro("LUA_USE_DLOPEN", "");
|
|
||||||
t.root_module.addCMacro("_REENTRANT", "");
|
|
||||||
t.linkSystemLibrary("dl");
|
|
||||||
},
|
|
||||||
else => {},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (target.result.isMinGW()) {
|
|
||||||
lib.root_module.addCMacro("LUA_BUILD_AS_DLL", "");
|
|
||||||
exe.root_module.addCMacro("LUA_BUILD_AS_DLL", "");
|
|
||||||
}
|
|
||||||
if (shared) |s| {
|
|
||||||
s.addCSourceFiles(.{
|
|
||||||
.root = lua_src.path("src"),
|
|
||||||
.files = &base_src,
|
|
||||||
.flags = &cflags,
|
|
||||||
});
|
|
||||||
|
|
||||||
s.installHeadersDirectory(
|
|
||||||
lua_src.path("src"),
|
|
||||||
"",
|
|
||||||
.{ .include_extensions = &lua_inc },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
lib.addCSourceFiles(.{
|
|
||||||
.root = lua_src.path("src"),
|
.root = lua_src.path("src"),
|
||||||
.files = &base_src,
|
.files = &base_src,
|
||||||
.flags = &cflags,
|
.flags = &cflags,
|
||||||
});
|
});
|
||||||
|
|
||||||
lib.installHeadersDirectory(
|
const shared = b.addModule("sharedlib", .{
|
||||||
lua_src.path("src"),
|
.link_libc = true,
|
||||||
"",
|
.optimize = optimize,
|
||||||
.{ .include_extensions = &lua_inc },
|
.target = target,
|
||||||
);
|
.strip = if (target.result.os.tag == .windows) true else null,
|
||||||
|
});
|
||||||
|
shared.addCSourceFiles(.{
|
||||||
|
.root = lua_src.path("src"),
|
||||||
|
.files = &base_src,
|
||||||
|
.flags = &cflags,
|
||||||
|
});
|
||||||
|
|
||||||
|
const exe = b.addModule("interpreter", .{
|
||||||
|
.link_libc = true,
|
||||||
|
.optimize = optimize,
|
||||||
|
.target = target,
|
||||||
|
});
|
||||||
exe.addCSourceFile(.{
|
exe.addCSourceFile(.{
|
||||||
.file = lua_src.path("src/lua.c"),
|
.file = lua_src.path("src/lua.c"),
|
||||||
.flags = &cflags,
|
.flags = &cflags,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const exec = b.addModule("compiler", .{
|
||||||
|
.link_libc = true,
|
||||||
|
.optimize = optimize,
|
||||||
|
.target = target,
|
||||||
|
});
|
||||||
exec.addCSourceFile(.{
|
exec.addCSourceFile(.{
|
||||||
.file = lua_src.path("src/luac.c"),
|
.file = lua_src.path("src/luac.c"),
|
||||||
.flags = &cflags,
|
.flags = &cflags,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (shared) |s| {
|
// Common compile flags
|
||||||
exe.linkLibrary(s);
|
for (&[_]*Build.Module{ static, shared, exe, exec }) |mod| {
|
||||||
b.installArtifact(s);
|
const link = mod != shared;
|
||||||
} else {
|
|
||||||
exe.linkLibrary(lib);
|
mod.addIncludePath(lua_src.path("src"));
|
||||||
b.installArtifact(lib);
|
if (link and !target.result.isMinGW())
|
||||||
|
mod.linkSystemLibrary("m", .{});
|
||||||
|
|
||||||
|
switch (target.result.os.tag) {
|
||||||
|
.aix => {
|
||||||
|
mod.addCMacro("LUA_USE_POSIX", "");
|
||||||
|
mod.addCMacro("LUA_USE_DLOPEN", "");
|
||||||
|
if (link)
|
||||||
|
mod.linkSystemLibrary("dl", .{});
|
||||||
|
},
|
||||||
|
.freebsd, .netbsd, .openbsd => {
|
||||||
|
mod.addCMacro("LUA_USE_LINUX", "");
|
||||||
|
mod.addCMacro("LUA_USE_READLINE", "");
|
||||||
|
mod.addIncludePath(.{ .cwd_relative = "/usr/include/edit" });
|
||||||
|
if (link)
|
||||||
|
mod.linkSystemLibrary("edit", .{});
|
||||||
|
},
|
||||||
|
.ios => {
|
||||||
|
mod.addCMacro("LUA_USE_IOS", "");
|
||||||
|
},
|
||||||
|
.linux => {
|
||||||
|
mod.addCMacro("LUA_USE_LINUX", "");
|
||||||
|
if (link)
|
||||||
|
mod.linkSystemLibrary("dl", .{});
|
||||||
|
if (use_readline.?) {
|
||||||
|
mod.addCMacro("LUA_USE_READLINE", "");
|
||||||
|
if (link)
|
||||||
|
mod.linkSystemLibrary("readline", .{});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.macos => {
|
||||||
|
mod.addCMacro("LUA_USE_MACOSX", "");
|
||||||
|
mod.addCMacro("LUA_USE_READLINE", "");
|
||||||
|
if (link)
|
||||||
|
mod.linkSystemLibrary("readline", .{});
|
||||||
|
},
|
||||||
|
.solaris => {
|
||||||
|
mod.addCMacro("LUA_USE_POSIX", "");
|
||||||
|
mod.addCMacro("LUA_USE_DLOPEN", "");
|
||||||
|
mod.addCMacro("_REENTRANT", "");
|
||||||
|
if (link)
|
||||||
|
mod.linkSystemLibrary("dl", .{});
|
||||||
|
},
|
||||||
|
else => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (target.result.isMinGW()) {
|
||||||
|
static.addCMacro("LUA_BUILD_AS_DLL", "");
|
||||||
|
exe.addCMacro("LUA_BUILD_AS_DLL", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
b.installArtifact(exe);
|
const sharedlib = b.addLibrary(.{
|
||||||
exec.linkLibrary(lib);
|
.name = "lua" ++ &[_]u8{
|
||||||
b.installArtifact(exec);
|
'0' + version.major, '0' + version.minor,
|
||||||
|
},
|
||||||
|
.root_module = shared,
|
||||||
|
.version = version,
|
||||||
|
.linkage = .dynamic,
|
||||||
|
});
|
||||||
|
b.installArtifact(sharedlib);
|
||||||
|
|
||||||
|
const staticlib =
|
||||||
|
b.addLibrary(.{
|
||||||
|
.name = "lua",
|
||||||
|
.root_module = static,
|
||||||
|
.version = version,
|
||||||
|
.linkage = .static,
|
||||||
|
});
|
||||||
|
b.installArtifact(staticlib);
|
||||||
|
|
||||||
|
exe.linkLibrary(if (build_shared) sharedlib else staticlib);
|
||||||
|
const lua_exe = b.addExecutable(.{
|
||||||
|
.name = "lua_exe",
|
||||||
|
.version = version,
|
||||||
|
.root_module = exe,
|
||||||
|
});
|
||||||
|
b.installArtifact(lua_exe);
|
||||||
|
|
||||||
|
exec.linkLibrary(staticlib);
|
||||||
|
const luac_exe = b.addExecutable(.{
|
||||||
|
.name = "luac",
|
||||||
|
.version = version,
|
||||||
|
.root_module = exe,
|
||||||
|
});
|
||||||
|
b.installArtifact(luac_exe);
|
||||||
|
|
||||||
b.installDirectory(.{
|
b.installDirectory(.{
|
||||||
.source_dir = lua_src.path("doc"),
|
.source_dir = lua_src.path("doc"),
|
||||||
|
|
@ -160,7 +164,8 @@ pub fn build(b: *Build) !void {
|
||||||
});
|
});
|
||||||
|
|
||||||
const run_step = b.step("run", "run lua interpreter");
|
const run_step = b.step("run", "run lua interpreter");
|
||||||
const run_cmd = b.addRunArtifact(exe);
|
const run_cmd = b.addRunArtifact(lua_exe);
|
||||||
|
if (b.args) |args| run_cmd.addArgs(args);
|
||||||
run_step.dependOn(&run_cmd.step);
|
run_step.dependOn(&run_cmd.step);
|
||||||
const unpack_step = b.step("unpack", "unpack source");
|
const unpack_step = b.step("unpack", "unpack source");
|
||||||
const unpack_cmd = b.addInstallDirectory(.{
|
const unpack_cmd = b.addInstallDirectory(.{
|
||||||
|
|
@ -170,64 +175,6 @@ pub fn build(b: *Build) !void {
|
||||||
});
|
});
|
||||||
unpack_step.dependOn(&unpack_cmd.step);
|
unpack_step.dependOn(&unpack_cmd.step);
|
||||||
}
|
}
|
||||||
const ArtifactTarget = union(enum) {
|
|
||||||
// True if shared options
|
|
||||||
shared: bool,
|
|
||||||
exe,
|
|
||||||
exec,
|
|
||||||
};
|
|
||||||
const ArtifactTargetOptions = struct {
|
|
||||||
target: ResolvedTarget,
|
|
||||||
optimize: OptimizeMode,
|
|
||||||
};
|
|
||||||
fn artifactOptions(comptime options: ArtifactTarget, opts: ArtifactTargetOptions) switch (options) {
|
|
||||||
.exe, .exec => Build.ExecutableOptions,
|
|
||||||
.shared => |shared| if (shared)
|
|
||||||
Build.SharedLibraryOptions
|
|
||||||
else
|
|
||||||
Build.StaticLibraryOptions,
|
|
||||||
} {
|
|
||||||
const t = opts.target.result.os.tag;
|
|
||||||
return switch (options) {
|
|
||||||
.shared => |shared| if (shared) blk: {
|
|
||||||
switch (t) {
|
|
||||||
.windows => break :blk .{
|
|
||||||
.name = lib_name ++ "54",
|
|
||||||
.target = opts.target,
|
|
||||||
.optimize = opts.optimize,
|
|
||||||
.strip = true,
|
|
||||||
},
|
|
||||||
else => break :blk .{
|
|
||||||
.name = lib_name,
|
|
||||||
.target = opts.target,
|
|
||||||
.optimize = opts.optimize,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
} else blk: {
|
|
||||||
switch (t) {
|
|
||||||
else => break :blk .{
|
|
||||||
.name = lib_name,
|
|
||||||
.target = opts.target,
|
|
||||||
.optimize = opts.optimize,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
.exe => switch (t) {
|
|
||||||
else => .{
|
|
||||||
.name = exe_name,
|
|
||||||
.target = opts.target,
|
|
||||||
.optimize = opts.optimize,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
.exec => switch (t) {
|
|
||||||
else => .{
|
|
||||||
.name = compiler_name,
|
|
||||||
.target = opts.target,
|
|
||||||
.optimize = opts.optimize,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const cflags = [_][]const u8{
|
const cflags = [_][]const u8{
|
||||||
"-std=gnu99",
|
"-std=gnu99",
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
.{
|
.{
|
||||||
.name = .lua,
|
.name = .lua,
|
||||||
.version = "5.4.7",
|
.version = "5.4.8",
|
||||||
.fingerprint = 0xd671372bcadcaace,
|
.fingerprint = 0xd671372bcadcaace,
|
||||||
|
|
||||||
.minimum_zig_version = "0.14.0",
|
.minimum_zig_version = "0.15.0",
|
||||||
|
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
.lua = .{
|
.lua = .{
|
||||||
.url = "https://www.lua.org/ftp/lua-5.4.7.tar.gz",
|
.url = "https://www.lua.org/ftp/lua-5.4.8.tar.gz",
|
||||||
.hash = "N-V-__8AAIMvFABt-Qcpk24RD10ldEN743D8Q2e19Er8x3dJ",
|
.hash = "N-V-__8AAKEzFAAA695b9LXBhUSVK5MAV_VKSm1mEj3Acbze",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue