@ -9,12 +9,15 @@ pub fn build_zlib(comptime subdir: []const u8, b: *std.Build, target: std.Build.
statlibname = " z " ;
}
const statlib = b . addStaticLibrary ( . {
const statlib = b . addLibrary ( . {
. linkage = . static ,
. name = statlibname ,
. target = target ,
. optimize = optimize ,
. root_module = b . createModule ( . {
. target = target ,
. optimize = optimize ,
} ) ,
} ) ;
var zlib_flags = std . ArrayList ( [ ] const u8 ) . init ( b . allocator ) ;
var zlib_flags = std . array_list . Managed ( [ ] const u8 ) . init ( b . allocator ) ;
defer zlib_flags . deinit ( ) ;
/ / try zlib_flags . appendSlice ( & . { " -Wall " , " -static-libgcc " , " -Wno-error=implicit-function-declaration " , " -O3 " } ) ; / / DL_info undeclared
/ / try zlib_flags . appendSlice ( & . { " -Wall " , " -static-libgcc " , " -O3 " } ) ; / / DL_info undeclared
@ -32,10 +35,10 @@ pub fn build_zlib(comptime subdir: []const u8, b: *std.Build, target: std.Build.
/ / try zlib_flags . appendSlice ( & . { " -O " } ) ; / / C99 and later do not support implicit function declarations
/ / try zlib_flags . appendSlice ( & . { " -O3 " , " -Wall " , " -Wwrite-strings " , " -Wpointer-arith " , " -Wconversion " , " -Wstrict-prototypes " , " -Wmissing-prototypes " } ) ;
var zlib_sources = std . ArrayList ( [ ] const u8 ) . init ( b . allocator ) ;
var zlib_sources = std . array_list . Managed ( [ ] const u8 ) . init ( b . allocator ) ;
{
var dir = try fs . cwd ( ) . openDir ( subdir , . { . iterate = true } ) ;
defer dir . close ( ) ;
var dir = try std . Io . Dir . cwd ( ) . openDir ( b . graph . io , subdir , . { . iterate = true } ) ;
defer dir . close ( b . graph . io ) ;
/ / var walker = try dir . walk ( b . allocator ) ;
/ / defer walker . deinit ( ) ;
@ -44,7 +47,7 @@ pub fn build_zlib(comptime subdir: []const u8, b: *std.Build, target: std.Build.
const allowed_exts = [ _ ] [ ] const u8 {
" .c " ,
} ;
while ( try it . next ( ) ) | entry | {
while ( try it . next ( b . graph . io ) ) | entry | {
if ( entry . kind = = . file ) {
const ext = fs . path . extension ( entry . name ) ;
const include_file = for ( allowed_exts ) | e | {
@ -59,15 +62,15 @@ pub fn build_zlib(comptime subdir: []const u8, b: *std.Build, target: std.Build.
}
}
}
statlib . linkLibC ( ) ;
statlib . addIncludePath ( b . path ( subdir ) ) ;
statlib . addIncludePath ( b . path ( subdir + + " /contrib/minzip " ) ) ;
statlib . addCSourceFiles ( . {
statlib . root_module . link_libc = true ;
statlib . root_module . addIncludePath ( b . path ( subdir ) ) ;
statlib . root_module . addIncludePath ( b . path ( subdir + + " /contrib/minzip " ) ) ;
statlib . root_module . addCSourceFiles ( . {
. files = zlib_sources . items ,
. flags = zlib_flags . items ,
} ) ;
b . installArtifact ( statlib ) ;
var dylib_flags = std . ArrayList ( [ ] const u8 ) . init ( b . allocator ) ;
var dylib_flags = std . array_list . Managed ( [ ] const u8 ) . init ( b . allocator ) ;
try dylib_flags . appendSlice ( zlib_flags . items ) ;
/ / trial
@ -79,82 +82,95 @@ pub fn build_zlib(comptime subdir: []const u8, b: *std.Build, target: std.Build.
/ / " -Wl,-out-implib,libz.dll.a " , / / seems to have no effect . zig always creates a . lib
/ / " -DZLIB_WINAPI " ,
/ / " -Wl,-exclude-libs=ALL " ,
std . debug . print ( " build_zlib.zig flags {s} \n " , . { dylib_flags . items } ) ;
const dylib = b . addSharedLibrary ( . {
std . debug . print ( " build_zlib.zig flags: " , . { } ) ;
for ( dylib_flags . items ) | f | std . debug . print ( " {s} " , . { f } ) ;
std . debug . print ( " \n " , . { } ) ;
const dylib = b . addLibrary ( . {
. linkage = . dynamic ,
. name = " zlib1 " ,
. target = target ,
. optimize = optimize ,
. root_module = b . createModule ( . {
. target = target ,
. optimize = optimize ,
} ) ,
} ) ;
dylib . linkLibC ( ) ;
dylib . addIncludePath ( b . path ( subdir ) ) ;
dylib . addIncludePath ( b . path ( subdir + + " /contrib/minizip " ) ) ;
dylib . addCSourceFiles ( . {
dylib . root_module . link_libc = true ;
dylib . root_module . addIncludePath ( b . path ( subdir ) ) ;
dylib . root_module . addIncludePath ( b . path ( subdir + + " /contrib/minizip " ) ) ;
dylib . root_module . addCSourceFiles ( . {
. files = zlib_sources . items ,
. flags = dylib_flags . items ,
} ) ;
/ / dylib . addWin32ResourceFile ( . { . file = . { . path = " zlib/win32/zlib1.rc " } } ) ; / / ignored for non - windows targets
dylib . addWin32ResourceFile ( . { . file = b . path ( subdir + + " /win32/zlib1.rc " ) } ) ; / / ignored for non - windows targets
/ / dylib . root_module . addWin32ResourceFile ( . { . file = . { . path = " zlib/win32/zlib1.rc " } } ) ; / / ignored for non - windows targets
dylib . root_module . addWin32ResourceFile ( . { . file = b . path ( subdir + + " /win32/zlib1.rc " ) } ) ; / / ignored for non - windows targets
b . installArtifact ( dylib ) ;
const mgz_exe = b . addExecutable ( . {
. name = " minigzip " ,
. target = target ,
. optimize = optimize ,
. root_module = b . createModule ( . {
. target = target ,
. optimize = optimize ,
} ) ,
} ) ;
mgz_exe . step . dependOn ( & statlib . step ) ;
mgz_exe . addIncludePath ( b . path ( subdir ) ) ;
mgz_exe . addCSourceFile ( . {
mgz_exe . root_module . addIncludePath ( b . path ( subdir ) ) ;
mgz_exe . root_module . addCSourceFile ( . {
. file = b . path ( subdir + + " /test/minigzip.c " ) ,
. flags = zlib_flags . items ,
} ) ;
mgz_exe . linkLibC ( ) ;
mgz_exe . linkLibrary ( statlib ) ;
mgz_exe . root_module . link_libc = true ;
mgz_exe . root_module . linkLibrary ( statlib ) ;
b . installArtifact ( mgz_exe ) ;
const eg_exe = b . addExecutable ( . {
. name = " zlib_example " ,
. target = target ,
. optimize = optimize ,
. root_module = b . createModule ( . {
. target = target ,
. optimize = optimize ,
} ) ,
} ) ;
eg_exe . step . dependOn ( & statlib . step ) ;
eg_exe . addIncludePath ( b . path ( subdir ) ) ;
eg_exe . addCSourceFile ( . {
eg_exe . root_module . addIncludePath ( b . path ( subdir ) ) ;
eg_exe . root_module . addCSourceFile ( . {
. file = b . path ( subdir + + " /test/example.c " ) ,
. flags = zlib_flags . items ,
} ) ;
eg_exe . linkLibC ( ) ;
eg_exe . linkLibrary ( statlib ) ;
eg_exe . root_module . link_libc = true ;
eg_exe . root_module . linkLibrary ( statlib ) ;
b . installArtifact ( eg_exe ) ;
const egd_exe = b . addExecutable ( . {
. name = " zlib_example_d " ,
. target = target ,
. optimize = optimize ,
. root_module = b . createModule ( . {
. target = target ,
. optimize = optimize ,
} ) ,
} ) ;
egd_exe . step . dependOn ( & statlib . step ) ;
egd_exe . addIncludePath ( b . path ( subdir ) ) ;
egd_exe . addCSourceFile ( . {
egd_exe . root_module . addIncludePath ( b . path ( subdir ) ) ;
egd_exe . root_module . addCSourceFile ( . {
. file = b . path ( subdir + + " /test/example.c " ) ,
. flags = dylib_flags . items ,
} ) ;
egd_exe . linkLibrary ( dylib ) ;
egd_exe . root_module . linkLibrary ( dylib ) ;
egd_exe . root_module . addRPathSpecial ( " $ORIGIN/../lib " ) ;
egd_exe . linkLibC ( ) ;
egd_exe . root_module . link_libc = true ;
b . installArtifact ( egd_exe ) ;
const mgzd_exe = b . addExecutable ( . {
. name = " minigzip_d " ,
. target = target ,
. optimize = optimize ,
. root_module = b . createModule ( . {
. target = target ,
. optimize = optimize ,
} ) ,
} ) ;
mgzd_exe . step . dependOn ( & statlib . step ) ;
mgzd_exe . addIncludePath ( b . path ( subdir ) ) ;
mgzd_exe . addCSourceFile ( . {
mgzd_exe . root_module . addIncludePath ( b . path ( subdir ) ) ;
mgzd_exe . root_module . addCSourceFile ( . {
. file = b . path ( subdir + + " /test/minigzip.c " ) ,
. flags = dylib_flags . items ,
} ) ;
mgzd_exe . root_module . addRPathSpecial ( " $ORIGIN/../lib " ) ;
mgzd_exe . linkLibrary ( dylib ) ;
mgzd_exe . root_module . linkLibrary ( dylib ) ;
b . installArtifact ( mgzd_exe ) ;
return statlib ;