| ... | ... | @@ -81,14 +81,48 @@ pub const Os = struct { |
| 81 | 81 | return tag == .solaris or tag == .illumos; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | pub fn exeFileExt(tag: Tag, arch: Cpu.Arch) [:0]const u8 { |
| 85 | return switch (tag) { |
| 86 | .windows => ".exe", |
| 87 | .uefi => ".efi", |
| 88 | .plan9 => arch.plan9Ext(), |
| 89 | else => switch (arch) { |
| 90 | .wasm32, .wasm64 => ".wasm", |
| 91 | else => "", |
| 92 | }, |
| 93 | }; |
| 94 | } |
| 95 | |
| 96 | pub fn staticLibSuffix(tag: Tag, abi: Abi) [:0]const u8 { |
| 97 | return switch (abi) { |
| 98 | .msvc => ".lib", |
| 99 | else => switch (tag) { |
| 100 | .windows, .uefi => ".lib", |
| 101 | else => ".a", |
| 102 | }, |
| 103 | }; |
| 104 | } |
| 105 | |
| 84 | 106 | pub fn dynamicLibSuffix(tag: Tag) [:0]const u8 { |
| 85 | | if (tag.isDarwin()) { |
| 86 | | return ".dylib"; |
| 87 | | } |
| 88 | | switch (tag) { |
| 89 | | .windows => return ".dll", |
| 90 | | else => return ".so", |
| 91 | | } |
| 107 | return switch (tag) { |
| 108 | .windows, .uefi => ".dll", |
| 109 | .ios, .macos, .watchos, .tvos => ".dylib", |
| 110 | else => ".so", |
| 111 | }; |
| 112 | } |
| 113 | |
| 114 | pub fn libPrefix(tag: Os.Tag, abi: Abi) [:0]const u8 { |
| 115 | return switch (abi) { |
| 116 | .msvc => "", |
| 117 | else => switch (tag) { |
| 118 | .windows, .uefi => "", |
| 119 | else => "lib", |
| 120 | }, |
| 121 | }; |
| 122 | } |
| 123 | |
| 124 | pub inline fn isGnuLibC(tag: Os.Tag, abi: Abi) bool { |
| 125 | return tag == .linux and abi.isGnu(); |
| 92 | 126 | } |
| 93 | 127 | |
| 94 | 128 | pub fn defaultVersionRange(tag: Tag, arch: Cpu.Arch) Os { |
| ... | ... | @@ -97,6 +131,78 @@ pub const Os = struct { |
| 97 | 131 | .version_range = VersionRange.default(tag, arch), |
| 98 | 132 | }; |
| 99 | 133 | } |
| 134 | |
| 135 | pub inline fn getVersionRangeTag(tag: Tag) @typeInfo(TaggedVersionRange).Union.tag_type.? { |
| 136 | return switch (tag) { |
| 137 | .freestanding, |
| 138 | .ananas, |
| 139 | .cloudabi, |
| 140 | .fuchsia, |
| 141 | .kfreebsd, |
| 142 | .lv2, |
| 143 | .zos, |
| 144 | .haiku, |
| 145 | .minix, |
| 146 | .rtems, |
| 147 | .nacl, |
| 148 | .aix, |
| 149 | .cuda, |
| 150 | .nvcl, |
| 151 | .amdhsa, |
| 152 | .ps4, |
| 153 | .ps5, |
| 154 | .elfiamcu, |
| 155 | .mesa3d, |
| 156 | .contiki, |
| 157 | .amdpal, |
| 158 | .hermit, |
| 159 | .hurd, |
| 160 | .emscripten, |
| 161 | .driverkit, |
| 162 | .shadermodel, |
| 163 | .liteos, |
| 164 | .uefi, |
| 165 | .opencl, // TODO: OpenCL versions |
| 166 | .glsl450, // TODO: GLSL versions |
| 167 | .vulkan, |
| 168 | .plan9, |
| 169 | .illumos, |
| 170 | .other, |
| 171 | => .none, |
| 172 | |
| 173 | .freebsd, |
| 174 | .macos, |
| 175 | .ios, |
| 176 | .tvos, |
| 177 | .watchos, |
| 178 | .netbsd, |
| 179 | .openbsd, |
| 180 | .dragonfly, |
| 181 | .solaris, |
| 182 | .wasi, |
| 183 | => .semver, |
| 184 | |
| 185 | .linux => .linux, |
| 186 | |
| 187 | .windows => .windows, |
| 188 | }; |
| 189 | } |
| 190 | |
| 191 | pub fn archName(tag: Tag, arch: Cpu.Arch) [:0]const u8 { |
| 192 | return switch (tag) { |
| 193 | .linux => switch (arch) { |
| 194 | .arm, .armeb, .thumb, .thumbeb => "arm", |
| 195 | .aarch64, .aarch64_be, .aarch64_32 => "aarch64", |
| 196 | .mips, .mipsel, .mips64, .mips64el => "mips", |
| 197 | .powerpc, .powerpcle, .powerpc64, .powerpc64le => "powerpc", |
| 198 | .riscv32, .riscv64 => "riscv", |
| 199 | .sparc, .sparcel, .sparc64 => "sparc", |
| 200 | .x86, .x86_64 => "x86", |
| 201 | else => @tagName(arch), |
| 202 | }, |
| 203 | else => @tagName(arch), |
| 204 | }; |
| 205 | } |
| 100 | 206 | }; |
| 101 | 207 | |
| 102 | 208 | /// Based on NTDDI version constants from |
| ... | ... | @@ -142,52 +248,60 @@ pub const Os = struct { |
| 142 | 248 | 19042, //win10_fe aka win10_20h2 |
| 143 | 249 | }; |
| 144 | 250 | |
| 145 | | /// Returns whether the first version `self` is newer (greater) than or equal to the second version `ver`. |
| 146 | | pub inline fn isAtLeast(self: WindowsVersion, ver: WindowsVersion) bool { |
| 147 | | return @intFromEnum(self) >= @intFromEnum(ver); |
| 251 | /// Returns whether the first version `ver` is newer (greater) than or equal to the second version `ver`. |
| 252 | pub inline fn isAtLeast(ver: WindowsVersion, min_ver: WindowsVersion) bool { |
| 253 | return @intFromEnum(ver) >= @intFromEnum(min_ver); |
| 148 | 254 | } |
| 149 | 255 | |
| 150 | 256 | pub const Range = struct { |
| 151 | 257 | min: WindowsVersion, |
| 152 | 258 | max: WindowsVersion, |
| 153 | 259 | |
| 154 | | pub inline fn includesVersion(self: Range, ver: WindowsVersion) bool { |
| 155 | | return @intFromEnum(ver) >= @intFromEnum(self.min) and @intFromEnum(ver) <= @intFromEnum(self.max); |
| 260 | pub inline fn includesVersion(range: Range, ver: WindowsVersion) bool { |
| 261 | return @intFromEnum(ver) >= @intFromEnum(range.min) and |
| 262 | @intFromEnum(ver) <= @intFromEnum(range.max); |
| 156 | 263 | } |
| 157 | 264 | |
| 158 | 265 | /// Checks if system is guaranteed to be at least `version` or older than `version`. |
| 159 | 266 | /// Returns `null` if a runtime check is required. |
| 160 | | pub inline fn isAtLeast(self: Range, ver: WindowsVersion) ?bool { |
| 161 | | if (@intFromEnum(self.min) >= @intFromEnum(ver)) return true; |
| 162 | | if (@intFromEnum(self.max) < @intFromEnum(ver)) return false; |
| 267 | pub inline fn isAtLeast(range: Range, min_ver: WindowsVersion) ?bool { |
| 268 | if (@intFromEnum(range.min) >= @intFromEnum(min_ver)) return true; |
| 269 | if (@intFromEnum(range.max) < @intFromEnum(min_ver)) return false; |
| 163 | 270 | return null; |
| 164 | 271 | } |
| 165 | 272 | }; |
| 166 | 273 | |
| 274 | pub fn parse(str: []const u8) !WindowsVersion { |
| 275 | return std.meta.stringToEnum(WindowsVersion, str) orelse |
| 276 | @enumFromInt(std.fmt.parseInt(u32, str, 0) catch |
| 277 | return error.InvalidOperatingSystemVersion); |
| 278 | } |
| 279 | |
| 167 | 280 | /// This function is defined to serialize a Zig source code representation of this |
| 168 | 281 | /// type, that, when parsed, will deserialize into the same data. |
| 169 | 282 | pub fn format( |
| 170 | | self: WindowsVersion, |
| 171 | | comptime fmt: []const u8, |
| 283 | ver: WindowsVersion, |
| 284 | comptime fmt_str: []const u8, |
| 172 | 285 | _: std.fmt.FormatOptions, |
| 173 | | out_stream: anytype, |
| 174 | | ) !void { |
| 175 | | if (comptime std.mem.eql(u8, fmt, "s")) { |
| 176 | | if (@intFromEnum(self) >= @intFromEnum(WindowsVersion.nt4) and @intFromEnum(self) <= @intFromEnum(WindowsVersion.latest)) { |
| 177 | | try std.fmt.format(out_stream, ".{s}", .{@tagName(self)}); |
| 178 | | } else { |
| 179 | | // TODO this code path breaks zig triples, but it is used in `builtin` |
| 180 | | try std.fmt.format(out_stream, "@enumFromInt(Target.Os.WindowsVersion, 0x{X:0>8})", .{@intFromEnum(self)}); |
| 181 | | } |
| 182 | | } else if (fmt.len == 0) { |
| 183 | | if (@intFromEnum(self) >= @intFromEnum(WindowsVersion.nt4) and @intFromEnum(self) <= @intFromEnum(WindowsVersion.latest)) { |
| 184 | | try std.fmt.format(out_stream, "WindowsVersion.{s}", .{@tagName(self)}); |
| 185 | | } else { |
| 186 | | try std.fmt.format(out_stream, "WindowsVersion(0x{X:0>8})", .{@intFromEnum(self)}); |
| 187 | | } |
| 188 | | } else { |
| 189 | | std.fmt.invalidFmtError(fmt, self); |
| 190 | | } |
| 286 | writer: anytype, |
| 287 | ) @TypeOf(writer).Error!void { |
| 288 | const maybe_name = std.enums.tagName(WindowsVersion, ver); |
| 289 | if (comptime std.mem.eql(u8, fmt_str, "s")) { |
| 290 | if (maybe_name) |name| |
| 291 | try writer.print(".{s}", .{name}) |
| 292 | else |
| 293 | try writer.print(".{d}", .{@intFromEnum(ver)}); |
| 294 | } else if (comptime std.mem.eql(u8, fmt_str, "c")) { |
| 295 | if (maybe_name) |name| |
| 296 | try writer.print(".{s}", .{name}) |
| 297 | else |
| 298 | try writer.print("@enumFromInt(0x{X:0>8})", .{@intFromEnum(ver)}); |
| 299 | } else if (fmt_str.len == 0) { |
| 300 | if (maybe_name) |name| |
| 301 | try writer.print("WindowsVersion.{s}", .{name}) |
| 302 | else |
| 303 | try writer.print("WindowsVersion(0x{X:0>8})", .{@intFromEnum(ver)}); |
| 304 | } else std.fmt.invalidFmtError(fmt_str, ver); |
| 191 | 305 | } |
| 192 | 306 | }; |
| 193 | 307 | |
| ... | ... | @@ -195,14 +309,14 @@ pub const Os = struct { |
| 195 | 309 | range: std.SemanticVersion.Range, |
| 196 | 310 | glibc: std.SemanticVersion, |
| 197 | 311 | |
| 198 | | pub inline fn includesVersion(self: LinuxVersionRange, ver: std.SemanticVersion) bool { |
| 199 | | return self.range.includesVersion(ver); |
| 312 | pub inline fn includesVersion(range: LinuxVersionRange, ver: std.SemanticVersion) bool { |
| 313 | return range.range.includesVersion(ver); |
| 200 | 314 | } |
| 201 | 315 | |
| 202 | 316 | /// Checks if system is guaranteed to be at least `version` or older than `version`. |
| 203 | 317 | /// Returns `null` if a runtime check is required. |
| 204 | | pub inline fn isAtLeast(self: LinuxVersionRange, ver: std.SemanticVersion) ?bool { |
| 205 | | return self.range.isAtLeast(ver); |
| 318 | pub inline fn isAtLeast(range: LinuxVersionRange, ver: std.SemanticVersion) ?bool { |
| 319 | return range.range.isAtLeast(ver); |
| 206 | 320 | } |
| 207 | 321 | }; |
| 208 | 322 | |
| ... | ... | @@ -239,7 +353,7 @@ pub const Os = struct { |
| 239 | 353 | /// The default `VersionRange` represents the range that the Zig Standard Library |
| 240 | 354 | /// bases its abstractions on. |
| 241 | 355 | pub fn default(tag: Tag, arch: Cpu.Arch) VersionRange { |
| 242 | | switch (tag) { |
| 356 | return switch (tag) { |
| 243 | 357 | .freestanding, |
| 244 | 358 | .ananas, |
| 245 | 359 | .cloudabi, |
| ... | ... | @@ -263,7 +377,6 @@ pub const Os = struct { |
| 263 | 377 | .amdpal, |
| 264 | 378 | .hermit, |
| 265 | 379 | .hurd, |
| 266 | | .wasi, |
| 267 | 380 | .emscripten, |
| 268 | 381 | .driverkit, |
| 269 | 382 | .shadermodel, |
| ... | ... | @@ -275,15 +388,15 @@ pub const Os = struct { |
| 275 | 388 | .plan9, |
| 276 | 389 | .illumos, |
| 277 | 390 | .other, |
| 278 | | => return .{ .none = {} }, |
| 391 | => .{ .none = {} }, |
| 279 | 392 | |
| 280 | | .freebsd => return .{ |
| 393 | .freebsd => .{ |
| 281 | 394 | .semver = std.SemanticVersion.Range{ |
| 282 | 395 | .min = .{ .major = 12, .minor = 0, .patch = 0 }, |
| 283 | 396 | .max = .{ .major = 14, .minor = 0, .patch = 0 }, |
| 284 | 397 | }, |
| 285 | 398 | }, |
| 286 | | .macos => return switch (arch) { |
| 399 | .macos => switch (arch) { |
| 287 | 400 | .aarch64 => VersionRange{ |
| 288 | 401 | .semver = .{ |
| 289 | 402 | .min = .{ .major = 11, .minor = 7, .patch = 1 }, |
| ... | ... | @@ -298,50 +411,56 @@ pub const Os = struct { |
| 298 | 411 | }, |
| 299 | 412 | else => unreachable, |
| 300 | 413 | }, |
| 301 | | .ios => return .{ |
| 414 | .ios => .{ |
| 302 | 415 | .semver = .{ |
| 303 | 416 | .min = .{ .major = 12, .minor = 0, .patch = 0 }, |
| 304 | 417 | .max = .{ .major = 17, .minor = 1, .patch = 0 }, |
| 305 | 418 | }, |
| 306 | 419 | }, |
| 307 | | .watchos => return .{ |
| 420 | .watchos => .{ |
| 308 | 421 | .semver = .{ |
| 309 | 422 | .min = .{ .major = 6, .minor = 0, .patch = 0 }, |
| 310 | 423 | .max = .{ .major = 10, .minor = 1, .patch = 0 }, |
| 311 | 424 | }, |
| 312 | 425 | }, |
| 313 | | .tvos => return .{ |
| 426 | .tvos => .{ |
| 314 | 427 | .semver = .{ |
| 315 | 428 | .min = .{ .major = 13, .minor = 0, .patch = 0 }, |
| 316 | 429 | .max = .{ .major = 17, .minor = 1, .patch = 0 }, |
| 317 | 430 | }, |
| 318 | 431 | }, |
| 319 | | .netbsd => return .{ |
| 432 | .netbsd => .{ |
| 320 | 433 | .semver = .{ |
| 321 | 434 | .min = .{ .major = 8, .minor = 0, .patch = 0 }, |
| 322 | 435 | .max = .{ .major = 10, .minor = 0, .patch = 0 }, |
| 323 | 436 | }, |
| 324 | 437 | }, |
| 325 | | .openbsd => return .{ |
| 438 | .openbsd => .{ |
| 326 | 439 | .semver = .{ |
| 327 | 440 | .min = .{ .major = 6, .minor = 8, .patch = 0 }, |
| 328 | 441 | .max = .{ .major = 7, .minor = 4, .patch = 0 }, |
| 329 | 442 | }, |
| 330 | 443 | }, |
| 331 | | .dragonfly => return .{ |
| 444 | .dragonfly => .{ |
| 332 | 445 | .semver = .{ |
| 333 | 446 | .min = .{ .major = 5, .minor = 8, .patch = 0 }, |
| 334 | 447 | .max = .{ .major = 6, .minor = 4, .patch = 0 }, |
| 335 | 448 | }, |
| 336 | 449 | }, |
| 337 | | .solaris => return .{ |
| 450 | .solaris => .{ |
| 338 | 451 | .semver = .{ |
| 339 | 452 | .min = .{ .major = 5, .minor = 11, .patch = 0 }, |
| 340 | 453 | .max = .{ .major = 5, .minor = 11, .patch = 0 }, |
| 341 | 454 | }, |
| 342 | 455 | }, |
| 456 | .wasi => .{ |
| 457 | .semver = .{ |
| 458 | .min = .{ .major = 0, .minor = 1, .patch = 0 }, |
| 459 | .max = .{ .major = 0, .minor = 1, .patch = 0 }, |
| 460 | }, |
| 461 | }, |
| 343 | 462 | |
| 344 | | .linux => return .{ |
| 463 | .linux => .{ |
| 345 | 464 | .linux = .{ |
| 346 | 465 | .range = .{ |
| 347 | 466 | .min = .{ .major = 4, .minor = 19, .patch = 0 }, |
| ... | ... | @@ -351,13 +470,13 @@ pub const Os = struct { |
| 351 | 470 | }, |
| 352 | 471 | }, |
| 353 | 472 | |
| 354 | | .windows => return .{ |
| 473 | .windows => .{ |
| 355 | 474 | .windows = .{ |
| 356 | 475 | .min = .win8_1, |
| 357 | 476 | .max = WindowsVersion.latest, |
| 358 | 477 | }, |
| 359 | 478 | }, |
| 360 | | } |
| 479 | }; |
| 361 | 480 | } |
| 362 | 481 | }; |
| 363 | 482 | |
| ... | ... | @@ -370,38 +489,28 @@ pub const Os = struct { |
| 370 | 489 | |
| 371 | 490 | /// Provides a tagged union. `Target` does not store the tag because it is |
| 372 | 491 | /// redundant with the OS tag; this function abstracts that part away. |
| 373 | | pub inline fn getVersionRange(self: Os) TaggedVersionRange { |
| 374 | | switch (self.tag) { |
| 375 | | .linux => return TaggedVersionRange{ .linux = self.version_range.linux }, |
| 376 | | .windows => return TaggedVersionRange{ .windows = self.version_range.windows }, |
| 377 | | |
| 378 | | .freebsd, |
| 379 | | .macos, |
| 380 | | .ios, |
| 381 | | .tvos, |
| 382 | | .watchos, |
| 383 | | .netbsd, |
| 384 | | .openbsd, |
| 385 | | .dragonfly, |
| 386 | | .solaris, |
| 387 | | => return TaggedVersionRange{ .semver = self.version_range.semver }, |
| 388 | | |
| 389 | | else => return .none, |
| 390 | | } |
| 492 | pub inline fn getVersionRange(os: Os) TaggedVersionRange { |
| 493 | return switch (os.tag.getVersionRangeTag()) { |
| 494 | .none => .{ .none = {} }, |
| 495 | .semver => .{ .semver = os.version_range.semver }, |
| 496 | .linux => .{ .linux = os.version_range.linux }, |
| 497 | .windows => .{ .windows = os.version_range.windows }, |
| 498 | }; |
| 391 | 499 | } |
| 392 | 500 | |
| 393 | 501 | /// Checks if system is guaranteed to be at least `version` or older than `version`. |
| 394 | 502 | /// Returns `null` if a runtime check is required. |
| 395 | | pub inline fn isAtLeast(self: Os, comptime tag: Tag, version: switch (tag) { |
| 396 | | else => std.SemanticVersion, |
| 503 | pub inline fn isAtLeast(os: Os, comptime tag: Tag, ver: switch (tag.getVersionRangeTag()) { |
| 504 | .none => void, |
| 505 | .semver, .linux => std.SemanticVersion, |
| 397 | 506 | .windows => WindowsVersion, |
| 398 | 507 | }) ?bool { |
| 399 | | if (self.tag != tag) return false; |
| 400 | | |
| 401 | | return switch (tag) { |
| 402 | | .linux => self.version_range.linux.isAtLeast(version), |
| 403 | | .windows => self.version_range.windows.isAtLeast(version), |
| 404 | | else => self.version_range.semver.isAtLeast(version), |
| 508 | return if (os.tag != tag) false else switch (tag.getVersionRangeTag()) { |
| 509 | .none => true, |
| 510 | inline .semver, |
| 511 | .linux, |
| 512 | .windows, |
| 513 | => |field| @field(os.version_range, @tagName(field)).isAtLeast(ver), |
| 405 | 514 | }; |
| 406 | 515 | } |
| 407 | 516 | |
| ... | ... | @@ -528,11 +637,8 @@ pub const Abi = enum { |
| 528 | 637 | mesh, |
| 529 | 638 | amplification, |
| 530 | 639 | |
| 531 | | pub fn default(arch: Cpu.Arch, target_os: Os) Abi { |
| 532 | | if (arch.isWasm()) { |
| 533 | | return .musl; |
| 534 | | } |
| 535 | | switch (target_os.tag) { |
| 640 | pub fn default(arch: Cpu.Arch, os: Os) Abi { |
| 641 | return if (arch.isWasm()) .musl else switch (os.tag) { |
| 536 | 642 | .freestanding, |
| 537 | 643 | .ananas, |
| 538 | 644 | .cloudabi, |
| ... | ... | @@ -554,7 +660,7 @@ pub const Abi = enum { |
| 554 | 660 | .amdpal, |
| 555 | 661 | .hermit, |
| 556 | 662 | .other, |
| 557 | | => return .eabi, |
| 663 | => .eabi, |
| 558 | 664 | .openbsd, |
| 559 | 665 | .freebsd, |
| 560 | 666 | .fuchsia, |
| ... | ... | @@ -563,12 +669,12 @@ pub const Abi = enum { |
| 563 | 669 | .hurd, |
| 564 | 670 | .haiku, |
| 565 | 671 | .windows, |
| 566 | | => return .gnu, |
| 567 | | .uefi => return .msvc, |
| 672 | => .gnu, |
| 673 | .uefi => .msvc, |
| 568 | 674 | .linux, |
| 569 | 675 | .wasi, |
| 570 | 676 | .emscripten, |
| 571 | | => return .musl, |
| 677 | => .musl, |
| 572 | 678 | .opencl, // TODO: SPIR-V ABIs with Linkage capability |
| 573 | 679 | .glsl450, |
| 574 | 680 | .vulkan, |
| ... | ... | @@ -582,8 +688,8 @@ pub const Abi = enum { |
| 582 | 688 | .liteos, // TODO: audit this |
| 583 | 689 | .solaris, |
| 584 | 690 | .illumos, |
| 585 | | => return .none, |
| 586 | | } |
| 691 | => .none, |
| 692 | }; |
| 587 | 693 | } |
| 588 | 694 | |
| 589 | 695 | pub inline fn isGnu(abi: Abi) bool { |
| ... | ... | @@ -635,7 +741,7 @@ pub const ObjectFormat = enum { |
| 635 | 741 | /// Nvidia PTX format |
| 636 | 742 | nvptx, |
| 637 | 743 | |
| 638 | | pub fn fileExt(of: ObjectFormat, cpu_arch: Cpu.Arch) [:0]const u8 { |
| 744 | pub fn fileExt(of: ObjectFormat, arch: Cpu.Arch) [:0]const u8 { |
| 639 | 745 | return switch (of) { |
| 640 | 746 | .coff => ".obj", |
| 641 | 747 | .elf, .macho, .wasm => ".o", |
| ... | ... | @@ -643,18 +749,18 @@ pub const ObjectFormat = enum { |
| 643 | 749 | .spirv => ".spv", |
| 644 | 750 | .hex => ".ihex", |
| 645 | 751 | .raw => ".bin", |
| 646 | | .plan9 => plan9Ext(cpu_arch), |
| 752 | .plan9 => arch.plan9Ext(), |
| 647 | 753 | .nvptx => ".ptx", |
| 648 | 754 | .dxcontainer => ".dxil", |
| 649 | 755 | }; |
| 650 | 756 | } |
| 651 | 757 | |
| 652 | | pub fn default(os_tag: Os.Tag, cpu_arch: Cpu.Arch) ObjectFormat { |
| 758 | pub fn default(os_tag: Os.Tag, arch: Cpu.Arch) ObjectFormat { |
| 653 | 759 | return switch (os_tag) { |
| 654 | 760 | .windows, .uefi => .coff, |
| 655 | 761 | .ios, .macos, .watchos, .tvos => .macho, |
| 656 | 762 | .plan9 => .plan9, |
| 657 | | else => return switch (cpu_arch) { |
| 763 | else => switch (arch) { |
| 658 | 764 | .wasm32, .wasm64 => .wasm, |
| 659 | 765 | .spirv32, .spirv64 => .spirv, |
| 660 | 766 | .nvptx, .nvptx64 => .nvptx, |
| ... | ... | @@ -725,14 +831,14 @@ pub const Cpu = struct { |
| 725 | 831 | |
| 726 | 832 | pub fn isEnabled(set: Set, arch_feature_index: Index) bool { |
| 727 | 833 | const usize_index = arch_feature_index / @bitSizeOf(usize); |
| 728 | | const bit_index = @as(ShiftInt, @intCast(arch_feature_index % @bitSizeOf(usize))); |
| 834 | const bit_index: ShiftInt = @intCast(arch_feature_index % @bitSizeOf(usize)); |
| 729 | 835 | return (set.ints[usize_index] & (@as(usize, 1) << bit_index)) != 0; |
| 730 | 836 | } |
| 731 | 837 | |
| 732 | 838 | /// Adds the specified feature but not its dependencies. |
| 733 | 839 | pub fn addFeature(set: *Set, arch_feature_index: Index) void { |
| 734 | 840 | const usize_index = arch_feature_index / @bitSizeOf(usize); |
| 735 | | const bit_index = @as(ShiftInt, @intCast(arch_feature_index % @bitSizeOf(usize))); |
| 841 | const bit_index: ShiftInt = @intCast(arch_feature_index % @bitSizeOf(usize)); |
| 736 | 842 | set.ints[usize_index] |= @as(usize, 1) << bit_index; |
| 737 | 843 | } |
| 738 | 844 | |
| ... | ... | @@ -751,7 +857,7 @@ pub const Cpu = struct { |
| 751 | 857 | /// Removes the specified feature but not its dependents. |
| 752 | 858 | pub fn removeFeature(set: *Set, arch_feature_index: Index) void { |
| 753 | 859 | const usize_index = arch_feature_index / @bitSizeOf(usize); |
| 754 | | const bit_index = @as(ShiftInt, @intCast(arch_feature_index % @bitSizeOf(usize))); |
| 860 | const bit_index: ShiftInt = @intCast(arch_feature_index % @bitSizeOf(usize)); |
| 755 | 861 | set.ints[usize_index] &= ~(@as(usize, 1) << bit_index); |
| 756 | 862 | } |
| 757 | 863 | |
| ... | ... | @@ -773,7 +879,7 @@ pub const Cpu = struct { |
| 773 | 879 | var old = set.ints; |
| 774 | 880 | while (true) { |
| 775 | 881 | for (all_features_list, 0..) |feature, index_usize| { |
| 776 | | const index = @as(Index, @intCast(index_usize)); |
| 882 | const index: Index = @intCast(index_usize); |
| 777 | 883 | if (set.isEnabled(index)) { |
| 778 | 884 | set.addFeatureSet(feature.dependencies); |
| 779 | 885 | } |
| ... | ... | @@ -785,7 +891,7 @@ pub const Cpu = struct { |
| 785 | 891 | } |
| 786 | 892 | |
| 787 | 893 | pub fn asBytes(set: *const Set) *const [byte_count]u8 { |
| 788 | | return @as(*const [byte_count]u8, @ptrCast(&set.ints)); |
| 894 | return std.mem.sliceAsBytes(&set.ints)[0..byte_count]; |
| 789 | 895 | } |
| 790 | 896 | |
| 791 | 897 | pub fn eql(set: Set, other_set: Set) bool { |
| ... | ... | @@ -1231,7 +1337,7 @@ pub const Cpu = struct { |
| 1231 | 1337 | } |
| 1232 | 1338 | |
| 1233 | 1339 | /// Returns a name that matches the lib/std/target/* source file name. |
| 1234 | | pub fn genericName(arch: Arch) []const u8 { |
| 1340 | pub fn genericName(arch: Arch) [:0]const u8 { |
| 1235 | 1341 | return switch (arch) { |
| 1236 | 1342 | .arm, .armeb, .thumb, .thumbeb => "arm", |
| 1237 | 1343 | .aarch64, .aarch64_be, .aarch64_32 => "aarch64", |
| ... | ... | @@ -1320,6 +1426,30 @@ pub const Cpu = struct { |
| 1320 | 1426 | const finalized = array; |
| 1321 | 1427 | return &finalized; |
| 1322 | 1428 | } |
| 1429 | |
| 1430 | /// 0c spim little-endian MIPS 3000 family |
| 1431 | /// 1c 68000 Motorola MC68000 |
| 1432 | /// 2c 68020 Motorola MC68020 |
| 1433 | /// 5c arm little-endian ARM |
| 1434 | /// 6c amd64 AMD64 and compatibles (e.g., Intel EM64T) |
| 1435 | /// 7c arm64 ARM64 (ARMv8) |
| 1436 | /// 8c 386 Intel x86, i486, Pentium, etc. |
| 1437 | /// kc sparc Sun SPARC |
| 1438 | /// qc power Power PC |
| 1439 | /// vc mips big-endian MIPS 3000 family |
| 1440 | pub fn plan9Ext(arch: Cpu.Arch) [:0]const u8 { |
| 1441 | return switch (arch) { |
| 1442 | .arm => ".5", |
| 1443 | .x86_64 => ".6", |
| 1444 | .aarch64 => ".7", |
| 1445 | .x86 => ".8", |
| 1446 | .sparc => ".k", |
| 1447 | .powerpc, .powerpcle => ".q", |
| 1448 | .mips, .mipsel => ".v", |
| 1449 | // ISAs without designated characters get 'X' for lack of a better option. |
| 1450 | else => ".X", |
| 1451 | }; |
| 1452 | } |
| 1323 | 1453 | }; |
| 1324 | 1454 | |
| 1325 | 1455 | pub const Model = struct { |
| ... | ... | @@ -1399,112 +1529,76 @@ pub const Cpu = struct { |
| 1399 | 1529 | } |
| 1400 | 1530 | }; |
| 1401 | 1531 | |
| 1402 | | pub fn zigTriple(self: Target, allocator: Allocator) Allocator.Error![]u8 { |
| 1403 | | return Query.fromTarget(self).zigTriple(allocator); |
| 1532 | pub fn zigTriple(target: Target, allocator: Allocator) Allocator.Error![]u8 { |
| 1533 | return Query.fromTarget(target).zigTriple(allocator); |
| 1404 | 1534 | } |
| 1405 | 1535 | |
| 1406 | | pub fn linuxTripleSimple(allocator: Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![]u8 { |
| 1407 | | return std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{ @tagName(cpu_arch), @tagName(os_tag), @tagName(abi) }); |
| 1536 | pub fn linuxTripleSimple(allocator: Allocator, arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![]u8 { |
| 1537 | return std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{ @tagName(arch), @tagName(os_tag), @tagName(abi) }); |
| 1408 | 1538 | } |
| 1409 | 1539 | |
| 1410 | | pub fn linuxTriple(self: Target, allocator: Allocator) ![]u8 { |
| 1411 | | return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi); |
| 1540 | pub fn linuxTriple(target: Target, allocator: Allocator) ![]u8 { |
| 1541 | return linuxTripleSimple(allocator, target.cpu.arch, target.os.tag, target.abi); |
| 1412 | 1542 | } |
| 1413 | 1543 | |
| 1414 | | pub fn exeFileExtSimple(cpu_arch: Cpu.Arch, os_tag: Os.Tag) [:0]const u8 { |
| 1415 | | return switch (os_tag) { |
| 1416 | | .windows => ".exe", |
| 1417 | | .uefi => ".efi", |
| 1418 | | .plan9 => plan9Ext(cpu_arch), |
| 1419 | | else => switch (cpu_arch) { |
| 1420 | | .wasm32, .wasm64 => ".wasm", |
| 1421 | | else => "", |
| 1422 | | }, |
| 1423 | | }; |
| 1424 | | } |
| 1425 | | |
| 1426 | | pub fn exeFileExt(self: Target) [:0]const u8 { |
| 1427 | | return exeFileExtSimple(self.cpu.arch, self.os.tag); |
| 1428 | | } |
| 1429 | | |
| 1430 | | pub fn staticLibSuffix_os_abi(os_tag: Os.Tag, abi: Abi) [:0]const u8 { |
| 1431 | | if (abi == .msvc) { |
| 1432 | | return ".lib"; |
| 1433 | | } |
| 1434 | | switch (os_tag) { |
| 1435 | | .windows, .uefi => return ".lib", |
| 1436 | | else => return ".a", |
| 1437 | | } |
| 1438 | | } |
| 1439 | | |
| 1440 | | pub fn staticLibSuffix(self: Target) [:0]const u8 { |
| 1441 | | return staticLibSuffix_os_abi(self.os.tag, self.abi); |
| 1442 | | } |
| 1443 | | |
| 1444 | | pub fn dynamicLibSuffix(self: Target) [:0]const u8 { |
| 1445 | | return self.os.tag.dynamicLibSuffix(); |
| 1544 | pub fn exeFileExt(target: Target) [:0]const u8 { |
| 1545 | return target.os.tag.exeFileExt(target.cpu.arch); |
| 1446 | 1546 | } |
| 1447 | 1547 | |
| 1448 | | pub fn libPrefix_os_abi(os_tag: Os.Tag, abi: Abi) [:0]const u8 { |
| 1449 | | if (abi == .msvc) { |
| 1450 | | return ""; |
| 1451 | | } |
| 1452 | | switch (os_tag) { |
| 1453 | | .windows, .uefi => return "", |
| 1454 | | else => return "lib", |
| 1455 | | } |
| 1548 | pub fn staticLibSuffix(target: Target) [:0]const u8 { |
| 1549 | return target.os.tag.staticLibSuffix(target.abi); |
| 1456 | 1550 | } |
| 1457 | 1551 | |
| 1458 | | pub fn libPrefix(self: Target) [:0]const u8 { |
| 1459 | | return libPrefix_os_abi(self.os.tag, self.abi); |
| 1552 | pub fn dynamicLibSuffix(target: Target) [:0]const u8 { |
| 1553 | return target.os.tag.dynamicLibSuffix(); |
| 1460 | 1554 | } |
| 1461 | 1555 | |
| 1462 | | pub inline fn isMinGW(self: Target) bool { |
| 1463 | | return self.os.tag == .windows and self.isGnu(); |
| 1556 | pub fn libPrefix(target: Target) [:0]const u8 { |
| 1557 | return target.os.tag.libPrefix(target.abi); |
| 1464 | 1558 | } |
| 1465 | 1559 | |
| 1466 | | pub inline fn isGnu(self: Target) bool { |
| 1467 | | return self.abi.isGnu(); |
| 1560 | pub inline fn isMinGW(target: Target) bool { |
| 1561 | return target.os.tag == .windows and target.isGnu(); |
| 1468 | 1562 | } |
| 1469 | 1563 | |
| 1470 | | pub inline fn isMusl(self: Target) bool { |
| 1471 | | return self.abi.isMusl(); |
| 1564 | pub inline fn isGnu(target: Target) bool { |
| 1565 | return target.abi.isGnu(); |
| 1472 | 1566 | } |
| 1473 | 1567 | |
| 1474 | | pub inline fn isAndroid(self: Target) bool { |
| 1475 | | return self.abi == .android; |
| 1568 | pub inline fn isMusl(target: Target) bool { |
| 1569 | return target.abi.isMusl(); |
| 1476 | 1570 | } |
| 1477 | 1571 | |
| 1478 | | pub inline fn isWasm(self: Target) bool { |
| 1479 | | return self.cpu.arch.isWasm(); |
| 1572 | pub inline fn isAndroid(target: Target) bool { |
| 1573 | return target.abi == .android; |
| 1480 | 1574 | } |
| 1481 | 1575 | |
| 1482 | | pub inline fn isDarwin(self: Target) bool { |
| 1483 | | return self.os.tag.isDarwin(); |
| 1576 | pub inline fn isWasm(target: Target) bool { |
| 1577 | return target.cpu.arch.isWasm(); |
| 1484 | 1578 | } |
| 1485 | 1579 | |
| 1486 | | pub inline fn isBSD(self: Target) bool { |
| 1487 | | return self.os.tag.isBSD(); |
| 1580 | pub inline fn isDarwin(target: Target) bool { |
| 1581 | return target.os.tag.isDarwin(); |
| 1488 | 1582 | } |
| 1489 | 1583 | |
| 1490 | | pub inline fn isBpfFreestanding(self: Target) bool { |
| 1491 | | return self.cpu.arch.isBpf() and self.os.tag == .freestanding; |
| 1584 | pub inline fn isBSD(target: Target) bool { |
| 1585 | return target.os.tag.isBSD(); |
| 1492 | 1586 | } |
| 1493 | 1587 | |
| 1494 | | pub inline fn isGnuLibC_os_tag_abi(os_tag: Os.Tag, abi: Abi) bool { |
| 1495 | | return os_tag == .linux and abi.isGnu(); |
| 1588 | pub inline fn isBpfFreestanding(target: Target) bool { |
| 1589 | return target.cpu.arch.isBpf() and target.os.tag == .freestanding; |
| 1496 | 1590 | } |
| 1497 | 1591 | |
| 1498 | | pub inline fn isGnuLibC(self: Target) bool { |
| 1499 | | return isGnuLibC_os_tag_abi(self.os.tag, self.abi); |
| 1592 | pub inline fn isGnuLibC(target: Target) bool { |
| 1593 | return target.os.tag.isGnuLibC(target.abi); |
| 1500 | 1594 | } |
| 1501 | 1595 | |
| 1502 | | pub inline fn supportsNewStackCall(self: Target) bool { |
| 1503 | | return !self.cpu.arch.isWasm(); |
| 1596 | pub inline fn supportsNewStackCall(target: Target) bool { |
| 1597 | return !target.cpu.arch.isWasm(); |
| 1504 | 1598 | } |
| 1505 | 1599 | |
| 1506 | | pub inline fn isSpirV(self: Target) bool { |
| 1507 | | return self.cpu.arch.isSpirV(); |
| 1600 | pub inline fn isSpirV(target: Target) bool { |
| 1601 | return target.cpu.arch.isSpirV(); |
| 1508 | 1602 | } |
| 1509 | 1603 | |
| 1510 | 1604 | pub const FloatAbi = enum { |
| ... | ... | @@ -1512,15 +1606,15 @@ pub const FloatAbi = enum { |
| 1512 | 1606 | soft, |
| 1513 | 1607 | }; |
| 1514 | 1608 | |
| 1515 | | pub inline fn getFloatAbi(self: Target) FloatAbi { |
| 1516 | | return self.abi.floatAbi(); |
| 1609 | pub inline fn getFloatAbi(target: Target) FloatAbi { |
| 1610 | return target.abi.floatAbi(); |
| 1517 | 1611 | } |
| 1518 | 1612 | |
| 1519 | | pub inline fn hasDynamicLinker(self: Target) bool { |
| 1520 | | if (self.cpu.arch.isWasm()) { |
| 1613 | pub inline fn hasDynamicLinker(target: Target) bool { |
| 1614 | if (target.cpu.arch.isWasm()) { |
| 1521 | 1615 | return false; |
| 1522 | 1616 | } |
| 1523 | | switch (self.os.tag) { |
| 1617 | switch (target.os.tag) { |
| 1524 | 1618 | .freestanding, |
| 1525 | 1619 | .ios, |
| 1526 | 1620 | .tvos, |
| ... | ... | @@ -1547,259 +1641,210 @@ pub const DynamicLinker = struct { |
| 1547 | 1641 | |
| 1548 | 1642 | /// Used to construct the dynamic linker path. This field should not be used |
| 1549 | 1643 | /// directly. See `get` and `set`. |
| 1550 | | max_byte: ?u8, |
| 1644 | len: u8, |
| 1551 | 1645 | |
| 1552 | | pub const none: DynamicLinker = .{ |
| 1553 | | .buffer = undefined, |
| 1554 | | .max_byte = null, |
| 1555 | | }; |
| 1646 | pub const none: DynamicLinker = .{ .buffer = undefined, .len = 0 }; |
| 1556 | 1647 | |
| 1557 | 1648 | /// Asserts that the length is less than or equal to 255 bytes. |
| 1558 | | pub fn init(dl_or_null: ?[]const u8) DynamicLinker { |
| 1559 | | var result: DynamicLinker = undefined; |
| 1560 | | result.set(dl_or_null); |
| 1561 | | return result; |
| 1649 | pub fn init(maybe_path: ?[]const u8) DynamicLinker { |
| 1650 | var dl: DynamicLinker = undefined; |
| 1651 | dl.set(maybe_path); |
| 1652 | return dl; |
| 1653 | } |
| 1654 | |
| 1655 | pub fn initFmt(comptime fmt_str: []const u8, args: anytype) !DynamicLinker { |
| 1656 | var dl: DynamicLinker = undefined; |
| 1657 | try dl.setFmt(fmt_str, args); |
| 1658 | return dl; |
| 1562 | 1659 | } |
| 1563 | 1660 | |
| 1564 | 1661 | /// The returned memory has the same lifetime as the `DynamicLinker`. |
| 1565 | | pub fn get(self: *const DynamicLinker) ?[]const u8 { |
| 1566 | | const m: usize = self.max_byte orelse return null; |
| 1567 | | return self.buffer[0 .. m + 1]; |
| 1662 | pub fn get(dl: *const DynamicLinker) ?[]const u8 { |
| 1663 | return if (dl.len > 0) dl.buffer[0..dl.len] else null; |
| 1568 | 1664 | } |
| 1569 | 1665 | |
| 1570 | 1666 | /// Asserts that the length is less than or equal to 255 bytes. |
| 1571 | | pub fn set(self: *DynamicLinker, dl_or_null: ?[]const u8) void { |
| 1572 | | if (dl_or_null) |dl| { |
| 1573 | | @memcpy(self.buffer[0..dl.len], dl); |
| 1574 | | self.max_byte = @intCast(dl.len - 1); |
| 1575 | | } else { |
| 1576 | | self.max_byte = null; |
| 1577 | | } |
| 1667 | pub fn set(dl: *DynamicLinker, maybe_path: ?[]const u8) void { |
| 1668 | const path = maybe_path orelse ""; |
| 1669 | @memcpy(dl.buffer[0..path.len], path); |
| 1670 | dl.len = @intCast(path.len); |
| 1578 | 1671 | } |
| 1579 | 1672 | |
| 1580 | | pub fn eql(a: DynamicLinker, b: DynamicLinker) bool { |
| 1581 | | const a_m = a.max_byte orelse return b.max_byte == null; |
| 1582 | | const b_m = b.max_byte orelse return false; |
| 1583 | | if (a_m != b_m) return false; |
| 1584 | | const a_s = a.buffer[0 .. a_m + 1]; |
| 1585 | | const b_s = b.buffer[0 .. a_m + 1]; |
| 1586 | | return std.mem.eql(u8, a_s, b_s); |
| 1673 | /// Asserts that the length is less than or equal to 255 bytes. |
| 1674 | pub fn setFmt(dl: *DynamicLinker, comptime fmt_str: []const u8, args: anytype) !void { |
| 1675 | dl.len = @intCast((try std.fmt.bufPrint(&dl.buffer, fmt_str, args)).len); |
| 1587 | 1676 | } |
| 1588 | | }; |
| 1589 | 1677 | |
| 1590 | | pub fn standardDynamicLinkerPath(target: Target) DynamicLinker { |
| 1591 | | return standardDynamicLinkerPath_cpu_os_abi(target.cpu, target.os.tag, target.abi); |
| 1592 | | } |
| 1593 | | |
| 1594 | | pub fn standardDynamicLinkerPath_cpu_os_abi(cpu: Cpu, os_tag: Os.Tag, abi: Abi) DynamicLinker { |
| 1595 | | var result = DynamicLinker.none; |
| 1596 | | const S = struct { |
| 1597 | | fn print(r: *DynamicLinker, comptime fmt: []const u8, args: anytype) DynamicLinker { |
| 1598 | | r.max_byte = @as(u8, @intCast((std.fmt.bufPrint(&r.buffer, fmt, args) catch unreachable).len - 1)); |
| 1599 | | return r.*; |
| 1600 | | } |
| 1601 | | fn copy(r: *DynamicLinker, s: []const u8) DynamicLinker { |
| 1602 | | @memcpy(r.buffer[0..s.len], s); |
| 1603 | | r.max_byte = @as(u8, @intCast(s.len - 1)); |
| 1604 | | return r.*; |
| 1605 | | } |
| 1606 | | }; |
| 1607 | | const print = S.print; |
| 1608 | | const copy = S.copy; |
| 1609 | | |
| 1610 | | if (abi == .android) { |
| 1611 | | const suffix = if (ptrBitWidth_cpu_abi(cpu, abi) == 64) "64" else ""; |
| 1612 | | return print(&result, "/system/bin/linker{s}", .{suffix}); |
| 1678 | pub fn eql(lhs: DynamicLinker, rhs: DynamicLinker) bool { |
| 1679 | return std.mem.eql(u8, lhs.buffer[0..lhs.len], rhs.buffer[0..rhs.len]); |
| 1613 | 1680 | } |
| 1614 | 1681 | |
| 1615 | | if (abi.isMusl()) { |
| 1616 | | const is_arm = switch (cpu.arch) { |
| 1617 | | .arm, .armeb, .thumb, .thumbeb => true, |
| 1618 | | else => false, |
| 1619 | | }; |
| 1620 | | const arch_part = switch (cpu.arch) { |
| 1621 | | .arm, .thumb => "arm", |
| 1622 | | .armeb, .thumbeb => "armeb", |
| 1623 | | else => |arch| @tagName(arch), |
| 1624 | | }; |
| 1625 | | const arch_suffix = if (is_arm and abi.floatAbi() == .hard) "hf" else ""; |
| 1626 | | return print(&result, "/lib/ld-musl-{s}{s}.so.1", .{ arch_part, arch_suffix }); |
| 1627 | | } |
| 1682 | pub fn standard(cpu: Cpu, os_tag: Os.Tag, abi: Abi) DynamicLinker { |
| 1683 | return if (abi == .android) initFmt("/system/bin/linker{s}", .{ |
| 1684 | if (ptrBitWidth_cpu_abi(cpu, abi) == 64) "64" else "", |
| 1685 | }) catch unreachable else if (abi.isMusl()) return initFmt("/lib/ld-musl-{s}{s}.so.1", .{ |
| 1686 | @tagName(switch (cpu.arch) { |
| 1687 | .thumb => .arm, |
| 1688 | .thumbeb => .armeb, |
| 1689 | else => cpu.arch, |
| 1690 | }), |
| 1691 | if (cpu.arch.isArmOrThumb() and abi.floatAbi() == .hard) "hf" else "", |
| 1692 | }) catch unreachable else switch (os_tag) { |
| 1693 | .freebsd => init("/libexec/ld-elf.so.1"), |
| 1694 | .netbsd => init("/libexec/ld.elf_so"), |
| 1695 | .openbsd => init("/usr/libexec/ld.so"), |
| 1696 | .dragonfly => init("/libexec/ld-elf.so.2"), |
| 1697 | .solaris, .illumos => init("/lib/64/ld.so.1"), |
| 1698 | .linux => switch (cpu.arch) { |
| 1699 | .x86, |
| 1700 | .sparc, |
| 1701 | .sparcel, |
| 1702 | => init("/lib/ld-linux.so.2"), |
| 1628 | 1703 | |
| 1629 | | switch (os_tag) { |
| 1630 | | .freebsd => return copy(&result, "/libexec/ld-elf.so.1"), |
| 1631 | | .netbsd => return copy(&result, "/libexec/ld.elf_so"), |
| 1632 | | .openbsd => return copy(&result, "/usr/libexec/ld.so"), |
| 1633 | | .dragonfly => return copy(&result, "/libexec/ld-elf.so.2"), |
| 1634 | | .solaris, .illumos => return copy(&result, "/lib/64/ld.so.1"), |
| 1635 | | .linux => switch (cpu.arch) { |
| 1636 | | .x86, |
| 1637 | | .sparc, |
| 1638 | | .sparcel, |
| 1639 | | => return copy(&result, "/lib/ld-linux.so.2"), |
| 1704 | .aarch64 => init("/lib/ld-linux-aarch64.so.1"), |
| 1705 | .aarch64_be => init("/lib/ld-linux-aarch64_be.so.1"), |
| 1706 | .aarch64_32 => init("/lib/ld-linux-aarch64_32.so.1"), |
| 1640 | 1707 | |
| 1641 | | .aarch64 => return copy(&result, "/lib/ld-linux-aarch64.so.1"), |
| 1642 | | .aarch64_be => return copy(&result, "/lib/ld-linux-aarch64_be.so.1"), |
| 1643 | | .aarch64_32 => return copy(&result, "/lib/ld-linux-aarch64_32.so.1"), |
| 1708 | .arm, |
| 1709 | .armeb, |
| 1710 | .thumb, |
| 1711 | .thumbeb, |
| 1712 | => initFmt("/lib/ld-linux{s}.so.3", .{switch (abi.floatAbi()) { |
| 1713 | .hard => "-armhf", |
| 1714 | else => "", |
| 1715 | }}) catch unreachable, |
| 1644 | 1716 | |
| 1645 | | .arm, |
| 1646 | | .armeb, |
| 1647 | | .thumb, |
| 1648 | | .thumbeb, |
| 1649 | | => return copy(&result, switch (abi.floatAbi()) { |
| 1650 | | .hard => "/lib/ld-linux-armhf.so.3", |
| 1651 | | else => "/lib/ld-linux.so.3", |
| 1652 | | }), |
| 1717 | .mips, |
| 1718 | .mipsel, |
| 1719 | .mips64, |
| 1720 | .mips64el, |
| 1721 | => initFmt("/lib{s}/{s}", .{ |
| 1722 | switch (abi) { |
| 1723 | .gnuabin32, .gnux32 => "32", |
| 1724 | .gnuabi64 => "64", |
| 1725 | else => "", |
| 1726 | }, |
| 1727 | if (mips.featureSetHas(cpu.features, .nan2008)) |
| 1728 | "ld-linux-mipsn8.so.1" |
| 1729 | else |
| 1730 | "ld.so.1", |
| 1731 | }) catch unreachable, |
| 1732 | |
| 1733 | .powerpc, .powerpcle => init("/lib/ld.so.1"), |
| 1734 | .powerpc64, .powerpc64le => init("/lib64/ld64.so.2"), |
| 1735 | .s390x => init("/lib64/ld64.so.1"), |
| 1736 | .sparc64 => init("/lib64/ld-linux.so.2"), |
| 1737 | .x86_64 => init(switch (abi) { |
| 1738 | .gnux32 => "/libx32/ld-linux-x32.so.2", |
| 1739 | else => "/lib64/ld-linux-x86-64.so.2", |
| 1740 | }), |
| 1741 | |
| 1742 | .riscv32 => init("/lib/ld-linux-riscv32-ilp32.so.1"), |
| 1743 | .riscv64 => init("/lib/ld-linux-riscv64-lp64.so.1"), |
| 1744 | |
| 1745 | // Architectures in this list have been verified as not having a standard |
| 1746 | // dynamic linker path. |
| 1747 | .wasm32, |
| 1748 | .wasm64, |
| 1749 | .bpfel, |
| 1750 | .bpfeb, |
| 1751 | .nvptx, |
| 1752 | .nvptx64, |
| 1753 | .spu_2, |
| 1754 | .avr, |
| 1755 | .spirv32, |
| 1756 | .spirv64, |
| 1757 | => none, |
| 1653 | 1758 | |
| 1654 | | .mips, |
| 1655 | | .mipsel, |
| 1656 | | .mips64, |
| 1657 | | .mips64el, |
| 1658 | | => { |
| 1659 | | const lib_suffix = switch (abi) { |
| 1660 | | .gnuabin32, .gnux32 => "32", |
| 1661 | | .gnuabi64 => "64", |
| 1662 | | else => "", |
| 1663 | | }; |
| 1664 | | const is_nan_2008 = mips.featureSetHas(cpu.features, .nan2008); |
| 1665 | | const loader = if (is_nan_2008) "ld-linux-mipsn8.so.1" else "ld.so.1"; |
| 1666 | | return print(&result, "/lib{s}/{s}", .{ lib_suffix, loader }); |
| 1759 | // TODO go over each item in this list and either move it to the above list, or |
| 1760 | // implement the standard dynamic linker path code for it. |
| 1761 | .arc, |
| 1762 | .csky, |
| 1763 | .hexagon, |
| 1764 | .m68k, |
| 1765 | .msp430, |
| 1766 | .r600, |
| 1767 | .amdgcn, |
| 1768 | .tce, |
| 1769 | .tcele, |
| 1770 | .xcore, |
| 1771 | .le32, |
| 1772 | .le64, |
| 1773 | .amdil, |
| 1774 | .amdil64, |
| 1775 | .hsail, |
| 1776 | .hsail64, |
| 1777 | .spir, |
| 1778 | .spir64, |
| 1779 | .kalimba, |
| 1780 | .shave, |
| 1781 | .lanai, |
| 1782 | .renderscript32, |
| 1783 | .renderscript64, |
| 1784 | .ve, |
| 1785 | .dxil, |
| 1786 | .loongarch32, |
| 1787 | .loongarch64, |
| 1788 | .xtensa, |
| 1789 | => none, |
| 1667 | 1790 | }, |
| 1668 | 1791 | |
| 1669 | | .powerpc, .powerpcle => return copy(&result, "/lib/ld.so.1"), |
| 1670 | | .powerpc64, .powerpc64le => return copy(&result, "/lib64/ld64.so.2"), |
| 1671 | | .s390x => return copy(&result, "/lib64/ld64.so.1"), |
| 1672 | | .sparc64 => return copy(&result, "/lib64/ld-linux.so.2"), |
| 1673 | | .x86_64 => return copy(&result, switch (abi) { |
| 1674 | | .gnux32 => "/libx32/ld-linux-x32.so.2", |
| 1675 | | else => "/lib64/ld-linux-x86-64.so.2", |
| 1676 | | }), |
| 1677 | | |
| 1678 | | .riscv32 => return copy(&result, "/lib/ld-linux-riscv32-ilp32.so.1"), |
| 1679 | | .riscv64 => return copy(&result, "/lib/ld-linux-riscv64-lp64.so.1"), |
| 1792 | .ios, |
| 1793 | .tvos, |
| 1794 | .watchos, |
| 1795 | .macos, |
| 1796 | => init("/usr/lib/dyld"), |
| 1680 | 1797 | |
| 1681 | | // Architectures in this list have been verified as not having a standard |
| 1798 | // Operating systems in this list have been verified as not having a standard |
| 1682 | 1799 | // dynamic linker path. |
| 1683 | | .wasm32, |
| 1684 | | .wasm64, |
| 1685 | | .bpfel, |
| 1686 | | .bpfeb, |
| 1687 | | .nvptx, |
| 1688 | | .nvptx64, |
| 1689 | | .spu_2, |
| 1690 | | .avr, |
| 1691 | | .spirv32, |
| 1692 | | .spirv64, |
| 1693 | | => return result, |
| 1800 | .freestanding, |
| 1801 | .uefi, |
| 1802 | .windows, |
| 1803 | .emscripten, |
| 1804 | .wasi, |
| 1805 | .opencl, |
| 1806 | .glsl450, |
| 1807 | .vulkan, |
| 1808 | .other, |
| 1809 | .plan9, |
| 1810 | => none, |
| 1811 | |
| 1812 | // TODO revisit when multi-arch for Haiku is available |
| 1813 | .haiku => init("/system/runtime_loader"), |
| 1694 | 1814 | |
| 1695 | 1815 | // TODO go over each item in this list and either move it to the above list, or |
| 1696 | 1816 | // implement the standard dynamic linker path code for it. |
| 1697 | | .arc, |
| 1698 | | .csky, |
| 1699 | | .hexagon, |
| 1700 | | .m68k, |
| 1701 | | .msp430, |
| 1702 | | .r600, |
| 1703 | | .amdgcn, |
| 1704 | | .tce, |
| 1705 | | .tcele, |
| 1706 | | .xcore, |
| 1707 | | .le32, |
| 1708 | | .le64, |
| 1709 | | .amdil, |
| 1710 | | .amdil64, |
| 1711 | | .hsail, |
| 1712 | | .hsail64, |
| 1713 | | .spir, |
| 1714 | | .spir64, |
| 1715 | | .kalimba, |
| 1716 | | .shave, |
| 1717 | | .lanai, |
| 1718 | | .renderscript32, |
| 1719 | | .renderscript64, |
| 1720 | | .ve, |
| 1721 | | .dxil, |
| 1722 | | .loongarch32, |
| 1723 | | .loongarch64, |
| 1724 | | .xtensa, |
| 1725 | | => return result, |
| 1726 | | }, |
| 1727 | | |
| 1728 | | .ios, |
| 1729 | | .tvos, |
| 1730 | | .watchos, |
| 1731 | | .macos, |
| 1732 | | => return copy(&result, "/usr/lib/dyld"), |
| 1733 | | |
| 1734 | | // Operating systems in this list have been verified as not having a standard |
| 1735 | | // dynamic linker path. |
| 1736 | | .freestanding, |
| 1737 | | .uefi, |
| 1738 | | .windows, |
| 1739 | | .emscripten, |
| 1740 | | .wasi, |
| 1741 | | .opencl, |
| 1742 | | .glsl450, |
| 1743 | | .vulkan, |
| 1744 | | .other, |
| 1745 | | .plan9, |
| 1746 | | => return result, |
| 1747 | | |
| 1748 | | // TODO revisit when multi-arch for Haiku is available |
| 1749 | | .haiku => return copy(&result, "/system/runtime_loader"), |
| 1750 | | |
| 1751 | | // TODO go over each item in this list and either move it to the above list, or |
| 1752 | | // implement the standard dynamic linker path code for it. |
| 1753 | | .ananas, |
| 1754 | | .cloudabi, |
| 1755 | | .fuchsia, |
| 1756 | | .kfreebsd, |
| 1757 | | .lv2, |
| 1758 | | .zos, |
| 1759 | | .minix, |
| 1760 | | .rtems, |
| 1761 | | .nacl, |
| 1762 | | .aix, |
| 1763 | | .cuda, |
| 1764 | | .nvcl, |
| 1765 | | .amdhsa, |
| 1766 | | .ps4, |
| 1767 | | .ps5, |
| 1768 | | .elfiamcu, |
| 1769 | | .mesa3d, |
| 1770 | | .contiki, |
| 1771 | | .amdpal, |
| 1772 | | .hermit, |
| 1773 | | .hurd, |
| 1774 | | .driverkit, |
| 1775 | | .shadermodel, |
| 1776 | | .liteos, |
| 1777 | | => return result, |
| 1817 | .ananas, |
| 1818 | .cloudabi, |
| 1819 | .fuchsia, |
| 1820 | .kfreebsd, |
| 1821 | .lv2, |
| 1822 | .zos, |
| 1823 | .minix, |
| 1824 | .rtems, |
| 1825 | .nacl, |
| 1826 | .aix, |
| 1827 | .cuda, |
| 1828 | .nvcl, |
| 1829 | .amdhsa, |
| 1830 | .ps4, |
| 1831 | .ps5, |
| 1832 | .elfiamcu, |
| 1833 | .mesa3d, |
| 1834 | .contiki, |
| 1835 | .amdpal, |
| 1836 | .hermit, |
| 1837 | .hurd, |
| 1838 | .driverkit, |
| 1839 | .shadermodel, |
| 1840 | .liteos, |
| 1841 | => none, |
| 1842 | }; |
| 1778 | 1843 | } |
| 1779 | | } |
| 1844 | }; |
| 1780 | 1845 | |
| 1781 | | /// 0c spim little-endian MIPS 3000 family |
| 1782 | | /// 1c 68000 Motorola MC68000 |
| 1783 | | /// 2c 68020 Motorola MC68020 |
| 1784 | | /// 5c arm little-endian ARM |
| 1785 | | /// 6c amd64 AMD64 and compatibles (e.g., Intel EM64T) |
| 1786 | | /// 7c arm64 ARM64 (ARMv8) |
| 1787 | | /// 8c 386 Intel x86, i486, Pentium, etc. |
| 1788 | | /// kc sparc Sun SPARC |
| 1789 | | /// qc power Power PC |
| 1790 | | /// vc mips big-endian MIPS 3000 family |
| 1791 | | pub fn plan9Ext(cpu_arch: Cpu.Arch) [:0]const u8 { |
| 1792 | | return switch (cpu_arch) { |
| 1793 | | .arm => ".5", |
| 1794 | | .x86_64 => ".6", |
| 1795 | | .aarch64 => ".7", |
| 1796 | | .x86 => ".8", |
| 1797 | | .sparc => ".k", |
| 1798 | | .powerpc, .powerpcle => ".q", |
| 1799 | | .mips, .mipsel => ".v", |
| 1800 | | // ISAs without designated characters get 'X' for lack of a better option. |
| 1801 | | else => ".X", |
| 1802 | | }; |
| 1846 | pub fn standardDynamicLinkerPath(target: Target) DynamicLinker { |
| 1847 | return DynamicLinker.standard(target.cpu, target.os.tag, target.abi); |
| 1803 | 1848 | } |
| 1804 | 1849 | |
| 1805 | 1850 | pub fn maxIntAlignment(target: Target) u16 { |
| ... | ... | @@ -2076,7 +2121,7 @@ pub fn c_type_byte_size(t: Target, c_type: CType) u16 { |
| 2076 | 2121 | 16 => 2, |
| 2077 | 2122 | 32 => 4, |
| 2078 | 2123 | 64 => 8, |
| 2079 | | 80 => @as(u16, @intCast(std.mem.alignForward(usize, 10, c_type_alignment(t, .longdouble)))), |
| 2124 | 80 => @intCast(std.mem.alignForward(usize, 10, c_type_alignment(t, .longdouble))), |
| 2080 | 2125 | 128 => 16, |
| 2081 | 2126 | else => unreachable, |
| 2082 | 2127 | }, |
| ... | ... | @@ -2419,7 +2464,7 @@ pub fn c_type_alignment(target: Target, c_type: CType) u16 { |
| 2419 | 2464 | // Next-power-of-two-aligned, up to a maximum. |
| 2420 | 2465 | return @min( |
| 2421 | 2466 | std.math.ceilPowerOfTwoAssert(u16, (c_type_bit_size(target, c_type) + 7) / 8), |
| 2422 | | switch (target.cpu.arch) { |
| 2467 | @as(u16, switch (target.cpu.arch) { |
| 2423 | 2468 | .arm, .armeb, .thumb, .thumbeb => switch (target.os.tag) { |
| 2424 | 2469 | .netbsd => switch (target.abi) { |
| 2425 | 2470 | .gnueabi, |
| ... | ... | @@ -2431,7 +2476,7 @@ pub fn c_type_alignment(target: Target, c_type: CType) u16 { |
| 2431 | 2476 | .musleabihf, |
| 2432 | 2477 | => 8, |
| 2433 | 2478 | |
| 2434 | | else => @as(u16, 4), |
| 2479 | else => 4, |
| 2435 | 2480 | }, |
| 2436 | 2481 | .ios, .tvos, .watchos => 4, |
| 2437 | 2482 | else => 8, |
| ... | ... | @@ -2501,7 +2546,7 @@ pub fn c_type_alignment(target: Target, c_type: CType) u16 { |
| 2501 | 2546 | .wasm32, |
| 2502 | 2547 | .wasm64, |
| 2503 | 2548 | => 16, |
| 2504 | | }, |
| 2549 | }), |
| 2505 | 2550 | ); |
| 2506 | 2551 | } |
| 2507 | 2552 | |
| ... | ... | @@ -2559,8 +2604,8 @@ pub fn c_type_preferred_alignment(target: Target, c_type: CType) u16 { |
| 2559 | 2604 | // Next-power-of-two-aligned, up to a maximum. |
| 2560 | 2605 | return @min( |
| 2561 | 2606 | std.math.ceilPowerOfTwoAssert(u16, (c_type_bit_size(target, c_type) + 7) / 8), |
| 2562 | | switch (target.cpu.arch) { |
| 2563 | | .msp430 => @as(u16, 2), |
| 2607 | @as(u16, switch (target.cpu.arch) { |
| 2608 | .msp430 => 2, |
| 2564 | 2609 | |
| 2565 | 2610 | .csky, |
| 2566 | 2611 | .xcore, |
| ... | ... | @@ -2627,7 +2672,7 @@ pub fn c_type_preferred_alignment(target: Target, c_type: CType) u16 { |
| 2627 | 2672 | .wasm32, |
| 2628 | 2673 | .wasm64, |
| 2629 | 2674 | => 16, |
| 2630 | | }, |
| 2675 | }), |
| 2631 | 2676 | ); |
| 2632 | 2677 | } |
| 2633 | 2678 | |
| ... | ... | @@ -2767,19 +2812,7 @@ fn eqlIgnoreCase(ignore_case: bool, a: []const u8, b: []const u8) bool { |
| 2767 | 2812 | } |
| 2768 | 2813 | |
| 2769 | 2814 | pub fn osArchName(target: std.Target) [:0]const u8 { |
| 2770 | | return switch (target.os.tag) { |
| 2771 | | .linux => switch (target.cpu.arch) { |
| 2772 | | .arm, .armeb, .thumb, .thumbeb => "arm", |
| 2773 | | .aarch64, .aarch64_be, .aarch64_32 => "aarch64", |
| 2774 | | .mips, .mipsel, .mips64, .mips64el => "mips", |
| 2775 | | .powerpc, .powerpcle, .powerpc64, .powerpc64le => "powerpc", |
| 2776 | | .riscv32, .riscv64 => "riscv", |
| 2777 | | .sparc, .sparcel, .sparc64 => "sparc", |
| 2778 | | .x86, .x86_64 => "x86", |
| 2779 | | else => @tagName(target.cpu.arch), |
| 2780 | | }, |
| 2781 | | else => @tagName(target.cpu.arch), |
| 2782 | | }; |
| 2815 | return target.os.tag.archName(target.cpu.arch); |
| 2783 | 2816 | } |
| 2784 | 2817 | |
| 2785 | 2818 | const Target = @This(); |