| author | |
| committer | |
| log | ab89af3d397291f0126ad17d3787a51284457884 |
| tree | 4f418bfe9a67189e4b67c3365a1e746d5bf0bde5 |
| parent | aaf54ce6a7e5c69c92fe30e9ca0e8ffb7765f824 |
| parent | 3c1ccbdf3990b6d802cdc8a0db7c11eaac0960e8 |
| signature |
More support for OS/libc version ranges in `std.Target` and improvements to LLVM target triple construction7 files changed, 328 insertions(+), 139 deletions(-)
lib/std/Build/Cache.zig+1| ... | ... | @@ -221,6 +221,7 @@ pub const HashHelper = struct { |
| 221 | 221 | hh.add(linux.range.min); |
| 222 | 222 | hh.add(linux.range.max); |
| 223 | 223 | hh.add(linux.glibc); |
| 224 | hh.add(linux.android); | |
| 224 | 225 | }, |
| 225 | 226 | .windows => |windows| { |
| 226 | 227 | hh.add(windows.min); |
lib/std/Target.zig+205-112| ... | ... | @@ -160,49 +160,62 @@ pub const Os = struct { |
| 160 | 160 | pub inline fn versionRangeTag(tag: Tag) @typeInfo(TaggedVersionRange).@"union".tag_type.? { |
| 161 | 161 | return switch (tag) { |
| 162 | 162 | .freestanding, |
| 163 | .fuchsia, | |
| 164 | .ps3, | |
| 165 | .zos, | |
| 163 | .other, | |
| 164 | ||
| 165 | .elfiamcu, | |
| 166 | ||
| 166 | 167 | .haiku, |
| 167 | .rtems, | |
| 168 | .aix, | |
| 169 | .cuda, | |
| 170 | .nvcl, | |
| 171 | .amdhsa, | |
| 168 | .plan9, | |
| 169 | .serenity, | |
| 170 | ||
| 171 | // This should use semver once we determine the version history. | |
| 172 | .bridgeos, | |
| 173 | ||
| 174 | .illumos, | |
| 175 | ||
| 176 | .ps3, | |
| 172 | 177 | .ps4, |
| 173 | 178 | .ps5, |
| 174 | .elfiamcu, | |
| 179 | ||
| 180 | .emscripten, | |
| 181 | ||
| 175 | 182 | .mesa3d, |
| 183 | => .none, | |
| 184 | ||
| 176 | 185 | .contiki, |
| 177 | .amdpal, | |
| 186 | .fuchsia, | |
| 178 | 187 | .hermit, |
| 188 | ||
| 189 | .aix, | |
| 179 | 190 | .hurd, |
| 180 | .emscripten, | |
| 181 | .uefi, | |
| 182 | .opencl, // TODO: OpenCL versions | |
| 183 | .opengl, // TODO: GLSL versions | |
| 184 | .vulkan, | |
| 185 | .plan9, | |
| 186 | .illumos, | |
| 187 | .serenity, | |
| 188 | .other, | |
| 189 | => .none, | |
| 191 | .rtems, | |
| 192 | .zos, | |
| 190 | 193 | |
| 191 | // This should use semver once we determine the version history. | |
| 192 | .bridgeos => .none, | |
| 194 | .dragonfly, | |
| 195 | .freebsd, | |
| 196 | .netbsd, | |
| 197 | .openbsd, | |
| 193 | 198 | |
| 194 | 199 | .driverkit, |
| 195 | .freebsd, | |
| 196 | 200 | .macos, |
| 197 | 201 | .ios, |
| 198 | 202 | .tvos, |
| 199 | .watchos, | |
| 200 | 203 | .visionos, |
| 201 | .netbsd, | |
| 202 | .openbsd, | |
| 203 | .dragonfly, | |
| 204 | .watchos, | |
| 205 | ||
| 204 | 206 | .solaris, |
| 207 | ||
| 208 | .uefi, | |
| 209 | ||
| 205 | 210 | .wasi, |
| 211 | ||
| 212 | .amdhsa, | |
| 213 | .amdpal, | |
| 214 | .cuda, | |
| 215 | .nvcl, | |
| 216 | .opencl, | |
| 217 | .opengl, | |
| 218 | .vulkan, | |
| 206 | 219 | => .semver, |
| 207 | 220 | |
| 208 | 221 | .linux => .linux, |
| ... | ... | @@ -257,10 +270,11 @@ pub const Os = struct { |
| 257 | 270 | win11_zn = 0x0A00000E, //aka win11_21h2 |
| 258 | 271 | win11_ga = 0x0A00000F, //aka win11_22h2 |
| 259 | 272 | win11_ge = 0x0A000010, //aka win11_23h2 |
| 273 | win11_dt = 0x0A000011, //aka win11_24h2 | |
| 260 | 274 | _, |
| 261 | 275 | |
| 262 | 276 | /// Latest Windows version that the Zig Standard Library is aware of |
| 263 | pub const latest = WindowsVersion.win11_ge; | |
| 277 | pub const latest = WindowsVersion.win11_dt; | |
| 264 | 278 | |
| 265 | 279 | /// Compared against build numbers reported by the runtime to distinguish win10 versions, |
| 266 | 280 | /// where 0x0A000000 + index corresponds to the WindowsVersion u32 value. |
| ... | ... | @@ -282,6 +296,7 @@ pub const Os = struct { |
| 282 | 296 | 22000, //win11_zn aka win11_21h2 |
| 283 | 297 | 22621, //win11_ga aka win11_22h2 |
| 284 | 298 | 22631, //win11_ge aka win11_23h2 |
| 299 | 26100, //win11_dt aka win11_24h2 | |
| 285 | 300 | }; |
| 286 | 301 | |
| 287 | 302 | /// Returns whether the first version `ver` is newer (greater) than or equal to the second version `ver`. |
| ... | ... | @@ -344,6 +359,8 @@ pub const Os = struct { |
| 344 | 359 | pub const LinuxVersionRange = struct { |
| 345 | 360 | range: std.SemanticVersion.Range, |
| 346 | 361 | glibc: std.SemanticVersion, |
| 362 | /// Android API level. | |
| 363 | android: u32 = 14, // This default value is to be deleted after zig1.wasm is updated. | |
| 347 | 364 | |
| 348 | 365 | pub inline fn includesVersion(range: LinuxVersionRange, ver: std.SemanticVersion) bool { |
| 349 | 366 | return range.range.includesVersion(ver); |
| ... | ... | @@ -391,84 +408,106 @@ pub const Os = struct { |
| 391 | 408 | pub fn default(tag: Tag, arch: Cpu.Arch) VersionRange { |
| 392 | 409 | return switch (tag) { |
| 393 | 410 | .freestanding, |
| 394 | .fuchsia, | |
| 395 | .ps3, | |
| 396 | .zos, | |
| 397 | .haiku, | |
| 398 | .rtems, | |
| 399 | .aix, | |
| 400 | .cuda, | |
| 401 | .nvcl, | |
| 402 | .amdhsa, | |
| 403 | .ps4, | |
| 404 | .ps5, | |
| 411 | .other, | |
| 412 | ||
| 405 | 413 | .elfiamcu, |
| 406 | .mesa3d, | |
| 407 | .contiki, | |
| 408 | .amdpal, | |
| 409 | .hermit, | |
| 410 | .hurd, | |
| 411 | .emscripten, | |
| 412 | .uefi, | |
| 413 | .opencl, // TODO: OpenCL versions | |
| 414 | .opengl, // TODO: GLSL versions | |
| 415 | .vulkan, | |
| 414 | ||
| 415 | .haiku, | |
| 416 | 416 | .plan9, |
| 417 | .illumos, | |
| 418 | 417 | .serenity, |
| 418 | ||
| 419 | // This should use semver once we determine the version history. | |
| 419 | 420 | .bridgeos, |
| 420 | .other, | |
| 421 | ||
| 422 | .illumos, | |
| 423 | ||
| 424 | .ps3, | |
| 425 | .ps4, | |
| 426 | .ps5, | |
| 427 | ||
| 428 | .emscripten, | |
| 429 | ||
| 430 | .mesa3d, | |
| 421 | 431 | => .{ .none = {} }, |
| 422 | 432 | |
| 423 | .freebsd => .{ | |
| 424 | .semver = std.SemanticVersion.Range{ | |
| 425 | .min = .{ .major = 12, .minor = 0, .patch = 0 }, | |
| 426 | .max = .{ .major = 14, .minor = 0, .patch = 0 }, | |
| 433 | .contiki => .{ | |
| 434 | .semver = .{ | |
| 435 | .min = .{ .major = 4, .minor = 0, .patch = 0 }, | |
| 436 | .max = .{ .major = 4, .minor = 9, .patch = 0 }, | |
| 427 | 437 | }, |
| 428 | 438 | }, |
| 429 | .driverkit => .{ | |
| 439 | .fuchsia => .{ | |
| 430 | 440 | .semver = .{ |
| 431 | .min = .{ .major = 19, .minor = 0, .patch = 0 }, | |
| 432 | .max = .{ .major = 24, .minor = 0, .patch = 0 }, | |
| 441 | .min = .{ .major = 1, .minor = 1, .patch = 0 }, | |
| 442 | .max = .{ .major = 20, .minor = 1, .patch = 0 }, | |
| 433 | 443 | }, |
| 434 | 444 | }, |
| 435 | .macos => switch (arch) { | |
| 436 | .aarch64 => VersionRange{ | |
| 437 | .semver = .{ | |
| 438 | .min = .{ .major = 11, .minor = 7, .patch = 1 }, | |
| 439 | .max = .{ .major = 14, .minor = 6, .patch = 1 }, | |
| 440 | }, | |
| 445 | .hermit => .{ | |
| 446 | .semver = .{ | |
| 447 | .min = .{ .major = 0, .minor = 4, .patch = 0 }, | |
| 448 | .max = .{ .major = 0, .minor = 8, .patch = 0 }, | |
| 449 | }, | |
| 450 | }, | |
| 451 | ||
| 452 | .aix => .{ | |
| 453 | .semver = .{ | |
| 454 | .min = .{ .major = 7, .minor = 2, .patch = 5 }, | |
| 455 | .max = .{ .major = 7, .minor = 3, .patch = 2 }, | |
| 441 | 456 | }, |
| 442 | .x86_64 => VersionRange{ | |
| 443 | .semver = .{ | |
| 444 | .min = .{ .major = 11, .minor = 7, .patch = 1 }, | |
| 445 | .max = .{ .major = 14, .minor = 6, .patch = 1 }, | |
| 457 | }, | |
| 458 | .hurd => .{ | |
| 459 | .semver = .{ | |
| 460 | .min = .{ .major = 0, .minor = 9, .patch = 0 }, | |
| 461 | .max = .{ .major = 0, .minor = 9, .patch = 0 }, | |
| 462 | }, | |
| 463 | }, | |
| 464 | .linux => .{ | |
| 465 | .linux = .{ | |
| 466 | .range = .{ | |
| 467 | .min = .{ .major = 4, .minor = 19, .patch = 0 }, | |
| 468 | .max = .{ .major = 6, .minor = 11, .patch = 5 }, | |
| 446 | 469 | }, |
| 470 | .glibc = blk: { | |
| 471 | const default_min: std.SemanticVersion = .{ .major = 2, .minor = 28, .patch = 0 }; | |
| 472 | ||
| 473 | for (std.zig.target.available_libcs) |libc| { | |
| 474 | // We don't know the ABI here. We can get away with not checking it | |
| 475 | // for now, but that may not always remain true. | |
| 476 | if (libc.os != tag or libc.arch != arch) continue; | |
| 477 | ||
| 478 | if (libc.glibc_min) |min| { | |
| 479 | if (min.order(default_min) == .gt) break :blk min; | |
| 480 | } | |
| 481 | } | |
| 482 | ||
| 483 | break :blk default_min; | |
| 484 | }, | |
| 485 | .android = 14, | |
| 447 | 486 | }, |
| 448 | else => unreachable, | |
| 449 | 487 | }, |
| 450 | .ios => .{ | |
| 488 | .rtems => .{ | |
| 451 | 489 | .semver = .{ |
| 452 | .min = .{ .major = 12, .minor = 0, .patch = 0 }, | |
| 453 | .max = .{ .major = 17, .minor = 6, .patch = 1 }, | |
| 490 | .min = .{ .major = 5, .minor = 1, .patch = 0 }, | |
| 491 | .max = .{ .major = 5, .minor = 3, .patch = 0 }, | |
| 454 | 492 | }, |
| 455 | 493 | }, |
| 456 | .watchos => .{ | |
| 494 | .zos => .{ | |
| 457 | 495 | .semver = .{ |
| 458 | .min = .{ .major = 6, .minor = 0, .patch = 0 }, | |
| 459 | .max = .{ .major = 10, .minor = 6, .patch = 0 }, | |
| 496 | .min = .{ .major = 2, .minor = 5, .patch = 0 }, | |
| 497 | .max = .{ .major = 3, .minor = 1, .patch = 0 }, | |
| 460 | 498 | }, |
| 461 | 499 | }, |
| 462 | .tvos => .{ | |
| 500 | ||
| 501 | .dragonfly => .{ | |
| 463 | 502 | .semver = .{ |
| 464 | .min = .{ .major = 13, .minor = 0, .patch = 0 }, | |
| 465 | .max = .{ .major = 17, .minor = 6, .patch = 0 }, | |
| 503 | .min = .{ .major = 5, .minor = 8, .patch = 0 }, | |
| 504 | .max = .{ .major = 6, .minor = 4, .patch = 0 }, | |
| 466 | 505 | }, |
| 467 | 506 | }, |
| 468 | .visionos => .{ | |
| 507 | .freebsd => .{ | |
| 469 | 508 | .semver = .{ |
| 470 | .min = .{ .major = 1, .minor = 0, .patch = 0 }, | |
| 471 | .max = .{ .major = 1, .minor = 3, .patch = 0 }, | |
| 509 | .min = .{ .major = 12, .minor = 0, .patch = 0 }, | |
| 510 | .max = .{ .major = 14, .minor = 1, .patch = 0 }, | |
| 472 | 511 | }, |
| 473 | 512 | }, |
| 474 | 513 | .netbsd => .{ |
| ... | ... | @@ -480,49 +519,51 @@ pub const Os = struct { |
| 480 | 519 | .openbsd => .{ |
| 481 | 520 | .semver = .{ |
| 482 | 521 | .min = .{ .major = 7, .minor = 3, .patch = 0 }, |
| 483 | .max = .{ .major = 7, .minor = 5, .patch = 0 }, | |
| 522 | .max = .{ .major = 7, .minor = 6, .patch = 0 }, | |
| 484 | 523 | }, |
| 485 | 524 | }, |
| 486 | .dragonfly => .{ | |
| 525 | ||
| 526 | .driverkit => .{ | |
| 487 | 527 | .semver = .{ |
| 488 | .min = .{ .major = 5, .minor = 8, .patch = 0 }, | |
| 489 | .max = .{ .major = 6, .minor = 4, .patch = 0 }, | |
| 528 | .min = .{ .major = 19, .minor = 0, .patch = 0 }, | |
| 529 | .max = .{ .major = 24, .minor = 2, .patch = 0 }, | |
| 490 | 530 | }, |
| 491 | 531 | }, |
| 492 | .solaris => .{ | |
| 532 | .macos => .{ | |
| 493 | 533 | .semver = .{ |
| 494 | .min = .{ .major = 11, .minor = 0, .patch = 0 }, | |
| 495 | .max = .{ .major = 11, .minor = 4, .patch = 0 }, | |
| 534 | .min = .{ .major = 11, .minor = 7, .patch = 1 }, | |
| 535 | .max = .{ .major = 15, .minor = 2, .patch = 0 }, | |
| 496 | 536 | }, |
| 497 | 537 | }, |
| 498 | .wasi => .{ | |
| 538 | .ios => .{ | |
| 499 | 539 | .semver = .{ |
| 500 | .min = .{ .major = 0, .minor = 1, .patch = 0 }, | |
| 501 | .max = .{ .major = 0, .minor = 1, .patch = 0 }, | |
| 540 | .min = .{ .major = 12, .minor = 0, .patch = 0 }, | |
| 541 | .max = .{ .major = 18, .minor = 1, .patch = 0 }, | |
| 542 | }, | |
| 543 | }, | |
| 544 | .tvos => .{ | |
| 545 | .semver = .{ | |
| 546 | .min = .{ .major = 13, .minor = 0, .patch = 0 }, | |
| 547 | .max = .{ .major = 18, .minor = 1, .patch = 0 }, | |
| 548 | }, | |
| 549 | }, | |
| 550 | .visionos => .{ | |
| 551 | .semver = .{ | |
| 552 | .min = .{ .major = 1, .minor = 0, .patch = 0 }, | |
| 553 | .max = .{ .major = 2, .minor = 1, .patch = 0 }, | |
| 554 | }, | |
| 555 | }, | |
| 556 | .watchos => .{ | |
| 557 | .semver = .{ | |
| 558 | .min = .{ .major = 6, .minor = 0, .patch = 0 }, | |
| 559 | .max = .{ .major = 11, .minor = 1, .patch = 0 }, | |
| 502 | 560 | }, |
| 503 | 561 | }, |
| 504 | 562 | |
| 505 | .linux => .{ | |
| 506 | .linux = .{ | |
| 507 | .range = .{ | |
| 508 | .min = .{ .major = 4, .minor = 19, .patch = 0 }, | |
| 509 | .max = .{ .major = 6, .minor = 10, .patch = 3 }, | |
| 510 | }, | |
| 511 | .glibc = blk: { | |
| 512 | const default_min: std.SemanticVersion = .{ .major = 2, .minor = 28, .patch = 0 }; | |
| 513 | ||
| 514 | for (std.zig.target.available_libcs) |libc| { | |
| 515 | // We don't know the ABI here. We can get away with not checking it | |
| 516 | // for now, but that may not always remain true. | |
| 517 | if (libc.os != tag or libc.arch != arch) continue; | |
| 518 | ||
| 519 | if (libc.glibc_min) |min| { | |
| 520 | if (min.order(default_min) == .gt) break :blk min; | |
| 521 | } | |
| 522 | } | |
| 523 | ||
| 524 | break :blk default_min; | |
| 525 | }, | |
| 563 | .solaris => .{ | |
| 564 | .semver = .{ | |
| 565 | .min = .{ .major = 11, .minor = 0, .patch = 0 }, | |
| 566 | .max = .{ .major = 11, .minor = 4, .patch = 0 }, | |
| 526 | 567 | }, |
| 527 | 568 | }, |
| 528 | 569 | |
| ... | ... | @@ -532,6 +573,58 @@ pub const Os = struct { |
| 532 | 573 | .max = WindowsVersion.latest, |
| 533 | 574 | }, |
| 534 | 575 | }, |
| 576 | .uefi => .{ | |
| 577 | .semver = .{ | |
| 578 | .min = .{ .major = 2, .minor = 0, .patch = 0 }, | |
| 579 | .max = .{ .major = 2, .minor = 9, .patch = 0 }, | |
| 580 | }, | |
| 581 | }, | |
| 582 | ||
| 583 | .wasi => .{ | |
| 584 | .semver = .{ | |
| 585 | .min = .{ .major = 0, .minor = 1, .patch = 0 }, | |
| 586 | .max = .{ .major = 0, .minor = 2, .patch = 2 }, | |
| 587 | }, | |
| 588 | }, | |
| 589 | ||
| 590 | .amdhsa => .{ | |
| 591 | .semver = .{ | |
| 592 | .min = .{ .major = 5, .minor = 0, .patch = 2 }, | |
| 593 | .max = .{ .major = 6, .minor = 2, .patch = 2 }, | |
| 594 | }, | |
| 595 | }, | |
| 596 | .amdpal => .{ | |
| 597 | .semver = .{ | |
| 598 | .min = .{ .major = 1, .minor = 1, .patch = 0 }, | |
| 599 | .max = .{ .major = 3, .minor = 5, .patch = 0 }, | |
| 600 | }, | |
| 601 | }, | |
| 602 | .cuda => .{ | |
| 603 | .semver = .{ | |
| 604 | .min = .{ .major = 11, .minor = 0, .patch = 1 }, | |
| 605 | .max = .{ .major = 12, .minor = 6, .patch = 1 }, | |
| 606 | }, | |
| 607 | }, | |
| 608 | .nvcl, | |
| 609 | .opencl, | |
| 610 | => .{ | |
| 611 | .semver = .{ | |
| 612 | .min = .{ .major = 2, .minor = 2, .patch = 0 }, | |
| 613 | .max = .{ .major = 3, .minor = 0, .patch = 0 }, | |
| 614 | }, | |
| 615 | }, | |
| 616 | .opengl => .{ | |
| 617 | .semver = .{ | |
| 618 | .min = .{ .major = 4, .minor = 5, .patch = 0 }, | |
| 619 | .max = .{ .major = 4, .minor = 6, .patch = 0 }, | |
| 620 | }, | |
| 621 | }, | |
| 622 | .vulkan => .{ | |
| 623 | .semver = .{ | |
| 624 | .min = .{ .major = 1, .minor = 2, .patch = 0 }, | |
| 625 | .max = .{ .major = 1, .minor = 3, .patch = 0 }, | |
| 626 | }, | |
| 627 | }, | |
| 535 | 628 | }; |
| 536 | 629 | } |
| 537 | 630 | }; |
lib/std/Target/Query.zig+52-7| ... | ... | @@ -25,10 +25,14 @@ os_version_min: ?OsVersion = null, |
| 25 | 25 | /// When `os_tag` is native, `null` means equal to the native OS version. |
| 26 | 26 | os_version_max: ?OsVersion = null, |
| 27 | 27 | |
| 28 | /// `null` means default when cross compiling, or native when os_tag is native. | |
| 28 | /// `null` means default when cross compiling, or native when `os_tag` is native. | |
| 29 | 29 | /// If `isGnuLibC()` is `false`, this must be `null` and is ignored. |
| 30 | 30 | glibc_version: ?SemanticVersion = null, |
| 31 | 31 | |
| 32 | /// `null` means default when cross compiling, or native when `os_tag` is native. | |
| 33 | /// If `isAndroid()` is `false`, this must be `null` and is ignored. | |
| 34 | android_api_level: ?u32 = null, | |
| 35 | ||
| 32 | 36 | /// `null` means the native C ABI, if `os_tag` is native, otherwise it means the default C ABI. |
| 33 | 37 | abi: ?Target.Abi = null, |
| 34 | 38 | |
| ... | ... | @@ -98,10 +102,8 @@ pub fn fromTarget(target: Target) Query { |
| 98 | 102 | .os_version_min = undefined, |
| 99 | 103 | .os_version_max = undefined, |
| 100 | 104 | .abi = target.abi, |
| 101 | .glibc_version = if (target.isGnuLibC()) | |
| 102 | target.os.version_range.linux.glibc | |
| 103 | else | |
| 104 | null, | |
| 105 | .glibc_version = if (target.isGnuLibC()) target.os.version_range.linux.glibc else null, | |
| 106 | .android_api_level = if (target.abi.isAndroid()) target.os.version_range.linux.android else null, | |
| 105 | 107 | }; |
| 106 | 108 | result.updateOsVersionRange(target.os); |
| 107 | 109 | |
| ... | ... | @@ -147,7 +149,7 @@ pub const ParseOptions = struct { |
| 147 | 149 | /// The fields are, respectively: |
| 148 | 150 | /// * CPU Architecture |
| 149 | 151 | /// * Operating System (and optional version range) |
| 150 | /// * C ABI (optional, with optional glibc version) | |
| 152 | /// * C ABI (optional, with optional glibc version or Android API level) | |
| 151 | 153 | /// The string "native" can be used for CPU architecture as well as Operating System. |
| 152 | 154 | /// If the CPU Architecture is specified as "native", then the Operating System and C ABI may be omitted. |
| 153 | 155 | arch_os_abi: []const u8 = "native", |
| ... | ... | @@ -234,6 +236,11 @@ pub fn parse(args: ParseOptions) !Query { |
| 234 | 236 | error.Overflow => return error.InvalidAbiVersion, |
| 235 | 237 | error.InvalidVersion => return error.InvalidAbiVersion, |
| 236 | 238 | }; |
| 239 | } else if (abi.isAndroid()) { | |
| 240 | result.android_api_level = std.fmt.parseUnsigned(u32, abi_ver_text, 10) catch |err| switch (err) { | |
| 241 | error.InvalidCharacter => return error.InvalidVersion, | |
| 242 | error.Overflow => return error.Overflow, | |
| 243 | }; | |
| 237 | 244 | } else { |
| 238 | 245 | return error.InvalidAbiVersion; |
| 239 | 246 | } |
| ... | ... | @@ -355,7 +362,7 @@ pub fn isNativeCpu(self: Query) bool { |
| 355 | 362 | |
| 356 | 363 | pub fn isNativeOs(self: Query) bool { |
| 357 | 364 | return self.os_tag == null and self.os_version_min == null and self.os_version_max == null and |
| 358 | self.dynamic_linker.get() == null and self.glibc_version == null; | |
| 365 | self.dynamic_linker.get() == null and self.glibc_version == null and self.android_api_level == null; | |
| 359 | 366 | } |
| 360 | 367 | |
| 361 | 368 | pub fn isNativeAbi(self: Query) bool { |
| ... | ... | @@ -439,6 +446,13 @@ pub fn zigTriple(self: Query, allocator: Allocator) Allocator.Error![]u8 { |
| 439 | 446 | result.appendSliceAssumeCapacity(name); |
| 440 | 447 | result.appendAssumeCapacity('.'); |
| 441 | 448 | try formatVersion(v, result.writer()); |
| 449 | } else if (self.android_api_level) |lvl| { | |
| 450 | const name = if (self.abi) |abi| @tagName(abi) else "android"; | |
| 451 | try result.ensureUnusedCapacity(name.len + 2); | |
| 452 | result.appendAssumeCapacity('-'); | |
| 453 | result.appendSliceAssumeCapacity(name); | |
| 454 | result.appendAssumeCapacity('.'); | |
| 455 | try result.writer().print("{d}", .{lvl}); | |
| 442 | 456 | } else if (self.abi) |abi| { |
| 443 | 457 | const name = @tagName(abi); |
| 444 | 458 | try result.ensureUnusedCapacity(name.len + 1); |
| ... | ... | @@ -561,6 +575,7 @@ pub fn eql(a: Query, b: Query) bool { |
| 561 | 575 | if (!OsVersion.eqlOpt(a.os_version_min, b.os_version_min)) return false; |
| 562 | 576 | if (!OsVersion.eqlOpt(a.os_version_max, b.os_version_max)) return false; |
| 563 | 577 | if (!versionEqualOpt(a.glibc_version, b.glibc_version)) return false; |
| 578 | if (a.android_api_level != b.android_api_level) return false; | |
| 564 | 579 | if (a.abi != b.abi) return false; |
| 565 | 580 | if (!a.dynamic_linker.eql(b.dynamic_linker)) return false; |
| 566 | 581 | if (a.ofmt != b.ofmt) return false; |
| ... | ... | @@ -592,6 +607,15 @@ test parse { |
| 592 | 607 | |
| 593 | 608 | try std.testing.expectEqualSlices(u8, "native-native-gnu.2.1.1", text); |
| 594 | 609 | } |
| 610 | if (builtin.target.abi.isAndroid()) { | |
| 611 | var query = try Query.parse(.{}); | |
| 612 | query.android_api_level = 30; | |
| 613 | ||
| 614 | const text = try query.zigTriple(std.testing.allocator); | |
| 615 | defer std.testing.allocator.free(text); | |
| 616 | ||
| 617 | try std.testing.expectEqualSlices(u8, "native-native-android.30", text); | |
| 618 | } | |
| 595 | 619 | { |
| 596 | 620 | const query = try Query.parse(.{ |
| 597 | 621 | .arch_os_abi = "aarch64-linux", |
| ... | ... | @@ -677,4 +701,25 @@ test parse { |
| 677 | 701 | defer std.testing.allocator.free(text); |
| 678 | 702 | try std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-gnu.2.27", text); |
| 679 | 703 | } |
| 704 | { | |
| 705 | const query = try Query.parse(.{ | |
| 706 | .arch_os_abi = "aarch64-linux.3.10...4.4.1-android.30", | |
| 707 | }); | |
| 708 | const target = try std.zig.system.resolveTargetQuery(query); | |
| 709 | ||
| 710 | try std.testing.expect(target.cpu.arch == .aarch64); | |
| 711 | try std.testing.expect(target.os.tag == .linux); | |
| 712 | try std.testing.expect(target.os.version_range.linux.range.min.major == 3); | |
| 713 | try std.testing.expect(target.os.version_range.linux.range.min.minor == 10); | |
| 714 | try std.testing.expect(target.os.version_range.linux.range.min.patch == 0); | |
| 715 | try std.testing.expect(target.os.version_range.linux.range.max.major == 4); | |
| 716 | try std.testing.expect(target.os.version_range.linux.range.max.minor == 4); | |
| 717 | try std.testing.expect(target.os.version_range.linux.range.max.patch == 1); | |
| 718 | try std.testing.expect(target.os.version_range.linux.android == 30); | |
| 719 | try std.testing.expect(target.abi == .android); | |
| 720 | ||
| 721 | const text = try query.zigTriple(std.testing.allocator); | |
| 722 | defer std.testing.allocator.free(text); | |
| 723 | try std.testing.expectEqualSlices(u8, "aarch64-linux.3.10...4.4.1-android.30", text); | |
| 724 | } | |
| 680 | 725 | } |
lib/std/c.zig+11-7| ... | ... | @@ -44,22 +44,26 @@ comptime { |
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | /// If not linking libc, returns false. | |
| 48 | /// If linking musl libc, returns true. | |
| 49 | /// If linking gnu libc (glibc), returns true if the target version is greater | |
| 50 | /// than or equal to `glibc_version`. | |
| 51 | /// If linking a libc other than these, returns `false`. | |
| 52 | pub inline fn versionCheck(comptime glibc_version: std.SemanticVersion) bool { | |
| 47 | /// * If not linking libc, returns `false`. | |
| 48 | /// * If linking musl libc, returns `true`. | |
| 49 | /// * If linking GNU libc (glibc), returns `true` if the target version is greater than or equal to | |
| 50 | /// `version`. | |
| 51 | /// * If linking Android libc (bionic), returns `true` if the target API level is greater than or | |
| 52 | /// equal to `version.major`, ignoring other components. | |
| 53 | /// * If linking a libc other than these, returns `false`. | |
| 54 | pub inline fn versionCheck(comptime version: std.SemanticVersion) bool { | |
| 53 | 55 | return comptime blk: { |
| 54 | 56 | if (!builtin.link_libc) break :blk false; |
| 55 | 57 | if (native_abi.isMusl()) break :blk true; |
| 56 | 58 | if (builtin.target.isGnuLibC()) { |
| 57 | 59 | const ver = builtin.os.version_range.linux.glibc; |
| 58 | const order = ver.order(glibc_version); | |
| 60 | const order = ver.order(version); | |
| 59 | 61 | break :blk switch (order) { |
| 60 | 62 | .gt, .eq => true, |
| 61 | 63 | .lt => false, |
| 62 | 64 | }; |
| 65 | } else if (builtin.abi.isAndroid()) { | |
| 66 | break :blk builtin.os.version_range.linux.android >= version.major; | |
| 63 | 67 | } else { |
| 64 | 68 | break :blk false; |
| 65 | 69 | } |
lib/std/zig/system.zig+4| ... | ... | @@ -331,6 +331,10 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target { |
| 331 | 331 | os.version_range.linux.glibc = glibc; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | if (query.android_api_level) |android| { | |
| 335 | os.version_range.linux.android = android; | |
| 336 | } | |
| 337 | ||
| 334 | 338 | // Until https://github.com/ziglang/zig/issues/4592 is implemented (support detecting the |
| 335 | 339 | // native CPU architecture as being different than the current target), we use this: |
| 336 | 340 | const cpu_arch = query.cpu_arch orelse builtin.cpu.arch; |
src/Builtin.zig+3| ... | ... | @@ -124,6 +124,7 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void { |
| 124 | 124 | \\ .minor = {}, |
| 125 | 125 | \\ .patch = {}, |
| 126 | 126 | \\ }}, |
| 127 | \\ .android = {}, | |
| 127 | 128 | \\ }}}}, |
| 128 | 129 | \\ |
| 129 | 130 | , .{ |
| ... | ... | @@ -138,6 +139,8 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void { |
| 138 | 139 | linux.glibc.major, |
| 139 | 140 | linux.glibc.minor, |
| 140 | 141 | linux.glibc.patch, |
| 142 | ||
| 143 | linux.android, | |
| 141 | 144 | }), |
| 142 | 145 | .windows => |windows| try buffer.writer().print( |
| 143 | 146 | \\ .windows = .{{ |
src/codegen/llvm.zig+52-13| ... | ... | @@ -164,14 +164,34 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 { |
| 164 | 164 | }; |
| 165 | 165 | |
| 166 | 166 | if (llvm_sub_arch) |sub| try llvm_triple.appendSlice(sub); |
| 167 | try llvm_triple.append('-'); | |
| 167 | 168 | |
| 168 | // Unlike CPU backends, GPU backends actually care about the vendor tag. | |
| 169 | try llvm_triple.appendSlice(switch (target.cpu.arch) { | |
| 170 | .amdgcn => if (target.os.tag == .mesa3d) "-mesa-" else "-amd-", | |
| 171 | .nvptx, .nvptx64 => "-nvidia-", | |
| 172 | .spirv64 => if (target.os.tag == .amdhsa) "-amd-" else "-unknown-", | |
| 173 | else => "-unknown-", | |
| 169 | try llvm_triple.appendSlice(switch (target.os.tag) { | |
| 170 | .aix, | |
| 171 | .zos, | |
| 172 | => "ibm", | |
| 173 | .bridgeos, | |
| 174 | .driverkit, | |
| 175 | .ios, | |
| 176 | .macos, | |
| 177 | .tvos, | |
| 178 | .visionos, | |
| 179 | .watchos, | |
| 180 | => "apple", | |
| 181 | .ps4, | |
| 182 | .ps5, | |
| 183 | => "scei", | |
| 184 | .amdhsa, | |
| 185 | .amdpal, | |
| 186 | => "amd", | |
| 187 | .cuda, | |
| 188 | .nvcl, | |
| 189 | => "nvidia", | |
| 190 | .mesa3d, | |
| 191 | => "mesa", | |
| 192 | else => "unknown", | |
| 174 | 193 | }); |
| 194 | try llvm_triple.append('-'); | |
| 175 | 195 | |
| 176 | 196 | const llvm_os = switch (target.os.tag) { |
| 177 | 197 | .freestanding => "unknown", |
| ... | ... | @@ -219,13 +239,20 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 { |
| 219 | 239 | }; |
| 220 | 240 | try llvm_triple.appendSlice(llvm_os); |
| 221 | 241 | |
| 222 | if (target.os.tag.isDarwin()) { | |
| 223 | const min_version = target.os.version_range.semver.min; | |
| 224 | try llvm_triple.writer().print("{d}.{d}.{d}", .{ | |
| 225 | min_version.major, | |
| 226 | min_version.minor, | |
| 227 | min_version.patch, | |
| 228 | }); | |
| 242 | switch (target.os.versionRange()) { | |
| 243 | .none, | |
| 244 | .windows, | |
| 245 | => {}, | |
| 246 | .semver => |ver| try llvm_triple.writer().print("{d}.{d}.{d}", .{ | |
| 247 | ver.min.major, | |
| 248 | ver.min.minor, | |
| 249 | ver.min.patch, | |
| 250 | }), | |
| 251 | .linux => |ver| try llvm_triple.writer().print("{d}.{d}.{d}", .{ | |
| 252 | ver.range.min.major, | |
| 253 | ver.range.min.minor, | |
| 254 | ver.range.min.patch, | |
| 255 | }), | |
| 229 | 256 | } |
| 230 | 257 | try llvm_triple.append('-'); |
| 231 | 258 | |
| ... | ... | @@ -259,6 +286,18 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 { |
| 259 | 286 | }; |
| 260 | 287 | try llvm_triple.appendSlice(llvm_abi); |
| 261 | 288 | |
| 289 | switch (target.os.versionRange()) { | |
| 290 | .none, | |
| 291 | .semver, | |
| 292 | .windows, | |
| 293 | => {}, | |
| 294 | .linux => |ver| if (target.abi.isGnu()) try llvm_triple.writer().print("{d}.{d}.{d}", .{ | |
| 295 | ver.glibc.major, | |
| 296 | ver.glibc.minor, | |
| 297 | ver.glibc.patch, | |
| 298 | }) else if (target.abi.isAndroid()) try llvm_triple.writer().print("{d}", .{ver.android}), | |
| 299 | } | |
| 300 | ||
| 262 | 301 | return llvm_triple.toOwnedSlice(); |
| 263 | 302 | } |
| 264 | 303 |