1
1
const std = @import ("std" );
2
2
const this = @This ();
3
3
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
+
4
20
fn getModule (b : * std.Build , target : std.Build.ResolvedTarget , optimize : std.builtin.OptimizeMode ) * std.Build.Module {
5
21
if (b .modules .contains ("zfitsio" )) {
6
22
return b .modules .get ("zfitsio" ).? ;
@@ -18,12 +34,12 @@ pub fn build(b: *std.Build) !void {
18
34
const use_system_libs = b .option (bool , "use-system-libs" , "Use system-installed libraries instead of building from source" ) orelse false ;
19
35
20
36
const zlib_lib = if (! use_system_libs )
21
- createZlib (b , target , optimize ) orelse unreachable
37
+ getZlib (b , target , optimize )
22
38
else
23
39
null ;
24
40
25
41
const cfitsio_lib = if (! use_system_libs ) blk : {
26
- const lib = createCfitsio (b , target , optimize ) orelse unreachable ;
42
+ const lib = getCfitsio (b , target , optimize );
27
43
if (zlib_lib ) | zl | lib .linkLibrary (zl );
28
44
break :blk lib ;
29
45
} else null ;
0 commit comments