From 000aa30086eb4b470d2b567ce377f0e4a9d9a516 Mon Sep 17 00:00:00 2001 From: mlugg Date: Wed, 16 Aug 2023 21:28:50 +0100 Subject: [PATCH] std.Build: check for native CPU when serializing CrossTarget When using `std.Build.dependency` with target options, dependencies would sometimes get targets which are equivalent but have distinct names, e.g. `native` vs `native-native`. This is a somewhat broad issue, and it's unclear how to fix it more generally - perhaps we should special-case CrossTarget in options passing, or maybe targets should have a canonical name which we guarantee to use everywhere aside from raw user input. However, this commit fixes the most egregious issue, which was an active blocker to using the package manager for some users. This was caused by the CPU changing from `native` to a specific descriptor (e.g. `skylake+sgx`), which then changed the behavior of `zigTriple`. Resolves: #16856 --- lib/std/Build.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 046f9af796..472ef7d740 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -414,7 +414,12 @@ fn userInputOptionsFromArgs(allocator: Allocator, args: anytype) UserInputOption }) catch @panic("OOM"); user_input_options.put("cpu", .{ .name = "cpu", - .value = .{ .scalar = serializeCpu(allocator, v.getCpu()) catch unreachable }, + .value = .{ + .scalar = if (v.isNativeCpu()) + "native" + else + serializeCpu(allocator, v.getCpu()) catch unreachable, + }, .used = false, }) catch @panic("OOM"); },