Skip to content

Commit 8441cf6

Browse files
committed
Added caching functionallity to improve compiling speed
1 parent 5d42853 commit 8441cf6

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

build.zig

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
const std = @import("std");
22
const this = @This();
33

4+
var _cfitsio_lib_cache: ?*std.Build.Step.Compile = null;
5+
fn getCfitsio(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Step.Compile {
6+
if (_cfitsio_lib_cache) |lib| return lib;
7+
8+
_cfitsio_lib_cache = createCfitsio(b, target, optimize);
9+
return _cfitsio_lib_cache.?;
10+
}
11+
12+
var _zlib_lib_cache: ?*std.Build.Step.Compile = null;
13+
fn getZlib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Step.Compile {
14+
if (_zlib_lib_cache) |lib| return lib;
15+
16+
_zlib_lib_cache = createZlib(b, target, optimize);
17+
return _zlib_lib_cache.?;
18+
}
19+
420
fn getModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Module {
521
if (b.modules.contains("zfitsio")) {
622
return b.modules.get("zfitsio").?;
@@ -18,12 +34,12 @@ pub fn build(b: *std.Build) !void {
1834
const use_system_libs = b.option(bool, "use-system-libs", "Use system-installed libraries instead of building from source") orelse false;
1935

2036
const zlib_lib = if (!use_system_libs)
21-
createZlib(b, target, optimize) orelse unreachable
37+
getZlib(b, target, optimize)
2238
else
2339
null;
2440

2541
const cfitsio_lib = if (!use_system_libs) blk: {
26-
const lib = createCfitsio(b, target, optimize) orelse unreachable;
42+
const lib = getCfitsio(b, target, optimize);
2743
if (zlib_lib) |zl| lib.linkLibrary(zl);
2844
break :blk lib;
2945
} else null;

0 commit comments

Comments
 (0)