motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 4219825042057ce901df1261e089ef477c381fe7 (tree)
parent 7be3b1de455c9cf247dc3ab8c4fd75c9b16d77cf
Author: Alex Rønne Petersen <alex@alexrp.com>
Date:   Mon,  1 Jun 2026 14:44:13 +0200

test: use -ffunction-sections -fdata-sections for C backend module tests if needed

We need this for certain targets for the same reason we do it when bootstrapping
the compiler from zig1.wasm.

Diffstat:
Mtest/tests.zig | 99++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 60 insertions(+), 39 deletions(-)

diff --git a/test/tests.zig b/test/tests.zig @@ -2811,45 +2811,66 @@ fn addOneModuleTest( compile_c.addCSourceFile(.{ .file = these_tests.getEmittedBin(), - .flags = &.{ - // Tracking issue for making the C backend generate C89 compatible code: - // https://github.com/ziglang/zig/issues/19468 - "-std=c99", - "-Werror", - - "-Wall", - "-Wembedded-directive", - "-Wempty-translation-unit", - "-Wextra", - "-Wgnu", - "-Winvalid-utf8", - "-Wkeyword-macro", - "-Woverlength-strings", - - // Tracking issue for making the C backend generate code - // that does not trigger warnings: - // https://github.com/ziglang/zig/issues/19467 - - // spotted everywhere - "-Wno-builtin-requires-header", - - // spotted on linux - "-Wno-braced-scalar-init", - "-Wno-excess-initializers", - "-Wno-incompatible-pointer-types-discards-qualifiers", - "-Wno-unused", - "-Wno-unused-parameter", - - // spotted on darwin - "-Wno-incompatible-pointer-types", - - // https://github.com/llvm/llvm-project/issues/153314 - "-Wno-unterminated-string-initialization", - - // In both Zig and C it is legal to return a pointer to a - // local. The C backend lowers such thing directly, so the - // corresponding warning in C must be disabled. - "-Wno-return-stack-address", + .flags = blk: { + const invariant_cflags: []const []const u8 = &.{ + // Tracking issue for making the C backend generate C89 compatible code: + // https://github.com/ziglang/zig/issues/19468 + "-std=c99", + "-Werror", + + "-Wall", + "-Wembedded-directive", + "-Wempty-translation-unit", + "-Wextra", + "-Wgnu", + "-Winvalid-utf8", + "-Wkeyword-macro", + "-Woverlength-strings", + + // Tracking issue for making the C backend generate code + // that does not trigger warnings: + // https://github.com/ziglang/zig/issues/19467 + + // spotted everywhere + "-Wno-builtin-requires-header", + + // spotted on linux + "-Wno-braced-scalar-init", + "-Wno-excess-initializers", + "-Wno-incompatible-pointer-types-discards-qualifiers", + "-Wno-unused", + "-Wno-unused-parameter", + + // spotted on darwin + "-Wno-incompatible-pointer-types", + + // https://github.com/llvm/llvm-project/issues/153314 + "-Wno-unterminated-string-initialization", + + // In both Zig and C it is legal to return a pointer to a + // local. The C backend lowers such thing directly, so the + // corresponding warning in C must be disabled. + "-Wno-return-stack-address", + }; + + const function_data_sections = switch (target.cpu.arch) { + .arm, + .armeb, + .thumb, + .thumbeb, + .hexagon, + .powerpc, + .powerpcle, + .powerpc64, + .powerpc64le, + => true, + else => false, + }; + + break :blk if (function_data_sections) invariant_cflags ++ &[_][]const u8{ + "-ffunction-sections", + "-fdata-sections", + } else invariant_cflags; }, }); compile_c.addIncludePath(b.path("lib")); // for zig.h