Skip to content

Commit

Permalink
Link libc by default unless -Dno-libc is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix "xq" Queißner committed Jun 18, 2024
1 parent 68dbbe1 commit 6c9fcec
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const link_libc = !(b.option(bool, "no-libc", "Prevents linking of libc by default") orelse false);

const config = blk: {
var config = Config{};

Expand Down Expand Up @@ -142,14 +144,14 @@ pub fn build(b: *std.Build) void {
});
zfat_lib.installHeader(b.path("src/fatfs/ff.h"), "ff.h");
zfat_lib.installHeader(b.path("src/fatfs/diskio.h"), "diskio.h");
initialize_mod(b, &zfat_lib.root_module, config);
initialize_mod(b, &zfat_lib.root_module, config, link_libc);

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

// usage demo:
Expand All @@ -176,7 +178,7 @@ 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 {
fn initialize_mod(b: *std.Build, mod: *std.Build.Module, config: Config, link_libc: bool) void {
mod.addIncludePath(b.path("src/fatfs"));
mod.addCSourceFiles(.{
.root = b.path("src/fatfs"),
Expand All @@ -189,7 +191,7 @@ fn initialize_mod(b: *std.Build, mod: *std.Build.Module, config: Config) void {
});
apply_public_config(b, mod, config);
apply_private_config(b, mod, config);
mod.link_libc = true;
mod.link_libc = link_libc;
}

fn apply_public_config(b: *std.Build, module: *std.Build.Module, config: Config) void {
Expand Down

0 comments on commit 6c9fcec

Please sign in to comment.