rename std.zig.CrossTarget to std.Target.Query

This commit is contained in:
Andrew Kelley 2023-12-04 12:35:04 -07:00
parent 67d48b94d6
commit 3179f58c41
24 changed files with 216 additions and 223 deletions

View File

@ -481,6 +481,7 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/start.zig" "${CMAKE_SOURCE_DIR}/lib/std/start.zig"
"${CMAKE_SOURCE_DIR}/lib/std/std.zig" "${CMAKE_SOURCE_DIR}/lib/std/std.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Target.zig" "${CMAKE_SOURCE_DIR}/lib/std/Target.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Target/Query.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Target/aarch64.zig" "${CMAKE_SOURCE_DIR}/lib/std/Target/aarch64.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Target/amdgpu.zig" "${CMAKE_SOURCE_DIR}/lib/std/Target/amdgpu.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Target/arm.zig" "${CMAKE_SOURCE_DIR}/lib/std/Target/arm.zig"
@ -508,7 +509,6 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/zig.zig" "${CMAKE_SOURCE_DIR}/lib/std/zig.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/Ast.zig" "${CMAKE_SOURCE_DIR}/lib/std/zig/Ast.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/AstRlAnnotate.zig" "${CMAKE_SOURCE_DIR}/lib/std/zig/AstRlAnnotate.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/CrossTarget.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/c_builtins.zig" "${CMAKE_SOURCE_DIR}/lib/std/zig/c_builtins.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/Parse.zig" "${CMAKE_SOURCE_DIR}/lib/std/zig/Parse.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig" "${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig"

View File

@ -10,11 +10,11 @@ const log = std.log;
const ArrayList = std.ArrayList; const ArrayList = std.ArrayList;
const StringHashMap = std.StringHashMap; const StringHashMap = std.StringHashMap;
const Allocator = mem.Allocator; const Allocator = mem.Allocator;
const Target = std.Target;
const process = std.process; const process = std.process;
const EnvMap = std.process.EnvMap; const EnvMap = std.process.EnvMap;
const fmt_lib = std.fmt; const fmt_lib = std.fmt;
const File = std.fs.File; const File = std.fs.File;
const TargetQuery = std.zig.CrossTarget;
const Sha256 = std.crypto.hash.sha2.Sha256; const Sha256 = std.crypto.hash.sha2.Sha256;
const Build = @This(); const Build = @This();
@ -375,7 +375,7 @@ fn userInputOptionsFromArgs(allocator: Allocator, args: anytype) UserInputOption
const v = @field(args, field.name); const v = @field(args, field.name);
const T = @TypeOf(v); const T = @TypeOf(v);
switch (T) { switch (T) {
TargetQuery => { Target.Query => {
user_input_options.put(field.name, .{ user_input_options.put(field.name, .{
.name = field.name, .name = field.name,
.value = .{ .scalar = v.zigTriple(allocator) catch @panic("OOM") }, .value = .{ .scalar = v.zigTriple(allocator) catch @panic("OOM") },
@ -1195,9 +1195,9 @@ pub fn standardOptimizeOption(self: *Build, options: StandardOptimizeOptionOptio
} }
pub const StandardTargetOptionsArgs = struct { pub const StandardTargetOptionsArgs = struct {
whitelist: ?[]const TargetQuery = null, whitelist: ?[]const Target.Query = null,
default_target: TargetQuery = .{}, default_target: Target.Query = .{},
}; };
/// Exposes standard `zig build` options for choosing a target and additionally /// Exposes standard `zig build` options for choosing a target and additionally
@ -1208,7 +1208,7 @@ pub fn standardTargetOptions(b: *Build, args: StandardTargetOptionsArgs) Resolve
} }
/// Exposes standard `zig build` options for choosing a target. /// Exposes standard `zig build` options for choosing a target.
pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsArgs) TargetQuery { pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsArgs) Target.Query {
const maybe_triple = self.option( const maybe_triple = self.option(
[]const u8, []const u8,
"target", "target",
@ -1222,8 +1222,8 @@ pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsA
const triple = maybe_triple orelse "native"; const triple = maybe_triple orelse "native";
var diags: TargetQuery.ParseOptions.Diagnostics = .{}; var diags: Target.Query.ParseOptions.Diagnostics = .{};
const selected_target = TargetQuery.parse(.{ const selected_target = Target.Query.parse(.{
.arch_os_abi = triple, .arch_os_abi = triple,
.cpu_features = mcpu, .cpu_features = mcpu,
.diagnostics = &diags, .diagnostics = &diags,
@ -1260,7 +1260,7 @@ pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsA
\\Available operating systems: \\Available operating systems:
\\ \\
, .{diags.os_name.?}); , .{diags.os_name.?});
inline for (std.meta.fields(std.Target.Os.Tag)) |field| { inline for (std.meta.fields(Target.Os.Tag)) |field| {
log.err(" {s}", .{field.name}); log.err(" {s}", .{field.name});
} }
self.markInvalidUserInput(); self.markInvalidUserInput();
@ -1279,7 +1279,7 @@ pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsA
// Make sure it's a match of one of the list. // Make sure it's a match of one of the list.
var mismatch_triple = true; var mismatch_triple = true;
var mismatch_cpu_features = true; var mismatch_cpu_features = true;
var whitelist_item: TargetQuery = .{}; var whitelist_item: Target.Query = .{};
for (list) |t| { for (list) |t| {
mismatch_cpu_features = true; mismatch_cpu_features = true;
mismatch_triple = true; mismatch_triple = true;
@ -1316,7 +1316,7 @@ pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsA
var populated_cpu_features = whitelist_cpu.model.features; var populated_cpu_features = whitelist_cpu.model.features;
populated_cpu_features.populateDependencies(all_features); populated_cpu_features.populateDependencies(all_features);
for (all_features, 0..) |feature, i_usize| { for (all_features, 0..) |feature, i_usize| {
const i = @as(std.Target.Cpu.Feature.Set.Index, @intCast(i_usize)); const i = @as(Target.Cpu.Feature.Set.Index, @intCast(i_usize));
const in_cpu_set = populated_cpu_features.isEnabled(i); const in_cpu_set = populated_cpu_features.isEnabled(i);
if (in_cpu_set) { if (in_cpu_set) {
log.err("{s} ", .{feature.name}); log.err("{s} ", .{feature.name});
@ -1324,7 +1324,7 @@ pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsA
} }
log.err(" Remove: ", .{}); log.err(" Remove: ", .{});
for (all_features, 0..) |feature, i_usize| { for (all_features, 0..) |feature, i_usize| {
const i = @as(std.Target.Cpu.Feature.Set.Index, @intCast(i_usize)); const i = @as(Target.Cpu.Feature.Set.Index, @intCast(i_usize));
const in_cpu_set = populated_cpu_features.isEnabled(i); const in_cpu_set = populated_cpu_features.isEnabled(i);
const in_actual_set = selected_cpu.features.isEnabled(i); const in_actual_set = selected_cpu.features.isEnabled(i);
if (in_actual_set and !in_cpu_set) { if (in_actual_set and !in_cpu_set) {
@ -1587,7 +1587,7 @@ pub fn fmt(self: *Build, comptime format: []const u8, args: anytype) []u8 {
pub fn findProgram(self: *Build, names: []const []const u8, paths: []const []const u8) ![]const u8 { pub fn findProgram(self: *Build, names: []const []const u8, paths: []const []const u8) ![]const u8 {
// TODO report error for ambiguous situations // TODO report error for ambiguous situations
const exe_extension = @as(TargetQuery, .{}).exeFileExt(); const exe_extension = @as(Target.Query, .{}).exeFileExt();
for (self.search_prefixes.items) |search_prefix| { for (self.search_prefixes.items) |search_prefix| {
for (names) |name| { for (names) |name| {
if (fs.path.isAbsolute(name)) { if (fs.path.isAbsolute(name)) {
@ -2064,7 +2064,7 @@ pub const InstalledFile = struct {
} }
}; };
pub fn serializeCpu(allocator: Allocator, cpu: std.Target.Cpu) ![]const u8 { pub fn serializeCpu(allocator: Allocator, cpu: Target.Cpu) ![]const u8 {
// TODO this logic can disappear if cpu model + features becomes part of the target triple // TODO this logic can disappear if cpu model + features becomes part of the target triple
const all_features = cpu.arch.allFeaturesList(); const all_features = cpu.arch.allFeaturesList();
var populated_cpu_features = cpu.model.features; var populated_cpu_features = cpu.model.features;
@ -2078,7 +2078,7 @@ pub fn serializeCpu(allocator: Allocator, cpu: std.Target.Cpu) ![]const u8 {
try mcpu_buffer.appendSlice(cpu.model.name); try mcpu_buffer.appendSlice(cpu.model.name);
for (all_features, 0..) |feature, i_usize| { for (all_features, 0..) |feature, i_usize| {
const i = @as(std.Target.Cpu.Feature.Set.Index, @intCast(i_usize)); const i = @as(Target.Cpu.Feature.Set.Index, @intCast(i_usize));
const in_cpu_set = populated_cpu_features.isEnabled(i); const in_cpu_set = populated_cpu_features.isEnabled(i);
const in_actual_set = cpu.features.isEnabled(i); const in_actual_set = cpu.features.isEnabled(i);
if (in_cpu_set and !in_actual_set) { if (in_cpu_set and !in_actual_set) {
@ -2127,9 +2127,9 @@ pub fn hex64(x: u64) [16]u8 {
/// target. The query is kept because the Zig toolchain needs to know which parts /// target. The query is kept because the Zig toolchain needs to know which parts
/// of the target are "native". This can apply to the CPU, the OS, or even the ABI. /// of the target are "native". This can apply to the CPU, the OS, or even the ABI.
pub const ResolvedTarget = struct { pub const ResolvedTarget = struct {
query: TargetQuery, query: Target.Query,
target: std.Target, target: Target,
dynamic_linker: std.Target.DynamicLinker, dynamic_linker: Target.DynamicLinker,
pub fn toNativeTargetInfo(self: ResolvedTarget) std.zig.system.NativeTargetInfo { pub fn toNativeTargetInfo(self: ResolvedTarget) std.zig.system.NativeTargetInfo {
return .{ return .{
@ -2141,7 +2141,7 @@ pub const ResolvedTarget = struct {
/// Converts a target query into a fully resolved target that can be passed to /// Converts a target query into a fully resolved target that can be passed to
/// various parts of the API. /// various parts of the API.
pub fn resolveTargetQuery(b: *Build, query: TargetQuery) ResolvedTarget { pub fn resolveTargetQuery(b: *Build, query: Target.Query) ResolvedTarget {
// This context will likely be required in the future when the target is // This context will likely be required in the future when the target is
// resolved via a WASI API or via the build protocol. // resolved via a WASI API or via the build protocol.
_ = b; _ = b;
@ -2156,7 +2156,7 @@ pub fn resolveTargetQuery(b: *Build, query: TargetQuery) ResolvedTarget {
}; };
} }
pub fn wantSharedLibSymLinks(target: std.Target) bool { pub fn wantSharedLibSymLinks(target: Target) bool {
return target.os.tag != .windows; return target.os.tag != .windows;
} }

View File

@ -9,7 +9,6 @@ const StringHashMap = std.StringHashMap;
const Sha256 = std.crypto.hash.sha2.Sha256; const Sha256 = std.crypto.hash.sha2.Sha256;
const Allocator = mem.Allocator; const Allocator = mem.Allocator;
const Step = std.Build.Step; const Step = std.Build.Step;
const CrossTarget = std.zig.CrossTarget;
const NativeTargetInfo = std.zig.system.NativeTargetInfo; const NativeTargetInfo = std.zig.system.NativeTargetInfo;
const LazyPath = std.Build.LazyPath; const LazyPath = std.Build.LazyPath;
const PkgConfigPkg = std.Build.PkgConfigPkg; const PkgConfigPkg = std.Build.PkgConfigPkg;

View File

@ -3,6 +3,8 @@ os: Os,
abi: Abi, abi: Abi,
ofmt: ObjectFormat, ofmt: ObjectFormat,
pub const Query = @import("Target/Query.zig");
pub const Os = struct { pub const Os = struct {
tag: Tag, tag: Tag,
version_range: VersionRange, version_range: VersionRange,
@ -1387,7 +1389,7 @@ pub const Cpu = struct {
}; };
pub fn zigTriple(self: Target, allocator: Allocator) ![]u8 { pub fn zigTriple(self: Target, allocator: Allocator) ![]u8 {
return std.zig.CrossTarget.fromTarget(self).zigTriple(allocator); return Query.fromTarget(self).zigTriple(allocator);
} }
pub fn linuxTripleSimple(allocator: Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![]u8 { pub fn linuxTripleSimple(allocator: Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![]u8 {

View File

@ -1,13 +1,7 @@
//! Contains all the same data as `Target`, additionally introducing the concept of "the native target". //! Contains all the same data as `Target`, additionally introducing the
//! The purpose of this abstraction is to provide meaningful and unsurprising defaults. //! concept of "the native target". The purpose of this abstraction is to
//! This struct does reference any resources and it is copyable. //! provide meaningful and unsurprising defaults. This struct does reference
//! any resources and it is copyable.
const CrossTarget = @This();
const std = @import("../std.zig");
const builtin = @import("builtin");
const assert = std.debug.assert;
const Target = std.Target;
const mem = std.mem;
/// `null` means native. /// `null` means native.
cpu_arch: ?Target.Cpu.Arch = null, cpu_arch: ?Target.Cpu.Arch = null,
@ -69,8 +63,8 @@ pub const SemanticVersion = std.SemanticVersion;
pub const DynamicLinker = Target.DynamicLinker; pub const DynamicLinker = Target.DynamicLinker;
pub fn fromTarget(target: Target) CrossTarget { pub fn fromTarget(target: Target) Query {
var result: CrossTarget = .{ var result: Query = .{
.cpu_arch = target.cpu.arch, .cpu_arch = target.cpu.arch,
.cpu_model = .{ .explicit = target.cpu.model }, .cpu_model = .{ .explicit = target.cpu.model },
.os_tag = target.os.tag, .os_tag = target.os.tag,
@ -102,7 +96,7 @@ pub fn fromTarget(target: Target) CrossTarget {
return result; return result;
} }
fn updateOsVersionRange(self: *CrossTarget, os: Target.Os) void { fn updateOsVersionRange(self: *Query, os: Target.Os) void {
switch (os.tag) { switch (os.tag) {
.freestanding, .freestanding,
.ananas, .ananas,
@ -171,7 +165,7 @@ fn updateOsVersionRange(self: *CrossTarget, os: Target.Os) void {
} }
/// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
pub fn toTarget(self: CrossTarget) Target { pub fn toTarget(self: Query) Target {
return .{ return .{
.cpu = self.getCpu(), .cpu = self.getCpu(),
.os = self.getOs(), .os = self.getOs(),
@ -233,11 +227,11 @@ pub const ParseOptions = struct {
}; };
}; };
pub fn parse(args: ParseOptions) !CrossTarget { pub fn parse(args: ParseOptions) !Query {
var dummy_diags: ParseOptions.Diagnostics = undefined; var dummy_diags: ParseOptions.Diagnostics = undefined;
const diags = args.diagnostics orelse &dummy_diags; const diags = args.diagnostics orelse &dummy_diags;
var result: CrossTarget = .{ var result: Query = .{
.dynamic_linker = DynamicLinker.init(args.dynamic_linker), .dynamic_linker = DynamicLinker.init(args.dynamic_linker),
}; };
@ -341,7 +335,7 @@ pub fn parse(args: ParseOptions) !CrossTarget {
/// Similar to `parse` except instead of fully parsing, it only determines the CPU /// Similar to `parse` except instead of fully parsing, it only determines the CPU
/// architecture and returns it if it can be determined, and returns `null` otherwise. /// architecture and returns it if it can be determined, and returns `null` otherwise.
/// This is intended to be used if the API user of CrossTarget needs to learn the /// This is intended to be used if the API user of Query needs to learn the
/// target CPU architecture in order to fully populate `ParseOptions`. /// target CPU architecture in order to fully populate `ParseOptions`.
pub fn parseCpuArch(args: ParseOptions) ?Target.Cpu.Arch { pub fn parseCpuArch(args: ParseOptions) ?Target.Cpu.Arch {
var it = mem.splitScalar(u8, args.arch_os_abi, '-'); var it = mem.splitScalar(u8, args.arch_os_abi, '-');
@ -386,7 +380,7 @@ test parseVersion {
} }
/// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
pub fn getCpu(self: CrossTarget) Target.Cpu { pub fn getCpu(self: Query) Target.Cpu {
switch (self.cpu_model) { switch (self.cpu_model) {
.native => { .native => {
// This works when doing `zig build` because Zig generates a build executable using // This works when doing `zig build` because Zig generates a build executable using
@ -417,23 +411,23 @@ pub fn getCpu(self: CrossTarget) Target.Cpu {
} }
} }
pub fn getCpuArch(self: CrossTarget) Target.Cpu.Arch { pub fn getCpuArch(self: Query) Target.Cpu.Arch {
return self.cpu_arch orelse builtin.cpu.arch; return self.cpu_arch orelse builtin.cpu.arch;
} }
pub fn getCpuModel(self: CrossTarget) *const Target.Cpu.Model { pub fn getCpuModel(self: Query) *const Target.Cpu.Model {
return switch (self.cpu_model) { return switch (self.cpu_model) {
.explicit => |cpu_model| cpu_model, .explicit => |cpu_model| cpu_model,
else => self.getCpu().model, else => self.getCpu().model,
}; };
} }
pub fn getCpuFeatures(self: CrossTarget) Target.Cpu.Feature.Set { pub fn getCpuFeatures(self: Query) Target.Cpu.Feature.Set {
return self.getCpu().features; return self.getCpu().features;
} }
/// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
pub fn getOs(self: CrossTarget) Target.Os { pub fn getOs(self: Query) Target.Os {
// `builtin.os` works when doing `zig build` because Zig generates a build executable using // `builtin.os` works when doing `zig build` because Zig generates a build executable using
// native OS version range. However this will not be accurate otherwise, and // native OS version range. However this will not be accurate otherwise, and
// will need to be integrated with `std.zig.system.NativeTargetInfo.detect`. // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`.
@ -465,28 +459,28 @@ pub fn getOs(self: CrossTarget) Target.Os {
return adjusted_os; return adjusted_os;
} }
pub fn getOsTag(self: CrossTarget) Target.Os.Tag { pub fn getOsTag(self: Query) Target.Os.Tag {
return self.os_tag orelse builtin.os.tag; return self.os_tag orelse builtin.os.tag;
} }
/// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
pub fn getOsVersionMin(self: CrossTarget) OsVersion { pub fn getOsVersionMin(self: Query) OsVersion {
if (self.os_version_min) |version_min| return version_min; if (self.os_version_min) |version_min| return version_min;
var tmp: CrossTarget = undefined; var tmp: Query = undefined;
tmp.updateOsVersionRange(self.getOs()); tmp.updateOsVersionRange(self.getOs());
return tmp.os_version_min.?; return tmp.os_version_min.?;
} }
/// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
pub fn getOsVersionMax(self: CrossTarget) OsVersion { pub fn getOsVersionMax(self: Query) OsVersion {
if (self.os_version_max) |version_max| return version_max; if (self.os_version_max) |version_max| return version_max;
var tmp: CrossTarget = undefined; var tmp: Query = undefined;
tmp.updateOsVersionRange(self.getOs()); tmp.updateOsVersionRange(self.getOs());
return tmp.os_version_max.?; return tmp.os_version_max.?;
} }
/// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`. /// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
pub fn getAbi(self: CrossTarget) Target.Abi { pub fn getAbi(self: Query) Target.Abi {
if (self.abi) |abi| return abi; if (self.abi) |abi| return abi;
if (self.os_tag == null) { if (self.os_tag == null) {
@ -499,70 +493,70 @@ pub fn getAbi(self: CrossTarget) Target.Abi {
return Target.Abi.default(self.getCpuArch(), self.getOs()); return Target.Abi.default(self.getCpuArch(), self.getOs());
} }
pub fn isFreeBSD(self: CrossTarget) bool { pub fn isFreeBSD(self: Query) bool {
return self.getOsTag() == .freebsd; return self.getOsTag() == .freebsd;
} }
pub fn isDarwin(self: CrossTarget) bool { pub fn isDarwin(self: Query) bool {
return self.getOsTag().isDarwin(); return self.getOsTag().isDarwin();
} }
pub fn isNetBSD(self: CrossTarget) bool { pub fn isNetBSD(self: Query) bool {
return self.getOsTag() == .netbsd; return self.getOsTag() == .netbsd;
} }
pub fn isOpenBSD(self: CrossTarget) bool { pub fn isOpenBSD(self: Query) bool {
return self.getOsTag() == .openbsd; return self.getOsTag() == .openbsd;
} }
pub fn isUefi(self: CrossTarget) bool { pub fn isUefi(self: Query) bool {
return self.getOsTag() == .uefi; return self.getOsTag() == .uefi;
} }
pub fn isDragonFlyBSD(self: CrossTarget) bool { pub fn isDragonFlyBSD(self: Query) bool {
return self.getOsTag() == .dragonfly; return self.getOsTag() == .dragonfly;
} }
pub fn isLinux(self: CrossTarget) bool { pub fn isLinux(self: Query) bool {
return self.getOsTag() == .linux; return self.getOsTag() == .linux;
} }
pub fn isWindows(self: CrossTarget) bool { pub fn isWindows(self: Query) bool {
return self.getOsTag() == .windows; return self.getOsTag() == .windows;
} }
pub fn exeFileExt(self: CrossTarget) [:0]const u8 { pub fn exeFileExt(self: Query) [:0]const u8 {
return Target.exeFileExtSimple(self.getCpuArch(), self.getOsTag()); return Target.exeFileExtSimple(self.getCpuArch(), self.getOsTag());
} }
pub fn staticLibSuffix(self: CrossTarget) [:0]const u8 { pub fn staticLibSuffix(self: Query) [:0]const u8 {
return Target.staticLibSuffix_os_abi(self.getOsTag(), self.getAbi()); return Target.staticLibSuffix_os_abi(self.getOsTag(), self.getAbi());
} }
pub fn dynamicLibSuffix(self: CrossTarget) [:0]const u8 { pub fn dynamicLibSuffix(self: Query) [:0]const u8 {
return self.getOsTag().dynamicLibSuffix(); return self.getOsTag().dynamicLibSuffix();
} }
pub fn libPrefix(self: CrossTarget) [:0]const u8 { pub fn libPrefix(self: Query) [:0]const u8 {
return Target.libPrefix_os_abi(self.getOsTag(), self.getAbi()); return Target.libPrefix_os_abi(self.getOsTag(), self.getAbi());
} }
pub fn isNativeCpu(self: CrossTarget) bool { pub fn isNativeCpu(self: Query) bool {
return self.cpu_arch == null and return self.cpu_arch == null and
(self.cpu_model == .native or self.cpu_model == .determined_by_cpu_arch) and (self.cpu_model == .native or self.cpu_model == .determined_by_cpu_arch) and
self.cpu_features_sub.isEmpty() and self.cpu_features_add.isEmpty(); self.cpu_features_sub.isEmpty() and self.cpu_features_add.isEmpty();
} }
pub fn isNativeOs(self: CrossTarget) bool { pub fn isNativeOs(self: Query) bool {
return self.os_tag == null and self.os_version_min == null and self.os_version_max == null and return self.os_tag == null and self.os_version_min == null and self.os_version_max == null and
self.dynamic_linker.get() == null and self.glibc_version == null; self.dynamic_linker.get() == null and self.glibc_version == null;
} }
pub fn isNativeAbi(self: CrossTarget) bool { pub fn isNativeAbi(self: Query) bool {
return self.os_tag == null and self.abi == null; return self.os_tag == null and self.abi == null;
} }
pub fn isNative(self: CrossTarget) bool { pub fn isNative(self: Query) bool {
return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi(); return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi();
} }
@ -576,7 +570,7 @@ fn formatVersion(version: SemanticVersion, writer: anytype) !void {
} }
} }
pub fn zigTriple(self: CrossTarget, allocator: mem.Allocator) error{OutOfMemory}![]u8 { pub fn zigTriple(self: Query, allocator: mem.Allocator) error{OutOfMemory}![]u8 {
if (self.isNative()) { if (self.isNative()) {
return allocator.dupe(u8, "native"); return allocator.dupe(u8, "native");
} }
@ -622,37 +616,37 @@ pub fn zigTriple(self: CrossTarget, allocator: mem.Allocator) error{OutOfMemory}
return result.toOwnedSlice(); return result.toOwnedSlice();
} }
pub fn allocDescription(self: CrossTarget, allocator: mem.Allocator) ![]u8 { pub fn allocDescription(self: Query, allocator: mem.Allocator) ![]u8 {
// TODO is there anything else worthy of the description that is not // TODO is there anything else worthy of the description that is not
// already captured in the triple? // already captured in the triple?
return self.zigTriple(allocator); return self.zigTriple(allocator);
} }
pub fn linuxTriple(self: CrossTarget, allocator: mem.Allocator) ![]u8 { pub fn linuxTriple(self: Query, allocator: mem.Allocator) ![]u8 {
return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi()); return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi());
} }
pub fn isGnuLibC(self: CrossTarget) bool { pub fn isGnuLibC(self: Query) bool {
return Target.isGnuLibC_os_tag_abi(self.getOsTag(), self.getAbi()); return Target.isGnuLibC_os_tag_abi(self.getOsTag(), self.getAbi());
} }
pub fn setGnuLibCVersion(self: *CrossTarget, major: u32, minor: u32, patch: u32) void { pub fn setGnuLibCVersion(self: *Query, major: u32, minor: u32, patch: u32) void {
assert(self.isGnuLibC()); assert(self.isGnuLibC());
self.glibc_version = SemanticVersion{ .major = major, .minor = minor, .patch = patch }; self.glibc_version = SemanticVersion{ .major = major, .minor = minor, .patch = patch };
} }
pub fn getObjectFormat(self: CrossTarget) Target.ObjectFormat { pub fn getObjectFormat(self: Query) Target.ObjectFormat {
return self.ofmt orelse Target.ObjectFormat.default(self.getOsTag(), self.getCpuArch()); return self.ofmt orelse Target.ObjectFormat.default(self.getOsTag(), self.getCpuArch());
} }
pub fn updateCpuFeatures(self: CrossTarget, set: *Target.Cpu.Feature.Set) void { pub fn updateCpuFeatures(self: Query, set: *Target.Cpu.Feature.Set) void {
set.removeFeatureSet(self.cpu_features_sub); set.removeFeatureSet(self.cpu_features_sub);
set.addFeatureSet(self.cpu_features_add); set.addFeatureSet(self.cpu_features_add);
set.populateDependencies(self.getCpuArch().allFeaturesList()); set.populateDependencies(self.getCpuArch().allFeaturesList());
set.removeFeatureSet(self.cpu_features_sub); set.removeFeatureSet(self.cpu_features_sub);
} }
fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const u8) !void { fn parseOs(result: *Query, diags: *ParseOptions.Diagnostics, text: []const u8) !void {
var it = mem.splitScalar(u8, text, '.'); var it = mem.splitScalar(u8, text, '.');
const os_name = it.first(); const os_name = it.first();
diags.os_name = os_name; diags.os_name = os_name;
@ -749,12 +743,19 @@ fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const
} }
} }
test "CrossTarget.parse" { const Query = @This();
if (builtin.target.isGnuLibC()) { const std = @import("../std.zig");
var cross_target = try CrossTarget.parse(.{}); const builtin = @import("builtin");
cross_target.setGnuLibCVersion(2, 1, 1); const assert = std.debug.assert;
const Target = std.Target;
const mem = std.mem;
const text = try cross_target.zigTriple(std.testing.allocator); test parse {
if (builtin.target.isGnuLibC()) {
var query = try Query.parse(.{});
query.setGnuLibCVersion(2, 1, 1);
const text = try query.zigTriple(std.testing.allocator);
defer std.testing.allocator.free(text); defer std.testing.allocator.free(text);
var buf: [256]u8 = undefined; var buf: [256]u8 = undefined;
@ -767,30 +768,30 @@ test "CrossTarget.parse" {
try std.testing.expectEqualSlices(u8, triple, text); try std.testing.expectEqualSlices(u8, triple, text);
} }
{ {
const cross_target = try CrossTarget.parse(.{ const query = try Query.parse(.{
.arch_os_abi = "aarch64-linux", .arch_os_abi = "aarch64-linux",
.cpu_features = "native", .cpu_features = "native",
}); });
try std.testing.expect(cross_target.cpu_arch.? == .aarch64); try std.testing.expect(query.cpu_arch.? == .aarch64);
try std.testing.expect(cross_target.cpu_model == .native); try std.testing.expect(query.cpu_model == .native);
} }
{ {
const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" }); const query = try Query.parse(.{ .arch_os_abi = "native" });
try std.testing.expect(cross_target.cpu_arch == null); try std.testing.expect(query.cpu_arch == null);
try std.testing.expect(cross_target.isNative()); try std.testing.expect(query.isNative());
const text = try cross_target.zigTriple(std.testing.allocator); const text = try query.zigTriple(std.testing.allocator);
defer std.testing.allocator.free(text); defer std.testing.allocator.free(text);
try std.testing.expectEqualSlices(u8, "native", text); try std.testing.expectEqualSlices(u8, "native", text);
} }
{ {
const cross_target = try CrossTarget.parse(.{ const query = try Query.parse(.{
.arch_os_abi = "x86_64-linux-gnu", .arch_os_abi = "x86_64-linux-gnu",
.cpu_features = "x86_64-sse-sse2-avx-cx8", .cpu_features = "x86_64-sse-sse2-avx-cx8",
}); });
const target = cross_target.toTarget(); const target = query.toTarget();
try std.testing.expect(target.os.tag == .linux); try std.testing.expect(target.os.tag == .linux);
try std.testing.expect(target.abi == .gnu); try std.testing.expect(target.abi == .gnu);
@ -806,16 +807,16 @@ test "CrossTarget.parse" {
try std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 })); try std.testing.expect(Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87 }));
try std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse })); try std.testing.expect(!Target.x86.featureSetHasAll(target.cpu.features, .{ .mmx, .x87, .sse }));
const text = try cross_target.zigTriple(std.testing.allocator); const text = try query.zigTriple(std.testing.allocator);
defer std.testing.allocator.free(text); defer std.testing.allocator.free(text);
try std.testing.expectEqualSlices(u8, "x86_64-linux-gnu", text); try std.testing.expectEqualSlices(u8, "x86_64-linux-gnu", text);
} }
{ {
const cross_target = try CrossTarget.parse(.{ const query = try Query.parse(.{
.arch_os_abi = "arm-linux-musleabihf", .arch_os_abi = "arm-linux-musleabihf",
.cpu_features = "generic+v8a", .cpu_features = "generic+v8a",
}); });
const target = cross_target.toTarget(); const target = query.toTarget();
try std.testing.expect(target.os.tag == .linux); try std.testing.expect(target.os.tag == .linux);
try std.testing.expect(target.abi == .musleabihf); try std.testing.expect(target.abi == .musleabihf);
@ -823,16 +824,16 @@ test "CrossTarget.parse" {
try std.testing.expect(target.cpu.model == &Target.arm.cpu.generic); try std.testing.expect(target.cpu.model == &Target.arm.cpu.generic);
try std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a)); try std.testing.expect(Target.arm.featureSetHas(target.cpu.features, .v8a));
const text = try cross_target.zigTriple(std.testing.allocator); const text = try query.zigTriple(std.testing.allocator);
defer std.testing.allocator.free(text); defer std.testing.allocator.free(text);
try std.testing.expectEqualSlices(u8, "arm-linux-musleabihf", text); try std.testing.expectEqualSlices(u8, "arm-linux-musleabihf", text);
} }
{ {
const cross_target = try CrossTarget.parse(.{ const query = try Query.parse(.{
.arch_os_abi = "aarch64-linux.3.10...4.4.1-gnu.2.27", .arch_os_abi = "aarch64-linux.3.10...4.4.1-gnu.2.27",
.cpu_features = "generic+v8a", .cpu_features = "generic+v8a",
}); });
const target = cross_target.toTarget(); const target = query.toTarget();
try std.testing.expect(target.cpu.arch == .aarch64); try std.testing.expect(target.cpu.arch == .aarch64);
try std.testing.expect(target.os.tag == .linux); try std.testing.expect(target.os.tag == .linux);
@ -847,7 +848,7 @@ test "CrossTarget.parse" {
try std.testing.expect(target.os.version_range.linux.glibc.patch == 0); try std.testing.expect(target.os.version_range.linux.glibc.patch == 0);
try std.testing.expect(target.abi == .gnu); try std.testing.expect(target.abi == .gnu);
const text = try cross_target.zigTriple(std.testing.allocator); const text = try query.zigTriple(std.testing.allocator);
defer std.testing.allocator.free(text); defer std.testing.allocator.free(text);
try std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-gnu.2.27", text); try std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-gnu.2.27", text);
} }

View File

@ -16,7 +16,8 @@ pub const number_literal = @import("zig/number_literal.zig");
pub const primitives = @import("zig/primitives.zig"); pub const primitives = @import("zig/primitives.zig");
pub const Ast = @import("zig/Ast.zig"); pub const Ast = @import("zig/Ast.zig");
pub const system = @import("zig/system.zig"); pub const system = @import("zig/system.zig");
pub const CrossTarget = @import("zig/CrossTarget.zig"); /// Deprecated: use `std.Target.Query`.
pub const CrossTarget = std.Target.Query;
pub const BuiltinFn = @import("zig/BuiltinFn.zig"); pub const BuiltinFn = @import("zig/BuiltinFn.zig");
pub const AstRlAnnotate = @import("zig/AstRlAnnotate.zig"); pub const AstRlAnnotate = @import("zig/AstRlAnnotate.zig");

View File

@ -9,7 +9,6 @@ const native_endian = builtin.cpu.arch.endian();
const NativeTargetInfo = @This(); const NativeTargetInfo = @This();
const Target = std.Target; const Target = std.Target;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const CrossTarget = std.zig.CrossTarget;
const windows = std.zig.system.windows; const windows = std.zig.system.windows;
const darwin = std.zig.system.darwin; const darwin = std.zig.system.darwin;
const linux = std.zig.system.linux; const linux = std.zig.system.linux;
@ -30,13 +29,14 @@ pub const DetectError = error{
Unexpected, Unexpected,
}; };
/// Given a `CrossTarget`, which specifies in detail which parts of the target should be detected /// Given a `Target.Query`, which specifies in detail which parts of the
/// natively, which should be standard or default, and which are provided explicitly, this function /// target should be detected natively, which should be standard or default,
/// resolves the native components by detecting the native system, and then resolves standard/default parts /// and which are provided explicitly, this function resolves the native
/// relative to that. /// components by detecting the native system, and then resolves
pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo { /// standard/default parts relative to that.
var os = cross_target.getOsTag().defaultVersionRange(cross_target.getCpuArch()); pub fn detect(query: Target.Query) DetectError!NativeTargetInfo {
if (cross_target.os_tag == null) { var os = query.getOsTag().defaultVersionRange(query.getCpuArch());
if (query.os_tag == null) {
switch (builtin.target.os.tag) { switch (builtin.target.os.tag) {
.linux => { .linux => {
const uts = std.os.uname(); const uts = std.os.uname();
@ -162,45 +162,45 @@ pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo {
} }
} }
if (cross_target.os_version_min) |min| switch (min) { if (query.os_version_min) |min| switch (min) {
.none => {}, .none => {},
.semver => |semver| switch (cross_target.getOsTag()) { .semver => |semver| switch (query.getOsTag()) {
.linux => os.version_range.linux.range.min = semver, .linux => os.version_range.linux.range.min = semver,
else => os.version_range.semver.min = semver, else => os.version_range.semver.min = semver,
}, },
.windows => |win_ver| os.version_range.windows.min = win_ver, .windows => |win_ver| os.version_range.windows.min = win_ver,
}; };
if (cross_target.os_version_max) |max| switch (max) { if (query.os_version_max) |max| switch (max) {
.none => {}, .none => {},
.semver => |semver| switch (cross_target.getOsTag()) { .semver => |semver| switch (query.getOsTag()) {
.linux => os.version_range.linux.range.max = semver, .linux => os.version_range.linux.range.max = semver,
else => os.version_range.semver.max = semver, else => os.version_range.semver.max = semver,
}, },
.windows => |win_ver| os.version_range.windows.max = win_ver, .windows => |win_ver| os.version_range.windows.max = win_ver,
}; };
if (cross_target.glibc_version) |glibc| { if (query.glibc_version) |glibc| {
assert(cross_target.isGnuLibC()); assert(query.isGnuLibC());
os.version_range.linux.glibc = glibc; os.version_range.linux.glibc = glibc;
} }
// Until https://github.com/ziglang/zig/issues/4592 is implemented (support detecting the // Until https://github.com/ziglang/zig/issues/4592 is implemented (support detecting the
// native CPU architecture as being different than the current target), we use this: // native CPU architecture as being different than the current target), we use this:
const cpu_arch = cross_target.getCpuArch(); const cpu_arch = query.getCpuArch();
const cpu = switch (cross_target.cpu_model) { const cpu = switch (query.cpu_model) {
.native => detectNativeCpuAndFeatures(cpu_arch, os, cross_target), .native => detectNativeCpuAndFeatures(cpu_arch, os, query),
.baseline => Target.Cpu.baseline(cpu_arch), .baseline => Target.Cpu.baseline(cpu_arch),
.determined_by_cpu_arch => if (cross_target.cpu_arch == null) .determined_by_cpu_arch => if (query.cpu_arch == null)
detectNativeCpuAndFeatures(cpu_arch, os, cross_target) detectNativeCpuAndFeatures(cpu_arch, os, query)
else else
Target.Cpu.baseline(cpu_arch), Target.Cpu.baseline(cpu_arch),
.explicit => |model| model.toCpu(cpu_arch), .explicit => |model| model.toCpu(cpu_arch),
} orelse backup_cpu_detection: { } orelse backup_cpu_detection: {
break :backup_cpu_detection Target.Cpu.baseline(cpu_arch); break :backup_cpu_detection Target.Cpu.baseline(cpu_arch);
}; };
var result = try detectAbiAndDynamicLinker(cpu, os, cross_target); var result = try detectAbiAndDynamicLinker(cpu, os, query);
// For x86, we need to populate some CPU feature flags depending on architecture // For x86, we need to populate some CPU feature flags depending on architecture
// and mode: // and mode:
// * 16bit_mode => if the abi is code16 // * 16bit_mode => if the abi is code16
@ -209,15 +209,15 @@ pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo {
// sets one of them, that takes precedence. // sets one of them, that takes precedence.
switch (cpu_arch) { switch (cpu_arch) {
.x86 => { .x86 => {
if (!std.Target.x86.featureSetHasAny(cross_target.cpu_features_add, .{ if (!Target.x86.featureSetHasAny(query.cpu_features_add, .{
.@"16bit_mode", .@"32bit_mode", .@"16bit_mode", .@"32bit_mode",
})) { })) {
switch (result.target.abi) { switch (result.target.abi) {
.code16 => result.target.cpu.features.addFeature( .code16 => result.target.cpu.features.addFeature(
@intFromEnum(std.Target.x86.Feature.@"16bit_mode"), @intFromEnum(Target.x86.Feature.@"16bit_mode"),
), ),
else => result.target.cpu.features.addFeature( else => result.target.cpu.features.addFeature(
@intFromEnum(std.Target.x86.Feature.@"32bit_mode"), @intFromEnum(Target.x86.Feature.@"32bit_mode"),
), ),
} }
} }
@ -228,12 +228,12 @@ pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo {
}, },
.thumb, .thumbeb => { .thumb, .thumbeb => {
result.target.cpu.features.addFeature( result.target.cpu.features.addFeature(
@intFromEnum(std.Target.arm.Feature.thumb_mode), @intFromEnum(Target.arm.Feature.thumb_mode),
); );
}, },
else => {}, else => {},
} }
cross_target.updateCpuFeatures(&result.target.cpu.features); query.updateCpuFeatures(&result.target.cpu.features);
return result; return result;
} }
@ -253,22 +253,22 @@ pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo {
fn detectAbiAndDynamicLinker( fn detectAbiAndDynamicLinker(
cpu: Target.Cpu, cpu: Target.Cpu,
os: Target.Os, os: Target.Os,
cross_target: CrossTarget, query: Target.Query,
) DetectError!NativeTargetInfo { ) DetectError!NativeTargetInfo {
const native_target_has_ld = comptime builtin.target.hasDynamicLinker(); const native_target_has_ld = comptime builtin.target.hasDynamicLinker();
const is_linux = builtin.target.os.tag == .linux; const is_linux = builtin.target.os.tag == .linux;
const is_solarish = builtin.target.os.tag.isSolarish(); const is_solarish = builtin.target.os.tag.isSolarish();
const have_all_info = cross_target.dynamic_linker.get() != null and const have_all_info = query.dynamic_linker.get() != null and
cross_target.abi != null and (!is_linux or cross_target.abi.?.isGnu()); query.abi != null and (!is_linux or query.abi.?.isGnu());
const os_is_non_native = cross_target.os_tag != null; const os_is_non_native = query.os_tag != null;
// The Solaris/illumos environment is always the same. // The Solaris/illumos environment is always the same.
if (!native_target_has_ld or have_all_info or os_is_non_native or is_solarish) { if (!native_target_has_ld or have_all_info or os_is_non_native or is_solarish) {
return defaultAbiAndDynamicLinker(cpu, os, cross_target); return defaultAbiAndDynamicLinker(cpu, os, query);
} }
if (cross_target.abi) |abi| { if (query.abi) |abi| {
if (abi.isMusl()) { if (abi.isMusl()) {
// musl implies static linking. // musl implies static linking.
return defaultAbiAndDynamicLinker(cpu, os, cross_target); return defaultAbiAndDynamicLinker(cpu, os, query);
} }
} }
// The current target's ABI cannot be relied on for this. For example, we may build the zig // The current target's ABI cannot be relied on for this. For example, we may build the zig
@ -287,7 +287,7 @@ fn detectAbiAndDynamicLinker(
}; };
var ld_info_list_buffer: [all_abis.len]LdInfo = undefined; var ld_info_list_buffer: [all_abis.len]LdInfo = undefined;
var ld_info_list_len: usize = 0; var ld_info_list_len: usize = 0;
const ofmt = cross_target.ofmt orelse Target.ObjectFormat.default(os.tag, cpu.arch); const ofmt = query.ofmt orelse Target.ObjectFormat.default(os.tag, cpu.arch);
for (all_abis) |abi| { for (all_abis) |abi| {
// This may be a nonsensical parameter. We detect this with // This may be a nonsensical parameter. We detect this with
@ -345,7 +345,7 @@ fn detectAbiAndDynamicLinker(
error.Unexpected, error.Unexpected,
=> |e| { => |e| {
std.log.warn("Encountered error: {s}, falling back to default ABI and dynamic linker.\n", .{@errorName(e)}); std.log.warn("Encountered error: {s}, falling back to default ABI and dynamic linker.\n", .{@errorName(e)});
return defaultAbiAndDynamicLinker(cpu, os, cross_target); return defaultAbiAndDynamicLinker(cpu, os, query);
}, },
else => |e| return e, else => |e| return e,
@ -363,7 +363,7 @@ fn detectAbiAndDynamicLinker(
const line = buffer[0..newline]; const line = buffer[0..newline];
if (!mem.startsWith(u8, line, "#!")) break :blk file; if (!mem.startsWith(u8, line, "#!")) break :blk file;
var it = mem.tokenizeScalar(u8, line[2..], ' '); var it = mem.tokenizeScalar(u8, line[2..], ' ');
file_name = it.next() orelse return defaultAbiAndDynamicLinker(cpu, os, cross_target); file_name = it.next() orelse return defaultAbiAndDynamicLinker(cpu, os, query);
file.close(); file.close();
} }
}; };
@ -373,7 +373,7 @@ fn detectAbiAndDynamicLinker(
// trick (block self_exe) won't work. The next thing we fall back to is the same thing, but for elf_file. // trick (block self_exe) won't work. The next thing we fall back to is the same thing, but for elf_file.
// TODO: inline this function and combine the buffer we already read above to find // TODO: inline this function and combine the buffer we already read above to find
// the possible shebang line with the buffer we use for the ELF header. // the possible shebang line with the buffer we use for the ELF header.
return abiAndDynamicLinkerFromFile(elf_file, cpu, os, ld_info_list, cross_target) catch |err| switch (err) { return abiAndDynamicLinkerFromFile(elf_file, cpu, os, ld_info_list, query) catch |err| switch (err) {
error.FileSystem, error.FileSystem,
error.SystemResources, error.SystemResources,
error.SymLinkLoop, error.SymLinkLoop,
@ -393,7 +393,7 @@ fn detectAbiAndDynamicLinker(
// Finally, we fall back on the standard path. // Finally, we fall back on the standard path.
=> |e| { => |e| {
std.log.warn("Encountered error: {s}, falling back to default ABI and dynamic linker.\n", .{@errorName(e)}); std.log.warn("Encountered error: {s}, falling back to default ABI and dynamic linker.\n", .{@errorName(e)});
return defaultAbiAndDynamicLinker(cpu, os, cross_target); return defaultAbiAndDynamicLinker(cpu, os, query);
}, },
}; };
} }
@ -565,7 +565,7 @@ fn glibcVerFromSoFile(file: fs.File) !std.SemanticVersion {
while (it.next()) |s| { while (it.next()) |s| {
if (mem.startsWith(u8, s, "GLIBC_2.")) { if (mem.startsWith(u8, s, "GLIBC_2.")) {
const chopped = s["GLIBC_".len..]; const chopped = s["GLIBC_".len..];
const ver = CrossTarget.parseVersion(chopped) catch |err| switch (err) { const ver = Target.Query.parseVersion(chopped) catch |err| switch (err) {
error.Overflow => return error.InvalidGnuLibCVersion, error.Overflow => return error.InvalidGnuLibCVersion,
error.InvalidVersion => return error.InvalidGnuLibCVersion, error.InvalidVersion => return error.InvalidGnuLibCVersion,
}; };
@ -588,7 +588,7 @@ fn glibcVerFromLinkName(link_name: []const u8, prefix: []const u8) error{ Unreco
} }
// chop off "libc-" and ".so" // chop off "libc-" and ".so"
const link_name_chopped = link_name[prefix.len .. link_name.len - suffix.len]; const link_name_chopped = link_name[prefix.len .. link_name.len - suffix.len];
return CrossTarget.parseVersion(link_name_chopped) catch |err| switch (err) { return Target.Query.parseVersion(link_name_chopped) catch |err| switch (err) {
error.Overflow => return error.InvalidGnuLibCVersion, error.Overflow => return error.InvalidGnuLibCVersion,
error.InvalidVersion => return error.InvalidGnuLibCVersion, error.InvalidVersion => return error.InvalidGnuLibCVersion,
}; };
@ -627,7 +627,7 @@ pub fn abiAndDynamicLinkerFromFile(
cpu: Target.Cpu, cpu: Target.Cpu,
os: Target.Os, os: Target.Os,
ld_info_list: []const LdInfo, ld_info_list: []const LdInfo,
cross_target: CrossTarget, query: Target.Query,
) AbiAndDynamicLinkerFromFileError!NativeTargetInfo { ) AbiAndDynamicLinkerFromFileError!NativeTargetInfo {
var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 align(@alignOf(elf.Elf64_Ehdr)) = undefined; var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 align(@alignOf(elf.Elf64_Ehdr)) = undefined;
_ = try preadMin(file, &hdr_buf, 0, hdr_buf.len); _ = try preadMin(file, &hdr_buf, 0, hdr_buf.len);
@ -655,13 +655,13 @@ pub fn abiAndDynamicLinkerFromFile(
.target = .{ .target = .{
.cpu = cpu, .cpu = cpu,
.os = os, .os = os,
.abi = cross_target.abi orelse Target.Abi.default(cpu.arch, os), .abi = query.abi orelse Target.Abi.default(cpu.arch, os),
.ofmt = cross_target.ofmt orelse Target.ObjectFormat.default(os.tag, cpu.arch), .ofmt = query.ofmt orelse Target.ObjectFormat.default(os.tag, cpu.arch),
}, },
.dynamic_linker = cross_target.dynamic_linker, .dynamic_linker = query.dynamic_linker,
}; };
var rpath_offset: ?u64 = null; // Found inside PT_DYNAMIC var rpath_offset: ?u64 = null; // Found inside PT_DYNAMIC
const look_for_ld = cross_target.dynamic_linker.get() == null; const look_for_ld = query.dynamic_linker.get() == null;
var ph_buf: [16 * @sizeOf(elf.Elf64_Phdr)]u8 align(@alignOf(elf.Elf64_Phdr)) = undefined; var ph_buf: [16 * @sizeOf(elf.Elf64_Phdr)]u8 align(@alignOf(elf.Elf64_Phdr)) = undefined;
if (phentsize > @sizeOf(elf.Elf64_Phdr)) return error.InvalidElfFile; if (phentsize > @sizeOf(elf.Elf64_Phdr)) return error.InvalidElfFile;
@ -706,7 +706,7 @@ pub fn abiAndDynamicLinkerFromFile(
}, },
// We only need this for detecting glibc version. // We only need this for detecting glibc version.
elf.PT_DYNAMIC => if (builtin.target.os.tag == .linux and result.target.isGnuLibC() and elf.PT_DYNAMIC => if (builtin.target.os.tag == .linux and result.target.isGnuLibC() and
cross_target.glibc_version == null) query.glibc_version == null)
{ {
var dyn_off = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset); var dyn_off = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset);
const p_filesz = elfInt(is_64, need_bswap, ph32.p_filesz, ph64.p_filesz); const p_filesz = elfInt(is_64, need_bswap, ph32.p_filesz, ph64.p_filesz);
@ -747,7 +747,7 @@ pub fn abiAndDynamicLinkerFromFile(
} }
if (builtin.target.os.tag == .linux and result.target.isGnuLibC() and if (builtin.target.os.tag == .linux and result.target.isGnuLibC() and
cross_target.glibc_version == null) query.glibc_version == null)
{ {
const shstrndx = elfInt(is_64, need_bswap, hdr32.e_shstrndx, hdr64.e_shstrndx); const shstrndx = elfInt(is_64, need_bswap, hdr32.e_shstrndx, hdr64.e_shstrndx);
@ -927,19 +927,19 @@ fn preadMin(file: fs.File, buf: []u8, offset: u64, min_read_len: usize) !usize {
return i; return i;
} }
fn defaultAbiAndDynamicLinker(cpu: Target.Cpu, os: Target.Os, cross_target: CrossTarget) !NativeTargetInfo { fn defaultAbiAndDynamicLinker(cpu: Target.Cpu, os: Target.Os, query: Target.Query) !NativeTargetInfo {
const target: Target = .{ const target: Target = .{
.cpu = cpu, .cpu = cpu,
.os = os, .os = os,
.abi = cross_target.abi orelse Target.Abi.default(cpu.arch, os), .abi = query.abi orelse Target.Abi.default(cpu.arch, os),
.ofmt = cross_target.ofmt orelse Target.ObjectFormat.default(os.tag, cpu.arch), .ofmt = query.ofmt orelse Target.ObjectFormat.default(os.tag, cpu.arch),
}; };
return NativeTargetInfo{ return NativeTargetInfo{
.target = target, .target = target,
.dynamic_linker = if (cross_target.dynamic_linker.get() == null) .dynamic_linker = if (query.dynamic_linker.get() == null)
target.standardDynamicLinkerPath() target.standardDynamicLinkerPath()
else else
cross_target.dynamic_linker, query.dynamic_linker,
}; };
} }
@ -964,13 +964,13 @@ pub fn elfInt(is_64: bool, need_bswap: bool, int_32: anytype, int_64: anytype) @
} }
} }
fn detectNativeCpuAndFeatures(cpu_arch: Target.Cpu.Arch, os: Target.Os, cross_target: CrossTarget) ?Target.Cpu { fn detectNativeCpuAndFeatures(cpu_arch: Target.Cpu.Arch, os: Target.Os, query: Target.Query) ?Target.Cpu {
// Here we switch on a comptime value rather than `cpu_arch`. This is valid because `cpu_arch`, // Here we switch on a comptime value rather than `cpu_arch`. This is valid because `cpu_arch`,
// although it is a runtime value, is guaranteed to be one of the architectures in the set // although it is a runtime value, is guaranteed to be one of the architectures in the set
// of the respective switch prong. // of the respective switch prong.
switch (builtin.cpu.arch) { switch (builtin.cpu.arch) {
.x86_64, .x86 => { .x86_64, .x86 => {
return @import("x86.zig").detectNativeCpuAndFeatures(cpu_arch, os, cross_target); return @import("x86.zig").detectNativeCpuAndFeatures(cpu_arch, os, query);
}, },
else => {}, else => {},
} }

View File

@ -87,7 +87,7 @@ fn parseSystemVersion(buf: []const u8) !std.SemanticVersion {
const ver = try svt.expectContent(); const ver = try svt.expectContent();
try svt.skipUntilTag(.end, "string"); try svt.skipUntilTag(.end, "string");
return try std.zig.CrossTarget.parseVersion(ver); return try std.Target.Query.parseVersion(ver);
} }
const SystemVersionTokenizer = struct { const SystemVersionTokenizer = struct {

View File

@ -5,10 +5,7 @@ const io = std.io;
const fs = std.fs; const fs = std.fs;
const fmt = std.fmt; const fmt = std.fmt;
const testing = std.testing; const testing = std.testing;
const Target = std.Target; const Target = std.Target;
const CrossTarget = std.zig.CrossTarget;
const assert = std.debug.assert; const assert = std.debug.assert;
const SparcCpuinfoImpl = struct { const SparcCpuinfoImpl = struct {

View File

@ -1,7 +1,6 @@
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const Target = std.Target; const Target = std.Target;
const CrossTarget = std.zig.CrossTarget;
const XCR0_XMM = 0x02; const XCR0_XMM = 0x02;
const XCR0_YMM = 0x04; const XCR0_YMM = 0x04;
@ -23,8 +22,8 @@ inline fn hasMask(input: u32, mask: u32) bool {
return (input & mask) == mask; return (input & mask) == mask;
} }
pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, cross_target: CrossTarget) Target.Cpu { pub fn detectNativeCpuAndFeatures(arch: Target.Cpu.Arch, os: Target.Os, query: Target.Query) Target.Cpu {
_ = cross_target; _ = query;
var cpu = Target.Cpu{ var cpu = Target.Cpu{
.arch = arch, .arch = arch,
.model = Target.Cpu.Model.generic(arch), .model = Target.Cpu.Model.generic(arch),

View File

@ -41,7 +41,7 @@ pub const LibCInstallation = struct {
pub fn parse( pub fn parse(
allocator: Allocator, allocator: Allocator,
libc_file: []const u8, libc_file: []const u8,
target: std.zig.CrossTarget, target: std.Target.Query,
) !LibCInstallation { ) !LibCInstallation {
var self: LibCInstallation = .{}; var self: LibCInstallation = .{};

View File

@ -2551,7 +2551,7 @@ fn buildOutputType(
} }
}; };
var target_parse_options: std.zig.CrossTarget.ParseOptions = .{ var target_parse_options: std.Target.Query.ParseOptions = .{
.arch_os_abi = target_arch_os_abi, .arch_os_abi = target_arch_os_abi,
.cpu_features = target_mcpu, .cpu_features = target_mcpu,
.dynamic_linker = target_dynamic_linker, .dynamic_linker = target_dynamic_linker,
@ -2563,7 +2563,7 @@ fn buildOutputType(
if (llvm_m_args.items.len != 0) { if (llvm_m_args.items.len != 0) {
// If this returns null, we let it fall through to the case below which will // If this returns null, we let it fall through to the case below which will
// run the full parse function and do proper error handling. // run the full parse function and do proper error handling.
if (std.zig.CrossTarget.parseCpuArch(target_parse_options)) |cpu_arch| { if (std.Target.Query.parseCpuArch(target_parse_options)) |cpu_arch| {
var llvm_to_zig_name = std.StringHashMap([]const u8).init(gpa); var llvm_to_zig_name = std.StringHashMap([]const u8).init(gpa);
defer llvm_to_zig_name.deinit(); defer llvm_to_zig_name.deinit();
@ -2607,8 +2607,8 @@ fn buildOutputType(
} }
} }
const cross_target = try parseCrossTargetOrReportFatalError(arena, target_parse_options); const target_query = try parseTargetQueryOrReportFatalError(arena, target_parse_options);
const target_info = try detectNativeTargetInfo(cross_target); const target_info = try detectNativeTargetInfo(target_query);
if (target_info.target.os.tag != .freestanding) { if (target_info.target.os.tag != .freestanding) {
if (ensure_libc_on_non_freestanding) if (ensure_libc_on_non_freestanding)
@ -2695,13 +2695,13 @@ fn buildOutputType(
} }
if (use_lld) |opt| { if (use_lld) |opt| {
if (opt and cross_target.isDarwin()) { if (opt and target_query.isDarwin()) {
fatal("LLD requested with Mach-O object format. Only the self-hosted linker is supported for this target.", .{}); fatal("LLD requested with Mach-O object format. Only the self-hosted linker is supported for this target.", .{});
} }
} }
if (want_lto) |opt| { if (want_lto) |opt| {
if (opt and cross_target.isDarwin()) { if (opt and target_query.isDarwin()) {
fatal("LTO is not yet supported with the Mach-O object format. More details: https://github.com/ziglang/zig/issues/8680", .{}); fatal("LTO is not yet supported with the Mach-O object format. More details: https://github.com/ziglang/zig/issues/8680", .{});
} }
} }
@ -2771,7 +2771,7 @@ fn buildOutputType(
var libc_installation: ?LibCInstallation = null; var libc_installation: ?LibCInstallation = null;
if (libc_paths_file) |paths_file| { if (libc_paths_file) |paths_file| {
libc_installation = LibCInstallation.parse(arena, paths_file, cross_target) catch |err| { libc_installation = LibCInstallation.parse(arena, paths_file, target_query) catch |err| {
fatal("unable to parse libc paths file at path {s}: {s}", .{ paths_file, @errorName(err) }); fatal("unable to parse libc paths file at path {s}: {s}", .{ paths_file, @errorName(err) });
}; };
} }
@ -2835,7 +2835,7 @@ fn buildOutputType(
// After this point, external_system_libs is used instead of system_libs. // After this point, external_system_libs is used instead of system_libs.
// Trigger native system library path detection if necessary. // Trigger native system library path detection if necessary.
if (sysroot == null and cross_target.isNativeOs() and cross_target.isNativeAbi() and if (sysroot == null and target_query.isNativeOs() and target_query.isNativeAbi() and
(external_system_libs.len != 0 or want_native_include_dirs)) (external_system_libs.len != 0 or want_native_include_dirs))
{ {
const paths = std.zig.system.NativePaths.detect(arena, target_info) catch |err| { const paths = std.zig.system.NativePaths.detect(arena, target_info) catch |err| {
@ -2864,7 +2864,7 @@ fn buildOutputType(
libc_installation = try LibCInstallation.findNative(.{ libc_installation = try LibCInstallation.findNative(.{
.allocator = arena, .allocator = arena,
.verbose = true, .verbose = true,
.target = cross_target.toTarget(), .target = target_query.toTarget(),
}); });
try lib_dirs.appendSlice(&.{ libc_installation.?.msvc_lib_dir.?, libc_installation.?.kernel32_lib_dir.? }); try lib_dirs.appendSlice(&.{ libc_installation.?.msvc_lib_dir.?, libc_installation.?.kernel32_lib_dir.? });
@ -3455,8 +3455,8 @@ fn buildOutputType(
.global_cache_directory = global_cache_directory, .global_cache_directory = global_cache_directory,
.root_name = root_name, .root_name = root_name,
.target = target_info.target, .target = target_info.target,
.is_native_os = cross_target.isNativeOs(), .is_native_os = target_query.isNativeOs(),
.is_native_abi = cross_target.isNativeAbi(), .is_native_abi = target_query.isNativeAbi(),
.dynamic_linker = target_info.dynamic_linker.get(), .dynamic_linker = target_info.dynamic_linker.get(),
.sysroot = sysroot, .sysroot = sysroot,
.output_mode = output_mode, .output_mode = output_mode,
@ -4013,16 +4013,16 @@ const ModuleDepIterator = struct {
} }
}; };
fn parseCrossTargetOrReportFatalError( fn parseTargetQueryOrReportFatalError(
allocator: Allocator, allocator: Allocator,
opts: std.zig.CrossTarget.ParseOptions, opts: std.Target.Query.ParseOptions,
) !std.zig.CrossTarget { ) !std.Target.Query {
var opts_with_diags = opts; var opts_with_diags = opts;
var diags: std.zig.CrossTarget.ParseOptions.Diagnostics = .{}; var diags: std.Target.Query.ParseOptions.Diagnostics = .{};
if (opts_with_diags.diagnostics == null) { if (opts_with_diags.diagnostics == null) {
opts_with_diags.diagnostics = &diags; opts_with_diags.diagnostics = &diags;
} }
return std.zig.CrossTarget.parse(opts_with_diags) catch |err| switch (err) { return std.Target.Query.parse(opts_with_diags) catch |err| switch (err) {
error.UnknownCpuModel => { error.UnknownCpuModel => {
help: { help: {
var help_text = std.ArrayList(u8).init(allocator); var help_text = std.ArrayList(u8).init(allocator);
@ -4666,9 +4666,9 @@ fn detectRcIncludeDirs(arena: Allocator, zig_lib_dir: []const u8, auto_includes:
while (true) { while (true) {
switch (cur_includes) { switch (cur_includes) {
.any, .msvc => { .any, .msvc => {
const cross_target = std.zig.CrossTarget.parse(.{ .arch_os_abi = "native-windows-msvc" }) catch unreachable; const target_query = std.Target.Query.parse(.{ .arch_os_abi = "native-windows-msvc" }) catch unreachable;
const target = cross_target.toTarget(); const target = target_query.toTarget();
const is_native_abi = cross_target.isNativeAbi(); const is_native_abi = target_query.isNativeAbi();
const detected_libc = Compilation.detectLibCIncludeDirs(arena, zig_lib_dir, target, is_native_abi, true, null) catch |err| { const detected_libc = Compilation.detectLibCIncludeDirs(arena, zig_lib_dir, target, is_native_abi, true, null) catch |err| {
if (cur_includes == .any) { if (cur_includes == .any) {
// fall back to mingw // fall back to mingw
@ -4691,9 +4691,9 @@ fn detectRcIncludeDirs(arena: Allocator, zig_lib_dir: []const u8, auto_includes:
}; };
}, },
.gnu => { .gnu => {
const cross_target = std.zig.CrossTarget.parse(.{ .arch_os_abi = "native-windows-gnu" }) catch unreachable; const target_query = std.Target.Query.parse(.{ .arch_os_abi = "native-windows-gnu" }) catch unreachable;
const target = cross_target.toTarget(); const target = target_query.toTarget();
const is_native_abi = cross_target.isNativeAbi(); const is_native_abi = target_query.isNativeAbi();
const detected_libc = try Compilation.detectLibCIncludeDirs(arena, zig_lib_dir, target, is_native_abi, true, null); const detected_libc = try Compilation.detectLibCIncludeDirs(arena, zig_lib_dir, target, is_native_abi, true, null);
return .{ return .{
.include_paths = detected_libc.libc_include_dir_list, .include_paths = detected_libc.libc_include_dir_list,
@ -4754,7 +4754,7 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void {
} }
} }
const cross_target = try parseCrossTargetOrReportFatalError(gpa, .{ const target_query = try parseTargetQueryOrReportFatalError(gpa, .{
.arch_os_abi = target_arch_os_abi, .arch_os_abi = target_arch_os_abi,
}); });
@ -4766,7 +4766,7 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void {
const libc_installation: ?*LibCInstallation = libc: { const libc_installation: ?*LibCInstallation = libc: {
if (input_file) |libc_file| { if (input_file) |libc_file| {
const libc = try arena.create(LibCInstallation); const libc = try arena.create(LibCInstallation);
libc.* = LibCInstallation.parse(arena, libc_file, cross_target) catch |err| { libc.* = LibCInstallation.parse(arena, libc_file, target_query) catch |err| {
fatal("unable to parse libc file at path {s}: {s}", .{ libc_file, @errorName(err) }); fatal("unable to parse libc file at path {s}: {s}", .{ libc_file, @errorName(err) });
}; };
break :libc libc; break :libc libc;
@ -4781,8 +4781,8 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void {
}; };
defer zig_lib_directory.handle.close(); defer zig_lib_directory.handle.close();
const target = cross_target.toTarget(); const target = target_query.toTarget();
const is_native_abi = cross_target.isNativeAbi(); const is_native_abi = target_query.isNativeAbi();
const libc_dirs = Compilation.detectLibCIncludeDirs( const libc_dirs = Compilation.detectLibCIncludeDirs(
arena, arena,
@ -4812,15 +4812,15 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void {
} }
if (input_file) |libc_file| { if (input_file) |libc_file| {
var libc = LibCInstallation.parse(gpa, libc_file, cross_target) catch |err| { var libc = LibCInstallation.parse(gpa, libc_file, target_query) catch |err| {
fatal("unable to parse libc file at path {s}: {s}", .{ libc_file, @errorName(err) }); fatal("unable to parse libc file at path {s}: {s}", .{ libc_file, @errorName(err) });
}; };
defer libc.deinit(gpa); defer libc.deinit(gpa);
} else { } else {
if (!cross_target.isNative()) { if (!target_query.isNative()) {
fatal("unable to detect libc for non-native target", .{}); fatal("unable to detect libc for non-native target", .{});
} }
const target_info = try detectNativeTargetInfo(cross_target); const target_info = try detectNativeTargetInfo(target_query);
var libc = LibCInstallation.findNative(.{ var libc = LibCInstallation.findNative(.{
.allocator = gpa, .allocator = gpa,
@ -5113,8 +5113,8 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
gimmeMoreOfThoseSweetSweetFileDescriptors(); gimmeMoreOfThoseSweetSweetFileDescriptors();
const cross_target: std.zig.CrossTarget = .{}; const target_query: std.Target.Query = .{};
const target_info = try detectNativeTargetInfo(cross_target); const target_info = try detectNativeTargetInfo(target_query);
const exe_basename = try std.zig.binNameAlloc(arena, .{ const exe_basename = try std.zig.binNameAlloc(arena, .{
.root_name = "build", .root_name = "build",
@ -5283,8 +5283,8 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
.global_cache_directory = global_cache_directory, .global_cache_directory = global_cache_directory,
.root_name = "build", .root_name = "build",
.target = target_info.target, .target = target_info.target,
.is_native_os = cross_target.isNativeOs(), .is_native_os = target_query.isNativeOs(),
.is_native_abi = cross_target.isNativeAbi(), .is_native_abi = target_query.isNativeAbi(),
.dynamic_linker = target_info.dynamic_linker.get(), .dynamic_linker = target_info.dynamic_linker.get(),
.output_mode = .Exe, .output_mode = .Exe,
.main_mod = &main_mod, .main_mod = &main_mod,
@ -6269,8 +6269,8 @@ test "fds" {
gimmeMoreOfThoseSweetSweetFileDescriptors(); gimmeMoreOfThoseSweetSweetFileDescriptors();
} }
fn detectNativeTargetInfo(cross_target: std.zig.CrossTarget) !std.zig.system.NativeTargetInfo { fn detectNativeTargetInfo(target_query: std.Target.Query) !std.zig.system.NativeTargetInfo {
return std.zig.system.NativeTargetInfo.detect(cross_target); return std.zig.system.NativeTargetInfo.detect(target_query);
} }
const usage_ast_check = const usage_ast_check =
@ -6672,8 +6672,8 @@ fn warnAboutForeignBinaries(
target_info: *const std.zig.system.NativeTargetInfo, target_info: *const std.zig.system.NativeTargetInfo,
link_libc: bool, link_libc: bool,
) !void { ) !void {
const host_cross_target: std.zig.CrossTarget = .{}; const host_query: std.Target.Query = .{};
const host_target_info = try detectNativeTargetInfo(host_cross_target); const host_target_info = try detectNativeTargetInfo(host_query);
switch (host_target_info.getExternalExecutor(target_info, .{ .link_libc = link_libc })) { switch (host_target_info.getExternalExecutor(target_info, .{ .link_libc = link_libc })) {
.native => return, .native => return,

View File

@ -5,7 +5,7 @@ const nl = if (@import("builtin").os.tag == .windows) "\r\n" else "\n";
pub fn addCases(ctx: *Cases, b: *std.Build) !void { pub fn addCases(ctx: *Cases, b: *std.Build) !void {
// These tests should work with all platforms, but we're using linux_x64 for // These tests should work with all platforms, but we're using linux_x64 for
// now for consistency. Will be expanded eventually. // now for consistency. Will be expanded eventually.
const linux_x64: std.zig.CrossTarget = .{ const linux_x64: std.Target.Query = .{
.cpu_arch = .x86_64, .cpu_arch = .x86_64,
.os_tag = .linux, .os_tag = .linux,
}; };

View File

@ -3833,7 +3833,6 @@ const link = @import("link.zig");
const std = @import("std"); const std = @import("std");
const Build = std.Build; const Build = std.Build;
const CrossTarget = std.zig.CrossTarget;
const Options = link.Options; const Options = link.Options;
const Step = Build.Step; const Step = Build.Step;
const WriteFile = Step.WriteFile; const WriteFile = Step.WriteFile;

View File

@ -8,7 +8,7 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = t, .name = t,
.root_source_file = .{ .path = "main.c" }, .root_source_file = .{ .path = "main.c" },
.target = b.resolveTargetQuery(std.zig.CrossTarget.parse( .target = b.resolveTargetQuery(std.Target.Query.parse(
.{ .arch_os_abi = t }, .{ .arch_os_abi = t },
) catch unreachable), ) catch unreachable),
}); });

View File

@ -199,7 +199,6 @@ const std = @import("std");
const Build = std.Build; const Build = std.Build;
const Compile = Step.Compile; const Compile = Step.Compile;
const CrossTarget = std.zig.CrossTarget;
const Run = Step.Run; const Run = Step.Run;
const Step = Build.Step; const Step = Build.Step;
const WriteFile = Step.WriteFile; const WriteFile = Step.WriteFile;

View File

@ -95,7 +95,5 @@ const addExecutable = link.addExecutable;
const expectLinkErrors = link.expectLinkErrors; const expectLinkErrors = link.expectLinkErrors;
const link = @import("link.zig"); const link = @import("link.zig");
const std = @import("std"); const std = @import("std");
const CrossTarget = std.zig.CrossTarget;
const Options = link.Options; const Options = link.Options;
const Step = std.Build.Step; const Step = std.Build.Step;

View File

@ -1,7 +1,7 @@
const std = @import("std"); const std = @import("std");
const Cases = @import("src/Cases.zig"); const Cases = @import("src/Cases.zig");
const targets = [_]std.zig.CrossTarget{ const targets = [_]std.Target.Query{
.{ .cpu_arch = .aarch64, .os_tag = .freestanding, .abi = .none }, .{ .cpu_arch = .aarch64, .os_tag = .freestanding, .abi = .none },
.{ .cpu_arch = .aarch64, .os_tag = .ios, .abi = .none }, .{ .cpu_arch = .aarch64, .os_tag = .ios, .abi = .none },
.{ .cpu_arch = .aarch64, .os_tag = .ios, .abi = .simulator }, .{ .cpu_arch = .aarch64, .os_tag = .ios, .abi = .simulator },

View File

@ -188,7 +188,7 @@ pub fn exe(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Cas
return ctx.addExe(name, target); return ctx.addExe(name, target);
} }
pub fn exeFromCompiledC(ctx: *Cases, name: []const u8, target_query: std.zig.CrossTarget, b: *std.Build) *Case { pub fn exeFromCompiledC(ctx: *Cases, name: []const u8, target_query: std.Target.Query, b: *std.Build) *Case {
var adjusted_query = target_query; var adjusted_query = target_query;
adjusted_query.ofmt = .c; adjusted_query.ofmt = .c;
ctx.cases.append(Case{ ctx.cases.append(Case{
@ -423,7 +423,7 @@ fn addFromDirInner(
var manifest = try TestManifest.parse(ctx.arena, src); var manifest = try TestManifest.parse(ctx.arena, src);
const backends = try manifest.getConfigForKeyAlloc(ctx.arena, "backend", Backend); const backends = try manifest.getConfigForKeyAlloc(ctx.arena, "backend", Backend);
const targets = try manifest.getConfigForKeyAlloc(ctx.arena, "target", std.zig.CrossTarget); const targets = try manifest.getConfigForKeyAlloc(ctx.arena, "target", std.Target.Query);
const c_frontends = try manifest.getConfigForKeyAlloc(ctx.arena, "c_frontend", CFrontend); const c_frontends = try manifest.getConfigForKeyAlloc(ctx.arena, "c_frontend", CFrontend);
const is_test = try manifest.getConfigForKeyAssertSingle("is_test", bool); const is_test = try manifest.getConfigForKeyAssertSingle("is_test", bool);
const link_libc = try manifest.getConfigForKeyAssertSingle("link_libc", bool); const link_libc = try manifest.getConfigForKeyAssertSingle("link_libc", bool);
@ -1160,9 +1160,9 @@ const TestManifest = struct {
} }
fn getDefaultParser(comptime T: type) ParseFn(T) { fn getDefaultParser(comptime T: type) ParseFn(T) {
if (T == std.zig.CrossTarget) return struct { if (T == std.Target.Query) return struct {
fn parse(str: []const u8) anyerror!T { fn parse(str: []const u8) anyerror!T {
return std.zig.CrossTarget.parse(.{ .arch_os_abi = str }); return std.Target.Query.parse(.{ .arch_os_abi = str });
} }
}.parse; }.parse;
@ -1287,7 +1287,7 @@ pub fn main() !void {
if (cases.items.len == 0) { if (cases.items.len == 0) {
const backends = try manifest.getConfigForKeyAlloc(arena, "backend", Backend); const backends = try manifest.getConfigForKeyAlloc(arena, "backend", Backend);
const targets = try manifest.getConfigForKeyAlloc(arena, "target", std.zig.CrossTarget); const targets = try manifest.getConfigForKeyAlloc(arena, "target", std.Target.Query);
const c_frontends = try manifest.getConfigForKeyAlloc(ctx.arena, "c_frontend", CFrontend); const c_frontends = try manifest.getConfigForKeyAlloc(ctx.arena, "c_frontend", CFrontend);
const is_test = try manifest.getConfigForKeyAssertSingle("is_test", bool); const is_test = try manifest.getConfigForKeyAssertSingle("is_test", bool);
const link_libc = try manifest.getConfigForKeyAssertSingle("link_libc", bool); const link_libc = try manifest.getConfigForKeyAssertSingle("link_libc", bool);
@ -1385,7 +1385,7 @@ pub fn main() !void {
return runCases(&ctx, zig_exe_path); return runCases(&ctx, zig_exe_path);
} }
fn resolveTargetQuery(query: std.zig.CrossTarget) std.Build.ResolvedTarget { fn resolveTargetQuery(query: std.Target.Query) std.Build.ResolvedTarget {
const result = std.zig.system.NativeTargetInfo.detect(query) catch const result = std.zig.system.NativeTargetInfo.detect(query) catch
@panic("unable to resolve target query"); @panic("unable to resolve target query");

View File

@ -5,7 +5,6 @@ const ArrayList = std.ArrayList;
const fmt = std.fmt; const fmt = std.fmt;
const mem = std.mem; const mem = std.mem;
const fs = std.fs; const fs = std.fs;
const CrossTarget = std.zig.CrossTarget;
pub const TranslateCContext = struct { pub const TranslateCContext = struct {
b: *std.Build, b: *std.Build,
@ -18,7 +17,7 @@ pub const TranslateCContext = struct {
sources: ArrayList(SourceFile), sources: ArrayList(SourceFile),
expected_lines: ArrayList([]const u8), expected_lines: ArrayList([]const u8),
allow_warnings: bool, allow_warnings: bool,
target: CrossTarget = .{}, target: std.Target.Query = .{},
const SourceFile = struct { const SourceFile = struct {
filename: []const u8, filename: []const u8,
@ -74,7 +73,7 @@ pub const TranslateCContext = struct {
pub fn addWithTarget( pub fn addWithTarget(
self: *TranslateCContext, self: *TranslateCContext,
name: []const u8, name: []const u8,
target: CrossTarget, target: std.Target.Query,
source: []const u8, source: []const u8,
expected_lines: []const []const u8, expected_lines: []const []const u8,
) void { ) void {

View File

@ -2,7 +2,7 @@ pub const SimpleCase = struct {
src_path: []const u8, src_path: []const u8,
link_libc: bool = false, link_libc: bool = false,
all_modes: bool = false, all_modes: bool = false,
target: std.zig.CrossTarget = .{}, target: std.Target.Query = .{},
is_test: bool = false, is_test: bool = false,
is_exe: bool = true, is_exe: bool = true,
/// Run only on this OS. /// Run only on this OS.

View File

@ -4,17 +4,17 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Test it"); const test_step = b.step("test", "Test it");
b.default_step = test_step; b.default_step = test_step;
const cross_target = b.resolveTargetQuery(.{ const target = b.resolveTargetQuery(.{
.cpu_arch = .x86_64, .cpu_arch = .x86_64,
.os_tag = .windows, .os_tag = .windows,
.abi = .gnu, .abi = .gnu,
}); });
add(b, b.host, .any, test_step); add(b, b.host, .any, test_step);
add(b, cross_target, .any, test_step); add(b, target, .any, test_step);
add(b, b.host, .gnu, test_step); add(b, b.host, .gnu, test_step);
add(b, cross_target, .gnu, test_step); add(b, target, .gnu, test_step);
} }
fn add( fn add(

View File

@ -21,7 +21,7 @@ pub const CompareOutputContext = @import("src/CompareOutput.zig");
pub const StackTracesContext = @import("src/StackTrace.zig"); pub const StackTracesContext = @import("src/StackTrace.zig");
const TestTarget = struct { const TestTarget = struct {
target: std.zig.CrossTarget = .{}, target: std.Target.Query = .{},
optimize_mode: std.builtin.OptimizeMode = .Debug, optimize_mode: std.builtin.OptimizeMode = .Debug,
link_libc: ?bool = null, link_libc: ?bool = null,
single_threaded: ?bool = null, single_threaded: ?bool = null,
@ -145,7 +145,7 @@ const test_targets = blk: {
//}, //},
// https://github.com/ziglang/zig/issues/13623 // https://github.com/ziglang/zig/issues/13623
//.{ //.{
// .target = std.zig.CrossTarget.parse(.{ // .target = std.Target.Query.parse(.{
// .arch_os_abi = "arm-linux-none", // .arch_os_abi = "arm-linux-none",
// .cpu_features = "generic+v8a", // .cpu_features = "generic+v8a",
// }) catch unreachable, // }) catch unreachable,
@ -286,13 +286,13 @@ const test_targets = blk: {
}, },
.{ .{
.target = std.zig.CrossTarget.parse(.{ .target = std.Target.Query.parse(.{
.arch_os_abi = "arm-linux-none", .arch_os_abi = "arm-linux-none",
.cpu_features = "generic+v8a", .cpu_features = "generic+v8a",
}) catch unreachable, }) catch unreachable,
}, },
.{ .{
.target = std.zig.CrossTarget.parse(.{ .target = std.Target.Query.parse(.{
.arch_os_abi = "arm-linux-musleabihf", .arch_os_abi = "arm-linux-musleabihf",
.cpu_features = "generic+v8a", .cpu_features = "generic+v8a",
}) catch unreachable, }) catch unreachable,
@ -300,7 +300,7 @@ const test_targets = blk: {
}, },
// https://github.com/ziglang/zig/issues/3287 // https://github.com/ziglang/zig/issues/3287
//.{ //.{
// .target = std.zig.CrossTarget.parse(.{ // .target = std.Target.Query.parse(.{
// .arch_os_abi = "arm-linux-gnueabihf", // .arch_os_abi = "arm-linux-gnueabihf",
// .cpu_features = "generic+v8a", // .cpu_features = "generic+v8a",
// }) catch unreachable, // }) catch unreachable,
@ -494,7 +494,7 @@ const test_targets = blk: {
}; };
const CAbiTarget = struct { const CAbiTarget = struct {
target: std.zig.CrossTarget = .{}, target: std.Target.Query = .{},
use_llvm: ?bool = null, use_llvm: ?bool = null,
use_lld: ?bool = null, use_lld: ?bool = null,
pic: ?bool = null, pic: ?bool = null,

View File

@ -1,7 +1,6 @@
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const tests = @import("tests.zig"); const tests = @import("tests.zig");
const CrossTarget = std.zig.CrossTarget;
// ******************************************************** // ********************************************************
// * * // * *
@ -1846,7 +1845,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub extern fn foo5(a: [*c]f32) callconv(.Thiscall) void; \\pub extern fn foo5(a: [*c]f32) callconv(.Thiscall) void;
}); });
cases.addWithTarget("Calling convention", CrossTarget.parse(.{ cases.addWithTarget("Calling convention", std.Target.Query.parse(.{
.arch_os_abi = "arm-linux-none", .arch_os_abi = "arm-linux-none",
.cpu_features = "generic+v8_5a", .cpu_features = "generic+v8_5a",
}) catch unreachable, }) catch unreachable,
@ -1857,7 +1856,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub extern fn foo2(a: [*c]f32) callconv(.AAPCSVFP) void; \\pub extern fn foo2(a: [*c]f32) callconv(.AAPCSVFP) void;
}); });
cases.addWithTarget("Calling convention", CrossTarget.parse(.{ cases.addWithTarget("Calling convention", std.Target.Query.parse(.{
.arch_os_abi = "aarch64-linux-none", .arch_os_abi = "aarch64-linux-none",
.cpu_features = "generic+v8_5a", .cpu_features = "generic+v8_5a",
}) catch unreachable, }) catch unreachable,