don't inherit allowed deprecation from parent modules

Inheriting allow-deprecation from parent modules doesn't make too much
sense, so instead make them default to disallow unless otherwise
specified. This allows build system to avoid redundant
`-fno-allow-deprecated` args.

This makes the generated CLIs smaller, and makes zig1.wasm update not
needed.

Also represented `is_root` differently (moved to field of graph).
This commit is contained in:
Andrew Kelley 2025-02-25 23:50:56 -08:00
parent 4ddb13468b
commit c5aa680c88
4 changed files with 7 additions and 10 deletions

View File

@ -80,6 +80,7 @@ pub fn main() !void {
.query = .{}, .query = .{},
.result = try std.zig.system.resolveTargetQuery(.{}), .result = try std.zig.system.resolveTargetQuery(.{}),
}, },
.root_builder = undefined, // populated below
}; };
graph.cache.addPrefix(.{ .path = null, .handle = std.fs.cwd() }); graph.cache.addPrefix(.{ .path = null, .handle = std.fs.cwd() });
@ -94,6 +95,7 @@ pub fn main() !void {
local_cache_directory, local_cache_directory,
dependencies.root_deps, dependencies.root_deps,
); );
graph.root_builder = builder;
var targets = ArrayList([]const u8).init(arena); var targets = ArrayList([]const u8).init(arena);
var debug_log_scopes = ArrayList([]const u8).init(arena); var debug_log_scopes = ArrayList([]const u8).init(arena);

View File

@ -94,9 +94,6 @@ available_deps: AvailableDeps,
release_mode: ReleaseMode, release_mode: ReleaseMode,
/// `true` only for the root `Build`; `false` for any `Build` belonging to a dependency.
is_root: bool = false,
pub const ReleaseMode = enum { pub const ReleaseMode = enum {
off, off,
any, any,
@ -121,10 +118,11 @@ pub const Graph = struct {
/// Information about the native target. Computed before build() is invoked. /// Information about the native target. Computed before build() is invoked.
host: ResolvedTarget, host: ResolvedTarget,
incremental: ?bool = null, incremental: ?bool = null,
allow_deprecated: ?bool = null,
random_seed: u32 = 0, random_seed: u32 = 0,
dependency_cache: InitializedDepMap = .empty, dependency_cache: InitializedDepMap = .empty,
allow_so_scripts: ?bool = null, allow_so_scripts: ?bool = null,
allow_deprecated: ?bool = null,
root_builder: *std.Build,
}; };
const AvailableDeps = []const struct { []const u8, []const u8 }; const AvailableDeps = []const struct { []const u8, []const u8 };
@ -308,7 +306,6 @@ pub fn create(
.pkg_hash = "", .pkg_hash = "",
.available_deps = available_deps, .available_deps = available_deps,
.release_mode = .off, .release_mode = .off,
.is_root = true,
}; };
try b.top_level_steps.put(arena, b.install_tls.step.name, &b.install_tls); try b.top_level_steps.put(arena, b.install_tls.step.name, &b.install_tls);
try b.top_level_steps.put(arena, b.uninstall_tls.step.name, &b.uninstall_tls); try b.top_level_steps.put(arena, b.uninstall_tls.step.name, &b.uninstall_tls);

View File

@ -557,10 +557,9 @@ pub fn appendZigProcessFlags(
try addFlag(zig_args, m.pic, "-fPIC", "-fno-PIC"); 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.red_zone, "-mred-zone", "-mno-red-zone");
if (m.root_source_file != null) { // -fno-allow-deprecated is the CLI default, and not inherited, so only pass the flag if true.
const allow_deprecated = m.owner.graph.allow_deprecated orelse !m.owner.is_root; const allow_deprecated = m.owner.graph.allow_deprecated orelse (m.owner.graph.root_builder != m.owner);
try addFlag(zig_args, allow_deprecated, "-fallow-deprecated", "-fno-allow-deprecated"); if (allow_deprecated == true) try zig_args.append("-fallow-deprecated");
}
if (m.dwarf_format) |dwarf_format| { if (m.dwarf_format) |dwarf_format| {
try zig_args.append(switch (dwarf_format) { try zig_args.append(switch (dwarf_format) {

View File

@ -238,7 +238,6 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
const allow_deprecated = b: { const allow_deprecated = b: {
if (options.inherited.allow_deprecated) |x| break :b x; if (options.inherited.allow_deprecated) |x| break :b x;
if (options.parent) |p| break :b p.allow_deprecated;
break :b false; break :b false;
}; };