| ... | @@ -383,7 +383,7 @@ pub const CrossTarget = struct { | ... | @@ -383,7 +383,7 @@ pub const CrossTarget = struct { |
| 383 | pub fn getAbi(self: CrossTarget) Target.Abi { | 383 | pub fn getAbi(self: CrossTarget) Target.Abi { |
| 384 | if (self.abi) |abi| return abi; | 384 | if (self.abi) |abi| return abi; |
| 385 | | 385 | |
| 386 | if (self.isNativeOs()) { | 386 | if (self.os_tag == null) { |
| 387 | // This works when doing `zig build` because Zig generates a build executable using | 387 | // This works when doing `zig build` because Zig generates a build executable using |
| 388 | // native CPU model & features. However this will not be accurate otherwise, and | 388 | // native CPU model & features. However this will not be accurate otherwise, and |
| 389 | // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`. | 389 | // will need to be integrated with `std.zig.system.NativeTargetInfo.detect`. |
| ... | @@ -441,21 +441,11 @@ pub const CrossTarget = struct { | ... | @@ -441,21 +441,11 @@ pub const CrossTarget = struct { |
| 441 | return Target.libPrefix_cpu_arch_abi(self.getCpuArch(), self.getAbi()); | 441 | return Target.libPrefix_cpu_arch_abi(self.getCpuArch(), self.getAbi()); |
| 442 | } | 442 | } |
| 443 | | 443 | |
| 444 | pub fn isNativeCpu(self: CrossTarget) bool { | | |
| 445 | return self.cpu_arch == null and self.cpu_model == null and | | |
| 446 | self.cpu_features_sub.isEmpty() and self.cpu_features_add.isEmpty(); | | |
| 447 | } | | |
| 448 | | | |
| 449 | pub fn isNativeOs(self: CrossTarget) bool { | | |
| 450 | return self.os_tag == null and self.os_version_min == null and self.os_version_max == null; | | |
| 451 | } | | |
| 452 | | | |
| 453 | pub fn isNativeAbi(self: CrossTarget) bool { | | |
| 454 | return self.abi == null and self.glibc_version == null; | | |
| 455 | } | | |
| 456 | | | |
| 457 | pub fn isNative(self: CrossTarget) bool { | 444 | pub fn isNative(self: CrossTarget) bool { |
| 458 | return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi(); | 445 | return self.cpu_arch == null and self.cpu_model == null and |
| | 446 | self.cpu_features_sub.isEmpty() and self.cpu_features_add.isEmpty() and |
| | 447 | self.os_tag == null and self.os_version_min == null and self.os_version_max == null and |
| | 448 | self.abi == null; |
| 459 | } | 449 | } |
| 460 | | 450 | |
| 461 | pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![:0]u8 { | 451 | pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![:0]u8 { |
| ... | @@ -463,7 +453,7 @@ pub const CrossTarget = struct { | ... | @@ -463,7 +453,7 @@ pub const CrossTarget = struct { |
| 463 | return mem.dupeZ(allocator, u8, "native"); | 453 | return mem.dupeZ(allocator, u8, "native"); |
| 464 | } | 454 | } |
| 465 | | 455 | |
| 466 | const arch_name = if (self.isNativeCpu()) "native" else @tagName(self.getCpuArch()); | 456 | const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native"; |
| 467 | const os_name = if (self.os_tag) |os_tag| @tagName(os_tag) else "native"; | 457 | const os_name = if (self.os_tag) |os_tag| @tagName(os_tag) else "native"; |
| 468 | | 458 | |
| 469 | var result = try std.Buffer.allocPrint(allocator, "{}-{}", .{ arch_name, os_name }); | 459 | var result = try std.Buffer.allocPrint(allocator, "{}-{}", .{ arch_name, os_name }); |
| ... | @@ -557,12 +547,20 @@ pub const CrossTarget = struct { | ... | @@ -557,12 +547,20 @@ pub const CrossTarget = struct { |
| 557 | unavailable, | 547 | unavailable, |
| 558 | }; | 548 | }; |
| 559 | | 549 | |
| | 550 | /// Note that even a `CrossTarget` which returns `false` for `isNative` could still be natively executed. |
| | 551 | /// For example `-target arm-native` running on an aarch64 host. |
| 560 | pub fn getExternalExecutor(self: CrossTarget) Executor { | 552 | pub fn getExternalExecutor(self: CrossTarget) Executor { |
| 561 | const os_tag = self.getOsTag(); | | |
| 562 | const cpu_arch = self.getCpuArch(); | 553 | const cpu_arch = self.getCpuArch(); |
| | 554 | const os_tag = self.getOsTag(); |
| | 555 | const os_match = os_tag == Target.current.os.tag; |
| | 556 | |
| | 557 | // If the OS matches, and the CPU arch matches, the binary is considered native. |
| | 558 | if (self.os_tag == null and cpu_arch == Target.current.cpu.arch) { |
| | 559 | return .native; |
| | 560 | } |
| 563 | | 561 | |
| 564 | // If the target OS matches the host OS, we can use QEMU to emulate a foreign architecture. | 562 | // If the OS matches, we can use QEMU to emulate a foreign architecture. |
| 565 | if (os_tag == Target.current.os.tag) { | 563 | if (os_match) { |
| 566 | return switch (cpu_arch) { | 564 | return switch (cpu_arch) { |
| 567 | .aarch64 => Executor{ .qemu = "qemu-aarch64" }, | 565 | .aarch64 => Executor{ .qemu = "qemu-aarch64" }, |
| 568 | .aarch64_be => Executor{ .qemu = "qemu-aarch64_be" }, | 566 | .aarch64_be => Executor{ .qemu = "qemu-aarch64_be" }, |