Commit 9d8adb38a1

Alex Rønne Petersen <alex@alexrp.com>
2025-04-02 14:36:21
std.Build: Make no_builtin a property of Module instead of Step.Compile.
This reflects how the compiler actually treats it. Closes #23424.
1 parent aa7c6dc
Changed files (4)
lib
std
test
lib/std/Build/Step/Compile.zig
@@ -229,8 +229,6 @@ is_linking_libc: bool = false,
 /// Computed during make().
 is_linking_libcpp: bool = false,
 
-no_builtin: ?bool = null,
-
 /// Populated during the make phase when there is a long-lived compiler process.
 /// Managed by the build runner, not user build script.
 zig_process: ?*Step.ZigProcess,
@@ -1646,10 +1644,6 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
         }
     }
 
-    if (compile.no_builtin) |enabled| {
-        try zig_args.append(if (enabled) "-fbuiltin" else "-fno-builtin");
-    }
-
     if (b.sysroot) |sysroot| {
         try zig_args.appendSlice(&[_][]const u8{ "--sysroot", sysroot });
     }
lib/std/Build/Module.zig
@@ -33,6 +33,7 @@ omit_frame_pointer: ?bool,
 error_tracing: ?bool,
 link_libc: ?bool,
 link_libcpp: ?bool,
+no_builtin: ?bool,
 
 /// Symbols to be exported when compiling to WebAssembly.
 export_symbol_names: []const []const u8 = &.{},
@@ -268,6 +269,7 @@ pub const CreateOptions = struct {
     /// more difficult to obtain stack traces. Has target-dependent effects.
     omit_frame_pointer: ?bool = null,
     error_tracing: ?bool = null,
+    no_builtin: ?bool = null,
 };
 
 pub const Import = struct {
@@ -314,6 +316,7 @@ pub fn init(
                 .omit_frame_pointer = options.omit_frame_pointer,
                 .error_tracing = options.error_tracing,
                 .export_symbol_names = &.{},
+                .no_builtin = options.no_builtin,
             };
 
             m.import_table.ensureUnusedCapacity(allocator, options.imports.len) catch @panic("OOM");
@@ -564,6 +567,7 @@ pub fn appendZigProcessFlags(
     try addFlag(zig_args, m.valgrind, "-fvalgrind", "-fno-valgrind");
     try addFlag(zig_args, m.pic, "-fPIC", "-fno-PIC");
     try addFlag(zig_args, m.red_zone, "-mred-zone", "-mno-red-zone");
+    try addFlag(zig_args, m.no_builtin, "-fno-builtin", "-fbuiltin");
 
     if (m.sanitize_c) |sc| switch (sc) {
         .off => try zig_args.append("-fno-sanitize-c"),
test/src/LlvmIr.zig
@@ -107,9 +107,9 @@ pub fn addCase(self: *LlvmIr, case: TestCase) void {
 
     obj.dll_export_fns = case.params.dll_export_fns;
     obj.pie = case.params.pie;
-    obj.no_builtin = case.params.no_builtin;
 
     obj.root_module.dwarf_format = case.params.dwarf_format;
+    obj.root_module.no_builtin = case.params.no_builtin;
     obj.root_module.red_zone = case.params.red_zone;
     obj.root_module.stack_check = case.params.stack_check;
     obj.root_module.stack_protector = case.params.stack_protector;
test/tests.zig
@@ -1827,7 +1827,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
             .zig_lib_dir = b.path("lib"),
         });
         these_tests.linkage = test_target.linkage;
-        if (options.no_builtin) these_tests.no_builtin = true;
+        if (options.no_builtin) these_tests.root_module.no_builtin = false;
         if (options.build_options) |build_options| {
             these_tests.root_module.addOptions("build_options", build_options);
         }