Skip to content

Commit

Permalink
Matches module and library more closely
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix "xq" Queißner committed Jun 17, 2024
1 parent 629ec4f commit 68dbbe1
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -140,32 +140,17 @@ pub fn build(b: *std.Build) void {
.target = target,
.optimize = optimize,
});
zfat_lib.addIncludePath(b.path("src/fatfs"));
zfat_lib.installHeader(b.path("src/fatfs/ff.h"), "ff.h");
zfat_lib.installHeader(b.path("src/fatfs/diskio.h"), "diskio.h");
zfat_lib.addCSourceFiles(.{
.root = b.path("src/fatfs"),
.files = &.{
"ff.c",
"ffunicode.c",
"ffsystem.c",
},
.flags = &.{"-std=c99"},
});
zfat_lib.linkLibC();
apply_public_config(b, &zfat_lib.root_module, config);
apply_private_config(b, &zfat_lib.root_module, config);
initialize_mod(b, &zfat_lib.root_module, config);

const zfat_mod = b.addModule("zfat", .{
.root_source_file = b.path("src/fatfs.zig"),
.target = target,
.optimize = optimize,
});
zfat_mod.linkLibrary(zfat_lib);
zfat_mod.addIncludePath(b.path("src/fatfs"));
initialize_mod(b, zfat_mod, config);
zfat_mod.addOptions("config", mod_options);
zfat_mod.link_libc = true;
apply_public_config(b, zfat_mod, config);

// usage demo:

Expand All @@ -191,6 +176,22 @@ pub fn build(b: *std.Build) void {
run_step.dependOn(&run_cmd.step);
}

fn initialize_mod(b: *std.Build, mod: *std.Build.Module, config: Config) void {
mod.addIncludePath(b.path("src/fatfs"));
mod.addCSourceFiles(.{
.root = b.path("src/fatfs"),
.files = &.{
"ff.c",
"ffunicode.c",
"ffsystem.c",
},
.flags = &.{"-std=c99"},
});
apply_public_config(b, mod, config);
apply_private_config(b, mod, config);
mod.link_libc = true;
}

fn apply_public_config(b: *std.Build, module: *std.Build.Module, config: Config) void {
switch (config.volumes) {
.count => |count| {
Expand Down

0 comments on commit 68dbbe1

Please sign in to comment.