From b8cb059f637c60349cc0ebcbb2c0b50dea708341 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Thu, 27 Aug 2026 12:41:46 +0200 Subject: [PATCH] Add a build option to remove the freestanding libc --- .github/workflows/ci.yml | 1 + build.zig | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aefdd13d..5524ff38 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,6 +78,7 @@ jobs: zig build -Dtarget=x86_64-freebsd zig build -Dtarget=aarch64-freebsd zig build -Dtarget=wasm32-freestanding + zig build -Dtarget=wasm32-freestanding -Dwasm_freestanding_libc=false zig build -Doptimize=ReleaseFast rm -fr zig-cache zig-out diff --git a/build.zig b/build.zig index 929dd9cf..73c96566 100644 --- a/build.zig +++ b/build.zig @@ -183,6 +183,11 @@ pub fn build(b: *std.Build) !void { const enable_benchmarks = b.option(bool, "enable_benchmarks", "Whether tests should be benchmarks.") orelse false; const benchmarks_iterations = b.option(u32, "iterations", "Number of iterations for benchmarks.") orelse 200; + const wasm_freestanding_libc = b.option( + bool, + "wasm_freestanding_libc", + "Include the built-in libc compatibility layer for wasm32-freestanding.", + ) orelse true; var build_static = b.option(bool, "static", "Build libsodium as a static library.") orelse true; var build_shared = b.option(bool, "shared", "Build libsodium as a shared library.") orelse true; @@ -265,7 +270,7 @@ pub fn build(b: *std.Build) !void { "-Werror=vla", }; - if (wasm_freestanding) { + if (wasm_freestanding and wasm_freestanding_libc) { lib.root_module.addCSourceFiles(.{ .files = &.{wasm_libc_path ++ "/libc.c"}, .flags = flags,