mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 15:14:08 +00:00
first time facilio compiles
This commit is contained in:
parent
08d831cc31
commit
3ebdfc656f
2 changed files with 109 additions and 0 deletions
108
build.zig
108
build.zig
|
@ -1,12 +1,22 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
|
const facilio = std.build.Pkg{
|
||||||
|
.name = "facilio",
|
||||||
|
.source = std.build.FileSource{ .path = "src/deps/facilio.zig" },
|
||||||
|
};
|
||||||
|
|
||||||
pub fn build(b: *std.build.Builder) void {
|
pub fn build(b: *std.build.Builder) void {
|
||||||
|
|
||||||
// Standard release options allow the person running `zig build` to select
|
// Standard release options allow the person running `zig build` to select
|
||||||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
||||||
const mode = b.standardReleaseOptions();
|
const mode = b.standardReleaseOptions();
|
||||||
|
|
||||||
const lib = b.addStaticLibrary("zap", "src/main.zig");
|
const lib = b.addStaticLibrary("zap", "src/main.zig");
|
||||||
lib.setBuildMode(mode);
|
lib.setBuildMode(mode);
|
||||||
|
lib.addPackage(facilio);
|
||||||
|
|
||||||
|
const lib_facilio = addFacilioLib(lib);
|
||||||
|
lib.linkLibrary(lib_facilio);
|
||||||
lib.install();
|
lib.install();
|
||||||
|
|
||||||
const main_tests = b.addTest("src/main.zig");
|
const main_tests = b.addTest("src/main.zig");
|
||||||
|
@ -15,3 +25,101 @@ pub fn build(b: *std.build.Builder) void {
|
||||||
const test_step = b.step("test", "Run library tests");
|
const test_step = b.step("test", "Run library tests");
|
||||||
test_step.dependOn(&main_tests.step);
|
test_step.dependOn(&main_tests.step);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn addFacilioLib(exe: *std.build.LibExeObjStep) *std.build.LibExeObjStep {
|
||||||
|
ensureGit(exe.builder.allocator);
|
||||||
|
ensureMake(exe.builder.allocator);
|
||||||
|
makeFacilioLibdump(exe.builder.allocator) catch unreachable;
|
||||||
|
|
||||||
|
var b = exe.builder;
|
||||||
|
var lib_facilio = b.addStaticLibrary("facilio", null);
|
||||||
|
lib_facilio.linkLibC();
|
||||||
|
|
||||||
|
// Generate flags
|
||||||
|
var flags = std.ArrayList([]const u8).init(std.heap.page_allocator);
|
||||||
|
if (b.is_release) flags.append("-Os") catch unreachable;
|
||||||
|
flags.append("-Wno-return-type-c-linkage") catch unreachable;
|
||||||
|
flags.append("-fno-sanitize=undefined") catch unreachable;
|
||||||
|
|
||||||
|
lib_facilio.addIncludePath("./src/deps/facilio/libdump/all");
|
||||||
|
|
||||||
|
// legacy for fio_mem
|
||||||
|
lib_facilio.addIncludePath("src/deps/facilio/lib/facil/legacy");
|
||||||
|
|
||||||
|
// Add C
|
||||||
|
lib_facilio.addCSourceFiles(&.{
|
||||||
|
"src/deps/facilio/libdump/all/http.c",
|
||||||
|
"src/deps/facilio/libdump/all/fiobj_numbers.c",
|
||||||
|
"src/deps/facilio/libdump/all/fio_siphash.c",
|
||||||
|
"src/deps/facilio/libdump/all/fiobj_str.c",
|
||||||
|
"src/deps/facilio/libdump/all/http1.c",
|
||||||
|
"src/deps/facilio/libdump/all/fiobj_ary.c",
|
||||||
|
"src/deps/facilio/libdump/all/fiobj_data.c",
|
||||||
|
"src/deps/facilio/libdump/all/fiobj_hash.c",
|
||||||
|
"src/deps/facilio/libdump/all/websockets.c",
|
||||||
|
"src/deps/facilio/libdump/all/fiobj_json.c",
|
||||||
|
"src/deps/facilio/libdump/all/fio.c",
|
||||||
|
"src/deps/facilio/libdump/all/fiobject.c",
|
||||||
|
"src/deps/facilio/libdump/all/http_internal.c",
|
||||||
|
"src/deps/facilio/libdump/all/fiobj_mustache.c",
|
||||||
|
}, flags.items);
|
||||||
|
|
||||||
|
return lib_facilio;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sdkPath(comptime suffix: []const u8) []const u8 {
|
||||||
|
if (suffix[0] != '/') @compileError("suffix must be an absolute path");
|
||||||
|
return comptime blk: {
|
||||||
|
const root_dir = std.fs.path.dirname(@src().file) orelse ".";
|
||||||
|
break :blk root_dir ++ suffix;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ensureGit(allocator: std.mem.Allocator) void {
|
||||||
|
const result = std.ChildProcess.exec(.{
|
||||||
|
.allocator = allocator,
|
||||||
|
.argv = &.{ "git", "--version" },
|
||||||
|
}) catch { // e.g. FileNotFound
|
||||||
|
std.log.err("mach: error: 'git --version' failed. Is git not installed?", .{});
|
||||||
|
std.process.exit(1);
|
||||||
|
};
|
||||||
|
defer {
|
||||||
|
allocator.free(result.stderr);
|
||||||
|
allocator.free(result.stdout);
|
||||||
|
}
|
||||||
|
if (result.term.Exited != 0) {
|
||||||
|
std.log.err("mach: error: 'git --version' failed. Is git not installed?", .{});
|
||||||
|
std.process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ensureMake(allocator: std.mem.Allocator) void {
|
||||||
|
const result = std.ChildProcess.exec(.{
|
||||||
|
.allocator = allocator,
|
||||||
|
.argv = &.{ "make", "--version" },
|
||||||
|
}) catch { // e.g. FileNotFound
|
||||||
|
std.log.err("error: 'make --version' failed. Is make not installed?", .{});
|
||||||
|
std.process.exit(1);
|
||||||
|
};
|
||||||
|
defer {
|
||||||
|
allocator.free(result.stderr);
|
||||||
|
allocator.free(result.stdout);
|
||||||
|
}
|
||||||
|
if (result.term.Exited != 0) {
|
||||||
|
std.log.err("error: 'make --version' failed. Is make not installed?", .{});
|
||||||
|
std.process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn makeFacilioLibdump(allocator: std.mem.Allocator) !void {
|
||||||
|
var child = std.ChildProcess.init(&.{
|
||||||
|
"make",
|
||||||
|
"-C",
|
||||||
|
"./src/deps/facilio",
|
||||||
|
"libdump",
|
||||||
|
}, allocator);
|
||||||
|
child.cwd = sdkPath("/");
|
||||||
|
child.stderr = std.io.getStdErr();
|
||||||
|
child.stdout = std.io.getStdOut();
|
||||||
|
_ = try child.spawnAndWait();
|
||||||
|
}
|
||||||
|
|
1
src/deps/facilio.zig
Normal file
1
src/deps/facilio.zig
Normal file
|
@ -0,0 +1 @@
|
||||||
|
// zig type definitions for facilio lib
|
Loading…
Add table
Reference in a new issue