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/std.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/amdgpu.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/Ast.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/Parse.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig"

View File

@ -10,11 +10,11 @@ const log = std.log;
const ArrayList = std.ArrayList;
const StringHashMap = std.StringHashMap;
const Allocator = mem.Allocator;
const Target = std.Target;
const process = std.process;
const EnvMap = std.process.EnvMap;
const fmt_lib = std.fmt;
const File = std.fs.File;
const TargetQuery = std.zig.CrossTarget;
const Sha256 = std.crypto.hash.sha2.Sha256;
const Build = @This();
@ -375,7 +375,7 @@ fn userInputOptionsFromArgs(allocator: Allocator, args: anytype) UserInputOption
const v = @field(args, field.name);
const T = @TypeOf(v);
switch (T) {
TargetQuery => {
Target.Query => {
user_input_options.put(field.name, .{
.name = field.name,
.value = .{ .scalar = v.zigTriple(allocator) catch @panic("OOM") },
@ -1195,9 +1195,9 @@ pub fn standardOptimizeOption(self: *Build, options: StandardOptimizeOptionOptio
}
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
@ -1208,7 +1208,7 @@ pub fn standardTargetOptions(b: *Build, args: StandardTargetOptionsArgs) Resolve
}
/// 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 u8,
"target",
@ -1222,8 +1222,8 @@ pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsA
const triple = maybe_triple orelse "native";
var diags: TargetQuery.ParseOptions.Diagnostics = .{};
const selected_target = TargetQuery.parse(.{
var diags: Target.Query.ParseOptions.Diagnostics = .{};
const selected_target = Target.Query.parse(.{
.arch_os_abi = triple,
.cpu_features = mcpu,
.diagnostics = &diags,
@ -1260,7 +1260,7 @@ pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsA
\\Available operating systems:
\\
, .{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});
}
self.markInvalidUserInput();
@ -1279,7 +1279,7 @@ pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsA
// Make sure it's a match of one of the list.
var mismatch_triple = true;
var mismatch_cpu_features = true;
var whitelist_item: TargetQuery = .{};
var whitelist_item: Target.Query = .{};
for (list) |t| {
mismatch_cpu_features = true;
mismatch_triple = true;
@ -1316,7 +1316,7 @@ pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsA
var populated_cpu_features = whitelist_cpu.model.features;
populated_cpu_features.populateDependencies(all_features);
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);
if (in_cpu_set) {
log.err("{s} ", .{feature.name});
@ -1324,7 +1324,7 @@ pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsA
}
log.err(" Remove: ", .{});
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_actual_set = selected_cpu.features.isEnabled(i);
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 {
// 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 (names) |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
const all_features = cpu.arch.allFeaturesList();
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);
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_actual_set = cpu.features.isEnabled(i);
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
/// of the target are "native". This can apply to the CPU, the OS, or even the ABI.
pub const ResolvedTarget = struct {
query: TargetQuery,
target: std.Target,
dynamic_linker: std.Target.DynamicLinker,
query: Target.Query,
target: Target,
dynamic_linker: Target.DynamicLinker,
pub fn toNativeTargetInfo(self: ResolvedTarget) std.zig.system.NativeTargetInfo {
return .{
@ -2141,7 +2141,7 @@ pub const ResolvedTarget = struct {
/// Converts a target query into a fully resolved target that can be passed to
/// 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
// resolved via a WASI API or via the build protocol.
_ = 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;
}

View File

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

View File

@ -3,6 +3,8 @@ os: Os,
abi: Abi,
ofmt: ObjectFormat,
pub const Query = @import("Target/Query.zig");
pub const Os = struct {
tag: Tag,
version_range: VersionRange,
@ -1387,7 +1389,7 @@ pub const Cpu = struct {
};
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 {

View File

@ -1,13 +1,7 @@
//! Contains all the same data as `Target`, additionally introducing the concept of "the native target".
//! The purpose of this abstraction is to 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;
//! Contains all the same data as `Target`, additionally introducing the
//! concept of "the native target". The purpose of this abstraction is to
//! provide meaningful and unsurprising defaults. This struct does reference
//! any resources and it is copyable.
/// `null` means native.
cpu_arch: ?Target.Cpu.Arch = null,
@ -69,8 +63,8 @@ pub const SemanticVersion = std.SemanticVersion;
pub const DynamicLinker = Target.DynamicLinker;
pub fn fromTarget(target: Target) CrossTarget {
var result: CrossTarget = .{
pub fn fromTarget(target: Target) Query {
var result: Query = .{
.cpu_arch = target.cpu.arch,
.cpu_model = .{ .explicit = target.cpu.model },
.os_tag = target.os.tag,
@ -102,7 +96,7 @@ pub fn fromTarget(target: Target) CrossTarget {
return result;
}
fn updateOsVersionRange(self: *CrossTarget, os: Target.Os) void {
fn updateOsVersionRange(self: *Query, os: Target.Os) void {
switch (os.tag) {
.freestanding,
.ananas,
@ -171,7 +165,7 @@ fn updateOsVersionRange(self: *CrossTarget, os: Target.Os) void {
}
/// TODO deprecated, use `std.zig.system.NativeTargetInfo.detect`.
pub fn toTarget(self: CrossTarget) Target {
pub fn toTarget(self: Query) Target {
return .{
.cpu = self.getCpu(),
.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;
const diags = args.diagnostics orelse &dummy_diags;
var result: CrossTarget = .{
var result: Query = .{
.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
/// 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`.
pub fn parseCpuArch(args: ParseOptions) ?Target.Cpu.Arch {
var it = mem.splitScalar(u8, args.arch_os_abi, '-');
@ -386,7 +380,7 @@ test parseVersion {
}
/// 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) {
.native => {
// 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;
}
pub fn getCpuModel(self: CrossTarget) *const Target.Cpu.Model {
pub fn getCpuModel(self: Query) *const Target.Cpu.Model {
return switch (self.cpu_model) {
.explicit => |cpu_model| cpu_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;
}
/// 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
// native OS version range. However this will not be accurate otherwise, and
// 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;
}
pub fn getOsTag(self: CrossTarget) Target.Os.Tag {
pub fn getOsTag(self: Query) Target.Os.Tag {
return self.os_tag orelse builtin.os.tag;
}
/// 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;
var tmp: CrossTarget = undefined;
var tmp: Query = undefined;
tmp.updateOsVersionRange(self.getOs());
return tmp.os_version_min.?;
}
/// 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;
var tmp: CrossTarget = undefined;
var tmp: Query = undefined;
tmp.updateOsVersionRange(self.getOs());
return tmp.os_version_max.?;
}
/// 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.os_tag == null) {
@ -499,70 +493,70 @@ pub fn getAbi(self: CrossTarget) Target.Abi {
return Target.Abi.default(self.getCpuArch(), self.getOs());
}
pub fn isFreeBSD(self: CrossTarget) bool {
pub fn isFreeBSD(self: Query) bool {
return self.getOsTag() == .freebsd;
}
pub fn isDarwin(self: CrossTarget) bool {
pub fn isDarwin(self: Query) bool {
return self.getOsTag().isDarwin();
}
pub fn isNetBSD(self: CrossTarget) bool {
pub fn isNetBSD(self: Query) bool {
return self.getOsTag() == .netbsd;
}
pub fn isOpenBSD(self: CrossTarget) bool {
pub fn isOpenBSD(self: Query) bool {
return self.getOsTag() == .openbsd;
}
pub fn isUefi(self: CrossTarget) bool {
pub fn isUefi(self: Query) bool {
return self.getOsTag() == .uefi;
}
pub fn isDragonFlyBSD(self: CrossTarget) bool {
pub fn isDragonFlyBSD(self: Query) bool {
return self.getOsTag() == .dragonfly;
}
pub fn isLinux(self: CrossTarget) bool {
pub fn isLinux(self: Query) bool {
return self.getOsTag() == .linux;
}
pub fn isWindows(self: CrossTarget) bool {
pub fn isWindows(self: Query) bool {
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());
}
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());
}
pub fn dynamicLibSuffix(self: CrossTarget) [:0]const u8 {
pub fn dynamicLibSuffix(self: Query) [:0]const u8 {
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());
}
pub fn isNativeCpu(self: CrossTarget) bool {
pub fn isNativeCpu(self: Query) bool {
return self.cpu_arch == null 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();
}
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
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;
}
pub fn isNative(self: CrossTarget) bool {
pub fn isNative(self: Query) bool {
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()) {
return allocator.dupe(u8, "native");
}
@ -622,37 +616,37 @@ pub fn zigTriple(self: CrossTarget, allocator: mem.Allocator) error{OutOfMemory}
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
// already captured in the triple?
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());
}
pub fn isGnuLibC(self: CrossTarget) bool {
pub fn isGnuLibC(self: Query) bool {
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());
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());
}
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.addFeatureSet(self.cpu_features_add);
set.populateDependencies(self.getCpuArch().allFeaturesList());
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, '.');
const os_name = it.first();
diags.os_name = os_name;
@ -749,12 +743,19 @@ fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const
}
}
test "CrossTarget.parse" {
if (builtin.target.isGnuLibC()) {
var cross_target = try CrossTarget.parse(.{});
cross_target.setGnuLibCVersion(2, 1, 1);
const Query = @This();
const std = @import("../std.zig");
const builtin = @import("builtin");
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);
var buf: [256]u8 = undefined;
@ -767,30 +768,30 @@ test "CrossTarget.parse" {
try std.testing.expectEqualSlices(u8, triple, text);
}
{
const cross_target = try CrossTarget.parse(.{
const query = try Query.parse(.{
.arch_os_abi = "aarch64-linux",
.cpu_features = "native",
});
try std.testing.expect(cross_target.cpu_arch.? == .aarch64);
try std.testing.expect(cross_target.cpu_model == .native);
try std.testing.expect(query.cpu_arch.? == .aarch64);
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(cross_target.isNative());
try std.testing.expect(query.cpu_arch == null);
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);
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",
.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.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, .sse }));
const text = try cross_target.zigTriple(std.testing.allocator);
const text = try query.zigTriple(std.testing.allocator);
defer std.testing.allocator.free(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",
.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.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.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);
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",
.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.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.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);
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 Ast = @import("zig/Ast.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 AstRlAnnotate = @import("zig/AstRlAnnotate.zig");

View File

@ -9,7 +9,6 @@ const native_endian = builtin.cpu.arch.endian();
const NativeTargetInfo = @This();
const Target = std.Target;
const Allocator = std.mem.Allocator;
const CrossTarget = std.zig.CrossTarget;
const windows = std.zig.system.windows;
const darwin = std.zig.system.darwin;
const linux = std.zig.system.linux;
@ -30,13 +29,14 @@ pub const DetectError = error{
Unexpected,
};
/// Given a `CrossTarget`, which specifies in detail which parts of the target should be detected
/// natively, which should be standard or default, and which are provided explicitly, this function
/// resolves the native components by detecting the native system, and then resolves standard/default parts
/// relative to that.
pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo {
var os = cross_target.getOsTag().defaultVersionRange(cross_target.getCpuArch());
if (cross_target.os_tag == null) {
/// Given a `Target.Query`, which specifies in detail which parts of the
/// target should be detected natively, which should be standard or default,
/// and which are provided explicitly, this function resolves the native
/// components by detecting the native system, and then resolves
/// standard/default parts relative to that.
pub fn detect(query: Target.Query) DetectError!NativeTargetInfo {
var os = query.getOsTag().defaultVersionRange(query.getCpuArch());
if (query.os_tag == null) {
switch (builtin.target.os.tag) {
.linux => {
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 => {},
.semver => |semver| switch (cross_target.getOsTag()) {
.semver => |semver| switch (query.getOsTag()) {
.linux => os.version_range.linux.range.min = semver,
else => os.version_range.semver.min = semver,
},
.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 => {},
.semver => |semver| switch (cross_target.getOsTag()) {
.semver => |semver| switch (query.getOsTag()) {
.linux => os.version_range.linux.range.max = semver,
else => os.version_range.semver.max = semver,
},
.windows => |win_ver| os.version_range.windows.max = win_ver,
};
if (cross_target.glibc_version) |glibc| {
assert(cross_target.isGnuLibC());
if (query.glibc_version) |glibc| {
assert(query.isGnuLibC());
os.version_range.linux.glibc = glibc;
}
// 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:
const cpu_arch = cross_target.getCpuArch();
const cpu_arch = query.getCpuArch();
const cpu = switch (cross_target.cpu_model) {
.native => detectNativeCpuAndFeatures(cpu_arch, os, cross_target),
const cpu = switch (query.cpu_model) {
.native => detectNativeCpuAndFeatures(cpu_arch, os, query),
.baseline => Target.Cpu.baseline(cpu_arch),
.determined_by_cpu_arch => if (cross_target.cpu_arch == null)
detectNativeCpuAndFeatures(cpu_arch, os, cross_target)
.determined_by_cpu_arch => if (query.cpu_arch == null)
detectNativeCpuAndFeatures(cpu_arch, os, query)
else
Target.Cpu.baseline(cpu_arch),
.explicit => |model| model.toCpu(cpu_arch),
} orelse backup_cpu_detection: {
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
// and mode:
// * 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.
switch (cpu_arch) {
.x86 => {
if (!std.Target.x86.featureSetHasAny(cross_target.cpu_features_add, .{
if (!Target.x86.featureSetHasAny(query.cpu_features_add, .{
.@"16bit_mode", .@"32bit_mode",
})) {
switch (result.target.abi) {
.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(
@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 => {
result.target.cpu.features.addFeature(
@intFromEnum(std.Target.arm.Feature.thumb_mode),
@intFromEnum(Target.arm.Feature.thumb_mode),
);
},
else => {},
}
cross_target.updateCpuFeatures(&result.target.cpu.features);
query.updateCpuFeatures(&result.target.cpu.features);
return result;
}
@ -253,22 +253,22 @@ pub fn detect(cross_target: CrossTarget) DetectError!NativeTargetInfo {
fn detectAbiAndDynamicLinker(
cpu: Target.Cpu,
os: Target.Os,
cross_target: CrossTarget,
query: Target.Query,
) DetectError!NativeTargetInfo {
const native_target_has_ld = comptime builtin.target.hasDynamicLinker();
const is_linux = builtin.target.os.tag == .linux;
const is_solarish = builtin.target.os.tag.isSolarish();
const have_all_info = cross_target.dynamic_linker.get() != null and
cross_target.abi != null and (!is_linux or cross_target.abi.?.isGnu());
const os_is_non_native = cross_target.os_tag != null;
const have_all_info = query.dynamic_linker.get() != null and
query.abi != null and (!is_linux or query.abi.?.isGnu());
const os_is_non_native = query.os_tag != null;
// 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) {
return defaultAbiAndDynamicLinker(cpu, os, cross_target);
return defaultAbiAndDynamicLinker(cpu, os, query);
}
if (cross_target.abi) |abi| {
if (query.abi) |abi| {
if (abi.isMusl()) {
// 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
@ -287,7 +287,7 @@ fn detectAbiAndDynamicLinker(
};
var ld_info_list_buffer: [all_abis.len]LdInfo = undefined;
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| {
// This may be a nonsensical parameter. We detect this with
@ -345,7 +345,7 @@ fn detectAbiAndDynamicLinker(
error.Unexpected,
=> |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,
@ -363,7 +363,7 @@ fn detectAbiAndDynamicLinker(
const line = buffer[0..newline];
if (!mem.startsWith(u8, line, "#!")) break :blk file;
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();
}
};
@ -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.
// 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.
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.SystemResources,
error.SymLinkLoop,
@ -393,7 +393,7 @@ fn detectAbiAndDynamicLinker(
// Finally, we fall back on the standard path.
=> |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| {
if (mem.startsWith(u8, s, "GLIBC_2.")) {
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.InvalidVersion => return error.InvalidGnuLibCVersion,
};
@ -588,7 +588,7 @@ fn glibcVerFromLinkName(link_name: []const u8, prefix: []const u8) error{ Unreco
}
// chop off "libc-" and ".so"
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.InvalidVersion => return error.InvalidGnuLibCVersion,
};
@ -627,7 +627,7 @@ pub fn abiAndDynamicLinkerFromFile(
cpu: Target.Cpu,
os: Target.Os,
ld_info_list: []const LdInfo,
cross_target: CrossTarget,
query: Target.Query,
) AbiAndDynamicLinkerFromFileError!NativeTargetInfo {
var hdr_buf: [@sizeOf(elf.Elf64_Ehdr)]u8 align(@alignOf(elf.Elf64_Ehdr)) = undefined;
_ = try preadMin(file, &hdr_buf, 0, hdr_buf.len);
@ -655,13 +655,13 @@ pub fn abiAndDynamicLinkerFromFile(
.target = .{
.cpu = cpu,
.os = os,
.abi = cross_target.abi orelse Target.Abi.default(cpu.arch, os),
.ofmt = cross_target.ofmt orelse Target.ObjectFormat.default(os.tag, cpu.arch),
.abi = query.abi orelse Target.Abi.default(cpu.arch, os),
.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
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;
if (phentsize > @sizeOf(elf.Elf64_Phdr)) return error.InvalidElfFile;
@ -706,7 +706,7 @@ pub fn abiAndDynamicLinkerFromFile(
},
// We only need this for detecting glibc version.
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);
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
cross_target.glibc_version == null)
query.glibc_version == null)
{
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;
}
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 = .{
.cpu = cpu,
.os = os,
.abi = cross_target.abi orelse Target.Abi.default(cpu.arch, os),
.ofmt = cross_target.ofmt orelse Target.ObjectFormat.default(os.tag, cpu.arch),
.abi = query.abi orelse Target.Abi.default(cpu.arch, os),
.ofmt = query.ofmt orelse Target.ObjectFormat.default(os.tag, cpu.arch),
};
return NativeTargetInfo{
.target = target,
.dynamic_linker = if (cross_target.dynamic_linker.get() == null)
.dynamic_linker = if (query.dynamic_linker.get() == null)
target.standardDynamicLinkerPath()
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`,
// although it is a runtime value, is guaranteed to be one of the architectures in the set
// of the respective switch prong.
switch (builtin.cpu.arch) {
.x86_64, .x86 => {
return @import("x86.zig").detectNativeCpuAndFeatures(cpu_arch, os, cross_target);
return @import("x86.zig").detectNativeCpuAndFeatures(cpu_arch, os, query);
},
else => {},
}

View File

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

View File

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

View File

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

View File

@ -41,7 +41,7 @@ pub const LibCInstallation = struct {
pub fn parse(
allocator: Allocator,
libc_file: []const u8,
target: std.zig.CrossTarget,
target: std.Target.Query,
) !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,
.cpu_features = target_mcpu,
.dynamic_linker = target_dynamic_linker,
@ -2563,7 +2563,7 @@ fn buildOutputType(
if (llvm_m_args.items.len != 0) {
// 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.
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);
defer llvm_to_zig_name.deinit();
@ -2607,8 +2607,8 @@ fn buildOutputType(
}
}
const cross_target = try parseCrossTargetOrReportFatalError(arena, target_parse_options);
const target_info = try detectNativeTargetInfo(cross_target);
const target_query = try parseTargetQueryOrReportFatalError(arena, target_parse_options);
const target_info = try detectNativeTargetInfo(target_query);
if (target_info.target.os.tag != .freestanding) {
if (ensure_libc_on_non_freestanding)
@ -2695,13 +2695,13 @@ fn buildOutputType(
}
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.", .{});
}
}
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", .{});
}
}
@ -2771,7 +2771,7 @@ fn buildOutputType(
var libc_installation: ?LibCInstallation = null;
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) });
};
}
@ -2835,7 +2835,7 @@ fn buildOutputType(
// After this point, external_system_libs is used instead of system_libs.
// 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))
{
const paths = std.zig.system.NativePaths.detect(arena, target_info) catch |err| {
@ -2864,7 +2864,7 @@ fn buildOutputType(
libc_installation = try LibCInstallation.findNative(.{
.allocator = arena,
.verbose = true,
.target = cross_target.toTarget(),
.target = target_query.toTarget(),
});
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,
.root_name = root_name,
.target = target_info.target,
.is_native_os = cross_target.isNativeOs(),
.is_native_abi = cross_target.isNativeAbi(),
.is_native_os = target_query.isNativeOs(),
.is_native_abi = target_query.isNativeAbi(),
.dynamic_linker = target_info.dynamic_linker.get(),
.sysroot = sysroot,
.output_mode = output_mode,
@ -4013,16 +4013,16 @@ const ModuleDepIterator = struct {
}
};
fn parseCrossTargetOrReportFatalError(
fn parseTargetQueryOrReportFatalError(
allocator: Allocator,
opts: std.zig.CrossTarget.ParseOptions,
) !std.zig.CrossTarget {
opts: std.Target.Query.ParseOptions,
) !std.Target.Query {
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) {
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 => {
help: {
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) {
switch (cur_includes) {
.any, .msvc => {
const cross_target = std.zig.CrossTarget.parse(.{ .arch_os_abi = "native-windows-msvc" }) catch unreachable;
const target = cross_target.toTarget();
const is_native_abi = cross_target.isNativeAbi();
const target_query = std.Target.Query.parse(.{ .arch_os_abi = "native-windows-msvc" }) catch unreachable;
const target = target_query.toTarget();
const is_native_abi = target_query.isNativeAbi();
const detected_libc = Compilation.detectLibCIncludeDirs(arena, zig_lib_dir, target, is_native_abi, true, null) catch |err| {
if (cur_includes == .any) {
// fall back to mingw
@ -4691,9 +4691,9 @@ fn detectRcIncludeDirs(arena: Allocator, zig_lib_dir: []const u8, auto_includes:
};
},
.gnu => {
const cross_target = std.zig.CrossTarget.parse(.{ .arch_os_abi = "native-windows-gnu" }) catch unreachable;
const target = cross_target.toTarget();
const is_native_abi = cross_target.isNativeAbi();
const target_query = std.Target.Query.parse(.{ .arch_os_abi = "native-windows-gnu" }) catch unreachable;
const target = target_query.toTarget();
const is_native_abi = target_query.isNativeAbi();
const detected_libc = try Compilation.detectLibCIncludeDirs(arena, zig_lib_dir, target, is_native_abi, true, null);
return .{
.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,
});
@ -4766,7 +4766,7 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void {
const libc_installation: ?*LibCInstallation = libc: {
if (input_file) |libc_file| {
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) });
};
break :libc libc;
@ -4781,8 +4781,8 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void {
};
defer zig_lib_directory.handle.close();
const target = cross_target.toTarget();
const is_native_abi = cross_target.isNativeAbi();
const target = target_query.toTarget();
const is_native_abi = target_query.isNativeAbi();
const libc_dirs = Compilation.detectLibCIncludeDirs(
arena,
@ -4812,15 +4812,15 @@ pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void {
}
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) });
};
defer libc.deinit(gpa);
} else {
if (!cross_target.isNative()) {
if (!target_query.isNative()) {
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(.{
.allocator = gpa,
@ -5113,8 +5113,8 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
gimmeMoreOfThoseSweetSweetFileDescriptors();
const cross_target: std.zig.CrossTarget = .{};
const target_info = try detectNativeTargetInfo(cross_target);
const target_query: std.Target.Query = .{};
const target_info = try detectNativeTargetInfo(target_query);
const exe_basename = try std.zig.binNameAlloc(arena, .{
.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,
.root_name = "build",
.target = target_info.target,
.is_native_os = cross_target.isNativeOs(),
.is_native_abi = cross_target.isNativeAbi(),
.is_native_os = target_query.isNativeOs(),
.is_native_abi = target_query.isNativeAbi(),
.dynamic_linker = target_info.dynamic_linker.get(),
.output_mode = .Exe,
.main_mod = &main_mod,
@ -6269,8 +6269,8 @@ test "fds" {
gimmeMoreOfThoseSweetSweetFileDescriptors();
}
fn detectNativeTargetInfo(cross_target: std.zig.CrossTarget) !std.zig.system.NativeTargetInfo {
return std.zig.system.NativeTargetInfo.detect(cross_target);
fn detectNativeTargetInfo(target_query: std.Target.Query) !std.zig.system.NativeTargetInfo {
return std.zig.system.NativeTargetInfo.detect(target_query);
}
const usage_ast_check =
@ -6672,8 +6672,8 @@ fn warnAboutForeignBinaries(
target_info: *const std.zig.system.NativeTargetInfo,
link_libc: bool,
) !void {
const host_cross_target: std.zig.CrossTarget = .{};
const host_target_info = try detectNativeTargetInfo(host_cross_target);
const host_query: std.Target.Query = .{};
const host_target_info = try detectNativeTargetInfo(host_query);
switch (host_target_info.getExternalExecutor(target_info, .{ .link_libc = link_libc })) {
.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 {
// These tests should work with all platforms, but we're using linux_x64 for
// now for consistency. Will be expanded eventually.
const linux_x64: std.zig.CrossTarget = .{
const linux_x64: std.Target.Query = .{
.cpu_arch = .x86_64,
.os_tag = .linux,
};

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
const std = @import("std");
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 = .ios, .abi = .none },
.{ .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);
}
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;
adjusted_query.ofmt = .c;
ctx.cases.append(Case{
@ -423,7 +423,7 @@ fn addFromDirInner(
var manifest = try TestManifest.parse(ctx.arena, src);
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 is_test = try manifest.getConfigForKeyAssertSingle("is_test", bool);
const link_libc = try manifest.getConfigForKeyAssertSingle("link_libc", bool);
@ -1160,9 +1160,9 @@ const TestManifest = struct {
}
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 {
return std.zig.CrossTarget.parse(.{ .arch_os_abi = str });
return std.Target.Query.parse(.{ .arch_os_abi = str });
}
}.parse;
@ -1287,7 +1287,7 @@ pub fn main() !void {
if (cases.items.len == 0) {
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 is_test = try manifest.getConfigForKeyAssertSingle("is_test", bool);
const link_libc = try manifest.getConfigForKeyAssertSingle("link_libc", bool);
@ -1385,7 +1385,7 @@ pub fn main() !void {
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
@panic("unable to resolve target query");

View File

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

View File

@ -2,7 +2,7 @@ pub const SimpleCase = struct {
src_path: []const u8,
link_libc: bool = false,
all_modes: bool = false,
target: std.zig.CrossTarget = .{},
target: std.Target.Query = .{},
is_test: bool = false,
is_exe: bool = true,
/// 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");
b.default_step = test_step;
const cross_target = b.resolveTargetQuery(.{
const target = b.resolveTargetQuery(.{
.cpu_arch = .x86_64,
.os_tag = .windows,
.abi = .gnu,
});
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, cross_target, .gnu, test_step);
add(b, target, .gnu, test_step);
}
fn add(

View File

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

View File

@ -1,7 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
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;
});
cases.addWithTarget("Calling convention", CrossTarget.parse(.{
cases.addWithTarget("Calling convention", std.Target.Query.parse(.{
.arch_os_abi = "arm-linux-none",
.cpu_features = "generic+v8_5a",
}) catch unreachable,
@ -1857,7 +1856,7 @@ pub fn addCases(cases: *tests.TranslateCContext) 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",
.cpu_features = "generic+v8_5a",
}) catch unreachable,