1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 15:14:08 +00:00

build: ensure submodule

This commit is contained in:
Rene Schallner 2023-01-11 15:47:32 +01:00
parent 3ebdfc656f
commit 68e197cc21
2 changed files with 23 additions and 7 deletions

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# zap - make zig web apps great again
## wraps `facil.io` lib

View file

@ -5,7 +5,7 @@ const facilio = std.build.Pkg{
.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
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
@ -15,7 +15,7 @@ pub fn build(b: *std.build.Builder) void {
lib.setBuildMode(mode);
lib.addPackage(facilio);
const lib_facilio = addFacilioLib(lib);
const lib_facilio = try addFacilioLib(lib);
lib.linkLibrary(lib_facilio);
lib.install();
@ -26,10 +26,11 @@ pub fn build(b: *std.build.Builder) void {
test_step.dependOn(&main_tests.step);
}
pub fn addFacilioLib(exe: *std.build.LibExeObjStep) *std.build.LibExeObjStep {
pub fn addFacilioLib(exe: *std.build.LibExeObjStep) !*std.build.LibExeObjStep {
ensureGit(exe.builder.allocator);
try ensureSubmodule(exe.builder.allocator, "src/deps/facilio");
ensureMake(exe.builder.allocator);
makeFacilioLibdump(exe.builder.allocator) catch unreachable;
try makeFacilioLibdump(exe.builder.allocator);
var b = exe.builder;
var lib_facilio = b.addStaticLibrary("facilio", null);
@ -37,9 +38,9 @@ pub fn addFacilioLib(exe: *std.build.LibExeObjStep) *std.build.LibExeObjStep {
// 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;
if (b.is_release) try flags.append("-Os");
try flags.append("-Wno-return-type-c-linkage");
try flags.append("-fno-sanitize=undefined");
lib_facilio.addIncludePath("./src/deps/facilio/libdump/all");
@ -93,6 +94,18 @@ fn ensureGit(allocator: std.mem.Allocator) void {
}
}
fn ensureSubmodule(allocator: std.mem.Allocator, path: []const u8) !void {
if (std.process.getEnvVarOwned(allocator, "NO_ENSURE_SUBMODULES")) |no_ensure_submodules| {
defer allocator.free(no_ensure_submodules);
if (std.mem.eql(u8, no_ensure_submodules, "true")) return;
} else |_| {}
var child = std.ChildProcess.init(&.{ "git", "submodule", "update", "--init", path }, allocator);
child.cwd = sdkPath("/");
child.stderr = std.io.getStdErr();
child.stdout = std.io.getStdOut();
_ = try child.spawnAndWait();
}
fn ensureMake(allocator: std.mem.Allocator) void {
const result = std.ChildProcess.exec(.{
.allocator = allocator,