pkg/wuffs: define build defines separately, not in defs.zig

This commit is contained in:
Mitchell Hashimoto
2024-09-02 20:27:39 -07:00
parent d6e5c8e20f
commit c6e187865a
3 changed files with 27 additions and 38 deletions

View File

@ -1,6 +1,6 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
@ -13,18 +13,16 @@ pub fn build(b: *std.Build) void {
.link_libc = true,
});
module.addIncludePath(wuffs.path("release/c"));
module.addCSourceFile(
.{
.file = wuffs.path("release/c/wuffs-v0.4.c"),
.flags = f: {
const flags = @import("src/defs.zig").build;
var a: [flags.len][]const u8 = undefined;
inline for (flags, 0..) |flag, i| {
a[i] = "-D" ++ flag ++ "=1";
var flags = std.ArrayList([]const u8).init(b.allocator);
defer flags.deinit();
try flags.append("-DWUFFS_IMPLEMENTATION");
inline for (@import("src/c.zig").defines) |key| {
try flags.append("-D" ++ key);
}
break :f &a;
},
},
);
module.addIncludePath(wuffs.path("release/c"));
module.addCSourceFile(.{
.file = wuffs.path("release/c/wuffs-v0.4.c"),
.flags = flags.items,
});
}

View File

@ -1,6 +1,18 @@
pub const c = @cImport({
for (@import("defs.zig").cimport) |d| {
@cDefine(d, "1");
}
for (defines) |d| @cDefine(d, "1");
@cInclude("wuffs-v0.4.c");
});
/// All the C macros defined so that the header matches the build.
pub const defines: []const []const u8 = &[_][]const u8{
"WUFFS_CONFIG__MODULES",
"WUFFS_CONFIG__MODULE__AUX__BASE",
"WUFFS_CONFIG__MODULE__AUX__IMAGE",
"WUFFS_CONFIG__MODULE__BASE",
"WUFFS_CONFIG__MODULE__ADLER32",
"WUFFS_CONFIG__MODULE__CRC32",
"WUFFS_CONFIG__MODULE__DEFLATE",
"WUFFS_CONFIG__MODULE__JPEG",
"WUFFS_CONFIG__MODULE__PNG",
"WUFFS_CONFIG__MODULE__ZLIB",
};

View File

@ -1,21 +0,0 @@
//! Define all of the C macros that WUFFS uses to configure itself here so
//! that the settings used to import the C "header" file stay in sync with the
//! settings used build the C "source" file.
pub const cimport = [_][]const u8{
"WUFFS_CONFIG__MODULES",
"WUFFS_CONFIG__MODULE__AUX__BASE",
"WUFFS_CONFIG__MODULE__AUX__IMAGE",
"WUFFS_CONFIG__MODULE__BASE",
"WUFFS_CONFIG__MODULE__ADLER32",
"WUFFS_CONFIG__MODULE__CRC32",
"WUFFS_CONFIG__MODULE__DEFLATE",
"WUFFS_CONFIG__MODULE__JPEG",
"WUFFS_CONFIG__MODULE__PNG",
"WUFFS_CONFIG__MODULE__ZLIB",
};
// The only difference should be that the "build" defines WUFFS_IMPLEMENTATION
pub const build = [_][]const u8{
"WUFFS_IMPLEMENTATION",
} ++ cimport;