| author | |
| committer | |
| log | 142471fcc46070326526e3976f0150fe734df0b6 |
| tree | 67d4dec7968cf6d6765cd3bc66524721cf0554d2 |
| parent | 579f572cf203eda11da7e4e919fdfc12e15f03e2 |
Introduce the concept of "target query" and "resolved target". A target
query is what the user specifies, with some things left to default. A
resolved target has the default things discovered and populated.
In the future, std.zig.CrossTarget will be rename to std.Target.Query.
Introduces `std.Build.resolveTargetQuery` to get from one to the other.
The concept of `main_mod_path` is gone, no longer supported. You have to
put the root source file at the module root now.
* remove deprecated API
* update build.zig for the breaking API changes in this branch
* move std.Build.Step.Compile.BuildId to std.zig.BuildId
* add more options to std.Build.ExecutableOptions, std.Build.ObjectOptions,
std.Build.SharedLibraryOptions, std.Build.StaticLibraryOptions, and
std.Build.TestOptions.
* remove `std.Build.constructCMacro`. There is no use for this API.
* deprecate `std.Build.Step.Compile.defineCMacro`. Instead,
`std.Build.Module.addCMacro` is provided.
- remove `std.Build.Step.Compile.defineCMacroRaw`.
* deprecate `std.Build.Step.Compile.linkFrameworkNeeded`
- use `std.Build.Module.linkFramework`
* deprecate `std.Build.Step.Compile.linkFrameworkWeak`
- use `std.Build.Module.linkFramework`
* move more logic into `std.Build.Module`
* allow `target` and `optimize` to be `null` when creating a Module.
Along with other fields, those unspecified options will be inherited
from parent `Module` when inserted into an import table.
* the `target` field of `addExecutable` is now required. pass `b.host`
to get the host target.122 files changed, 1812 insertions(+), 1338 deletions(-)
build.zig+53-39| ... | @@ -39,10 +39,10 @@ pub fn build(b: *std.Build) !void { | ... | @@ -39,10 +39,10 @@ pub fn build(b: *std.Build) !void { |
| 39 | const docgen_exe = b.addExecutable(.{ | 39 | const docgen_exe = b.addExecutable(.{ |
| 40 | .name = "docgen", | 40 | .name = "docgen", |
| 41 | .root_source_file = .{ .path = "tools/docgen.zig" }, | 41 | .root_source_file = .{ .path = "tools/docgen.zig" }, |
| 42 | .target = .{}, | 42 | .target = b.host, |
| 43 | .optimize = .Debug, | 43 | .optimize = .Debug, |
| 44 | .single_threaded = single_threaded, | ||
| 44 | }); | 45 | }); |
| 45 | docgen_exe.single_threaded = single_threaded; | ||
| 46 | 46 | ||
| 47 | const docgen_cmd = b.addRunArtifact(docgen_exe); | 47 | const docgen_cmd = b.addRunArtifact(docgen_exe); |
| 48 | docgen_cmd.addArgs(&.{ "--zig", b.zig_exe }); | 48 | docgen_cmd.addArgs(&.{ "--zig", b.zig_exe }); |
| ... | @@ -89,11 +89,11 @@ pub fn build(b: *std.Build) !void { | ... | @@ -89,11 +89,11 @@ pub fn build(b: *std.Build) !void { |
| 89 | const check_case_exe = b.addExecutable(.{ | 89 | const check_case_exe = b.addExecutable(.{ |
| 90 | .name = "check-case", | 90 | .name = "check-case", |
| 91 | .root_source_file = .{ .path = "test/src/Cases.zig" }, | 91 | .root_source_file = .{ .path = "test/src/Cases.zig" }, |
| 92 | .target = b.host, | ||
| 92 | .optimize = optimize, | 93 | .optimize = optimize, |
| 93 | .main_mod_path = .{ .path = "." }, | 94 | .single_threaded = single_threaded, |
| 94 | }); | 95 | }); |
| 95 | check_case_exe.stack_size = stack_size; | 96 | check_case_exe.stack_size = stack_size; |
| 96 | check_case_exe.single_threaded = single_threaded; | ||
| 97 | 97 | ||
| 98 | const skip_debug = b.option(bool, "skip-debug", "Main test suite skips debug builds") orelse false; | 98 | const skip_debug = b.option(bool, "skip-debug", "Main test suite skips debug builds") orelse false; |
| 99 | const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse false; | 99 | const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse false; |
| ... | @@ -194,14 +194,18 @@ pub fn build(b: *std.Build) !void { | ... | @@ -194,14 +194,18 @@ pub fn build(b: *std.Build) !void { |
| 194 | break :blk 4; | 194 | break :blk 4; |
| 195 | }; | 195 | }; |
| 196 | 196 | ||
| 197 | const exe = addCompilerStep(b, optimize, target); | 197 | const exe = addCompilerStep(b, .{ |
| 198 | exe.strip = strip; | 198 | .optimize = optimize, |
| 199 | .target = target, | ||
| 200 | .strip = strip, | ||
| 201 | .sanitize_thread = sanitize_thread, | ||
| 202 | .single_threaded = single_threaded, | ||
| 203 | }); | ||
| 199 | exe.pie = pie; | 204 | exe.pie = pie; |
| 200 | exe.sanitize_thread = sanitize_thread; | ||
| 201 | exe.entitlements = entitlements; | 205 | exe.entitlements = entitlements; |
| 202 | 206 | ||
| 203 | exe.build_id = b.option( | 207 | exe.build_id = b.option( |
| 204 | std.Build.Step.Compile.BuildId, | 208 | std.zig.BuildId, |
| 205 | "build-id", | 209 | "build-id", |
| 206 | "Request creation of '.note.gnu.build-id' section", | 210 | "Request creation of '.note.gnu.build-id' section", |
| 207 | ); | 211 | ); |
| ... | @@ -217,9 +221,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -217,9 +221,7 @@ pub fn build(b: *std.Build) !void { |
| 217 | 221 | ||
| 218 | test_step.dependOn(&exe.step); | 222 | test_step.dependOn(&exe.step); |
| 219 | 223 | ||
| 220 | exe.single_threaded = single_threaded; | 224 | if (target.target.os.tag == .windows and target.target.abi == .gnu) { |
| 221 | |||
| 222 | if (target.isWindows() and target.getAbi() == .gnu) { | ||
| 223 | // LTO is currently broken on mingw, this can be removed when it's fixed. | 225 | // LTO is currently broken on mingw, this can be removed when it's fixed. |
| 224 | exe.want_lto = false; | 226 | exe.want_lto = false; |
| 225 | check_case_exe.want_lto = false; | 227 | check_case_exe.want_lto = false; |
| ... | @@ -230,7 +232,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -230,7 +232,7 @@ pub fn build(b: *std.Build) !void { |
| 230 | exe.use_lld = use_llvm; | 232 | exe.use_lld = use_llvm; |
| 231 | 233 | ||
| 232 | const exe_options = b.addOptions(); | 234 | const exe_options = b.addOptions(); |
| 233 | exe.addOptions("build_options", exe_options); | 235 | exe.root_module.addOptions("build_options", exe_options); |
| 234 | 236 | ||
| 235 | exe_options.addOption(u32, "mem_leak_frames", mem_leak_frames); | 237 | exe_options.addOption(u32, "mem_leak_frames", mem_leak_frames); |
| 236 | exe_options.addOption(bool, "skip_non_native", skip_non_native); | 238 | exe_options.addOption(bool, "skip_non_native", skip_non_native); |
| ... | @@ -345,7 +347,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -345,7 +347,7 @@ pub fn build(b: *std.Build) !void { |
| 345 | try addStaticLlvmOptionsToExe(exe); | 347 | try addStaticLlvmOptionsToExe(exe); |
| 346 | try addStaticLlvmOptionsToExe(check_case_exe); | 348 | try addStaticLlvmOptionsToExe(check_case_exe); |
| 347 | } | 349 | } |
| 348 | if (target.isWindows()) { | 350 | if (target.target.os.tag == .windows) { |
| 349 | inline for (.{ exe, check_case_exe }) |artifact| { | 351 | inline for (.{ exe, check_case_exe }) |artifact| { |
| 350 | artifact.linkSystemLibrary("version"); | 352 | artifact.linkSystemLibrary("version"); |
| 351 | artifact.linkSystemLibrary("uuid"); | 353 | artifact.linkSystemLibrary("uuid"); |
| ... | @@ -369,7 +371,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -369,7 +371,7 @@ pub fn build(b: *std.Build) !void { |
| 369 | ); | 371 | ); |
| 370 | 372 | ||
| 371 | // On mingw, we need to opt into windows 7+ to get some features required by tracy. | 373 | // On mingw, we need to opt into windows 7+ to get some features required by tracy. |
| 372 | const tracy_c_flags: []const []const u8 = if (target.isWindows() and target.getAbi() == .gnu) | 374 | const tracy_c_flags: []const []const u8 = if (target.target.os.tag == .windows and target.target.abi == .gnu) |
| 373 | &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" } | 375 | &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" } |
| 374 | else | 376 | else |
| 375 | &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }; | 377 | &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }; |
| ... | @@ -377,11 +379,11 @@ pub fn build(b: *std.Build) !void { | ... | @@ -377,11 +379,11 @@ pub fn build(b: *std.Build) !void { |
| 377 | exe.addIncludePath(.{ .cwd_relative = tracy_path }); | 379 | exe.addIncludePath(.{ .cwd_relative = tracy_path }); |
| 378 | exe.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags }); | 380 | exe.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags }); |
| 379 | if (!enable_llvm) { | 381 | if (!enable_llvm) { |
| 380 | exe.linkSystemLibraryName("c++"); | 382 | exe.root_module.linkSystemLibrary("c++", .{ .use_pkg_config = .no }); |
| 381 | } | 383 | } |
| 382 | exe.linkLibC(); | 384 | exe.linkLibC(); |
| 383 | 385 | ||
| 384 | if (target.isWindows()) { | 386 | if (target.target.os.tag == .windows) { |
| 385 | exe.linkSystemLibrary("dbghelp"); | 387 | exe.linkSystemLibrary("dbghelp"); |
| 386 | exe.linkSystemLibrary("ws2_32"); | 388 | exe.linkSystemLibrary("ws2_32"); |
| 387 | } | 389 | } |
| ... | @@ -390,7 +392,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -390,7 +392,7 @@ pub fn build(b: *std.Build) !void { |
| 390 | const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter"); | 392 | const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter"); |
| 391 | 393 | ||
| 392 | const test_cases_options = b.addOptions(); | 394 | const test_cases_options = b.addOptions(); |
| 393 | check_case_exe.addOptions("build_options", test_cases_options); | 395 | check_case_exe.root_module.addOptions("build_options", test_cases_options); |
| 394 | 396 | ||
| 395 | test_cases_options.addOption(bool, "enable_tracy", false); | 397 | test_cases_options.addOption(bool, "enable_tracy", false); |
| 396 | test_cases_options.addOption(bool, "enable_logging", enable_logging); | 398 | test_cases_options.addOption(bool, "enable_logging", enable_logging); |
| ... | @@ -540,16 +542,19 @@ pub fn build(b: *std.Build) !void { | ... | @@ -540,16 +542,19 @@ pub fn build(b: *std.Build) !void { |
| 540 | fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { | 542 | fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { |
| 541 | const semver = try std.SemanticVersion.parse(version); | 543 | const semver = try std.SemanticVersion.parse(version); |
| 542 | 544 | ||
| 543 | var target: std.zig.CrossTarget = .{ | 545 | var target_query: std.zig.CrossTarget = .{ |
| 544 | .cpu_arch = .wasm32, | 546 | .cpu_arch = .wasm32, |
| 545 | .os_tag = .wasi, | 547 | .os_tag = .wasi, |
| 546 | }; | 548 | }; |
| 547 | target.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.bulk_memory)); | 549 | target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.bulk_memory)); |
| 548 | 550 | ||
| 549 | const exe = addCompilerStep(b, .ReleaseSmall, target); | 551 | const exe = addCompilerStep(b, .{ |
| 552 | .optimize = .ReleaseSmall, | ||
| 553 | .target = b.resolveTargetQuery(target_query), | ||
| 554 | }); | ||
| 550 | 555 | ||
| 551 | const exe_options = b.addOptions(); | 556 | const exe_options = b.addOptions(); |
| 552 | exe.addOptions("build_options", exe_options); | 557 | exe.root_module.addOptions("build_options", exe_options); |
| 553 | 558 | ||
| 554 | exe_options.addOption(u32, "mem_leak_frames", 0); | 559 | exe_options.addOption(u32, "mem_leak_frames", 0); |
| 555 | exe_options.addOption(bool, "have_llvm", false); | 560 | exe_options.addOption(bool, "have_llvm", false); |
| ... | @@ -584,17 +589,24 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { | ... | @@ -584,17 +589,24 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { |
| 584 | update_zig1_step.dependOn(&copy_zig_h.step); | 589 | update_zig1_step.dependOn(&copy_zig_h.step); |
| 585 | } | 590 | } |
| 586 | 591 | ||
| 587 | fn addCompilerStep( | 592 | const AddCompilerStepOptions = struct { |
| 588 | b: *std.Build, | ||
| 589 | optimize: std.builtin.OptimizeMode, | 593 | optimize: std.builtin.OptimizeMode, |
| 590 | target: std.zig.CrossTarget, | 594 | target: std.Build.ResolvedTarget, |
| 591 | ) *std.Build.Step.Compile { | 595 | strip: ?bool = null, |
| 596 | sanitize_thread: ?bool = null, | ||
| 597 | single_threaded: ?bool = null, | ||
| 598 | }; | ||
| 599 | |||
| 600 | fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.Step.Compile { | ||
| 592 | const exe = b.addExecutable(.{ | 601 | const exe = b.addExecutable(.{ |
| 593 | .name = "zig", | 602 | .name = "zig", |
| 594 | .root_source_file = .{ .path = "src/main.zig" }, | 603 | .root_source_file = .{ .path = "src/main.zig" }, |
| 595 | .target = target, | 604 | .target = options.target, |
| 596 | .optimize = optimize, | 605 | .optimize = options.optimize, |
| 597 | .max_rss = 7_000_000_000, | 606 | .max_rss = 7_000_000_000, |
| 607 | .strip = options.strip, | ||
| 608 | .sanitize_thread = options.sanitize_thread, | ||
| 609 | .single_threaded = options.single_threaded, | ||
| 598 | }); | 610 | }); |
| 599 | exe.stack_size = stack_size; | 611 | exe.stack_size = stack_size; |
| 600 | 612 | ||
| ... | @@ -602,15 +614,15 @@ fn addCompilerStep( | ... | @@ -602,15 +614,15 @@ fn addCompilerStep( |
| 602 | aro_options.addOption([]const u8, "version_str", "aro-zig"); | 614 | aro_options.addOption([]const u8, "version_str", "aro-zig"); |
| 603 | const aro_options_module = aro_options.createModule(); | 615 | const aro_options_module = aro_options.createModule(); |
| 604 | const aro_backend = b.createModule(.{ | 616 | const aro_backend = b.createModule(.{ |
| 605 | .source_file = .{ .path = "deps/aro/backend.zig" }, | 617 | .root_source_file = .{ .path = "deps/aro/backend.zig" }, |
| 606 | .dependencies = &.{.{ | 618 | .imports = &.{.{ |
| 607 | .name = "build_options", | 619 | .name = "build_options", |
| 608 | .module = aro_options_module, | 620 | .module = aro_options_module, |
| 609 | }}, | 621 | }}, |
| 610 | }); | 622 | }); |
| 611 | const aro_module = b.createModule(.{ | 623 | const aro_module = b.createModule(.{ |
| 612 | .source_file = .{ .path = "deps/aro/aro.zig" }, | 624 | .root_source_file = .{ .path = "deps/aro/aro.zig" }, |
| 613 | .dependencies = &.{ | 625 | .imports = &.{ |
| 614 | .{ | 626 | .{ |
| 615 | .name = "build_options", | 627 | .name = "build_options", |
| 616 | .module = aro_options_module, | 628 | .module = aro_options_module, |
| ... | @@ -625,7 +637,7 @@ fn addCompilerStep( | ... | @@ -625,7 +637,7 @@ fn addCompilerStep( |
| 625 | }, | 637 | }, |
| 626 | }); | 638 | }); |
| 627 | 639 | ||
| 628 | exe.addModule("aro", aro_module); | 640 | exe.root_module.addImport("aro", aro_module); |
| 629 | return exe; | 641 | return exe; |
| 630 | } | 642 | } |
| 631 | 643 | ||
| ... | @@ -649,7 +661,7 @@ fn addCmakeCfgOptionsToExe( | ... | @@ -649,7 +661,7 @@ fn addCmakeCfgOptionsToExe( |
| 649 | exe: *std.Build.Step.Compile, | 661 | exe: *std.Build.Step.Compile, |
| 650 | use_zig_libcxx: bool, | 662 | use_zig_libcxx: bool, |
| 651 | ) !void { | 663 | ) !void { |
| 652 | if (exe.target.isDarwin()) { | 664 | if (exe.rootModuleTarget().isDarwin()) { |
| 653 | // useful for package maintainers | 665 | // useful for package maintainers |
| 654 | exe.headerpad_max_install_names = true; | 666 | exe.headerpad_max_install_names = true; |
| 655 | } | 667 | } |
| ... | @@ -677,8 +689,8 @@ fn addCmakeCfgOptionsToExe( | ... | @@ -677,8 +689,8 @@ fn addCmakeCfgOptionsToExe( |
| 677 | // against system-provided LLVM, Clang, LLD. | 689 | // against system-provided LLVM, Clang, LLD. |
| 678 | const need_cpp_includes = true; | 690 | const need_cpp_includes = true; |
| 679 | const static = cfg.llvm_linkage == .static; | 691 | const static = cfg.llvm_linkage == .static; |
| 680 | const lib_suffix = if (static) exe.target.staticLibSuffix()[1..] else exe.target.dynamicLibSuffix()[1..]; | 692 | const lib_suffix = if (static) exe.rootModuleTarget().staticLibSuffix()[1..] else exe.rootModuleTarget().dynamicLibSuffix()[1..]; |
| 681 | switch (exe.target.getOsTag()) { | 693 | switch (exe.rootModuleTarget().os.tag) { |
| 682 | .linux => { | 694 | .linux => { |
| 683 | // First we try to link against the detected libcxx name. If that doesn't work, we fall | 695 | // First we try to link against the detected libcxx name. If that doesn't work, we fall |
| 684 | // back to -lc++ and cross our fingers. | 696 | // back to -lc++ and cross our fingers. |
| ... | @@ -694,7 +706,7 @@ fn addCmakeCfgOptionsToExe( | ... | @@ -694,7 +706,7 @@ fn addCmakeCfgOptionsToExe( |
| 694 | exe.linkLibCpp(); | 706 | exe.linkLibCpp(); |
| 695 | }, | 707 | }, |
| 696 | .windows => { | 708 | .windows => { |
| 697 | if (exe.target.getAbi() != .msvc) exe.linkLibCpp(); | 709 | if (exe.rootModuleTarget().abi != .msvc) exe.linkLibCpp(); |
| 698 | }, | 710 | }, |
| 699 | .freebsd => { | 711 | .freebsd => { |
| 700 | if (static) { | 712 | if (static) { |
| ... | @@ -756,12 +768,12 @@ fn addStaticLlvmOptionsToExe(exe: *std.Build.Step.Compile) !void { | ... | @@ -756,12 +768,12 @@ fn addStaticLlvmOptionsToExe(exe: *std.Build.Step.Compile) !void { |
| 756 | exe.linkSystemLibrary("z"); | 768 | exe.linkSystemLibrary("z"); |
| 757 | exe.linkSystemLibrary("zstd"); | 769 | exe.linkSystemLibrary("zstd"); |
| 758 | 770 | ||
| 759 | if (exe.target.getOs().tag != .windows or exe.target.getAbi() != .msvc) { | 771 | if (exe.rootModuleTarget().os.tag != .windows or exe.rootModuleTarget().abi != .msvc) { |
| 760 | // This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries. | 772 | // This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries. |
| 761 | exe.linkSystemLibrary("c++"); | 773 | exe.linkSystemLibrary("c++"); |
| 762 | } | 774 | } |
| 763 | 775 | ||
| 764 | if (exe.target.getOs().tag == .windows) { | 776 | if (exe.rootModuleTarget().os.tag == .windows) { |
| 765 | exe.linkSystemLibrary("version"); | 777 | exe.linkSystemLibrary("version"); |
| 766 | exe.linkSystemLibrary("uuid"); | 778 | exe.linkSystemLibrary("uuid"); |
| 767 | exe.linkSystemLibrary("ole32"); | 779 | exe.linkSystemLibrary("ole32"); |
| ... | @@ -810,7 +822,9 @@ fn addCMakeLibraryList(exe: *std.Build.Step.Compile, list: []const u8) void { | ... | @@ -810,7 +822,9 @@ fn addCMakeLibraryList(exe: *std.Build.Step.Compile, list: []const u8) void { |
| 810 | while (it.next()) |lib| { | 822 | while (it.next()) |lib| { |
| 811 | if (mem.startsWith(u8, lib, "-l")) { | 823 | if (mem.startsWith(u8, lib, "-l")) { |
| 812 | exe.linkSystemLibrary(lib["-l".len..]); | 824 | exe.linkSystemLibrary(lib["-l".len..]); |
| 813 | } else if (exe.target.isWindows() and mem.endsWith(u8, lib, ".lib") and !fs.path.isAbsolute(lib)) { | 825 | } else if (exe.rootModuleTarget().os.tag == .windows and |
| 826 | mem.endsWith(u8, lib, ".lib") and !fs.path.isAbsolute(lib)) | ||
| 827 | { | ||
| 814 | exe.linkSystemLibrary(lib[0 .. lib.len - ".lib".len]); | 828 | exe.linkSystemLibrary(lib[0 .. lib.len - ".lib".len]); |
| 815 | } else { | 829 | } else { |
| 816 | exe.addObjectFile(.{ .cwd_relative = lib }); | 830 | exe.addObjectFile(.{ .cwd_relative = lib }); |
deps/aro/build/GenerateDef.zig+2-2| ... | @@ -21,7 +21,7 @@ pub const Options = struct { | ... | @@ -21,7 +21,7 @@ pub const Options = struct { |
| 21 | pub const Kind = enum { dafsa, named }; | 21 | pub const Kind = enum { dafsa, named }; |
| 22 | }; | 22 | }; |
| 23 | 23 | ||
| 24 | pub fn create(owner: *std.Build, options: Options) std.Build.ModuleDependency { | 24 | pub fn create(owner: *std.Build, options: Options) std.Build.Module.Import { |
| 25 | const self = owner.allocator.create(GenerateDef) catch @panic("OOM"); | 25 | const self = owner.allocator.create(GenerateDef) catch @panic("OOM"); |
| 26 | const path = owner.pathJoin(&.{ options.src_prefix, options.name }); | 26 | const path = owner.pathJoin(&.{ options.src_prefix, options.name }); |
| 27 | 27 | ||
| ... | @@ -39,7 +39,7 @@ pub fn create(owner: *std.Build, options: Options) std.Build.ModuleDependency { | ... | @@ -39,7 +39,7 @@ pub fn create(owner: *std.Build, options: Options) std.Build.ModuleDependency { |
| 39 | .generated_file = .{ .step = &self.step }, | 39 | .generated_file = .{ .step = &self.step }, |
| 40 | }; | 40 | }; |
| 41 | const module = self.step.owner.createModule(.{ | 41 | const module = self.step.owner.createModule(.{ |
| 42 | .source_file = .{ .generated = &self.generated_file }, | 42 | .root_source_file = .{ .generated = &self.generated_file }, |
| 43 | }); | 43 | }); |
| 44 | return .{ | 44 | return .{ |
| 45 | .module = module, | 45 | .module = module, |
lib/build_runner.zig+6-1| ... | @@ -46,7 +46,12 @@ pub fn main() !void { | ... | @@ -46,7 +46,12 @@ pub fn main() !void { |
| 46 | return error.InvalidArgs; | 46 | return error.InvalidArgs; |
| 47 | }; | 47 | }; |
| 48 | 48 | ||
| 49 | const host = try std.zig.system.NativeTargetInfo.detect(.{}); | 49 | const detected = try std.zig.system.NativeTargetInfo.detect(.{}); |
| 50 | const host: std.Build.ResolvedTarget = .{ | ||
| 51 | .query = .{}, | ||
| 52 | .target = detected.target, | ||
| 53 | .dynamic_linker = detected.dynamic_linker, | ||
| 54 | }; | ||
| 50 | 55 | ||
| 51 | const build_root_directory: std.Build.Cache.Directory = .{ | 56 | const build_root_directory: std.Build.Cache.Directory = .{ |
| 52 | .path = build_root, | 57 | .path = build_root, |
lib/std/Build.zig+129-48| ... | @@ -14,20 +14,11 @@ const process = std.process; | ... | @@ -14,20 +14,11 @@ const process = std.process; |
| 14 | const EnvMap = std.process.EnvMap; | 14 | const EnvMap = std.process.EnvMap; |
| 15 | const fmt_lib = std.fmt; | 15 | const fmt_lib = std.fmt; |
| 16 | const File = std.fs.File; | 16 | const File = std.fs.File; |
| 17 | const CrossTarget = std.zig.CrossTarget; | 17 | const TargetQuery = std.zig.CrossTarget; |
| 18 | const NativeTargetInfo = std.zig.system.NativeTargetInfo; | ||
| 19 | const Sha256 = std.crypto.hash.sha2.Sha256; | 18 | const Sha256 = std.crypto.hash.sha2.Sha256; |
| 20 | const Build = @This(); | 19 | const Build = @This(); |
| 21 | 20 | ||
| 22 | pub const Cache = @import("Build/Cache.zig"); | 21 | pub const Cache = @import("Build/Cache.zig"); |
| 23 | |||
| 24 | /// deprecated: use `Step.Compile`. | ||
| 25 | pub const LibExeObjStep = Step.Compile; | ||
| 26 | /// deprecated: use `Build`. | ||
| 27 | pub const Builder = Build; | ||
| 28 | /// deprecated: use `Step.InstallDir.Options` | ||
| 29 | pub const InstallDirectoryOptions = Step.InstallDir.Options; | ||
| 30 | |||
| 31 | pub const Step = @import("Build/Step.zig"); | 22 | pub const Step = @import("Build/Step.zig"); |
| 32 | pub const Module = @import("Build/Module.zig"); | 23 | pub const Module = @import("Build/Module.zig"); |
| 33 | 24 | ||
| ... | @@ -94,7 +85,7 @@ enable_wine: bool = false, | ... | @@ -94,7 +85,7 @@ enable_wine: bool = false, |
| 94 | glibc_runtimes_dir: ?[]const u8 = null, | 85 | glibc_runtimes_dir: ?[]const u8 = null, |
| 95 | 86 | ||
| 96 | /// Information about the native target. Computed before build() is invoked. | 87 | /// Information about the native target. Computed before build() is invoked. |
| 97 | host: NativeTargetInfo, | 88 | host: ResolvedTarget, |
| 98 | 89 | ||
| 99 | dep_prefix: []const u8 = "", | 90 | dep_prefix: []const u8 = "", |
| 100 | 91 | ||
| ... | @@ -220,7 +211,7 @@ pub fn create( | ... | @@ -220,7 +211,7 @@ pub fn create( |
| 220 | build_root: Cache.Directory, | 211 | build_root: Cache.Directory, |
| 221 | cache_root: Cache.Directory, | 212 | cache_root: Cache.Directory, |
| 222 | global_cache_root: Cache.Directory, | 213 | global_cache_root: Cache.Directory, |
| 223 | host: NativeTargetInfo, | 214 | host: ResolvedTarget, |
| 224 | cache: *Cache, | 215 | cache: *Cache, |
| 225 | available_deps: AvailableDeps, | 216 | available_deps: AvailableDeps, |
| 226 | ) !*Build { | 217 | ) !*Build { |
| ... | @@ -384,7 +375,7 @@ fn userInputOptionsFromArgs(allocator: Allocator, args: anytype) UserInputOption | ... | @@ -384,7 +375,7 @@ fn userInputOptionsFromArgs(allocator: Allocator, args: anytype) UserInputOption |
| 384 | const v = @field(args, field.name); | 375 | const v = @field(args, field.name); |
| 385 | const T = @TypeOf(v); | 376 | const T = @TypeOf(v); |
| 386 | switch (T) { | 377 | switch (T) { |
| 387 | CrossTarget => { | 378 | TargetQuery => { |
| 388 | user_input_options.put(field.name, .{ | 379 | user_input_options.put(field.name, .{ |
| 389 | .name = field.name, | 380 | .name = field.name, |
| 390 | .value = .{ .scalar = v.zigTriple(allocator) catch @panic("OOM") }, | 381 | .value = .{ .scalar = v.zigTriple(allocator) catch @panic("OOM") }, |
| ... | @@ -593,14 +584,22 @@ pub fn addOptions(self: *Build) *Step.Options { | ... | @@ -593,14 +584,22 @@ pub fn addOptions(self: *Build) *Step.Options { |
| 593 | 584 | ||
| 594 | pub const ExecutableOptions = struct { | 585 | pub const ExecutableOptions = struct { |
| 595 | name: []const u8, | 586 | name: []const u8, |
| 587 | /// If you want the executable to run on the same computer as the one | ||
| 588 | /// building the package, pass the `host` field of the package's `Build` | ||
| 589 | /// instance. | ||
| 590 | target: ResolvedTarget, | ||
| 596 | root_source_file: ?LazyPath = null, | 591 | root_source_file: ?LazyPath = null, |
| 597 | version: ?std.SemanticVersion = null, | 592 | version: ?std.SemanticVersion = null, |
| 598 | target: CrossTarget = .{}, | ||
| 599 | optimize: std.builtin.OptimizeMode = .Debug, | 593 | optimize: std.builtin.OptimizeMode = .Debug, |
| 600 | linkage: ?Step.Compile.Linkage = null, | 594 | linkage: ?Step.Compile.Linkage = null, |
| 601 | max_rss: usize = 0, | 595 | max_rss: usize = 0, |
| 602 | link_libc: ?bool = null, | 596 | link_libc: ?bool = null, |
| 603 | single_threaded: ?bool = null, | 597 | single_threaded: ?bool = null, |
| 598 | pic: ?bool = null, | ||
| 599 | strip: ?bool = null, | ||
| 600 | unwind_tables: ?bool = null, | ||
| 601 | omit_frame_pointer: ?bool = null, | ||
| 602 | sanitize_thread: ?bool = null, | ||
| 604 | use_llvm: ?bool = null, | 603 | use_llvm: ?bool = null, |
| 605 | use_lld: ?bool = null, | 604 | use_lld: ?bool = null, |
| 606 | zig_lib_dir: ?LazyPath = null, | 605 | zig_lib_dir: ?LazyPath = null, |
| ... | @@ -621,6 +620,11 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { | ... | @@ -621,6 +620,11 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { |
| 621 | .optimize = options.optimize, | 620 | .optimize = options.optimize, |
| 622 | .link_libc = options.link_libc, | 621 | .link_libc = options.link_libc, |
| 623 | .single_threaded = options.single_threaded, | 622 | .single_threaded = options.single_threaded, |
| 623 | .pic = options.pic, | ||
| 624 | .strip = options.strip, | ||
| 625 | .unwind_tables = options.unwind_tables, | ||
| 626 | .omit_frame_pointer = options.omit_frame_pointer, | ||
| 627 | .sanitize_thread = options.sanitize_thread, | ||
| 624 | }, | 628 | }, |
| 625 | .version = options.version, | 629 | .version = options.version, |
| 626 | .kind = .exe, | 630 | .kind = .exe, |
| ... | @@ -636,11 +640,18 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { | ... | @@ -636,11 +640,18 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { |
| 636 | pub const ObjectOptions = struct { | 640 | pub const ObjectOptions = struct { |
| 637 | name: []const u8, | 641 | name: []const u8, |
| 638 | root_source_file: ?LazyPath = null, | 642 | root_source_file: ?LazyPath = null, |
| 639 | target: CrossTarget, | 643 | /// To choose the same computer as the one building the package, pass the |
| 644 | /// `host` field of the package's `Build` instance. | ||
| 645 | target: ResolvedTarget, | ||
| 640 | optimize: std.builtin.OptimizeMode, | 646 | optimize: std.builtin.OptimizeMode, |
| 641 | max_rss: usize = 0, | 647 | max_rss: usize = 0, |
| 642 | link_libc: ?bool = null, | 648 | link_libc: ?bool = null, |
| 643 | single_threaded: ?bool = null, | 649 | single_threaded: ?bool = null, |
| 650 | pic: ?bool = null, | ||
| 651 | strip: ?bool = null, | ||
| 652 | unwind_tables: ?bool = null, | ||
| 653 | omit_frame_pointer: ?bool = null, | ||
| 654 | sanitize_thread: ?bool = null, | ||
| 644 | use_llvm: ?bool = null, | 655 | use_llvm: ?bool = null, |
| 645 | use_lld: ?bool = null, | 656 | use_lld: ?bool = null, |
| 646 | zig_lib_dir: ?LazyPath = null, | 657 | zig_lib_dir: ?LazyPath = null, |
| ... | @@ -655,6 +666,11 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { | ... | @@ -655,6 +666,11 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { |
| 655 | .optimize = options.optimize, | 666 | .optimize = options.optimize, |
| 656 | .link_libc = options.link_libc, | 667 | .link_libc = options.link_libc, |
| 657 | .single_threaded = options.single_threaded, | 668 | .single_threaded = options.single_threaded, |
| 669 | .pic = options.pic, | ||
| 670 | .strip = options.strip, | ||
| 671 | .unwind_tables = options.unwind_tables, | ||
| 672 | .omit_frame_pointer = options.omit_frame_pointer, | ||
| 673 | .sanitize_thread = options.sanitize_thread, | ||
| 658 | }, | 674 | }, |
| 659 | .kind = .obj, | 675 | .kind = .obj, |
| 660 | .max_rss = options.max_rss, | 676 | .max_rss = options.max_rss, |
| ... | @@ -666,13 +682,20 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { | ... | @@ -666,13 +682,20 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { |
| 666 | 682 | ||
| 667 | pub const SharedLibraryOptions = struct { | 683 | pub const SharedLibraryOptions = struct { |
| 668 | name: []const u8, | 684 | name: []const u8, |
| 685 | /// To choose the same computer as the one building the package, pass the | ||
| 686 | /// `host` field of the package's `Build` instance. | ||
| 687 | target: ResolvedTarget, | ||
| 688 | optimize: std.builtin.OptimizeMode, | ||
| 669 | root_source_file: ?LazyPath = null, | 689 | root_source_file: ?LazyPath = null, |
| 670 | version: ?std.SemanticVersion = null, | 690 | version: ?std.SemanticVersion = null, |
| 671 | target: CrossTarget, | ||
| 672 | optimize: std.builtin.OptimizeMode, | ||
| 673 | max_rss: usize = 0, | 691 | max_rss: usize = 0, |
| 674 | link_libc: ?bool = null, | 692 | link_libc: ?bool = null, |
| 675 | single_threaded: ?bool = null, | 693 | single_threaded: ?bool = null, |
| 694 | pic: ?bool = null, | ||
| 695 | strip: ?bool = null, | ||
| 696 | unwind_tables: ?bool = null, | ||
| 697 | omit_frame_pointer: ?bool = null, | ||
| 698 | sanitize_thread: ?bool = null, | ||
| 676 | use_llvm: ?bool = null, | 699 | use_llvm: ?bool = null, |
| 677 | use_lld: ?bool = null, | 700 | use_lld: ?bool = null, |
| 678 | zig_lib_dir: ?LazyPath = null, | 701 | zig_lib_dir: ?LazyPath = null, |
| ... | @@ -693,6 +716,11 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile | ... | @@ -693,6 +716,11 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile |
| 693 | .root_source_file = options.root_source_file, | 716 | .root_source_file = options.root_source_file, |
| 694 | .link_libc = options.link_libc, | 717 | .link_libc = options.link_libc, |
| 695 | .single_threaded = options.single_threaded, | 718 | .single_threaded = options.single_threaded, |
| 719 | .pic = options.pic, | ||
| 720 | .strip = options.strip, | ||
| 721 | .unwind_tables = options.unwind_tables, | ||
| 722 | .omit_frame_pointer = options.omit_frame_pointer, | ||
| 723 | .sanitize_thread = options.sanitize_thread, | ||
| 696 | }, | 724 | }, |
| 697 | .kind = .lib, | 725 | .kind = .lib, |
| 698 | .linkage = .dynamic, | 726 | .linkage = .dynamic, |
| ... | @@ -708,12 +736,19 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile | ... | @@ -708,12 +736,19 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile |
| 708 | pub const StaticLibraryOptions = struct { | 736 | pub const StaticLibraryOptions = struct { |
| 709 | name: []const u8, | 737 | name: []const u8, |
| 710 | root_source_file: ?LazyPath = null, | 738 | root_source_file: ?LazyPath = null, |
| 711 | target: CrossTarget, | 739 | /// To choose the same computer as the one building the package, pass the |
| 740 | /// `host` field of the package's `Build` instance. | ||
| 741 | target: ResolvedTarget, | ||
| 712 | optimize: std.builtin.OptimizeMode, | 742 | optimize: std.builtin.OptimizeMode, |
| 713 | version: ?std.SemanticVersion = null, | 743 | version: ?std.SemanticVersion = null, |
| 714 | max_rss: usize = 0, | 744 | max_rss: usize = 0, |
| 715 | link_libc: ?bool = null, | 745 | link_libc: ?bool = null, |
| 716 | single_threaded: ?bool = null, | 746 | single_threaded: ?bool = null, |
| 747 | pic: ?bool = null, | ||
| 748 | strip: ?bool = null, | ||
| 749 | unwind_tables: ?bool = null, | ||
| 750 | omit_frame_pointer: ?bool = null, | ||
| 751 | sanitize_thread: ?bool = null, | ||
| 717 | use_llvm: ?bool = null, | 752 | use_llvm: ?bool = null, |
| 718 | use_lld: ?bool = null, | 753 | use_lld: ?bool = null, |
| 719 | zig_lib_dir: ?LazyPath = null, | 754 | zig_lib_dir: ?LazyPath = null, |
| ... | @@ -728,6 +763,11 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile | ... | @@ -728,6 +763,11 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile |
| 728 | .root_source_file = options.root_source_file, | 763 | .root_source_file = options.root_source_file, |
| 729 | .link_libc = options.link_libc, | 764 | .link_libc = options.link_libc, |
| 730 | .single_threaded = options.single_threaded, | 765 | .single_threaded = options.single_threaded, |
| 766 | .pic = options.pic, | ||
| 767 | .strip = options.strip, | ||
| 768 | .unwind_tables = options.unwind_tables, | ||
| 769 | .omit_frame_pointer = options.omit_frame_pointer, | ||
| 770 | .sanitize_thread = options.sanitize_thread, | ||
| 731 | }, | 771 | }, |
| 732 | .kind = .lib, | 772 | .kind = .lib, |
| 733 | .linkage = .static, | 773 | .linkage = .static, |
| ... | @@ -742,7 +782,7 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile | ... | @@ -742,7 +782,7 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile |
| 742 | pub const TestOptions = struct { | 782 | pub const TestOptions = struct { |
| 743 | name: []const u8 = "test", | 783 | name: []const u8 = "test", |
| 744 | root_source_file: LazyPath, | 784 | root_source_file: LazyPath, |
| 745 | target: CrossTarget = .{}, | 785 | target: ?ResolvedTarget = null, |
| 746 | optimize: std.builtin.OptimizeMode = .Debug, | 786 | optimize: std.builtin.OptimizeMode = .Debug, |
| 747 | version: ?std.SemanticVersion = null, | 787 | version: ?std.SemanticVersion = null, |
| 748 | max_rss: usize = 0, | 788 | max_rss: usize = 0, |
| ... | @@ -750,6 +790,11 @@ pub const TestOptions = struct { | ... | @@ -750,6 +790,11 @@ pub const TestOptions = struct { |
| 750 | test_runner: ?[]const u8 = null, | 790 | test_runner: ?[]const u8 = null, |
| 751 | link_libc: ?bool = null, | 791 | link_libc: ?bool = null, |
| 752 | single_threaded: ?bool = null, | 792 | single_threaded: ?bool = null, |
| 793 | pic: ?bool = null, | ||
| 794 | strip: ?bool = null, | ||
| 795 | unwind_tables: ?bool = null, | ||
| 796 | omit_frame_pointer: ?bool = null, | ||
| 797 | sanitize_thread: ?bool = null, | ||
| 753 | use_llvm: ?bool = null, | 798 | use_llvm: ?bool = null, |
| 754 | use_lld: ?bool = null, | 799 | use_lld: ?bool = null, |
| 755 | zig_lib_dir: ?LazyPath = null, | 800 | zig_lib_dir: ?LazyPath = null, |
| ... | @@ -761,10 +806,15 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { | ... | @@ -761,10 +806,15 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { |
| 761 | .kind = .@"test", | 806 | .kind = .@"test", |
| 762 | .root_module = .{ | 807 | .root_module = .{ |
| 763 | .root_source_file = options.root_source_file, | 808 | .root_source_file = options.root_source_file, |
| 764 | .target = options.target, | 809 | .target = options.target orelse b.host, |
| 765 | .optimize = options.optimize, | 810 | .optimize = options.optimize, |
| 766 | .link_libc = options.link_libc, | 811 | .link_libc = options.link_libc, |
| 767 | .single_threaded = options.single_threaded, | 812 | .single_threaded = options.single_threaded, |
| 813 | .pic = options.pic, | ||
| 814 | .strip = options.strip, | ||
| 815 | .unwind_tables = options.unwind_tables, | ||
| 816 | .omit_frame_pointer = options.omit_frame_pointer, | ||
| 817 | .sanitize_thread = options.sanitize_thread, | ||
| 768 | }, | 818 | }, |
| 769 | .max_rss = options.max_rss, | 819 | .max_rss = options.max_rss, |
| 770 | .filter = options.filter, | 820 | .filter = options.filter, |
| ... | @@ -778,7 +828,9 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { | ... | @@ -778,7 +828,9 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { |
| 778 | pub const AssemblyOptions = struct { | 828 | pub const AssemblyOptions = struct { |
| 779 | name: []const u8, | 829 | name: []const u8, |
| 780 | source_file: LazyPath, | 830 | source_file: LazyPath, |
| 781 | target: CrossTarget, | 831 | /// To choose the same computer as the one building the package, pass the |
| 832 | /// `host` field of the package's `Build` instance. | ||
| 833 | target: ResolvedTarget, | ||
| 782 | optimize: std.builtin.OptimizeMode, | 834 | optimize: std.builtin.OptimizeMode, |
| 783 | max_rss: usize = 0, | 835 | max_rss: usize = 0, |
| 784 | zig_lib_dir: ?LazyPath = null, | 836 | zig_lib_dir: ?LazyPath = null, |
| ... | @@ -1061,7 +1113,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ | ... | @@ -1061,7 +1113,7 @@ pub fn option(self: *Build, comptime T: type, name_raw: []const u8, description_ |
| 1061 | return null; | 1113 | return null; |
| 1062 | }, | 1114 | }, |
| 1063 | .scalar => |s| { | 1115 | .scalar => |s| { |
| 1064 | if (Step.Compile.BuildId.parse(s)) |build_id| { | 1116 | if (std.zig.BuildId.parse(s)) |build_id| { |
| 1065 | return build_id; | 1117 | return build_id; |
| 1066 | } else |err| { | 1118 | } else |err| { |
| 1067 | log.err("unable to parse option '-D{s}': {s}", .{ name, @errorName(err) }); | 1119 | log.err("unable to parse option '-D{s}': {s}", .{ name, @errorName(err) }); |
| ... | @@ -1126,13 +1178,20 @@ pub fn standardOptimizeOption(self: *Build, options: StandardOptimizeOptionOptio | ... | @@ -1126,13 +1178,20 @@ pub fn standardOptimizeOption(self: *Build, options: StandardOptimizeOptionOptio |
| 1126 | } | 1178 | } |
| 1127 | 1179 | ||
| 1128 | pub const StandardTargetOptionsArgs = struct { | 1180 | pub const StandardTargetOptionsArgs = struct { |
| 1129 | whitelist: ?[]const CrossTarget = null, | 1181 | whitelist: ?[]const TargetQuery = null, |
| 1130 | 1182 | ||
| 1131 | default_target: CrossTarget = CrossTarget{}, | 1183 | default_target: TargetQuery = .{}, |
| 1132 | }; | 1184 | }; |
| 1133 | 1185 | ||
| 1186 | /// Exposes standard `zig build` options for choosing a target and additionally | ||
| 1187 | /// resolves the target query. | ||
| 1188 | pub fn standardTargetOptions(b: *Build, args: StandardTargetOptionsArgs) ResolvedTarget { | ||
| 1189 | const query = b.standardTargetOptionsQueryOnly(args); | ||
| 1190 | return b.resolveTargetQuery(query); | ||
| 1191 | } | ||
| 1192 | |||
| 1134 | /// Exposes standard `zig build` options for choosing a target. | 1193 | /// Exposes standard `zig build` options for choosing a target. |
| 1135 | pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) CrossTarget { | 1194 | pub fn standardTargetOptionsQueryOnly(self: *Build, args: StandardTargetOptionsArgs) TargetQuery { |
| 1136 | const maybe_triple = self.option( | 1195 | const maybe_triple = self.option( |
| 1137 | []const u8, | 1196 | []const u8, |
| 1138 | "target", | 1197 | "target", |
| ... | @@ -1146,8 +1205,8 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros | ... | @@ -1146,8 +1205,8 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros |
| 1146 | 1205 | ||
| 1147 | const triple = maybe_triple orelse "native"; | 1206 | const triple = maybe_triple orelse "native"; |
| 1148 | 1207 | ||
| 1149 | var diags: CrossTarget.ParseOptions.Diagnostics = .{}; | 1208 | var diags: TargetQuery.ParseOptions.Diagnostics = .{}; |
| 1150 | const selected_target = CrossTarget.parse(.{ | 1209 | const selected_target = TargetQuery.parse(.{ |
| 1151 | .arch_os_abi = triple, | 1210 | .arch_os_abi = triple, |
| 1152 | .cpu_features = mcpu, | 1211 | .cpu_features = mcpu, |
| 1153 | .diagnostics = &diags, | 1212 | .diagnostics = &diags, |
| ... | @@ -1203,7 +1262,7 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros | ... | @@ -1203,7 +1262,7 @@ pub fn standardTargetOptions(self: *Build, args: StandardTargetOptionsArgs) Cros |
| 1203 | // Make sure it's a match of one of the list. | 1262 | // Make sure it's a match of one of the list. |
| 1204 | var mismatch_triple = true; | 1263 | var mismatch_triple = true; |
| 1205 | var mismatch_cpu_features = true; | 1264 | var mismatch_cpu_features = true; |
| 1206 | var whitelist_item = CrossTarget{}; | 1265 | var whitelist_item: TargetQuery = .{}; |
| 1207 | for (list) |t| { | 1266 | for (list) |t| { |
| 1208 | mismatch_cpu_features = true; | 1267 | mismatch_cpu_features = true; |
| 1209 | mismatch_triple = true; | 1268 | mismatch_triple = true; |
| ... | @@ -1340,7 +1399,7 @@ pub fn addUserInputFlag(self: *Build, name_raw: []const u8) !bool { | ... | @@ -1340,7 +1399,7 @@ pub fn addUserInputFlag(self: *Build, name_raw: []const u8) !bool { |
| 1340 | 1399 | ||
| 1341 | fn typeToEnum(comptime T: type) TypeId { | 1400 | fn typeToEnum(comptime T: type) TypeId { |
| 1342 | return switch (T) { | 1401 | return switch (T) { |
| 1343 | Step.Compile.BuildId => .build_id, | 1402 | std.zig.BuildId => .build_id, |
| 1344 | else => return switch (@typeInfo(T)) { | 1403 | else => return switch (@typeInfo(T)) { |
| 1345 | .Int => .int, | 1404 | .Int => .int, |
| 1346 | .Float => .float, | 1405 | .Float => .float, |
| ... | @@ -1408,7 +1467,7 @@ pub fn installFile(self: *Build, src_path: []const u8, dest_rel_path: []const u8 | ... | @@ -1408,7 +1467,7 @@ pub fn installFile(self: *Build, src_path: []const u8, dest_rel_path: []const u8 |
| 1408 | self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .prefix, dest_rel_path).step); | 1467 | self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .prefix, dest_rel_path).step); |
| 1409 | } | 1468 | } |
| 1410 | 1469 | ||
| 1411 | pub fn installDirectory(self: *Build, options: InstallDirectoryOptions) void { | 1470 | pub fn installDirectory(self: *Build, options: Step.InstallDir.Options) void { |
| 1412 | self.getInstallStep().dependOn(&self.addInstallDirectory(options).step); | 1471 | self.getInstallStep().dependOn(&self.addInstallDirectory(options).step); |
| 1413 | } | 1472 | } |
| 1414 | 1473 | ||
| ... | @@ -1454,7 +1513,7 @@ pub fn addInstallFileWithDir( | ... | @@ -1454,7 +1513,7 @@ pub fn addInstallFileWithDir( |
| 1454 | return Step.InstallFile.create(self, source.dupe(self), install_dir, dest_rel_path); | 1513 | return Step.InstallFile.create(self, source.dupe(self), install_dir, dest_rel_path); |
| 1455 | } | 1514 | } |
| 1456 | 1515 | ||
| 1457 | pub fn addInstallDirectory(self: *Build, options: InstallDirectoryOptions) *Step.InstallDir { | 1516 | pub fn addInstallDirectory(self: *Build, options: Step.InstallDir.Options) *Step.InstallDir { |
| 1458 | return Step.InstallDir.create(self, options); | 1517 | return Step.InstallDir.create(self, options); |
| 1459 | } | 1518 | } |
| 1460 | 1519 | ||
| ... | @@ -1511,7 +1570,7 @@ pub fn fmt(self: *Build, comptime format: []const u8, args: anytype) []u8 { | ... | @@ -1511,7 +1570,7 @@ pub fn fmt(self: *Build, comptime format: []const u8, args: anytype) []u8 { |
| 1511 | 1570 | ||
| 1512 | pub fn findProgram(self: *Build, names: []const []const u8, paths: []const []const u8) ![]const u8 { | 1571 | pub fn findProgram(self: *Build, names: []const []const u8, paths: []const []const u8) ![]const u8 { |
| 1513 | // TODO report error for ambiguous situations | 1572 | // TODO report error for ambiguous situations |
| 1514 | const exe_extension = @as(CrossTarget, .{}).exeFileExt(); | 1573 | const exe_extension = @as(TargetQuery, .{}).exeFileExt(); |
| 1515 | for (self.search_prefixes.items) |search_prefix| { | 1574 | for (self.search_prefixes.items) |search_prefix| { |
| 1516 | for (names) |name| { | 1575 | for (names) |name| { |
| 1517 | if (fs.path.isAbsolute(name)) { | 1576 | if (fs.path.isAbsolute(name)) { |
| ... | @@ -1957,22 +2016,6 @@ pub fn dumpBadGetPathHelp( | ... | @@ -1957,22 +2016,6 @@ pub fn dumpBadGetPathHelp( |
| 1957 | tty_config.setColor(w, .reset) catch {}; | 2016 | tty_config.setColor(w, .reset) catch {}; |
| 1958 | } | 2017 | } |
| 1959 | 2018 | ||
| 1960 | /// Allocates a new string for assigning a value to a named macro. | ||
| 1961 | /// If the value is omitted, it is set to 1. | ||
| 1962 | /// `name` and `value` need not live longer than the function call. | ||
| 1963 | pub fn constructCMacro(allocator: Allocator, name: []const u8, value: ?[]const u8) []const u8 { | ||
| 1964 | var macro = allocator.alloc( | ||
| 1965 | u8, | ||
| 1966 | name.len + if (value) |value_slice| value_slice.len + 1 else 0, | ||
| 1967 | ) catch |err| if (err == error.OutOfMemory) @panic("Out of memory") else unreachable; | ||
| 1968 | @memcpy(macro[0..name.len], name); | ||
| 1969 | if (value) |value_slice| { | ||
| 1970 | macro[name.len] = '='; | ||
| 1971 | @memcpy(macro[name.len + 1 ..][0..value_slice.len], value_slice); | ||
| 1972 | } | ||
| 1973 | return macro; | ||
| 1974 | } | ||
| 1975 | |||
| 1976 | pub const InstallDir = union(enum) { | 2019 | pub const InstallDir = union(enum) { |
| 1977 | prefix: void, | 2020 | prefix: void, |
| 1978 | lib: void, | 2021 | lib: void, |
| ... | @@ -2062,6 +2105,44 @@ pub fn hex64(x: u64) [16]u8 { | ... | @@ -2062,6 +2105,44 @@ pub fn hex64(x: u64) [16]u8 { |
| 2062 | return result; | 2105 | return result; |
| 2063 | } | 2106 | } |
| 2064 | 2107 | ||
| 2108 | /// A pair of target query and fully resolved target. | ||
| 2109 | /// This type is generally required by build system API that need to be given a | ||
| 2110 | /// target. The query is kept because the Zig toolchain needs to know which parts | ||
| 2111 | /// of the target are "native". This can apply to the CPU, the OS, or even the ABI. | ||
| 2112 | pub const ResolvedTarget = struct { | ||
| 2113 | query: TargetQuery, | ||
| 2114 | target: std.Target, | ||
| 2115 | dynamic_linker: std.Target.DynamicLinker, | ||
| 2116 | |||
| 2117 | pub fn toNativeTargetInfo(self: ResolvedTarget) std.zig.system.NativeTargetInfo { | ||
| 2118 | return .{ | ||
| 2119 | .target = self.target, | ||
| 2120 | .dynamic_linker = self.dynamic_linker, | ||
| 2121 | }; | ||
| 2122 | } | ||
| 2123 | }; | ||
| 2124 | |||
| 2125 | /// Converts a target query into a fully resolved target that can be passed to | ||
| 2126 | /// various parts of the API. | ||
| 2127 | pub fn resolveTargetQuery(b: *Build, query: TargetQuery) ResolvedTarget { | ||
| 2128 | // This context will likely be required in the future when the target is | ||
| 2129 | // resolved via a WASI API or via the build protocol. | ||
| 2130 | _ = b; | ||
| 2131 | |||
| 2132 | const result = std.zig.system.NativeTargetInfo.detect(query) catch | ||
| 2133 | @panic("unable to resolve target query"); | ||
| 2134 | |||
| 2135 | return .{ | ||
| 2136 | .query = query, | ||
| 2137 | .target = result.target, | ||
| 2138 | .dynamic_linker = result.dynamic_linker, | ||
| 2139 | }; | ||
| 2140 | } | ||
| 2141 | |||
| 2142 | pub fn wantSharedLibSymLinks(target: std.Target) bool { | ||
| 2143 | return target.os.tag != .windows; | ||
| 2144 | } | ||
| 2145 | |||
| 2065 | test { | 2146 | test { |
| 2066 | _ = Cache; | 2147 | _ = Cache; |
| 2067 | _ = Step; | 2148 | _ = Step; |
lib/std/Build/Cache.zig+1-1| ... | @@ -270,7 +270,7 @@ pub const HashHelper = struct { | ... | @@ -270,7 +270,7 @@ pub const HashHelper = struct { |
| 270 | .none => {}, | 270 | .none => {}, |
| 271 | } | 271 | } |
| 272 | }, | 272 | }, |
| 273 | std.Build.Step.Compile.BuildId => switch (x) { | 273 | std.zig.BuildId => switch (x) { |
| 274 | .none, .fast, .uuid, .sha1, .md5 => hh.add(std.meta.activeTag(x)), | 274 | .none, .fast, .uuid, .sha1, .md5 => hh.add(std.meta.activeTag(x)), |
| 275 | .hexstring => |hex_string| hh.addBytes(hex_string.toSlice()), | 275 | .hexstring => |hex_string| hh.addBytes(hex_string.toSlice()), |
| 276 | }, | 276 | }, |
lib/std/Build/Module.zig+239-108| ... | @@ -3,27 +3,24 @@ owner: *std.Build, | ... | @@ -3,27 +3,24 @@ owner: *std.Build, |
| 3 | /// Tracks the set of steps that depend on this `Module`. This ensures that | 3 | /// Tracks the set of steps that depend on this `Module`. This ensures that |
| 4 | /// when making this `Module` depend on other `Module` objects and `Step` | 4 | /// when making this `Module` depend on other `Module` objects and `Step` |
| 5 | /// objects, respective `Step` dependencies can be added. | 5 | /// objects, respective `Step` dependencies can be added. |
| 6 | depending_steps: std.AutoArrayHashMapUnmanaged(*std.Build.Step.Compile, void), | 6 | depending_steps: std.AutoArrayHashMapUnmanaged(*Step.Compile, void), |
| 7 | /// This could either be a generated file, in which case the module | ||
| 8 | /// contains exactly one file, or it could be a path to the root source | ||
| 9 | /// file of directory of files which constitute the module. | ||
| 10 | /// If `null`, it means this module is made up of only `link_objects`. | ||
| 11 | root_source_file: ?LazyPath, | 7 | root_source_file: ?LazyPath, |
| 12 | /// The modules that are mapped into this module's import table. | 8 | /// The modules that are mapped into this module's import table. |
| 13 | import_table: std.StringArrayHashMap(*Module), | 9 | /// Use `addImport` rather than modifying this field directly in order to |
| 10 | /// maintain step dependency edges. | ||
| 11 | import_table: std.StringArrayHashMapUnmanaged(*Module), | ||
| 14 | 12 | ||
| 15 | target: std.zig.CrossTarget, | 13 | target: ?std.Build.ResolvedTarget = null, |
| 16 | target_info: NativeTargetInfo, | 14 | optimize: ?std.builtin.OptimizeMode = null, |
| 17 | optimize: std.builtin.OptimizeMode, | ||
| 18 | dwarf_format: ?std.dwarf.Format, | 15 | dwarf_format: ?std.dwarf.Format, |
| 19 | 16 | ||
| 20 | c_macros: std.ArrayList([]const u8), | 17 | c_macros: std.ArrayListUnmanaged([]const u8), |
| 21 | include_dirs: std.ArrayList(IncludeDir), | 18 | include_dirs: std.ArrayListUnmanaged(IncludeDir), |
| 22 | lib_paths: std.ArrayList(LazyPath), | 19 | lib_paths: std.ArrayListUnmanaged(LazyPath), |
| 23 | rpaths: std.ArrayList(LazyPath), | 20 | rpaths: std.ArrayListUnmanaged(RPath), |
| 24 | frameworks: std.StringArrayHashMapUnmanaged(FrameworkLinkInfo), | 21 | frameworks: std.StringArrayHashMapUnmanaged(LinkFrameworkOptions), |
| 25 | c_std: std.Build.CStd, | 22 | c_std: std.Build.CStd, |
| 26 | link_objects: std.ArrayList(LinkObject), | 23 | link_objects: std.ArrayListUnmanaged(LinkObject), |
| 27 | 24 | ||
| 28 | strip: ?bool, | 25 | strip: ?bool, |
| 29 | unwind_tables: ?bool, | 26 | unwind_tables: ?bool, |
| ... | @@ -53,9 +50,14 @@ link_libcpp: ?bool, | ... | @@ -53,9 +50,14 @@ link_libcpp: ?bool, |
| 53 | /// Symbols to be exported when compiling to WebAssembly. | 50 | /// Symbols to be exported when compiling to WebAssembly. |
| 54 | export_symbol_names: []const []const u8 = &.{}, | 51 | export_symbol_names: []const []const u8 = &.{}, |
| 55 | 52 | ||
| 53 | pub const RPath = union(enum) { | ||
| 54 | lazy_path: LazyPath, | ||
| 55 | special: []const u8, | ||
| 56 | }; | ||
| 57 | |||
| 56 | pub const LinkObject = union(enum) { | 58 | pub const LinkObject = union(enum) { |
| 57 | static_path: LazyPath, | 59 | static_path: LazyPath, |
| 58 | other_step: *std.Build.Step.Compile, | 60 | other_step: *Step.Compile, |
| 59 | system_lib: SystemLib, | 61 | system_lib: SystemLib, |
| 60 | assembly_file: LazyPath, | 62 | assembly_file: LazyPath, |
| 61 | c_source_file: *CSourceFile, | 63 | c_source_file: *CSourceFile, |
| ... | @@ -133,21 +135,32 @@ pub const IncludeDir = union(enum) { | ... | @@ -133,21 +135,32 @@ pub const IncludeDir = union(enum) { |
| 133 | path_after: LazyPath, | 135 | path_after: LazyPath, |
| 134 | framework_path: LazyPath, | 136 | framework_path: LazyPath, |
| 135 | framework_path_system: LazyPath, | 137 | framework_path_system: LazyPath, |
| 136 | other_step: *std.Build.Step.Compile, | 138 | other_step: *Step.Compile, |
| 137 | config_header_step: *std.Build.Step.ConfigHeader, | 139 | config_header_step: *Step.ConfigHeader, |
| 138 | }; | 140 | }; |
| 139 | 141 | ||
| 140 | pub const FrameworkLinkInfo = struct { | 142 | pub const LinkFrameworkOptions = struct { |
| 141 | needed: bool = false, | 143 | needed: bool = false, |
| 142 | weak: bool = false, | 144 | weak: bool = false, |
| 143 | }; | 145 | }; |
| 144 | 146 | ||
| 147 | /// Unspecified options here will be inherited from parent `Module` when | ||
| 148 | /// inserted into an import table. | ||
| 145 | pub const CreateOptions = struct { | 149 | pub const CreateOptions = struct { |
| 146 | target: std.zig.CrossTarget, | 150 | /// This could either be a generated file, in which case the module |
| 147 | target_info: ?NativeTargetInfo = null, | 151 | /// contains exactly one file, or it could be a path to the root source |
| 148 | optimize: std.builtin.OptimizeMode, | 152 | /// file of directory of files which constitute the module. |
| 153 | /// If `null`, it means this module is made up of only `link_objects`. | ||
| 149 | root_source_file: ?LazyPath = null, | 154 | root_source_file: ?LazyPath = null, |
| 150 | import_table: []const Import = &.{}, | 155 | |
| 156 | /// The table of other modules that this module can access via `@import`. | ||
| 157 | /// Imports are allowed to be cyclical, so this table can be added to after | ||
| 158 | /// the `Module` is created via `addImport`. | ||
| 159 | imports: []const Import = &.{}, | ||
| 160 | |||
| 161 | target: ?std.Build.ResolvedTarget = null, | ||
| 162 | optimize: ?std.builtin.OptimizeMode = null, | ||
| 163 | |||
| 151 | link_libc: ?bool = null, | 164 | link_libc: ?bool = null, |
| 152 | link_libcpp: ?bool = null, | 165 | link_libcpp: ?bool = null, |
| 153 | single_threaded: ?bool = null, | 166 | single_threaded: ?bool = null, |
| ... | @@ -173,26 +186,26 @@ pub const Import = struct { | ... | @@ -173,26 +186,26 @@ pub const Import = struct { |
| 173 | module: *Module, | 186 | module: *Module, |
| 174 | }; | 187 | }; |
| 175 | 188 | ||
| 176 | pub fn init(owner: *std.Build, options: CreateOptions, compile: ?*std.Build.Step.Compile) Module { | 189 | pub fn init(m: *Module, owner: *std.Build, options: CreateOptions, compile: ?*Step.Compile) void { |
| 177 | var m: Module = .{ | 190 | const allocator = owner.allocator; |
| 191 | |||
| 192 | m.* = .{ | ||
| 178 | .owner = owner, | 193 | .owner = owner, |
| 179 | .depending_steps = .{}, | 194 | .depending_steps = .{}, |
| 180 | .root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null, | 195 | .root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null, |
| 181 | .import_table = std.StringArrayHashMap(*Module).init(owner.allocator), | 196 | .import_table = .{}, |
| 182 | .target = options.target, | 197 | .target = options.target, |
| 183 | .target_info = options.target_info orelse | ||
| 184 | NativeTargetInfo.detect(options.target) catch @panic("unhandled error"), | ||
| 185 | .optimize = options.optimize, | 198 | .optimize = options.optimize, |
| 186 | .link_libc = options.link_libc, | 199 | .link_libc = options.link_libc, |
| 187 | .link_libcpp = options.link_libcpp, | 200 | .link_libcpp = options.link_libcpp, |
| 188 | .dwarf_format = options.dwarf_format, | 201 | .dwarf_format = options.dwarf_format, |
| 189 | .c_macros = std.ArrayList([]const u8).init(owner.allocator), | 202 | .c_macros = .{}, |
| 190 | .include_dirs = std.ArrayList(IncludeDir).init(owner.allocator), | 203 | .include_dirs = .{}, |
| 191 | .lib_paths = std.ArrayList(LazyPath).init(owner.allocator), | 204 | .lib_paths = .{}, |
| 192 | .rpaths = std.ArrayList(LazyPath).init(owner.allocator), | 205 | .rpaths = .{}, |
| 193 | .frameworks = .{}, | 206 | .frameworks = .{}, |
| 194 | .c_std = options.c_std, | 207 | .c_std = options.c_std, |
| 195 | .link_objects = std.ArrayList(LinkObject).init(owner.allocator), | 208 | .link_objects = .{}, |
| 196 | .strip = options.strip, | 209 | .strip = options.strip, |
| 197 | .unwind_tables = options.unwind_tables, | 210 | .unwind_tables = options.unwind_tables, |
| 198 | .single_threaded = options.single_threaded, | 211 | .single_threaded = options.single_threaded, |
| ... | @@ -208,31 +221,30 @@ pub fn init(owner: *std.Build, options: CreateOptions, compile: ?*std.Build.Step | ... | @@ -208,31 +221,30 @@ pub fn init(owner: *std.Build, options: CreateOptions, compile: ?*std.Build.Step |
| 208 | .export_symbol_names = &.{}, | 221 | .export_symbol_names = &.{}, |
| 209 | }; | 222 | }; |
| 210 | 223 | ||
| 211 | if (compile) |c| { | 224 | m.import_table.ensureUnusedCapacity(allocator, options.imports.len) catch @panic("OOM"); |
| 212 | m.depending_steps.put(owner.allocator, c, {}) catch @panic("OOM"); | 225 | for (options.imports) |dep| { |
| 226 | m.import_table.putAssumeCapacity(dep.name, dep.module); | ||
| 213 | } | 227 | } |
| 214 | 228 | ||
| 215 | m.import_table.ensureUnusedCapacity(options.import_table.len) catch @panic("OOM"); | 229 | if (compile) |c| { |
| 216 | for (options.import_table) |dep| { | 230 | m.depending_steps.put(allocator, c, {}) catch @panic("OOM"); |
| 217 | m.import_table.putAssumeCapacity(dep.name, dep.module); | ||
| 218 | } | 231 | } |
| 219 | 232 | ||
| 233 | // This logic accesses `depending_steps` which was just modified above. | ||
| 220 | var it = m.iterateDependencies(null); | 234 | var it = m.iterateDependencies(null); |
| 221 | while (it.next()) |item| addShallowDependencies(&m, item.module); | 235 | while (it.next()) |item| addShallowDependencies(m, item.module); |
| 222 | |||
| 223 | return m; | ||
| 224 | } | 236 | } |
| 225 | 237 | ||
| 226 | pub fn create(owner: *std.Build, options: CreateOptions) *Module { | 238 | pub fn create(owner: *std.Build, options: CreateOptions) *Module { |
| 227 | const m = owner.allocator.create(Module) catch @panic("OOM"); | 239 | const m = owner.allocator.create(Module) catch @panic("OOM"); |
| 228 | m.* = init(owner, options, null); | 240 | m.init(owner, options, null); |
| 229 | return m; | 241 | return m; |
| 230 | } | 242 | } |
| 231 | 243 | ||
| 232 | /// Adds an existing module to be used with `@import`. | 244 | /// Adds an existing module to be used with `@import`. |
| 233 | pub fn addImport(m: *Module, name: []const u8, module: *Module) void { | 245 | pub fn addImport(m: *Module, name: []const u8, module: *Module) void { |
| 234 | const b = m.owner; | 246 | const b = m.owner; |
| 235 | m.import_table.put(b.dupe(name), module) catch @panic("OOM"); | 247 | m.import_table.put(b.allocator, b.dupe(name), module) catch @panic("OOM"); |
| 236 | 248 | ||
| 237 | var it = module.iterateDependencies(null); | 249 | var it = module.iterateDependencies(null); |
| 238 | while (it.next()) |item| addShallowDependencies(m, item.module); | 250 | while (it.next()) |item| addShallowDependencies(m, item.module); |
| ... | @@ -244,7 +256,10 @@ pub fn addImport(m: *Module, name: []const u8, module: *Module) void { | ... | @@ -244,7 +256,10 @@ pub fn addImport(m: *Module, name: []const u8, module: *Module) void { |
| 244 | fn addShallowDependencies(m: *Module, dependee: *Module) void { | 256 | fn addShallowDependencies(m: *Module, dependee: *Module) void { |
| 245 | if (dependee.root_source_file) |lazy_path| addLazyPathDependencies(m, dependee, lazy_path); | 257 | if (dependee.root_source_file) |lazy_path| addLazyPathDependencies(m, dependee, lazy_path); |
| 246 | for (dependee.lib_paths.items) |lib_path| addLazyPathDependencies(m, dependee, lib_path); | 258 | for (dependee.lib_paths.items) |lib_path| addLazyPathDependencies(m, dependee, lib_path); |
| 247 | for (dependee.rpaths.items) |rpath| addLazyPathDependencies(m, dependee, rpath); | 259 | for (dependee.rpaths.items) |rpath| switch (rpath) { |
| 260 | .lazy_path => |lp| addLazyPathDependencies(m, dependee, lp), | ||
| 261 | .special => {}, | ||
| 262 | }; | ||
| 248 | 263 | ||
| 249 | for (dependee.link_objects.items) |link_object| switch (link_object) { | 264 | for (dependee.link_objects.items) |link_object| switch (link_object) { |
| 250 | .other_step => |compile| addStepDependencies(m, dependee, &compile.step), | 265 | .other_step => |compile| addStepDependencies(m, dependee, &compile.step), |
| ... | @@ -277,7 +292,7 @@ fn addLazyPathDependenciesOnly(m: *Module, lazy_path: LazyPath) void { | ... | @@ -277,7 +292,7 @@ fn addLazyPathDependenciesOnly(m: *Module, lazy_path: LazyPath) void { |
| 277 | } | 292 | } |
| 278 | } | 293 | } |
| 279 | 294 | ||
| 280 | fn addStepDependencies(m: *Module, module: *Module, dependee: *std.Build.Step) void { | 295 | fn addStepDependencies(m: *Module, module: *Module, dependee: *Step) void { |
| 281 | addStepDependenciesOnly(m, dependee); | 296 | addStepDependenciesOnly(m, dependee); |
| 282 | if (m != module) { | 297 | if (m != module) { |
| 283 | for (m.depending_steps.keys()) |compile| { | 298 | for (m.depending_steps.keys()) |compile| { |
| ... | @@ -286,20 +301,19 @@ fn addStepDependencies(m: *Module, module: *Module, dependee: *std.Build.Step) v | ... | @@ -286,20 +301,19 @@ fn addStepDependencies(m: *Module, module: *Module, dependee: *std.Build.Step) v |
| 286 | } | 301 | } |
| 287 | } | 302 | } |
| 288 | 303 | ||
| 289 | fn addStepDependenciesOnly(m: *Module, dependee: *std.Build.Step) void { | 304 | fn addStepDependenciesOnly(m: *Module, dependee: *Step) void { |
| 290 | for (m.depending_steps.keys()) |compile| { | 305 | for (m.depending_steps.keys()) |compile| { |
| 291 | compile.step.dependOn(dependee); | 306 | compile.step.dependOn(dependee); |
| 292 | } | 307 | } |
| 293 | } | 308 | } |
| 294 | 309 | ||
| 295 | /// Creates a new module and adds it to be used with `@import`. | 310 | /// Creates a new module and adds it to be used with `@import`. |
| 296 | pub fn addAnonymousImport(m: *Module, name: []const u8, options: std.Build.CreateModuleOptions) void { | 311 | pub fn addAnonymousImport(m: *Module, name: []const u8, options: CreateOptions) void { |
| 297 | const b = m.step.owner; | 312 | const module = create(m.owner, options); |
| 298 | const module = b.createModule(options); | ||
| 299 | return addImport(m, name, module); | 313 | return addImport(m, name, module); |
| 300 | } | 314 | } |
| 301 | 315 | ||
| 302 | pub fn addOptions(m: *Module, module_name: []const u8, options: *std.Build.Step.Options) void { | 316 | pub fn addOptions(m: *Module, module_name: []const u8, options: *Step.Options) void { |
| 303 | addImport(m, module_name, options.createModule()); | 317 | addImport(m, module_name, options.createModule()); |
| 304 | } | 318 | } |
| 305 | 319 | ||
| ... | @@ -311,14 +325,14 @@ pub const DependencyIterator = struct { | ... | @@ -311,14 +325,14 @@ pub const DependencyIterator = struct { |
| 311 | pub const Key = struct { | 325 | pub const Key = struct { |
| 312 | /// The compilation that contains the `Module`. Note that a `Module` might be | 326 | /// The compilation that contains the `Module`. Note that a `Module` might be |
| 313 | /// used by more than one compilation. | 327 | /// used by more than one compilation. |
| 314 | compile: ?*std.Build.Step.Compile, | 328 | compile: ?*Step.Compile, |
| 315 | module: *Module, | 329 | module: *Module, |
| 316 | }; | 330 | }; |
| 317 | 331 | ||
| 318 | pub const Item = struct { | 332 | pub const Item = struct { |
| 319 | /// The compilation that contains the `Module`. Note that a `Module` might be | 333 | /// The compilation that contains the `Module`. Note that a `Module` might be |
| 320 | /// used by more than one compilation. | 334 | /// used by more than one compilation. |
| 321 | compile: ?*std.Build.Step.Compile, | 335 | compile: ?*Step.Compile, |
| 322 | module: *Module, | 336 | module: *Module, |
| 323 | name: []const u8, | 337 | name: []const u8, |
| 324 | }; | 338 | }; |
| ... | @@ -368,7 +382,7 @@ pub const DependencyIterator = struct { | ... | @@ -368,7 +382,7 @@ pub const DependencyIterator = struct { |
| 368 | 382 | ||
| 369 | pub fn iterateDependencies( | 383 | pub fn iterateDependencies( |
| 370 | m: *Module, | 384 | m: *Module, |
| 371 | chase_steps: ?*std.Build.Step.Compile, | 385 | chase_steps: ?*Step.Compile, |
| 372 | ) DependencyIterator { | 386 | ) DependencyIterator { |
| 373 | var it: DependencyIterator = .{ | 387 | var it: DependencyIterator = .{ |
| 374 | .allocator = m.owner.allocator, | 388 | .allocator = m.owner.allocator, |
| ... | @@ -397,16 +411,18 @@ pub fn linkSystemLibrary( | ... | @@ -397,16 +411,18 @@ pub fn linkSystemLibrary( |
| 397 | options: LinkSystemLibraryOptions, | 411 | options: LinkSystemLibraryOptions, |
| 398 | ) void { | 412 | ) void { |
| 399 | const b = m.owner; | 413 | const b = m.owner; |
| 400 | if (m.target_info.target.is_libc_lib_name(name)) { | 414 | |
| 415 | const target = m.requireKnownTarget(); | ||
| 416 | if (target.is_libc_lib_name(name)) { | ||
| 401 | m.link_libc = true; | 417 | m.link_libc = true; |
| 402 | return; | 418 | return; |
| 403 | } | 419 | } |
| 404 | if (m.target_info.target.is_libcpp_lib_name(name)) { | 420 | if (target.is_libcpp_lib_name(name)) { |
| 405 | m.link_libcpp = true; | 421 | m.link_libcpp = true; |
| 406 | return; | 422 | return; |
| 407 | } | 423 | } |
| 408 | 424 | ||
| 409 | m.link_objects.append(.{ | 425 | m.link_objects.append(b.allocator, .{ |
| 410 | .system_lib = .{ | 426 | .system_lib = .{ |
| 411 | .name = b.dupe(name), | 427 | .name = b.dupe(name), |
| 412 | .needed = options.needed, | 428 | .needed = options.needed, |
| ... | @@ -418,6 +434,11 @@ pub fn linkSystemLibrary( | ... | @@ -418,6 +434,11 @@ pub fn linkSystemLibrary( |
| 418 | }) catch @panic("OOM"); | 434 | }) catch @panic("OOM"); |
| 419 | } | 435 | } |
| 420 | 436 | ||
| 437 | pub fn linkFramework(m: *Module, name: []const u8, options: LinkFrameworkOptions) void { | ||
| 438 | const b = m.owner; | ||
| 439 | m.frameworks.put(b.allocator, b.dupe(name), options) catch @panic("OOM"); | ||
| 440 | } | ||
| 441 | |||
| 421 | pub const AddCSourceFilesOptions = struct { | 442 | pub const AddCSourceFilesOptions = struct { |
| 422 | /// When provided, `files` are relative to `dependency` rather than the | 443 | /// When provided, `files` are relative to `dependency` rather than the |
| 423 | /// package that owns the `Compile` step. | 444 | /// package that owns the `Compile` step. |
| ... | @@ -428,19 +449,23 @@ pub const AddCSourceFilesOptions = struct { | ... | @@ -428,19 +449,23 @@ pub const AddCSourceFilesOptions = struct { |
| 428 | 449 | ||
| 429 | /// Handy when you have many C/C++ source files and want them all to have the same flags. | 450 | /// Handy when you have many C/C++ source files and want them all to have the same flags. |
| 430 | pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void { | 451 | pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void { |
| 431 | const c_source_files = m.owner.allocator.create(CSourceFiles) catch @panic("OOM"); | 452 | const b = m.owner; |
| 453 | const allocator = b.allocator; | ||
| 454 | const c_source_files = allocator.create(CSourceFiles) catch @panic("OOM"); | ||
| 432 | c_source_files.* = .{ | 455 | c_source_files.* = .{ |
| 433 | .dependency = options.dependency, | 456 | .dependency = options.dependency, |
| 434 | .files = m.owner.dupeStrings(options.files), | 457 | .files = b.dupeStrings(options.files), |
| 435 | .flags = m.owner.dupeStrings(options.flags), | 458 | .flags = b.dupeStrings(options.flags), |
| 436 | }; | 459 | }; |
| 437 | m.link_objects.append(.{ .c_source_files = c_source_files }) catch @panic("OOM"); | 460 | m.link_objects.append(allocator, .{ .c_source_files = c_source_files }) catch @panic("OOM"); |
| 438 | } | 461 | } |
| 439 | 462 | ||
| 440 | pub fn addCSourceFile(m: *Module, source: CSourceFile) void { | 463 | pub fn addCSourceFile(m: *Module, source: CSourceFile) void { |
| 441 | const c_source_file = m.owner.allocator.create(CSourceFile) catch @panic("OOM"); | 464 | const b = m.owner; |
| 442 | c_source_file.* = source.dupe(m.owner); | 465 | const allocator = b.allocator; |
| 443 | m.link_objects.append(.{ .c_source_file = c_source_file }) catch @panic("OOM"); | 466 | const c_source_file = allocator.create(CSourceFile) catch @panic("OOM"); |
| 467 | c_source_file.* = source.dupe(b); | ||
| 468 | m.link_objects.append(allocator, .{ .c_source_file = c_source_file }) catch @panic("OOM"); | ||
| 444 | addLazyPathDependenciesOnly(m, source.file); | 469 | addLazyPathDependenciesOnly(m, source.file); |
| 445 | } | 470 | } |
| 446 | 471 | ||
| ... | @@ -448,30 +473,122 @@ pub fn addCSourceFile(m: *Module, source: CSourceFile) void { | ... | @@ -448,30 +473,122 @@ pub fn addCSourceFile(m: *Module, source: CSourceFile) void { |
| 448 | /// Can be called regardless of target. The .rc file will be ignored | 473 | /// Can be called regardless of target. The .rc file will be ignored |
| 449 | /// if the target object format does not support embedded resources. | 474 | /// if the target object format does not support embedded resources. |
| 450 | pub fn addWin32ResourceFile(m: *Module, source: RcSourceFile) void { | 475 | pub fn addWin32ResourceFile(m: *Module, source: RcSourceFile) void { |
| 476 | const b = m.owner; | ||
| 477 | const allocator = b.allocator; | ||
| 478 | const target = m.requireKnownTarget(); | ||
| 451 | // Only the PE/COFF format has a Resource Table, so for any other target | 479 | // Only the PE/COFF format has a Resource Table, so for any other target |
| 452 | // the resource file is ignored. | 480 | // the resource file is ignored. |
| 453 | if (m.target_info.target.ofmt != .coff) return; | 481 | if (target.ofmt != .coff) return; |
| 454 | 482 | ||
| 455 | const rc_source_file = m.owner.allocator.create(RcSourceFile) catch @panic("OOM"); | 483 | const rc_source_file = allocator.create(RcSourceFile) catch @panic("OOM"); |
| 456 | rc_source_file.* = source.dupe(m.owner); | 484 | rc_source_file.* = source.dupe(b); |
| 457 | m.link_objects.append(.{ .win32_resource_file = rc_source_file }) catch @panic("OOM"); | 485 | m.link_objects.append(allocator, .{ .win32_resource_file = rc_source_file }) catch @panic("OOM"); |
| 458 | addLazyPathDependenciesOnly(m, source.file); | 486 | addLazyPathDependenciesOnly(m, source.file); |
| 459 | } | 487 | } |
| 460 | 488 | ||
| 461 | pub fn addAssemblyFile(m: *Module, source: LazyPath) void { | 489 | pub fn addAssemblyFile(m: *Module, source: LazyPath) void { |
| 462 | m.link_objects.append(.{ .assembly_file = source.dupe(m.owner) }) catch @panic("OOM"); | 490 | const b = m.owner; |
| 491 | m.link_objects.append(b.allocator, .{ .assembly_file = source.dupe(b) }) catch @panic("OOM"); | ||
| 463 | addLazyPathDependenciesOnly(m, source); | 492 | addLazyPathDependenciesOnly(m, source); |
| 464 | } | 493 | } |
| 465 | 494 | ||
| 466 | pub fn addObjectFile(m: *Module, source: LazyPath) void { | 495 | pub fn addObjectFile(m: *Module, object: LazyPath) void { |
| 467 | m.link_objects.append(.{ .static_path = source.dupe(m.owner) }) catch @panic("OOM"); | 496 | const b = m.owner; |
| 468 | addLazyPathDependencies(m, source); | 497 | m.link_objects.append(b.allocator, .{ .static_path = object.dupe(b) }) catch @panic("OOM"); |
| 498 | addLazyPathDependenciesOnly(m, object); | ||
| 499 | } | ||
| 500 | |||
| 501 | pub fn addObject(m: *Module, object: *Step.Compile) void { | ||
| 502 | assert(object.kind == .obj); | ||
| 503 | m.linkLibraryOrObject(object); | ||
| 504 | } | ||
| 505 | |||
| 506 | pub fn linkLibrary(m: *Module, library: *Step.Compile) void { | ||
| 507 | assert(library.kind == .lib); | ||
| 508 | m.linkLibraryOrObject(library); | ||
| 509 | } | ||
| 510 | |||
| 511 | pub fn addAfterIncludePath(m: *Module, lazy_path: LazyPath) void { | ||
| 512 | const b = m.owner; | ||
| 513 | m.include_dirs.append(b.allocator, .{ .path_after = lazy_path.dupe(b) }) catch @panic("OOM"); | ||
| 514 | addLazyPathDependenciesOnly(m, lazy_path); | ||
| 515 | } | ||
| 516 | |||
| 517 | pub fn addSystemIncludePath(m: *Module, lazy_path: LazyPath) void { | ||
| 518 | const b = m.owner; | ||
| 519 | m.include_dirs.append(b.allocator, .{ .path_system = lazy_path.dupe(b) }) catch @panic("OOM"); | ||
| 520 | addLazyPathDependenciesOnly(m, lazy_path); | ||
| 521 | } | ||
| 522 | |||
| 523 | pub fn addIncludePath(m: *Module, lazy_path: LazyPath) void { | ||
| 524 | const b = m.owner; | ||
| 525 | m.include_dirs.append(b.allocator, .{ .path = lazy_path.dupe(b) }) catch @panic("OOM"); | ||
| 526 | addLazyPathDependenciesOnly(m, lazy_path); | ||
| 527 | } | ||
| 528 | |||
| 529 | pub fn addConfigHeader(m: *Module, config_header: *Step.ConfigHeader) void { | ||
| 530 | const allocator = m.owner.allocator; | ||
| 531 | m.include_dirs.append(allocator, .{ .config_header_step = config_header }) catch @panic("OOM"); | ||
| 532 | addStepDependenciesOnly(m, &config_header.step); | ||
| 533 | } | ||
| 534 | |||
| 535 | pub fn addSystemFrameworkPath(m: *Module, directory_path: LazyPath) void { | ||
| 536 | const b = m.owner; | ||
| 537 | m.include_dirs.append(b.allocator, .{ .framework_path_system = directory_path.dupe(b) }) catch | ||
| 538 | @panic("OOM"); | ||
| 539 | addLazyPathDependenciesOnly(m, directory_path); | ||
| 540 | } | ||
| 541 | |||
| 542 | pub fn addFrameworkPath(m: *Module, directory_path: LazyPath) void { | ||
| 543 | const b = m.owner; | ||
| 544 | m.include_dirs.append(b.allocator, .{ .framework_path = directory_path.dupe(b) }) catch | ||
| 545 | @panic("OOM"); | ||
| 546 | addLazyPathDependenciesOnly(m, directory_path); | ||
| 547 | } | ||
| 548 | |||
| 549 | pub fn addLibraryPath(m: *Module, directory_path: LazyPath) void { | ||
| 550 | const b = m.owner; | ||
| 551 | m.lib_paths.append(b.allocator, directory_path.dupe(b)) catch @panic("OOM"); | ||
| 552 | addLazyPathDependenciesOnly(m, directory_path); | ||
| 553 | } | ||
| 554 | |||
| 555 | pub fn addRPath(m: *Module, directory_path: LazyPath) void { | ||
| 556 | const b = m.owner; | ||
| 557 | switch (directory_path) { | ||
| 558 | .path, .cwd_relative => |path| { | ||
| 559 | // TODO: remove this check after people upgrade and stop expecting it to work | ||
| 560 | if (std.mem.startsWith(u8, path, "@executable_path") or | ||
| 561 | std.mem.startsWith(u8, path, "@loader_path")) | ||
| 562 | { | ||
| 563 | @panic("this function is for adding directory paths. It does not support special rpaths. use addRPathSpecial for that."); | ||
| 564 | } | ||
| 565 | }, | ||
| 566 | else => {}, | ||
| 567 | } | ||
| 568 | m.rpaths.append(b.allocator, .{ .lazy_path = directory_path.dupe(b) }) catch @panic("OOM"); | ||
| 569 | addLazyPathDependenciesOnly(m, directory_path); | ||
| 570 | } | ||
| 571 | |||
| 572 | pub fn addRPathSpecial(m: *Module, bytes: []const u8) void { | ||
| 573 | const b = m.owner; | ||
| 574 | m.rpaths.append(b.allocator, .{ .special = b.dupe(bytes) }) catch @panic("OOM"); | ||
| 575 | } | ||
| 576 | |||
| 577 | /// Equvialent to the following C code, applied to all C source files owned by | ||
| 578 | /// this `Module`: | ||
| 579 | /// ```c | ||
| 580 | /// #define name value | ||
| 581 | /// ``` | ||
| 582 | /// `name` and `value` need not live longer than the function call. | ||
| 583 | pub fn addCMacro(m: *Module, name: []const u8, value: []const u8) void { | ||
| 584 | const b = m.owner; | ||
| 585 | m.c_macros.append(b.allocator, b.fmt("-D{s}={s}", .{ name, value })) catch @panic("OOM"); | ||
| 469 | } | 586 | } |
| 470 | 587 | ||
| 471 | pub fn appendZigProcessFlags( | 588 | pub fn appendZigProcessFlags( |
| 472 | m: *Module, | 589 | m: *Module, |
| 473 | zig_args: *std.ArrayList([]const u8), | 590 | zig_args: *std.ArrayList([]const u8), |
| 474 | asking_step: ?*std.Build.Step, | 591 | asking_step: ?*Step, |
| 475 | ) !void { | 592 | ) !void { |
| 476 | const b = m.owner; | 593 | const b = m.owner; |
| 477 | 594 | ||
| ... | @@ -495,27 +612,30 @@ pub fn appendZigProcessFlags( | ... | @@ -495,27 +612,30 @@ pub fn appendZigProcessFlags( |
| 495 | } | 612 | } |
| 496 | 613 | ||
| 497 | try zig_args.ensureUnusedCapacity(1); | 614 | try zig_args.ensureUnusedCapacity(1); |
| 498 | switch (m.optimize) { | 615 | if (m.optimize) |optimize| switch (optimize) { |
| 499 | .Debug => {}, // Skip since it's the default. | 616 | .Debug => zig_args.appendAssumeCapacity("-ODebug"), |
| 500 | .ReleaseSmall => zig_args.appendAssumeCapacity("-OReleaseSmall"), | 617 | .ReleaseSmall => zig_args.appendAssumeCapacity("-OReleaseSmall"), |
| 501 | .ReleaseFast => zig_args.appendAssumeCapacity("-OReleaseFast"), | 618 | .ReleaseFast => zig_args.appendAssumeCapacity("-OReleaseFast"), |
| 502 | .ReleaseSafe => zig_args.appendAssumeCapacity("-OReleaseSafe"), | 619 | .ReleaseSafe => zig_args.appendAssumeCapacity("-OReleaseSafe"), |
| 503 | } | 620 | }; |
| 504 | 621 | ||
| 505 | if (m.code_model != .default) { | 622 | if (m.code_model != .default) { |
| 506 | try zig_args.append("-mcmodel"); | 623 | try zig_args.append("-mcmodel"); |
| 507 | try zig_args.append(@tagName(m.code_model)); | 624 | try zig_args.append(@tagName(m.code_model)); |
| 508 | } | 625 | } |
| 509 | 626 | ||
| 510 | if (!m.target.isNative()) { | 627 | if (m.target) |target| { |
| 511 | try zig_args.appendSlice(&.{ | 628 | // Communicate the query via CLI since it's more compact. |
| 512 | "-target", try m.target.zigTriple(b.allocator), | 629 | if (!target.query.isNative()) { |
| 513 | "-mcpu", try std.Build.serializeCpu(b.allocator, m.target.getCpu()), | 630 | try zig_args.appendSlice(&.{ |
| 514 | }); | 631 | "-target", try target.query.zigTriple(b.allocator), |
| 515 | 632 | "-mcpu", try std.Build.serializeCpu(b.allocator, target.query.getCpu()), | |
| 516 | if (m.target.dynamic_linker.get()) |dynamic_linker| { | 633 | }); |
| 517 | try zig_args.append("--dynamic-linker"); | 634 | |
| 518 | try zig_args.append(dynamic_linker); | 635 | if (target.query.dynamic_linker.get()) |dynamic_linker| { |
| 636 | try zig_args.append("--dynamic-linker"); | ||
| 637 | try zig_args.append(dynamic_linker); | ||
| 638 | } | ||
| 519 | } | 639 | } |
| 520 | } | 640 | } |
| 521 | 641 | ||
| ... | @@ -565,10 +685,7 @@ pub fn appendZigProcessFlags( | ... | @@ -565,10 +685,7 @@ pub fn appendZigProcessFlags( |
| 565 | } | 685 | } |
| 566 | } | 686 | } |
| 567 | 687 | ||
| 568 | for (m.c_macros.items) |c_macro| { | 688 | try zig_args.appendSlice(m.c_macros.items); |
| 569 | try zig_args.append("-D"); | ||
| 570 | try zig_args.append(c_macro); | ||
| 571 | } | ||
| 572 | 689 | ||
| 573 | try zig_args.ensureUnusedCapacity(2 * m.lib_paths.items.len); | 690 | try zig_args.ensureUnusedCapacity(2 * m.lib_paths.items.len); |
| 574 | for (m.lib_paths.items) |lib_path| { | 691 | for (m.lib_paths.items) |lib_path| { |
| ... | @@ -577,26 +694,16 @@ pub fn appendZigProcessFlags( | ... | @@ -577,26 +694,16 @@ pub fn appendZigProcessFlags( |
| 577 | } | 694 | } |
| 578 | 695 | ||
| 579 | try zig_args.ensureUnusedCapacity(2 * m.rpaths.items.len); | 696 | try zig_args.ensureUnusedCapacity(2 * m.rpaths.items.len); |
| 580 | for (m.rpaths.items) |rpath| { | 697 | for (m.rpaths.items) |rpath| switch (rpath) { |
| 581 | zig_args.appendAssumeCapacity("-rpath"); | 698 | .lazy_path => |lp| { |
| 582 | 699 | zig_args.appendAssumeCapacity("-rpath"); | |
| 583 | if (m.target_info.target.isDarwin()) switch (rpath) { | 700 | zig_args.appendAssumeCapacity(lp.getPath2(b, asking_step)); |
| 584 | .path, .cwd_relative => |path| { | 701 | }, |
| 585 | // On Darwin, we should not try to expand special runtime paths such as | 702 | .special => |bytes| { |
| 586 | // * @executable_path | 703 | zig_args.appendAssumeCapacity("-rpath"); |
| 587 | // * @loader_path | 704 | zig_args.appendAssumeCapacity(bytes); |
| 588 | if (std.mem.startsWith(u8, path, "@executable_path") or | 705 | }, |
| 589 | std.mem.startsWith(u8, path, "@loader_path")) | 706 | }; |
| 590 | { | ||
| 591 | zig_args.appendAssumeCapacity(path); | ||
| 592 | continue; | ||
| 593 | } | ||
| 594 | }, | ||
| 595 | .generated, .dependency => {}, | ||
| 596 | }; | ||
| 597 | |||
| 598 | zig_args.appendAssumeCapacity(rpath.getPath2(b, asking_step)); | ||
| 599 | } | ||
| 600 | } | 707 | } |
| 601 | 708 | ||
| 602 | fn addFlag( | 709 | fn addFlag( |
| ... | @@ -609,8 +716,32 @@ fn addFlag( | ... | @@ -609,8 +716,32 @@ fn addFlag( |
| 609 | return args.append(if (cond) then_name else else_name); | 716 | return args.append(if (cond) then_name else else_name); |
| 610 | } | 717 | } |
| 611 | 718 | ||
| 719 | fn linkLibraryOrObject(m: *Module, other: *Step.Compile) void { | ||
| 720 | const allocator = m.owner.allocator; | ||
| 721 | _ = other.getEmittedBin(); // Indicate there is a dependency on the outputted binary. | ||
| 722 | addStepDependenciesOnly(m, &other.step); | ||
| 723 | |||
| 724 | if (other.rootModuleTarget().os.tag == .windows and other.isDynamicLibrary()) { | ||
| 725 | _ = other.getEmittedImplib(); // Indicate dependency on the outputted implib. | ||
| 726 | } | ||
| 727 | |||
| 728 | m.link_objects.append(allocator, .{ .other_step = other }) catch @panic("OOM"); | ||
| 729 | m.include_dirs.append(allocator, .{ .other_step = other }) catch @panic("OOM"); | ||
| 730 | |||
| 731 | for (other.installed_headers.items) |install_step| { | ||
| 732 | addStepDependenciesOnly(m, install_step); | ||
| 733 | } | ||
| 734 | } | ||
| 735 | |||
| 736 | fn requireKnownTarget(m: *Module) std.Target { | ||
| 737 | const resolved_target = m.target orelse | ||
| 738 | @panic("this API requires the Module to be created with a known 'target' field"); | ||
| 739 | return resolved_target.target; | ||
| 740 | } | ||
| 741 | |||
| 612 | const Module = @This(); | 742 | const Module = @This(); |
| 613 | const std = @import("std"); | 743 | const std = @import("std"); |
| 614 | const assert = std.debug.assert; | 744 | const assert = std.debug.assert; |
| 615 | const LazyPath = std.Build.LazyPath; | 745 | const LazyPath = std.Build.LazyPath; |
| 616 | const NativeTargetInfo = std.zig.system.NativeTargetInfo; | 746 | const NativeTargetInfo = std.zig.system.NativeTargetInfo; |
| 747 | const Step = std.Build.Step; |
lib/std/Build/Step/CheckObject.zig+26-22| ... | @@ -44,11 +44,11 @@ pub fn create( | ... | @@ -44,11 +44,11 @@ pub fn create( |
| 44 | 44 | ||
| 45 | const SearchPhrase = struct { | 45 | const SearchPhrase = struct { |
| 46 | string: []const u8, | 46 | string: []const u8, |
| 47 | file_source: ?std.Build.LazyPath = null, | 47 | lazy_path: ?std.Build.LazyPath = null, |
| 48 | 48 | ||
| 49 | fn resolve(phrase: SearchPhrase, b: *std.Build, step: *Step) []const u8 { | 49 | fn resolve(phrase: SearchPhrase, b: *std.Build, step: *Step) []const u8 { |
| 50 | const file_source = phrase.file_source orelse return phrase.string; | 50 | const lazy_path = phrase.lazy_path orelse return phrase.string; |
| 51 | return b.fmt("{s} {s}", .{ phrase.string, file_source.getPath2(b, step) }); | 51 | return b.fmt("{s} {s}", .{ phrase.string, lazy_path.getPath2(b, step) }); |
| 52 | } | 52 | } |
| 53 | }; | 53 | }; |
| 54 | 54 | ||
| ... | @@ -321,14 +321,14 @@ pub fn checkExact(self: *CheckObject, phrase: []const u8) void { | ... | @@ -321,14 +321,14 @@ pub fn checkExact(self: *CheckObject, phrase: []const u8) void { |
| 321 | 321 | ||
| 322 | /// Like `checkExact()` but takes an additional argument `LazyPath` which will be | 322 | /// Like `checkExact()` but takes an additional argument `LazyPath` which will be |
| 323 | /// resolved to a full search query in `make()`. | 323 | /// resolved to a full search query in `make()`. |
| 324 | pub fn checkExactPath(self: *CheckObject, phrase: []const u8, file_source: std.Build.LazyPath) void { | 324 | pub fn checkExactPath(self: *CheckObject, phrase: []const u8, lazy_path: std.Build.LazyPath) void { |
| 325 | self.checkExactInner(phrase, file_source); | 325 | self.checkExactInner(phrase, lazy_path); |
| 326 | } | 326 | } |
| 327 | 327 | ||
| 328 | fn checkExactInner(self: *CheckObject, phrase: []const u8, file_source: ?std.Build.LazyPath) void { | 328 | fn checkExactInner(self: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { |
| 329 | assert(self.checks.items.len > 0); | 329 | assert(self.checks.items.len > 0); |
| 330 | const last = &self.checks.items[self.checks.items.len - 1]; | 330 | const last = &self.checks.items[self.checks.items.len - 1]; |
| 331 | last.exact(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source }); | 331 | last.exact(.{ .string = self.step.owner.dupe(phrase), .lazy_path = lazy_path }); |
| 332 | } | 332 | } |
| 333 | 333 | ||
| 334 | /// Adds a fuzzy match phrase to the latest created Check. | 334 | /// Adds a fuzzy match phrase to the latest created Check. |
| ... | @@ -336,16 +336,20 @@ pub fn checkContains(self: *CheckObject, phrase: []const u8) void { | ... | @@ -336,16 +336,20 @@ pub fn checkContains(self: *CheckObject, phrase: []const u8) void { |
| 336 | self.checkContainsInner(phrase, null); | 336 | self.checkContainsInner(phrase, null); |
| 337 | } | 337 | } |
| 338 | 338 | ||
| 339 | /// Like `checkContains()` but takes an additional argument `FileSource` which will be | 339 | /// Like `checkContains()` but takes an additional argument `lazy_path` which will be |
| 340 | /// resolved to a full search query in `make()`. | 340 | /// resolved to a full search query in `make()`. |
| 341 | pub fn checkContainsPath(self: *CheckObject, phrase: []const u8, file_source: std.Build.LazyPath) void { | 341 | pub fn checkContainsPath( |
| 342 | self.checkContainsInner(phrase, file_source); | 342 | self: *CheckObject, |
| 343 | phrase: []const u8, | ||
| 344 | lazy_path: std.Build.LazyPath, | ||
| 345 | ) void { | ||
| 346 | self.checkContainsInner(phrase, lazy_path); | ||
| 343 | } | 347 | } |
| 344 | 348 | ||
| 345 | fn checkContainsInner(self: *CheckObject, phrase: []const u8, file_source: ?std.Build.FileSource) void { | 349 | fn checkContainsInner(self: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { |
| 346 | assert(self.checks.items.len > 0); | 350 | assert(self.checks.items.len > 0); |
| 347 | const last = &self.checks.items[self.checks.items.len - 1]; | 351 | const last = &self.checks.items[self.checks.items.len - 1]; |
| 348 | last.contains(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source }); | 352 | last.contains(.{ .string = self.step.owner.dupe(phrase), .lazy_path = lazy_path }); |
| 349 | } | 353 | } |
| 350 | 354 | ||
| 351 | /// Adds an exact match phrase with variable extractor to the latest created Check. | 355 | /// Adds an exact match phrase with variable extractor to the latest created Check. |
| ... | @@ -353,16 +357,16 @@ pub fn checkExtract(self: *CheckObject, phrase: []const u8) void { | ... | @@ -353,16 +357,16 @@ pub fn checkExtract(self: *CheckObject, phrase: []const u8) void { |
| 353 | self.checkExtractInner(phrase, null); | 357 | self.checkExtractInner(phrase, null); |
| 354 | } | 358 | } |
| 355 | 359 | ||
| 356 | /// Like `checkExtract()` but takes an additional argument `FileSource` which will be | 360 | /// Like `checkExtract()` but takes an additional argument `LazyPath` which will be |
| 357 | /// resolved to a full search query in `make()`. | 361 | /// resolved to a full search query in `make()`. |
| 358 | pub fn checkExtractFileSource(self: *CheckObject, phrase: []const u8, file_source: std.Build.FileSource) void { | 362 | pub fn checkExtractLazyPath(self: *CheckObject, phrase: []const u8, lazy_path: std.Build.LazyPath) void { |
| 359 | self.checkExtractInner(phrase, file_source); | 363 | self.checkExtractInner(phrase, lazy_path); |
| 360 | } | 364 | } |
| 361 | 365 | ||
| 362 | fn checkExtractInner(self: *CheckObject, phrase: []const u8, file_source: ?std.Build.FileSource) void { | 366 | fn checkExtractInner(self: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { |
| 363 | assert(self.checks.items.len > 0); | 367 | assert(self.checks.items.len > 0); |
| 364 | const last = &self.checks.items[self.checks.items.len - 1]; | 368 | const last = &self.checks.items[self.checks.items.len - 1]; |
| 365 | last.extract(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source }); | 369 | last.extract(.{ .string = self.step.owner.dupe(phrase), .lazy_path = lazy_path }); |
| 366 | } | 370 | } |
| 367 | 371 | ||
| 368 | /// Adds another searched phrase to the latest created Check | 372 | /// Adds another searched phrase to the latest created Check |
| ... | @@ -371,16 +375,16 @@ pub fn checkNotPresent(self: *CheckObject, phrase: []const u8) void { | ... | @@ -371,16 +375,16 @@ pub fn checkNotPresent(self: *CheckObject, phrase: []const u8) void { |
| 371 | self.checkNotPresentInner(phrase, null); | 375 | self.checkNotPresentInner(phrase, null); |
| 372 | } | 376 | } |
| 373 | 377 | ||
| 374 | /// Like `checkExtract()` but takes an additional argument `FileSource` which will be | 378 | /// Like `checkExtract()` but takes an additional argument `LazyPath` which will be |
| 375 | /// resolved to a full search query in `make()`. | 379 | /// resolved to a full search query in `make()`. |
| 376 | pub fn checkNotPresentFileSource(self: *CheckObject, phrase: []const u8, file_source: std.Build.FileSource) void { | 380 | pub fn checkNotPresentLazyPath(self: *CheckObject, phrase: []const u8, lazy_path: std.Build.LazyPath) void { |
| 377 | self.checkNotPresentInner(phrase, file_source); | 381 | self.checkNotPresentInner(phrase, lazy_path); |
| 378 | } | 382 | } |
| 379 | 383 | ||
| 380 | fn checkNotPresentInner(self: *CheckObject, phrase: []const u8, file_source: ?std.Build.FileSource) void { | 384 | fn checkNotPresentInner(self: *CheckObject, phrase: []const u8, lazy_path: ?std.Build.LazyPath) void { |
| 381 | assert(self.checks.items.len > 0); | 385 | assert(self.checks.items.len > 0); |
| 382 | const last = &self.checks.items[self.checks.items.len - 1]; | 386 | const last = &self.checks.items[self.checks.items.len - 1]; |
| 383 | last.notPresent(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source }); | 387 | last.notPresent(.{ .string = self.step.owner.dupe(phrase), .lazy_path = lazy_path }); |
| 384 | } | 388 | } |
| 385 | 389 | ||
| 386 | /// Creates a new check checking in the file headers (section, program headers, etc.). | 390 | /// Creates a new check checking in the file headers (section, program headers, etc.). |
lib/std/Build/Step/Compile.zig+81-203| ... | @@ -88,7 +88,7 @@ each_lib_rpath: ?bool = null, | ... | @@ -88,7 +88,7 @@ each_lib_rpath: ?bool = null, |
| 88 | /// As an example, the bloaty project refuses to work unless its inputs have | 88 | /// As an example, the bloaty project refuses to work unless its inputs have |
| 89 | /// build ids, in order to prevent accidental mismatches. | 89 | /// build ids, in order to prevent accidental mismatches. |
| 90 | /// The default is to not include this section because it slows down linking. | 90 | /// The default is to not include this section because it slows down linking. |
| 91 | build_id: ?BuildId = null, | 91 | build_id: ?std.zig.BuildId = null, |
| 92 | 92 | ||
| 93 | /// Create a .eh_frame_hdr section and a PT_GNU_EH_FRAME segment in the ELF | 93 | /// Create a .eh_frame_hdr section and a PT_GNU_EH_FRAME segment in the ELF |
| 94 | /// file. | 94 | /// file. |
| ... | @@ -200,7 +200,7 @@ pub const ExpectedCompileErrors = union(enum) { | ... | @@ -200,7 +200,7 @@ pub const ExpectedCompileErrors = union(enum) { |
| 200 | exact: []const []const u8, | 200 | exact: []const []const u8, |
| 201 | }; | 201 | }; |
| 202 | 202 | ||
| 203 | const Entry = union(enum) { | 203 | pub const Entry = union(enum) { |
| 204 | /// Let the compiler decide whether to make an entry point and what to name | 204 | /// Let the compiler decide whether to make an entry point and what to name |
| 205 | /// it. | 205 | /// it. |
| 206 | default, | 206 | default, |
| ... | @@ -232,82 +232,6 @@ pub const Options = struct { | ... | @@ -232,82 +232,6 @@ pub const Options = struct { |
| 232 | win32_manifest: ?LazyPath = null, | 232 | win32_manifest: ?LazyPath = null, |
| 233 | }; | 233 | }; |
| 234 | 234 | ||
| 235 | pub const BuildId = union(enum) { | ||
| 236 | none, | ||
| 237 | fast, | ||
| 238 | uuid, | ||
| 239 | sha1, | ||
| 240 | md5, | ||
| 241 | hexstring: HexString, | ||
| 242 | |||
| 243 | pub fn eql(a: BuildId, b: BuildId) bool { | ||
| 244 | const a_tag = std.meta.activeTag(a); | ||
| 245 | const b_tag = std.meta.activeTag(b); | ||
| 246 | if (a_tag != b_tag) return false; | ||
| 247 | return switch (a) { | ||
| 248 | .none, .fast, .uuid, .sha1, .md5 => true, | ||
| 249 | .hexstring => |a_hexstring| mem.eql(u8, a_hexstring.toSlice(), b.hexstring.toSlice()), | ||
| 250 | }; | ||
| 251 | } | ||
| 252 | |||
| 253 | pub const HexString = struct { | ||
| 254 | bytes: [32]u8, | ||
| 255 | len: u8, | ||
| 256 | |||
| 257 | /// Result is byte values, *not* hex-encoded. | ||
| 258 | pub fn toSlice(hs: *const HexString) []const u8 { | ||
| 259 | return hs.bytes[0..hs.len]; | ||
| 260 | } | ||
| 261 | }; | ||
| 262 | |||
| 263 | /// Input is byte values, *not* hex-encoded. | ||
| 264 | /// Asserts `bytes` fits inside `HexString` | ||
| 265 | pub fn initHexString(bytes: []const u8) BuildId { | ||
| 266 | var result: BuildId = .{ .hexstring = .{ | ||
| 267 | .bytes = undefined, | ||
| 268 | .len = @as(u8, @intCast(bytes.len)), | ||
| 269 | } }; | ||
| 270 | @memcpy(result.hexstring.bytes[0..bytes.len], bytes); | ||
| 271 | return result; | ||
| 272 | } | ||
| 273 | |||
| 274 | /// Converts UTF-8 text to a `BuildId`. | ||
| 275 | pub fn parse(text: []const u8) !BuildId { | ||
| 276 | if (mem.eql(u8, text, "none")) { | ||
| 277 | return .none; | ||
| 278 | } else if (mem.eql(u8, text, "fast")) { | ||
| 279 | return .fast; | ||
| 280 | } else if (mem.eql(u8, text, "uuid")) { | ||
| 281 | return .uuid; | ||
| 282 | } else if (mem.eql(u8, text, "sha1") or mem.eql(u8, text, "tree")) { | ||
| 283 | return .sha1; | ||
| 284 | } else if (mem.eql(u8, text, "md5")) { | ||
| 285 | return .md5; | ||
| 286 | } else if (mem.startsWith(u8, text, "0x")) { | ||
| 287 | var result: BuildId = .{ .hexstring = undefined }; | ||
| 288 | const slice = try std.fmt.hexToBytes(&result.hexstring.bytes, text[2..]); | ||
| 289 | result.hexstring.len = @as(u8, @intCast(slice.len)); | ||
| 290 | return result; | ||
| 291 | } | ||
| 292 | return error.InvalidBuildIdStyle; | ||
| 293 | } | ||
| 294 | |||
| 295 | test parse { | ||
| 296 | try std.testing.expectEqual(BuildId.md5, try parse("md5")); | ||
| 297 | try std.testing.expectEqual(BuildId.none, try parse("none")); | ||
| 298 | try std.testing.expectEqual(BuildId.fast, try parse("fast")); | ||
| 299 | try std.testing.expectEqual(BuildId.uuid, try parse("uuid")); | ||
| 300 | try std.testing.expectEqual(BuildId.sha1, try parse("sha1")); | ||
| 301 | try std.testing.expectEqual(BuildId.sha1, try parse("tree")); | ||
| 302 | |||
| 303 | try std.testing.expect(BuildId.initHexString("").eql(try parse("0x"))); | ||
| 304 | try std.testing.expect(BuildId.initHexString("\x12\x34\x56").eql(try parse("0x123456"))); | ||
| 305 | try std.testing.expectError(error.InvalidLength, parse("0x12-34")); | ||
| 306 | try std.testing.expectError(error.InvalidCharacter, parse("0xfoobbb")); | ||
| 307 | try std.testing.expectError(error.InvalidBuildIdStyle, parse("yaddaxxx")); | ||
| 308 | } | ||
| 309 | }; | ||
| 310 | |||
| 311 | pub const Kind = enum { | 235 | pub const Kind = enum { |
| 312 | exe, | 236 | exe, |
| 313 | lib, | 237 | lib, |
| ... | @@ -329,6 +253,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -329,6 +253,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 329 | else | 253 | else |
| 330 | owner.fmt("{s} ", .{name}); | 254 | owner.fmt("{s} ", .{name}); |
| 331 | 255 | ||
| 256 | const target = options.root_module.target.?.target; | ||
| 257 | |||
| 332 | const step_name = owner.fmt("{s} {s}{s} {s}", .{ | 258 | const step_name = owner.fmt("{s} {s}{s} {s}", .{ |
| 333 | switch (options.kind) { | 259 | switch (options.kind) { |
| 334 | .exe => "zig build-exe", | 260 | .exe => "zig build-exe", |
| ... | @@ -337,16 +263,13 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -337,16 +263,13 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 337 | .@"test" => "zig test", | 263 | .@"test" => "zig test", |
| 338 | }, | 264 | }, |
| 339 | name_adjusted, | 265 | name_adjusted, |
| 340 | @tagName(options.root_module.optimize), | 266 | @tagName(options.root_module.optimize orelse .Debug), |
| 341 | options.root_module.target.zigTriple(owner.allocator) catch @panic("OOM"), | 267 | target.zigTriple(owner.allocator) catch @panic("OOM"), |
| 342 | }); | 268 | }); |
| 343 | 269 | ||
| 344 | const target_info = NativeTargetInfo.detect(options.root_module.target) catch | ||
| 345 | @panic("unhandled error"); | ||
| 346 | |||
| 347 | const out_filename = std.zig.binNameAlloc(owner.allocator, .{ | 270 | const out_filename = std.zig.binNameAlloc(owner.allocator, .{ |
| 348 | .root_name = name, | 271 | .root_name = name, |
| 349 | .target = target_info.target, | 272 | .target = target, |
| 350 | .output_mode = switch (options.kind) { | 273 | .output_mode = switch (options.kind) { |
| 351 | .lib => .Lib, | 274 | .lib => .Lib, |
| 352 | .obj => .Obj, | 275 | .obj => .Obj, |
| ... | @@ -361,7 +284,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -361,7 +284,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 361 | 284 | ||
| 362 | const self = owner.allocator.create(Compile) catch @panic("OOM"); | 285 | const self = owner.allocator.create(Compile) catch @panic("OOM"); |
| 363 | self.* = .{ | 286 | self.* = .{ |
| 364 | .root_module = Module.init(owner, options.root_module, self), | 287 | .root_module = undefined, |
| 365 | .verbose_link = false, | 288 | .verbose_link = false, |
| 366 | .verbose_cc = false, | 289 | .verbose_cc = false, |
| 367 | .linkage = options.linkage, | 290 | .linkage = options.linkage, |
| ... | @@ -403,6 +326,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -403,6 +326,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 403 | .use_lld = options.use_lld, | 326 | .use_lld = options.use_lld, |
| 404 | }; | 327 | }; |
| 405 | 328 | ||
| 329 | self.root_module.init(owner, options.root_module, self); | ||
| 330 | |||
| 406 | if (options.zig_lib_dir) |lp| { | 331 | if (options.zig_lib_dir) |lp| { |
| 407 | self.zig_lib_dir = lp.dupe(self.step.owner); | 332 | self.zig_lib_dir = lp.dupe(self.step.owner); |
| 408 | lp.addStepDependencies(&self.step); | 333 | lp.addStepDependencies(&self.step); |
| ... | @@ -410,7 +335,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -410,7 +335,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 410 | 335 | ||
| 411 | // Only the PE/COFF format has a Resource Table which is where the manifest | 336 | // Only the PE/COFF format has a Resource Table which is where the manifest |
| 412 | // gets embedded, so for any other target the manifest file is just ignored. | 337 | // gets embedded, so for any other target the manifest file is just ignored. |
| 413 | if (target_info.target.ofmt == .coff) { | 338 | if (target.ofmt == .coff) { |
| 414 | if (options.win32_manifest) |lp| { | 339 | if (options.win32_manifest) |lp| { |
| 415 | self.win32_manifest = lp.dupe(self.step.owner); | 340 | self.win32_manifest = lp.dupe(self.step.owner); |
| 416 | lp.addStepDependencies(&self.step); | 341 | lp.addStepDependencies(&self.step); |
| ... | @@ -421,14 +346,14 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -421,14 +346,14 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 421 | if (self.linkage != null and self.linkage.? == .static) { | 346 | if (self.linkage != null and self.linkage.? == .static) { |
| 422 | self.out_lib_filename = self.out_filename; | 347 | self.out_lib_filename = self.out_filename; |
| 423 | } else if (self.version) |version| { | 348 | } else if (self.version) |version| { |
| 424 | if (target_info.target.isDarwin()) { | 349 | if (target.isDarwin()) { |
| 425 | self.major_only_filename = owner.fmt("lib{s}.{d}.dylib", .{ | 350 | self.major_only_filename = owner.fmt("lib{s}.{d}.dylib", .{ |
| 426 | self.name, | 351 | self.name, |
| 427 | version.major, | 352 | version.major, |
| 428 | }); | 353 | }); |
| 429 | self.name_only_filename = owner.fmt("lib{s}.dylib", .{self.name}); | 354 | self.name_only_filename = owner.fmt("lib{s}.dylib", .{self.name}); |
| 430 | self.out_lib_filename = self.out_filename; | 355 | self.out_lib_filename = self.out_filename; |
| 431 | } else if (target_info.target.os.tag == .windows) { | 356 | } else if (target.os.tag == .windows) { |
| 432 | self.out_lib_filename = owner.fmt("{s}.lib", .{self.name}); | 357 | self.out_lib_filename = owner.fmt("{s}.lib", .{self.name}); |
| 433 | } else { | 358 | } else { |
| 434 | self.major_only_filename = owner.fmt("lib{s}.so.{d}", .{ self.name, version.major }); | 359 | self.major_only_filename = owner.fmt("lib{s}.so.{d}", .{ self.name, version.major }); |
| ... | @@ -436,9 +361,9 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -436,9 +361,9 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 436 | self.out_lib_filename = self.out_filename; | 361 | self.out_lib_filename = self.out_filename; |
| 437 | } | 362 | } |
| 438 | } else { | 363 | } else { |
| 439 | if (target_info.target.isDarwin()) { | 364 | if (target.isDarwin()) { |
| 440 | self.out_lib_filename = self.out_filename; | 365 | self.out_lib_filename = self.out_filename; |
| 441 | } else if (target_info.target.os.tag == .windows) { | 366 | } else if (target.os.tag == .windows) { |
| 442 | self.out_lib_filename = owner.fmt("{s}.lib", .{self.name}); | 367 | self.out_lib_filename = owner.fmt("{s}.lib", .{self.name}); |
| 443 | } else { | 368 | } else { |
| 444 | self.out_lib_filename = self.out_filename; | 369 | self.out_lib_filename = self.out_filename; |
| ... | @@ -545,7 +470,7 @@ pub const run = @compileError("deprecated; use std.Build.addRunArtifact"); | ... | @@ -545,7 +470,7 @@ pub const run = @compileError("deprecated; use std.Build.addRunArtifact"); |
| 545 | pub const install = @compileError("deprecated; use std.Build.installArtifact"); | 470 | pub const install = @compileError("deprecated; use std.Build.installArtifact"); |
| 546 | 471 | ||
| 547 | pub fn checkObject(self: *Compile) *Step.CheckObject { | 472 | pub fn checkObject(self: *Compile) *Step.CheckObject { |
| 548 | return Step.CheckObject.create(self.step.owner, self.getEmittedBin(), self.target_info.target.ofmt); | 473 | return Step.CheckObject.create(self.step.owner, self.getEmittedBin(), self.rootModuleTarget().ofmt); |
| 549 | } | 474 | } |
| 550 | 475 | ||
| 551 | /// deprecated: use `setLinkerScript` | 476 | /// deprecated: use `setLinkerScript` |
| ... | @@ -562,25 +487,6 @@ pub fn forceUndefinedSymbol(self: *Compile, symbol_name: []const u8) void { | ... | @@ -562,25 +487,6 @@ pub fn forceUndefinedSymbol(self: *Compile, symbol_name: []const u8) void { |
| 562 | self.force_undefined_symbols.put(b.dupe(symbol_name), {}) catch @panic("OOM"); | 487 | self.force_undefined_symbols.put(b.dupe(symbol_name), {}) catch @panic("OOM"); |
| 563 | } | 488 | } |
| 564 | 489 | ||
| 565 | pub fn linkFramework(self: *Compile, framework_name: []const u8) void { | ||
| 566 | const b = self.step.owner; | ||
| 567 | self.frameworks.put(b.dupe(framework_name), .{}) catch @panic("OOM"); | ||
| 568 | } | ||
| 569 | |||
| 570 | pub fn linkFrameworkNeeded(self: *Compile, framework_name: []const u8) void { | ||
| 571 | const b = self.step.owner; | ||
| 572 | self.frameworks.put(b.dupe(framework_name), .{ | ||
| 573 | .needed = true, | ||
| 574 | }) catch @panic("OOM"); | ||
| 575 | } | ||
| 576 | |||
| 577 | pub fn linkFrameworkWeak(self: *Compile, framework_name: []const u8) void { | ||
| 578 | const b = self.step.owner; | ||
| 579 | self.frameworks.put(b.dupe(framework_name), .{ | ||
| 580 | .weak = true, | ||
| 581 | }) catch @panic("OOM"); | ||
| 582 | } | ||
| 583 | |||
| 584 | /// Returns whether the library, executable, or object depends on a particular system library. | 490 | /// Returns whether the library, executable, or object depends on a particular system library. |
| 585 | pub fn dependsOnSystemLibrary(self: *const Compile, name: []const u8) bool { | 491 | pub fn dependsOnSystemLibrary(self: *const Compile, name: []const u8) bool { |
| 586 | var is_linking_libc = false; | 492 | var is_linking_libc = false; |
| ... | @@ -598,22 +504,17 @@ pub fn dependsOnSystemLibrary(self: *const Compile, name: []const u8) bool { | ... | @@ -598,22 +504,17 @@ pub fn dependsOnSystemLibrary(self: *const Compile, name: []const u8) bool { |
| 598 | is_linking_libcpp = is_linking_libcpp or module.link_libcpp == true; | 504 | is_linking_libcpp = is_linking_libcpp or module.link_libcpp == true; |
| 599 | } | 505 | } |
| 600 | 506 | ||
| 601 | if (self.root_module.target_info.target.is_libc_lib_name(name)) { | 507 | if (self.rootModuleTarget().is_libc_lib_name(name)) { |
| 602 | return is_linking_libc; | 508 | return is_linking_libc; |
| 603 | } | 509 | } |
| 604 | 510 | ||
| 605 | if (self.root_module.target_info.target.is_libcpp_lib_name(name)) { | 511 | if (self.rootModuleTarget().is_libcpp_lib_name(name)) { |
| 606 | return is_linking_libcpp; | 512 | return is_linking_libcpp; |
| 607 | } | 513 | } |
| 608 | 514 | ||
| 609 | return false; | 515 | return false; |
| 610 | } | 516 | } |
| 611 | 517 | ||
| 612 | pub fn linkLibrary(self: *Compile, lib: *Compile) void { | ||
| 613 | assert(lib.kind == .lib); | ||
| 614 | self.linkLibraryOrObject(lib); | ||
| 615 | } | ||
| 616 | |||
| 617 | pub fn isDynamicLibrary(self: *const Compile) bool { | 518 | pub fn isDynamicLibrary(self: *const Compile) bool { |
| 618 | return self.kind == .lib and self.linkage == Linkage.dynamic; | 519 | return self.kind == .lib and self.linkage == Linkage.dynamic; |
| 619 | } | 520 | } |
| ... | @@ -623,16 +524,24 @@ pub fn isStaticLibrary(self: *const Compile) bool { | ... | @@ -623,16 +524,24 @@ pub fn isStaticLibrary(self: *const Compile) bool { |
| 623 | } | 524 | } |
| 624 | 525 | ||
| 625 | pub fn producesPdbFile(self: *Compile) bool { | 526 | pub fn producesPdbFile(self: *Compile) bool { |
| 527 | const target = self.rootModuleTarget(); | ||
| 626 | // TODO: Is this right? Isn't PDB for *any* PE/COFF file? | 528 | // TODO: Is this right? Isn't PDB for *any* PE/COFF file? |
| 627 | // TODO: just share this logic with the compiler, silly! | 529 | // TODO: just share this logic with the compiler, silly! |
| 628 | if (!self.target.isWindows() and !self.target.isUefi()) return false; | 530 | switch (target.os.tag) { |
| 629 | if (self.target.getObjectFormat() == .c) return false; | 531 | .windows, .uefi => {}, |
| 630 | if (self.strip == true or (self.strip == null and self.optimize == .ReleaseSmall)) return false; | 532 | else => return false, |
| 533 | } | ||
| 534 | if (target.ofmt == .c) return false; | ||
| 535 | if (self.root_module.strip == true or | ||
| 536 | (self.root_module.strip == null and self.root_module.optimize == .ReleaseSmall)) | ||
| 537 | { | ||
| 538 | return false; | ||
| 539 | } | ||
| 631 | return self.isDynamicLibrary() or self.kind == .exe or self.kind == .@"test"; | 540 | return self.isDynamicLibrary() or self.kind == .exe or self.kind == .@"test"; |
| 632 | } | 541 | } |
| 633 | 542 | ||
| 634 | pub fn producesImplib(self: *Compile) bool { | 543 | pub fn producesImplib(self: *Compile) bool { |
| 635 | return self.isDynamicLibrary() and self.root_module.target_info.target.os.tag == .windows; | 544 | return self.isDynamicLibrary() and self.rootModuleTarget().os.tag == .windows; |
| 636 | } | 545 | } |
| 637 | 546 | ||
| 638 | pub fn linkLibC(self: *Compile) void { | 547 | pub fn linkLibC(self: *Compile) void { |
| ... | @@ -643,18 +552,9 @@ pub fn linkLibCpp(self: *Compile) void { | ... | @@ -643,18 +552,9 @@ pub fn linkLibCpp(self: *Compile) void { |
| 643 | self.root_module.link_libcpp = true; | 552 | self.root_module.link_libcpp = true; |
| 644 | } | 553 | } |
| 645 | 554 | ||
| 646 | /// If the value is omitted, it is set to 1. | 555 | /// Deprecated. Use `c.root_module.addCMacro`. |
| 647 | /// `name` and `value` need not live longer than the function call. | 556 | pub fn defineCMacro(c: *Compile, name: []const u8, value: ?[]const u8) void { |
| 648 | pub fn defineCMacro(self: *Compile, name: []const u8, value: ?[]const u8) void { | 557 | c.root_module.addCMacro(name, value orelse "1"); |
| 649 | const b = self.step.owner; | ||
| 650 | const macro = std.Build.constructCMacro(b.allocator, name, value); | ||
| 651 | self.c_macros.append(macro) catch @panic("OOM"); | ||
| 652 | } | ||
| 653 | |||
| 654 | /// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1. | ||
| 655 | pub fn defineCMacroRaw(self: *Compile, name_and_value: []const u8) void { | ||
| 656 | const b = self.step.owner; | ||
| 657 | self.c_macros.append(b.dupe(name_and_value)) catch @panic("OOM"); | ||
| 658 | } | 558 | } |
| 659 | 559 | ||
| 660 | /// Run pkg-config for the given library name and parse the output, returning the arguments | 560 | /// Run pkg-config for the given library name and parse the output, returning the arguments |
| ... | @@ -765,6 +665,20 @@ pub fn linkSystemLibrary2( | ... | @@ -765,6 +665,20 @@ pub fn linkSystemLibrary2( |
| 765 | return self.root_module.linkSystemLibrary(name, options); | 665 | return self.root_module.linkSystemLibrary(name, options); |
| 766 | } | 666 | } |
| 767 | 667 | ||
| 668 | pub fn linkFramework(c: *Compile, name: []const u8) void { | ||
| 669 | c.root_module.linkFramework(name, .{}); | ||
| 670 | } | ||
| 671 | |||
| 672 | /// Deprecated. Use `c.root_module.linkFramework`. | ||
| 673 | pub fn linkFrameworkNeeded(c: *Compile, name: []const u8) void { | ||
| 674 | c.root_module.linkFramework(name, .{ .needed = true }); | ||
| 675 | } | ||
| 676 | |||
| 677 | /// Deprecated. Use `c.root_module.linkFramework`. | ||
| 678 | pub fn linkFrameworkWeak(c: *Compile, name: []const u8) void { | ||
| 679 | c.root_module.linkFramework(name, .{ .weak = true }); | ||
| 680 | } | ||
| 681 | |||
| 768 | /// Handy when you have many C/C++ source files and want them all to have the same flags. | 682 | /// Handy when you have many C/C++ source files and want them all to have the same flags. |
| 769 | pub fn addCSourceFiles(self: *Compile, options: Module.AddCSourceFilesOptions) void { | 683 | pub fn addCSourceFiles(self: *Compile, options: Module.AddCSourceFilesOptions) void { |
| 770 | self.root_module.addCSourceFiles(options); | 684 | self.root_module.addCSourceFiles(options); |
| ... | @@ -805,27 +719,18 @@ fn getEmittedFileGeneric(self: *Compile, output_file: *?*GeneratedFile) LazyPath | ... | @@ -805,27 +719,18 @@ fn getEmittedFileGeneric(self: *Compile, output_file: *?*GeneratedFile) LazyPath |
| 805 | return .{ .generated = generated_file }; | 719 | return .{ .generated = generated_file }; |
| 806 | } | 720 | } |
| 807 | 721 | ||
| 808 | /// deprecated: use `getEmittedBinDirectory` | ||
| 809 | pub const getOutputDirectorySource = getEmittedBinDirectory; | ||
| 810 | |||
| 811 | /// Returns the path to the directory that contains the emitted binary file. | 722 | /// Returns the path to the directory that contains the emitted binary file. |
| 812 | pub fn getEmittedBinDirectory(self: *Compile) LazyPath { | 723 | pub fn getEmittedBinDirectory(self: *Compile) LazyPath { |
| 813 | _ = self.getEmittedBin(); | 724 | _ = self.getEmittedBin(); |
| 814 | return self.getEmittedFileGeneric(&self.emit_directory); | 725 | return self.getEmittedFileGeneric(&self.emit_directory); |
| 815 | } | 726 | } |
| 816 | 727 | ||
| 817 | /// deprecated: use `getEmittedBin` | ||
| 818 | pub const getOutputSource = getEmittedBin; | ||
| 819 | |||
| 820 | /// Returns the path to the generated executable, library or object file. | 728 | /// Returns the path to the generated executable, library or object file. |
| 821 | /// To run an executable built with zig build, use `run`, or create an install step and invoke it. | 729 | /// To run an executable built with zig build, use `run`, or create an install step and invoke it. |
| 822 | pub fn getEmittedBin(self: *Compile) LazyPath { | 730 | pub fn getEmittedBin(self: *Compile) LazyPath { |
| 823 | return self.getEmittedFileGeneric(&self.generated_bin); | 731 | return self.getEmittedFileGeneric(&self.generated_bin); |
| 824 | } | 732 | } |
| 825 | 733 | ||
| 826 | /// deprecated: use `getEmittedImplib` | ||
| 827 | pub const getOutputLibSource = getEmittedImplib; | ||
| 828 | |||
| 829 | /// Returns the path to the generated import library. | 734 | /// Returns the path to the generated import library. |
| 830 | /// This function can only be called for libraries. | 735 | /// This function can only be called for libraries. |
| 831 | pub fn getEmittedImplib(self: *Compile) LazyPath { | 736 | pub fn getEmittedImplib(self: *Compile) LazyPath { |
| ... | @@ -833,9 +738,6 @@ pub fn getEmittedImplib(self: *Compile) LazyPath { | ... | @@ -833,9 +738,6 @@ pub fn getEmittedImplib(self: *Compile) LazyPath { |
| 833 | return self.getEmittedFileGeneric(&self.generated_implib); | 738 | return self.getEmittedFileGeneric(&self.generated_implib); |
| 834 | } | 739 | } |
| 835 | 740 | ||
| 836 | /// deprecated: use `getEmittedH` | ||
| 837 | pub const getOutputHSource = getEmittedH; | ||
| 838 | |||
| 839 | /// Returns the path to the generated header file. | 741 | /// Returns the path to the generated header file. |
| 840 | /// This function can only be called for libraries or objects. | 742 | /// This function can only be called for libraries or objects. |
| 841 | pub fn getEmittedH(self: *Compile) LazyPath { | 743 | pub fn getEmittedH(self: *Compile) LazyPath { |
| ... | @@ -843,9 +745,6 @@ pub fn getEmittedH(self: *Compile) LazyPath { | ... | @@ -843,9 +745,6 @@ pub fn getEmittedH(self: *Compile) LazyPath { |
| 843 | return self.getEmittedFileGeneric(&self.generated_h); | 745 | return self.getEmittedFileGeneric(&self.generated_h); |
| 844 | } | 746 | } |
| 845 | 747 | ||
| 846 | /// deprecated: use `getEmittedPdb`. | ||
| 847 | pub const getOutputPdbSource = getEmittedPdb; | ||
| 848 | |||
| 849 | /// Returns the generated PDB file. | 748 | /// Returns the generated PDB file. |
| 850 | /// If the compilation does not produce a PDB file, this causes a FileNotFound error | 749 | /// If the compilation does not produce a PDB file, this causes a FileNotFound error |
| 851 | /// at build time. | 750 | /// at build time. |
| ... | @@ -882,56 +781,44 @@ pub fn addObjectFile(self: *Compile, source: LazyPath) void { | ... | @@ -882,56 +781,44 @@ pub fn addObjectFile(self: *Compile, source: LazyPath) void { |
| 882 | self.root_module.addObjectFile(source); | 781 | self.root_module.addObjectFile(source); |
| 883 | } | 782 | } |
| 884 | 783 | ||
| 885 | pub fn addObject(self: *Compile, obj: *Compile) void { | 784 | pub fn addObject(self: *Compile, object: *Compile) void { |
| 886 | assert(obj.kind == .obj); | 785 | self.root_module.addObject(object); |
| 887 | self.linkLibraryOrObject(obj); | ||
| 888 | } | 786 | } |
| 889 | 787 | ||
| 890 | pub fn addAfterIncludePath(self: *Compile, path: LazyPath) void { | 788 | pub fn linkLibrary(self: *Compile, library: *Compile) void { |
| 891 | const b = self.step.owner; | 789 | self.root_module.linkLibrary(library); |
| 892 | self.include_dirs.append(.{ .path_after = path.dupe(b) }) catch @panic("OOM"); | ||
| 893 | path.addStepDependencies(&self.step); | ||
| 894 | } | 790 | } |
| 895 | 791 | ||
| 896 | pub fn addSystemIncludePath(self: *Compile, path: LazyPath) void { | 792 | pub fn addAfterIncludePath(self: *Compile, lazy_path: LazyPath) void { |
| 897 | const b = self.step.owner; | 793 | self.root_module.addAfterIncludePath(lazy_path); |
| 898 | self.include_dirs.append(.{ .path_system = path.dupe(b) }) catch @panic("OOM"); | ||
| 899 | path.addStepDependencies(&self.step); | ||
| 900 | } | 794 | } |
| 901 | 795 | ||
| 902 | pub fn addIncludePath(self: *Compile, path: LazyPath) void { | 796 | pub fn addSystemIncludePath(self: *Compile, lazy_path: LazyPath) void { |
| 903 | const b = self.step.owner; | 797 | self.root_module.addSystemIncludePath(lazy_path); |
| 904 | self.include_dirs.append(.{ .path = path.dupe(b) }) catch @panic("OOM"); | 798 | } |
| 905 | path.addStepDependencies(&self.step); | 799 | |
| 800 | pub fn addIncludePath(self: *Compile, lazy_path: LazyPath) void { | ||
| 801 | self.root_module.addIncludePath(lazy_path); | ||
| 906 | } | 802 | } |
| 907 | 803 | ||
| 908 | pub fn addConfigHeader(self: *Compile, config_header: *Step.ConfigHeader) void { | 804 | pub fn addConfigHeader(self: *Compile, config_header: *Step.ConfigHeader) void { |
| 909 | self.step.dependOn(&config_header.step); | 805 | self.root_module.addConfigHeader(config_header); |
| 910 | self.include_dirs.append(.{ .config_header_step = config_header }) catch @panic("OOM"); | ||
| 911 | } | 806 | } |
| 912 | 807 | ||
| 913 | pub fn addLibraryPath(self: *Compile, directory_source: LazyPath) void { | 808 | pub fn addLibraryPath(self: *Compile, directory_path: LazyPath) void { |
| 914 | const b = self.step.owner; | 809 | self.root_module.addLibraryPath(directory_path); |
| 915 | self.lib_paths.append(directory_source.dupe(b)) catch @panic("OOM"); | ||
| 916 | directory_source.addStepDependencies(&self.step); | ||
| 917 | } | 810 | } |
| 918 | 811 | ||
| 919 | pub fn addRPath(self: *Compile, directory_source: LazyPath) void { | 812 | pub fn addRPath(self: *Compile, directory_path: LazyPath) void { |
| 920 | const b = self.step.owner; | 813 | self.root_module.addRPath(directory_path); |
| 921 | self.rpaths.append(directory_source.dupe(b)) catch @panic("OOM"); | ||
| 922 | directory_source.addStepDependencies(&self.step); | ||
| 923 | } | 814 | } |
| 924 | 815 | ||
| 925 | pub fn addSystemFrameworkPath(self: *Compile, directory_source: LazyPath) void { | 816 | pub fn addSystemFrameworkPath(self: *Compile, directory_path: LazyPath) void { |
| 926 | const b = self.step.owner; | 817 | self.root_module.addSystemFrameworkPath(directory_path); |
| 927 | self.include_dirs.append(.{ .framework_path_system = directory_source.dupe(b) }) catch @panic("OOM"); | ||
| 928 | directory_source.addStepDependencies(&self.step); | ||
| 929 | } | 818 | } |
| 930 | 819 | ||
| 931 | pub fn addFrameworkPath(self: *Compile, directory_source: LazyPath) void { | 820 | pub fn addFrameworkPath(self: *Compile, directory_path: LazyPath) void { |
| 932 | const b = self.step.owner; | 821 | self.root_module.addFrameworkPath(directory_path); |
| 933 | self.include_dirs.append(.{ .framework_path = directory_source.dupe(b) }) catch @panic("OOM"); | ||
| 934 | directory_source.addStepDependencies(&self.step); | ||
| 935 | } | 822 | } |
| 936 | 823 | ||
| 937 | pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void { | 824 | pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void { |
| ... | @@ -944,20 +831,6 @@ pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void { | ... | @@ -944,20 +831,6 @@ pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void { |
| 944 | self.exec_cmd_args = duped_args; | 831 | self.exec_cmd_args = duped_args; |
| 945 | } | 832 | } |
| 946 | 833 | ||
| 947 | fn linkLibraryOrObject(self: *Compile, other: *Compile) void { | ||
| 948 | other.getEmittedBin().addStepDependencies(&self.step); | ||
| 949 | if (other.target.isWindows() and other.isDynamicLibrary()) { | ||
| 950 | other.getEmittedImplib().addStepDependencies(&self.step); | ||
| 951 | } | ||
| 952 | |||
| 953 | self.link_objects.append(.{ .other_step = other }) catch @panic("OOM"); | ||
| 954 | self.include_dirs.append(.{ .other_step = other }) catch @panic("OOM"); | ||
| 955 | |||
| 956 | for (other.installed_headers.items) |install_step| { | ||
| 957 | self.step.dependOn(install_step); | ||
| 958 | } | ||
| 959 | } | ||
| 960 | |||
| 961 | fn appendModuleArgs(cs: *Compile, zig_args: *ArrayList([]const u8)) !void { | 834 | fn appendModuleArgs(cs: *Compile, zig_args: *ArrayList([]const u8)) !void { |
| 962 | const b = cs.step.owner; | 835 | const b = cs.step.owner; |
| 963 | // First, traverse the whole dependency graph and give every module a | 836 | // First, traverse the whole dependency graph and give every module a |
| ... | @@ -1014,7 +887,7 @@ fn appendModuleArgs(cs: *Compile, zig_args: *ArrayList([]const u8)) !void { | ... | @@ -1014,7 +887,7 @@ fn appendModuleArgs(cs: *Compile, zig_args: *ArrayList([]const u8)) !void { |
| 1014 | fn constructDepString( | 887 | fn constructDepString( |
| 1015 | allocator: std.mem.Allocator, | 888 | allocator: std.mem.Allocator, |
| 1016 | mod_names: std.AutoArrayHashMapUnmanaged(*Module, []const u8), | 889 | mod_names: std.AutoArrayHashMapUnmanaged(*Module, []const u8), |
| 1017 | deps: std.StringArrayHashMap(*Module), | 890 | deps: std.StringArrayHashMapUnmanaged(*Module), |
| 1018 | ) ![]const u8 { | 891 | ) ![]const u8 { |
| 1019 | var deps_str = std.ArrayList(u8).init(allocator); | 892 | var deps_str = std.ArrayList(u8).init(allocator); |
| 1020 | var it = deps.iterator(); | 893 | var it = deps.iterator(); |
| ... | @@ -1082,7 +955,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1082,7 +955,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1082 | try addFlag(&zig_args, "llvm", self.use_llvm); | 955 | try addFlag(&zig_args, "llvm", self.use_llvm); |
| 1083 | try addFlag(&zig_args, "lld", self.use_lld); | 956 | try addFlag(&zig_args, "lld", self.use_lld); |
| 1084 | 957 | ||
| 1085 | if (self.root_module.target.ofmt) |ofmt| { | 958 | if (self.root_module.target.?.query.ofmt) |ofmt| { |
| 1086 | try zig_args.append(try std.fmt.allocPrint(b.allocator, "-ofmt={s}", .{@tagName(ofmt)})); | 959 | try zig_args.append(try std.fmt.allocPrint(b.allocator, "-ofmt={s}", .{@tagName(ofmt)})); |
| 1087 | } | 960 | } |
| 1088 | 961 | ||
| ... | @@ -1110,7 +983,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1110,7 +983,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1110 | 983 | ||
| 1111 | { | 984 | { |
| 1112 | var seen_system_libs: std.StringHashMapUnmanaged(void) = .{}; | 985 | var seen_system_libs: std.StringHashMapUnmanaged(void) = .{}; |
| 1113 | var frameworks: std.StringArrayHashMapUnmanaged(Module.FrameworkLinkInfo) = .{}; | 986 | var frameworks: std.StringArrayHashMapUnmanaged(Module.LinkFrameworkOptions) = .{}; |
| 1114 | 987 | ||
| 1115 | var prev_has_cflags = false; | 988 | var prev_has_cflags = false; |
| 1116 | var prev_has_rcflags = false; | 989 | var prev_has_rcflags = false; |
| ... | @@ -1240,7 +1113,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1240,7 +1113,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1240 | try zig_args.append(full_path_lib); | 1113 | try zig_args.append(full_path_lib); |
| 1241 | 1114 | ||
| 1242 | if (other.linkage == Linkage.dynamic and | 1115 | if (other.linkage == Linkage.dynamic and |
| 1243 | self.root_module.target_info.target.os.tag != .windows) | 1116 | self.rootModuleTarget().os.tag != .windows) |
| 1244 | { | 1117 | { |
| 1245 | if (fs.path.dirname(full_path_lib)) |dirname| { | 1118 | if (fs.path.dirname(full_path_lib)) |dirname| { |
| 1246 | try zig_args.append("-rpath"); | 1119 | try zig_args.append("-rpath"); |
| ... | @@ -1471,11 +1344,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1471,11 +1344,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1471 | try zig_args.append(b.fmt("{}", .{version})); | 1344 | try zig_args.append(b.fmt("{}", .{version})); |
| 1472 | } | 1345 | } |
| 1473 | 1346 | ||
| 1474 | if (self.root_module.target_info.target.isDarwin()) { | 1347 | if (self.rootModuleTarget().isDarwin()) { |
| 1475 | const install_name = self.install_name orelse b.fmt("@rpath/{s}{s}{s}", .{ | 1348 | const install_name = self.install_name orelse b.fmt("@rpath/{s}{s}{s}", .{ |
| 1476 | self.root_module.target_info.target.libPrefix(), | 1349 | self.rootModuleTarget().libPrefix(), |
| 1477 | self.name, | 1350 | self.name, |
| 1478 | self.root_module.target_info.target.dynamicLibSuffix(), | 1351 | self.rootModuleTarget().dynamicLibSuffix(), |
| 1479 | }); | 1352 | }); |
| 1480 | try zig_args.append("-install_name"); | 1353 | try zig_args.append("-install_name"); |
| 1481 | try zig_args.append(install_name); | 1354 | try zig_args.append(install_name); |
| ... | @@ -1763,7 +1636,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1763,7 +1636,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1763 | } | 1636 | } |
| 1764 | 1637 | ||
| 1765 | if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic and | 1638 | if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic and |
| 1766 | self.version != null and self.root_module.target.wantSharedLibSymLinks()) | 1639 | self.version != null and std.Build.wantSharedLibSymLinks(self.rootModuleTarget())) |
| 1767 | { | 1640 | { |
| 1768 | try doAtomicSymLinks( | 1641 | try doAtomicSymLinks( |
| 1769 | step, | 1642 | step, |
| ... | @@ -1932,3 +1805,8 @@ fn matchCompileError(actual: []const u8, expected: []const u8) bool { | ... | @@ -1932,3 +1805,8 @@ fn matchCompileError(actual: []const u8, expected: []const u8) bool { |
| 1932 | } | 1805 | } |
| 1933 | return false; | 1806 | return false; |
| 1934 | } | 1807 | } |
| 1808 | |||
| 1809 | pub fn rootModuleTarget(c: *Compile) std.Target { | ||
| 1810 | // The root module is always given a target, so we know this to be non-null. | ||
| 1811 | return c.root_module.target.?.target; | ||
| 1812 | } |
lib/std/Build/Step/ConfigHeader.zig-6| ... | @@ -15,9 +15,6 @@ pub const Style = union(enum) { | ... | @@ -15,9 +15,6 @@ pub const Style = union(enum) { |
| 15 | /// Start with nothing, like blank, and output a nasm .asm file. | 15 | /// Start with nothing, like blank, and output a nasm .asm file. |
| 16 | nasm, | 16 | nasm, |
| 17 | 17 | ||
| 18 | /// deprecated: use `getPath` | ||
| 19 | pub const getFileSource = getPath; | ||
| 20 | |||
| 21 | pub fn getPath(style: Style) ?std.Build.LazyPath { | 18 | pub fn getPath(style: Style) ?std.Build.LazyPath { |
| 22 | switch (style) { | 19 | switch (style) { |
| 23 | .autoconf, .cmake => |s| return s, | 20 | .autoconf, .cmake => |s| return s, |
| ... | @@ -107,9 +104,6 @@ pub fn addValues(self: *ConfigHeader, values: anytype) void { | ... | @@ -107,9 +104,6 @@ pub fn addValues(self: *ConfigHeader, values: anytype) void { |
| 107 | return addValuesInner(self, values) catch @panic("OOM"); | 104 | return addValuesInner(self, values) catch @panic("OOM"); |
| 108 | } | 105 | } |
| 109 | 106 | ||
| 110 | /// deprecated: use `getOutput` | ||
| 111 | pub const getFileSource = getOutput; | ||
| 112 | |||
| 113 | pub fn getOutput(self: *ConfigHeader) std.Build.LazyPath { | 107 | pub fn getOutput(self: *ConfigHeader) std.Build.LazyPath { |
| 114 | return .{ .generated = &self.output_file }; | 108 | return .{ .generated = &self.output_file }; |
| 115 | } | 109 | } |
lib/std/Build/Step/InstallArtifact.zig+1-1| ... | @@ -94,7 +94,7 @@ pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *Ins | ... | @@ -94,7 +94,7 @@ pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *Ins |
| 94 | .dylib_symlinks = if (options.dylib_symlinks orelse (dest_dir != null and | 94 | .dylib_symlinks = if (options.dylib_symlinks orelse (dest_dir != null and |
| 95 | artifact.isDynamicLibrary() and | 95 | artifact.isDynamicLibrary() and |
| 96 | artifact.version != null and | 96 | artifact.version != null and |
| 97 | artifact.target.wantSharedLibSymLinks())) .{ | 97 | std.Build.wantSharedLibSymLinks(artifact.rootModuleTarget()))) .{ |
| 98 | .major_only_filename = artifact.major_only_filename.?, | 98 | .major_only_filename = artifact.major_only_filename.?, |
| 99 | .name_only_filename = artifact.name_only_filename.?, | 99 | .name_only_filename = artifact.name_only_filename.?, |
| 100 | } else null, | 100 | } else null, |
lib/std/Build/Step/Options.zig+1-5| ... | @@ -165,9 +165,6 @@ fn printLiteral(out: anytype, val: anytype, indent: u8) !void { | ... | @@ -165,9 +165,6 @@ fn printLiteral(out: anytype, val: anytype, indent: u8) !void { |
| 165 | } | 165 | } |
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | /// deprecated: use `addOptionPath` | ||
| 169 | pub const addOptionFileSource = addOptionPath; | ||
| 170 | |||
| 171 | /// The value is the path in the cache dir. | 168 | /// The value is the path in the cache dir. |
| 172 | /// Adds a dependency automatically. | 169 | /// Adds a dependency automatically. |
| 173 | pub fn addOptionPath( | 170 | pub fn addOptionPath( |
| ... | @@ -189,8 +186,7 @@ pub fn addOptionArtifact(self: *Options, name: []const u8, artifact: *Step.Compi | ... | @@ -189,8 +186,7 @@ pub fn addOptionArtifact(self: *Options, name: []const u8, artifact: *Step.Compi |
| 189 | 186 | ||
| 190 | pub fn createModule(self: *Options) *std.Build.Module { | 187 | pub fn createModule(self: *Options) *std.Build.Module { |
| 191 | return self.step.owner.createModule(.{ | 188 | return self.step.owner.createModule(.{ |
| 192 | .source_file = self.getOutput(), | 189 | .root_source_file = self.getOutput(), |
| 193 | .dependencies = &.{}, | ||
| 194 | }); | 190 | }); |
| 195 | } | 191 | } |
| 196 | 192 |
lib/std/Build/Step/Run.zig+11-16| ... | @@ -197,16 +197,10 @@ pub fn addPrefixedOutputFileArg( | ... | @@ -197,16 +197,10 @@ pub fn addPrefixedOutputFileArg( |
| 197 | return .{ .generated = &output.generated_file }; | 197 | return .{ .generated = &output.generated_file }; |
| 198 | } | 198 | } |
| 199 | 199 | ||
| 200 | /// deprecated: use `addFileArg` | ||
| 201 | pub const addFileSourceArg = addFileArg; | ||
| 202 | |||
| 203 | pub fn addFileArg(self: *Run, lp: std.Build.LazyPath) void { | 200 | pub fn addFileArg(self: *Run, lp: std.Build.LazyPath) void { |
| 204 | self.addPrefixedFileArg("", lp); | 201 | self.addPrefixedFileArg("", lp); |
| 205 | } | 202 | } |
| 206 | 203 | ||
| 207 | // deprecated: use `addPrefixedFileArg` | ||
| 208 | pub const addPrefixedFileSourceArg = addPrefixedFileArg; | ||
| 209 | |||
| 210 | pub fn addPrefixedFileArg(self: *Run, prefix: []const u8, lp: std.Build.LazyPath) void { | 204 | pub fn addPrefixedFileArg(self: *Run, prefix: []const u8, lp: std.Build.LazyPath) void { |
| 211 | const b = self.step.owner; | 205 | const b = self.step.owner; |
| 212 | 206 | ||
| ... | @@ -488,7 +482,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -488,7 +482,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 488 | man.hash.addBytes(file_path); | 482 | man.hash.addBytes(file_path); |
| 489 | }, | 483 | }, |
| 490 | .artifact => |artifact| { | 484 | .artifact => |artifact| { |
| 491 | if (artifact.root_module.target_info.target.os.tag == .windows) { | 485 | if (artifact.rootModuleTarget().os.tag == .windows) { |
| 492 | // On Windows we don't have rpaths so we have to add .dll search paths to PATH | 486 | // On Windows we don't have rpaths so we have to add .dll search paths to PATH |
| 493 | self.addPathForDynLibs(artifact); | 487 | self.addPathForDynLibs(artifact); |
| 494 | } | 488 | } |
| ... | @@ -682,9 +676,10 @@ fn runCommand( | ... | @@ -682,9 +676,10 @@ fn runCommand( |
| 682 | else => break :interpret, | 676 | else => break :interpret, |
| 683 | } | 677 | } |
| 684 | 678 | ||
| 685 | const need_cross_glibc = exe.root_module.target_info.target.isGnuLibC() and | 679 | const need_cross_glibc = exe.rootModuleTarget().isGnuLibC() and |
| 686 | exe.is_linking_libc; | 680 | exe.is_linking_libc; |
| 687 | switch (b.host.getExternalExecutor(&exe.root_module.target_info, .{ | 681 | const other_target_info = exe.root_module.target.?.toNativeTargetInfo(); |
| 682 | switch (b.host.toNativeTargetInfo().getExternalExecutor(&other_target_info, .{ | ||
| 688 | .qemu_fixes_dl = need_cross_glibc and b.glibc_runtimes_dir != null, | 683 | .qemu_fixes_dl = need_cross_glibc and b.glibc_runtimes_dir != null, |
| 689 | .link_libc = exe.is_linking_libc, | 684 | .link_libc = exe.is_linking_libc, |
| 690 | })) { | 685 | })) { |
| ... | @@ -715,9 +710,9 @@ fn runCommand( | ... | @@ -715,9 +710,9 @@ fn runCommand( |
| 715 | // needs the directory to be called "i686" rather than | 710 | // needs the directory to be called "i686" rather than |
| 716 | // "x86" which is why we do it manually here. | 711 | // "x86" which is why we do it manually here. |
| 717 | const fmt_str = "{s}" ++ fs.path.sep_str ++ "{s}-{s}-{s}"; | 712 | const fmt_str = "{s}" ++ fs.path.sep_str ++ "{s}-{s}-{s}"; |
| 718 | const cpu_arch = exe.root_module.target_info.target.cpu.arch; | 713 | const cpu_arch = exe.rootModuleTarget().cpu.arch; |
| 719 | const os_tag = exe.root_module.target_info.target.os.tag; | 714 | const os_tag = exe.rootModuleTarget().os.tag; |
| 720 | const abi = exe.root_module.target_info.target.abi; | 715 | const abi = exe.rootModuleTarget().abi; |
| 721 | const cpu_arch_name: []const u8 = if (cpu_arch == .x86) | 716 | const cpu_arch_name: []const u8 = if (cpu_arch == .x86) |
| 722 | "i686" | 717 | "i686" |
| 723 | else | 718 | else |
| ... | @@ -770,7 +765,7 @@ fn runCommand( | ... | @@ -770,7 +765,7 @@ fn runCommand( |
| 770 | if (allow_skip) return error.MakeSkipped; | 765 | if (allow_skip) return error.MakeSkipped; |
| 771 | 766 | ||
| 772 | const host_name = try b.host.target.zigTriple(b.allocator); | 767 | const host_name = try b.host.target.zigTriple(b.allocator); |
| 773 | const foreign_name = try exe.root_module.target_info.target.zigTriple(b.allocator); | 768 | const foreign_name = try exe.rootModuleTarget().zigTriple(b.allocator); |
| 774 | 769 | ||
| 775 | return step.fail("the host system ({s}) is unable to execute binaries from the target ({s})", .{ | 770 | return step.fail("the host system ({s}) is unable to execute binaries from the target ({s})", .{ |
| 776 | host_name, foreign_name, | 771 | host_name, foreign_name, |
| ... | @@ -778,7 +773,7 @@ fn runCommand( | ... | @@ -778,7 +773,7 @@ fn runCommand( |
| 778 | }, | 773 | }, |
| 779 | } | 774 | } |
| 780 | 775 | ||
| 781 | if (exe.root_module.target_info.target.os.tag == .windows) { | 776 | if (exe.rootModuleTarget().os.tag == .windows) { |
| 782 | // On Windows we don't have rpaths so we have to add .dll search paths to PATH | 777 | // On Windows we don't have rpaths so we have to add .dll search paths to PATH |
| 783 | self.addPathForDynLibs(exe); | 778 | self.addPathForDynLibs(exe); |
| 784 | } | 779 | } |
| ... | @@ -1300,7 +1295,7 @@ fn addPathForDynLibs(self: *Run, artifact: *Step.Compile) void { | ... | @@ -1300,7 +1295,7 @@ fn addPathForDynLibs(self: *Run, artifact: *Step.Compile) void { |
| 1300 | while (it.next()) |item| { | 1295 | while (it.next()) |item| { |
| 1301 | const other = item.compile.?; | 1296 | const other = item.compile.?; |
| 1302 | if (item.module == &other.root_module) { | 1297 | if (item.module == &other.root_module) { |
| 1303 | if (item.module.target_info.target.os.tag == .windows and other.isDynamicLibrary()) { | 1298 | if (item.module.target.?.target.os.tag == .windows and other.isDynamicLibrary()) { |
| 1304 | addPathDir(self, fs.path.dirname(other.getEmittedBin().getPath(b)).?); | 1299 | addPathDir(self, fs.path.dirname(other.getEmittedBin().getPath(b)).?); |
| 1305 | addPathForDynLibs(self, other); | 1300 | addPathForDynLibs(self, other); |
| 1306 | } | 1301 | } |
| ... | @@ -1321,7 +1316,7 @@ fn failForeign( | ... | @@ -1321,7 +1316,7 @@ fn failForeign( |
| 1321 | 1316 | ||
| 1322 | const b = self.step.owner; | 1317 | const b = self.step.owner; |
| 1323 | const host_name = try b.host.target.zigTriple(b.allocator); | 1318 | const host_name = try b.host.target.zigTriple(b.allocator); |
| 1324 | const foreign_name = try exe.root_module.target_info.target.zigTriple(b.allocator); | 1319 | const foreign_name = try exe.rootModuleTarget().zigTriple(b.allocator); |
| 1325 | 1320 | ||
| 1326 | return self.step.fail( | 1321 | return self.step.fail( |
| 1327 | \\unable to spawn foreign binary '{s}' ({s}) on host system ({s}) | 1322 | \\unable to spawn foreign binary '{s}' ({s}) on host system ({s}) |
lib/std/Build/Step/TranslateC.zig+5-6| ... | @@ -2,7 +2,6 @@ const std = @import("std"); | ... | @@ -2,7 +2,6 @@ const std = @import("std"); |
| 2 | const Step = std.Build.Step; | 2 | const Step = std.Build.Step; |
| 3 | const fs = std.fs; | 3 | const fs = std.fs; |
| 4 | const mem = std.mem; | 4 | const mem = std.mem; |
| 5 | const CrossTarget = std.zig.CrossTarget; | ||
| 6 | 5 | ||
| 7 | const TranslateC = @This(); | 6 | const TranslateC = @This(); |
| 8 | 7 | ||
| ... | @@ -13,7 +12,7 @@ source: std.Build.LazyPath, | ... | @@ -13,7 +12,7 @@ source: std.Build.LazyPath, |
| 13 | include_dirs: std.ArrayList([]const u8), | 12 | include_dirs: std.ArrayList([]const u8), |
| 14 | c_macros: std.ArrayList([]const u8), | 13 | c_macros: std.ArrayList([]const u8), |
| 15 | out_basename: []const u8, | 14 | out_basename: []const u8, |
| 16 | target: CrossTarget, | 15 | target: std.Build.ResolvedTarget, |
| 17 | optimize: std.builtin.OptimizeMode, | 16 | optimize: std.builtin.OptimizeMode, |
| 18 | output_file: std.Build.GeneratedFile, | 17 | output_file: std.Build.GeneratedFile, |
| 19 | link_libc: bool, | 18 | link_libc: bool, |
| ... | @@ -21,7 +20,7 @@ use_clang: bool, | ... | @@ -21,7 +20,7 @@ use_clang: bool, |
| 21 | 20 | ||
| 22 | pub const Options = struct { | 21 | pub const Options = struct { |
| 23 | source_file: std.Build.LazyPath, | 22 | source_file: std.Build.LazyPath, |
| 24 | target: CrossTarget, | 23 | target: std.Build.ResolvedTarget, |
| 25 | optimize: std.builtin.OptimizeMode, | 24 | optimize: std.builtin.OptimizeMode, |
| 26 | link_libc: bool = true, | 25 | link_libc: bool = true, |
| 27 | use_clang: bool = true, | 26 | use_clang: bool = true, |
| ... | @@ -54,7 +53,7 @@ pub fn create(owner: *std.Build, options: Options) *TranslateC { | ... | @@ -54,7 +53,7 @@ pub fn create(owner: *std.Build, options: Options) *TranslateC { |
| 54 | pub const AddExecutableOptions = struct { | 53 | pub const AddExecutableOptions = struct { |
| 55 | name: ?[]const u8 = null, | 54 | name: ?[]const u8 = null, |
| 56 | version: ?std.SemanticVersion = null, | 55 | version: ?std.SemanticVersion = null, |
| 57 | target: ?CrossTarget = null, | 56 | target: ?std.Build.ResolvedTarget = null, |
| 58 | optimize: ?std.builtin.OptimizeMode = null, | 57 | optimize: ?std.builtin.OptimizeMode = null, |
| 59 | linkage: ?Step.Compile.Linkage = null, | 58 | linkage: ?Step.Compile.Linkage = null, |
| 60 | }; | 59 | }; |
| ... | @@ -139,9 +138,9 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -139,9 +138,9 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 139 | 138 | ||
| 140 | try argv_list.append("--listen=-"); | 139 | try argv_list.append("--listen=-"); |
| 141 | 140 | ||
| 142 | if (!self.target.isNative()) { | 141 | if (!self.target.query.isNative()) { |
| 143 | try argv_list.append("-target"); | 142 | try argv_list.append("-target"); |
| 144 | try argv_list.append(try self.target.zigTriple(b.allocator)); | 143 | try argv_list.append(try self.target.query.zigTriple(b.allocator)); |
| 145 | } | 144 | } |
| 146 | 145 | ||
| 147 | switch (self.optimize) { | 146 | switch (self.optimize) { |
lib/std/Build/Step/WriteFile.zig-7| ... | @@ -28,9 +28,6 @@ pub const File = struct { | ... | @@ -28,9 +28,6 @@ pub const File = struct { |
| 28 | sub_path: []const u8, | 28 | sub_path: []const u8, |
| 29 | contents: Contents, | 29 | contents: Contents, |
| 30 | 30 | ||
| 31 | /// deprecated: use `getPath` | ||
| 32 | pub const getFileSource = getPath; | ||
| 33 | |||
| 34 | pub fn getPath(self: *File) std.Build.LazyPath { | 31 | pub fn getPath(self: *File) std.Build.LazyPath { |
| 35 | return .{ .generated = &self.generated_file }; | 32 | return .{ .generated = &self.generated_file }; |
| 36 | } | 33 | } |
| ... | @@ -126,10 +123,6 @@ pub fn addBytesToSource(wf: *WriteFile, bytes: []const u8, sub_path: []const u8) | ... | @@ -126,10 +123,6 @@ pub fn addBytesToSource(wf: *WriteFile, bytes: []const u8, sub_path: []const u8) |
| 126 | }) catch @panic("OOM"); | 123 | }) catch @panic("OOM"); |
| 127 | } | 124 | } |
| 128 | 125 | ||
| 129 | pub const getFileSource = @compileError("Deprecated; use the return value from add()/addCopyFile(), or use files[i].getPath()"); | ||
| 130 | |||
| 131 | pub const getDirectorySource = getDirectory; | ||
| 132 | |||
| 133 | /// Returns a `LazyPath` representing the base directory that contains all the | 126 | /// Returns a `LazyPath` representing the base directory that contains all the |
| 134 | /// files from this `WriteFile`. | 127 | /// files from this `WriteFile`. |
| 135 | pub fn getDirectory(wf: *WriteFile) std.Build.LazyPath { | 128 | pub fn getDirectory(wf: *WriteFile) std.Build.LazyPath { |
lib/std/std.zig-3| ... | @@ -194,9 +194,6 @@ pub const zig = @import("zig.zig"); | ... | @@ -194,9 +194,6 @@ pub const zig = @import("zig.zig"); |
| 194 | 194 | ||
| 195 | pub const start = @import("start.zig"); | 195 | pub const start = @import("start.zig"); |
| 196 | 196 | ||
| 197 | /// deprecated: use `Build`. | ||
| 198 | pub const build = Build; | ||
| 199 | |||
| 200 | const root = @import("root"); | 197 | const root = @import("root"); |
| 201 | const options_override = if (@hasDecl(root, "std_options")) root.std_options else struct {}; | 198 | const options_override = if (@hasDecl(root, "std_options")) root.std_options else struct {}; |
| 202 | 199 |
lib/std/zig.zig+77| ... | @@ -203,6 +203,83 @@ pub fn binNameAlloc(allocator: std.mem.Allocator, options: BinNameOptions) error | ... | @@ -203,6 +203,83 @@ pub fn binNameAlloc(allocator: std.mem.Allocator, options: BinNameOptions) error |
| 203 | } | 203 | } |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | pub const BuildId = union(enum) { | ||
| 207 | none, | ||
| 208 | fast, | ||
| 209 | uuid, | ||
| 210 | sha1, | ||
| 211 | md5, | ||
| 212 | hexstring: HexString, | ||
| 213 | |||
| 214 | pub fn eql(a: BuildId, b: BuildId) bool { | ||
| 215 | const Tag = @TypeOf(BuildId).Union.tag_type.?; | ||
| 216 | const a_tag: Tag = a; | ||
| 217 | const b_tag: Tag = b; | ||
| 218 | if (a_tag != b_tag) return false; | ||
| 219 | return switch (a) { | ||
| 220 | .none, .fast, .uuid, .sha1, .md5 => true, | ||
| 221 | .hexstring => |a_hexstring| std.mem.eql(u8, a_hexstring.toSlice(), b.hexstring.toSlice()), | ||
| 222 | }; | ||
| 223 | } | ||
| 224 | |||
| 225 | pub const HexString = struct { | ||
| 226 | bytes: [32]u8, | ||
| 227 | len: u8, | ||
| 228 | |||
| 229 | /// Result is byte values, *not* hex-encoded. | ||
| 230 | pub fn toSlice(hs: *const HexString) []const u8 { | ||
| 231 | return hs.bytes[0..hs.len]; | ||
| 232 | } | ||
| 233 | }; | ||
| 234 | |||
| 235 | /// Input is byte values, *not* hex-encoded. | ||
| 236 | /// Asserts `bytes` fits inside `HexString` | ||
| 237 | pub fn initHexString(bytes: []const u8) BuildId { | ||
| 238 | var result: BuildId = .{ .hexstring = .{ | ||
| 239 | .bytes = undefined, | ||
| 240 | .len = @intCast(bytes.len), | ||
| 241 | } }; | ||
| 242 | @memcpy(result.hexstring.bytes[0..bytes.len], bytes); | ||
| 243 | return result; | ||
| 244 | } | ||
| 245 | |||
| 246 | /// Converts UTF-8 text to a `BuildId`. | ||
| 247 | pub fn parse(text: []const u8) !BuildId { | ||
| 248 | if (std.mem.eql(u8, text, "none")) { | ||
| 249 | return .none; | ||
| 250 | } else if (std.mem.eql(u8, text, "fast")) { | ||
| 251 | return .fast; | ||
| 252 | } else if (std.mem.eql(u8, text, "uuid")) { | ||
| 253 | return .uuid; | ||
| 254 | } else if (std.mem.eql(u8, text, "sha1") or std.mem.eql(u8, text, "tree")) { | ||
| 255 | return .sha1; | ||
| 256 | } else if (std.mem.eql(u8, text, "md5")) { | ||
| 257 | return .md5; | ||
| 258 | } else if (std.mem.startsWith(u8, text, "0x")) { | ||
| 259 | var result: BuildId = .{ .hexstring = undefined }; | ||
| 260 | const slice = try std.fmt.hexToBytes(&result.hexstring.bytes, text[2..]); | ||
| 261 | result.hexstring.len = @as(u8, @intCast(slice.len)); | ||
| 262 | return result; | ||
| 263 | } | ||
| 264 | return error.InvalidBuildIdStyle; | ||
| 265 | } | ||
| 266 | |||
| 267 | test parse { | ||
| 268 | try std.testing.expectEqual(BuildId.md5, try parse("md5")); | ||
| 269 | try std.testing.expectEqual(BuildId.none, try parse("none")); | ||
| 270 | try std.testing.expectEqual(BuildId.fast, try parse("fast")); | ||
| 271 | try std.testing.expectEqual(BuildId.uuid, try parse("uuid")); | ||
| 272 | try std.testing.expectEqual(BuildId.sha1, try parse("sha1")); | ||
| 273 | try std.testing.expectEqual(BuildId.sha1, try parse("tree")); | ||
| 274 | |||
| 275 | try std.testing.expect(BuildId.initHexString("").eql(try parse("0x"))); | ||
| 276 | try std.testing.expect(BuildId.initHexString("\x12\x34\x56").eql(try parse("0x123456"))); | ||
| 277 | try std.testing.expectError(error.InvalidLength, parse("0x12-34")); | ||
| 278 | try std.testing.expectError(error.InvalidCharacter, parse("0xfoobbb")); | ||
| 279 | try std.testing.expectError(error.InvalidBuildIdStyle, parse("yaddaxxx")); | ||
| 280 | } | ||
| 281 | }; | ||
| 282 | |||
| 206 | test { | 283 | test { |
| 207 | @import("std").testing.refAllDecls(@This()); | 284 | @import("std").testing.refAllDecls(@This()); |
| 208 | } | 285 | } |
lib/std/zig/CrossTarget.zig-4| ... | @@ -632,10 +632,6 @@ pub fn linuxTriple(self: CrossTarget, allocator: mem.Allocator) ![]u8 { | ... | @@ -632,10 +632,6 @@ pub fn linuxTriple(self: CrossTarget, allocator: mem.Allocator) ![]u8 { |
| 632 | return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi()); | 632 | return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi()); |
| 633 | } | 633 | } |
| 634 | 634 | ||
| 635 | pub fn wantSharedLibSymLinks(self: CrossTarget) bool { | ||
| 636 | return self.getOsTag() != .windows; | ||
| 637 | } | ||
| 638 | |||
| 639 | pub fn isGnuLibC(self: CrossTarget) bool { | 635 | pub fn isGnuLibC(self: CrossTarget) bool { |
| 640 | return Target.isGnuLibC_os_tag_abi(self.getOsTag(), self.getAbi()); | 636 | return Target.isGnuLibC_os_tag_abi(self.getOsTag(), self.getAbi()); |
| 641 | } | 637 | } |
lib/std/zig/system/NativeTargetInfo.zig+2-2| ... | @@ -1008,8 +1008,8 @@ pub const GetExternalExecutorOptions = struct { | ... | @@ -1008,8 +1008,8 @@ pub const GetExternalExecutorOptions = struct { |
| 1008 | link_libc: bool = false, | 1008 | link_libc: bool = false, |
| 1009 | }; | 1009 | }; |
| 1010 | 1010 | ||
| 1011 | /// Return whether or not the given host target is capable of executing natively executables | 1011 | /// Return whether or not the given host is capable of running executables of |
| 1012 | /// of the other target. | 1012 | /// the other target. |
| 1013 | pub fn getExternalExecutor( | 1013 | pub fn getExternalExecutor( |
| 1014 | host: NativeTargetInfo, | 1014 | host: NativeTargetInfo, |
| 1015 | candidate: *const NativeTargetInfo, | 1015 | candidate: *const NativeTargetInfo, |
src/Compilation.zig+1-2| ... | @@ -30,7 +30,6 @@ const fatal = @import("main.zig").fatal; | ... | @@ -30,7 +30,6 @@ const fatal = @import("main.zig").fatal; |
| 30 | const clangMain = @import("main.zig").clangMain; | 30 | const clangMain = @import("main.zig").clangMain; |
| 31 | const Module = @import("Module.zig"); | 31 | const Module = @import("Module.zig"); |
| 32 | const InternPool = @import("InternPool.zig"); | 32 | const InternPool = @import("InternPool.zig"); |
| 33 | const BuildId = std.Build.CompileStep.BuildId; | ||
| 34 | const Cache = std.Build.Cache; | 33 | const Cache = std.Build.Cache; |
| 35 | const c_codegen = @import("codegen/c.zig"); | 34 | const c_codegen = @import("codegen/c.zig"); |
| 36 | const libtsan = @import("libtsan.zig"); | 35 | const libtsan = @import("libtsan.zig"); |
| ... | @@ -910,7 +909,7 @@ pub const InitOptions = struct { | ... | @@ -910,7 +909,7 @@ pub const InitOptions = struct { |
| 910 | linker_print_map: bool = false, | 909 | linker_print_map: bool = false, |
| 911 | linker_opt_bisect_limit: i32 = -1, | 910 | linker_opt_bisect_limit: i32 = -1, |
| 912 | each_lib_rpath: ?bool = null, | 911 | each_lib_rpath: ?bool = null, |
| 913 | build_id: ?BuildId = null, | 912 | build_id: ?std.zig.BuildId = null, |
| 914 | disable_c_depfile: bool = false, | 913 | disable_c_depfile: bool = false, |
| 915 | linker_z_nodelete: bool = false, | 914 | linker_z_nodelete: bool = false, |
| 916 | linker_z_notext: bool = false, | 915 | linker_z_notext: bool = false, |
src/link.zig+1-2| ... | @@ -10,7 +10,6 @@ const wasi_libc = @import("wasi_libc.zig"); | ... | @@ -10,7 +10,6 @@ const wasi_libc = @import("wasi_libc.zig"); |
| 10 | 10 | ||
| 11 | const Air = @import("Air.zig"); | 11 | const Air = @import("Air.zig"); |
| 12 | const Allocator = std.mem.Allocator; | 12 | const Allocator = std.mem.Allocator; |
| 13 | const BuildId = std.Build.CompileStep.BuildId; | ||
| 14 | const Cache = std.Build.Cache; | 13 | const Cache = std.Build.Cache; |
| 15 | const Compilation = @import("Compilation.zig"); | 14 | const Compilation = @import("Compilation.zig"); |
| 16 | const LibCInstallation = @import("libc_installation.zig").LibCInstallation; | 15 | const LibCInstallation = @import("libc_installation.zig").LibCInstallation; |
| ... | @@ -185,7 +184,7 @@ pub const Options = struct { | ... | @@ -185,7 +184,7 @@ pub const Options = struct { |
| 185 | error_return_tracing: bool, | 184 | error_return_tracing: bool, |
| 186 | skip_linker_dependencies: bool, | 185 | skip_linker_dependencies: bool, |
| 187 | each_lib_rpath: bool, | 186 | each_lib_rpath: bool, |
| 188 | build_id: BuildId, | 187 | build_id: std.zig.BuildId, |
| 189 | disable_lld_caching: bool, | 188 | disable_lld_caching: bool, |
| 190 | is_test: bool, | 189 | is_test: bool, |
| 191 | hash_style: HashStyle, | 190 | hash_style: HashStyle, |
src/main.zig+3-4| ... | @@ -21,7 +21,6 @@ const introspect = @import("introspect.zig"); | ... | @@ -21,7 +21,6 @@ const introspect = @import("introspect.zig"); |
| 21 | const EnvVar = introspect.EnvVar; | 21 | const EnvVar = introspect.EnvVar; |
| 22 | const LibCInstallation = @import("libc_installation.zig").LibCInstallation; | 22 | const LibCInstallation = @import("libc_installation.zig").LibCInstallation; |
| 23 | const wasi_libc = @import("wasi_libc.zig"); | 23 | const wasi_libc = @import("wasi_libc.zig"); |
| 24 | const BuildId = std.Build.CompileStep.BuildId; | ||
| 25 | const Cache = std.Build.Cache; | 24 | const Cache = std.Build.Cache; |
| 26 | const target_util = @import("target.zig"); | 25 | const target_util = @import("target.zig"); |
| 27 | const crash_report = @import("crash_report.zig"); | 26 | const crash_report = @import("crash_report.zig"); |
| ... | @@ -882,7 +881,7 @@ fn buildOutputType( | ... | @@ -882,7 +881,7 @@ fn buildOutputType( |
| 882 | var link_eh_frame_hdr = false; | 881 | var link_eh_frame_hdr = false; |
| 883 | var link_emit_relocs = false; | 882 | var link_emit_relocs = false; |
| 884 | var each_lib_rpath: ?bool = null; | 883 | var each_lib_rpath: ?bool = null; |
| 885 | var build_id: ?BuildId = null; | 884 | var build_id: ?std.zig.BuildId = null; |
| 886 | var sysroot: ?[]const u8 = null; | 885 | var sysroot: ?[]const u8 = null; |
| 887 | var libc_paths_file: ?[]const u8 = try EnvVar.ZIG_LIBC.get(arena); | 886 | var libc_paths_file: ?[]const u8 = try EnvVar.ZIG_LIBC.get(arena); |
| 888 | var machine_code_model: std.builtin.CodeModel = .default; | 887 | var machine_code_model: std.builtin.CodeModel = .default; |
| ... | @@ -1551,7 +1550,7 @@ fn buildOutputType( | ... | @@ -1551,7 +1550,7 @@ fn buildOutputType( |
| 1551 | build_id = .fast; | 1550 | build_id = .fast; |
| 1552 | } else if (mem.startsWith(u8, arg, "--build-id=")) { | 1551 | } else if (mem.startsWith(u8, arg, "--build-id=")) { |
| 1553 | const style = arg["--build-id=".len..]; | 1552 | const style = arg["--build-id=".len..]; |
| 1554 | build_id = BuildId.parse(style) catch |err| { | 1553 | build_id = std.zig.BuildId.parse(style) catch |err| { |
| 1555 | fatal("unable to parse --build-id style '{s}': {s}", .{ | 1554 | fatal("unable to parse --build-id style '{s}': {s}", .{ |
| 1556 | style, @errorName(err), | 1555 | style, @errorName(err), |
| 1557 | }); | 1556 | }); |
| ... | @@ -1847,7 +1846,7 @@ fn buildOutputType( | ... | @@ -1847,7 +1846,7 @@ fn buildOutputType( |
| 1847 | const key = linker_arg[0..equals_pos]; | 1846 | const key = linker_arg[0..equals_pos]; |
| 1848 | const value = linker_arg[equals_pos + 1 ..]; | 1847 | const value = linker_arg[equals_pos + 1 ..]; |
| 1849 | if (mem.eql(u8, key, "--build-id")) { | 1848 | if (mem.eql(u8, key, "--build-id")) { |
| 1850 | build_id = BuildId.parse(value) catch |err| { | 1849 | build_id = std.zig.BuildId.parse(value) catch |err| { |
| 1851 | fatal("unable to parse --build-id style '{s}': {s}", .{ | 1850 | fatal("unable to parse --build-id style '{s}': {s}", .{ |
| 1852 | value, @errorName(err), | 1851 | value, @errorName(err), |
| 1853 | }); | 1852 | }); |
test/behavior/eval.zig+10-10| ... | @@ -876,27 +876,27 @@ test "two comptime calls with array default initialized to undefined" { | ... | @@ -876,27 +876,27 @@ test "two comptime calls with array default initialized to undefined" { |
| 876 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 876 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 877 | 877 | ||
| 878 | const S = struct { | 878 | const S = struct { |
| 879 | const CrossTarget = struct { | 879 | const A = struct { |
| 880 | dynamic_linker: DynamicLinker = DynamicLinker{}, | 880 | c: B = B{}, |
| 881 | 881 | ||
| 882 | pub fn parse() void { | 882 | pub fn d() void { |
| 883 | var result: CrossTarget = .{}; | 883 | var f: A = .{}; |
| 884 | result.getCpuArch(); | 884 | f.e(); |
| 885 | } | 885 | } |
| 886 | 886 | ||
| 887 | pub fn getCpuArch(self: CrossTarget) void { | 887 | pub fn e(g: A) void { |
| 888 | _ = self; | 888 | _ = g; |
| 889 | } | 889 | } |
| 890 | }; | 890 | }; |
| 891 | 891 | ||
| 892 | const DynamicLinker = struct { | 892 | const B = struct { |
| 893 | buffer: [255]u8 = undefined, | 893 | buffer: [255]u8 = undefined, |
| 894 | }; | 894 | }; |
| 895 | }; | 895 | }; |
| 896 | 896 | ||
| 897 | comptime { | 897 | comptime { |
| 898 | S.CrossTarget.parse(); | 898 | S.A.d(); |
| 899 | S.CrossTarget.parse(); | 899 | S.A.d(); |
| 900 | } | 900 | } |
| 901 | } | 901 | } |
| 902 | 902 |
test/cases.zig+5-5| ... | @@ -9,9 +9,9 @@ pub const BuildOptions = struct { | ... | @@ -9,9 +9,9 @@ pub const BuildOptions = struct { |
| 9 | llvm_has_xtensa: bool, | 9 | llvm_has_xtensa: bool, |
| 10 | }; | 10 | }; |
| 11 | 11 | ||
| 12 | pub fn addCases(cases: *Cases, build_options: BuildOptions) !void { | 12 | pub fn addCases(cases: *Cases, build_options: BuildOptions, b: *std.Build) !void { |
| 13 | try @import("compile_errors.zig").addCases(cases); | 13 | try @import("compile_errors.zig").addCases(cases, b); |
| 14 | try @import("cbe.zig").addCases(cases); | 14 | try @import("cbe.zig").addCases(cases, b); |
| 15 | try @import("llvm_targets.zig").addCases(cases, build_options); | 15 | try @import("llvm_targets.zig").addCases(cases, build_options, b); |
| 16 | try @import("nvptx.zig").addCases(cases); | 16 | try @import("nvptx.zig").addCases(cases, b); |
| 17 | } | 17 | } |
test/cbe.zig+24-24| ... | @@ -2,16 +2,16 @@ const std = @import("std"); | ... | @@ -2,16 +2,16 @@ const std = @import("std"); |
| 2 | const Cases = @import("src/Cases.zig"); | 2 | const Cases = @import("src/Cases.zig"); |
| 3 | const nl = if (@import("builtin").os.tag == .windows) "\r\n" else "\n"; | 3 | const nl = if (@import("builtin").os.tag == .windows) "\r\n" else "\n"; |
| 4 | 4 | ||
| 5 | // These tests should work with all platforms, but we're using linux_x64 for | 5 | pub fn addCases(ctx: *Cases, b: *std.Build) !void { |
| 6 | // now for consistency. Will be expanded eventually. | 6 | // These tests should work with all platforms, but we're using linux_x64 for |
| 7 | const linux_x64 = std.zig.CrossTarget{ | 7 | // now for consistency. Will be expanded eventually. |
| 8 | .cpu_arch = .x86_64, | 8 | const linux_x64: std.zig.CrossTarget = .{ |
| 9 | .os_tag = .linux, | 9 | .cpu_arch = .x86_64, |
| 10 | }; | 10 | .os_tag = .linux, |
| 11 | 11 | }; | |
| 12 | pub fn addCases(ctx: *Cases) !void { | 12 | |
| 13 | { | 13 | { |
| 14 | var case = ctx.exeFromCompiledC("hello world with updates", .{}); | 14 | var case = ctx.exeFromCompiledC("hello world with updates", .{}, b); |
| 15 | 15 | ||
| 16 | // Regular old hello world | 16 | // Regular old hello world |
| 17 | case.addCompareOutput( | 17 | case.addCompareOutput( |
| ... | @@ -59,7 +59,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -59,7 +59,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | { | 61 | { |
| 62 | var case = ctx.exeFromCompiledC("var args", .{}); | 62 | var case = ctx.exeFromCompiledC("var args", .{}, b); |
| 63 | 63 | ||
| 64 | case.addCompareOutput( | 64 | case.addCompareOutput( |
| 65 | \\extern fn printf(format: [*:0]const u8, ...) c_int; | 65 | \\extern fn printf(format: [*:0]const u8, ...) c_int; |
| ... | @@ -72,7 +72,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -72,7 +72,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | { | 74 | { |
| 75 | var case = ctx.exeFromCompiledC("errorFromInt", .{}); | 75 | var case = ctx.exeFromCompiledC("errorFromInt", .{}, b); |
| 76 | 76 | ||
| 77 | case.addCompareOutput( | 77 | case.addCompareOutput( |
| 78 | \\pub export fn main() c_int { | 78 | \\pub export fn main() c_int { |
| ... | @@ -108,7 +108,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -108,7 +108,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | { | 110 | { |
| 111 | var case = ctx.exeFromCompiledC("x86_64-linux inline assembly", linux_x64); | 111 | var case = ctx.exeFromCompiledC("x86_64-linux inline assembly", linux_x64, b); |
| 112 | 112 | ||
| 113 | // Exit with 0 | 113 | // Exit with 0 |
| 114 | case.addCompareOutput( | 114 | case.addCompareOutput( |
| ... | @@ -202,7 +202,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -202,7 +202,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | { | 204 | { |
| 205 | var case = ctx.exeFromCompiledC("alloc and retptr", .{}); | 205 | var case = ctx.exeFromCompiledC("alloc and retptr", .{}, b); |
| 206 | 206 | ||
| 207 | case.addCompareOutput( | 207 | case.addCompareOutput( |
| 208 | \\fn add(a: i32, b: i32) i32 { | 208 | \\fn add(a: i32, b: i32) i32 { |
| ... | @@ -220,7 +220,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -220,7 +220,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 220 | } | 220 | } |
| 221 | 221 | ||
| 222 | { | 222 | { |
| 223 | var case = ctx.exeFromCompiledC("inferred local const and var", .{}); | 223 | var case = ctx.exeFromCompiledC("inferred local const and var", .{}, b); |
| 224 | 224 | ||
| 225 | case.addCompareOutput( | 225 | case.addCompareOutput( |
| 226 | \\fn add(a: i32, b: i32) i32 { | 226 | \\fn add(a: i32, b: i32) i32 { |
| ... | @@ -236,7 +236,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -236,7 +236,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 236 | , ""); | 236 | , ""); |
| 237 | } | 237 | } |
| 238 | { | 238 | { |
| 239 | var case = ctx.exeFromCompiledC("control flow", .{}); | 239 | var case = ctx.exeFromCompiledC("control flow", .{}, b); |
| 240 | 240 | ||
| 241 | // Simple while loop | 241 | // Simple while loop |
| 242 | case.addCompareOutput( | 242 | case.addCompareOutput( |
| ... | @@ -423,7 +423,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -423,7 +423,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 423 | }); | 423 | }); |
| 424 | } | 424 | } |
| 425 | //{ | 425 | //{ |
| 426 | // var case = ctx.exeFromCompiledC("optionals", .{}); | 426 | // var case = ctx.exeFromCompiledC("optionals", .{}, b); |
| 427 | 427 | ||
| 428 | // // Simple while loop | 428 | // // Simple while loop |
| 429 | // case.addCompareOutput( | 429 | // case.addCompareOutput( |
| ... | @@ -451,7 +451,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -451,7 +451,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 451 | //} | 451 | //} |
| 452 | 452 | ||
| 453 | { | 453 | { |
| 454 | var case = ctx.exeFromCompiledC("errors", .{}); | 454 | var case = ctx.exeFromCompiledC("errors", .{}, b); |
| 455 | case.addCompareOutput( | 455 | case.addCompareOutput( |
| 456 | \\pub export fn main() c_int { | 456 | \\pub export fn main() c_int { |
| 457 | \\ var e1 = error.Foo; | 457 | \\ var e1 = error.Foo; |
| ... | @@ -495,7 +495,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -495,7 +495,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 495 | } | 495 | } |
| 496 | 496 | ||
| 497 | { | 497 | { |
| 498 | var case = ctx.exeFromCompiledC("structs", .{}); | 498 | var case = ctx.exeFromCompiledC("structs", .{}, b); |
| 499 | case.addError( | 499 | case.addError( |
| 500 | \\const Point = struct { x: i32, y: i32 }; | 500 | \\const Point = struct { x: i32, y: i32 }; |
| 501 | \\pub export fn main() c_int { | 501 | \\pub export fn main() c_int { |
| ... | @@ -562,7 +562,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -562,7 +562,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 562 | } | 562 | } |
| 563 | 563 | ||
| 564 | { | 564 | { |
| 565 | var case = ctx.exeFromCompiledC("unions", .{}); | 565 | var case = ctx.exeFromCompiledC("unions", .{}, b); |
| 566 | 566 | ||
| 567 | case.addError( | 567 | case.addError( |
| 568 | \\const U = union { | 568 | \\const U = union { |
| ... | @@ -596,7 +596,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -596,7 +596,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 596 | } | 596 | } |
| 597 | 597 | ||
| 598 | { | 598 | { |
| 599 | var case = ctx.exeFromCompiledC("enums", .{}); | 599 | var case = ctx.exeFromCompiledC("enums", .{}, b); |
| 600 | 600 | ||
| 601 | case.addError( | 601 | case.addError( |
| 602 | \\const E1 = packed enum { a, b, c }; | 602 | \\const E1 = packed enum { a, b, c }; |
| ... | @@ -838,7 +838,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -838,7 +838,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 838 | } | 838 | } |
| 839 | 839 | ||
| 840 | { | 840 | { |
| 841 | var case = ctx.exeFromCompiledC("shift right and left", .{}); | 841 | var case = ctx.exeFromCompiledC("shift right and left", .{}, b); |
| 842 | case.addCompareOutput( | 842 | case.addCompareOutput( |
| 843 | \\pub export fn main() c_int { | 843 | \\pub export fn main() c_int { |
| 844 | \\ var i: u32 = 16; | 844 | \\ var i: u32 = 16; |
| ... | @@ -863,7 +863,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -863,7 +863,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 863 | } | 863 | } |
| 864 | 864 | ||
| 865 | { | 865 | { |
| 866 | var case = ctx.exeFromCompiledC("inferred error sets", .{}); | 866 | var case = ctx.exeFromCompiledC("inferred error sets", .{}, b); |
| 867 | 867 | ||
| 868 | case.addCompareOutput( | 868 | case.addCompareOutput( |
| 869 | \\pub export fn main() c_int { | 869 | \\pub export fn main() c_int { |
| ... | @@ -884,7 +884,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -884,7 +884,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 884 | 884 | ||
| 885 | { | 885 | { |
| 886 | // TODO: add u64 tests, ran into issues with the literal generated for std.math.maxInt(u64) | 886 | // TODO: add u64 tests, ran into issues with the literal generated for std.math.maxInt(u64) |
| 887 | var case = ctx.exeFromCompiledC("add and sub wrapping operations", .{}); | 887 | var case = ctx.exeFromCompiledC("add and sub wrapping operations", .{}, b); |
| 888 | case.addCompareOutput( | 888 | case.addCompareOutput( |
| 889 | \\pub export fn main() c_int { | 889 | \\pub export fn main() c_int { |
| 890 | \\ // Addition | 890 | \\ // Addition |
| ... | @@ -933,7 +933,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -933,7 +933,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 933 | } | 933 | } |
| 934 | 934 | ||
| 935 | { | 935 | { |
| 936 | var case = ctx.exeFromCompiledC("rem", linux_x64); | 936 | var case = ctx.exeFromCompiledC("rem", linux_x64, b); |
| 937 | case.addCompareOutput( | 937 | case.addCompareOutput( |
| 938 | \\fn assert(ok: bool) void { | 938 | \\fn assert(ok: bool) void { |
| 939 | \\ if (!ok) unreachable; | 939 | \\ if (!ok) unreachable; |
test/compile_errors.zig+11-11| ... | @@ -2,9 +2,9 @@ const std = @import("std"); | ... | @@ -2,9 +2,9 @@ const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | const Cases = @import("src/Cases.zig"); | 3 | const Cases = @import("src/Cases.zig"); |
| 4 | 4 | ||
| 5 | pub fn addCases(ctx: *Cases) !void { | 5 | pub fn addCases(ctx: *Cases, b: *std.Build) !void { |
| 6 | { | 6 | { |
| 7 | const case = ctx.obj("multiline error messages", .{}); | 7 | const case = ctx.obj("multiline error messages", b.host); |
| 8 | 8 | ||
| 9 | case.addError( | 9 | case.addError( |
| 10 | \\comptime { | 10 | \\comptime { |
| ... | @@ -39,7 +39,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -39,7 +39,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | { | 41 | { |
| 42 | const case = ctx.obj("isolated carriage return in multiline string literal", .{}); | 42 | const case = ctx.obj("isolated carriage return in multiline string literal", b.host); |
| 43 | 43 | ||
| 44 | case.addError("const foo = \\\\\test\r\r rogue carriage return\n;", &[_][]const u8{ | 44 | case.addError("const foo = \\\\\test\r\r rogue carriage return\n;", &[_][]const u8{ |
| 45 | ":1:19: error: expected ';' after declaration", | 45 | ":1:19: error: expected ';' after declaration", |
| ... | @@ -48,7 +48,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -48,7 +48,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | { | 50 | { |
| 51 | const case = ctx.obj("missing semicolon at EOF", .{}); | 51 | const case = ctx.obj("missing semicolon at EOF", b.host); |
| 52 | case.addError( | 52 | case.addError( |
| 53 | \\const foo = 1 | 53 | \\const foo = 1 |
| 54 | , &[_][]const u8{ | 54 | , &[_][]const u8{ |
| ... | @@ -57,7 +57,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -57,7 +57,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | { | 59 | { |
| 60 | const case = ctx.obj("argument causes error", .{}); | 60 | const case = ctx.obj("argument causes error", b.host); |
| 61 | 61 | ||
| 62 | case.addError( | 62 | case.addError( |
| 63 | \\pub export fn entry() void { | 63 | \\pub export fn entry() void { |
| ... | @@ -80,7 +80,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -80,7 +80,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | { | 82 | { |
| 83 | const case = ctx.obj("astgen failure in file struct", .{}); | 83 | const case = ctx.obj("astgen failure in file struct", b.host); |
| 84 | 84 | ||
| 85 | case.addError( | 85 | case.addError( |
| 86 | \\pub export fn entry() void { | 86 | \\pub export fn entry() void { |
| ... | @@ -95,7 +95,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -95,7 +95,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | { | 97 | { |
| 98 | const case = ctx.obj("invalid store to comptime field", .{}); | 98 | const case = ctx.obj("invalid store to comptime field", b.host); |
| 99 | 99 | ||
| 100 | case.addError( | 100 | case.addError( |
| 101 | \\const a = @import("a.zig"); | 101 | \\const a = @import("a.zig"); |
| ... | @@ -119,7 +119,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -119,7 +119,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | { | 121 | { |
| 122 | const case = ctx.obj("file in multiple modules", .{}); | 122 | const case = ctx.obj("file in multiple modules", b.host); |
| 123 | case.addDepModule("foo", "foo.zig"); | 123 | case.addDepModule("foo", "foo.zig"); |
| 124 | 124 | ||
| 125 | case.addError( | 125 | case.addError( |
| ... | @@ -138,7 +138,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -138,7 +138,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | { | 140 | { |
| 141 | const case = ctx.obj("wrong same named struct", .{}); | 141 | const case = ctx.obj("wrong same named struct", b.host); |
| 142 | 142 | ||
| 143 | case.addError( | 143 | case.addError( |
| 144 | \\const a = @import("a.zig"); | 144 | \\const a = @import("a.zig"); |
| ... | @@ -172,7 +172,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -172,7 +172,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | { | 174 | { |
| 175 | const case = ctx.obj("non-printable invalid character", .{}); | 175 | const case = ctx.obj("non-printable invalid character", b.host); |
| 176 | 176 | ||
| 177 | case.addError("\xff\xfe" ++ | 177 | case.addError("\xff\xfe" ++ |
| 178 | \\export fn foo() bool { | 178 | \\export fn foo() bool { |
| ... | @@ -185,7 +185,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -185,7 +185,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | { | 187 | { |
| 188 | const case = ctx.obj("imported generic method call with invalid param", .{}); | 188 | const case = ctx.obj("imported generic method call with invalid param", b.host); |
| 189 | 189 | ||
| 190 | case.addError( | 190 | case.addError( |
| 191 | \\pub const import = @import("import.zig"); | 191 | \\pub const import = @import("import.zig"); |
test/link/bss/build.zig+1| ... | @@ -7,6 +7,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -7,6 +7,7 @@ pub fn build(b: *std.Build) void { |
| 7 | const exe = b.addExecutable(.{ | 7 | const exe = b.addExecutable(.{ |
| 8 | .name = "bss", | 8 | .name = "bss", |
| 9 | .root_source_file = .{ .path = "main.zig" }, | 9 | .root_source_file = .{ .path = "main.zig" }, |
| 10 | .target = b.host, | ||
| 10 | .optimize = .Debug, | 11 | .optimize = .Debug, |
| 11 | }); | 12 | }); |
| 12 | 13 |
test/link/common_symbols/build.zig+1-1| ... | @@ -14,7 +14,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -14,7 +14,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 14 | const lib_a = b.addStaticLibrary(.{ | 14 | const lib_a = b.addStaticLibrary(.{ |
| 15 | .name = "a", | 15 | .name = "a", |
| 16 | .optimize = optimize, | 16 | .optimize = optimize, |
| 17 | .target = .{}, | 17 | .target = b.host, |
| 18 | }); | 18 | }); |
| 19 | lib_a.addCSourceFiles(.{ | 19 | lib_a.addCSourceFiles(.{ |
| 20 | .files = &.{ "c.c", "a.c", "b.c" }, | 20 | .files = &.{ "c.c", "a.c", "b.c" }, |
test/link/common_symbols_alignment/build.zig+1-1| ... | @@ -14,7 +14,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -14,7 +14,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 14 | const lib_a = b.addStaticLibrary(.{ | 14 | const lib_a = b.addStaticLibrary(.{ |
| 15 | .name = "a", | 15 | .name = "a", |
| 16 | .optimize = optimize, | 16 | .optimize = optimize, |
| 17 | .target = .{}, | 17 | .target = b.host, |
| 18 | }); | 18 | }); |
| 19 | lib_a.addCSourceFiles(.{ | 19 | lib_a.addCSourceFiles(.{ |
| 20 | .files = &.{"a.c"}, | 20 | .files = &.{"a.c"}, |
test/link/elf.zig+656-441| ... | @@ -5,20 +5,20 @@ | ... | @@ -5,20 +5,20 @@ |
| 5 | pub fn testAll(b: *Build) *Step { | 5 | pub fn testAll(b: *Build) *Step { |
| 6 | const elf_step = b.step("test-elf", "Run ELF tests"); | 6 | const elf_step = b.step("test-elf", "Run ELF tests"); |
| 7 | 7 | ||
| 8 | const default_target = CrossTarget{ | 8 | const default_target = b.resolveTargetQuery(.{ |
| 9 | .cpu_arch = .x86_64, // TODO relax this once ELF linker is able to handle other archs | 9 | .cpu_arch = .x86_64, // TODO relax this once ELF linker is able to handle other archs |
| 10 | .os_tag = .linux, | 10 | .os_tag = .linux, |
| 11 | }; | 11 | }); |
| 12 | const musl_target = CrossTarget{ | 12 | const musl_target = b.resolveTargetQuery(.{ |
| 13 | .cpu_arch = .x86_64, | 13 | .cpu_arch = .x86_64, |
| 14 | .os_tag = .linux, | 14 | .os_tag = .linux, |
| 15 | .abi = .musl, | 15 | .abi = .musl, |
| 16 | }; | 16 | }); |
| 17 | const glibc_target = CrossTarget{ | 17 | const glibc_target = b.resolveTargetQuery(.{ |
| 18 | .cpu_arch = .x86_64, | 18 | .cpu_arch = .x86_64, |
| 19 | .os_tag = .linux, | 19 | .os_tag = .linux, |
| 20 | .abi = .gnu, | 20 | .abi = .gnu, |
| 21 | }; | 21 | }); |
| 22 | 22 | ||
| 23 | // Exercise linker in -r mode | 23 | // Exercise linker in -r mode |
| 24 | elf_step.dependOn(testEmitRelocatable(b, .{ .use_llvm = false, .target = musl_target })); | 24 | elf_step.dependOn(testEmitRelocatable(b, .{ .use_llvm = false, .target = musl_target })); |
| ... | @@ -132,14 +132,18 @@ pub fn testAll(b: *Build) *Step { | ... | @@ -132,14 +132,18 @@ pub fn testAll(b: *Build) *Step { |
| 132 | fn testAbsSymbols(b: *Build, opts: Options) *Step { | 132 | fn testAbsSymbols(b: *Build, opts: Options) *Step { |
| 133 | const test_step = addTestStep(b, "abs-symbols", opts); | 133 | const test_step = addTestStep(b, "abs-symbols", opts); |
| 134 | 134 | ||
| 135 | const obj = addObject(b, "obj", opts); | 135 | const obj = addObject(b, opts, .{ |
| 136 | addAsmSourceBytes(obj, | 136 | .name = "obj", |
| 137 | .asm_source_bytes = | ||
| 137 | \\.globl foo | 138 | \\.globl foo |
| 138 | \\foo = 0x800008 | 139 | \\foo = 0x800008 |
| 139 | ); | 140 | \\ |
| 141 | , | ||
| 142 | }); | ||
| 140 | 143 | ||
| 141 | const exe = addExecutable(b, "test", opts); | 144 | const exe = addExecutable(b, opts, .{ |
| 142 | addCSourceBytes(exe, | 145 | .name = "test", |
| 146 | .c_source_bytes = | ||
| 143 | \\#include <signal.h> | 147 | \\#include <signal.h> |
| 144 | \\#include <stdio.h> | 148 | \\#include <stdio.h> |
| 145 | \\#include <stdlib.h> | 149 | \\#include <stdlib.h> |
| ... | @@ -159,7 +163,8 @@ fn testAbsSymbols(b: *Build, opts: Options) *Step { | ... | @@ -159,7 +163,8 @@ fn testAbsSymbols(b: *Build, opts: Options) *Step { |
| 159 | \\ foo = 5; | 163 | \\ foo = 5; |
| 160 | \\ return 0; | 164 | \\ return 0; |
| 161 | \\} | 165 | \\} |
| 162 | , &.{}); | 166 | , |
| 167 | }); | ||
| 163 | exe.addObject(obj); | 168 | exe.addObject(obj); |
| 164 | exe.linkLibC(); | 169 | exe.linkLibC(); |
| 165 | 170 | ||
| ... | @@ -173,31 +178,36 @@ fn testAbsSymbols(b: *Build, opts: Options) *Step { | ... | @@ -173,31 +178,36 @@ fn testAbsSymbols(b: *Build, opts: Options) *Step { |
| 173 | fn testAsNeeded(b: *Build, opts: Options) *Step { | 178 | fn testAsNeeded(b: *Build, opts: Options) *Step { |
| 174 | const test_step = addTestStep(b, "as-needed", opts); | 179 | const test_step = addTestStep(b, "as-needed", opts); |
| 175 | 180 | ||
| 176 | const main_o = addObject(b, "main", opts); | 181 | const main_o = addObject(b, opts, .{ |
| 177 | addCSourceBytes(main_o, | 182 | .name = "main", |
| 183 | .c_source_bytes = | ||
| 178 | \\#include <stdio.h> | 184 | \\#include <stdio.h> |
| 179 | \\int baz(); | 185 | \\int baz(); |
| 180 | \\int main() { | 186 | \\int main() { |
| 181 | \\ printf("%d\n", baz()); | 187 | \\ printf("%d\n", baz()); |
| 182 | \\ return 0; | 188 | \\ return 0; |
| 183 | \\} | 189 | \\} |
| 184 | , &.{}); | 190 | \\ |
| 191 | , | ||
| 192 | }); | ||
| 185 | main_o.linkLibC(); | 193 | main_o.linkLibC(); |
| 186 | 194 | ||
| 187 | const libfoo = addSharedLibrary(b, "foo", opts); | 195 | const libfoo = addSharedLibrary(b, opts, .{ .name = "foo" }); |
| 188 | addCSourceBytes(libfoo, "int foo() { return 42; }", &.{}); | 196 | addCSourceBytes(libfoo, "int foo() { return 42; }", &.{}); |
| 189 | 197 | ||
| 190 | const libbar = addSharedLibrary(b, "bar", opts); | 198 | const libbar = addSharedLibrary(b, opts, .{ .name = "bar" }); |
| 191 | addCSourceBytes(libbar, "int bar() { return 42; }", &.{}); | 199 | addCSourceBytes(libbar, "int bar() { return 42; }", &.{}); |
| 192 | 200 | ||
| 193 | const libbaz = addSharedLibrary(b, "baz", opts); | 201 | const libbaz = addSharedLibrary(b, opts, .{ .name = "baz" }); |
| 194 | addCSourceBytes(libbaz, | 202 | addCSourceBytes(libbaz, |
| 195 | \\int foo(); | 203 | \\int foo(); |
| 196 | \\int baz() { return foo(); } | 204 | \\int baz() { return foo(); } |
| 197 | , &.{}); | 205 | , &.{}); |
| 198 | 206 | ||
| 199 | { | 207 | { |
| 200 | const exe = addExecutable(b, "test", opts); | 208 | const exe = addExecutable(b, opts, .{ |
| 209 | .name = "test", | ||
| 210 | }); | ||
| 201 | exe.addObject(main_o); | 211 | exe.addObject(main_o); |
| 202 | exe.linkSystemLibrary2("foo", .{ .needed = true }); | 212 | exe.linkSystemLibrary2("foo", .{ .needed = true }); |
| 203 | exe.addLibraryPath(libfoo.getEmittedBinDirectory()); | 213 | exe.addLibraryPath(libfoo.getEmittedBinDirectory()); |
| ... | @@ -225,7 +235,9 @@ fn testAsNeeded(b: *Build, opts: Options) *Step { | ... | @@ -225,7 +235,9 @@ fn testAsNeeded(b: *Build, opts: Options) *Step { |
| 225 | } | 235 | } |
| 226 | 236 | ||
| 227 | { | 237 | { |
| 228 | const exe = addExecutable(b, "test", opts); | 238 | const exe = addExecutable(b, opts, .{ |
| 239 | .name = "test", | ||
| 240 | }); | ||
| 229 | exe.addObject(main_o); | 241 | exe.addObject(main_o); |
| 230 | exe.linkSystemLibrary2("foo", .{ .needed = false }); | 242 | exe.linkSystemLibrary2("foo", .{ .needed = false }); |
| 231 | exe.addLibraryPath(libfoo.getEmittedBinDirectory()); | 243 | exe.addLibraryPath(libfoo.getEmittedBinDirectory()); |
| ... | @@ -259,7 +271,7 @@ fn testAsNeeded(b: *Build, opts: Options) *Step { | ... | @@ -259,7 +271,7 @@ fn testAsNeeded(b: *Build, opts: Options) *Step { |
| 259 | fn testCanonicalPlt(b: *Build, opts: Options) *Step { | 271 | fn testCanonicalPlt(b: *Build, opts: Options) *Step { |
| 260 | const test_step = addTestStep(b, "canonical-plt", opts); | 272 | const test_step = addTestStep(b, "canonical-plt", opts); |
| 261 | 273 | ||
| 262 | const dso = addSharedLibrary(b, "a", opts); | 274 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 263 | addCSourceBytes(dso, | 275 | addCSourceBytes(dso, |
| 264 | \\void *foo() { | 276 | \\void *foo() { |
| 265 | \\ return foo; | 277 | \\ return foo; |
| ... | @@ -269,17 +281,21 @@ fn testCanonicalPlt(b: *Build, opts: Options) *Step { | ... | @@ -269,17 +281,21 @@ fn testCanonicalPlt(b: *Build, opts: Options) *Step { |
| 269 | \\} | 281 | \\} |
| 270 | , &.{}); | 282 | , &.{}); |
| 271 | 283 | ||
| 272 | const b_o = addObject(b, "obj", opts); | 284 | const b_o = addObject(b, opts, .{ |
| 273 | addCSourceBytes(b_o, | 285 | .name = "obj", |
| 286 | .c_source_bytes = | ||
| 274 | \\void *bar(); | 287 | \\void *bar(); |
| 275 | \\void *baz() { | 288 | \\void *baz() { |
| 276 | \\ return bar; | 289 | \\ return bar; |
| 277 | \\} | 290 | \\} |
| 278 | , &.{}); | 291 | \\ |
| 279 | b_o.force_pic = true; | 292 | , |
| 293 | .pic = true, | ||
| 294 | }); | ||
| 280 | 295 | ||
| 281 | const main_o = addObject(b, "main", opts); | 296 | const main_o = addObject(b, opts, .{ |
| 282 | addCSourceBytes(main_o, | 297 | .name = "main", |
| 298 | .c_source_bytes = | ||
| 283 | \\#include <assert.h> | 299 | \\#include <assert.h> |
| 284 | \\void *foo(); | 300 | \\void *foo(); |
| 285 | \\void *bar(); | 301 | \\void *bar(); |
| ... | @@ -290,11 +306,15 @@ fn testCanonicalPlt(b: *Build, opts: Options) *Step { | ... | @@ -290,11 +306,15 @@ fn testCanonicalPlt(b: *Build, opts: Options) *Step { |
| 290 | \\ assert(bar == baz()); | 306 | \\ assert(bar == baz()); |
| 291 | \\ return 0; | 307 | \\ return 0; |
| 292 | \\} | 308 | \\} |
| 293 | , &.{}); | 309 | \\ |
| 310 | , | ||
| 311 | .pic = false, | ||
| 312 | }); | ||
| 294 | main_o.linkLibC(); | 313 | main_o.linkLibC(); |
| 295 | main_o.force_pic = false; | ||
| 296 | 314 | ||
| 297 | const exe = addExecutable(b, "main", opts); | 315 | const exe = addExecutable(b, opts, .{ |
| 316 | .name = "main", | ||
| 317 | }); | ||
| 298 | exe.addObject(main_o); | 318 | exe.addObject(main_o); |
| 299 | exe.addObject(b_o); | 319 | exe.addObject(b_o); |
| 300 | exe.linkLibrary(dso); | 320 | exe.linkLibrary(dso); |
| ... | @@ -311,7 +331,9 @@ fn testCanonicalPlt(b: *Build, opts: Options) *Step { | ... | @@ -311,7 +331,9 @@ fn testCanonicalPlt(b: *Build, opts: Options) *Step { |
| 311 | fn testCommonSymbols(b: *Build, opts: Options) *Step { | 331 | fn testCommonSymbols(b: *Build, opts: Options) *Step { |
| 312 | const test_step = addTestStep(b, "common-symbols", opts); | 332 | const test_step = addTestStep(b, "common-symbols", opts); |
| 313 | 333 | ||
| 314 | const exe = addExecutable(b, "test", opts); | 334 | const exe = addExecutable(b, opts, .{ |
| 335 | .name = "test", | ||
| 336 | }); | ||
| 315 | addCSourceBytes(exe, | 337 | addCSourceBytes(exe, |
| 316 | \\int foo; | 338 | \\int foo; |
| 317 | \\int bar; | 339 | \\int bar; |
| ... | @@ -338,8 +360,9 @@ fn testCommonSymbols(b: *Build, opts: Options) *Step { | ... | @@ -338,8 +360,9 @@ fn testCommonSymbols(b: *Build, opts: Options) *Step { |
| 338 | fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step { | 360 | fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step { |
| 339 | const test_step = addTestStep(b, "common-symbols-in-archive", opts); | 361 | const test_step = addTestStep(b, "common-symbols-in-archive", opts); |
| 340 | 362 | ||
| 341 | const a_o = addObject(b, "a", opts); | 363 | const a_o = addObject(b, opts, .{ |
| 342 | addCSourceBytes(a_o, | 364 | .name = "a", |
| 365 | .c_source_bytes = | ||
| 343 | \\#include <stdio.h> | 366 | \\#include <stdio.h> |
| 344 | \\int foo; | 367 | \\int foo; |
| 345 | \\int bar; | 368 | \\int bar; |
| ... | @@ -348,28 +371,43 @@ fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step { | ... | @@ -348,28 +371,43 @@ fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step { |
| 348 | \\int main() { | 371 | \\int main() { |
| 349 | \\ printf("%d %d %d %d\n", foo, bar, baz, two ? two() : -1); | 372 | \\ printf("%d %d %d %d\n", foo, bar, baz, two ? two() : -1); |
| 350 | \\} | 373 | \\} |
| 351 | , &.{"-fcommon"}); | 374 | \\ |
| 375 | , | ||
| 376 | .c_source_flags = &.{"-fcommon"}, | ||
| 377 | }); | ||
| 352 | a_o.linkLibC(); | 378 | a_o.linkLibC(); |
| 353 | 379 | ||
| 354 | const b_o = addObject(b, "b", opts); | 380 | const b_o = addObject(b, opts, .{ |
| 355 | addCSourceBytes(b_o, "int foo = 5;", &.{"-fcommon"}); | 381 | .name = "b", |
| 382 | .c_source_bytes = "int foo = 5;", | ||
| 383 | .c_source_flags = &.{"-fcommon"}, | ||
| 384 | }); | ||
| 356 | 385 | ||
| 357 | { | 386 | { |
| 358 | const c_o = addObject(b, "c", opts); | 387 | const c_o = addObject(b, opts, .{ |
| 359 | addCSourceBytes(c_o, | 388 | .name = "c", |
| 389 | .c_source_bytes = | ||
| 360 | \\int bar; | 390 | \\int bar; |
| 361 | \\int two() { return 2; } | 391 | \\int two() { return 2; } |
| 362 | , &.{"-fcommon"}); | 392 | \\ |
| 363 | 393 | , | |
| 364 | const d_o = addObject(b, "d", opts); | 394 | .c_source_flags = &.{"-fcommon"}, |
| 365 | addCSourceBytes(d_o, "int baz;", &.{"-fcommon"}); | 395 | }); |
| 366 | 396 | ||
| 367 | const lib = addStaticLibrary(b, "lib", opts); | 397 | const d_o = addObject(b, opts, .{ |
| 398 | .name = "d", | ||
| 399 | .c_source_bytes = "int baz;", | ||
| 400 | .c_source_flags = &.{"-fcommon"}, | ||
| 401 | }); | ||
| 402 | |||
| 403 | const lib = addStaticLibrary(b, opts, .{ .name = "lib" }); | ||
| 368 | lib.addObject(b_o); | 404 | lib.addObject(b_o); |
| 369 | lib.addObject(c_o); | 405 | lib.addObject(c_o); |
| 370 | lib.addObject(d_o); | 406 | lib.addObject(d_o); |
| 371 | 407 | ||
| 372 | const exe = addExecutable(b, "test", opts); | 408 | const exe = addExecutable(b, opts, .{ |
| 409 | .name = "test", | ||
| 410 | }); | ||
| 373 | exe.addObject(a_o); | 411 | exe.addObject(a_o); |
| 374 | exe.linkLibrary(lib); | 412 | exe.linkLibrary(lib); |
| 375 | exe.linkLibC(); | 413 | exe.linkLibC(); |
| ... | @@ -380,18 +418,23 @@ fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step { | ... | @@ -380,18 +418,23 @@ fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step { |
| 380 | } | 418 | } |
| 381 | 419 | ||
| 382 | { | 420 | { |
| 383 | const e_o = addObject(b, "e", opts); | 421 | const e_o = addObject(b, opts, .{ |
| 384 | addCSourceBytes(e_o, | 422 | .name = "e", |
| 423 | .c_source_bytes = | ||
| 385 | \\int bar = 0; | 424 | \\int bar = 0; |
| 386 | \\int baz = 7; | 425 | \\int baz = 7; |
| 387 | \\int two() { return 2; } | 426 | \\int two() { return 2; } |
| 388 | , &.{"-fcommon"}); | 427 | , |
| 428 | .c_source_flags = &.{"-fcommon"}, | ||
| 429 | }); | ||
| 389 | 430 | ||
| 390 | const lib = addStaticLibrary(b, "lib", opts); | 431 | const lib = addStaticLibrary(b, opts, .{ .name = "lib" }); |
| 391 | lib.addObject(b_o); | 432 | lib.addObject(b_o); |
| 392 | lib.addObject(e_o); | 433 | lib.addObject(e_o); |
| 393 | 434 | ||
| 394 | const exe = addExecutable(b, "test", opts); | 435 | const exe = addExecutable(b, opts, .{ |
| 436 | .name = "test", | ||
| 437 | }); | ||
| 395 | exe.addObject(a_o); | 438 | exe.addObject(a_o); |
| 396 | exe.linkLibrary(lib); | 439 | exe.linkLibrary(lib); |
| 397 | exe.linkLibC(); | 440 | exe.linkLibC(); |
| ... | @@ -407,21 +450,23 @@ fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step { | ... | @@ -407,21 +450,23 @@ fn testCommonSymbolsInArchive(b: *Build, opts: Options) *Step { |
| 407 | fn testCopyrel(b: *Build, opts: Options) *Step { | 450 | fn testCopyrel(b: *Build, opts: Options) *Step { |
| 408 | const test_step = addTestStep(b, "copyrel", opts); | 451 | const test_step = addTestStep(b, "copyrel", opts); |
| 409 | 452 | ||
| 410 | const dso = addSharedLibrary(b, "a", opts); | 453 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 411 | addCSourceBytes(dso, | 454 | addCSourceBytes(dso, |
| 412 | \\int foo = 3; | 455 | \\int foo = 3; |
| 413 | \\int bar = 5; | 456 | \\int bar = 5; |
| 414 | , &.{}); | 457 | , &.{}); |
| 415 | 458 | ||
| 416 | const exe = addExecutable(b, "main", opts); | 459 | const exe = addExecutable(b, opts, .{ |
| 417 | addCSourceBytes(exe, | 460 | .name = "main", |
| 461 | .c_source_bytes = | ||
| 418 | \\#include<stdio.h> | 462 | \\#include<stdio.h> |
| 419 | \\extern int foo, bar; | 463 | \\extern int foo, bar; |
| 420 | \\int main() { | 464 | \\int main() { |
| 421 | \\ printf("%d %d\n", foo, bar); | 465 | \\ printf("%d %d\n", foo, bar); |
| 422 | \\ return 0; | 466 | \\ return 0; |
| 423 | \\} | 467 | \\} |
| 424 | , &.{}); | 468 | , |
| 469 | }); | ||
| 425 | exe.linkLibrary(dso); | 470 | exe.linkLibrary(dso); |
| 426 | exe.linkLibC(); | 471 | exe.linkLibC(); |
| 427 | // https://github.com/ziglang/zig/issues/17619 | 472 | // https://github.com/ziglang/zig/issues/17619 |
| ... | @@ -437,7 +482,7 @@ fn testCopyrel(b: *Build, opts: Options) *Step { | ... | @@ -437,7 +482,7 @@ fn testCopyrel(b: *Build, opts: Options) *Step { |
| 437 | fn testCopyrelAlias(b: *Build, opts: Options) *Step { | 482 | fn testCopyrelAlias(b: *Build, opts: Options) *Step { |
| 438 | const test_step = addTestStep(b, "copyrel-alias", opts); | 483 | const test_step = addTestStep(b, "copyrel-alias", opts); |
| 439 | 484 | ||
| 440 | const dso = addSharedLibrary(b, "a", opts); | 485 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 441 | addCSourceBytes(dso, | 486 | addCSourceBytes(dso, |
| 442 | \\int bruh = 31; | 487 | \\int bruh = 31; |
| 443 | \\int foo = 42; | 488 | \\int foo = 42; |
| ... | @@ -445,7 +490,10 @@ fn testCopyrelAlias(b: *Build, opts: Options) *Step { | ... | @@ -445,7 +490,10 @@ fn testCopyrelAlias(b: *Build, opts: Options) *Step { |
| 445 | \\extern int baz __attribute__((alias("foo"))); | 490 | \\extern int baz __attribute__((alias("foo"))); |
| 446 | , &.{}); | 491 | , &.{}); |
| 447 | 492 | ||
| 448 | const exe = addExecutable(b, "main", opts); | 493 | const exe = addExecutable(b, opts, .{ |
| 494 | .name = "main", | ||
| 495 | .pic = false, | ||
| 496 | }); | ||
| 449 | addCSourceBytes(exe, | 497 | addCSourceBytes(exe, |
| 450 | \\#include<stdio.h> | 498 | \\#include<stdio.h> |
| 451 | \\extern int foo; | 499 | \\extern int foo; |
| ... | @@ -461,7 +509,6 @@ fn testCopyrelAlias(b: *Build, opts: Options) *Step { | ... | @@ -461,7 +509,6 @@ fn testCopyrelAlias(b: *Build, opts: Options) *Step { |
| 461 | , &.{}); | 509 | , &.{}); |
| 462 | exe.linkLibrary(dso); | 510 | exe.linkLibrary(dso); |
| 463 | exe.linkLibC(); | 511 | exe.linkLibC(); |
| 464 | exe.force_pic = false; | ||
| 465 | exe.pie = false; | 512 | exe.pie = false; |
| 466 | 513 | ||
| 467 | const run = addRunArtifact(exe); | 514 | const run = addRunArtifact(exe); |
| ... | @@ -474,28 +521,31 @@ fn testCopyrelAlias(b: *Build, opts: Options) *Step { | ... | @@ -474,28 +521,31 @@ fn testCopyrelAlias(b: *Build, opts: Options) *Step { |
| 474 | fn testCopyrelAlignment(b: *Build, opts: Options) *Step { | 521 | fn testCopyrelAlignment(b: *Build, opts: Options) *Step { |
| 475 | const test_step = addTestStep(b, "copyrel-alignment", opts); | 522 | const test_step = addTestStep(b, "copyrel-alignment", opts); |
| 476 | 523 | ||
| 477 | const a_so = addSharedLibrary(b, "a", opts); | 524 | const a_so = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 478 | addCSourceBytes(a_so, "__attribute__((aligned(32))) int foo = 5;", &.{}); | 525 | addCSourceBytes(a_so, "__attribute__((aligned(32))) int foo = 5;", &.{}); |
| 479 | 526 | ||
| 480 | const b_so = addSharedLibrary(b, "b", opts); | 527 | const b_so = addSharedLibrary(b, opts, .{ .name = "b" }); |
| 481 | addCSourceBytes(b_so, "__attribute__((aligned(8))) int foo = 5;", &.{}); | 528 | addCSourceBytes(b_so, "__attribute__((aligned(8))) int foo = 5;", &.{}); |
| 482 | 529 | ||
| 483 | const c_so = addSharedLibrary(b, "c", opts); | 530 | const c_so = addSharedLibrary(b, opts, .{ .name = "c" }); |
| 484 | addCSourceBytes(c_so, "__attribute__((aligned(256))) int foo = 5;", &.{}); | 531 | addCSourceBytes(c_so, "__attribute__((aligned(256))) int foo = 5;", &.{}); |
| 485 | 532 | ||
| 486 | const obj = addObject(b, "main", opts); | 533 | const obj = addObject(b, opts, .{ |
| 487 | addCSourceBytes(obj, | 534 | .name = "main", |
| 535 | .c_source_bytes = | ||
| 488 | \\#include <stdio.h> | 536 | \\#include <stdio.h> |
| 489 | \\extern int foo; | 537 | \\extern int foo; |
| 490 | \\int main() { printf("%d\n", foo); } | 538 | \\int main() { printf("%d\n", foo); } |
| 491 | , &.{}); | 539 | \\ |
| 540 | , | ||
| 541 | .pic = false, | ||
| 542 | }); | ||
| 492 | obj.linkLibC(); | 543 | obj.linkLibC(); |
| 493 | obj.force_pic = false; | ||
| 494 | 544 | ||
| 495 | const exp_stdout = "5\n"; | 545 | const exp_stdout = "5\n"; |
| 496 | 546 | ||
| 497 | { | 547 | { |
| 498 | const exe = addExecutable(b, "main", opts); | 548 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 499 | exe.addObject(obj); | 549 | exe.addObject(obj); |
| 500 | exe.linkLibrary(a_so); | 550 | exe.linkLibrary(a_so); |
| 501 | exe.linkLibC(); | 551 | exe.linkLibC(); |
| ... | @@ -514,7 +564,7 @@ fn testCopyrelAlignment(b: *Build, opts: Options) *Step { | ... | @@ -514,7 +564,7 @@ fn testCopyrelAlignment(b: *Build, opts: Options) *Step { |
| 514 | } | 564 | } |
| 515 | 565 | ||
| 516 | { | 566 | { |
| 517 | const exe = addExecutable(b, "main", opts); | 567 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 518 | exe.addObject(obj); | 568 | exe.addObject(obj); |
| 519 | exe.linkLibrary(b_so); | 569 | exe.linkLibrary(b_so); |
| 520 | exe.linkLibC(); | 570 | exe.linkLibC(); |
| ... | @@ -533,7 +583,7 @@ fn testCopyrelAlignment(b: *Build, opts: Options) *Step { | ... | @@ -533,7 +583,7 @@ fn testCopyrelAlignment(b: *Build, opts: Options) *Step { |
| 533 | } | 583 | } |
| 534 | 584 | ||
| 535 | { | 585 | { |
| 536 | const exe = addExecutable(b, "main", opts); | 586 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 537 | exe.addObject(obj); | 587 | exe.addObject(obj); |
| 538 | exe.linkLibrary(c_so); | 588 | exe.linkLibrary(c_so); |
| 539 | exe.linkLibC(); | 589 | exe.linkLibC(); |
| ... | @@ -557,7 +607,7 @@ fn testCopyrelAlignment(b: *Build, opts: Options) *Step { | ... | @@ -557,7 +607,7 @@ fn testCopyrelAlignment(b: *Build, opts: Options) *Step { |
| 557 | fn testDsoPlt(b: *Build, opts: Options) *Step { | 607 | fn testDsoPlt(b: *Build, opts: Options) *Step { |
| 558 | const test_step = addTestStep(b, "dso-plt", opts); | 608 | const test_step = addTestStep(b, "dso-plt", opts); |
| 559 | 609 | ||
| 560 | const dso = addSharedLibrary(b, "dso", opts); | 610 | const dso = addSharedLibrary(b, opts, .{ .name = "dso" }); |
| 561 | addCSourceBytes(dso, | 611 | addCSourceBytes(dso, |
| 562 | \\#include<stdio.h> | 612 | \\#include<stdio.h> |
| 563 | \\void world() { | 613 | \\void world() { |
| ... | @@ -573,7 +623,7 @@ fn testDsoPlt(b: *Build, opts: Options) *Step { | ... | @@ -573,7 +623,7 @@ fn testDsoPlt(b: *Build, opts: Options) *Step { |
| 573 | , &.{}); | 623 | , &.{}); |
| 574 | dso.linkLibC(); | 624 | dso.linkLibC(); |
| 575 | 625 | ||
| 576 | const exe = addExecutable(b, "test", opts); | 626 | const exe = addExecutable(b, opts, .{ .name = "test" }); |
| 577 | addCSourceBytes(exe, | 627 | addCSourceBytes(exe, |
| 578 | \\#include<stdio.h> | 628 | \\#include<stdio.h> |
| 579 | \\void world() { | 629 | \\void world() { |
| ... | @@ -599,7 +649,7 @@ fn testDsoPlt(b: *Build, opts: Options) *Step { | ... | @@ -599,7 +649,7 @@ fn testDsoPlt(b: *Build, opts: Options) *Step { |
| 599 | fn testDsoUndef(b: *Build, opts: Options) *Step { | 649 | fn testDsoUndef(b: *Build, opts: Options) *Step { |
| 600 | const test_step = addTestStep(b, "dso-undef", opts); | 650 | const test_step = addTestStep(b, "dso-undef", opts); |
| 601 | 651 | ||
| 602 | const dso = addSharedLibrary(b, "dso", opts); | 652 | const dso = addSharedLibrary(b, opts, .{ .name = "dso" }); |
| 603 | addCSourceBytes(dso, | 653 | addCSourceBytes(dso, |
| 604 | \\extern int foo; | 654 | \\extern int foo; |
| 605 | \\int bar = 5; | 655 | \\int bar = 5; |
| ... | @@ -607,13 +657,15 @@ fn testDsoUndef(b: *Build, opts: Options) *Step { | ... | @@ -607,13 +657,15 @@ fn testDsoUndef(b: *Build, opts: Options) *Step { |
| 607 | , &.{}); | 657 | , &.{}); |
| 608 | dso.linkLibC(); | 658 | dso.linkLibC(); |
| 609 | 659 | ||
| 610 | const obj = addObject(b, "obj", opts); | 660 | const obj = addObject(b, opts, .{ |
| 611 | addCSourceBytes(obj, "int foo = 3;", &.{}); | 661 | .name = "obj", |
| 662 | .c_source_bytes = "int foo = 3;", | ||
| 663 | }); | ||
| 612 | 664 | ||
| 613 | const lib = addStaticLibrary(b, "lib", opts); | 665 | const lib = addStaticLibrary(b, opts, .{ .name = "lib" }); |
| 614 | lib.addObject(obj); | 666 | lib.addObject(obj); |
| 615 | 667 | ||
| 616 | const exe = addExecutable(b, "test", opts); | 668 | const exe = addExecutable(b, opts, .{ .name = "test" }); |
| 617 | exe.linkLibrary(dso); | 669 | exe.linkLibrary(dso); |
| 618 | exe.linkLibrary(lib); | 670 | exe.linkLibrary(lib); |
| 619 | addCSourceBytes(exe, | 671 | addCSourceBytes(exe, |
| ... | @@ -641,8 +693,9 @@ fn testDsoUndef(b: *Build, opts: Options) *Step { | ... | @@ -641,8 +693,9 @@ fn testDsoUndef(b: *Build, opts: Options) *Step { |
| 641 | fn testEmitRelocatable(b: *Build, opts: Options) *Step { | 693 | fn testEmitRelocatable(b: *Build, opts: Options) *Step { |
| 642 | const test_step = addTestStep(b, "emit-relocatable", opts); | 694 | const test_step = addTestStep(b, "emit-relocatable", opts); |
| 643 | 695 | ||
| 644 | const obj1 = addObject(b, "obj1", opts); | 696 | const obj1 = addObject(b, opts, .{ |
| 645 | addZigSourceBytes(obj1, | 697 | .name = "obj1", |
| 698 | .zig_source_bytes = | ||
| 646 | \\const std = @import("std"); | 699 | \\const std = @import("std"); |
| 647 | \\extern var bar: i32; | 700 | \\extern var bar: i32; |
| 648 | \\export fn foo() i32 { | 701 | \\export fn foo() i32 { |
| ... | @@ -651,18 +704,20 @@ fn testEmitRelocatable(b: *Build, opts: Options) *Step { | ... | @@ -651,18 +704,20 @@ fn testEmitRelocatable(b: *Build, opts: Options) *Step { |
| 651 | \\export fn printFoo() void { | 704 | \\export fn printFoo() void { |
| 652 | \\ std.debug.print("foo={d}\n", .{foo()}); | 705 | \\ std.debug.print("foo={d}\n", .{foo()}); |
| 653 | \\} | 706 | \\} |
| 654 | ); | 707 | , |
| 655 | addCSourceBytes(obj1, | 708 | .c_source_bytes = |
| 656 | \\#include <stdio.h> | 709 | \\#include <stdio.h> |
| 657 | \\int bar = 42; | 710 | \\int bar = 42; |
| 658 | \\void printBar() { | 711 | \\void printBar() { |
| 659 | \\ fprintf(stderr, "bar=%d\n", bar); | 712 | \\ fprintf(stderr, "bar=%d\n", bar); |
| 660 | \\} | 713 | \\} |
| 661 | , &.{}); | 714 | , |
| 715 | }); | ||
| 662 | obj1.linkLibC(); | 716 | obj1.linkLibC(); |
| 663 | 717 | ||
| 664 | const exe = addExecutable(b, "test", opts); | 718 | const exe = addExecutable(b, opts, .{ |
| 665 | addZigSourceBytes(exe, | 719 | .name = "test", |
| 720 | .zig_source_bytes = | ||
| 666 | \\const std = @import("std"); | 721 | \\const std = @import("std"); |
| 667 | \\extern fn printFoo() void; | 722 | \\extern fn printFoo() void; |
| 668 | \\extern fn printBar() void; | 723 | \\extern fn printBar() void; |
| ... | @@ -670,7 +725,8 @@ fn testEmitRelocatable(b: *Build, opts: Options) *Step { | ... | @@ -670,7 +725,8 @@ fn testEmitRelocatable(b: *Build, opts: Options) *Step { |
| 670 | \\ printFoo(); | 725 | \\ printFoo(); |
| 671 | \\ printBar(); | 726 | \\ printBar(); |
| 672 | \\} | 727 | \\} |
| 673 | ); | 728 | , |
| 729 | }); | ||
| 674 | exe.addObject(obj1); | 730 | exe.addObject(obj1); |
| 675 | exe.linkLibC(); | 731 | exe.linkLibC(); |
| 676 | 732 | ||
| ... | @@ -688,20 +744,26 @@ fn testEmitRelocatable(b: *Build, opts: Options) *Step { | ... | @@ -688,20 +744,26 @@ fn testEmitRelocatable(b: *Build, opts: Options) *Step { |
| 688 | fn testEmitStaticLib(b: *Build, opts: Options) *Step { | 744 | fn testEmitStaticLib(b: *Build, opts: Options) *Step { |
| 689 | const test_step = addTestStep(b, "emit-static-lib", opts); | 745 | const test_step = addTestStep(b, "emit-static-lib", opts); |
| 690 | 746 | ||
| 691 | const obj1 = addObject(b, "obj1", opts); | 747 | const obj1 = addObject(b, opts, .{ |
| 692 | addCSourceBytes(obj1, | 748 | .name = "obj1", |
| 749 | .c_source_bytes = | ||
| 693 | \\int foo = 0; | 750 | \\int foo = 0; |
| 694 | \\int bar = 2; | 751 | \\int bar = 2; |
| 695 | \\int fooBar() { | 752 | \\int fooBar() { |
| 696 | \\ return foo + bar; | 753 | \\ return foo + bar; |
| 697 | \\} | 754 | \\} |
| 698 | , &.{}); | 755 | , |
| 756 | }); | ||
| 699 | 757 | ||
| 700 | const obj2 = addObject(b, "obj2", opts); | 758 | const obj2 = addObject(b, opts, .{ |
| 701 | addCSourceBytes(obj2, "int tentative;", &.{"-fcommon"}); | 759 | .name = "obj2", |
| 760 | .c_source_bytes = "int tentative;", | ||
| 761 | .c_source_flags = &.{"-fcommon"}, | ||
| 762 | }); | ||
| 702 | 763 | ||
| 703 | const obj3 = addObject(b, "a_very_long_file_name_so_that_it_ends_up_in_strtab", opts); | 764 | const obj3 = addObject(b, opts, .{ |
| 704 | addZigSourceBytes(obj3, | 765 | .name = "a_very_long_file_name_so_that_it_ends_up_in_strtab", |
| 766 | .zig_source_bytes = | ||
| 705 | \\fn weakFoo() callconv(.C) usize { | 767 | \\fn weakFoo() callconv(.C) usize { |
| 706 | \\ return 42; | 768 | \\ return 42; |
| 707 | \\} | 769 | \\} |
| ... | @@ -710,9 +772,10 @@ fn testEmitStaticLib(b: *Build, opts: Options) *Step { | ... | @@ -710,9 +772,10 @@ fn testEmitStaticLib(b: *Build, opts: Options) *Step { |
| 710 | \\ @export(weakFoo, .{ .name = "weakFoo", .linkage = .Weak }); | 772 | \\ @export(weakFoo, .{ .name = "weakFoo", .linkage = .Weak }); |
| 711 | \\ @export(strongBar, .{ .name = "strongBarAlias", .linkage = .Strong }); | 773 | \\ @export(strongBar, .{ .name = "strongBarAlias", .linkage = .Strong }); |
| 712 | \\} | 774 | \\} |
| 713 | ); | 775 | , |
| 776 | }); | ||
| 714 | 777 | ||
| 715 | const lib = addStaticLibrary(b, "lib", opts); | 778 | const lib = addStaticLibrary(b, opts, .{ .name = "lib" }); |
| 716 | lib.addObject(obj1); | 779 | lib.addObject(obj1); |
| 717 | lib.addObject(obj2); | 780 | lib.addObject(obj2); |
| 718 | lib.addObject(obj3); | 781 | lib.addObject(obj3); |
| ... | @@ -747,30 +810,36 @@ fn testEmitStaticLib(b: *Build, opts: Options) *Step { | ... | @@ -747,30 +810,36 @@ fn testEmitStaticLib(b: *Build, opts: Options) *Step { |
| 747 | fn testEmitStaticLibZig(b: *Build, opts: Options) *Step { | 810 | fn testEmitStaticLibZig(b: *Build, opts: Options) *Step { |
| 748 | const test_step = addTestStep(b, "emit-static-lib-zig", opts); | 811 | const test_step = addTestStep(b, "emit-static-lib-zig", opts); |
| 749 | 812 | ||
| 750 | const obj1 = addObject(b, "obj1", opts); | 813 | const obj1 = addObject(b, opts, .{ |
| 751 | addZigSourceBytes(obj1, | 814 | .name = "obj1", |
| 815 | .zig_source_bytes = | ||
| 752 | \\export var foo: i32 = 42; | 816 | \\export var foo: i32 = 42; |
| 753 | \\export var bar: i32 = 2; | 817 | \\export var bar: i32 = 2; |
| 754 | ); | 818 | , |
| 819 | }); | ||
| 755 | 820 | ||
| 756 | const lib = addStaticLibrary(b, "lib", opts); | 821 | const lib = addStaticLibrary(b, opts, .{ |
| 757 | addZigSourceBytes(lib, | 822 | .name = "lib", |
| 823 | .zig_source_bytes = | ||
| 758 | \\extern var foo: i32; | 824 | \\extern var foo: i32; |
| 759 | \\extern var bar: i32; | 825 | \\extern var bar: i32; |
| 760 | \\export fn fooBar() i32 { | 826 | \\export fn fooBar() i32 { |
| 761 | \\ return foo + bar; | 827 | \\ return foo + bar; |
| 762 | \\} | 828 | \\} |
| 763 | ); | 829 | , |
| 830 | }); | ||
| 764 | lib.addObject(obj1); | 831 | lib.addObject(obj1); |
| 765 | 832 | ||
| 766 | const exe = addExecutable(b, "test", opts); | 833 | const exe = addExecutable(b, opts, .{ |
| 767 | addZigSourceBytes(exe, | 834 | .name = "test", |
| 835 | .zig_source_bytes = | ||
| 768 | \\const std = @import("std"); | 836 | \\const std = @import("std"); |
| 769 | \\extern fn fooBar() i32; | 837 | \\extern fn fooBar() i32; |
| 770 | \\pub fn main() void { | 838 | \\pub fn main() void { |
| 771 | \\ std.debug.print("{d}", .{fooBar()}); | 839 | \\ std.debug.print("{d}", .{fooBar()}); |
| 772 | \\} | 840 | \\} |
| 773 | ); | 841 | , |
| 842 | }); | ||
| 774 | exe.linkLibrary(lib); | 843 | exe.linkLibrary(lib); |
| 775 | 844 | ||
| 776 | const run = addRunArtifact(exe); | 845 | const run = addRunArtifact(exe); |
| ... | @@ -783,7 +852,7 @@ fn testEmitStaticLibZig(b: *Build, opts: Options) *Step { | ... | @@ -783,7 +852,7 @@ fn testEmitStaticLibZig(b: *Build, opts: Options) *Step { |
| 783 | fn testEmptyObject(b: *Build, opts: Options) *Step { | 852 | fn testEmptyObject(b: *Build, opts: Options) *Step { |
| 784 | const test_step = addTestStep(b, "empty-object", opts); | 853 | const test_step = addTestStep(b, "empty-object", opts); |
| 785 | 854 | ||
| 786 | const exe = addExecutable(b, "test", opts); | 855 | const exe = addExecutable(b, opts, .{ .name = "test" }); |
| 787 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); | 856 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); |
| 788 | addCSourceBytes(exe, "", &.{}); | 857 | addCSourceBytes(exe, "", &.{}); |
| 789 | exe.linkLibC(); | 858 | exe.linkLibC(); |
| ... | @@ -798,18 +867,23 @@ fn testEmptyObject(b: *Build, opts: Options) *Step { | ... | @@ -798,18 +867,23 @@ fn testEmptyObject(b: *Build, opts: Options) *Step { |
| 798 | fn testEntryPoint(b: *Build, opts: Options) *Step { | 867 | fn testEntryPoint(b: *Build, opts: Options) *Step { |
| 799 | const test_step = addTestStep(b, "entry-point", opts); | 868 | const test_step = addTestStep(b, "entry-point", opts); |
| 800 | 869 | ||
| 801 | const a_o = addObject(b, "a", opts); | 870 | const a_o = addObject(b, opts, .{ |
| 802 | addAsmSourceBytes(a_o, | 871 | .name = "a", |
| 872 | .asm_source_bytes = | ||
| 803 | \\.globl foo, bar | 873 | \\.globl foo, bar |
| 804 | \\foo = 0x1000 | 874 | \\foo = 0x1000 |
| 805 | \\bar = 0x2000 | 875 | \\bar = 0x2000 |
| 806 | ); | 876 | \\ |
| 877 | , | ||
| 878 | }); | ||
| 807 | 879 | ||
| 808 | const b_o = addObject(b, "b", opts); | 880 | const b_o = addObject(b, opts, .{ |
| 809 | addCSourceBytes(b_o, "int main() { return 0; }", &.{}); | 881 | .name = "b", |
| 882 | .c_source_bytes = "int main() { return 0; }", | ||
| 883 | }); | ||
| 810 | 884 | ||
| 811 | { | 885 | { |
| 812 | const exe = addExecutable(b, "main", opts); | 886 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 813 | exe.addObject(a_o); | 887 | exe.addObject(a_o); |
| 814 | exe.addObject(b_o); | 888 | exe.addObject(b_o); |
| 815 | exe.entry = .{ .symbol_name = "foo" }; | 889 | exe.entry = .{ .symbol_name = "foo" }; |
| ... | @@ -825,7 +899,7 @@ fn testEntryPoint(b: *Build, opts: Options) *Step { | ... | @@ -825,7 +899,7 @@ fn testEntryPoint(b: *Build, opts: Options) *Step { |
| 825 | // TODO looks like not assigning a unique name to this executable will | 899 | // TODO looks like not assigning a unique name to this executable will |
| 826 | // cause an artifact collision taking the cached executable from the above | 900 | // cause an artifact collision taking the cached executable from the above |
| 827 | // step instead of generating a new one. | 901 | // step instead of generating a new one. |
| 828 | const exe = addExecutable(b, "other", opts); | 902 | const exe = addExecutable(b, opts, .{ .name = "other" }); |
| 829 | exe.addObject(a_o); | 903 | exe.addObject(a_o); |
| 830 | exe.addObject(b_o); | 904 | exe.addObject(b_o); |
| 831 | exe.entry = .{ .symbol_name = "bar" }; | 905 | exe.entry = .{ .symbol_name = "bar" }; |
| ... | @@ -843,8 +917,9 @@ fn testEntryPoint(b: *Build, opts: Options) *Step { | ... | @@ -843,8 +917,9 @@ fn testEntryPoint(b: *Build, opts: Options) *Step { |
| 843 | fn testExportDynamic(b: *Build, opts: Options) *Step { | 917 | fn testExportDynamic(b: *Build, opts: Options) *Step { |
| 844 | const test_step = addTestStep(b, "export-dynamic", opts); | 918 | const test_step = addTestStep(b, "export-dynamic", opts); |
| 845 | 919 | ||
| 846 | const obj = addObject(b, "obj", opts); | 920 | const obj = addObject(b, opts, .{ |
| 847 | addAsmSourceBytes(obj, | 921 | .name = "obj", |
| 922 | .asm_source_bytes = | ||
| 848 | \\.text | 923 | \\.text |
| 849 | \\ .globl foo | 924 | \\ .globl foo |
| 850 | \\ .hidden foo | 925 | \\ .hidden foo |
| ... | @@ -856,12 +931,14 @@ fn testExportDynamic(b: *Build, opts: Options) *Step { | ... | @@ -856,12 +931,14 @@ fn testExportDynamic(b: *Build, opts: Options) *Step { |
| 856 | \\ .globl _start | 931 | \\ .globl _start |
| 857 | \\_start: | 932 | \\_start: |
| 858 | \\ nop | 933 | \\ nop |
| 859 | ); | 934 | \\ |
| 935 | , | ||
| 936 | }); | ||
| 860 | 937 | ||
| 861 | const dso = addSharedLibrary(b, "a", opts); | 938 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 862 | addCSourceBytes(dso, "int baz = 10;", &.{}); | 939 | addCSourceBytes(dso, "int baz = 10;", &.{}); |
| 863 | 940 | ||
| 864 | const exe = addExecutable(b, "main", opts); | 941 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 865 | addCSourceBytes(exe, | 942 | addCSourceBytes(exe, |
| 866 | \\extern int baz; | 943 | \\extern int baz; |
| 867 | \\int callBaz() { | 944 | \\int callBaz() { |
| ... | @@ -885,7 +962,7 @@ fn testExportDynamic(b: *Build, opts: Options) *Step { | ... | @@ -885,7 +962,7 @@ fn testExportDynamic(b: *Build, opts: Options) *Step { |
| 885 | fn testExportSymbolsFromExe(b: *Build, opts: Options) *Step { | 962 | fn testExportSymbolsFromExe(b: *Build, opts: Options) *Step { |
| 886 | const test_step = addTestStep(b, "export-symbols-from-exe", opts); | 963 | const test_step = addTestStep(b, "export-symbols-from-exe", opts); |
| 887 | 964 | ||
| 888 | const dso = addSharedLibrary(b, "a", opts); | 965 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 889 | addCSourceBytes(dso, | 966 | addCSourceBytes(dso, |
| 890 | \\void expfn1(); | 967 | \\void expfn1(); |
| 891 | \\void expfn2() {} | 968 | \\void expfn2() {} |
| ... | @@ -895,7 +972,7 @@ fn testExportSymbolsFromExe(b: *Build, opts: Options) *Step { | ... | @@ -895,7 +972,7 @@ fn testExportSymbolsFromExe(b: *Build, opts: Options) *Step { |
| 895 | \\} | 972 | \\} |
| 896 | , &.{}); | 973 | , &.{}); |
| 897 | 974 | ||
| 898 | const exe = addExecutable(b, "main", opts); | 975 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 899 | addCSourceBytes(exe, | 976 | addCSourceBytes(exe, |
| 900 | \\void expfn1() {} | 977 | \\void expfn1() {} |
| 901 | \\void expfn2() {} | 978 | \\void expfn2() {} |
| ... | @@ -923,10 +1000,10 @@ fn testExportSymbolsFromExe(b: *Build, opts: Options) *Step { | ... | @@ -923,10 +1000,10 @@ fn testExportSymbolsFromExe(b: *Build, opts: Options) *Step { |
| 923 | fn testFuncAddress(b: *Build, opts: Options) *Step { | 1000 | fn testFuncAddress(b: *Build, opts: Options) *Step { |
| 924 | const test_step = addTestStep(b, "func-address", opts); | 1001 | const test_step = addTestStep(b, "func-address", opts); |
| 925 | 1002 | ||
| 926 | const dso = addSharedLibrary(b, "a", opts); | 1003 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 927 | addCSourceBytes(dso, "void fn() {}", &.{}); | 1004 | addCSourceBytes(dso, "void fn() {}", &.{}); |
| 928 | 1005 | ||
| 929 | const exe = addExecutable(b, "main", opts); | 1006 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 930 | addCSourceBytes(exe, | 1007 | addCSourceBytes(exe, |
| 931 | \\#include <assert.h> | 1008 | \\#include <assert.h> |
| 932 | \\typedef void Func(); | 1009 | \\typedef void Func(); |
| ... | @@ -937,7 +1014,7 @@ fn testFuncAddress(b: *Build, opts: Options) *Step { | ... | @@ -937,7 +1014,7 @@ fn testFuncAddress(b: *Build, opts: Options) *Step { |
| 937 | \\} | 1014 | \\} |
| 938 | , &.{}); | 1015 | , &.{}); |
| 939 | exe.linkLibrary(dso); | 1016 | exe.linkLibrary(dso); |
| 940 | exe.force_pic = false; | 1017 | exe.root_module.pic = false; |
| 941 | exe.pie = false; | 1018 | exe.pie = false; |
| 942 | 1019 | ||
| 943 | const run = addRunArtifact(exe); | 1020 | const run = addRunArtifact(exe); |
| ... | @@ -950,8 +1027,9 @@ fn testFuncAddress(b: *Build, opts: Options) *Step { | ... | @@ -950,8 +1027,9 @@ fn testFuncAddress(b: *Build, opts: Options) *Step { |
| 950 | fn testGcSections(b: *Build, opts: Options) *Step { | 1027 | fn testGcSections(b: *Build, opts: Options) *Step { |
| 951 | const test_step = addTestStep(b, "gc-sections", opts); | 1028 | const test_step = addTestStep(b, "gc-sections", opts); |
| 952 | 1029 | ||
| 953 | const obj = addObject(b, "obj", opts); | 1030 | const obj = addObject(b, opts, .{ |
| 954 | addCppSourceBytes(obj, | 1031 | .name = "obj", |
| 1032 | .cpp_source_bytes = | ||
| 955 | \\#include <stdio.h> | 1033 | \\#include <stdio.h> |
| 956 | \\int two() { return 2; } | 1034 | \\int two() { return 2; } |
| 957 | \\int live_var1 = 1; | 1035 | \\int live_var1 = 1; |
| ... | @@ -966,14 +1044,15 @@ fn testGcSections(b: *Build, opts: Options) *Step { | ... | @@ -966,14 +1044,15 @@ fn testGcSections(b: *Build, opts: Options) *Step { |
| 966 | \\ printf("%d %d\n", live_var1, live_var2); | 1044 | \\ printf("%d %d\n", live_var1, live_var2); |
| 967 | \\ live_fn2(); | 1045 | \\ live_fn2(); |
| 968 | \\} | 1046 | \\} |
| 969 | , &.{}); | 1047 | , |
| 1048 | }); | ||
| 970 | obj.link_function_sections = true; | 1049 | obj.link_function_sections = true; |
| 971 | obj.link_data_sections = true; | 1050 | obj.link_data_sections = true; |
| 972 | obj.linkLibC(); | 1051 | obj.linkLibC(); |
| 973 | obj.linkLibCpp(); | 1052 | obj.linkLibCpp(); |
| 974 | 1053 | ||
| 975 | { | 1054 | { |
| 976 | const exe = addExecutable(b, "test", opts); | 1055 | const exe = addExecutable(b, opts, .{ .name = "test" }); |
| 977 | exe.addObject(obj); | 1056 | exe.addObject(obj); |
| 978 | exe.link_gc_sections = false; | 1057 | exe.link_gc_sections = false; |
| 979 | exe.linkLibC(); | 1058 | exe.linkLibC(); |
| ... | @@ -1004,7 +1083,7 @@ fn testGcSections(b: *Build, opts: Options) *Step { | ... | @@ -1004,7 +1083,7 @@ fn testGcSections(b: *Build, opts: Options) *Step { |
| 1004 | } | 1083 | } |
| 1005 | 1084 | ||
| 1006 | { | 1085 | { |
| 1007 | const exe = addExecutable(b, "test", opts); | 1086 | const exe = addExecutable(b, opts, .{ .name = "test" }); |
| 1008 | exe.addObject(obj); | 1087 | exe.addObject(obj); |
| 1009 | exe.link_gc_sections = true; | 1088 | exe.link_gc_sections = true; |
| 1010 | exe.linkLibC(); | 1089 | exe.linkLibC(); |
| ... | @@ -1040,11 +1119,12 @@ fn testGcSections(b: *Build, opts: Options) *Step { | ... | @@ -1040,11 +1119,12 @@ fn testGcSections(b: *Build, opts: Options) *Step { |
| 1040 | fn testGcSectionsZig(b: *Build, opts: Options) *Step { | 1119 | fn testGcSectionsZig(b: *Build, opts: Options) *Step { |
| 1041 | const test_step = addTestStep(b, "gc-sections-zig", opts); | 1120 | const test_step = addTestStep(b, "gc-sections-zig", opts); |
| 1042 | 1121 | ||
| 1043 | const obj = addObject(b, "obj", .{ | 1122 | const obj = addObject(b, .{ |
| 1044 | .target = opts.target, | 1123 | .target = opts.target, |
| 1045 | .use_llvm = true, | 1124 | .use_llvm = true, |
| 1046 | }); | 1125 | }, .{ |
| 1047 | addCSourceBytes(obj, | 1126 | .name = "obj", |
| 1127 | .c_source_bytes = | ||
| 1048 | \\int live_var1 = 1; | 1128 | \\int live_var1 = 1; |
| 1049 | \\int live_var2 = 2; | 1129 | \\int live_var2 = 2; |
| 1050 | \\int dead_var1 = 3; | 1130 | \\int dead_var1 = 3; |
| ... | @@ -1053,13 +1133,15 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { | ... | @@ -1053,13 +1133,15 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { |
| 1053 | \\void live_fn2() { live_fn1(); } | 1133 | \\void live_fn2() { live_fn1(); } |
| 1054 | \\void dead_fn1() {} | 1134 | \\void dead_fn1() {} |
| 1055 | \\void dead_fn2() { dead_fn1(); } | 1135 | \\void dead_fn2() { dead_fn1(); } |
| 1056 | , &.{}); | 1136 | , |
| 1137 | }); | ||
| 1057 | obj.link_function_sections = true; | 1138 | obj.link_function_sections = true; |
| 1058 | obj.link_data_sections = true; | 1139 | obj.link_data_sections = true; |
| 1059 | 1140 | ||
| 1060 | { | 1141 | { |
| 1061 | const exe = addExecutable(b, "test1", opts); | 1142 | const exe = addExecutable(b, opts, .{ |
| 1062 | addZigSourceBytes(exe, | 1143 | .name = "test1", |
| 1144 | .zig_source_bytes = | ||
| 1063 | \\const std = @import("std"); | 1145 | \\const std = @import("std"); |
| 1064 | \\extern var live_var1: i32; | 1146 | \\extern var live_var1: i32; |
| 1065 | \\extern var live_var2: i32; | 1147 | \\extern var live_var2: i32; |
| ... | @@ -1069,7 +1151,8 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { | ... | @@ -1069,7 +1151,8 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { |
| 1069 | \\ stdout.writer().print("{d} {d}\n", .{ live_var1, live_var2 }) catch unreachable; | 1151 | \\ stdout.writer().print("{d} {d}\n", .{ live_var1, live_var2 }) catch unreachable; |
| 1070 | \\ live_fn2(); | 1152 | \\ live_fn2(); |
| 1071 | \\} | 1153 | \\} |
| 1072 | ); | 1154 | , |
| 1155 | }); | ||
| 1073 | exe.addObject(obj); | 1156 | exe.addObject(obj); |
| 1074 | exe.link_gc_sections = false; | 1157 | exe.link_gc_sections = false; |
| 1075 | 1158 | ||
| ... | @@ -1098,8 +1181,9 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { | ... | @@ -1098,8 +1181,9 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { |
| 1098 | } | 1181 | } |
| 1099 | 1182 | ||
| 1100 | { | 1183 | { |
| 1101 | const exe = addExecutable(b, "test2", opts); | 1184 | const exe = addExecutable(b, opts, .{ |
| 1102 | addZigSourceBytes(exe, | 1185 | .name = "test2", |
| 1186 | .zig_source_bytes = | ||
| 1103 | \\const std = @import("std"); | 1187 | \\const std = @import("std"); |
| 1104 | \\extern var live_var1: i32; | 1188 | \\extern var live_var1: i32; |
| 1105 | \\extern var live_var2: i32; | 1189 | \\extern var live_var2: i32; |
| ... | @@ -1109,7 +1193,8 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { | ... | @@ -1109,7 +1193,8 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { |
| 1109 | \\ stdout.writer().print("{d} {d}\n", .{ live_var1, live_var2 }) catch unreachable; | 1193 | \\ stdout.writer().print("{d} {d}\n", .{ live_var1, live_var2 }) catch unreachable; |
| 1110 | \\ live_fn2(); | 1194 | \\ live_fn2(); |
| 1111 | \\} | 1195 | \\} |
| 1112 | ); | 1196 | , |
| 1197 | }); | ||
| 1113 | exe.addObject(obj); | 1198 | exe.addObject(obj); |
| 1114 | exe.link_gc_sections = true; | 1199 | exe.link_gc_sections = true; |
| 1115 | 1200 | ||
| ... | @@ -1143,7 +1228,7 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { | ... | @@ -1143,7 +1228,7 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step { |
| 1143 | fn testHiddenWeakUndef(b: *Build, opts: Options) *Step { | 1228 | fn testHiddenWeakUndef(b: *Build, opts: Options) *Step { |
| 1144 | const test_step = addTestStep(b, "hidden-weak-undef", opts); | 1229 | const test_step = addTestStep(b, "hidden-weak-undef", opts); |
| 1145 | 1230 | ||
| 1146 | const dso = addSharedLibrary(b, "a", opts); | 1231 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 1147 | addCSourceBytes(dso, | 1232 | addCSourceBytes(dso, |
| 1148 | \\__attribute__((weak, visibility("hidden"))) void foo(); | 1233 | \\__attribute__((weak, visibility("hidden"))) void foo(); |
| 1149 | \\void bar() { foo(); } | 1234 | \\void bar() { foo(); } |
| ... | @@ -1162,7 +1247,7 @@ fn testHiddenWeakUndef(b: *Build, opts: Options) *Step { | ... | @@ -1162,7 +1247,7 @@ fn testHiddenWeakUndef(b: *Build, opts: Options) *Step { |
| 1162 | fn testIFuncAlias(b: *Build, opts: Options) *Step { | 1247 | fn testIFuncAlias(b: *Build, opts: Options) *Step { |
| 1163 | const test_step = addTestStep(b, "ifunc-alias", opts); | 1248 | const test_step = addTestStep(b, "ifunc-alias", opts); |
| 1164 | 1249 | ||
| 1165 | const exe = addExecutable(b, "main", opts); | 1250 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 1166 | addCSourceBytes(exe, | 1251 | addCSourceBytes(exe, |
| 1167 | \\#include <assert.h> | 1252 | \\#include <assert.h> |
| 1168 | \\void foo() {} | 1253 | \\void foo() {} |
| ... | @@ -1173,7 +1258,7 @@ fn testIFuncAlias(b: *Build, opts: Options) *Step { | ... | @@ -1173,7 +1258,7 @@ fn testIFuncAlias(b: *Build, opts: Options) *Step { |
| 1173 | \\ assert(bar == bar2); | 1258 | \\ assert(bar == bar2); |
| 1174 | \\} | 1259 | \\} |
| 1175 | , &.{}); | 1260 | , &.{}); |
| 1176 | exe.force_pic = true; | 1261 | exe.root_module.pic = true; |
| 1177 | exe.linkLibC(); | 1262 | exe.linkLibC(); |
| 1178 | // https://github.com/ziglang/zig/issues/17619 | 1263 | // https://github.com/ziglang/zig/issues/17619 |
| 1179 | exe.pie = true; | 1264 | exe.pie = true; |
| ... | @@ -1188,7 +1273,7 @@ fn testIFuncAlias(b: *Build, opts: Options) *Step { | ... | @@ -1188,7 +1273,7 @@ fn testIFuncAlias(b: *Build, opts: Options) *Step { |
| 1188 | fn testIFuncDlopen(b: *Build, opts: Options) *Step { | 1273 | fn testIFuncDlopen(b: *Build, opts: Options) *Step { |
| 1189 | const test_step = addTestStep(b, "ifunc-dlopen", opts); | 1274 | const test_step = addTestStep(b, "ifunc-dlopen", opts); |
| 1190 | 1275 | ||
| 1191 | const dso = addSharedLibrary(b, "a", opts); | 1276 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 1192 | addCSourceBytes(dso, | 1277 | addCSourceBytes(dso, |
| 1193 | \\__attribute__((ifunc("resolve_foo"))) | 1278 | \\__attribute__((ifunc("resolve_foo"))) |
| 1194 | \\void foo(void); | 1279 | \\void foo(void); |
| ... | @@ -1200,7 +1285,7 @@ fn testIFuncDlopen(b: *Build, opts: Options) *Step { | ... | @@ -1200,7 +1285,7 @@ fn testIFuncDlopen(b: *Build, opts: Options) *Step { |
| 1200 | \\} | 1285 | \\} |
| 1201 | , &.{}); | 1286 | , &.{}); |
| 1202 | 1287 | ||
| 1203 | const exe = addExecutable(b, "main", opts); | 1288 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 1204 | addCSourceBytes(exe, | 1289 | addCSourceBytes(exe, |
| 1205 | \\#include <dlfcn.h> | 1290 | \\#include <dlfcn.h> |
| 1206 | \\#include <assert.h> | 1291 | \\#include <assert.h> |
| ... | @@ -1219,7 +1304,7 @@ fn testIFuncDlopen(b: *Build, opts: Options) *Step { | ... | @@ -1219,7 +1304,7 @@ fn testIFuncDlopen(b: *Build, opts: Options) *Step { |
| 1219 | exe.linkLibrary(dso); | 1304 | exe.linkLibrary(dso); |
| 1220 | exe.linkLibC(); | 1305 | exe.linkLibC(); |
| 1221 | exe.linkSystemLibrary2("dl", .{}); | 1306 | exe.linkSystemLibrary2("dl", .{}); |
| 1222 | exe.force_pic = false; | 1307 | exe.root_module.pic = false; |
| 1223 | exe.pie = false; | 1308 | exe.pie = false; |
| 1224 | 1309 | ||
| 1225 | const run = addRunArtifact(exe); | 1310 | const run = addRunArtifact(exe); |
| ... | @@ -1232,7 +1317,7 @@ fn testIFuncDlopen(b: *Build, opts: Options) *Step { | ... | @@ -1232,7 +1317,7 @@ fn testIFuncDlopen(b: *Build, opts: Options) *Step { |
| 1232 | fn testIFuncDso(b: *Build, opts: Options) *Step { | 1317 | fn testIFuncDso(b: *Build, opts: Options) *Step { |
| 1233 | const test_step = addTestStep(b, "ifunc-dso", opts); | 1318 | const test_step = addTestStep(b, "ifunc-dso", opts); |
| 1234 | 1319 | ||
| 1235 | const dso = addSharedLibrary(b, "a", opts); | 1320 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 1236 | addCSourceBytes(dso, | 1321 | addCSourceBytes(dso, |
| 1237 | \\#include<stdio.h> | 1322 | \\#include<stdio.h> |
| 1238 | \\__attribute__((ifunc("resolve_foobar"))) | 1323 | \\__attribute__((ifunc("resolve_foobar"))) |
| ... | @@ -1247,7 +1332,7 @@ fn testIFuncDso(b: *Build, opts: Options) *Step { | ... | @@ -1247,7 +1332,7 @@ fn testIFuncDso(b: *Build, opts: Options) *Step { |
| 1247 | , &.{}); | 1332 | , &.{}); |
| 1248 | dso.linkLibC(); | 1333 | dso.linkLibC(); |
| 1249 | 1334 | ||
| 1250 | const exe = addExecutable(b, "main", opts); | 1335 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 1251 | addCSourceBytes(exe, | 1336 | addCSourceBytes(exe, |
| 1252 | \\void foobar(void); | 1337 | \\void foobar(void); |
| 1253 | \\int main() { | 1338 | \\int main() { |
| ... | @@ -1283,7 +1368,7 @@ fn testIFuncDynamic(b: *Build, opts: Options) *Step { | ... | @@ -1283,7 +1368,7 @@ fn testIFuncDynamic(b: *Build, opts: Options) *Step { |
| 1283 | ; | 1368 | ; |
| 1284 | 1369 | ||
| 1285 | { | 1370 | { |
| 1286 | const exe = addExecutable(b, "main", opts); | 1371 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 1287 | addCSourceBytes(exe, main_c, &.{}); | 1372 | addCSourceBytes(exe, main_c, &.{}); |
| 1288 | exe.linkLibC(); | 1373 | exe.linkLibC(); |
| 1289 | exe.link_z_lazy = true; | 1374 | exe.link_z_lazy = true; |
| ... | @@ -1295,7 +1380,7 @@ fn testIFuncDynamic(b: *Build, opts: Options) *Step { | ... | @@ -1295,7 +1380,7 @@ fn testIFuncDynamic(b: *Build, opts: Options) *Step { |
| 1295 | test_step.dependOn(&run.step); | 1380 | test_step.dependOn(&run.step); |
| 1296 | } | 1381 | } |
| 1297 | { | 1382 | { |
| 1298 | const exe = addExecutable(b, "other", opts); | 1383 | const exe = addExecutable(b, opts, .{ .name = "other" }); |
| 1299 | addCSourceBytes(exe, main_c, &.{}); | 1384 | addCSourceBytes(exe, main_c, &.{}); |
| 1300 | exe.linkLibC(); | 1385 | exe.linkLibC(); |
| 1301 | // https://github.com/ziglang/zig/issues/17619 | 1386 | // https://github.com/ziglang/zig/issues/17619 |
| ... | @@ -1312,7 +1397,7 @@ fn testIFuncDynamic(b: *Build, opts: Options) *Step { | ... | @@ -1312,7 +1397,7 @@ fn testIFuncDynamic(b: *Build, opts: Options) *Step { |
| 1312 | fn testIFuncExport(b: *Build, opts: Options) *Step { | 1397 | fn testIFuncExport(b: *Build, opts: Options) *Step { |
| 1313 | const test_step = addTestStep(b, "ifunc-export", opts); | 1398 | const test_step = addTestStep(b, "ifunc-export", opts); |
| 1314 | 1399 | ||
| 1315 | const dso = addSharedLibrary(b, "a", opts); | 1400 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 1316 | addCSourceBytes(dso, | 1401 | addCSourceBytes(dso, |
| 1317 | \\#include <stdio.h> | 1402 | \\#include <stdio.h> |
| 1318 | \\__attribute__((ifunc("resolve_foobar"))) | 1403 | \\__attribute__((ifunc("resolve_foobar"))) |
| ... | @@ -1338,7 +1423,7 @@ fn testIFuncExport(b: *Build, opts: Options) *Step { | ... | @@ -1338,7 +1423,7 @@ fn testIFuncExport(b: *Build, opts: Options) *Step { |
| 1338 | fn testIFuncFuncPtr(b: *Build, opts: Options) *Step { | 1423 | fn testIFuncFuncPtr(b: *Build, opts: Options) *Step { |
| 1339 | const test_step = addTestStep(b, "ifunc-func-ptr", opts); | 1424 | const test_step = addTestStep(b, "ifunc-func-ptr", opts); |
| 1340 | 1425 | ||
| 1341 | const exe = addExecutable(b, "main", opts); | 1426 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 1342 | addCSourceBytes(exe, | 1427 | addCSourceBytes(exe, |
| 1343 | \\typedef int Fn(); | 1428 | \\typedef int Fn(); |
| 1344 | \\int foo() __attribute__((ifunc("resolve_foo"))); | 1429 | \\int foo() __attribute__((ifunc("resolve_foo"))); |
| ... | @@ -1361,7 +1446,7 @@ fn testIFuncFuncPtr(b: *Build, opts: Options) *Step { | ... | @@ -1361,7 +1446,7 @@ fn testIFuncFuncPtr(b: *Build, opts: Options) *Step { |
| 1361 | \\ printf("%d\n", f()); | 1446 | \\ printf("%d\n", f()); |
| 1362 | \\} | 1447 | \\} |
| 1363 | , &.{}); | 1448 | , &.{}); |
| 1364 | exe.force_pic = true; | 1449 | exe.root_module.pic = true; |
| 1365 | exe.linkLibC(); | 1450 | exe.linkLibC(); |
| 1366 | // https://github.com/ziglang/zig/issues/17619 | 1451 | // https://github.com/ziglang/zig/issues/17619 |
| 1367 | exe.pie = true; | 1452 | exe.pie = true; |
| ... | @@ -1376,7 +1461,7 @@ fn testIFuncFuncPtr(b: *Build, opts: Options) *Step { | ... | @@ -1376,7 +1461,7 @@ fn testIFuncFuncPtr(b: *Build, opts: Options) *Step { |
| 1376 | fn testIFuncNoPlt(b: *Build, opts: Options) *Step { | 1461 | fn testIFuncNoPlt(b: *Build, opts: Options) *Step { |
| 1377 | const test_step = addTestStep(b, "ifunc-noplt", opts); | 1462 | const test_step = addTestStep(b, "ifunc-noplt", opts); |
| 1378 | 1463 | ||
| 1379 | const exe = addExecutable(b, "main", opts); | 1464 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 1380 | addCSourceBytes(exe, | 1465 | addCSourceBytes(exe, |
| 1381 | \\#include <stdio.h> | 1466 | \\#include <stdio.h> |
| 1382 | \\__attribute__((ifunc("resolve_foo"))) | 1467 | \\__attribute__((ifunc("resolve_foo"))) |
| ... | @@ -1392,7 +1477,7 @@ fn testIFuncNoPlt(b: *Build, opts: Options) *Step { | ... | @@ -1392,7 +1477,7 @@ fn testIFuncNoPlt(b: *Build, opts: Options) *Step { |
| 1392 | \\ foo(); | 1477 | \\ foo(); |
| 1393 | \\} | 1478 | \\} |
| 1394 | , &.{"-fno-plt"}); | 1479 | , &.{"-fno-plt"}); |
| 1395 | exe.force_pic = true; | 1480 | exe.root_module.pic = true; |
| 1396 | exe.linkLibC(); | 1481 | exe.linkLibC(); |
| 1397 | // https://github.com/ziglang/zig/issues/17619 | 1482 | // https://github.com/ziglang/zig/issues/17619 |
| 1398 | exe.pie = true; | 1483 | exe.pie = true; |
| ... | @@ -1407,7 +1492,7 @@ fn testIFuncNoPlt(b: *Build, opts: Options) *Step { | ... | @@ -1407,7 +1492,7 @@ fn testIFuncNoPlt(b: *Build, opts: Options) *Step { |
| 1407 | fn testIFuncStatic(b: *Build, opts: Options) *Step { | 1492 | fn testIFuncStatic(b: *Build, opts: Options) *Step { |
| 1408 | const test_step = addTestStep(b, "ifunc-static", opts); | 1493 | const test_step = addTestStep(b, "ifunc-static", opts); |
| 1409 | 1494 | ||
| 1410 | const exe = addExecutable(b, "main", opts); | 1495 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 1411 | addCSourceBytes(exe, | 1496 | addCSourceBytes(exe, |
| 1412 | \\#include <stdio.h> | 1497 | \\#include <stdio.h> |
| 1413 | \\void foo() __attribute__((ifunc("resolve_foo"))); | 1498 | \\void foo() __attribute__((ifunc("resolve_foo"))); |
| ... | @@ -1435,7 +1520,7 @@ fn testIFuncStatic(b: *Build, opts: Options) *Step { | ... | @@ -1435,7 +1520,7 @@ fn testIFuncStatic(b: *Build, opts: Options) *Step { |
| 1435 | fn testIFuncStaticPie(b: *Build, opts: Options) *Step { | 1520 | fn testIFuncStaticPie(b: *Build, opts: Options) *Step { |
| 1436 | const test_step = addTestStep(b, "ifunc-static-pie", opts); | 1521 | const test_step = addTestStep(b, "ifunc-static-pie", opts); |
| 1437 | 1522 | ||
| 1438 | const exe = addExecutable(b, "main", opts); | 1523 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 1439 | addCSourceBytes(exe, | 1524 | addCSourceBytes(exe, |
| 1440 | \\#include <stdio.h> | 1525 | \\#include <stdio.h> |
| 1441 | \\void foo() __attribute__((ifunc("resolve_foo"))); | 1526 | \\void foo() __attribute__((ifunc("resolve_foo"))); |
| ... | @@ -1451,7 +1536,7 @@ fn testIFuncStaticPie(b: *Build, opts: Options) *Step { | ... | @@ -1451,7 +1536,7 @@ fn testIFuncStaticPie(b: *Build, opts: Options) *Step { |
| 1451 | \\} | 1536 | \\} |
| 1452 | , &.{}); | 1537 | , &.{}); |
| 1453 | exe.linkage = .static; | 1538 | exe.linkage = .static; |
| 1454 | exe.force_pic = true; | 1539 | exe.root_module.pic = true; |
| 1455 | exe.pie = true; | 1540 | exe.pie = true; |
| 1456 | exe.linkLibC(); | 1541 | exe.linkLibC(); |
| 1457 | 1542 | ||
| ... | @@ -1478,7 +1563,7 @@ fn testImageBase(b: *Build, opts: Options) *Step { | ... | @@ -1478,7 +1563,7 @@ fn testImageBase(b: *Build, opts: Options) *Step { |
| 1478 | const test_step = addTestStep(b, "image-base", opts); | 1563 | const test_step = addTestStep(b, "image-base", opts); |
| 1479 | 1564 | ||
| 1480 | { | 1565 | { |
| 1481 | const exe = addExecutable(b, "main1", opts); | 1566 | const exe = addExecutable(b, opts, .{ .name = "main1" }); |
| 1482 | addCSourceBytes(exe, | 1567 | addCSourceBytes(exe, |
| 1483 | \\#include <stdio.h> | 1568 | \\#include <stdio.h> |
| 1484 | \\int main() { | 1569 | \\int main() { |
| ... | @@ -1502,7 +1587,7 @@ fn testImageBase(b: *Build, opts: Options) *Step { | ... | @@ -1502,7 +1587,7 @@ fn testImageBase(b: *Build, opts: Options) *Step { |
| 1502 | } | 1587 | } |
| 1503 | 1588 | ||
| 1504 | { | 1589 | { |
| 1505 | const exe = addExecutable(b, "main2", opts); | 1590 | const exe = addExecutable(b, opts, .{ .name = "main2" }); |
| 1506 | addCSourceBytes(exe, "void _start() {}", &.{}); | 1591 | addCSourceBytes(exe, "void _start() {}", &.{}); |
| 1507 | exe.image_base = 0xffffffff8000000; | 1592 | exe.image_base = 0xffffffff8000000; |
| 1508 | 1593 | ||
| ... | @@ -1520,22 +1605,26 @@ fn testImageBase(b: *Build, opts: Options) *Step { | ... | @@ -1520,22 +1605,26 @@ fn testImageBase(b: *Build, opts: Options) *Step { |
| 1520 | fn testImportingDataDynamic(b: *Build, opts: Options) *Step { | 1605 | fn testImportingDataDynamic(b: *Build, opts: Options) *Step { |
| 1521 | const test_step = addTestStep(b, "importing-data-dynamic", opts); | 1606 | const test_step = addTestStep(b, "importing-data-dynamic", opts); |
| 1522 | 1607 | ||
| 1523 | const dso = addSharedLibrary(b, "a", .{ | 1608 | const dso = addSharedLibrary(b, .{ |
| 1524 | .target = opts.target, | 1609 | .target = opts.target, |
| 1525 | .optimize = opts.optimize, | 1610 | .optimize = opts.optimize, |
| 1526 | .use_llvm = true, | 1611 | .use_llvm = true, |
| 1612 | }, .{ | ||
| 1613 | .name = "a", | ||
| 1614 | .c_source_bytes = "int foo = 42;", | ||
| 1527 | }); | 1615 | }); |
| 1528 | addCSourceBytes(dso, "int foo = 42;", &.{}); | ||
| 1529 | 1616 | ||
| 1530 | const main = addExecutable(b, "main", opts); | 1617 | const main = addExecutable(b, opts, .{ |
| 1531 | addZigSourceBytes(main, | 1618 | .name = "main", |
| 1619 | .zig_source_bytes = | ||
| 1532 | \\extern var foo: i32; | 1620 | \\extern var foo: i32; |
| 1533 | \\pub fn main() void { | 1621 | \\pub fn main() void { |
| 1534 | \\ @import("std").debug.print("{d}\n", .{foo}); | 1622 | \\ @import("std").debug.print("{d}\n", .{foo}); |
| 1535 | \\} | 1623 | \\} |
| 1536 | ); | 1624 | , |
| 1625 | .strip = true, // TODO temp hack | ||
| 1626 | }); | ||
| 1537 | main.pie = true; | 1627 | main.pie = true; |
| 1538 | main.strip = true; // TODO temp hack | ||
| 1539 | main.linkLibrary(dso); | 1628 | main.linkLibrary(dso); |
| 1540 | main.linkLibC(); | 1629 | main.linkLibC(); |
| 1541 | 1630 | ||
| ... | @@ -1549,28 +1638,34 @@ fn testImportingDataDynamic(b: *Build, opts: Options) *Step { | ... | @@ -1549,28 +1638,34 @@ fn testImportingDataDynamic(b: *Build, opts: Options) *Step { |
| 1549 | fn testImportingDataStatic(b: *Build, opts: Options) *Step { | 1638 | fn testImportingDataStatic(b: *Build, opts: Options) *Step { |
| 1550 | const test_step = addTestStep(b, "importing-data-static", opts); | 1639 | const test_step = addTestStep(b, "importing-data-static", opts); |
| 1551 | 1640 | ||
| 1552 | const obj = addObject(b, "a", .{ | 1641 | const obj = addObject(b, .{ |
| 1553 | .target = opts.target, | 1642 | .target = opts.target, |
| 1554 | .optimize = opts.optimize, | 1643 | .optimize = opts.optimize, |
| 1555 | .use_llvm = true, | 1644 | .use_llvm = true, |
| 1645 | }, .{ | ||
| 1646 | .name = "a", | ||
| 1647 | .c_source_bytes = "int foo = 42;", | ||
| 1556 | }); | 1648 | }); |
| 1557 | addCSourceBytes(obj, "int foo = 42;", &.{}); | ||
| 1558 | 1649 | ||
| 1559 | const lib = addStaticLibrary(b, "a", .{ | 1650 | const lib = addStaticLibrary(b, .{ |
| 1560 | .target = opts.target, | 1651 | .target = opts.target, |
| 1561 | .optimize = opts.optimize, | 1652 | .optimize = opts.optimize, |
| 1562 | .use_llvm = true, | 1653 | .use_llvm = true, |
| 1654 | }, .{ | ||
| 1655 | .name = "a", | ||
| 1563 | }); | 1656 | }); |
| 1564 | lib.addObject(obj); | 1657 | lib.addObject(obj); |
| 1565 | 1658 | ||
| 1566 | const main = addExecutable(b, "main", opts); | 1659 | const main = addExecutable(b, opts, .{ |
| 1567 | addZigSourceBytes(main, | 1660 | .name = "main", |
| 1661 | .zig_source_bytes = | ||
| 1568 | \\extern var foo: i32; | 1662 | \\extern var foo: i32; |
| 1569 | \\pub fn main() void { | 1663 | \\pub fn main() void { |
| 1570 | \\ @import("std").debug.print("{d}\n", .{foo}); | 1664 | \\ @import("std").debug.print("{d}\n", .{foo}); |
| 1571 | \\} | 1665 | \\} |
| 1572 | ); | 1666 | , |
| 1573 | main.strip = true; // TODO temp hack | 1667 | .strip = true, // TODO temp hack |
| 1668 | }); | ||
| 1574 | main.linkLibrary(lib); | 1669 | main.linkLibrary(lib); |
| 1575 | main.linkLibC(); | 1670 | main.linkLibC(); |
| 1576 | 1671 | ||
| ... | @@ -1584,63 +1679,76 @@ fn testImportingDataStatic(b: *Build, opts: Options) *Step { | ... | @@ -1584,63 +1679,76 @@ fn testImportingDataStatic(b: *Build, opts: Options) *Step { |
| 1584 | fn testInitArrayOrder(b: *Build, opts: Options) *Step { | 1679 | fn testInitArrayOrder(b: *Build, opts: Options) *Step { |
| 1585 | const test_step = addTestStep(b, "init-array-order", opts); | 1680 | const test_step = addTestStep(b, "init-array-order", opts); |
| 1586 | 1681 | ||
| 1587 | const a_o = addObject(b, "a", opts); | 1682 | const a_o = addObject(b, opts, .{ |
| 1588 | addCSourceBytes(a_o, | 1683 | .name = "a", |
| 1684 | .c_source_bytes = | ||
| 1589 | \\#include <stdio.h> | 1685 | \\#include <stdio.h> |
| 1590 | \\__attribute__((constructor(10000))) void init4() { printf("1"); } | 1686 | \\__attribute__((constructor(10000))) void init4() { printf("1"); } |
| 1591 | , &.{}); | 1687 | , |
| 1688 | }); | ||
| 1592 | a_o.linkLibC(); | 1689 | a_o.linkLibC(); |
| 1593 | 1690 | ||
| 1594 | const b_o = addObject(b, "b", opts); | 1691 | const b_o = addObject(b, opts, .{ |
| 1595 | addCSourceBytes(b_o, | 1692 | .name = "b", |
| 1693 | .c_source_bytes = | ||
| 1596 | \\#include <stdio.h> | 1694 | \\#include <stdio.h> |
| 1597 | \\__attribute__((constructor(1000))) void init3() { printf("2"); } | 1695 | \\__attribute__((constructor(1000))) void init3() { printf("2"); } |
| 1598 | , &.{}); | 1696 | , |
| 1697 | }); | ||
| 1599 | b_o.linkLibC(); | 1698 | b_o.linkLibC(); |
| 1600 | 1699 | ||
| 1601 | const c_o = addObject(b, "c", opts); | 1700 | const c_o = addObject(b, opts, .{ |
| 1602 | addCSourceBytes(c_o, | 1701 | .name = "c", |
| 1702 | .c_source_bytes = | ||
| 1603 | \\#include <stdio.h> | 1703 | \\#include <stdio.h> |
| 1604 | \\__attribute__((constructor)) void init1() { printf("3"); } | 1704 | \\__attribute__((constructor)) void init1() { printf("3"); } |
| 1605 | , &.{}); | 1705 | , |
| 1706 | }); | ||
| 1606 | c_o.linkLibC(); | 1707 | c_o.linkLibC(); |
| 1607 | 1708 | ||
| 1608 | const d_o = addObject(b, "d", opts); | 1709 | const d_o = addObject(b, opts, .{ |
| 1609 | addCSourceBytes(d_o, | 1710 | .name = "d", |
| 1711 | .c_source_bytes = | ||
| 1610 | \\#include <stdio.h> | 1712 | \\#include <stdio.h> |
| 1611 | \\__attribute__((constructor)) void init2() { printf("4"); } | 1713 | \\__attribute__((constructor)) void init2() { printf("4"); } |
| 1612 | , &.{}); | 1714 | , |
| 1715 | }); | ||
| 1613 | d_o.linkLibC(); | 1716 | d_o.linkLibC(); |
| 1614 | 1717 | ||
| 1615 | const e_o = addObject(b, "e", opts); | 1718 | const e_o = addObject(b, opts, .{ |
| 1616 | addCSourceBytes(e_o, | 1719 | .name = "e", |
| 1720 | .c_source_bytes = | ||
| 1617 | \\#include <stdio.h> | 1721 | \\#include <stdio.h> |
| 1618 | \\__attribute__((destructor(10000))) void fini4() { printf("5"); } | 1722 | \\__attribute__((destructor(10000))) void fini4() { printf("5"); } |
| 1619 | , &.{}); | 1723 | , |
| 1724 | }); | ||
| 1620 | e_o.linkLibC(); | 1725 | e_o.linkLibC(); |
| 1621 | 1726 | ||
| 1622 | const f_o = addObject(b, "f", opts); | 1727 | const f_o = addObject(b, opts, .{ |
| 1623 | addCSourceBytes(f_o, | 1728 | .name = "f", |
| 1729 | .c_source_bytes = | ||
| 1624 | \\#include <stdio.h> | 1730 | \\#include <stdio.h> |
| 1625 | \\__attribute__((destructor(1000))) void fini3() { printf("6"); } | 1731 | \\__attribute__((destructor(1000))) void fini3() { printf("6"); } |
| 1626 | , &.{}); | 1732 | , |
| 1733 | }); | ||
| 1627 | f_o.linkLibC(); | 1734 | f_o.linkLibC(); |
| 1628 | 1735 | ||
| 1629 | const g_o = addObject(b, "g", opts); | 1736 | const g_o = addObject(b, opts, .{ |
| 1630 | addCSourceBytes(g_o, | 1737 | .name = "g", |
| 1738 | .c_source_bytes = | ||
| 1631 | \\#include <stdio.h> | 1739 | \\#include <stdio.h> |
| 1632 | \\__attribute__((destructor)) void fini1() { printf("7"); } | 1740 | \\__attribute__((destructor)) void fini1() { printf("7"); } |
| 1633 | , &.{}); | 1741 | , |
| 1742 | }); | ||
| 1634 | g_o.linkLibC(); | 1743 | g_o.linkLibC(); |
| 1635 | 1744 | ||
| 1636 | const h_o = addObject(b, "h", opts); | 1745 | const h_o = addObject(b, opts, .{ .name = "h", .c_source_bytes = |
| 1637 | addCSourceBytes(h_o, | 1746 | \\#include <stdio.h> |
| 1638 | \\#include <stdio.h> | 1747 | \\__attribute__((destructor)) void fini2() { printf("8"); } |
| 1639 | \\__attribute__((destructor)) void fini2() { printf("8"); } | 1748 | }); |
| 1640 | , &.{}); | ||
| 1641 | h_o.linkLibC(); | 1749 | h_o.linkLibC(); |
| 1642 | 1750 | ||
| 1643 | const exe = addExecutable(b, "main", opts); | 1751 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 1644 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); | 1752 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); |
| 1645 | exe.addObject(a_o); | 1753 | exe.addObject(a_o); |
| 1646 | exe.addObject(b_o); | 1754 | exe.addObject(b_o); |
| ... | @@ -1651,7 +1759,7 @@ fn testInitArrayOrder(b: *Build, opts: Options) *Step { | ... | @@ -1651,7 +1759,7 @@ fn testInitArrayOrder(b: *Build, opts: Options) *Step { |
| 1651 | exe.addObject(g_o); | 1759 | exe.addObject(g_o); |
| 1652 | exe.addObject(h_o); | 1760 | exe.addObject(h_o); |
| 1653 | 1761 | ||
| 1654 | if (opts.target.isGnuLibC()) { | 1762 | if (opts.target.target.isGnuLibC()) { |
| 1655 | // TODO I think we need to clarify our use of `-fPIC -fPIE` flags for different targets | 1763 | // TODO I think we need to clarify our use of `-fPIC -fPIE` flags for different targets |
| 1656 | exe.pie = true; | 1764 | exe.pie = true; |
| 1657 | } | 1765 | } |
| ... | @@ -1666,7 +1774,7 @@ fn testInitArrayOrder(b: *Build, opts: Options) *Step { | ... | @@ -1666,7 +1774,7 @@ fn testInitArrayOrder(b: *Build, opts: Options) *Step { |
| 1666 | fn testLargeAlignmentDso(b: *Build, opts: Options) *Step { | 1774 | fn testLargeAlignmentDso(b: *Build, opts: Options) *Step { |
| 1667 | const test_step = addTestStep(b, "large-alignment-dso", opts); | 1775 | const test_step = addTestStep(b, "large-alignment-dso", opts); |
| 1668 | 1776 | ||
| 1669 | const dso = addSharedLibrary(b, "dso", opts); | 1777 | const dso = addSharedLibrary(b, opts, .{ .name = "dso" }); |
| 1670 | addCSourceBytes(dso, | 1778 | addCSourceBytes(dso, |
| 1671 | \\#include <stdio.h> | 1779 | \\#include <stdio.h> |
| 1672 | \\#include <stdint.h> | 1780 | \\#include <stdint.h> |
| ... | @@ -1695,7 +1803,7 @@ fn testLargeAlignmentDso(b: *Build, opts: Options) *Step { | ... | @@ -1695,7 +1803,7 @@ fn testLargeAlignmentDso(b: *Build, opts: Options) *Step { |
| 1695 | check.checkComputeCompare("addr2 16 %", .{ .op = .eq, .value = .{ .literal = 0 } }); | 1803 | check.checkComputeCompare("addr2 16 %", .{ .op = .eq, .value = .{ .literal = 0 } }); |
| 1696 | test_step.dependOn(&check.step); | 1804 | test_step.dependOn(&check.step); |
| 1697 | 1805 | ||
| 1698 | const exe = addExecutable(b, "test", opts); | 1806 | const exe = addExecutable(b, opts, .{ .name = "test" }); |
| 1699 | addCSourceBytes(exe, | 1807 | addCSourceBytes(exe, |
| 1700 | \\void greet(); | 1808 | \\void greet(); |
| 1701 | \\int main() { greet(); } | 1809 | \\int main() { greet(); } |
| ... | @@ -1715,7 +1823,7 @@ fn testLargeAlignmentDso(b: *Build, opts: Options) *Step { | ... | @@ -1715,7 +1823,7 @@ fn testLargeAlignmentDso(b: *Build, opts: Options) *Step { |
| 1715 | fn testLargeAlignmentExe(b: *Build, opts: Options) *Step { | 1823 | fn testLargeAlignmentExe(b: *Build, opts: Options) *Step { |
| 1716 | const test_step = addTestStep(b, "large-alignment-exe", opts); | 1824 | const test_step = addTestStep(b, "large-alignment-exe", opts); |
| 1717 | 1825 | ||
| 1718 | const exe = addExecutable(b, "test", opts); | 1826 | const exe = addExecutable(b, opts, .{ .name = "test" }); |
| 1719 | addCSourceBytes(exe, | 1827 | addCSourceBytes(exe, |
| 1720 | \\#include <stdio.h> | 1828 | \\#include <stdio.h> |
| 1721 | \\#include <stdint.h> | 1829 | \\#include <stdint.h> |
| ... | @@ -1760,7 +1868,7 @@ fn testLargeAlignmentExe(b: *Build, opts: Options) *Step { | ... | @@ -1760,7 +1868,7 @@ fn testLargeAlignmentExe(b: *Build, opts: Options) *Step { |
| 1760 | fn testLargeBss(b: *Build, opts: Options) *Step { | 1868 | fn testLargeBss(b: *Build, opts: Options) *Step { |
| 1761 | const test_step = addTestStep(b, "large-bss", opts); | 1869 | const test_step = addTestStep(b, "large-bss", opts); |
| 1762 | 1870 | ||
| 1763 | const exe = addExecutable(b, "main", opts); | 1871 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 1764 | addCSourceBytes(exe, | 1872 | addCSourceBytes(exe, |
| 1765 | \\char arr[0x100000000]; | 1873 | \\char arr[0x100000000]; |
| 1766 | \\int main() { | 1874 | \\int main() { |
| ... | @@ -1781,27 +1889,31 @@ fn testLargeBss(b: *Build, opts: Options) *Step { | ... | @@ -1781,27 +1889,31 @@ fn testLargeBss(b: *Build, opts: Options) *Step { |
| 1781 | fn testLinkOrder(b: *Build, opts: Options) *Step { | 1889 | fn testLinkOrder(b: *Build, opts: Options) *Step { |
| 1782 | const test_step = addTestStep(b, "link-order", opts); | 1890 | const test_step = addTestStep(b, "link-order", opts); |
| 1783 | 1891 | ||
| 1784 | const obj = addObject(b, "obj", opts); | 1892 | const obj = addObject(b, opts, .{ |
| 1785 | addCSourceBytes(obj, "void foo() {}", &.{}); | 1893 | .name = "obj", |
| 1786 | obj.force_pic = true; | 1894 | .c_source_bytes = "void foo() {}", |
| 1895 | .pic = true, | ||
| 1896 | }); | ||
| 1787 | 1897 | ||
| 1788 | const dso = addSharedLibrary(b, "a", opts); | 1898 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 1789 | dso.addObject(obj); | 1899 | dso.addObject(obj); |
| 1790 | 1900 | ||
| 1791 | const lib = addStaticLibrary(b, "b", opts); | 1901 | const lib = addStaticLibrary(b, opts, .{ .name = "b" }); |
| 1792 | lib.addObject(obj); | 1902 | lib.addObject(obj); |
| 1793 | 1903 | ||
| 1794 | const main_o = addObject(b, "main", opts); | 1904 | const main_o = addObject(b, opts, .{ |
| 1795 | addCSourceBytes(main_o, | 1905 | .name = "main", |
| 1906 | .c_source_bytes = | ||
| 1796 | \\void foo(); | 1907 | \\void foo(); |
| 1797 | \\int main() { | 1908 | \\int main() { |
| 1798 | \\ foo(); | 1909 | \\ foo(); |
| 1799 | \\} | 1910 | \\} |
| 1800 | , &.{}); | 1911 | , |
| 1912 | }); | ||
| 1801 | 1913 | ||
| 1802 | // https://github.com/ziglang/zig/issues/17450 | 1914 | // https://github.com/ziglang/zig/issues/17450 |
| 1803 | // { | 1915 | // { |
| 1804 | // const exe = addExecutable(b, "main1", opts); | 1916 | // const exe = addExecutable(b, opts, .{ .name = "main1"}); |
| 1805 | // exe.addObject(main_o); | 1917 | // exe.addObject(main_o); |
| 1806 | // exe.linkSystemLibrary2("a", .{}); | 1918 | // exe.linkSystemLibrary2("a", .{}); |
| 1807 | // exe.addLibraryPath(dso.getEmittedBinDirectory()); | 1919 | // exe.addLibraryPath(dso.getEmittedBinDirectory()); |
| ... | @@ -1818,7 +1930,7 @@ fn testLinkOrder(b: *Build, opts: Options) *Step { | ... | @@ -1818,7 +1930,7 @@ fn testLinkOrder(b: *Build, opts: Options) *Step { |
| 1818 | // } | 1930 | // } |
| 1819 | 1931 | ||
| 1820 | { | 1932 | { |
| 1821 | const exe = addExecutable(b, "main2", opts); | 1933 | const exe = addExecutable(b, opts, .{ .name = "main2" }); |
| 1822 | exe.addObject(main_o); | 1934 | exe.addObject(main_o); |
| 1823 | exe.linkSystemLibrary2("b", .{}); | 1935 | exe.linkSystemLibrary2("b", .{}); |
| 1824 | exe.addLibraryPath(lib.getEmittedBinDirectory()); | 1936 | exe.addLibraryPath(lib.getEmittedBinDirectory()); |
| ... | @@ -1840,14 +1952,14 @@ fn testLinkOrder(b: *Build, opts: Options) *Step { | ... | @@ -1840,14 +1952,14 @@ fn testLinkOrder(b: *Build, opts: Options) *Step { |
| 1840 | fn testLdScript(b: *Build, opts: Options) *Step { | 1952 | fn testLdScript(b: *Build, opts: Options) *Step { |
| 1841 | const test_step = addTestStep(b, "ld-script", opts); | 1953 | const test_step = addTestStep(b, "ld-script", opts); |
| 1842 | 1954 | ||
| 1843 | const dso = addSharedLibrary(b, "bar", opts); | 1955 | const dso = addSharedLibrary(b, opts, .{ .name = "bar" }); |
| 1844 | addCSourceBytes(dso, "int foo() { return 42; }", &.{}); | 1956 | addCSourceBytes(dso, "int foo() { return 42; }", &.{}); |
| 1845 | 1957 | ||
| 1846 | const scripts = WriteFile.create(b); | 1958 | const scripts = WriteFile.create(b); |
| 1847 | _ = scripts.add("liba.so", "INPUT(libfoo.so)"); | 1959 | _ = scripts.add("liba.so", "INPUT(libfoo.so)"); |
| 1848 | _ = scripts.add("libfoo.so", "GROUP(AS_NEEDED(-lbar))"); | 1960 | _ = scripts.add("libfoo.so", "GROUP(AS_NEEDED(-lbar))"); |
| 1849 | 1961 | ||
| 1850 | const exe = addExecutable(b, "main", opts); | 1962 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 1851 | addCSourceBytes(exe, | 1963 | addCSourceBytes(exe, |
| 1852 | \\int foo(); | 1964 | \\int foo(); |
| 1853 | \\int main() { | 1965 | \\int main() { |
| ... | @@ -1875,7 +1987,7 @@ fn testLdScriptPathError(b: *Build, opts: Options) *Step { | ... | @@ -1875,7 +1987,7 @@ fn testLdScriptPathError(b: *Build, opts: Options) *Step { |
| 1875 | const scripts = WriteFile.create(b); | 1987 | const scripts = WriteFile.create(b); |
| 1876 | _ = scripts.add("liba.so", "INPUT(libfoo.so)"); | 1988 | _ = scripts.add("liba.so", "INPUT(libfoo.so)"); |
| 1877 | 1989 | ||
| 1878 | const exe = addExecutable(b, "main", opts); | 1990 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 1879 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); | 1991 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); |
| 1880 | exe.linkSystemLibrary2("a", .{}); | 1992 | exe.linkSystemLibrary2("a", .{}); |
| 1881 | exe.addLibraryPath(scripts.getDirectory()); | 1993 | exe.addLibraryPath(scripts.getDirectory()); |
| ... | @@ -1895,13 +2007,15 @@ fn testLdScriptPathError(b: *Build, opts: Options) *Step { | ... | @@ -1895,13 +2007,15 @@ fn testLdScriptPathError(b: *Build, opts: Options) *Step { |
| 1895 | fn testMismatchedCpuArchitectureError(b: *Build, opts: Options) *Step { | 2007 | fn testMismatchedCpuArchitectureError(b: *Build, opts: Options) *Step { |
| 1896 | const test_step = addTestStep(b, "mismatched-cpu-architecture-error", opts); | 2008 | const test_step = addTestStep(b, "mismatched-cpu-architecture-error", opts); |
| 1897 | 2009 | ||
| 1898 | const obj = addObject(b, "a", .{ | 2010 | const obj = addObject(b, .{ |
| 1899 | .target = .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu }, | 2011 | .target = b.resolveTargetQuery(.{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu }), |
| 2012 | }, .{ | ||
| 2013 | .name = "a", | ||
| 2014 | .c_source_bytes = "int foo;", | ||
| 2015 | .strip = true, | ||
| 1900 | }); | 2016 | }); |
| 1901 | addCSourceBytes(obj, "int foo;", &.{}); | ||
| 1902 | obj.strip = true; | ||
| 1903 | 2017 | ||
| 1904 | const exe = addExecutable(b, "main", opts); | 2018 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 1905 | addCSourceBytes(exe, | 2019 | addCSourceBytes(exe, |
| 1906 | \\extern int foo; | 2020 | \\extern int foo; |
| 1907 | \\int main() { | 2021 | \\int main() { |
| ... | @@ -1922,7 +2036,7 @@ fn testMismatchedCpuArchitectureError(b: *Build, opts: Options) *Step { | ... | @@ -1922,7 +2036,7 @@ fn testMismatchedCpuArchitectureError(b: *Build, opts: Options) *Step { |
| 1922 | fn testLinkingC(b: *Build, opts: Options) *Step { | 2036 | fn testLinkingC(b: *Build, opts: Options) *Step { |
| 1923 | const test_step = addTestStep(b, "linking-c", opts); | 2037 | const test_step = addTestStep(b, "linking-c", opts); |
| 1924 | 2038 | ||
| 1925 | const exe = addExecutable(b, "test", opts); | 2039 | const exe = addExecutable(b, opts, .{ .name = "test" }); |
| 1926 | addCSourceBytes(exe, | 2040 | addCSourceBytes(exe, |
| 1927 | \\#include <stdio.h> | 2041 | \\#include <stdio.h> |
| 1928 | \\int main() { | 2042 | \\int main() { |
| ... | @@ -1951,7 +2065,7 @@ fn testLinkingC(b: *Build, opts: Options) *Step { | ... | @@ -1951,7 +2065,7 @@ fn testLinkingC(b: *Build, opts: Options) *Step { |
| 1951 | fn testLinkingCpp(b: *Build, opts: Options) *Step { | 2065 | fn testLinkingCpp(b: *Build, opts: Options) *Step { |
| 1952 | const test_step = addTestStep(b, "linking-cpp", opts); | 2066 | const test_step = addTestStep(b, "linking-cpp", opts); |
| 1953 | 2067 | ||
| 1954 | const exe = addExecutable(b, "test", opts); | 2068 | const exe = addExecutable(b, opts, .{ .name = "test" }); |
| 1955 | addCppSourceBytes(exe, | 2069 | addCppSourceBytes(exe, |
| 1956 | \\#include <iostream> | 2070 | \\#include <iostream> |
| 1957 | \\int main() { | 2071 | \\int main() { |
| ... | @@ -1981,24 +2095,28 @@ fn testLinkingCpp(b: *Build, opts: Options) *Step { | ... | @@ -1981,24 +2095,28 @@ fn testLinkingCpp(b: *Build, opts: Options) *Step { |
| 1981 | fn testLinkingObj(b: *Build, opts: Options) *Step { | 2095 | fn testLinkingObj(b: *Build, opts: Options) *Step { |
| 1982 | const test_step = addTestStep(b, "linking-obj", opts); | 2096 | const test_step = addTestStep(b, "linking-obj", opts); |
| 1983 | 2097 | ||
| 1984 | const obj = addObject(b, "aobj", opts); | 2098 | const obj = addObject(b, opts, .{ |
| 1985 | addZigSourceBytes(obj, | 2099 | .name = "aobj", |
| 2100 | .zig_source_bytes = | ||
| 1986 | \\extern var mod: usize; | 2101 | \\extern var mod: usize; |
| 1987 | \\export fn callMe() usize { | 2102 | \\export fn callMe() usize { |
| 1988 | \\ return me * mod; | 2103 | \\ return me * mod; |
| 1989 | \\} | 2104 | \\} |
| 1990 | \\var me: usize = 42; | 2105 | \\var me: usize = 42; |
| 1991 | ); | 2106 | , |
| 2107 | }); | ||
| 1992 | 2108 | ||
| 1993 | const exe = addExecutable(b, "testobj", opts); | 2109 | const exe = addExecutable(b, opts, .{ |
| 1994 | addZigSourceBytes(exe, | 2110 | .name = "testobj", |
| 2111 | .zig_source_bytes = | ||
| 1995 | \\const std = @import("std"); | 2112 | \\const std = @import("std"); |
| 1996 | \\extern fn callMe() usize; | 2113 | \\extern fn callMe() usize; |
| 1997 | \\export var mod: usize = 2; | 2114 | \\export var mod: usize = 2; |
| 1998 | \\pub fn main() void { | 2115 | \\pub fn main() void { |
| 1999 | \\ std.debug.print("{d}\n", .{callMe()}); | 2116 | \\ std.debug.print("{d}\n", .{callMe()}); |
| 2000 | \\} | 2117 | \\} |
| 2001 | ); | 2118 | , |
| 2119 | }); | ||
| 2002 | exe.addObject(obj); | 2120 | exe.addObject(obj); |
| 2003 | 2121 | ||
| 2004 | const run = addRunArtifact(exe); | 2122 | const run = addRunArtifact(exe); |
| ... | @@ -2011,26 +2129,32 @@ fn testLinkingObj(b: *Build, opts: Options) *Step { | ... | @@ -2011,26 +2129,32 @@ fn testLinkingObj(b: *Build, opts: Options) *Step { |
| 2011 | fn testLinkingStaticLib(b: *Build, opts: Options) *Step { | 2129 | fn testLinkingStaticLib(b: *Build, opts: Options) *Step { |
| 2012 | const test_step = addTestStep(b, "linking-static-lib", opts); | 2130 | const test_step = addTestStep(b, "linking-static-lib", opts); |
| 2013 | 2131 | ||
| 2014 | const obj = addObject(b, "bobj", opts); | 2132 | const obj = addObject(b, opts, .{ |
| 2015 | addZigSourceBytes(obj, "export var bar: i32 = -42;"); | 2133 | .name = "bobj", |
| 2134 | .zig_source_bytes = "export var bar: i32 = -42;", | ||
| 2135 | }); | ||
| 2016 | 2136 | ||
| 2017 | const lib = addStaticLibrary(b, "alib", opts); | 2137 | const lib = addStaticLibrary(b, opts, .{ |
| 2018 | addZigSourceBytes(lib, | 2138 | .name = "alib", |
| 2139 | .zig_source_bytes = | ||
| 2019 | \\export fn foo() i32 { | 2140 | \\export fn foo() i32 { |
| 2020 | \\ return 42; | 2141 | \\ return 42; |
| 2021 | \\} | 2142 | \\} |
| 2022 | ); | 2143 | , |
| 2144 | }); | ||
| 2023 | lib.addObject(obj); | 2145 | lib.addObject(obj); |
| 2024 | 2146 | ||
| 2025 | const exe = addExecutable(b, "testlib", opts); | 2147 | const exe = addExecutable(b, opts, .{ |
| 2026 | addZigSourceBytes(exe, | 2148 | .name = "testlib", |
| 2149 | .zig_source_bytes = | ||
| 2027 | \\const std = @import("std"); | 2150 | \\const std = @import("std"); |
| 2028 | \\extern fn foo() i32; | 2151 | \\extern fn foo() i32; |
| 2029 | \\extern var bar: i32; | 2152 | \\extern var bar: i32; |
| 2030 | \\pub fn main() void { | 2153 | \\pub fn main() void { |
| 2031 | \\ std.debug.print("{d}\n", .{foo() + bar}); | 2154 | \\ std.debug.print("{d}\n", .{foo() + bar}); |
| 2032 | \\} | 2155 | \\} |
| 2033 | ); | 2156 | , |
| 2157 | }); | ||
| 2034 | exe.linkLibrary(lib); | 2158 | exe.linkLibrary(lib); |
| 2035 | 2159 | ||
| 2036 | const run = addRunArtifact(exe); | 2160 | const run = addRunArtifact(exe); |
| ... | @@ -2043,12 +2167,14 @@ fn testLinkingStaticLib(b: *Build, opts: Options) *Step { | ... | @@ -2043,12 +2167,14 @@ fn testLinkingStaticLib(b: *Build, opts: Options) *Step { |
| 2043 | fn testLinkingZig(b: *Build, opts: Options) *Step { | 2167 | fn testLinkingZig(b: *Build, opts: Options) *Step { |
| 2044 | const test_step = addTestStep(b, "linking-zig-static", opts); | 2168 | const test_step = addTestStep(b, "linking-zig-static", opts); |
| 2045 | 2169 | ||
| 2046 | const exe = addExecutable(b, "test", opts); | 2170 | const exe = addExecutable(b, opts, .{ |
| 2047 | addZigSourceBytes(exe, | 2171 | .name = "test", |
| 2172 | .zig_source_bytes = | ||
| 2048 | \\pub fn main() void { | 2173 | \\pub fn main() void { |
| 2049 | \\ @import("std").debug.print("Hello World!\n", .{}); | 2174 | \\ @import("std").debug.print("Hello World!\n", .{}); |
| 2050 | \\} | 2175 | \\} |
| 2051 | ); | 2176 | , |
| 2177 | }); | ||
| 2052 | 2178 | ||
| 2053 | const run = addRunArtifact(exe); | 2179 | const run = addRunArtifact(exe); |
| 2054 | run.expectStdErrEqual("Hello World!\n"); | 2180 | run.expectStdErrEqual("Hello World!\n"); |
| ... | @@ -2069,7 +2195,7 @@ fn testLinkingZig(b: *Build, opts: Options) *Step { | ... | @@ -2069,7 +2195,7 @@ fn testLinkingZig(b: *Build, opts: Options) *Step { |
| 2069 | fn testNoEhFrameHdr(b: *Build, opts: Options) *Step { | 2195 | fn testNoEhFrameHdr(b: *Build, opts: Options) *Step { |
| 2070 | const test_step = addTestStep(b, "no-eh-frame-hdr", opts); | 2196 | const test_step = addTestStep(b, "no-eh-frame-hdr", opts); |
| 2071 | 2197 | ||
| 2072 | const exe = addExecutable(b, "main", opts); | 2198 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 2073 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); | 2199 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); |
| 2074 | exe.link_eh_frame_hdr = false; | 2200 | exe.link_eh_frame_hdr = false; |
| 2075 | exe.linkLibC(); | 2201 | exe.linkLibC(); |
| ... | @@ -2086,7 +2212,7 @@ fn testNoEhFrameHdr(b: *Build, opts: Options) *Step { | ... | @@ -2086,7 +2212,7 @@ fn testNoEhFrameHdr(b: *Build, opts: Options) *Step { |
| 2086 | fn testPie(b: *Build, opts: Options) *Step { | 2212 | fn testPie(b: *Build, opts: Options) *Step { |
| 2087 | const test_step = addTestStep(b, "hello-pie", opts); | 2213 | const test_step = addTestStep(b, "hello-pie", opts); |
| 2088 | 2214 | ||
| 2089 | const exe = addExecutable(b, "main", opts); | 2215 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 2090 | addCSourceBytes(exe, | 2216 | addCSourceBytes(exe, |
| 2091 | \\#include <stdio.h> | 2217 | \\#include <stdio.h> |
| 2092 | \\int main() { | 2218 | \\int main() { |
| ... | @@ -2095,7 +2221,7 @@ fn testPie(b: *Build, opts: Options) *Step { | ... | @@ -2095,7 +2221,7 @@ fn testPie(b: *Build, opts: Options) *Step { |
| 2095 | \\} | 2221 | \\} |
| 2096 | , &.{}); | 2222 | , &.{}); |
| 2097 | exe.linkLibC(); | 2223 | exe.linkLibC(); |
| 2098 | exe.force_pic = true; | 2224 | exe.root_module.pic = true; |
| 2099 | exe.pie = true; | 2225 | exe.pie = true; |
| 2100 | 2226 | ||
| 2101 | const run = addRunArtifact(exe); | 2227 | const run = addRunArtifact(exe); |
| ... | @@ -2117,7 +2243,7 @@ fn testPie(b: *Build, opts: Options) *Step { | ... | @@ -2117,7 +2243,7 @@ fn testPie(b: *Build, opts: Options) *Step { |
| 2117 | fn testPltGot(b: *Build, opts: Options) *Step { | 2243 | fn testPltGot(b: *Build, opts: Options) *Step { |
| 2118 | const test_step = addTestStep(b, "plt-got", opts); | 2244 | const test_step = addTestStep(b, "plt-got", opts); |
| 2119 | 2245 | ||
| 2120 | const dso = addSharedLibrary(b, "a", opts); | 2246 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 2121 | addCSourceBytes(dso, | 2247 | addCSourceBytes(dso, |
| 2122 | \\#include <stdio.h> | 2248 | \\#include <stdio.h> |
| 2123 | \\void ignore(void *foo) {} | 2249 | \\void ignore(void *foo) {} |
| ... | @@ -2127,7 +2253,7 @@ fn testPltGot(b: *Build, opts: Options) *Step { | ... | @@ -2127,7 +2253,7 @@ fn testPltGot(b: *Build, opts: Options) *Step { |
| 2127 | , &.{}); | 2253 | , &.{}); |
| 2128 | dso.linkLibC(); | 2254 | dso.linkLibC(); |
| 2129 | 2255 | ||
| 2130 | const exe = addExecutable(b, "main", opts); | 2256 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 2131 | addCSourceBytes(exe, | 2257 | addCSourceBytes(exe, |
| 2132 | \\void ignore(void *); | 2258 | \\void ignore(void *); |
| 2133 | \\int hello(); | 2259 | \\int hello(); |
| ... | @@ -2135,7 +2261,7 @@ fn testPltGot(b: *Build, opts: Options) *Step { | ... | @@ -2135,7 +2261,7 @@ fn testPltGot(b: *Build, opts: Options) *Step { |
| 2135 | \\int main() { hello(); } | 2261 | \\int main() { hello(); } |
| 2136 | , &.{}); | 2262 | , &.{}); |
| 2137 | exe.linkLibrary(dso); | 2263 | exe.linkLibrary(dso); |
| 2138 | exe.force_pic = true; | 2264 | exe.root_module.pic = true; |
| 2139 | exe.linkLibC(); | 2265 | exe.linkLibC(); |
| 2140 | // https://github.com/ziglang/zig/issues/17619 | 2266 | // https://github.com/ziglang/zig/issues/17619 |
| 2141 | exe.pie = true; | 2267 | exe.pie = true; |
| ... | @@ -2151,10 +2277,12 @@ fn testPreinitArray(b: *Build, opts: Options) *Step { | ... | @@ -2151,10 +2277,12 @@ fn testPreinitArray(b: *Build, opts: Options) *Step { |
| 2151 | const test_step = addTestStep(b, "preinit-array", opts); | 2277 | const test_step = addTestStep(b, "preinit-array", opts); |
| 2152 | 2278 | ||
| 2153 | { | 2279 | { |
| 2154 | const obj = addObject(b, "obj", opts); | 2280 | const obj = addObject(b, opts, .{ |
| 2155 | addCSourceBytes(obj, "void _start() {}", &.{}); | 2281 | .name = "obj", |
| 2282 | .c_source_bytes = "void _start() {}", | ||
| 2283 | }); | ||
| 2156 | 2284 | ||
| 2157 | const exe = addExecutable(b, "main1", opts); | 2285 | const exe = addExecutable(b, opts, .{ .name = "main1" }); |
| 2158 | exe.addObject(obj); | 2286 | exe.addObject(obj); |
| 2159 | 2287 | ||
| 2160 | const check = exe.checkObject(); | 2288 | const check = exe.checkObject(); |
| ... | @@ -2163,7 +2291,7 @@ fn testPreinitArray(b: *Build, opts: Options) *Step { | ... | @@ -2163,7 +2291,7 @@ fn testPreinitArray(b: *Build, opts: Options) *Step { |
| 2163 | } | 2291 | } |
| 2164 | 2292 | ||
| 2165 | { | 2293 | { |
| 2166 | const exe = addExecutable(b, "main2", opts); | 2294 | const exe = addExecutable(b, opts, .{ .name = "main2" }); |
| 2167 | addCSourceBytes(exe, | 2295 | addCSourceBytes(exe, |
| 2168 | \\void preinit_fn() {} | 2296 | \\void preinit_fn() {} |
| 2169 | \\int main() {} | 2297 | \\int main() {} |
| ... | @@ -2183,38 +2311,48 @@ fn testPreinitArray(b: *Build, opts: Options) *Step { | ... | @@ -2183,38 +2311,48 @@ fn testPreinitArray(b: *Build, opts: Options) *Step { |
| 2183 | fn testRelocatableArchive(b: *Build, opts: Options) *Step { | 2311 | fn testRelocatableArchive(b: *Build, opts: Options) *Step { |
| 2184 | const test_step = addTestStep(b, "relocatable-archive", opts); | 2312 | const test_step = addTestStep(b, "relocatable-archive", opts); |
| 2185 | 2313 | ||
| 2186 | const obj1 = addObject(b, "obj1", opts); | 2314 | const obj1 = addObject(b, opts, .{ |
| 2187 | addCSourceBytes(obj1, | 2315 | .name = "obj1", |
| 2316 | .c_source_bytes = | ||
| 2188 | \\void bar(); | 2317 | \\void bar(); |
| 2189 | \\void foo() { | 2318 | \\void foo() { |
| 2190 | \\ bar(); | 2319 | \\ bar(); |
| 2191 | \\} | 2320 | \\} |
| 2192 | , &.{}); | 2321 | , |
| 2322 | }); | ||
| 2193 | 2323 | ||
| 2194 | const obj2 = addObject(b, "obj2", opts); | 2324 | const obj2 = addObject(b, opts, .{ |
| 2195 | addCSourceBytes(obj2, | 2325 | .name = "obj2", |
| 2326 | .c_source_bytes = | ||
| 2196 | \\void bar() {} | 2327 | \\void bar() {} |
| 2197 | , &.{}); | 2328 | , |
| 2329 | }); | ||
| 2198 | 2330 | ||
| 2199 | const obj3 = addObject(b, "obj3", opts); | 2331 | const obj3 = addObject(b, opts, .{ |
| 2200 | addCSourceBytes(obj3, | 2332 | .name = "obj3", |
| 2333 | .c_source_bytes = | ||
| 2201 | \\void baz(); | 2334 | \\void baz(); |
| 2202 | , &.{}); | 2335 | , |
| 2336 | }); | ||
| 2203 | 2337 | ||
| 2204 | const obj4 = addObject(b, "obj4", opts); | 2338 | const obj4 = addObject(b, opts, .{ |
| 2205 | addCSourceBytes(obj4, | 2339 | .name = "obj4", |
| 2340 | .c_source_bytes = | ||
| 2206 | \\void foo(); | 2341 | \\void foo(); |
| 2207 | \\int main() { | 2342 | \\int main() { |
| 2208 | \\ foo(); | 2343 | \\ foo(); |
| 2209 | \\} | 2344 | \\} |
| 2210 | , &.{}); | 2345 | , |
| 2346 | }); | ||
| 2211 | 2347 | ||
| 2212 | const lib = addStaticLibrary(b, "lib", opts); | 2348 | const lib = addStaticLibrary(b, opts, .{ .name = "lib" }); |
| 2213 | lib.addObject(obj1); | 2349 | lib.addObject(obj1); |
| 2214 | lib.addObject(obj2); | 2350 | lib.addObject(obj2); |
| 2215 | lib.addObject(obj3); | 2351 | lib.addObject(obj3); |
| 2216 | 2352 | ||
| 2217 | const obj5 = addObject(b, "obj5", opts); | 2353 | const obj5 = addObject(b, opts, .{ |
| 2354 | .name = "obj5", | ||
| 2355 | }); | ||
| 2218 | obj5.addObject(obj4); | 2356 | obj5.addObject(obj4); |
| 2219 | obj5.linkLibrary(lib); | 2357 | obj5.linkLibrary(lib); |
| 2220 | 2358 | ||
| ... | @@ -2234,13 +2372,15 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { | ... | @@ -2234,13 +2372,15 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { |
| 2234 | const test_step = addTestStep(b, "relocatable-eh-frame", opts); | 2372 | const test_step = addTestStep(b, "relocatable-eh-frame", opts); |
| 2235 | 2373 | ||
| 2236 | { | 2374 | { |
| 2237 | const obj = addObject(b, "obj1", opts); | 2375 | const obj = addObject(b, opts, .{ |
| 2238 | addCppSourceBytes(obj, | 2376 | .name = "obj1", |
| 2377 | .cpp_source_bytes = | ||
| 2239 | \\#include <stdexcept> | 2378 | \\#include <stdexcept> |
| 2240 | \\int try_me() { | 2379 | \\int try_me() { |
| 2241 | \\ throw std::runtime_error("Oh no!"); | 2380 | \\ throw std::runtime_error("Oh no!"); |
| 2242 | \\} | 2381 | \\} |
| 2243 | , &.{}); | 2382 | , |
| 2383 | }); | ||
| 2244 | addCppSourceBytes(obj, | 2384 | addCppSourceBytes(obj, |
| 2245 | \\extern int try_me(); | 2385 | \\extern int try_me(); |
| 2246 | \\int try_again() { | 2386 | \\int try_again() { |
| ... | @@ -2249,7 +2389,7 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { | ... | @@ -2249,7 +2389,7 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { |
| 2249 | , &.{}); | 2389 | , &.{}); |
| 2250 | obj.linkLibCpp(); | 2390 | obj.linkLibCpp(); |
| 2251 | 2391 | ||
| 2252 | const exe = addExecutable(b, "test1", opts); | 2392 | const exe = addExecutable(b, opts, .{ .name = "test1" }); |
| 2253 | addCppSourceBytes(exe, | 2393 | addCppSourceBytes(exe, |
| 2254 | \\#include <iostream> | 2394 | \\#include <iostream> |
| 2255 | \\#include <stdexcept> | 2395 | \\#include <stdexcept> |
| ... | @@ -2273,13 +2413,15 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { | ... | @@ -2273,13 +2413,15 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { |
| 2273 | 2413 | ||
| 2274 | { | 2414 | { |
| 2275 | // Let's make the object file COMDAT group heavy! | 2415 | // Let's make the object file COMDAT group heavy! |
| 2276 | const obj = addObject(b, "obj2", opts); | 2416 | const obj = addObject(b, opts, .{ |
| 2277 | addCppSourceBytes(obj, | 2417 | .name = "obj2", |
| 2418 | .cpp_source_bytes = | ||
| 2278 | \\#include <stdexcept> | 2419 | \\#include <stdexcept> |
| 2279 | \\int try_me() { | 2420 | \\int try_me() { |
| 2280 | \\ throw std::runtime_error("Oh no!"); | 2421 | \\ throw std::runtime_error("Oh no!"); |
| 2281 | \\} | 2422 | \\} |
| 2282 | , &.{}); | 2423 | , |
| 2424 | }); | ||
| 2283 | addCppSourceBytes(obj, | 2425 | addCppSourceBytes(obj, |
| 2284 | \\extern int try_me(); | 2426 | \\extern int try_me(); |
| 2285 | \\int try_again() { | 2427 | \\int try_again() { |
| ... | @@ -2301,7 +2443,7 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { | ... | @@ -2301,7 +2443,7 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { |
| 2301 | , &.{}); | 2443 | , &.{}); |
| 2302 | obj.linkLibCpp(); | 2444 | obj.linkLibCpp(); |
| 2303 | 2445 | ||
| 2304 | const exe = addExecutable(b, "test2", opts); | 2446 | const exe = addExecutable(b, opts, .{ .name = "test2" }); |
| 2305 | exe.addObject(obj); | 2447 | exe.addObject(obj); |
| 2306 | exe.linkLibCpp(); | 2448 | exe.linkLibCpp(); |
| 2307 | 2449 | ||
| ... | @@ -2316,13 +2458,18 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { | ... | @@ -2316,13 +2458,18 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { |
| 2316 | fn testRelocatableNoEhFrame(b: *Build, opts: Options) *Step { | 2458 | fn testRelocatableNoEhFrame(b: *Build, opts: Options) *Step { |
| 2317 | const test_step = addTestStep(b, "relocatable-no-eh-frame", opts); | 2459 | const test_step = addTestStep(b, "relocatable-no-eh-frame", opts); |
| 2318 | 2460 | ||
| 2319 | const obj1 = addObject(b, "obj1", opts); | 2461 | const obj1 = addObject(b, opts, .{ |
| 2320 | addCSourceBytes(obj1, "int bar() { return 42; }", &.{ | 2462 | .name = "obj1", |
| 2321 | "-fno-unwind-tables", | 2463 | .c_source_bytes = "int bar() { return 42; }", |
| 2322 | "-fno-asynchronous-unwind-tables", | 2464 | .c_source_flags = &.{ |
| 2465 | "-fno-unwind-tables", | ||
| 2466 | "-fno-asynchronous-unwind-tables", | ||
| 2467 | }, | ||
| 2323 | }); | 2468 | }); |
| 2324 | 2469 | ||
| 2325 | const obj2 = addObject(b, "obj2", opts); | 2470 | const obj2 = addObject(b, opts, .{ |
| 2471 | .name = "obj2", | ||
| 2472 | }); | ||
| 2326 | obj2.addObject(obj1); | 2473 | obj2.addObject(obj1); |
| 2327 | 2474 | ||
| 2328 | const check1 = obj1.checkObject(); | 2475 | const check1 = obj1.checkObject(); |
| ... | @@ -2343,23 +2490,25 @@ fn testRelocatableNoEhFrame(b: *Build, opts: Options) *Step { | ... | @@ -2343,23 +2490,25 @@ fn testRelocatableNoEhFrame(b: *Build, opts: Options) *Step { |
| 2343 | fn testSharedAbsSymbol(b: *Build, opts: Options) *Step { | 2490 | fn testSharedAbsSymbol(b: *Build, opts: Options) *Step { |
| 2344 | const test_step = addTestStep(b, "shared-abs-symbol", opts); | 2491 | const test_step = addTestStep(b, "shared-abs-symbol", opts); |
| 2345 | 2492 | ||
| 2346 | const dso = addSharedLibrary(b, "a", opts); | 2493 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 2347 | addAsmSourceBytes(dso, | 2494 | addAsmSourceBytes(dso, |
| 2348 | \\.globl foo | 2495 | \\.globl foo |
| 2349 | \\foo = 3; | 2496 | \\foo = 3; |
| 2350 | ); | 2497 | ); |
| 2351 | 2498 | ||
| 2352 | const obj = addObject(b, "obj", opts); | 2499 | const obj = addObject(b, opts, .{ |
| 2353 | addCSourceBytes(obj, | 2500 | .name = "obj", |
| 2501 | .c_source_bytes = | ||
| 2354 | \\#include <stdio.h> | 2502 | \\#include <stdio.h> |
| 2355 | \\extern char foo; | 2503 | \\extern char foo; |
| 2356 | \\int main() { printf("foo=%p\n", &foo); } | 2504 | \\int main() { printf("foo=%p\n", &foo); } |
| 2357 | , &.{}); | 2505 | , |
| 2358 | obj.force_pic = true; | 2506 | .pic = true, |
| 2507 | }); | ||
| 2359 | obj.linkLibC(); | 2508 | obj.linkLibC(); |
| 2360 | 2509 | ||
| 2361 | { | 2510 | { |
| 2362 | const exe = addExecutable(b, "main1", opts); | 2511 | const exe = addExecutable(b, opts, .{ .name = "main1" }); |
| 2363 | exe.addObject(obj); | 2512 | exe.addObject(obj); |
| 2364 | exe.linkLibrary(dso); | 2513 | exe.linkLibrary(dso); |
| 2365 | exe.pie = true; | 2514 | exe.pie = true; |
| ... | @@ -2380,7 +2529,7 @@ fn testSharedAbsSymbol(b: *Build, opts: Options) *Step { | ... | @@ -2380,7 +2529,7 @@ fn testSharedAbsSymbol(b: *Build, opts: Options) *Step { |
| 2380 | 2529 | ||
| 2381 | // https://github.com/ziglang/zig/issues/17430 | 2530 | // https://github.com/ziglang/zig/issues/17430 |
| 2382 | // { | 2531 | // { |
| 2383 | // const exe = addExecutable(b, "main2", opts); | 2532 | // const exe = addExecutable(b, opts, .{ .name = "main2"}); |
| 2384 | // exe.addObject(obj); | 2533 | // exe.addObject(obj); |
| 2385 | // exe.linkLibrary(dso); | 2534 | // exe.linkLibrary(dso); |
| 2386 | // exe.pie = false; | 2535 | // exe.pie = false; |
| ... | @@ -2405,20 +2554,22 @@ fn testSharedAbsSymbol(b: *Build, opts: Options) *Step { | ... | @@ -2405,20 +2554,22 @@ fn testSharedAbsSymbol(b: *Build, opts: Options) *Step { |
| 2405 | fn testStrip(b: *Build, opts: Options) *Step { | 2554 | fn testStrip(b: *Build, opts: Options) *Step { |
| 2406 | const test_step = addTestStep(b, "strip", opts); | 2555 | const test_step = addTestStep(b, "strip", opts); |
| 2407 | 2556 | ||
| 2408 | const obj = addObject(b, "obj", opts); | 2557 | const obj = addObject(b, opts, .{ |
| 2409 | addCSourceBytes(obj, | 2558 | .name = "obj", |
| 2559 | .c_source_bytes = | ||
| 2410 | \\#include <stdio.h> | 2560 | \\#include <stdio.h> |
| 2411 | \\int main() { | 2561 | \\int main() { |
| 2412 | \\ printf("Hello!\n"); | 2562 | \\ printf("Hello!\n"); |
| 2413 | \\ return 0; | 2563 | \\ return 0; |
| 2414 | \\} | 2564 | \\} |
| 2415 | , &.{}); | 2565 | , |
| 2566 | }); | ||
| 2416 | obj.linkLibC(); | 2567 | obj.linkLibC(); |
| 2417 | 2568 | ||
| 2418 | { | 2569 | { |
| 2419 | const exe = addExecutable(b, "main1", opts); | 2570 | const exe = addExecutable(b, opts, .{ .name = "main1" }); |
| 2420 | exe.addObject(obj); | 2571 | exe.addObject(obj); |
| 2421 | exe.strip = false; | 2572 | exe.root_module.strip = false; |
| 2422 | exe.linkLibC(); | 2573 | exe.linkLibC(); |
| 2423 | 2574 | ||
| 2424 | const check = exe.checkObject(); | 2575 | const check = exe.checkObject(); |
| ... | @@ -2429,9 +2580,9 @@ fn testStrip(b: *Build, opts: Options) *Step { | ... | @@ -2429,9 +2580,9 @@ fn testStrip(b: *Build, opts: Options) *Step { |
| 2429 | } | 2580 | } |
| 2430 | 2581 | ||
| 2431 | { | 2582 | { |
| 2432 | const exe = addExecutable(b, "main2", opts); | 2583 | const exe = addExecutable(b, opts, .{ .name = "main2" }); |
| 2433 | exe.addObject(obj); | 2584 | exe.addObject(obj); |
| 2434 | exe.strip = true; | 2585 | exe.root_module.strip = true; |
| 2435 | exe.linkLibC(); | 2586 | exe.linkLibC(); |
| 2436 | 2587 | ||
| 2437 | const check = exe.checkObject(); | 2588 | const check = exe.checkObject(); |
| ... | @@ -2447,16 +2598,19 @@ fn testStrip(b: *Build, opts: Options) *Step { | ... | @@ -2447,16 +2598,19 @@ fn testStrip(b: *Build, opts: Options) *Step { |
| 2447 | fn testTlsDfStaticTls(b: *Build, opts: Options) *Step { | 2598 | fn testTlsDfStaticTls(b: *Build, opts: Options) *Step { |
| 2448 | const test_step = addTestStep(b, "tls-df-static-tls", opts); | 2599 | const test_step = addTestStep(b, "tls-df-static-tls", opts); |
| 2449 | 2600 | ||
| 2450 | const obj = addObject(b, "obj", opts); | 2601 | const obj = addObject(b, opts, .{ |
| 2451 | addCSourceBytes(obj, | 2602 | .name = "obj", |
| 2603 | .c_source_bytes = | ||
| 2452 | \\static _Thread_local int foo = 5; | 2604 | \\static _Thread_local int foo = 5; |
| 2453 | \\void mutate() { ++foo; } | 2605 | \\void mutate() { ++foo; } |
| 2454 | \\int bar() { return foo; } | 2606 | \\int bar() { return foo; } |
| 2455 | , &.{"-ftls-model=initial-exec"}); | 2607 | , |
| 2456 | obj.force_pic = true; | 2608 | .c_source_flags = &.{"-ftls-model=initial-exec"}, |
| 2609 | .pic = true, | ||
| 2610 | }); | ||
| 2457 | 2611 | ||
| 2458 | { | 2612 | { |
| 2459 | const dso = addSharedLibrary(b, "a", opts); | 2613 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 2460 | dso.addObject(obj); | 2614 | dso.addObject(obj); |
| 2461 | // dso.link_relax = true; | 2615 | // dso.link_relax = true; |
| 2462 | 2616 | ||
| ... | @@ -2468,7 +2622,7 @@ fn testTlsDfStaticTls(b: *Build, opts: Options) *Step { | ... | @@ -2468,7 +2622,7 @@ fn testTlsDfStaticTls(b: *Build, opts: Options) *Step { |
| 2468 | 2622 | ||
| 2469 | // TODO add -Wl,--no-relax | 2623 | // TODO add -Wl,--no-relax |
| 2470 | // { | 2624 | // { |
| 2471 | // const dso = addSharedLibrary(b, "a", opts); | 2625 | // const dso = addSharedLibrary(b, opts, .{ .name = "a"}); |
| 2472 | // dso.addObject(obj); | 2626 | // dso.addObject(obj); |
| 2473 | // dso.link_relax = false; | 2627 | // dso.link_relax = false; |
| 2474 | 2628 | ||
| ... | @@ -2484,7 +2638,7 @@ fn testTlsDfStaticTls(b: *Build, opts: Options) *Step { | ... | @@ -2484,7 +2638,7 @@ fn testTlsDfStaticTls(b: *Build, opts: Options) *Step { |
| 2484 | fn testTlsDso(b: *Build, opts: Options) *Step { | 2638 | fn testTlsDso(b: *Build, opts: Options) *Step { |
| 2485 | const test_step = addTestStep(b, "tls-dso", opts); | 2639 | const test_step = addTestStep(b, "tls-dso", opts); |
| 2486 | 2640 | ||
| 2487 | const dso = addSharedLibrary(b, "a", opts); | 2641 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 2488 | addCSourceBytes(dso, | 2642 | addCSourceBytes(dso, |
| 2489 | \\extern _Thread_local int foo; | 2643 | \\extern _Thread_local int foo; |
| 2490 | \\_Thread_local int bar; | 2644 | \\_Thread_local int bar; |
| ... | @@ -2492,7 +2646,7 @@ fn testTlsDso(b: *Build, opts: Options) *Step { | ... | @@ -2492,7 +2646,7 @@ fn testTlsDso(b: *Build, opts: Options) *Step { |
| 2492 | \\int get_bar1() { return bar; } | 2646 | \\int get_bar1() { return bar; } |
| 2493 | , &.{}); | 2647 | , &.{}); |
| 2494 | 2648 | ||
| 2495 | const exe = addExecutable(b, "main", opts); | 2649 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 2496 | addCSourceBytes(exe, | 2650 | addCSourceBytes(exe, |
| 2497 | \\#include <stdio.h> | 2651 | \\#include <stdio.h> |
| 2498 | \\_Thread_local int foo; | 2652 | \\_Thread_local int foo; |
| ... | @@ -2526,8 +2680,9 @@ fn testTlsDso(b: *Build, opts: Options) *Step { | ... | @@ -2526,8 +2680,9 @@ fn testTlsDso(b: *Build, opts: Options) *Step { |
| 2526 | fn testTlsGd(b: *Build, opts: Options) *Step { | 2680 | fn testTlsGd(b: *Build, opts: Options) *Step { |
| 2527 | const test_step = addTestStep(b, "tls-gd", opts); | 2681 | const test_step = addTestStep(b, "tls-gd", opts); |
| 2528 | 2682 | ||
| 2529 | const main_o = addObject(b, "main", opts); | 2683 | const main_o = addObject(b, opts, .{ |
| 2530 | addCSourceBytes(main_o, | 2684 | .name = "main", |
| 2685 | .c_source_bytes = | ||
| 2531 | \\#include <stdio.h> | 2686 | \\#include <stdio.h> |
| 2532 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x1 = 1; | 2687 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x1 = 1; |
| 2533 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x2; | 2688 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x2; |
| ... | @@ -2540,37 +2695,42 @@ fn testTlsGd(b: *Build, opts: Options) *Step { | ... | @@ -2540,37 +2695,42 @@ fn testTlsGd(b: *Build, opts: Options) *Step { |
| 2540 | \\ printf("%d %d %d %d %d %d\n", x1, x2, x3, x4, get_x5(), get_x6()); | 2695 | \\ printf("%d %d %d %d %d %d\n", x1, x2, x3, x4, get_x5(), get_x6()); |
| 2541 | \\ return 0; | 2696 | \\ return 0; |
| 2542 | \\} | 2697 | \\} |
| 2543 | , &.{}); | 2698 | , |
| 2699 | .pic = true, | ||
| 2700 | }); | ||
| 2544 | main_o.linkLibC(); | 2701 | main_o.linkLibC(); |
| 2545 | main_o.force_pic = true; | ||
| 2546 | 2702 | ||
| 2547 | const a_o = addObject(b, "a", opts); | 2703 | const a_o = addObject(b, opts, .{ |
| 2548 | addCSourceBytes(a_o, | 2704 | .name = "a", |
| 2705 | .c_source_bytes = | ||
| 2549 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x3 = 3; | 2706 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x3 = 3; |
| 2550 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x5 = 5; | 2707 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x5 = 5; |
| 2551 | \\int get_x5() { return x5; } | 2708 | \\int get_x5() { return x5; } |
| 2552 | , &.{}); | 2709 | , |
| 2553 | a_o.force_pic = true; | 2710 | .pic = true, |
| 2711 | }); | ||
| 2554 | 2712 | ||
| 2555 | const b_o = addObject(b, "b", opts); | 2713 | const b_o = addObject(b, opts, .{ |
| 2556 | addCSourceBytes(b_o, | 2714 | .name = "b", |
| 2715 | .c_source_bytes = | ||
| 2557 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x4 = 4; | 2716 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x4 = 4; |
| 2558 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x6 = 6; | 2717 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x6 = 6; |
| 2559 | \\int get_x6() { return x6; } | 2718 | \\int get_x6() { return x6; } |
| 2560 | , &.{}); | 2719 | , |
| 2561 | b_o.force_pic = true; | 2720 | .pic = true, |
| 2721 | }); | ||
| 2562 | 2722 | ||
| 2563 | const exp_stdout = "1 2 3 4 5 6\n"; | 2723 | const exp_stdout = "1 2 3 4 5 6\n"; |
| 2564 | 2724 | ||
| 2565 | const dso1 = addSharedLibrary(b, "a", opts); | 2725 | const dso1 = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 2566 | dso1.addObject(a_o); | 2726 | dso1.addObject(a_o); |
| 2567 | 2727 | ||
| 2568 | const dso2 = addSharedLibrary(b, "b", opts); | 2728 | const dso2 = addSharedLibrary(b, opts, .{ .name = "b" }); |
| 2569 | dso2.addObject(b_o); | 2729 | dso2.addObject(b_o); |
| 2570 | // dso2.link_relax = false; // TODO | 2730 | // dso2.link_relax = false; // TODO |
| 2571 | 2731 | ||
| 2572 | { | 2732 | { |
| 2573 | const exe = addExecutable(b, "main1", opts); | 2733 | const exe = addExecutable(b, opts, .{ .name = "main1" }); |
| 2574 | exe.addObject(main_o); | 2734 | exe.addObject(main_o); |
| 2575 | exe.linkLibrary(dso1); | 2735 | exe.linkLibrary(dso1); |
| 2576 | exe.linkLibrary(dso2); | 2736 | exe.linkLibrary(dso2); |
| ... | @@ -2581,7 +2741,7 @@ fn testTlsGd(b: *Build, opts: Options) *Step { | ... | @@ -2581,7 +2741,7 @@ fn testTlsGd(b: *Build, opts: Options) *Step { |
| 2581 | } | 2741 | } |
| 2582 | 2742 | ||
| 2583 | { | 2743 | { |
| 2584 | const exe = addExecutable(b, "main2", opts); | 2744 | const exe = addExecutable(b, opts, .{ .name = "main2" }); |
| 2585 | exe.addObject(main_o); | 2745 | exe.addObject(main_o); |
| 2586 | // exe.link_relax = false; // TODO | 2746 | // exe.link_relax = false; // TODO |
| 2587 | exe.linkLibrary(dso1); | 2747 | exe.linkLibrary(dso1); |
| ... | @@ -2594,7 +2754,7 @@ fn testTlsGd(b: *Build, opts: Options) *Step { | ... | @@ -2594,7 +2754,7 @@ fn testTlsGd(b: *Build, opts: Options) *Step { |
| 2594 | 2754 | ||
| 2595 | // https://github.com/ziglang/zig/issues/17430 ?? | 2755 | // https://github.com/ziglang/zig/issues/17430 ?? |
| 2596 | // { | 2756 | // { |
| 2597 | // const exe = addExecutable(b, "main3", opts); | 2757 | // const exe = addExecutable(b, opts, .{ .name = "main3"}); |
| 2598 | // exe.addObject(main_o); | 2758 | // exe.addObject(main_o); |
| 2599 | // exe.linkLibrary(dso1); | 2759 | // exe.linkLibrary(dso1); |
| 2600 | // exe.linkLibrary(dso2); | 2760 | // exe.linkLibrary(dso2); |
| ... | @@ -2606,7 +2766,7 @@ fn testTlsGd(b: *Build, opts: Options) *Step { | ... | @@ -2606,7 +2766,7 @@ fn testTlsGd(b: *Build, opts: Options) *Step { |
| 2606 | // } | 2766 | // } |
| 2607 | 2767 | ||
| 2608 | // { | 2768 | // { |
| 2609 | // const exe = addExecutable(b, "main4", opts); | 2769 | // const exe = addExecutable(b, opts, .{ .name = "main4"}); |
| 2610 | // exe.addObject(main_o); | 2770 | // exe.addObject(main_o); |
| 2611 | // // exe.link_relax = false; // TODO | 2771 | // // exe.link_relax = false; // TODO |
| 2612 | // exe.linkLibrary(dso1); | 2772 | // exe.linkLibrary(dso1); |
| ... | @@ -2624,8 +2784,9 @@ fn testTlsGd(b: *Build, opts: Options) *Step { | ... | @@ -2624,8 +2784,9 @@ fn testTlsGd(b: *Build, opts: Options) *Step { |
| 2624 | fn testTlsGdNoPlt(b: *Build, opts: Options) *Step { | 2784 | fn testTlsGdNoPlt(b: *Build, opts: Options) *Step { |
| 2625 | const test_step = addTestStep(b, "tls-gd-no-plt", opts); | 2785 | const test_step = addTestStep(b, "tls-gd-no-plt", opts); |
| 2626 | 2786 | ||
| 2627 | const obj = addObject(b, "obj", opts); | 2787 | const obj = addObject(b, opts, .{ |
| 2628 | addCSourceBytes(obj, | 2788 | .name = "obj", |
| 2789 | .c_source_bytes = | ||
| 2629 | \\#include <stdio.h> | 2790 | \\#include <stdio.h> |
| 2630 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x1 = 1; | 2791 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x1 = 1; |
| 2631 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x2; | 2792 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x2; |
| ... | @@ -2639,18 +2800,20 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step { | ... | @@ -2639,18 +2800,20 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step { |
| 2639 | \\ printf("%d %d %d %d %d %d\n", x1, x2, x3, x4, get_x5(), get_x6()); | 2800 | \\ printf("%d %d %d %d %d %d\n", x1, x2, x3, x4, get_x5(), get_x6()); |
| 2640 | \\ return 0; | 2801 | \\ return 0; |
| 2641 | \\} | 2802 | \\} |
| 2642 | , &.{"-fno-plt"}); | 2803 | , |
| 2643 | obj.force_pic = true; | 2804 | .c_source_flags = &.{"-fno-plt"}, |
| 2805 | .pic = true, | ||
| 2806 | }); | ||
| 2644 | obj.linkLibC(); | 2807 | obj.linkLibC(); |
| 2645 | 2808 | ||
| 2646 | const a_so = addSharedLibrary(b, "a", opts); | 2809 | const a_so = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 2647 | addCSourceBytes(a_so, | 2810 | addCSourceBytes(a_so, |
| 2648 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x3 = 3; | 2811 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x3 = 3; |
| 2649 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x5 = 5; | 2812 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x5 = 5; |
| 2650 | \\int get_x5() { return x5; } | 2813 | \\int get_x5() { return x5; } |
| 2651 | , &.{"-fno-plt"}); | 2814 | , &.{"-fno-plt"}); |
| 2652 | 2815 | ||
| 2653 | const b_so = addSharedLibrary(b, "b", opts); | 2816 | const b_so = addSharedLibrary(b, opts, .{ .name = "b" }); |
| 2654 | addCSourceBytes(b_so, | 2817 | addCSourceBytes(b_so, |
| 2655 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x4 = 4; | 2818 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x4 = 4; |
| 2656 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x6 = 6; | 2819 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x6 = 6; |
| ... | @@ -2659,7 +2822,7 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step { | ... | @@ -2659,7 +2822,7 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step { |
| 2659 | // b_so.link_relax = false; // TODO | 2822 | // b_so.link_relax = false; // TODO |
| 2660 | 2823 | ||
| 2661 | { | 2824 | { |
| 2662 | const exe = addExecutable(b, "main1", opts); | 2825 | const exe = addExecutable(b, opts, .{ .name = "main1" }); |
| 2663 | exe.addObject(obj); | 2826 | exe.addObject(obj); |
| 2664 | exe.linkLibrary(a_so); | 2827 | exe.linkLibrary(a_so); |
| 2665 | exe.linkLibrary(b_so); | 2828 | exe.linkLibrary(b_so); |
| ... | @@ -2673,7 +2836,7 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step { | ... | @@ -2673,7 +2836,7 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step { |
| 2673 | } | 2836 | } |
| 2674 | 2837 | ||
| 2675 | { | 2838 | { |
| 2676 | const exe = addExecutable(b, "main2", opts); | 2839 | const exe = addExecutable(b, opts, .{ .name = "main2" }); |
| 2677 | exe.addObject(obj); | 2840 | exe.addObject(obj); |
| 2678 | exe.linkLibrary(a_so); | 2841 | exe.linkLibrary(a_so); |
| 2679 | exe.linkLibrary(b_so); | 2842 | exe.linkLibrary(b_so); |
| ... | @@ -2693,8 +2856,9 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step { | ... | @@ -2693,8 +2856,9 @@ fn testTlsGdNoPlt(b: *Build, opts: Options) *Step { |
| 2693 | fn testTlsGdToIe(b: *Build, opts: Options) *Step { | 2856 | fn testTlsGdToIe(b: *Build, opts: Options) *Step { |
| 2694 | const test_step = addTestStep(b, "tls-gd-to-ie", opts); | 2857 | const test_step = addTestStep(b, "tls-gd-to-ie", opts); |
| 2695 | 2858 | ||
| 2696 | const a_o = addObject(b, "a", opts); | 2859 | const a_o = addObject(b, opts, .{ |
| 2697 | addCSourceBytes(a_o, | 2860 | .name = "a", |
| 2861 | .c_source_bytes = | ||
| 2698 | \\#include <stdio.h> | 2862 | \\#include <stdio.h> |
| 2699 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x1 = 1; | 2863 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int x1 = 1; |
| 2700 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x2 = 2; | 2864 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int x2 = 2; |
| ... | @@ -2705,22 +2869,25 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step { | ... | @@ -2705,22 +2869,25 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step { |
| 2705 | \\ printf("%d %d %d\n", x1, x2, x3); | 2869 | \\ printf("%d %d %d\n", x1, x2, x3); |
| 2706 | \\ return 0; | 2870 | \\ return 0; |
| 2707 | \\} | 2871 | \\} |
| 2708 | , &.{}); | 2872 | , |
| 2873 | .pic = true, | ||
| 2874 | }); | ||
| 2709 | a_o.linkLibC(); | 2875 | a_o.linkLibC(); |
| 2710 | a_o.force_pic = true; | ||
| 2711 | 2876 | ||
| 2712 | const b_o = addObject(b, "b", opts); | 2877 | const b_o = addObject(b, opts, .{ |
| 2713 | addCSourceBytes(b_o, | 2878 | .name = "b", |
| 2879 | .c_source_bytes = | ||
| 2714 | \\int foo(); | 2880 | \\int foo(); |
| 2715 | \\int main() { foo(); } | 2881 | \\int main() { foo(); } |
| 2716 | , &.{}); | 2882 | , |
| 2717 | b_o.force_pic = true; | 2883 | .pic = true, |
| 2884 | }); | ||
| 2718 | 2885 | ||
| 2719 | { | 2886 | { |
| 2720 | const dso = addSharedLibrary(b, "a1", opts); | 2887 | const dso = addSharedLibrary(b, opts, .{ .name = "a1" }); |
| 2721 | dso.addObject(a_o); | 2888 | dso.addObject(a_o); |
| 2722 | 2889 | ||
| 2723 | const exe = addExecutable(b, "main1", opts); | 2890 | const exe = addExecutable(b, opts, .{ .name = "main1" }); |
| 2724 | exe.addObject(b_o); | 2891 | exe.addObject(b_o); |
| 2725 | exe.linkLibrary(dso); | 2892 | exe.linkLibrary(dso); |
| 2726 | exe.linkLibC(); | 2893 | exe.linkLibC(); |
| ... | @@ -2733,11 +2900,11 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step { | ... | @@ -2733,11 +2900,11 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step { |
| 2733 | } | 2900 | } |
| 2734 | 2901 | ||
| 2735 | { | 2902 | { |
| 2736 | const dso = addSharedLibrary(b, "a2", opts); | 2903 | const dso = addSharedLibrary(b, opts, .{ .name = "a2" }); |
| 2737 | dso.addObject(a_o); | 2904 | dso.addObject(a_o); |
| 2738 | // dso.link_relax = false; // TODO | 2905 | // dso.link_relax = false; // TODO |
| 2739 | 2906 | ||
| 2740 | const exe = addExecutable(b, "main2", opts); | 2907 | const exe = addExecutable(b, opts, .{ .name = "main2" }); |
| 2741 | exe.addObject(b_o); | 2908 | exe.addObject(b_o); |
| 2742 | exe.linkLibrary(dso); | 2909 | exe.linkLibrary(dso); |
| 2743 | exe.linkLibC(); | 2910 | exe.linkLibC(); |
| ... | @@ -2750,11 +2917,11 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step { | ... | @@ -2750,11 +2917,11 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step { |
| 2750 | } | 2917 | } |
| 2751 | 2918 | ||
| 2752 | // { | 2919 | // { |
| 2753 | // const dso = addSharedLibrary(b, "a", opts); | 2920 | // const dso = addSharedLibrary(b, opts, .{ .name = "a"}); |
| 2754 | // dso.addObject(a_o); | 2921 | // dso.addObject(a_o); |
| 2755 | // dso.link_z_nodlopen = true; | 2922 | // dso.link_z_nodlopen = true; |
| 2756 | 2923 | ||
| 2757 | // const exe = addExecutable(b, "main", opts); | 2924 | // const exe = addExecutable(b, opts, .{ .name = "main"}); |
| 2758 | // exe.addObject(b_o); | 2925 | // exe.addObject(b_o); |
| 2759 | // exe.linkLibrary(dso); | 2926 | // exe.linkLibrary(dso); |
| 2760 | 2927 | ||
| ... | @@ -2764,12 +2931,12 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step { | ... | @@ -2764,12 +2931,12 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step { |
| 2764 | // } | 2931 | // } |
| 2765 | 2932 | ||
| 2766 | // { | 2933 | // { |
| 2767 | // const dso = addSharedLibrary(b, "a", opts); | 2934 | // const dso = addSharedLibrary(b, opts, .{ .name = "a"}); |
| 2768 | // dso.addObject(a_o); | 2935 | // dso.addObject(a_o); |
| 2769 | // dso.link_relax = false; | 2936 | // dso.link_relax = false; |
| 2770 | // dso.link_z_nodlopen = true; | 2937 | // dso.link_z_nodlopen = true; |
| 2771 | 2938 | ||
| 2772 | // const exe = addExecutable(b, "main", opts); | 2939 | // const exe = addExecutable(b, opts, .{ .name = "main"}); |
| 2773 | // exe.addObject(b_o); | 2940 | // exe.addObject(b_o); |
| 2774 | // exe.linkLibrary(dso); | 2941 | // exe.linkLibrary(dso); |
| 2775 | 2942 | ||
| ... | @@ -2784,7 +2951,7 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step { | ... | @@ -2784,7 +2951,7 @@ fn testTlsGdToIe(b: *Build, opts: Options) *Step { |
| 2784 | fn testTlsIe(b: *Build, opts: Options) *Step { | 2951 | fn testTlsIe(b: *Build, opts: Options) *Step { |
| 2785 | const test_step = addTestStep(b, "tls-ie", opts); | 2952 | const test_step = addTestStep(b, "tls-ie", opts); |
| 2786 | 2953 | ||
| 2787 | const dso = addSharedLibrary(b, "a", opts); | 2954 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 2788 | addCSourceBytes(dso, | 2955 | addCSourceBytes(dso, |
| 2789 | \\#include <stdio.h> | 2956 | \\#include <stdio.h> |
| 2790 | \\__attribute__((tls_model("initial-exec"))) static _Thread_local int foo; | 2957 | \\__attribute__((tls_model("initial-exec"))) static _Thread_local int foo; |
| ... | @@ -2799,8 +2966,9 @@ fn testTlsIe(b: *Build, opts: Options) *Step { | ... | @@ -2799,8 +2966,9 @@ fn testTlsIe(b: *Build, opts: Options) *Step { |
| 2799 | , &.{}); | 2966 | , &.{}); |
| 2800 | dso.linkLibC(); | 2967 | dso.linkLibC(); |
| 2801 | 2968 | ||
| 2802 | const main_o = addObject(b, "main", opts); | 2969 | const main_o = addObject(b, opts, .{ |
| 2803 | addCSourceBytes(main_o, | 2970 | .name = "main", |
| 2971 | .c_source_bytes = | ||
| 2804 | \\#include <stdio.h> | 2972 | \\#include <stdio.h> |
| 2805 | \\_Thread_local int baz; | 2973 | \\_Thread_local int baz; |
| 2806 | \\void set(); | 2974 | \\void set(); |
| ... | @@ -2812,13 +2980,14 @@ fn testTlsIe(b: *Build, opts: Options) *Step { | ... | @@ -2812,13 +2980,14 @@ fn testTlsIe(b: *Build, opts: Options) *Step { |
| 2812 | \\ print(); | 2980 | \\ print(); |
| 2813 | \\ printf("%d\n", baz); | 2981 | \\ printf("%d\n", baz); |
| 2814 | \\} | 2982 | \\} |
| 2815 | , &.{}); | 2983 | , |
| 2984 | }); | ||
| 2816 | main_o.linkLibC(); | 2985 | main_o.linkLibC(); |
| 2817 | 2986 | ||
| 2818 | const exp_stdout = "0 0 3 5 7\n"; | 2987 | const exp_stdout = "0 0 3 5 7\n"; |
| 2819 | 2988 | ||
| 2820 | { | 2989 | { |
| 2821 | const exe = addExecutable(b, "main1", opts); | 2990 | const exe = addExecutable(b, opts, .{ .name = "main1" }); |
| 2822 | exe.addObject(main_o); | 2991 | exe.addObject(main_o); |
| 2823 | exe.linkLibrary(dso); | 2992 | exe.linkLibrary(dso); |
| 2824 | exe.linkLibC(); | 2993 | exe.linkLibC(); |
| ... | @@ -2831,7 +3000,7 @@ fn testTlsIe(b: *Build, opts: Options) *Step { | ... | @@ -2831,7 +3000,7 @@ fn testTlsIe(b: *Build, opts: Options) *Step { |
| 2831 | } | 3000 | } |
| 2832 | 3001 | ||
| 2833 | { | 3002 | { |
| 2834 | const exe = addExecutable(b, "main2", opts); | 3003 | const exe = addExecutable(b, opts, .{ .name = "main2" }); |
| 2835 | exe.addObject(main_o); | 3004 | exe.addObject(main_o); |
| 2836 | exe.linkLibrary(dso); | 3005 | exe.linkLibrary(dso); |
| 2837 | exe.linkLibC(); | 3006 | exe.linkLibC(); |
| ... | @@ -2850,38 +3019,46 @@ fn testTlsIe(b: *Build, opts: Options) *Step { | ... | @@ -2850,38 +3019,46 @@ fn testTlsIe(b: *Build, opts: Options) *Step { |
| 2850 | fn testTlsLargeAlignment(b: *Build, opts: Options) *Step { | 3019 | fn testTlsLargeAlignment(b: *Build, opts: Options) *Step { |
| 2851 | const test_step = addTestStep(b, "tls-large-alignment", opts); | 3020 | const test_step = addTestStep(b, "tls-large-alignment", opts); |
| 2852 | 3021 | ||
| 2853 | const a_o = addObject(b, "a", opts); | 3022 | const a_o = addObject(b, opts, .{ |
| 2854 | addCSourceBytes(a_o, | 3023 | .name = "a", |
| 3024 | .c_source_bytes = | ||
| 2855 | \\__attribute__((section(".tdata1"))) | 3025 | \\__attribute__((section(".tdata1"))) |
| 2856 | \\_Thread_local int x = 42; | 3026 | \\_Thread_local int x = 42; |
| 2857 | , &.{"-std=c11"}); | 3027 | , |
| 2858 | a_o.force_pic = true; | 3028 | .c_source_flags = &.{"-std=c11"}, |
| 3029 | .pic = true, | ||
| 3030 | }); | ||
| 2859 | 3031 | ||
| 2860 | const b_o = addObject(b, "b", opts); | 3032 | const b_o = addObject(b, opts, .{ |
| 2861 | addCSourceBytes(b_o, | 3033 | .name = "b", |
| 3034 | .c_source_bytes = | ||
| 2862 | \\__attribute__((section(".tdata2"))) | 3035 | \\__attribute__((section(".tdata2"))) |
| 2863 | \\_Alignas(256) _Thread_local int y[] = { 1, 2, 3 }; | 3036 | \\_Alignas(256) _Thread_local int y[] = { 1, 2, 3 }; |
| 2864 | , &.{"-std=c11"}); | 3037 | , |
| 2865 | b_o.force_pic = true; | 3038 | .c_source_flags = &.{"-std=c11"}, |
| 3039 | .pic = true, | ||
| 3040 | }); | ||
| 2866 | 3041 | ||
| 2867 | const c_o = addObject(b, "c", opts); | 3042 | const c_o = addObject(b, opts, .{ |
| 2868 | addCSourceBytes(c_o, | 3043 | .name = "c", |
| 3044 | .c_source_bytes = | ||
| 2869 | \\#include <stdio.h> | 3045 | \\#include <stdio.h> |
| 2870 | \\extern _Thread_local int x; | 3046 | \\extern _Thread_local int x; |
| 2871 | \\extern _Thread_local int y[]; | 3047 | \\extern _Thread_local int y[]; |
| 2872 | \\int main() { | 3048 | \\int main() { |
| 2873 | \\ printf("%d %d %d %d\n", x, y[0], y[1], y[2]); | 3049 | \\ printf("%d %d %d %d\n", x, y[0], y[1], y[2]); |
| 2874 | \\} | 3050 | \\} |
| 2875 | , &.{}); | 3051 | , |
| 2876 | c_o.force_pic = true; | 3052 | .pic = true, |
| 3053 | }); | ||
| 2877 | c_o.linkLibC(); | 3054 | c_o.linkLibC(); |
| 2878 | 3055 | ||
| 2879 | { | 3056 | { |
| 2880 | const dso = addSharedLibrary(b, "a", opts); | 3057 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 2881 | dso.addObject(a_o); | 3058 | dso.addObject(a_o); |
| 2882 | dso.addObject(b_o); | 3059 | dso.addObject(b_o); |
| 2883 | 3060 | ||
| 2884 | const exe = addExecutable(b, "main", opts); | 3061 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 2885 | exe.addObject(c_o); | 3062 | exe.addObject(c_o); |
| 2886 | exe.linkLibrary(dso); | 3063 | exe.linkLibrary(dso); |
| 2887 | exe.linkLibC(); | 3064 | exe.linkLibC(); |
| ... | @@ -2894,7 +3071,7 @@ fn testTlsLargeAlignment(b: *Build, opts: Options) *Step { | ... | @@ -2894,7 +3071,7 @@ fn testTlsLargeAlignment(b: *Build, opts: Options) *Step { |
| 2894 | } | 3071 | } |
| 2895 | 3072 | ||
| 2896 | { | 3073 | { |
| 2897 | const exe = addExecutable(b, "main", opts); | 3074 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 2898 | exe.addObject(a_o); | 3075 | exe.addObject(a_o); |
| 2899 | exe.addObject(b_o); | 3076 | exe.addObject(b_o); |
| 2900 | exe.addObject(c_o); | 3077 | exe.addObject(c_o); |
| ... | @@ -2913,7 +3090,7 @@ fn testTlsLargeAlignment(b: *Build, opts: Options) *Step { | ... | @@ -2913,7 +3090,7 @@ fn testTlsLargeAlignment(b: *Build, opts: Options) *Step { |
| 2913 | fn testTlsLargeTbss(b: *Build, opts: Options) *Step { | 3090 | fn testTlsLargeTbss(b: *Build, opts: Options) *Step { |
| 2914 | const test_step = addTestStep(b, "tls-large-tbss", opts); | 3091 | const test_step = addTestStep(b, "tls-large-tbss", opts); |
| 2915 | 3092 | ||
| 2916 | const exe = addExecutable(b, "main", opts); | 3093 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 2917 | addAsmSourceBytes(exe, | 3094 | addAsmSourceBytes(exe, |
| 2918 | \\.globl x, y | 3095 | \\.globl x, y |
| 2919 | \\.section .tbss,"awT",@nobits | 3096 | \\.section .tbss,"awT",@nobits |
| ... | @@ -2947,7 +3124,7 @@ fn testTlsLargeTbss(b: *Build, opts: Options) *Step { | ... | @@ -2947,7 +3124,7 @@ fn testTlsLargeTbss(b: *Build, opts: Options) *Step { |
| 2947 | fn testTlsLargeStaticImage(b: *Build, opts: Options) *Step { | 3124 | fn testTlsLargeStaticImage(b: *Build, opts: Options) *Step { |
| 2948 | const test_step = addTestStep(b, "tls-large-static-image", opts); | 3125 | const test_step = addTestStep(b, "tls-large-static-image", opts); |
| 2949 | 3126 | ||
| 2950 | const exe = addExecutable(b, "main", opts); | 3127 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 2951 | addCSourceBytes(exe, "_Thread_local int x[] = { 1, 2, 3, [10000] = 5 };", &.{}); | 3128 | addCSourceBytes(exe, "_Thread_local int x[] = { 1, 2, 3, [10000] = 5 };", &.{}); |
| 2952 | addCSourceBytes(exe, | 3129 | addCSourceBytes(exe, |
| 2953 | \\#include <stdio.h> | 3130 | \\#include <stdio.h> |
| ... | @@ -2956,7 +3133,7 @@ fn testTlsLargeStaticImage(b: *Build, opts: Options) *Step { | ... | @@ -2956,7 +3133,7 @@ fn testTlsLargeStaticImage(b: *Build, opts: Options) *Step { |
| 2956 | \\ printf("%d %d %d %d %d\n", x[0], x[1], x[2], x[3], x[10000]); | 3133 | \\ printf("%d %d %d %d %d\n", x[0], x[1], x[2], x[3], x[10000]); |
| 2957 | \\} | 3134 | \\} |
| 2958 | , &.{}); | 3135 | , &.{}); |
| 2959 | exe.force_pic = true; | 3136 | exe.root_module.pic = true; |
| 2960 | exe.linkLibC(); | 3137 | exe.linkLibC(); |
| 2961 | // https://github.com/ziglang/zig/issues/17619 | 3138 | // https://github.com/ziglang/zig/issues/17619 |
| 2962 | exe.pie = true; | 3139 | exe.pie = true; |
| ... | @@ -2971,8 +3148,9 @@ fn testTlsLargeStaticImage(b: *Build, opts: Options) *Step { | ... | @@ -2971,8 +3148,9 @@ fn testTlsLargeStaticImage(b: *Build, opts: Options) *Step { |
| 2971 | fn testTlsLd(b: *Build, opts: Options) *Step { | 3148 | fn testTlsLd(b: *Build, opts: Options) *Step { |
| 2972 | const test_step = addTestStep(b, "tls-ld", opts); | 3149 | const test_step = addTestStep(b, "tls-ld", opts); |
| 2973 | 3150 | ||
| 2974 | const main_o = addObject(b, "main", opts); | 3151 | const main_o = addObject(b, opts, .{ |
| 2975 | addCSourceBytes(main_o, | 3152 | .name = "main", |
| 3153 | .c_source_bytes = | ||
| 2976 | \\#include <stdio.h> | 3154 | \\#include <stdio.h> |
| 2977 | \\extern _Thread_local int foo; | 3155 | \\extern _Thread_local int foo; |
| 2978 | \\static _Thread_local int bar; | 3156 | \\static _Thread_local int bar; |
| ... | @@ -2983,18 +3161,23 @@ fn testTlsLd(b: *Build, opts: Options) *Step { | ... | @@ -2983,18 +3161,23 @@ fn testTlsLd(b: *Build, opts: Options) *Step { |
| 2983 | \\ printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar); | 3161 | \\ printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar); |
| 2984 | \\ return 0; | 3162 | \\ return 0; |
| 2985 | \\} | 3163 | \\} |
| 2986 | , &.{"-ftls-model=local-dynamic"}); | 3164 | , |
| 2987 | main_o.force_pic = true; | 3165 | .c_source_flags = &.{"-ftls-model=local-dynamic"}, |
| 3166 | .pic = true, | ||
| 3167 | }); | ||
| 2988 | main_o.linkLibC(); | 3168 | main_o.linkLibC(); |
| 2989 | 3169 | ||
| 2990 | const a_o = addObject(b, "a", opts); | 3170 | const a_o = addObject(b, opts, .{ |
| 2991 | addCSourceBytes(a_o, "_Thread_local int foo = 3;", &.{"-ftls-model=local-dynamic"}); | 3171 | .name = "a", |
| 2992 | a_o.force_pic = true; | 3172 | .c_source_bytes = "_Thread_local int foo = 3;", |
| 3173 | .c_source_flags = &.{"-ftls-model=local-dynamic"}, | ||
| 3174 | .pic = true, | ||
| 3175 | }); | ||
| 2993 | 3176 | ||
| 2994 | const exp_stdout = "3 5 3 5\n"; | 3177 | const exp_stdout = "3 5 3 5\n"; |
| 2995 | 3178 | ||
| 2996 | { | 3179 | { |
| 2997 | const exe = addExecutable(b, "main1", opts); | 3180 | const exe = addExecutable(b, opts, .{ .name = "main1" }); |
| 2998 | exe.addObject(main_o); | 3181 | exe.addObject(main_o); |
| 2999 | exe.addObject(a_o); | 3182 | exe.addObject(a_o); |
| 3000 | exe.linkLibC(); | 3183 | exe.linkLibC(); |
| ... | @@ -3007,7 +3190,7 @@ fn testTlsLd(b: *Build, opts: Options) *Step { | ... | @@ -3007,7 +3190,7 @@ fn testTlsLd(b: *Build, opts: Options) *Step { |
| 3007 | } | 3190 | } |
| 3008 | 3191 | ||
| 3009 | { | 3192 | { |
| 3010 | const exe = addExecutable(b, "main2", opts); | 3193 | const exe = addExecutable(b, opts, .{ .name = "main2" }); |
| 3011 | exe.addObject(main_o); | 3194 | exe.addObject(main_o); |
| 3012 | exe.addObject(a_o); | 3195 | exe.addObject(a_o); |
| 3013 | exe.linkLibC(); | 3196 | exe.linkLibC(); |
| ... | @@ -3026,14 +3209,14 @@ fn testTlsLd(b: *Build, opts: Options) *Step { | ... | @@ -3026,14 +3209,14 @@ fn testTlsLd(b: *Build, opts: Options) *Step { |
| 3026 | fn testTlsLdDso(b: *Build, opts: Options) *Step { | 3209 | fn testTlsLdDso(b: *Build, opts: Options) *Step { |
| 3027 | const test_step = addTestStep(b, "tls-ld-dso", opts); | 3210 | const test_step = addTestStep(b, "tls-ld-dso", opts); |
| 3028 | 3211 | ||
| 3029 | const dso = addSharedLibrary(b, "a", opts); | 3212 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 3030 | addCSourceBytes(dso, | 3213 | addCSourceBytes(dso, |
| 3031 | \\static _Thread_local int def, def1; | 3214 | \\static _Thread_local int def, def1; |
| 3032 | \\int f0() { return ++def; } | 3215 | \\int f0() { return ++def; } |
| 3033 | \\int f1() { return ++def1 + def; } | 3216 | \\int f1() { return ++def1 + def; } |
| 3034 | , &.{"-ftls-model=local-dynamic"}); | 3217 | , &.{"-ftls-model=local-dynamic"}); |
| 3035 | 3218 | ||
| 3036 | const exe = addExecutable(b, "main", opts); | 3219 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 3037 | addCSourceBytes(exe, | 3220 | addCSourceBytes(exe, |
| 3038 | \\#include <stdio.h> | 3221 | \\#include <stdio.h> |
| 3039 | \\extern int f0(); | 3222 | \\extern int f0(); |
| ... | @@ -3060,8 +3243,9 @@ fn testTlsLdDso(b: *Build, opts: Options) *Step { | ... | @@ -3060,8 +3243,9 @@ fn testTlsLdDso(b: *Build, opts: Options) *Step { |
| 3060 | fn testTlsLdNoPlt(b: *Build, opts: Options) *Step { | 3243 | fn testTlsLdNoPlt(b: *Build, opts: Options) *Step { |
| 3061 | const test_step = addTestStep(b, "tls-ld-no-plt", opts); | 3244 | const test_step = addTestStep(b, "tls-ld-no-plt", opts); |
| 3062 | 3245 | ||
| 3063 | const a_o = addObject(b, "a", opts); | 3246 | const a_o = addObject(b, opts, .{ |
| 3064 | addCSourceBytes(a_o, | 3247 | .name = "a", |
| 3248 | .c_source_bytes = | ||
| 3065 | \\#include <stdio.h> | 3249 | \\#include <stdio.h> |
| 3066 | \\extern _Thread_local int foo; | 3250 | \\extern _Thread_local int foo; |
| 3067 | \\static _Thread_local int bar; | 3251 | \\static _Thread_local int bar; |
| ... | @@ -3073,16 +3257,21 @@ fn testTlsLdNoPlt(b: *Build, opts: Options) *Step { | ... | @@ -3073,16 +3257,21 @@ fn testTlsLdNoPlt(b: *Build, opts: Options) *Step { |
| 3073 | \\ printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar); | 3257 | \\ printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar); |
| 3074 | \\ return 0; | 3258 | \\ return 0; |
| 3075 | \\} | 3259 | \\} |
| 3076 | , &.{ "-ftls-model=local-dynamic", "-fno-plt" }); | 3260 | , |
| 3261 | .c_source_flags = &.{ "-ftls-model=local-dynamic", "-fno-plt" }, | ||
| 3262 | .pic = true, | ||
| 3263 | }); | ||
| 3077 | a_o.linkLibC(); | 3264 | a_o.linkLibC(); |
| 3078 | a_o.force_pic = true; | ||
| 3079 | 3265 | ||
| 3080 | const b_o = addObject(b, "b", opts); | 3266 | const b_o = addObject(b, opts, .{ |
| 3081 | addCSourceBytes(b_o, "_Thread_local int foo = 3;", &.{ "-ftls-model=local-dynamic", "-fno-plt" }); | 3267 | .name = "b", |
| 3082 | b_o.force_pic = true; | 3268 | .c_source_bytes = "_Thread_local int foo = 3;", |
| 3269 | .c_source_flags = &.{ "-ftls-model=local-dynamic", "-fno-plt" }, | ||
| 3270 | .pic = true, | ||
| 3271 | }); | ||
| 3083 | 3272 | ||
| 3084 | { | 3273 | { |
| 3085 | const exe = addExecutable(b, "main1", opts); | 3274 | const exe = addExecutable(b, opts, .{ .name = "main1" }); |
| 3086 | exe.addObject(a_o); | 3275 | exe.addObject(a_o); |
| 3087 | exe.addObject(b_o); | 3276 | exe.addObject(b_o); |
| 3088 | exe.linkLibC(); | 3277 | exe.linkLibC(); |
| ... | @@ -3095,7 +3284,7 @@ fn testTlsLdNoPlt(b: *Build, opts: Options) *Step { | ... | @@ -3095,7 +3284,7 @@ fn testTlsLdNoPlt(b: *Build, opts: Options) *Step { |
| 3095 | } | 3284 | } |
| 3096 | 3285 | ||
| 3097 | { | 3286 | { |
| 3098 | const exe = addExecutable(b, "main2", opts); | 3287 | const exe = addExecutable(b, opts, .{ .name = "main2" }); |
| 3099 | exe.addObject(a_o); | 3288 | exe.addObject(a_o); |
| 3100 | exe.addObject(b_o); | 3289 | exe.addObject(b_o); |
| 3101 | exe.linkLibC(); | 3290 | exe.linkLibC(); |
| ... | @@ -3114,7 +3303,7 @@ fn testTlsLdNoPlt(b: *Build, opts: Options) *Step { | ... | @@ -3114,7 +3303,7 @@ fn testTlsLdNoPlt(b: *Build, opts: Options) *Step { |
| 3114 | fn testTlsNoPic(b: *Build, opts: Options) *Step { | 3303 | fn testTlsNoPic(b: *Build, opts: Options) *Step { |
| 3115 | const test_step = addTestStep(b, "tls-no-pic", opts); | 3304 | const test_step = addTestStep(b, "tls-no-pic", opts); |
| 3116 | 3305 | ||
| 3117 | const exe = addExecutable(b, "main", opts); | 3306 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 3118 | addCSourceBytes(exe, | 3307 | addCSourceBytes(exe, |
| 3119 | \\#include <stdio.h> | 3308 | \\#include <stdio.h> |
| 3120 | \\__attribute__((tls_model("global-dynamic"))) extern _Thread_local int foo; | 3309 | \\__attribute__((tls_model("global-dynamic"))) extern _Thread_local int foo; |
| ... | @@ -3132,7 +3321,7 @@ fn testTlsNoPic(b: *Build, opts: Options) *Step { | ... | @@ -3132,7 +3321,7 @@ fn testTlsNoPic(b: *Build, opts: Options) *Step { |
| 3132 | addCSourceBytes(exe, | 3321 | addCSourceBytes(exe, |
| 3133 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int foo; | 3322 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int foo; |
| 3134 | , &.{}); | 3323 | , &.{}); |
| 3135 | exe.force_pic = false; | 3324 | exe.root_module.pic = false; |
| 3136 | exe.linkLibC(); | 3325 | exe.linkLibC(); |
| 3137 | 3326 | ||
| 3138 | const run = addRunArtifact(exe); | 3327 | const run = addRunArtifact(exe); |
| ... | @@ -3145,7 +3334,7 @@ fn testTlsNoPic(b: *Build, opts: Options) *Step { | ... | @@ -3145,7 +3334,7 @@ fn testTlsNoPic(b: *Build, opts: Options) *Step { |
| 3145 | fn testTlsOffsetAlignment(b: *Build, opts: Options) *Step { | 3334 | fn testTlsOffsetAlignment(b: *Build, opts: Options) *Step { |
| 3146 | const test_step = addTestStep(b, "tls-offset-alignment", opts); | 3335 | const test_step = addTestStep(b, "tls-offset-alignment", opts); |
| 3147 | 3336 | ||
| 3148 | const dso = addSharedLibrary(b, "a", opts); | 3337 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 3149 | addCSourceBytes(dso, | 3338 | addCSourceBytes(dso, |
| 3150 | \\#include <assert.h> | 3339 | \\#include <assert.h> |
| 3151 | \\#include <stdlib.h> | 3340 | \\#include <stdlib.h> |
| ... | @@ -3163,7 +3352,7 @@ fn testTlsOffsetAlignment(b: *Build, opts: Options) *Step { | ... | @@ -3163,7 +3352,7 @@ fn testTlsOffsetAlignment(b: *Build, opts: Options) *Step { |
| 3163 | , &.{}); | 3352 | , &.{}); |
| 3164 | dso.linkLibC(); | 3353 | dso.linkLibC(); |
| 3165 | 3354 | ||
| 3166 | const exe = addExecutable(b, "main", opts); | 3355 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 3167 | addCSourceBytes(exe, | 3356 | addCSourceBytes(exe, |
| 3168 | \\#include <pthread.h> | 3357 | \\#include <pthread.h> |
| 3169 | \\#include <dlfcn.h> | 3358 | \\#include <dlfcn.h> |
| ... | @@ -3186,7 +3375,7 @@ fn testTlsOffsetAlignment(b: *Build, opts: Options) *Step { | ... | @@ -3186,7 +3375,7 @@ fn testTlsOffsetAlignment(b: *Build, opts: Options) *Step { |
| 3186 | , &.{}); | 3375 | , &.{}); |
| 3187 | exe.addRPath(dso.getEmittedBinDirectory()); | 3376 | exe.addRPath(dso.getEmittedBinDirectory()); |
| 3188 | exe.linkLibC(); | 3377 | exe.linkLibC(); |
| 3189 | exe.force_pic = true; | 3378 | exe.root_module.pic = true; |
| 3190 | // https://github.com/ziglang/zig/issues/17619 | 3379 | // https://github.com/ziglang/zig/issues/17619 |
| 3191 | exe.pie = true; | 3380 | exe.pie = true; |
| 3192 | 3381 | ||
| ... | @@ -3200,8 +3389,9 @@ fn testTlsOffsetAlignment(b: *Build, opts: Options) *Step { | ... | @@ -3200,8 +3389,9 @@ fn testTlsOffsetAlignment(b: *Build, opts: Options) *Step { |
| 3200 | fn testTlsPic(b: *Build, opts: Options) *Step { | 3389 | fn testTlsPic(b: *Build, opts: Options) *Step { |
| 3201 | const test_step = addTestStep(b, "tls-pic", opts); | 3390 | const test_step = addTestStep(b, "tls-pic", opts); |
| 3202 | 3391 | ||
| 3203 | const obj = addObject(b, "obj", opts); | 3392 | const obj = addObject(b, opts, .{ |
| 3204 | addCSourceBytes(obj, | 3393 | .name = "obj", |
| 3394 | .c_source_bytes = | ||
| 3205 | \\#include <stdio.h> | 3395 | \\#include <stdio.h> |
| 3206 | \\__attribute__((tls_model("global-dynamic"))) extern _Thread_local int foo; | 3396 | \\__attribute__((tls_model("global-dynamic"))) extern _Thread_local int foo; |
| 3207 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int bar; | 3397 | \\__attribute__((tls_model("global-dynamic"))) static _Thread_local int bar; |
| ... | @@ -3213,11 +3403,12 @@ fn testTlsPic(b: *Build, opts: Options) *Step { | ... | @@ -3213,11 +3403,12 @@ fn testTlsPic(b: *Build, opts: Options) *Step { |
| 3213 | \\ printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar); | 3403 | \\ printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar); |
| 3214 | \\ return 0; | 3404 | \\ return 0; |
| 3215 | \\} | 3405 | \\} |
| 3216 | , &.{}); | 3406 | , |
| 3407 | .pic = true, | ||
| 3408 | }); | ||
| 3217 | obj.linkLibC(); | 3409 | obj.linkLibC(); |
| 3218 | obj.force_pic = true; | ||
| 3219 | 3410 | ||
| 3220 | const exe = addExecutable(b, "main", opts); | 3411 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 3221 | addCSourceBytes(exe, | 3412 | addCSourceBytes(exe, |
| 3222 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int foo = 3; | 3413 | \\__attribute__((tls_model("global-dynamic"))) _Thread_local int foo = 3; |
| 3223 | , &.{}); | 3414 | , &.{}); |
| ... | @@ -3236,30 +3427,38 @@ fn testTlsPic(b: *Build, opts: Options) *Step { | ... | @@ -3236,30 +3427,38 @@ fn testTlsPic(b: *Build, opts: Options) *Step { |
| 3236 | fn testTlsSmallAlignment(b: *Build, opts: Options) *Step { | 3427 | fn testTlsSmallAlignment(b: *Build, opts: Options) *Step { |
| 3237 | const test_step = addTestStep(b, "tls-small-alignment", opts); | 3428 | const test_step = addTestStep(b, "tls-small-alignment", opts); |
| 3238 | 3429 | ||
| 3239 | const a_o = addObject(b, "a", opts); | 3430 | const a_o = addObject(b, opts, .{ |
| 3240 | addAsmSourceBytes(a_o, | 3431 | .name = "a", |
| 3432 | .asm_source_bytes = | ||
| 3241 | \\.text | 3433 | \\.text |
| 3242 | \\.byte 0 | 3434 | \\.byte 0 |
| 3243 | ); | 3435 | \\ |
| 3244 | a_o.force_pic = true; | 3436 | , |
| 3437 | .pic = true, | ||
| 3438 | }); | ||
| 3245 | 3439 | ||
| 3246 | const b_o = addObject(b, "b", opts); | 3440 | const b_o = addObject(b, opts, .{ |
| 3247 | addCSourceBytes(b_o, "_Thread_local char x = 42;", &.{"-std=c11"}); | 3441 | .name = "b", |
| 3248 | b_o.force_pic = true; | 3442 | .c_source_bytes = "_Thread_local char x = 42;", |
| 3443 | .c_source_flags = &.{"-std=c11"}, | ||
| 3444 | .pic = true, | ||
| 3445 | }); | ||
| 3249 | 3446 | ||
| 3250 | const c_o = addObject(b, "c", opts); | 3447 | const c_o = addObject(b, opts, .{ |
| 3251 | addCSourceBytes(c_o, | 3448 | .name = "c", |
| 3449 | .c_source_bytes = | ||
| 3252 | \\#include <stdio.h> | 3450 | \\#include <stdio.h> |
| 3253 | \\extern _Thread_local char x; | 3451 | \\extern _Thread_local char x; |
| 3254 | \\int main() { | 3452 | \\int main() { |
| 3255 | \\ printf("%d\n", x); | 3453 | \\ printf("%d\n", x); |
| 3256 | \\} | 3454 | \\} |
| 3257 | , &.{}); | 3455 | , |
| 3456 | .pic = true, | ||
| 3457 | }); | ||
| 3258 | c_o.linkLibC(); | 3458 | c_o.linkLibC(); |
| 3259 | c_o.force_pic = true; | ||
| 3260 | 3459 | ||
| 3261 | { | 3460 | { |
| 3262 | const exe = addExecutable(b, "main", opts); | 3461 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 3263 | exe.addObject(a_o); | 3462 | exe.addObject(a_o); |
| 3264 | exe.addObject(b_o); | 3463 | exe.addObject(b_o); |
| 3265 | exe.addObject(c_o); | 3464 | exe.addObject(c_o); |
| ... | @@ -3273,11 +3472,11 @@ fn testTlsSmallAlignment(b: *Build, opts: Options) *Step { | ... | @@ -3273,11 +3472,11 @@ fn testTlsSmallAlignment(b: *Build, opts: Options) *Step { |
| 3273 | } | 3472 | } |
| 3274 | 3473 | ||
| 3275 | { | 3474 | { |
| 3276 | const dso = addSharedLibrary(b, "a", opts); | 3475 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 3277 | dso.addObject(a_o); | 3476 | dso.addObject(a_o); |
| 3278 | dso.addObject(b_o); | 3477 | dso.addObject(b_o); |
| 3279 | 3478 | ||
| 3280 | const exe = addExecutable(b, "main", opts); | 3479 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 3281 | exe.addObject(c_o); | 3480 | exe.addObject(c_o); |
| 3282 | exe.linkLibrary(dso); | 3481 | exe.linkLibrary(dso); |
| 3283 | exe.linkLibC(); | 3482 | exe.linkLibC(); |
| ... | @@ -3295,7 +3494,7 @@ fn testTlsSmallAlignment(b: *Build, opts: Options) *Step { | ... | @@ -3295,7 +3494,7 @@ fn testTlsSmallAlignment(b: *Build, opts: Options) *Step { |
| 3295 | fn testTlsStatic(b: *Build, opts: Options) *Step { | 3494 | fn testTlsStatic(b: *Build, opts: Options) *Step { |
| 3296 | const test_step = addTestStep(b, "tls-static", opts); | 3495 | const test_step = addTestStep(b, "tls-static", opts); |
| 3297 | 3496 | ||
| 3298 | const exe = addExecutable(b, "test", opts); | 3497 | const exe = addExecutable(b, opts, .{ .name = "test" }); |
| 3299 | addCSourceBytes(exe, | 3498 | addCSourceBytes(exe, |
| 3300 | \\#include <stdio.h> | 3499 | \\#include <stdio.h> |
| 3301 | \\_Thread_local int a = 10; | 3500 | \\_Thread_local int a = 10; |
| ... | @@ -3326,12 +3525,14 @@ fn testTlsStatic(b: *Build, opts: Options) *Step { | ... | @@ -3326,12 +3525,14 @@ fn testTlsStatic(b: *Build, opts: Options) *Step { |
| 3326 | fn testUnknownFileTypeError(b: *Build, opts: Options) *Step { | 3525 | fn testUnknownFileTypeError(b: *Build, opts: Options) *Step { |
| 3327 | const test_step = addTestStep(b, "unknown-file-type-error", opts); | 3526 | const test_step = addTestStep(b, "unknown-file-type-error", opts); |
| 3328 | 3527 | ||
| 3329 | const dylib = addSharedLibrary(b, "a", .{ | 3528 | const dylib = addSharedLibrary(b, .{ |
| 3330 | .target = .{ .cpu_arch = .x86_64, .os_tag = .macos }, | 3529 | .target = b.resolveTargetQuery(.{ .cpu_arch = .x86_64, .os_tag = .macos }), |
| 3530 | }, .{ | ||
| 3531 | .name = "a", | ||
| 3532 | .zig_source_bytes = "export var foo: i32 = 0;", | ||
| 3331 | }); | 3533 | }); |
| 3332 | addZigSourceBytes(dylib, "export var foo: i32 = 0;"); | ||
| 3333 | 3534 | ||
| 3334 | const exe = addExecutable(b, "main", opts); | 3535 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 3335 | addCSourceBytes(exe, | 3536 | addCSourceBytes(exe, |
| 3336 | \\extern int foo; | 3537 | \\extern int foo; |
| 3337 | \\int main() { | 3538 | \\int main() { |
| ... | @@ -3354,28 +3555,34 @@ fn testUnknownFileTypeError(b: *Build, opts: Options) *Step { | ... | @@ -3354,28 +3555,34 @@ fn testUnknownFileTypeError(b: *Build, opts: Options) *Step { |
| 3354 | fn testUnresolvedError(b: *Build, opts: Options) *Step { | 3555 | fn testUnresolvedError(b: *Build, opts: Options) *Step { |
| 3355 | const test_step = addTestStep(b, "unresolved-error", opts); | 3556 | const test_step = addTestStep(b, "unresolved-error", opts); |
| 3356 | 3557 | ||
| 3357 | const obj1 = addObject(b, "a", opts); | 3558 | const obj1 = addObject(b, opts, .{ |
| 3358 | addCSourceBytes(obj1, | 3559 | .name = "a", |
| 3560 | .c_source_bytes = | ||
| 3359 | \\#include <stdio.h> | 3561 | \\#include <stdio.h> |
| 3360 | \\int foo(); | 3562 | \\int foo(); |
| 3361 | \\int bar() { | 3563 | \\int bar() { |
| 3362 | \\ return foo() + 1; | 3564 | \\ return foo() + 1; |
| 3363 | \\} | 3565 | \\} |
| 3364 | , &.{"-ffunction-sections"}); | 3566 | , |
| 3567 | .c_source_flags = &.{"-ffunction-sections"}, | ||
| 3568 | }); | ||
| 3365 | obj1.linkLibC(); | 3569 | obj1.linkLibC(); |
| 3366 | 3570 | ||
| 3367 | const obj2 = addObject(b, "b", opts); | 3571 | const obj2 = addObject(b, opts, .{ |
| 3368 | addCSourceBytes(obj2, | 3572 | .name = "b", |
| 3573 | .c_source_bytes = | ||
| 3369 | \\#include <stdio.h> | 3574 | \\#include <stdio.h> |
| 3370 | \\int foo(); | 3575 | \\int foo(); |
| 3371 | \\int bar(); | 3576 | \\int bar(); |
| 3372 | \\int main() { | 3577 | \\int main() { |
| 3373 | \\ return foo() + bar(); | 3578 | \\ return foo() + bar(); |
| 3374 | \\} | 3579 | \\} |
| 3375 | , &.{"-ffunction-sections"}); | 3580 | , |
| 3581 | .c_source_flags = &.{"-ffunction-sections"}, | ||
| 3582 | }); | ||
| 3376 | obj2.linkLibC(); | 3583 | obj2.linkLibC(); |
| 3377 | 3584 | ||
| 3378 | const exe = addExecutable(b, "main", opts); | 3585 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 3379 | exe.addObject(obj1); | 3586 | exe.addObject(obj1); |
| 3380 | exe.addObject(obj2); | 3587 | exe.addObject(obj2); |
| 3381 | exe.linkLibC(); | 3588 | exe.linkLibC(); |
| ... | @@ -3392,19 +3599,21 @@ fn testUnresolvedError(b: *Build, opts: Options) *Step { | ... | @@ -3392,19 +3599,21 @@ fn testUnresolvedError(b: *Build, opts: Options) *Step { |
| 3392 | fn testWeakExports(b: *Build, opts: Options) *Step { | 3599 | fn testWeakExports(b: *Build, opts: Options) *Step { |
| 3393 | const test_step = addTestStep(b, "weak-exports", opts); | 3600 | const test_step = addTestStep(b, "weak-exports", opts); |
| 3394 | 3601 | ||
| 3395 | const obj = addObject(b, "obj", opts); | 3602 | const obj = addObject(b, opts, .{ |
| 3396 | addCSourceBytes(obj, | 3603 | .name = "obj", |
| 3604 | .c_source_bytes = | ||
| 3397 | \\#include <stdio.h> | 3605 | \\#include <stdio.h> |
| 3398 | \\__attribute__((weak)) int foo(); | 3606 | \\__attribute__((weak)) int foo(); |
| 3399 | \\int main() { | 3607 | \\int main() { |
| 3400 | \\ printf("%d\n", foo ? foo() : 3); | 3608 | \\ printf("%d\n", foo ? foo() : 3); |
| 3401 | \\} | 3609 | \\} |
| 3402 | , &.{}); | 3610 | , |
| 3611 | .pic = true, | ||
| 3612 | }); | ||
| 3403 | obj.linkLibC(); | 3613 | obj.linkLibC(); |
| 3404 | obj.force_pic = true; | ||
| 3405 | 3614 | ||
| 3406 | { | 3615 | { |
| 3407 | const dso = addSharedLibrary(b, "a", opts); | 3616 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 3408 | dso.addObject(obj); | 3617 | dso.addObject(obj); |
| 3409 | dso.linkLibC(); | 3618 | dso.linkLibC(); |
| 3410 | 3619 | ||
| ... | @@ -3415,7 +3624,7 @@ fn testWeakExports(b: *Build, opts: Options) *Step { | ... | @@ -3415,7 +3624,7 @@ fn testWeakExports(b: *Build, opts: Options) *Step { |
| 3415 | } | 3624 | } |
| 3416 | 3625 | ||
| 3417 | { | 3626 | { |
| 3418 | const exe = addExecutable(b, "main", opts); | 3627 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 3419 | exe.addObject(obj); | 3628 | exe.addObject(obj); |
| 3420 | exe.linkLibC(); | 3629 | exe.linkLibC(); |
| 3421 | // https://github.com/ziglang/zig/issues/17619 | 3630 | // https://github.com/ziglang/zig/issues/17619 |
| ... | @@ -3437,14 +3646,14 @@ fn testWeakExports(b: *Build, opts: Options) *Step { | ... | @@ -3437,14 +3646,14 @@ fn testWeakExports(b: *Build, opts: Options) *Step { |
| 3437 | fn testWeakUndefsDso(b: *Build, opts: Options) *Step { | 3646 | fn testWeakUndefsDso(b: *Build, opts: Options) *Step { |
| 3438 | const test_step = addTestStep(b, "weak-undef-dso", opts); | 3647 | const test_step = addTestStep(b, "weak-undef-dso", opts); |
| 3439 | 3648 | ||
| 3440 | const dso = addSharedLibrary(b, "a", opts); | 3649 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 3441 | addCSourceBytes(dso, | 3650 | addCSourceBytes(dso, |
| 3442 | \\__attribute__((weak)) int foo(); | 3651 | \\__attribute__((weak)) int foo(); |
| 3443 | \\int bar() { return foo ? foo() : -1; } | 3652 | \\int bar() { return foo ? foo() : -1; } |
| 3444 | , &.{}); | 3653 | , &.{}); |
| 3445 | 3654 | ||
| 3446 | { | 3655 | { |
| 3447 | const exe = addExecutable(b, "main", opts); | 3656 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 3448 | addCSourceBytes(exe, | 3657 | addCSourceBytes(exe, |
| 3449 | \\#include <stdio.h> | 3658 | \\#include <stdio.h> |
| 3450 | \\int bar(); | 3659 | \\int bar(); |
| ... | @@ -3461,7 +3670,7 @@ fn testWeakUndefsDso(b: *Build, opts: Options) *Step { | ... | @@ -3461,7 +3670,7 @@ fn testWeakUndefsDso(b: *Build, opts: Options) *Step { |
| 3461 | } | 3670 | } |
| 3462 | 3671 | ||
| 3463 | { | 3672 | { |
| 3464 | const exe = addExecutable(b, "main", opts); | 3673 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 3465 | addCSourceBytes(exe, | 3674 | addCSourceBytes(exe, |
| 3466 | \\#include <stdio.h> | 3675 | \\#include <stdio.h> |
| 3467 | \\int foo() { return 5; } | 3676 | \\int foo() { return 5; } |
| ... | @@ -3484,12 +3693,14 @@ fn testWeakUndefsDso(b: *Build, opts: Options) *Step { | ... | @@ -3484,12 +3693,14 @@ fn testWeakUndefsDso(b: *Build, opts: Options) *Step { |
| 3484 | fn testZNow(b: *Build, opts: Options) *Step { | 3693 | fn testZNow(b: *Build, opts: Options) *Step { |
| 3485 | const test_step = addTestStep(b, "z-now", opts); | 3694 | const test_step = addTestStep(b, "z-now", opts); |
| 3486 | 3695 | ||
| 3487 | const obj = addObject(b, "obj", opts); | 3696 | const obj = addObject(b, opts, .{ |
| 3488 | addCSourceBytes(obj, "int main() { return 0; }", &.{}); | 3697 | .name = "obj", |
| 3489 | obj.force_pic = true; | 3698 | .c_source_bytes = "int main() { return 0; }", |
| 3699 | .pic = true, | ||
| 3700 | }); | ||
| 3490 | 3701 | ||
| 3491 | { | 3702 | { |
| 3492 | const dso = addSharedLibrary(b, "a", opts); | 3703 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 3493 | dso.addObject(obj); | 3704 | dso.addObject(obj); |
| 3494 | 3705 | ||
| 3495 | const check = dso.checkObject(); | 3706 | const check = dso.checkObject(); |
| ... | @@ -3499,7 +3710,7 @@ fn testZNow(b: *Build, opts: Options) *Step { | ... | @@ -3499,7 +3710,7 @@ fn testZNow(b: *Build, opts: Options) *Step { |
| 3499 | } | 3710 | } |
| 3500 | 3711 | ||
| 3501 | { | 3712 | { |
| 3502 | const dso = addSharedLibrary(b, "a", opts); | 3713 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 3503 | dso.addObject(obj); | 3714 | dso.addObject(obj); |
| 3504 | dso.link_z_lazy = true; | 3715 | dso.link_z_lazy = true; |
| 3505 | 3716 | ||
| ... | @@ -3515,7 +3726,7 @@ fn testZNow(b: *Build, opts: Options) *Step { | ... | @@ -3515,7 +3726,7 @@ fn testZNow(b: *Build, opts: Options) *Step { |
| 3515 | fn testZStackSize(b: *Build, opts: Options) *Step { | 3726 | fn testZStackSize(b: *Build, opts: Options) *Step { |
| 3516 | const test_step = addTestStep(b, "z-stack-size", opts); | 3727 | const test_step = addTestStep(b, "z-stack-size", opts); |
| 3517 | 3728 | ||
| 3518 | const exe = addExecutable(b, "main", opts); | 3729 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 3519 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); | 3730 | addCSourceBytes(exe, "int main() { return 0; }", &.{}); |
| 3520 | exe.stack_size = 0x800000; | 3731 | exe.stack_size = 0x800000; |
| 3521 | exe.linkLibC(); | 3732 | exe.linkLibC(); |
| ... | @@ -3540,8 +3751,9 @@ fn testZText(b: *Build, opts: Options) *Step { | ... | @@ -3540,8 +3751,9 @@ fn testZText(b: *Build, opts: Options) *Step { |
| 3540 | // musl supports only a very limited number of text relocations and only in DSOs (and | 3751 | // musl supports only a very limited number of text relocations and only in DSOs (and |
| 3541 | // rightly so!). | 3752 | // rightly so!). |
| 3542 | 3753 | ||
| 3543 | const a_o = addObject(b, "a", opts); | 3754 | const a_o = addObject(b, opts, .{ |
| 3544 | addAsmSourceBytes(a_o, | 3755 | .name = "a", |
| 3756 | .asm_source_bytes = | ||
| 3545 | \\.globl fn1 | 3757 | \\.globl fn1 |
| 3546 | \\fn1: | 3758 | \\fn1: |
| 3547 | \\ sub $8, %rsp | 3759 | \\ sub $8, %rsp |
| ... | @@ -3549,10 +3761,13 @@ fn testZText(b: *Build, opts: Options) *Step { | ... | @@ -3549,10 +3761,13 @@ fn testZText(b: *Build, opts: Options) *Step { |
| 3549 | \\ call *%rax | 3761 | \\ call *%rax |
| 3550 | \\ add $8, %rsp | 3762 | \\ add $8, %rsp |
| 3551 | \\ ret | 3763 | \\ ret |
| 3552 | ); | 3764 | \\ |
| 3765 | , | ||
| 3766 | }); | ||
| 3553 | 3767 | ||
| 3554 | const b_o = addObject(b, "b", opts); | 3768 | const b_o = addObject(b, opts, .{ |
| 3555 | addCSourceBytes(b_o, | 3769 | .name = "b", |
| 3770 | .c_source_bytes = | ||
| 3556 | \\int fn1(); | 3771 | \\int fn1(); |
| 3557 | \\int fn2() { | 3772 | \\int fn2() { |
| 3558 | \\ return 3; | 3773 | \\ return 3; |
| ... | @@ -3561,15 +3776,16 @@ fn testZText(b: *Build, opts: Options) *Step { | ... | @@ -3561,15 +3776,16 @@ fn testZText(b: *Build, opts: Options) *Step { |
| 3561 | \\int fnn() { | 3776 | \\int fnn() { |
| 3562 | \\ return fn1(); | 3777 | \\ return fn1(); |
| 3563 | \\} | 3778 | \\} |
| 3564 | , &.{}); | 3779 | , |
| 3565 | b_o.force_pic = true; | 3780 | .pic = true, |
| 3781 | }); | ||
| 3566 | 3782 | ||
| 3567 | const dso = addSharedLibrary(b, "a", opts); | 3783 | const dso = addSharedLibrary(b, opts, .{ .name = "a" }); |
| 3568 | dso.addObject(a_o); | 3784 | dso.addObject(a_o); |
| 3569 | dso.addObject(b_o); | 3785 | dso.addObject(b_o); |
| 3570 | dso.link_z_notext = true; | 3786 | dso.link_z_notext = true; |
| 3571 | 3787 | ||
| 3572 | const exe = addExecutable(b, "main", opts); | 3788 | const exe = addExecutable(b, opts, .{ .name = "main" }); |
| 3573 | addCSourceBytes(exe, | 3789 | addCSourceBytes(exe, |
| 3574 | \\#include <stdio.h> | 3790 | \\#include <stdio.h> |
| 3575 | \\int fnn(); | 3791 | \\int fnn(); |
| ... | @@ -3608,7 +3824,6 @@ const addObject = link.addObject; | ... | @@ -3608,7 +3824,6 @@ const addObject = link.addObject; |
| 3608 | const addRunArtifact = link.addRunArtifact; | 3824 | const addRunArtifact = link.addRunArtifact; |
| 3609 | const addSharedLibrary = link.addSharedLibrary; | 3825 | const addSharedLibrary = link.addSharedLibrary; |
| 3610 | const addStaticLibrary = link.addStaticLibrary; | 3826 | const addStaticLibrary = link.addStaticLibrary; |
| 3611 | const addZigSourceBytes = link.addZigSourceBytes; | ||
| 3612 | const expectLinkErrors = link.expectLinkErrors; | 3827 | const expectLinkErrors = link.expectLinkErrors; |
| 3613 | const link = @import("link.zig"); | 3828 | const link = @import("link.zig"); |
| 3614 | const std = @import("std"); | 3829 | const std = @import("std"); |
test/link/glibc_compat/build.zig+2-2| ... | @@ -8,9 +8,9 @@ pub fn build(b: *std.Build) void { | ... | @@ -8,9 +8,9 @@ pub fn build(b: *std.Build) void { |
| 8 | const exe = b.addExecutable(.{ | 8 | const exe = b.addExecutable(.{ |
| 9 | .name = t, | 9 | .name = t, |
| 10 | .root_source_file = .{ .path = "main.c" }, | 10 | .root_source_file = .{ .path = "main.c" }, |
| 11 | .target = std.zig.CrossTarget.parse( | 11 | .target = b.resolveTargetQuery(std.zig.CrossTarget.parse( |
| 12 | .{ .arch_os_abi = t }, | 12 | .{ .arch_os_abi = t }, |
| 13 | ) catch unreachable, | 13 | ) catch unreachable), |
| 14 | }); | 14 | }); |
| 15 | exe.linkLibC(); | 15 | exe.linkLibC(); |
| 16 | // TODO: actually test the output | 16 | // TODO: actually test the output |
test/link/interdependent_static_c_libs/build.zig+2-2| ... | @@ -14,7 +14,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -14,7 +14,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 14 | const lib_a = b.addStaticLibrary(.{ | 14 | const lib_a = b.addStaticLibrary(.{ |
| 15 | .name = "a", | 15 | .name = "a", |
| 16 | .optimize = optimize, | 16 | .optimize = optimize, |
| 17 | .target = .{}, | 17 | .target = b.host, |
| 18 | }); | 18 | }); |
| 19 | lib_a.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &[_][]const u8{} }); | 19 | lib_a.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &[_][]const u8{} }); |
| 20 | lib_a.addIncludePath(.{ .path = "." }); | 20 | lib_a.addIncludePath(.{ .path = "." }); |
| ... | @@ -22,7 +22,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -22,7 +22,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 22 | const lib_b = b.addStaticLibrary(.{ | 22 | const lib_b = b.addStaticLibrary(.{ |
| 23 | .name = "b", | 23 | .name = "b", |
| 24 | .optimize = optimize, | 24 | .optimize = optimize, |
| 25 | .target = .{}, | 25 | .target = b.host, |
| 26 | }); | 26 | }); |
| 27 | lib_b.addCSourceFile(.{ .file = .{ .path = "b.c" }, .flags = &[_][]const u8{} }); | 27 | lib_b.addCSourceFile(.{ .file = .{ .path = "b.c" }, .flags = &[_][]const u8{} }); |
| 28 | lib_b.addIncludePath(.{ .path = "." }); | 28 | lib_b.addIncludePath(.{ .path = "." }); |
test/link/link.zig+133-42| ... | @@ -7,62 +7,160 @@ pub fn build(b: *Build) void { | ... | @@ -7,62 +7,160 @@ pub fn build(b: *Build) void { |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | pub const Options = struct { | 9 | pub const Options = struct { |
| 10 | target: CrossTarget, | 10 | target: std.Build.ResolvedTarget, |
| 11 | optimize: std.builtin.OptimizeMode = .Debug, | 11 | optimize: std.builtin.OptimizeMode = .Debug, |
| 12 | use_llvm: bool = true, | 12 | use_llvm: bool = true, |
| 13 | use_lld: bool = false, | 13 | use_lld: bool = false, |
| 14 | }; | 14 | }; |
| 15 | 15 | ||
| 16 | pub fn addTestStep(b: *Build, comptime prefix: []const u8, opts: Options) *Step { | 16 | pub fn addTestStep(b: *Build, prefix: []const u8, opts: Options) *Step { |
| 17 | const target = opts.target.zigTriple(b.allocator) catch @panic("OOM"); | 17 | const target = opts.target.target.zigTriple(b.allocator) catch @panic("OOM"); |
| 18 | const optimize = @tagName(opts.optimize); | 18 | const optimize = @tagName(opts.optimize); |
| 19 | const use_llvm = if (opts.use_llvm) "llvm" else "no-llvm"; | 19 | const use_llvm = if (opts.use_llvm) "llvm" else "no-llvm"; |
| 20 | const name = std.fmt.allocPrint(b.allocator, "test-" ++ prefix ++ "-{s}-{s}-{s}", .{ | 20 | const name = std.fmt.allocPrint(b.allocator, "test-{s}-{s}-{s}-{s}", .{ |
| 21 | target, | 21 | prefix, target, optimize, use_llvm, |
| 22 | optimize, | ||
| 23 | use_llvm, | ||
| 24 | }) catch @panic("OOM"); | 22 | }) catch @panic("OOM"); |
| 25 | return b.step(name, ""); | 23 | return b.step(name, ""); |
| 26 | } | 24 | } |
| 27 | 25 | ||
| 28 | pub fn addExecutable(b: *Build, name: []const u8, opts: Options) *Compile { | 26 | const OverlayOptions = struct { |
| 29 | return b.addExecutable(.{ | 27 | name: []const u8, |
| 30 | .name = name, | 28 | asm_source_bytes: ?[]const u8 = null, |
| 31 | .target = opts.target, | 29 | c_source_bytes: ?[]const u8 = null, |
| 32 | .optimize = opts.optimize, | 30 | c_source_flags: []const []const u8 = &.{}, |
| 33 | .use_llvm = opts.use_llvm, | 31 | cpp_source_bytes: ?[]const u8 = null, |
| 34 | .use_lld = opts.use_lld, | 32 | cpp_source_flags: []const []const u8 = &.{}, |
| 33 | zig_source_bytes: ?[]const u8 = null, | ||
| 34 | pic: ?bool = null, | ||
| 35 | strip: ?bool = null, | ||
| 36 | }; | ||
| 37 | |||
| 38 | pub fn addExecutable(b: *std.Build, base: Options, overlay: OverlayOptions) *Step.Compile { | ||
| 39 | const compile_step = b.addExecutable(.{ | ||
| 40 | .name = overlay.name, | ||
| 41 | .root_source_file = rsf: { | ||
| 42 | const bytes = overlay.zig_source_bytes orelse break :rsf null; | ||
| 43 | break :rsf b.addWriteFiles().add("a.zig", bytes); | ||
| 44 | }, | ||
| 45 | .target = base.target, | ||
| 46 | .optimize = base.optimize, | ||
| 47 | .use_llvm = base.use_llvm, | ||
| 48 | .use_lld = base.use_lld, | ||
| 49 | .pic = overlay.pic, | ||
| 50 | .strip = overlay.strip, | ||
| 35 | }); | 51 | }); |
| 52 | if (overlay.cpp_source_bytes) |bytes| { | ||
| 53 | compile_step.addCSourceFile(.{ | ||
| 54 | .file = b.addWriteFiles().add("a.cpp", bytes), | ||
| 55 | .flags = overlay.cpp_source_flags, | ||
| 56 | }); | ||
| 57 | } | ||
| 58 | if (overlay.c_source_bytes) |bytes| { | ||
| 59 | compile_step.addCSourceFile(.{ | ||
| 60 | .file = b.addWriteFiles().add("a.c", bytes), | ||
| 61 | .flags = overlay.c_source_flags, | ||
| 62 | }); | ||
| 63 | } | ||
| 64 | if (overlay.asm_source_bytes) |bytes| { | ||
| 65 | compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes)); | ||
| 66 | } | ||
| 67 | return compile_step; | ||
| 36 | } | 68 | } |
| 37 | 69 | ||
| 38 | pub fn addObject(b: *Build, name: []const u8, opts: Options) *Compile { | 70 | pub fn addObject(b: *Build, base: Options, overlay: OverlayOptions) *Step.Compile { |
| 39 | return b.addObject(.{ | 71 | const compile_step = b.addObject(.{ |
| 40 | .name = name, | 72 | .name = overlay.name, |
| 41 | .target = opts.target, | 73 | .root_source_file = rsf: { |
| 42 | .optimize = opts.optimize, | 74 | const bytes = overlay.zig_source_bytes orelse break :rsf null; |
| 43 | .use_llvm = opts.use_llvm, | 75 | break :rsf b.addWriteFiles().add("a.zig", bytes); |
| 44 | .use_lld = opts.use_lld, | 76 | }, |
| 77 | .target = base.target, | ||
| 78 | .optimize = base.optimize, | ||
| 79 | .use_llvm = base.use_llvm, | ||
| 80 | .use_lld = base.use_lld, | ||
| 81 | .pic = overlay.pic, | ||
| 82 | .strip = overlay.strip, | ||
| 45 | }); | 83 | }); |
| 84 | if (overlay.cpp_source_bytes) |bytes| { | ||
| 85 | compile_step.addCSourceFile(.{ | ||
| 86 | .file = b.addWriteFiles().add("a.cpp", bytes), | ||
| 87 | .flags = overlay.cpp_source_flags, | ||
| 88 | }); | ||
| 89 | } | ||
| 90 | if (overlay.c_source_bytes) |bytes| { | ||
| 91 | compile_step.addCSourceFile(.{ | ||
| 92 | .file = b.addWriteFiles().add("a.c", bytes), | ||
| 93 | .flags = overlay.c_source_flags, | ||
| 94 | }); | ||
| 95 | } | ||
| 96 | if (overlay.asm_source_bytes) |bytes| { | ||
| 97 | compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes)); | ||
| 98 | } | ||
| 99 | return compile_step; | ||
| 46 | } | 100 | } |
| 47 | 101 | ||
| 48 | pub fn addStaticLibrary(b: *Build, name: []const u8, opts: Options) *Compile { | 102 | pub fn addStaticLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile { |
| 49 | return b.addStaticLibrary(.{ | 103 | const compile_step = b.addStaticLibrary(.{ |
| 50 | .name = name, | 104 | .name = overlay.name, |
| 51 | .target = opts.target, | 105 | .root_source_file = rsf: { |
| 52 | .optimize = opts.optimize, | 106 | const bytes = overlay.zig_source_bytes orelse break :rsf null; |
| 53 | .use_llvm = opts.use_llvm, | 107 | break :rsf b.addWriteFiles().add("a.zig", bytes); |
| 54 | .use_lld = opts.use_lld, | 108 | }, |
| 109 | .target = base.target, | ||
| 110 | .optimize = base.optimize, | ||
| 111 | .use_llvm = base.use_llvm, | ||
| 112 | .use_lld = base.use_lld, | ||
| 113 | .pic = overlay.pic, | ||
| 114 | .strip = overlay.strip, | ||
| 55 | }); | 115 | }); |
| 116 | if (overlay.cpp_source_bytes) |bytes| { | ||
| 117 | compile_step.addCSourceFile(.{ | ||
| 118 | .file = b.addWriteFiles().add("a.cpp", bytes), | ||
| 119 | .flags = overlay.cpp_source_flags, | ||
| 120 | }); | ||
| 121 | } | ||
| 122 | if (overlay.c_source_bytes) |bytes| { | ||
| 123 | compile_step.addCSourceFile(.{ | ||
| 124 | .file = b.addWriteFiles().add("a.c", bytes), | ||
| 125 | .flags = overlay.c_source_flags, | ||
| 126 | }); | ||
| 127 | } | ||
| 128 | if (overlay.asm_source_bytes) |bytes| { | ||
| 129 | compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes)); | ||
| 130 | } | ||
| 131 | return compile_step; | ||
| 56 | } | 132 | } |
| 57 | 133 | ||
| 58 | pub fn addSharedLibrary(b: *Build, name: []const u8, opts: Options) *Compile { | 134 | pub fn addSharedLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile { |
| 59 | return b.addSharedLibrary(.{ | 135 | const compile_step = b.addSharedLibrary(.{ |
| 60 | .name = name, | 136 | .name = overlay.name, |
| 61 | .target = opts.target, | 137 | .root_source_file = rsf: { |
| 62 | .optimize = opts.optimize, | 138 | const bytes = overlay.zig_source_bytes orelse break :rsf null; |
| 63 | .use_llvm = opts.use_llvm, | 139 | break :rsf b.addWriteFiles().add("a.zig", bytes); |
| 64 | .use_lld = opts.use_lld, | 140 | }, |
| 141 | .target = base.target, | ||
| 142 | .optimize = base.optimize, | ||
| 143 | .use_llvm = base.use_llvm, | ||
| 144 | .use_lld = base.use_lld, | ||
| 145 | .pic = overlay.pic, | ||
| 146 | .strip = overlay.strip, | ||
| 65 | }); | 147 | }); |
| 148 | if (overlay.cpp_source_bytes) |bytes| { | ||
| 149 | compile_step.addCSourceFile(.{ | ||
| 150 | .file = b.addWriteFiles().add("a.cpp", bytes), | ||
| 151 | .flags = overlay.cpp_source_flags, | ||
| 152 | }); | ||
| 153 | } | ||
| 154 | if (overlay.c_source_bytes) |bytes| { | ||
| 155 | compile_step.addCSourceFile(.{ | ||
| 156 | .file = b.addWriteFiles().add("a.c", bytes), | ||
| 157 | .flags = overlay.c_source_flags, | ||
| 158 | }); | ||
| 159 | } | ||
| 160 | if (overlay.asm_source_bytes) |bytes| { | ||
| 161 | compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes)); | ||
| 162 | } | ||
| 163 | return compile_step; | ||
| 66 | } | 164 | } |
| 67 | 165 | ||
| 68 | pub fn addRunArtifact(comp: *Compile) *Run { | 166 | pub fn addRunArtifact(comp: *Compile) *Run { |
| ... | @@ -72,13 +170,6 @@ pub fn addRunArtifact(comp: *Compile) *Run { | ... | @@ -72,13 +170,6 @@ pub fn addRunArtifact(comp: *Compile) *Run { |
| 72 | return run; | 170 | return run; |
| 73 | } | 171 | } |
| 74 | 172 | ||
| 75 | pub fn addZigSourceBytes(comp: *Compile, bytes: []const u8) void { | ||
| 76 | const b = comp.step.owner; | ||
| 77 | const file = WriteFile.create(b).add("a.zig", bytes); | ||
| 78 | file.addStepDependencies(&comp.step); | ||
| 79 | comp.root_src = file; | ||
| 80 | } | ||
| 81 | |||
| 82 | pub fn addCSourceBytes(comp: *Compile, bytes: []const u8, flags: []const []const u8) void { | 173 | pub fn addCSourceBytes(comp: *Compile, bytes: []const u8, flags: []const []const u8) void { |
| 83 | const b = comp.step.owner; | 174 | const b = comp.step.owner; |
| 84 | const file = WriteFile.create(b).add("a.c", bytes); | 175 | const file = WriteFile.create(b).add("a.c", bytes); |
test/link/macho.zig+32-27| ... | @@ -1,26 +1,29 @@ | ... | @@ -1,26 +1,29 @@ |
| 1 | //! Here we test our MachO linker for correctness and functionality. | 1 | //! Here we test our MachO linker for correctness and functionality. |
| 2 | //! TODO migrate standalone tests from test/link/macho/* to here. | 2 | //! TODO migrate standalone tests from test/link/macho/* to here. |
| 3 | 3 | ||
| 4 | pub fn testAll(b: *Build) *Step { | 4 | pub fn testAll(b: *std.Build) *Step { |
| 5 | const macho_step = b.step("test-macho", "Run MachO tests"); | 5 | const macho_step = b.step("test-macho", "Run MachO tests"); |
| 6 | 6 | ||
| 7 | const default_target = CrossTarget{ .os_tag = .macos }; | 7 | macho_step.dependOn(testResolvingBoundarySymbols(b, .{ |
| 8 | 8 | .target = b.resolveTargetQuery(.{ .os_tag = .macos }), | |
| 9 | macho_step.dependOn(testResolvingBoundarySymbols(b, .{ .target = default_target })); | 9 | })); |
| 10 | 10 | ||
| 11 | return macho_step; | 11 | return macho_step; |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | fn testResolvingBoundarySymbols(b: *Build, opts: Options) *Step { | 14 | fn testResolvingBoundarySymbols(b: *std.Build, opts: Options) *Step { |
| 15 | const test_step = addTestStep(b, "macho-resolving-boundary-symbols", opts); | 15 | const test_step = addTestStep(b, "macho-resolving-boundary-symbols", opts); |
| 16 | 16 | ||
| 17 | const obj1 = addObject(b, "obj1", opts); | 17 | const obj1 = addObject(b, opts, .{ |
| 18 | addCppSourceBytes(obj1, | 18 | .name = "obj1", |
| 19 | .cpp_source_bytes = | ||
| 19 | \\constexpr const char* MESSAGE __attribute__((used, section("__DATA_CONST,__message_ptr"))) = "codebase"; | 20 | \\constexpr const char* MESSAGE __attribute__((used, section("__DATA_CONST,__message_ptr"))) = "codebase"; |
| 20 | , &.{}); | 21 | , |
| 22 | }); | ||
| 21 | 23 | ||
| 22 | const main_o = addObject(b, "main", opts); | 24 | const main_o = addObject(b, opts, .{ |
| 23 | addZigSourceBytes(main_o, | 25 | .name = "main", |
| 26 | .zig_source_bytes = | ||
| 24 | \\const std = @import("std"); | 27 | \\const std = @import("std"); |
| 25 | \\extern fn interop() [*:0]const u8; | 28 | \\extern fn interop() [*:0]const u8; |
| 26 | \\pub fn main() !void { | 29 | \\pub fn main() !void { |
| ... | @@ -28,23 +31,27 @@ fn testResolvingBoundarySymbols(b: *Build, opts: Options) *Step { | ... | @@ -28,23 +31,27 @@ fn testResolvingBoundarySymbols(b: *Build, opts: Options) *Step { |
| 28 | \\ std.mem.span(interop()), | 31 | \\ std.mem.span(interop()), |
| 29 | \\ }); | 32 | \\ }); |
| 30 | \\} | 33 | \\} |
| 31 | ); | 34 | , |
| 35 | }); | ||
| 32 | 36 | ||
| 33 | { | 37 | { |
| 34 | const obj2 = addObject(b, "obj2", opts); | 38 | const obj2 = addObject(b, opts, .{ |
| 35 | addCppSourceBytes(obj2, | 39 | .name = "obj2", |
| 40 | .cpp_source_bytes = | ||
| 36 | \\extern const char* message_pointer __asm("section$start$__DATA_CONST$__message_ptr"); | 41 | \\extern const char* message_pointer __asm("section$start$__DATA_CONST$__message_ptr"); |
| 37 | \\extern "C" const char* interop() { | 42 | \\extern "C" const char* interop() { |
| 38 | \\ return message_pointer; | 43 | \\ return message_pointer; |
| 39 | \\} | 44 | \\} |
| 40 | , &.{}); | 45 | , |
| 46 | }); | ||
| 41 | 47 | ||
| 42 | const exe = addExecutable(b, "test", opts); | 48 | const exe = addExecutable(b, opts, .{ .name = "test" }); |
| 43 | exe.addObject(obj1); | 49 | exe.addObject(obj1); |
| 44 | exe.addObject(obj2); | 50 | exe.addObject(obj2); |
| 45 | exe.addObject(main_o); | 51 | exe.addObject(main_o); |
| 46 | 52 | ||
| 47 | const run = addRunArtifact(exe); | 53 | const run = b.addRunArtifact(exe); |
| 54 | run.skip_foreign_checks = true; | ||
| 48 | run.expectStdErrEqual("All your codebase are belong to us.\n"); | 55 | run.expectStdErrEqual("All your codebase are belong to us.\n"); |
| 49 | test_step.dependOn(&run.step); | 56 | test_step.dependOn(&run.step); |
| 50 | 57 | ||
| ... | @@ -55,15 +62,17 @@ fn testResolvingBoundarySymbols(b: *Build, opts: Options) *Step { | ... | @@ -55,15 +62,17 @@ fn testResolvingBoundarySymbols(b: *Build, opts: Options) *Step { |
| 55 | } | 62 | } |
| 56 | 63 | ||
| 57 | { | 64 | { |
| 58 | const obj3 = addObject(b, "obj3", opts); | 65 | const obj3 = addObject(b, opts, .{ |
| 59 | addCppSourceBytes(obj3, | 66 | .name = "obj3", |
| 67 | .cpp_source_bytes = | ||
| 60 | \\extern const char* message_pointer __asm("section$start$__DATA$__message_ptr"); | 68 | \\extern const char* message_pointer __asm("section$start$__DATA$__message_ptr"); |
| 61 | \\extern "C" const char* interop() { | 69 | \\extern "C" const char* interop() { |
| 62 | \\ return message_pointer; | 70 | \\ return message_pointer; |
| 63 | \\} | 71 | \\} |
| 64 | , &.{}); | 72 | , |
| 73 | }); | ||
| 65 | 74 | ||
| 66 | const exe = addExecutable(b, "test", opts); | 75 | const exe = addExecutable(b, opts, .{ .name = "test" }); |
| 67 | exe.addObject(obj1); | 76 | exe.addObject(obj1); |
| 68 | exe.addObject(obj3); | 77 | exe.addObject(obj3); |
| 69 | exe.addObject(main_o); | 78 | exe.addObject(main_o); |
| ... | @@ -77,20 +86,16 @@ fn testResolvingBoundarySymbols(b: *Build, opts: Options) *Step { | ... | @@ -77,20 +86,16 @@ fn testResolvingBoundarySymbols(b: *Build, opts: Options) *Step { |
| 77 | return test_step; | 86 | return test_step; |
| 78 | } | 87 | } |
| 79 | 88 | ||
| 80 | fn addTestStep(b: *Build, comptime prefix: []const u8, opts: Options) *Step { | 89 | fn addTestStep(b: *std.Build, comptime prefix: []const u8, opts: Options) *Step { |
| 81 | return link.addTestStep(b, "macho-" ++ prefix, opts); | 90 | return link.addTestStep(b, "macho-" ++ prefix, opts); |
| 82 | } | 91 | } |
| 83 | 92 | ||
| 84 | const addCppSourceBytes = link.addCppSourceBytes; | ||
| 85 | const addExecutable = link.addExecutable; | ||
| 86 | const addObject = link.addObject; | 93 | const addObject = link.addObject; |
| 87 | const addRunArtifact = link.addRunArtifact; | 94 | const addExecutable = link.addExecutable; |
| 88 | const addZigSourceBytes = link.addZigSourceBytes; | ||
| 89 | const expectLinkErrors = link.expectLinkErrors; | 95 | const expectLinkErrors = link.expectLinkErrors; |
| 90 | const link = @import("link.zig"); | 96 | const link = @import("link.zig"); |
| 91 | const std = @import("std"); | 97 | const std = @import("std"); |
| 92 | 98 | ||
| 93 | const Build = std.Build; | ||
| 94 | const CrossTarget = std.zig.CrossTarget; | 99 | const CrossTarget = std.zig.CrossTarget; |
| 95 | const Options = link.Options; | 100 | const Options = link.Options; |
| 96 | const Step = Build.Step; | 101 | const Step = std.Build.Step; |
test/link/macho/bugs/13056/build.zig+3-3| ... | @@ -14,14 +14,14 @@ pub fn build(b: *std.Build) void { | ... | @@ -14,14 +14,14 @@ pub fn build(b: *std.Build) void { |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 16 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 17 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 17 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 18 | const target_info = std.zig.system.NativeTargetInfo.detect(target) catch unreachable; | 18 | const sdk = std.zig.system.darwin.getSdk(b.allocator, target.target) orelse |
| 19 | const sdk = std.zig.system.darwin.getSdk(b.allocator, target_info.target) orelse | ||
| 20 | @panic("macOS SDK is required to run the test"); | 19 | @panic("macOS SDK is required to run the test"); |
| 21 | 20 | ||
| 22 | const exe = b.addExecutable(.{ | 21 | const exe = b.addExecutable(.{ |
| 23 | .name = "test", | 22 | .name = "test", |
| 24 | .optimize = optimize, | 23 | .optimize = optimize, |
| 24 | .target = b.host, | ||
| 25 | }); | 25 | }); |
| 26 | exe.addSystemIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include" }) }); | 26 | exe.addSystemIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include" }) }); |
| 27 | exe.addIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include/c++/v1" }) }); | 27 | exe.addIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include/c++/v1" }) }); |
test/link/macho/bugs/13457/build.zig+1-1| ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 17 | 17 | ||
| 18 | const exe = b.addExecutable(.{ | 18 | const exe = b.addExecutable(.{ |
| 19 | .name = "test", | 19 | .name = "test", |
test/link/macho/bugs/16308/build.zig+1-1| ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { |
| 6 | const test_step = b.step("test", "Test it"); | 6 | const test_step = b.step("test", "Test it"); |
| 7 | b.default_step = test_step; | 7 | b.default_step = test_step; |
| 8 | 8 | ||
| 9 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 9 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 10 | 10 | ||
| 11 | const lib = b.addSharedLibrary(.{ | 11 | const lib = b.addSharedLibrary(.{ |
| 12 | .name = "a", | 12 | .name = "a", |
test/link/macho/bugs/16628/build.zig+1-1| ... | @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 17 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 18 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 18 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 19 | 19 | ||
| 20 | const exe = b.addExecutable(.{ | 20 | const exe = b.addExecutable(.{ |
| 21 | .name = "test", | 21 | .name = "test", |
test/link/macho/dead_strip/build.zig+2-2| ... | @@ -4,7 +4,7 @@ pub const requires_symlinks = true; | ... | @@ -4,7 +4,7 @@ pub const requires_symlinks = true; |
| 4 | 4 | ||
| 5 | pub fn build(b: *std.Build) void { | 5 | pub fn build(b: *std.Build) void { |
| 6 | const optimize: std.builtin.OptimizeMode = .Debug; | 6 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 7 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 8 | 8 | ||
| 9 | const test_step = b.step("test", "Test the program"); | 9 | const test_step = b.step("test", "Test the program"); |
| 10 | b.default_step = test_step; | 10 | b.default_step = test_step; |
| ... | @@ -44,7 +44,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -44,7 +44,7 @@ pub fn build(b: *std.Build) void { |
| 44 | fn createScenario( | 44 | fn createScenario( |
| 45 | b: *std.Build, | 45 | b: *std.Build, |
| 46 | optimize: std.builtin.OptimizeMode, | 46 | optimize: std.builtin.OptimizeMode, |
| 47 | target: std.zig.CrossTarget, | 47 | target: std.Build.ResolvedTarget, |
| 48 | name: []const u8, | 48 | name: []const u8, |
| 49 | ) *std.Build.Step.Compile { | 49 | ) *std.Build.Step.Compile { |
| 50 | const exe = b.addExecutable(.{ | 50 | const exe = b.addExecutable(.{ |
test/link/macho/dead_strip_dylibs/build.zig+1| ... | @@ -52,6 +52,7 @@ fn createScenario( | ... | @@ -52,6 +52,7 @@ fn createScenario( |
| 52 | const exe = b.addExecutable(.{ | 52 | const exe = b.addExecutable(.{ |
| 53 | .name = name, | 53 | .name = name, |
| 54 | .optimize = optimize, | 54 | .optimize = optimize, |
| 55 | .target = b.host, | ||
| 55 | }); | 56 | }); |
| 56 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); | 57 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); |
| 57 | exe.linkLibC(); | 58 | exe.linkLibC(); |
test/link/macho/dylib/build.zig+2-2| ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 17 | 17 | ||
| 18 | const dylib = b.addSharedLibrary(.{ | 18 | const dylib = b.addSharedLibrary(.{ |
| 19 | .name = "a", | 19 | .name = "a", |
| ... | @@ -55,7 +55,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -55,7 +55,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 55 | 55 | ||
| 56 | check_exe.checkInHeaders(); | 56 | check_exe.checkInHeaders(); |
| 57 | check_exe.checkExact("cmd RPATH"); | 57 | check_exe.checkExact("cmd RPATH"); |
| 58 | check_exe.checkExactPath("path", dylib.getOutputDirectorySource()); | 58 | check_exe.checkExactPath("path", dylib.getEmittedBinDirectory()); |
| 59 | test_step.dependOn(&check_exe.step); | 59 | test_step.dependOn(&check_exe.step); |
| 60 | 60 | ||
| 61 | const run = b.addRunArtifact(exe); | 61 | const run = b.addRunArtifact(exe); |
test/link/macho/empty/build.zig+1-1| ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 17 | 17 | ||
| 18 | const exe = b.addExecutable(.{ | 18 | const exe = b.addExecutable(.{ |
| 19 | .name = "test", | 19 | .name = "test", |
test/link/macho/entry/build.zig+1-1| ... | @@ -16,7 +16,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -16,7 +16,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 16 | const exe = b.addExecutable(.{ | 16 | const exe = b.addExecutable(.{ |
| 17 | .name = "main", | 17 | .name = "main", |
| 18 | .optimize = optimize, | 18 | .optimize = optimize, |
| 19 | .target = .{ .os_tag = .macos }, | 19 | .target = b.resolveTargetQuery(.{ .os_tag = .macos }), |
| 20 | }); | 20 | }); |
| 21 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); | 21 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); |
| 22 | exe.linkLibC(); | 22 | exe.linkLibC(); |
test/link/macho/entry_in_archive/build.zig+2-2| ... | @@ -16,7 +16,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -16,7 +16,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 16 | const lib = b.addStaticLibrary(.{ | 16 | const lib = b.addStaticLibrary(.{ |
| 17 | .name = "main", | 17 | .name = "main", |
| 18 | .optimize = optimize, | 18 | .optimize = optimize, |
| 19 | .target = .{ .os_tag = .macos }, | 19 | .target = b.resolveTargetQuery(.{ .os_tag = .macos }), |
| 20 | }); | 20 | }); |
| 21 | lib.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); | 21 | lib.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); |
| 22 | lib.linkLibC(); | 22 | lib.linkLibC(); |
| ... | @@ -24,7 +24,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -24,7 +24,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 24 | const exe = b.addExecutable(.{ | 24 | const exe = b.addExecutable(.{ |
| 25 | .name = "main", | 25 | .name = "main", |
| 26 | .optimize = optimize, | 26 | .optimize = optimize, |
| 27 | .target = .{ .os_tag = .macos }, | 27 | .target = b.resolveTargetQuery(.{ .os_tag = .macos }), |
| 28 | }); | 28 | }); |
| 29 | exe.linkLibrary(lib); | 29 | exe.linkLibrary(lib); |
| 30 | exe.linkLibC(); | 30 | exe.linkLibC(); |
test/link/macho/entry_in_dylib/build.zig+2-2| ... | @@ -16,7 +16,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -16,7 +16,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 16 | const lib = b.addSharedLibrary(.{ | 16 | const lib = b.addSharedLibrary(.{ |
| 17 | .name = "bootstrap", | 17 | .name = "bootstrap", |
| 18 | .optimize = optimize, | 18 | .optimize = optimize, |
| 19 | .target = .{ .os_tag = .macos }, | 19 | .target = b.resolveTargetQuery(.{ .os_tag = .macos }), |
| 20 | }); | 20 | }); |
| 21 | lib.addCSourceFile(.{ .file = .{ .path = "bootstrap.c" }, .flags = &.{} }); | 21 | lib.addCSourceFile(.{ .file = .{ .path = "bootstrap.c" }, .flags = &.{} }); |
| 22 | lib.linkLibC(); | 22 | lib.linkLibC(); |
| ... | @@ -25,7 +25,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -25,7 +25,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 25 | const exe = b.addExecutable(.{ | 25 | const exe = b.addExecutable(.{ |
| 26 | .name = "main", | 26 | .name = "main", |
| 27 | .optimize = optimize, | 27 | .optimize = optimize, |
| 28 | .target = .{ .os_tag = .macos }, | 28 | .target = b.resolveTargetQuery(.{ .os_tag = .macos }), |
| 29 | }); | 29 | }); |
| 30 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); | 30 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); |
| 31 | exe.linkLibrary(lib); | 31 | exe.linkLibrary(lib); |
test/link/macho/headerpad/build.zig+1| ... | @@ -112,6 +112,7 @@ fn simpleExe( | ... | @@ -112,6 +112,7 @@ fn simpleExe( |
| 112 | const exe = b.addExecutable(.{ | 112 | const exe = b.addExecutable(.{ |
| 113 | .name = name, | 113 | .name = name, |
| 114 | .optimize = optimize, | 114 | .optimize = optimize, |
| 115 | .target = b.host, | ||
| 115 | }); | 116 | }); |
| 116 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); | 117 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); |
| 117 | exe.linkLibC(); | 118 | exe.linkLibC(); |
test/link/macho/linksection/build.zig+1-1| ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target = std.zig.CrossTarget{ .os_tag = .macos }; | 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 17 | 17 | ||
| 18 | const obj = b.addObject(.{ | 18 | const obj = b.addObject(.{ |
| 19 | .name = "test", | 19 | .name = "test", |
test/link/macho/needed_framework/build.zig+1| ... | @@ -19,6 +19,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -19,6 +19,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 19 | const exe = b.addExecutable(.{ | 19 | const exe = b.addExecutable(.{ |
| 20 | .name = "test", | 20 | .name = "test", |
| 21 | .optimize = optimize, | 21 | .optimize = optimize, |
| 22 | .target = b.host, | ||
| 22 | }); | 23 | }); |
| 23 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); | 24 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); |
| 24 | exe.linkLibC(); | 25 | exe.linkLibC(); |
test/link/macho/needed_library/build.zig+2-2| ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 17 | 17 | ||
| 18 | const dylib = b.addSharedLibrary(.{ | 18 | const dylib = b.addSharedLibrary(.{ |
| 19 | .name = "a", | 19 | .name = "a", |
| ... | @@ -33,7 +33,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -33,7 +33,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 33 | }); | 33 | }); |
| 34 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); | 34 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); |
| 35 | exe.linkLibC(); | 35 | exe.linkLibC(); |
| 36 | exe.linkSystemLibraryNeeded("a"); | 36 | exe.root_module.linkSystemLibrary("a", .{ .needed = true }); |
| 37 | exe.addLibraryPath(dylib.getEmittedBinDirectory()); | 37 | exe.addLibraryPath(dylib.getEmittedBinDirectory()); |
| 38 | exe.addRPath(dylib.getEmittedBinDirectory()); | 38 | exe.addRPath(dylib.getEmittedBinDirectory()); |
| 39 | exe.dead_strip_dylibs = true; | 39 | exe.dead_strip_dylibs = true; |
test/link/macho/objc/build.zig+1| ... | @@ -17,6 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -17,6 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 17 | const exe = b.addExecutable(.{ | 17 | const exe = b.addExecutable(.{ |
| 18 | .name = "test", | 18 | .name = "test", |
| 19 | .optimize = optimize, | 19 | .optimize = optimize, |
| 20 | .target = b.host, | ||
| 20 | }); | 21 | }); |
| 21 | exe.addIncludePath(.{ .path = "." }); | 22 | exe.addIncludePath(.{ .path = "." }); |
| 22 | exe.addCSourceFile(.{ .file = .{ .path = "Foo.m" }, .flags = &[0][]const u8{} }); | 23 | exe.addCSourceFile(.{ .file = .{ .path = "Foo.m" }, .flags = &[0][]const u8{} }); |
test/link/macho/objcpp/build.zig+1| ... | @@ -17,6 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -17,6 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 17 | const exe = b.addExecutable(.{ | 17 | const exe = b.addExecutable(.{ |
| 18 | .name = "test", | 18 | .name = "test", |
| 19 | .optimize = optimize, | 19 | .optimize = optimize, |
| 20 | .target = b.host, | ||
| 20 | }); | 21 | }); |
| 21 | b.default_step.dependOn(&exe.step); | 22 | b.default_step.dependOn(&exe.step); |
| 22 | exe.addIncludePath(.{ .path = "." }); | 23 | exe.addIncludePath(.{ .path = "." }); |
test/link/macho/pagezero/build.zig+1-1| ... | @@ -7,7 +7,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -7,7 +7,7 @@ pub fn build(b: *std.Build) void { |
| 7 | b.default_step = test_step; | 7 | b.default_step = test_step; |
| 8 | 8 | ||
| 9 | const optimize: std.builtin.OptimizeMode = .Debug; | 9 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 10 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 10 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 11 | 11 | ||
| 12 | { | 12 | { |
| 13 | const exe = b.addExecutable(.{ | 13 | const exe = b.addExecutable(.{ |
test/link/macho/reexports/build.zig+1-1| ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 17 | 17 | ||
| 18 | const lib = b.addStaticLibrary(.{ | 18 | const lib = b.addStaticLibrary(.{ |
| 19 | .name = "a", | 19 | .name = "a", |
test/link/macho/search_strategy/build.zig+3-3| ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 17 | 17 | ||
| 18 | { | 18 | { |
| 19 | // -search_dylibs_first | 19 | // -search_dylibs_first |
| ... | @@ -45,9 +45,9 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -45,9 +45,9 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 45 | fn createScenario( | 45 | fn createScenario( |
| 46 | b: *std.Build, | 46 | b: *std.Build, |
| 47 | optimize: std.builtin.OptimizeMode, | 47 | optimize: std.builtin.OptimizeMode, |
| 48 | target: std.zig.CrossTarget, | 48 | target: std.Build.ResolvedTarget, |
| 49 | name: []const u8, | 49 | name: []const u8, |
| 50 | search_strategy: std.Build.Step.Compile.SystemLib.SearchStrategy, | 50 | search_strategy: std.Build.Module.SystemLib.SearchStrategy, |
| 51 | ) *std.Build.Step.Compile { | 51 | ) *std.Build.Step.Compile { |
| 52 | const static = b.addStaticLibrary(.{ | 52 | const static = b.addStaticLibrary(.{ |
| 53 | .name = name, | 53 | .name = name, |
test/link/macho/stack_size/build.zig+1-1| ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 17 | 17 | ||
| 18 | const exe = b.addExecutable(.{ | 18 | const exe = b.addExecutable(.{ |
| 19 | .name = "main", | 19 | .name = "main", |
test/link/macho/strict_validation/build.zig+1-1| ... | @@ -14,7 +14,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -14,7 +14,7 @@ pub fn build(b: *std.Build) void { |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 16 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 17 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 17 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 18 | 18 | ||
| 19 | const exe = b.addExecutable(.{ | 19 | const exe = b.addExecutable(.{ |
| 20 | .name = "main", | 20 | .name = "main", |
test/link/macho/tbdv3/build.zig+1-1| ... | @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 17 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 18 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 18 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 19 | 19 | ||
| 20 | const lib = b.addSharedLibrary(.{ | 20 | const lib = b.addSharedLibrary(.{ |
| 21 | .name = "a", | 21 | .name = "a", |
test/link/macho/tls/build.zig+1-1| ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 17 | 17 | ||
| 18 | const lib = b.addSharedLibrary(.{ | 18 | const lib = b.addSharedLibrary(.{ |
| 19 | .name = "a", | 19 | .name = "a", |
test/link/macho/unwind_info/build.zig+3-3| ... | @@ -14,7 +14,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -14,7 +14,7 @@ pub fn build(b: *std.Build) void { |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 16 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 17 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 17 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 18 | 18 | ||
| 19 | testUnwindInfo(b, test_step, optimize, target, false, "no-dead-strip"); | 19 | testUnwindInfo(b, test_step, optimize, target, false, "no-dead-strip"); |
| 20 | testUnwindInfo(b, test_step, optimize, target, true, "yes-dead-strip"); | 20 | testUnwindInfo(b, test_step, optimize, target, true, "yes-dead-strip"); |
| ... | @@ -24,7 +24,7 @@ fn testUnwindInfo( | ... | @@ -24,7 +24,7 @@ fn testUnwindInfo( |
| 24 | b: *std.Build, | 24 | b: *std.Build, |
| 25 | test_step: *std.Build.Step, | 25 | test_step: *std.Build.Step, |
| 26 | optimize: std.builtin.OptimizeMode, | 26 | optimize: std.builtin.OptimizeMode, |
| 27 | target: std.zig.CrossTarget, | 27 | target: std.Build.ResolvedTarget, |
| 28 | dead_strip: bool, | 28 | dead_strip: bool, |
| 29 | name: []const u8, | 29 | name: []const u8, |
| 30 | ) void { | 30 | ) void { |
| ... | @@ -66,7 +66,7 @@ fn testUnwindInfo( | ... | @@ -66,7 +66,7 @@ fn testUnwindInfo( |
| 66 | fn createScenario( | 66 | fn createScenario( |
| 67 | b: *std.Build, | 67 | b: *std.Build, |
| 68 | optimize: std.builtin.OptimizeMode, | 68 | optimize: std.builtin.OptimizeMode, |
| 69 | target: std.zig.CrossTarget, | 69 | target: std.Build.ResolvedTarget, |
| 70 | name: []const u8, | 70 | name: []const u8, |
| 71 | ) *std.Build.Step.Compile { | 71 | ) *std.Build.Step.Compile { |
| 72 | const exe = b.addExecutable(.{ | 72 | const exe = b.addExecutable(.{ |
test/link/macho/weak_framework/build.zig+1| ... | @@ -17,6 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -17,6 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 17 | const exe = b.addExecutable(.{ | 17 | const exe = b.addExecutable(.{ |
| 18 | .name = "test", | 18 | .name = "test", |
| 19 | .optimize = optimize, | 19 | .optimize = optimize, |
| 20 | .target = b.host, | ||
| 20 | }); | 21 | }); |
| 21 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); | 22 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); |
| 22 | exe.linkLibC(); | 23 | exe.linkLibC(); |
test/link/macho/weak_library/build.zig+2-2| ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; | 16 | const target = b.resolveTargetQuery(.{ .os_tag = .macos }); |
| 17 | 17 | ||
| 18 | const dylib = b.addSharedLibrary(.{ | 18 | const dylib = b.addSharedLibrary(.{ |
| 19 | .name = "a", | 19 | .name = "a", |
| ... | @@ -32,7 +32,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -32,7 +32,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 32 | }); | 32 | }); |
| 33 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); | 33 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); |
| 34 | exe.linkLibC(); | 34 | exe.linkLibC(); |
| 35 | exe.linkSystemLibraryWeak("a"); | 35 | exe.root_module.linkSystemLibrary("a", .{ .weak = true }); |
| 36 | exe.addLibraryPath(dylib.getEmittedBinDirectory()); | 36 | exe.addLibraryPath(dylib.getEmittedBinDirectory()); |
| 37 | exe.addRPath(dylib.getEmittedBinDirectory()); | 37 | exe.addRPath(dylib.getEmittedBinDirectory()); |
| 38 | 38 |
test/link/static_libs_from_object_files/build.zig+8-6| ... | @@ -59,7 +59,7 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built | ... | @@ -59,7 +59,7 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 59 | .name = "test1", | 59 | .name = "test1", |
| 60 | .root_source_file = .{ .path = "main.zig" }, | 60 | .root_source_file = .{ .path = "main.zig" }, |
| 61 | .optimize = optimize, | 61 | .optimize = optimize, |
| 62 | .target = .{}, | 62 | .target = b.host, |
| 63 | }); | 63 | }); |
| 64 | 64 | ||
| 65 | for (files) |file| { | 65 | for (files) |file| { |
| ... | @@ -77,12 +77,12 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built | ... | @@ -77,12 +77,12 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 77 | { | 77 | { |
| 78 | const lib_a = b.addStaticLibrary(.{ | 78 | const lib_a = b.addStaticLibrary(.{ |
| 79 | .name = "test2_a", | 79 | .name = "test2_a", |
| 80 | .target = .{}, | 80 | .target = b.host, |
| 81 | .optimize = optimize, | 81 | .optimize = optimize, |
| 82 | }); | 82 | }); |
| 83 | const lib_b = b.addStaticLibrary(.{ | 83 | const lib_b = b.addStaticLibrary(.{ |
| 84 | .name = "test2_b", | 84 | .name = "test2_b", |
| 85 | .target = .{}, | 85 | .target = b.host, |
| 86 | .optimize = optimize, | 86 | .optimize = optimize, |
| 87 | }); | 87 | }); |
| 88 | 88 | ||
| ... | @@ -94,6 +94,7 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built | ... | @@ -94,6 +94,7 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 94 | const exe = b.addExecutable(.{ | 94 | const exe = b.addExecutable(.{ |
| 95 | .name = "test2", | 95 | .name = "test2", |
| 96 | .root_source_file = .{ .path = "main.zig" }, | 96 | .root_source_file = .{ .path = "main.zig" }, |
| 97 | .target = b.host, | ||
| 97 | .optimize = optimize, | 98 | .optimize = optimize, |
| 98 | }); | 99 | }); |
| 99 | exe.linkLibrary(lib_a); | 100 | exe.linkLibrary(lib_a); |
| ... | @@ -110,19 +111,19 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built | ... | @@ -110,19 +111,19 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 110 | { | 111 | { |
| 111 | const lib_a = b.addStaticLibrary(.{ | 112 | const lib_a = b.addStaticLibrary(.{ |
| 112 | .name = "test3_a", | 113 | .name = "test3_a", |
| 113 | .target = .{}, | 114 | .target = b.host, |
| 114 | .optimize = optimize, | 115 | .optimize = optimize, |
| 115 | }); | 116 | }); |
| 116 | const lib_b = b.addStaticLibrary(.{ | 117 | const lib_b = b.addStaticLibrary(.{ |
| 117 | .name = "test3_b", | 118 | .name = "test3_b", |
| 118 | .target = .{}, | 119 | .target = b.host, |
| 119 | .optimize = optimize, | 120 | .optimize = optimize, |
| 120 | }); | 121 | }); |
| 121 | 122 | ||
| 122 | for (files, 1..) |file, i| { | 123 | for (files, 1..) |file, i| { |
| 123 | const obj = b.addObject(.{ | 124 | const obj = b.addObject(.{ |
| 124 | .name = b.fmt("obj_{}", .{i}), | 125 | .name = b.fmt("obj_{}", .{i}), |
| 125 | .target = .{}, | 126 | .target = b.host, |
| 126 | .optimize = optimize, | 127 | .optimize = optimize, |
| 127 | }); | 128 | }); |
| 128 | obj.addCSourceFile(.{ .file = file, .flags = &flags }); | 129 | obj.addCSourceFile(.{ .file = file, .flags = &flags }); |
| ... | @@ -134,6 +135,7 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built | ... | @@ -134,6 +135,7 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 134 | const exe = b.addExecutable(.{ | 135 | const exe = b.addExecutable(.{ |
| 135 | .name = "test3", | 136 | .name = "test3", |
| 136 | .root_source_file = .{ .path = "main.zig" }, | 137 | .root_source_file = .{ .path = "main.zig" }, |
| 138 | .target = b.host, | ||
| 137 | .optimize = optimize, | 139 | .optimize = optimize, |
| 138 | }); | 140 | }); |
| 139 | exe.linkLibrary(lib_a); | 141 | exe.linkLibrary(lib_a); |
test/link/wasm/archive/build.zig+1-1| ... | @@ -20,11 +20,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -20,11 +20,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 20 | .root_source_file = .{ .path = "main.zig" }, | 20 | .root_source_file = .{ .path = "main.zig" }, |
| 21 | .optimize = optimize, | 21 | .optimize = optimize, |
| 22 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | 22 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, |
| 23 | .strip = false, | ||
| 23 | }); | 24 | }); |
| 24 | lib.entry = .disabled; | 25 | lib.entry = .disabled; |
| 25 | lib.use_llvm = false; | 26 | lib.use_llvm = false; |
| 26 | lib.use_lld = false; | 27 | lib.use_lld = false; |
| 27 | lib.strip = false; | ||
| 28 | 28 | ||
| 29 | const check = lib.checkObject(); | 29 | const check = lib.checkObject(); |
| 30 | check.checkInHeaders(); | 30 | check.checkInHeaders(); |
test/link/wasm/basic-features/build.zig+2-2| ... | @@ -8,12 +8,12 @@ pub fn build(b: *std.Build) void { | ... | @@ -8,12 +8,12 @@ pub fn build(b: *std.Build) void { |
| 8 | .name = "lib", | 8 | .name = "lib", |
| 9 | .root_source_file = .{ .path = "main.zig" }, | 9 | .root_source_file = .{ .path = "main.zig" }, |
| 10 | .optimize = .Debug, | 10 | .optimize = .Debug, |
| 11 | .target = .{ | 11 | .target = b.resolveTargetQuery(.{ |
| 12 | .cpu_arch = .wasm32, | 12 | .cpu_arch = .wasm32, |
| 13 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | 13 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, |
| 14 | .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}), | 14 | .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}), |
| 15 | .os_tag = .freestanding, | 15 | .os_tag = .freestanding, |
| 16 | }, | 16 | }), |
| 17 | }); | 17 | }); |
| 18 | lib.entry = .disabled; | 18 | lib.entry = .disabled; |
| 19 | lib.use_llvm = false; | 19 | lib.use_llvm = false; |
test/link/wasm/bss/build.zig+4-4| ... | @@ -17,13 +17,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt | ... | @@ -17,13 +17,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt |
| 17 | const lib = b.addExecutable(.{ | 17 | const lib = b.addExecutable(.{ |
| 18 | .name = "lib", | 18 | .name = "lib", |
| 19 | .root_source_file = .{ .path = "lib.zig" }, | 19 | .root_source_file = .{ .path = "lib.zig" }, |
| 20 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 21 | .optimize = optimize_mode, | 21 | .optimize = optimize_mode, |
| 22 | .strip = false, | ||
| 22 | }); | 23 | }); |
| 23 | lib.entry = .disabled; | 24 | lib.entry = .disabled; |
| 24 | lib.use_llvm = false; | 25 | lib.use_llvm = false; |
| 25 | lib.use_lld = false; | 26 | lib.use_lld = false; |
| 26 | lib.strip = false; | ||
| 27 | // to make sure the bss segment is emitted, we must import memory | 27 | // to make sure the bss segment is emitted, we must import memory |
| 28 | lib.import_memory = true; | 28 | lib.import_memory = true; |
| 29 | lib.link_gc_sections = false; | 29 | lib.link_gc_sections = false; |
| ... | @@ -65,13 +65,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt | ... | @@ -65,13 +65,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt |
| 65 | const lib = b.addExecutable(.{ | 65 | const lib = b.addExecutable(.{ |
| 66 | .name = "lib", | 66 | .name = "lib", |
| 67 | .root_source_file = .{ .path = "lib2.zig" }, | 67 | .root_source_file = .{ .path = "lib2.zig" }, |
| 68 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | 68 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 69 | .optimize = optimize_mode, | 69 | .optimize = optimize_mode, |
| 70 | .strip = false, | ||
| 70 | }); | 71 | }); |
| 71 | lib.entry = .disabled; | 72 | lib.entry = .disabled; |
| 72 | lib.use_llvm = false; | 73 | lib.use_llvm = false; |
| 73 | lib.use_lld = false; | 74 | lib.use_lld = false; |
| 74 | lib.strip = false; | ||
| 75 | // to make sure the bss segment is emitted, we must import memory | 75 | // to make sure the bss segment is emitted, we must import memory |
| 76 | lib.import_memory = true; | 76 | lib.import_memory = true; |
| 77 | lib.link_gc_sections = false; | 77 | lib.link_gc_sections = false; |
test/link/wasm/export-data/build.zig+1-1| ... | @@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void { |
| 17 | }); | 17 | }); |
| 18 | lib.entry = .disabled; | 18 | lib.entry = .disabled; |
| 19 | lib.use_lld = false; | 19 | lib.use_lld = false; |
| 20 | lib.export_symbol_names = &.{ "foo", "bar" }; | 20 | lib.root_module.export_symbol_names = &.{ "foo", "bar" }; |
| 21 | lib.global_base = 0; // put data section at address 0 to make data symbols easier to parse | 21 | lib.global_base = 0; // put data section at address 0 to make data symbols easier to parse |
| 22 | 22 | ||
| 23 | const check_lib = lib.checkObject(); | 23 | const check_lib = lib.checkObject(); |
test/link/wasm/export/build.zig+4-4| ... | @@ -17,7 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -17,7 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 17 | .name = "no-export", | 17 | .name = "no-export", |
| 18 | .root_source_file = .{ .path = "main.zig" }, | 18 | .root_source_file = .{ .path = "main.zig" }, |
| 19 | .optimize = optimize, | 19 | .optimize = optimize, |
| 20 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 21 | }); | 21 | }); |
| 22 | no_export.entry = .disabled; | 22 | no_export.entry = .disabled; |
| 23 | no_export.use_llvm = false; | 23 | no_export.use_llvm = false; |
| ... | @@ -27,7 +27,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -27,7 +27,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 27 | .name = "dynamic", | 27 | .name = "dynamic", |
| 28 | .root_source_file = .{ .path = "main.zig" }, | 28 | .root_source_file = .{ .path = "main.zig" }, |
| 29 | .optimize = optimize, | 29 | .optimize = optimize, |
| 30 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | 30 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 31 | }); | 31 | }); |
| 32 | dynamic_export.entry = .disabled; | 32 | dynamic_export.entry = .disabled; |
| 33 | dynamic_export.rdynamic = true; | 33 | dynamic_export.rdynamic = true; |
| ... | @@ -38,10 +38,10 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -38,10 +38,10 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 38 | .name = "force", | 38 | .name = "force", |
| 39 | .root_source_file = .{ .path = "main.zig" }, | 39 | .root_source_file = .{ .path = "main.zig" }, |
| 40 | .optimize = optimize, | 40 | .optimize = optimize, |
| 41 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | 41 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 42 | }); | 42 | }); |
| 43 | force_export.entry = .disabled; | 43 | force_export.entry = .disabled; |
| 44 | force_export.export_symbol_names = &.{"foo"}; | 44 | force_export.root_module.export_symbol_names = &.{"foo"}; |
| 45 | force_export.use_llvm = false; | 45 | force_export.use_llvm = false; |
| 46 | force_export.use_lld = false; | 46 | force_export.use_lld = false; |
| 47 | 47 |
test/link/wasm/extern-mangle/build.zig+1-1| ... | @@ -14,7 +14,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -14,7 +14,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 14 | const lib = b.addExecutable(.{ | 14 | const lib = b.addExecutable(.{ |
| 15 | .name = "lib", | 15 | .name = "lib", |
| 16 | .root_source_file = .{ .path = "lib.zig" }, | 16 | .root_source_file = .{ .path = "lib.zig" }, |
| 17 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | 17 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 18 | .optimize = optimize, | 18 | .optimize = optimize, |
| 19 | }); | 19 | }); |
| 20 | lib.entry = .disabled; | 20 | lib.entry = .disabled; |
test/link/wasm/extern/build.zig+1-1| ... | @@ -17,7 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -17,7 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 17 | .name = "extern", | 17 | .name = "extern", |
| 18 | .root_source_file = .{ .path = "main.zig" }, | 18 | .root_source_file = .{ .path = "main.zig" }, |
| 19 | .optimize = optimize, | 19 | .optimize = optimize, |
| 20 | .target = .{ .cpu_arch = .wasm32, .os_tag = .wasi }, | 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }), |
| 21 | }); | 21 | }); |
| 22 | exe.addCSourceFile(.{ .file = .{ .path = "foo.c" }, .flags = &.{} }); | 22 | exe.addCSourceFile(.{ .file = .{ .path = "foo.c" }, .flags = &.{} }); |
| 23 | exe.use_llvm = false; | 23 | exe.use_llvm = false; |
test/link/wasm/function-table/build.zig+3-3| ... | @@ -16,7 +16,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -16,7 +16,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 16 | const import_table = b.addExecutable(.{ | 16 | const import_table = b.addExecutable(.{ |
| 17 | .name = "import_table", | 17 | .name = "import_table", |
| 18 | .root_source_file = .{ .path = "lib.zig" }, | 18 | .root_source_file = .{ .path = "lib.zig" }, |
| 19 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 20 | .optimize = optimize, | 20 | .optimize = optimize, |
| 21 | }); | 21 | }); |
| 22 | import_table.entry = .disabled; | 22 | import_table.entry = .disabled; |
| ... | @@ -28,7 +28,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -28,7 +28,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 28 | const export_table = b.addExecutable(.{ | 28 | const export_table = b.addExecutable(.{ |
| 29 | .name = "export_table", | 29 | .name = "export_table", |
| 30 | .root_source_file = .{ .path = "lib.zig" }, | 30 | .root_source_file = .{ .path = "lib.zig" }, |
| 31 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | 31 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 32 | .optimize = optimize, | 32 | .optimize = optimize, |
| 33 | }); | 33 | }); |
| 34 | export_table.entry = .disabled; | 34 | export_table.entry = .disabled; |
| ... | @@ -40,7 +40,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -40,7 +40,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 40 | const regular_table = b.addExecutable(.{ | 40 | const regular_table = b.addExecutable(.{ |
| 41 | .name = "regular_table", | 41 | .name = "regular_table", |
| 42 | .root_source_file = .{ .path = "lib.zig" }, | 42 | .root_source_file = .{ .path = "lib.zig" }, |
| 43 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | 43 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 44 | .optimize = optimize, | 44 | .optimize = optimize, |
| 45 | }); | 45 | }); |
| 46 | regular_table.entry = .disabled; | 46 | regular_table.entry = .disabled; |
test/link/wasm/infer-features/build.zig+4-4| ... | @@ -7,11 +7,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -7,11 +7,11 @@ pub fn build(b: *std.Build) void { |
| 7 | const c_obj = b.addObject(.{ | 7 | const c_obj = b.addObject(.{ |
| 8 | .name = "c_obj", | 8 | .name = "c_obj", |
| 9 | .optimize = .Debug, | 9 | .optimize = .Debug, |
| 10 | .target = .{ | 10 | .target = b.resolveTargetQuery(.{ |
| 11 | .cpu_arch = .wasm32, | 11 | .cpu_arch = .wasm32, |
| 12 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge }, | 12 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge }, |
| 13 | .os_tag = .freestanding, | 13 | .os_tag = .freestanding, |
| 14 | }, | 14 | }), |
| 15 | }); | 15 | }); |
| 16 | c_obj.addCSourceFile(.{ .file = .{ .path = "foo.c" }, .flags = &.{} }); | 16 | c_obj.addCSourceFile(.{ .file = .{ .path = "foo.c" }, .flags = &.{} }); |
| 17 | 17 | ||
| ... | @@ -21,11 +21,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -21,11 +21,11 @@ pub fn build(b: *std.Build) void { |
| 21 | .name = "lib", | 21 | .name = "lib", |
| 22 | .root_source_file = .{ .path = "main.zig" }, | 22 | .root_source_file = .{ .path = "main.zig" }, |
| 23 | .optimize = .Debug, | 23 | .optimize = .Debug, |
| 24 | .target = .{ | 24 | .target = b.resolveTargetQuery(.{ |
| 25 | .cpu_arch = .wasm32, | 25 | .cpu_arch = .wasm32, |
| 26 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | 26 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, |
| 27 | .os_tag = .freestanding, | 27 | .os_tag = .freestanding, |
| 28 | }, | 28 | }), |
| 29 | }); | 29 | }); |
| 30 | lib.entry = .disabled; | 30 | lib.entry = .disabled; |
| 31 | lib.use_llvm = false; | 31 | lib.use_llvm = false; |
test/link/wasm/producers/build.zig+2-2| ... | @@ -17,13 +17,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -17,13 +17,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 17 | const lib = b.addExecutable(.{ | 17 | const lib = b.addExecutable(.{ |
| 18 | .name = "lib", | 18 | .name = "lib", |
| 19 | .root_source_file = .{ .path = "lib.zig" }, | 19 | .root_source_file = .{ .path = "lib.zig" }, |
| 20 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 21 | .optimize = optimize, | 21 | .optimize = optimize, |
| 22 | .strip = false, | ||
| 22 | }); | 23 | }); |
| 23 | lib.entry = .disabled; | 24 | lib.entry = .disabled; |
| 24 | lib.use_llvm = false; | 25 | lib.use_llvm = false; |
| 25 | lib.use_lld = false; | 26 | lib.use_lld = false; |
| 26 | lib.strip = false; | ||
| 27 | b.installArtifact(lib); | 27 | b.installArtifact(lib); |
| 28 | 28 | ||
| 29 | const version_fmt = "version " ++ builtin.zig_version_string; | 29 | const version_fmt = "version " ++ builtin.zig_version_string; |
test/link/wasm/segments/build.zig+2-2| ... | @@ -16,13 +16,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -16,13 +16,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 16 | const lib = b.addExecutable(.{ | 16 | const lib = b.addExecutable(.{ |
| 17 | .name = "lib", | 17 | .name = "lib", |
| 18 | .root_source_file = .{ .path = "lib.zig" }, | 18 | .root_source_file = .{ .path = "lib.zig" }, |
| 19 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 20 | .optimize = optimize, | 20 | .optimize = optimize, |
| 21 | .strip = false, | ||
| 21 | }); | 22 | }); |
| 22 | lib.entry = .disabled; | 23 | lib.entry = .disabled; |
| 23 | lib.use_llvm = false; | 24 | lib.use_llvm = false; |
| 24 | lib.use_lld = false; | 25 | lib.use_lld = false; |
| 25 | lib.strip = false; | ||
| 26 | lib.link_gc_sections = false; // so data is not garbage collected and we can verify data section | 26 | lib.link_gc_sections = false; // so data is not garbage collected and we can verify data section |
| 27 | b.installArtifact(lib); | 27 | b.installArtifact(lib); |
| 28 | 28 |
test/link/wasm/shared-memory/build.zig+3-3| ... | @@ -21,16 +21,16 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt | ... | @@ -21,16 +21,16 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt |
| 21 | .os_tag = .freestanding, | 21 | .os_tag = .freestanding, |
| 22 | }, | 22 | }, |
| 23 | .optimize = optimize_mode, | 23 | .optimize = optimize_mode, |
| 24 | .strip = false, | ||
| 25 | .single_threaded = false, | ||
| 24 | }); | 26 | }); |
| 25 | lib.entry = .disabled; | 27 | lib.entry = .disabled; |
| 26 | lib.use_lld = false; | 28 | lib.use_lld = false; |
| 27 | lib.strip = false; | ||
| 28 | lib.import_memory = true; | 29 | lib.import_memory = true; |
| 29 | lib.export_memory = true; | 30 | lib.export_memory = true; |
| 30 | lib.shared_memory = true; | 31 | lib.shared_memory = true; |
| 31 | lib.max_memory = 67108864; | 32 | lib.max_memory = 67108864; |
| 32 | lib.single_threaded = false; | 33 | lib.root_module.export_symbol_names = &.{"foo"}; |
| 33 | lib.export_symbol_names = &.{"foo"}; | ||
| 34 | 34 | ||
| 35 | const check_lib = lib.checkObject(); | 35 | const check_lib = lib.checkObject(); |
| 36 | 36 |
test/link/wasm/stack_pointer/build.zig+2-2| ... | @@ -16,13 +16,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -16,13 +16,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 16 | const lib = b.addExecutable(.{ | 16 | const lib = b.addExecutable(.{ |
| 17 | .name = "lib", | 17 | .name = "lib", |
| 18 | .root_source_file = .{ .path = "lib.zig" }, | 18 | .root_source_file = .{ .path = "lib.zig" }, |
| 19 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 20 | .optimize = optimize, | 20 | .optimize = optimize, |
| 21 | .strip = false, | ||
| 21 | }); | 22 | }); |
| 22 | lib.entry = .disabled; | 23 | lib.entry = .disabled; |
| 23 | lib.use_llvm = false; | 24 | lib.use_llvm = false; |
| 24 | lib.use_lld = false; | 25 | lib.use_lld = false; |
| 25 | lib.strip = false; | ||
| 26 | lib.stack_size = std.wasm.page_size * 2; // set an explicit stack size | 26 | lib.stack_size = std.wasm.page_size * 2; // set an explicit stack size |
| 27 | lib.link_gc_sections = false; | 27 | lib.link_gc_sections = false; |
| 28 | b.installArtifact(lib); | 28 | b.installArtifact(lib); |
test/link/wasm/type/build.zig+2-2| ... | @@ -16,13 +16,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -16,13 +16,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 16 | const lib = b.addExecutable(.{ | 16 | const lib = b.addExecutable(.{ |
| 17 | .name = "lib", | 17 | .name = "lib", |
| 18 | .root_source_file = .{ .path = "lib.zig" }, | 18 | .root_source_file = .{ .path = "lib.zig" }, |
| 19 | .target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding }, | 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 20 | .optimize = optimize, | 20 | .optimize = optimize, |
| 21 | .strip = false, | ||
| 21 | }); | 22 | }); |
| 22 | lib.entry = .disabled; | 23 | lib.entry = .disabled; |
| 23 | lib.use_llvm = false; | 24 | lib.use_llvm = false; |
| 24 | lib.use_lld = false; | 25 | lib.use_lld = false; |
| 25 | lib.strip = false; | ||
| 26 | b.installArtifact(lib); | 26 | b.installArtifact(lib); |
| 27 | 27 | ||
| 28 | const check_lib = lib.checkObject(); | 28 | const check_lib = lib.checkObject(); |
test/llvm_targets.zig+8-4| ... | @@ -127,17 +127,21 @@ const targets = [_]std.zig.CrossTarget{ | ... | @@ -127,17 +127,21 @@ const targets = [_]std.zig.CrossTarget{ |
| 127 | .{ .cpu_arch = .xtensa, .os_tag = .linux, .abi = .none }, | 127 | .{ .cpu_arch = .xtensa, .os_tag = .linux, .abi = .none }, |
| 128 | }; | 128 | }; |
| 129 | 129 | ||
| 130 | pub fn addCases(ctx: *Cases, build_options: @import("cases.zig").BuildOptions) !void { | 130 | pub fn addCases( |
| 131 | ctx: *Cases, | ||
| 132 | build_options: @import("cases.zig").BuildOptions, | ||
| 133 | b: *std.Build, | ||
| 134 | ) !void { | ||
| 131 | if (!build_options.enable_llvm) return; | 135 | if (!build_options.enable_llvm) return; |
| 132 | for (targets) |target| { | 136 | for (targets) |target_query| { |
| 133 | if (target.cpu_arch) |arch| switch (arch) { | 137 | if (target_query.cpu_arch) |arch| switch (arch) { |
| 134 | .m68k => if (!build_options.llvm_has_m68k) continue, | 138 | .m68k => if (!build_options.llvm_has_m68k) continue, |
| 135 | .csky => if (!build_options.llvm_has_csky) continue, | 139 | .csky => if (!build_options.llvm_has_csky) continue, |
| 136 | .arc => if (!build_options.llvm_has_arc) continue, | 140 | .arc => if (!build_options.llvm_has_arc) continue, |
| 137 | .xtensa => if (!build_options.llvm_has_xtensa) continue, | 141 | .xtensa => if (!build_options.llvm_has_xtensa) continue, |
| 138 | else => {}, | 142 | else => {}, |
| 139 | }; | 143 | }; |
| 140 | var case = ctx.noEmitUsingLlvmBackend("llvm_targets", target); | 144 | var case = ctx.noEmitUsingLlvmBackend("llvm_targets", b.resolveTargetQuery(target_query)); |
| 141 | case.addCompile(""); | 145 | case.addCompile(""); |
| 142 | } | 146 | } |
| 143 | } | 147 | } |
test/nvptx.zig+12-15| ... | @@ -1,9 +1,14 @@ | ... | @@ -1,9 +1,14 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const Cases = @import("src/Cases.zig"); | 2 | const Cases = @import("src/Cases.zig"); |
| 3 | 3 | ||
| 4 | pub fn addCases(ctx: *Cases) !void { | 4 | pub fn addCases(ctx: *Cases, b: *std.Build) !void { |
| 5 | const target = b.resolveTargetQuery(.{ | ||
| 6 | .cpu_arch = .nvptx64, | ||
| 7 | .os_tag = .cuda, | ||
| 8 | }); | ||
| 9 | |||
| 5 | { | 10 | { |
| 6 | var case = addPtx(ctx, "simple addition and subtraction"); | 11 | var case = addPtx(ctx, target, "simple addition and subtraction"); |
| 7 | 12 | ||
| 8 | case.addCompile( | 13 | case.addCompile( |
| 9 | \\fn add(a: i32, b: i32) i32 { | 14 | \\fn add(a: i32, b: i32) i32 { |
| ... | @@ -20,7 +25,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -20,7 +25,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 20 | } | 25 | } |
| 21 | 26 | ||
| 22 | { | 27 | { |
| 23 | var case = addPtx(ctx, "read special registers"); | 28 | var case = addPtx(ctx, target, "read special registers"); |
| 24 | 29 | ||
| 25 | case.addCompile( | 30 | case.addCompile( |
| 26 | \\fn threadIdX() u32 { | 31 | \\fn threadIdX() u32 { |
| ... | @@ -37,7 +42,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -37,7 +42,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 37 | } | 42 | } |
| 38 | 43 | ||
| 39 | { | 44 | { |
| 40 | var case = addPtx(ctx, "address spaces"); | 45 | var case = addPtx(ctx, target, "address spaces"); |
| 41 | 46 | ||
| 42 | case.addCompile( | 47 | case.addCompile( |
| 43 | \\var x: i32 addrspace(.global) = 0; | 48 | \\var x: i32 addrspace(.global) = 0; |
| ... | @@ -50,7 +55,7 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -50,7 +55,7 @@ pub fn addCases(ctx: *Cases) !void { |
| 50 | } | 55 | } |
| 51 | 56 | ||
| 52 | { | 57 | { |
| 53 | var case = addPtx(ctx, "reduce in shared mem"); | 58 | var case = addPtx(ctx, target, "reduce in shared mem"); |
| 54 | case.addCompile( | 59 | case.addCompile( |
| 55 | \\fn threadIdX() u32 { | 60 | \\fn threadIdX() u32 { |
| 56 | \\ return asm ("mov.u32 \t%[r], %tid.x;" | 61 | \\ return asm ("mov.u32 \t%[r], %tid.x;" |
| ... | @@ -82,18 +87,10 @@ pub fn addCases(ctx: *Cases) !void { | ... | @@ -82,18 +87,10 @@ pub fn addCases(ctx: *Cases) !void { |
| 82 | } | 87 | } |
| 83 | } | 88 | } |
| 84 | 89 | ||
| 85 | const nvptx_target = std.zig.CrossTarget{ | 90 | fn addPtx(ctx: *Cases, target: std.Build.ResolvedTarget, name: []const u8) *Cases.Case { |
| 86 | .cpu_arch = .nvptx64, | ||
| 87 | .os_tag = .cuda, | ||
| 88 | }; | ||
| 89 | |||
| 90 | pub fn addPtx( | ||
| 91 | ctx: *Cases, | ||
| 92 | name: []const u8, | ||
| 93 | ) *Cases.Case { | ||
| 94 | ctx.cases.append(.{ | 91 | ctx.cases.append(.{ |
| 95 | .name = name, | 92 | .name = name, |
| 96 | .target = nvptx_target, | 93 | .target = target, |
| 97 | .updates = std.ArrayList(Cases.Update).init(ctx.cases.allocator), | 94 | .updates = std.ArrayList(Cases.Update).init(ctx.cases.allocator), |
| 98 | .output_mode = .Obj, | 95 | .output_mode = .Obj, |
| 99 | .deps = std.ArrayList(Cases.DepModule).init(ctx.cases.allocator), | 96 | .deps = std.ArrayList(Cases.DepModule).init(ctx.cases.allocator), |
test/src/Cases.zig+60-49| ... | @@ -76,7 +76,7 @@ pub const Case = struct { | ... | @@ -76,7 +76,7 @@ pub const Case = struct { |
| 76 | name: []const u8, | 76 | name: []const u8, |
| 77 | /// The platform the test targets. For non-native platforms, an emulator | 77 | /// The platform the test targets. For non-native platforms, an emulator |
| 78 | /// such as QEMU is required for tests to complete. | 78 | /// such as QEMU is required for tests to complete. |
| 79 | target: CrossTarget, | 79 | target: std.Build.ResolvedTarget, |
| 80 | /// In order to be able to run e.g. Execution updates, this must be set | 80 | /// In order to be able to run e.g. Execution updates, this must be set |
| 81 | /// to Executable. | 81 | /// to Executable. |
| 82 | output_mode: std.builtin.OutputMode, | 82 | output_mode: std.builtin.OutputMode, |
| ... | @@ -155,7 +155,7 @@ pub const Translate = struct { | ... | @@ -155,7 +155,7 @@ pub const Translate = struct { |
| 155 | name: []const u8, | 155 | name: []const u8, |
| 156 | 156 | ||
| 157 | input: [:0]const u8, | 157 | input: [:0]const u8, |
| 158 | target: CrossTarget, | 158 | target: std.Build.ResolvedTarget, |
| 159 | link_libc: bool, | 159 | link_libc: bool, |
| 160 | c_frontend: CFrontend, | 160 | c_frontend: CFrontend, |
| 161 | kind: union(enum) { | 161 | kind: union(enum) { |
| ... | @@ -171,7 +171,7 @@ pub const Translate = struct { | ... | @@ -171,7 +171,7 @@ pub const Translate = struct { |
| 171 | pub fn addExe( | 171 | pub fn addExe( |
| 172 | ctx: *Cases, | 172 | ctx: *Cases, |
| 173 | name: []const u8, | 173 | name: []const u8, |
| 174 | target: CrossTarget, | 174 | target: std.Build.ResolvedTarget, |
| 175 | ) *Case { | 175 | ) *Case { |
| 176 | ctx.cases.append(Case{ | 176 | ctx.cases.append(Case{ |
| 177 | .name = name, | 177 | .name = name, |
| ... | @@ -184,16 +184,16 @@ pub fn addExe( | ... | @@ -184,16 +184,16 @@ pub fn addExe( |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | /// Adds a test case for Zig input, producing an executable | 186 | /// Adds a test case for Zig input, producing an executable |
| 187 | pub fn exe(ctx: *Cases, name: []const u8, target: CrossTarget) *Case { | 187 | pub fn exe(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Case { |
| 188 | return ctx.addExe(name, target); | 188 | return ctx.addExe(name, target); |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | pub fn exeFromCompiledC(ctx: *Cases, name: []const u8, target: CrossTarget) *Case { | 191 | pub fn exeFromCompiledC(ctx: *Cases, name: []const u8, target_query: std.zig.CrossTarget, b: *std.Build) *Case { |
| 192 | var target_adjusted = target; | 192 | var adjusted_query = target_query; |
| 193 | target_adjusted.ofmt = .c; | 193 | adjusted_query.ofmt = .c; |
| 194 | ctx.cases.append(Case{ | 194 | ctx.cases.append(Case{ |
| 195 | .name = name, | 195 | .name = name, |
| 196 | .target = target_adjusted, | 196 | .target = b.resolveTargetQuery(adjusted_query), |
| 197 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), | 197 | .updates = std.ArrayList(Update).init(ctx.cases.allocator), |
| 198 | .output_mode = .Exe, | 198 | .output_mode = .Exe, |
| 199 | .deps = std.ArrayList(DepModule).init(ctx.arena), | 199 | .deps = std.ArrayList(DepModule).init(ctx.arena), |
| ... | @@ -202,7 +202,7 @@ pub fn exeFromCompiledC(ctx: *Cases, name: []const u8, target: CrossTarget) *Cas | ... | @@ -202,7 +202,7 @@ pub fn exeFromCompiledC(ctx: *Cases, name: []const u8, target: CrossTarget) *Cas |
| 202 | return &ctx.cases.items[ctx.cases.items.len - 1]; | 202 | return &ctx.cases.items[ctx.cases.items.len - 1]; |
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | pub fn noEmitUsingLlvmBackend(ctx: *Cases, name: []const u8, target: CrossTarget) *Case { | 205 | pub fn noEmitUsingLlvmBackend(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Case { |
| 206 | ctx.cases.append(Case{ | 206 | ctx.cases.append(Case{ |
| 207 | .name = name, | 207 | .name = name, |
| 208 | .target = target, | 208 | .target = target, |
| ... | @@ -217,7 +217,7 @@ pub fn noEmitUsingLlvmBackend(ctx: *Cases, name: []const u8, target: CrossTarget | ... | @@ -217,7 +217,7 @@ pub fn noEmitUsingLlvmBackend(ctx: *Cases, name: []const u8, target: CrossTarget |
| 217 | 217 | ||
| 218 | /// Adds a test case that uses the LLVM backend to emit an executable. | 218 | /// Adds a test case that uses the LLVM backend to emit an executable. |
| 219 | /// Currently this implies linking libc, because only then we can generate a testable executable. | 219 | /// Currently this implies linking libc, because only then we can generate a testable executable. |
| 220 | pub fn exeUsingLlvmBackend(ctx: *Cases, name: []const u8, target: CrossTarget) *Case { | 220 | pub fn exeUsingLlvmBackend(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Case { |
| 221 | ctx.cases.append(Case{ | 221 | ctx.cases.append(Case{ |
| 222 | .name = name, | 222 | .name = name, |
| 223 | .target = target, | 223 | .target = target, |
| ... | @@ -233,7 +233,7 @@ pub fn exeUsingLlvmBackend(ctx: *Cases, name: []const u8, target: CrossTarget) * | ... | @@ -233,7 +233,7 @@ pub fn exeUsingLlvmBackend(ctx: *Cases, name: []const u8, target: CrossTarget) * |
| 233 | pub fn addObj( | 233 | pub fn addObj( |
| 234 | ctx: *Cases, | 234 | ctx: *Cases, |
| 235 | name: []const u8, | 235 | name: []const u8, |
| 236 | target: CrossTarget, | 236 | target: std.Build.ResolvedTarget, |
| 237 | ) *Case { | 237 | ) *Case { |
| 238 | ctx.cases.append(Case{ | 238 | ctx.cases.append(Case{ |
| 239 | .name = name, | 239 | .name = name, |
| ... | @@ -248,7 +248,7 @@ pub fn addObj( | ... | @@ -248,7 +248,7 @@ pub fn addObj( |
| 248 | pub fn addTest( | 248 | pub fn addTest( |
| 249 | ctx: *Cases, | 249 | ctx: *Cases, |
| 250 | name: []const u8, | 250 | name: []const u8, |
| 251 | target: CrossTarget, | 251 | target: std.Build.ResolvedTarget, |
| 252 | ) *Case { | 252 | ) *Case { |
| 253 | ctx.cases.append(Case{ | 253 | ctx.cases.append(Case{ |
| 254 | .name = name, | 254 | .name = name, |
| ... | @@ -262,17 +262,17 @@ pub fn addTest( | ... | @@ -262,17 +262,17 @@ pub fn addTest( |
| 262 | } | 262 | } |
| 263 | 263 | ||
| 264 | /// Adds a test case for Zig input, producing an object file. | 264 | /// Adds a test case for Zig input, producing an object file. |
| 265 | pub fn obj(ctx: *Cases, name: []const u8, target: CrossTarget) *Case { | 265 | pub fn obj(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Case { |
| 266 | return ctx.addObj(name, target); | 266 | return ctx.addObj(name, target); |
| 267 | } | 267 | } |
| 268 | 268 | ||
| 269 | /// Adds a test case for ZIR input, producing an object file. | 269 | /// Adds a test case for ZIR input, producing an object file. |
| 270 | pub fn objZIR(ctx: *Cases, name: []const u8, target: CrossTarget) *Case { | 270 | pub fn objZIR(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Case { |
| 271 | return ctx.addObj(name, target, .ZIR); | 271 | return ctx.addObj(name, target, .ZIR); |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | /// Adds a test case for Zig or ZIR input, producing C code. | 274 | /// Adds a test case for Zig or ZIR input, producing C code. |
| 275 | pub fn addC(ctx: *Cases, name: []const u8, target: CrossTarget) *Case { | 275 | pub fn addC(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Case { |
| 276 | var target_adjusted = target; | 276 | var target_adjusted = target; |
| 277 | target_adjusted.ofmt = std.Target.ObjectFormat.c; | 277 | target_adjusted.ofmt = std.Target.ObjectFormat.c; |
| 278 | ctx.cases.append(Case{ | 278 | ctx.cases.append(Case{ |
| ... | @@ -308,7 +308,7 @@ pub fn compareOutput( | ... | @@ -308,7 +308,7 @@ pub fn compareOutput( |
| 308 | pub fn addTransform( | 308 | pub fn addTransform( |
| 309 | ctx: *Cases, | 309 | ctx: *Cases, |
| 310 | name: []const u8, | 310 | name: []const u8, |
| 311 | target: CrossTarget, | 311 | target: std.Build.ResolvedTarget, |
| 312 | src: [:0]const u8, | 312 | src: [:0]const u8, |
| 313 | result: [:0]const u8, | 313 | result: [:0]const u8, |
| 314 | ) void { | 314 | ) void { |
| ... | @@ -320,7 +320,7 @@ pub fn addTransform( | ... | @@ -320,7 +320,7 @@ pub fn addTransform( |
| 320 | pub fn transform( | 320 | pub fn transform( |
| 321 | ctx: *Cases, | 321 | ctx: *Cases, |
| 322 | name: []const u8, | 322 | name: []const u8, |
| 323 | target: CrossTarget, | 323 | target: std.Build.ResolvedTarget, |
| 324 | src: [:0]const u8, | 324 | src: [:0]const u8, |
| 325 | result: [:0]const u8, | 325 | result: [:0]const u8, |
| 326 | ) void { | 326 | ) void { |
| ... | @@ -330,7 +330,7 @@ pub fn transform( | ... | @@ -330,7 +330,7 @@ pub fn transform( |
| 330 | pub fn addError( | 330 | pub fn addError( |
| 331 | ctx: *Cases, | 331 | ctx: *Cases, |
| 332 | name: []const u8, | 332 | name: []const u8, |
| 333 | target: CrossTarget, | 333 | target: std.Build.ResolvedTarget, |
| 334 | src: [:0]const u8, | 334 | src: [:0]const u8, |
| 335 | expected_errors: []const []const u8, | 335 | expected_errors: []const []const u8, |
| 336 | ) void { | 336 | ) void { |
| ... | @@ -343,7 +343,7 @@ pub fn addError( | ... | @@ -343,7 +343,7 @@ pub fn addError( |
| 343 | pub fn compileError( | 343 | pub fn compileError( |
| 344 | ctx: *Cases, | 344 | ctx: *Cases, |
| 345 | name: []const u8, | 345 | name: []const u8, |
| 346 | target: CrossTarget, | 346 | target: std.Build.ResolvedTarget, |
| 347 | src: [:0]const u8, | 347 | src: [:0]const u8, |
| 348 | expected_errors: []const []const u8, | 348 | expected_errors: []const []const u8, |
| 349 | ) void { | 349 | ) void { |
| ... | @@ -355,7 +355,7 @@ pub fn compileError( | ... | @@ -355,7 +355,7 @@ pub fn compileError( |
| 355 | pub fn addCompile( | 355 | pub fn addCompile( |
| 356 | ctx: *Cases, | 356 | ctx: *Cases, |
| 357 | name: []const u8, | 357 | name: []const u8, |
| 358 | target: CrossTarget, | 358 | target: std.Build.ResolvedTarget, |
| 359 | src: [:0]const u8, | 359 | src: [:0]const u8, |
| 360 | ) void { | 360 | ) void { |
| 361 | ctx.addObj(name, target).addCompile(src); | 361 | ctx.addObj(name, target).addCompile(src); |
| ... | @@ -368,9 +368,9 @@ pub fn addCompile( | ... | @@ -368,9 +368,9 @@ pub fn addCompile( |
| 368 | /// Each file should include a test manifest as a contiguous block of comments at | 368 | /// Each file should include a test manifest as a contiguous block of comments at |
| 369 | /// the end of the file. The first line should be the test type, followed by a set of | 369 | /// the end of the file. The first line should be the test type, followed by a set of |
| 370 | /// key-value config values, followed by a blank line, then the expected output. | 370 | /// key-value config values, followed by a blank line, then the expected output. |
| 371 | pub fn addFromDir(ctx: *Cases, dir: std.fs.Dir) void { | 371 | pub fn addFromDir(ctx: *Cases, dir: std.fs.Dir, b: *std.Build) void { |
| 372 | var current_file: []const u8 = "none"; | 372 | var current_file: []const u8 = "none"; |
| 373 | ctx.addFromDirInner(dir, &current_file) catch |err| { | 373 | ctx.addFromDirInner(dir, &current_file, b) catch |err| { |
| 374 | std.debug.panicExtra( | 374 | std.debug.panicExtra( |
| 375 | @errorReturnTrace(), | 375 | @errorReturnTrace(), |
| 376 | @returnAddress(), | 376 | @returnAddress(), |
| ... | @@ -386,6 +386,7 @@ fn addFromDirInner( | ... | @@ -386,6 +386,7 @@ fn addFromDirInner( |
| 386 | /// This is kept up to date with the currently being processed file so | 386 | /// This is kept up to date with the currently being processed file so |
| 387 | /// that if any errors occur the caller knows it happened during this file. | 387 | /// that if any errors occur the caller knows it happened during this file. |
| 388 | current_file: *[]const u8, | 388 | current_file: *[]const u8, |
| 389 | b: *std.Build, | ||
| 389 | ) !void { | 390 | ) !void { |
| 390 | var it = try iterable_dir.walk(ctx.arena); | 391 | var it = try iterable_dir.walk(ctx.arena); |
| 391 | var filenames = std.ArrayList([]const u8).init(ctx.arena); | 392 | var filenames = std.ArrayList([]const u8).init(ctx.arena); |
| ... | @@ -422,7 +423,7 @@ fn addFromDirInner( | ... | @@ -422,7 +423,7 @@ fn addFromDirInner( |
| 422 | var manifest = try TestManifest.parse(ctx.arena, src); | 423 | var manifest = try TestManifest.parse(ctx.arena, src); |
| 423 | 424 | ||
| 424 | const backends = try manifest.getConfigForKeyAlloc(ctx.arena, "backend", Backend); | 425 | const backends = try manifest.getConfigForKeyAlloc(ctx.arena, "backend", Backend); |
| 425 | const targets = try manifest.getConfigForKeyAlloc(ctx.arena, "target", CrossTarget); | 426 | const targets = try manifest.getConfigForKeyAlloc(ctx.arena, "target", std.zig.CrossTarget); |
| 426 | const c_frontends = try manifest.getConfigForKeyAlloc(ctx.arena, "c_frontend", CFrontend); | 427 | const c_frontends = try manifest.getConfigForKeyAlloc(ctx.arena, "c_frontend", CFrontend); |
| 427 | const is_test = try manifest.getConfigForKeyAssertSingle("is_test", bool); | 428 | const is_test = try manifest.getConfigForKeyAssertSingle("is_test", bool); |
| 428 | const link_libc = try manifest.getConfigForKeyAssertSingle("link_libc", bool); | 429 | const link_libc = try manifest.getConfigForKeyAssertSingle("link_libc", bool); |
| ... | @@ -430,12 +431,12 @@ fn addFromDirInner( | ... | @@ -430,12 +431,12 @@ fn addFromDirInner( |
| 430 | 431 | ||
| 431 | if (manifest.type == .translate_c) { | 432 | if (manifest.type == .translate_c) { |
| 432 | for (c_frontends) |c_frontend| { | 433 | for (c_frontends) |c_frontend| { |
| 433 | for (targets) |target| { | 434 | for (targets) |target_query| { |
| 434 | const output = try manifest.trailingLinesSplit(ctx.arena); | 435 | const output = try manifest.trailingLinesSplit(ctx.arena); |
| 435 | try ctx.translate.append(.{ | 436 | try ctx.translate.append(.{ |
| 436 | .name = std.fs.path.stem(filename), | 437 | .name = std.fs.path.stem(filename), |
| 437 | .c_frontend = c_frontend, | 438 | .c_frontend = c_frontend, |
| 438 | .target = target, | 439 | .target = b.resolveTargetQuery(target_query), |
| 439 | .link_libc = link_libc, | 440 | .link_libc = link_libc, |
| 440 | .input = src, | 441 | .input = src, |
| 441 | .kind = .{ .translate = output }, | 442 | .kind = .{ .translate = output }, |
| ... | @@ -446,12 +447,12 @@ fn addFromDirInner( | ... | @@ -446,12 +447,12 @@ fn addFromDirInner( |
| 446 | } | 447 | } |
| 447 | if (manifest.type == .run_translated_c) { | 448 | if (manifest.type == .run_translated_c) { |
| 448 | for (c_frontends) |c_frontend| { | 449 | for (c_frontends) |c_frontend| { |
| 449 | for (targets) |target| { | 450 | for (targets) |target_query| { |
| 450 | const output = try manifest.trailingSplit(ctx.arena); | 451 | const output = try manifest.trailingSplit(ctx.arena); |
| 451 | try ctx.translate.append(.{ | 452 | try ctx.translate.append(.{ |
| 452 | .name = std.fs.path.stem(filename), | 453 | .name = std.fs.path.stem(filename), |
| 453 | .c_frontend = c_frontend, | 454 | .c_frontend = c_frontend, |
| 454 | .target = target, | 455 | .target = b.resolveTargetQuery(target_query), |
| 455 | .link_libc = link_libc, | 456 | .link_libc = link_libc, |
| 456 | .input = src, | 457 | .input = src, |
| 457 | .kind = .{ .run = output }, | 458 | .kind = .{ .run = output }, |
| ... | @@ -464,16 +465,18 @@ fn addFromDirInner( | ... | @@ -464,16 +465,18 @@ fn addFromDirInner( |
| 464 | var cases = std.ArrayList(usize).init(ctx.arena); | 465 | var cases = std.ArrayList(usize).init(ctx.arena); |
| 465 | 466 | ||
| 466 | // Cross-product to get all possible test combinations | 467 | // Cross-product to get all possible test combinations |
| 467 | for (backends) |backend| { | 468 | for (targets) |target_query| { |
| 468 | for (targets) |target| { | 469 | const resolved_target = b.resolveTargetQuery(target_query); |
| 470 | const target = resolved_target.target; | ||
| 471 | for (backends) |backend| { | ||
| 469 | if (backend == .stage2 and | 472 | if (backend == .stage2 and |
| 470 | target.getCpuArch() != .wasm32 and target.getCpuArch() != .x86_64) | 473 | target.cpu.arch != .wasm32 and target.cpu.arch != .x86_64) |
| 471 | { | 474 | { |
| 472 | // Other backends don't support new liveness format | 475 | // Other backends don't support new liveness format |
| 473 | continue; | 476 | continue; |
| 474 | } | 477 | } |
| 475 | if (backend == .stage2 and target.getOsTag() == .macos and | 478 | if (backend == .stage2 and target.os.tag == .macos and |
| 476 | target.getCpuArch() == .x86_64 and builtin.cpu.arch == .aarch64) | 479 | target.cpu.arch == .x86_64 and builtin.cpu.arch == .aarch64) |
| 477 | { | 480 | { |
| 478 | // Rosetta has issues with ZLD | 481 | // Rosetta has issues with ZLD |
| 479 | continue; | 482 | continue; |
| ... | @@ -482,7 +485,7 @@ fn addFromDirInner( | ... | @@ -482,7 +485,7 @@ fn addFromDirInner( |
| 482 | const next = ctx.cases.items.len; | 485 | const next = ctx.cases.items.len; |
| 483 | try ctx.cases.append(.{ | 486 | try ctx.cases.append(.{ |
| 484 | .name = std.fs.path.stem(filename), | 487 | .name = std.fs.path.stem(filename), |
| 485 | .target = target, | 488 | .target = resolved_target, |
| 486 | .backend = backend, | 489 | .backend = backend, |
| 487 | .updates = std.ArrayList(Cases.Update).init(ctx.cases.allocator), | 490 | .updates = std.ArrayList(Cases.Update).init(ctx.cases.allocator), |
| 488 | .is_test = is_test, | 491 | .is_test = is_test, |
| ... | @@ -622,8 +625,8 @@ pub fn lowerToBuildSteps( | ... | @@ -622,8 +625,8 @@ pub fn lowerToBuildSteps( |
| 622 | } | 625 | } |
| 623 | 626 | ||
| 624 | for (case.deps.items) |dep| { | 627 | for (case.deps.items) |dep| { |
| 625 | artifact.addAnonymousModule(dep.name, .{ | 628 | artifact.root_module.addAnonymousImport(dep.name, .{ |
| 626 | .source_file = file_sources.get(dep.path).?, | 629 | .root_source_file = file_sources.get(dep.path).?, |
| 627 | }); | 630 | }); |
| 628 | } | 631 | } |
| 629 | 632 | ||
| ... | @@ -644,9 +647,8 @@ pub fn lowerToBuildSteps( | ... | @@ -644,9 +647,8 @@ pub fn lowerToBuildSteps( |
| 644 | parent_step.dependOn(&artifact.step); | 647 | parent_step.dependOn(&artifact.step); |
| 645 | }, | 648 | }, |
| 646 | .Execution => |expected_stdout| no_exec: { | 649 | .Execution => |expected_stdout| no_exec: { |
| 647 | const run = if (case.target.ofmt == .c) run_step: { | 650 | const run = if (case.target.target.ofmt == .c) run_step: { |
| 648 | const target_info = std.zig.system.NativeTargetInfo.detect(case.target) catch |err| | 651 | const target_info = case.target.toNativeTargetInfo(); |
| 649 | std.debug.panic("unable to detect target host: {s}\n", .{@errorName(err)}); | ||
| 650 | if (host.getExternalExecutor(&target_info, .{ .link_libc = true }) != .native) { | 652 | if (host.getExternalExecutor(&target_info, .{ .link_libc = true }) != .native) { |
| 651 | // We wouldn't be able to run the compiled C code. | 653 | // We wouldn't be able to run the compiled C code. |
| 652 | break :no_exec; | 654 | break :no_exec; |
| ... | @@ -666,7 +668,7 @@ pub fn lowerToBuildSteps( | ... | @@ -666,7 +668,7 @@ pub fn lowerToBuildSteps( |
| 666 | "--", | 668 | "--", |
| 667 | "-lc", | 669 | "-lc", |
| 668 | "-target", | 670 | "-target", |
| 669 | case.target.zigTriple(b.allocator) catch @panic("OOM"), | 671 | case.target.target.zigTriple(b.allocator) catch @panic("OOM"), |
| 670 | }); | 672 | }); |
| 671 | run_c.addArtifactArg(artifact); | 673 | run_c.addArtifactArg(artifact); |
| 672 | break :run_step run_c; | 674 | break :run_step run_c; |
| ... | @@ -692,8 +694,7 @@ pub fn lowerToBuildSteps( | ... | @@ -692,8 +694,7 @@ pub fn lowerToBuildSteps( |
| 692 | continue; // Pass test. | 694 | continue; // Pass test. |
| 693 | } | 695 | } |
| 694 | 696 | ||
| 695 | const target_info = std.zig.system.NativeTargetInfo.detect(case.target) catch |err| | 697 | const target_info = case.target.toNativeTargetInfo(); |
| 696 | std.debug.panic("unable to detect target host: {s}\n", .{@errorName(err)}); | ||
| 697 | if (host.getExternalExecutor(&target_info, .{ .link_libc = true }) != .native) { | 698 | if (host.getExternalExecutor(&target_info, .{ .link_libc = true }) != .native) { |
| 698 | // We wouldn't be able to run the compiled C code. | 699 | // We wouldn't be able to run the compiled C code. |
| 699 | continue; // Pass test. | 700 | continue; // Pass test. |
| ... | @@ -1159,9 +1160,9 @@ const TestManifest = struct { | ... | @@ -1159,9 +1160,9 @@ const TestManifest = struct { |
| 1159 | } | 1160 | } |
| 1160 | 1161 | ||
| 1161 | fn getDefaultParser(comptime T: type) ParseFn(T) { | 1162 | fn getDefaultParser(comptime T: type) ParseFn(T) { |
| 1162 | if (T == CrossTarget) return struct { | 1163 | if (T == std.zig.CrossTarget) return struct { |
| 1163 | fn parse(str: []const u8) anyerror!T { | 1164 | fn parse(str: []const u8) anyerror!T { |
| 1164 | return CrossTarget.parse(.{ .arch_os_abi = str }); | 1165 | return std.zig.CrossTarget.parse(.{ .arch_os_abi = str }); |
| 1165 | } | 1166 | } |
| 1166 | }.parse; | 1167 | }.parse; |
| 1167 | 1168 | ||
| ... | @@ -1198,7 +1199,6 @@ const builtin = @import("builtin"); | ... | @@ -1198,7 +1199,6 @@ const builtin = @import("builtin"); |
| 1198 | const std = @import("std"); | 1199 | const std = @import("std"); |
| 1199 | const assert = std.debug.assert; | 1200 | const assert = std.debug.assert; |
| 1200 | const Allocator = std.mem.Allocator; | 1201 | const Allocator = std.mem.Allocator; |
| 1201 | const CrossTarget = std.zig.CrossTarget; | ||
| 1202 | const Compilation = @import("../../src/Compilation.zig"); | 1202 | const Compilation = @import("../../src/Compilation.zig"); |
| 1203 | const zig_h = @import("../../src/link.zig").File.C.zig_h; | 1203 | const zig_h = @import("../../src/link.zig").File.C.zig_h; |
| 1204 | const introspect = @import("../../src/introspect.zig"); | 1204 | const introspect = @import("../../src/introspect.zig"); |
| ... | @@ -1287,7 +1287,7 @@ pub fn main() !void { | ... | @@ -1287,7 +1287,7 @@ pub fn main() !void { |
| 1287 | 1287 | ||
| 1288 | if (cases.items.len == 0) { | 1288 | if (cases.items.len == 0) { |
| 1289 | const backends = try manifest.getConfigForKeyAlloc(arena, "backend", Backend); | 1289 | const backends = try manifest.getConfigForKeyAlloc(arena, "backend", Backend); |
| 1290 | const targets = try manifest.getConfigForKeyAlloc(arena, "target", CrossTarget); | 1290 | const targets = try manifest.getConfigForKeyAlloc(arena, "target", std.zig.CrossTarget); |
| 1291 | const c_frontends = try manifest.getConfigForKeyAlloc(ctx.arena, "c_frontend", CFrontend); | 1291 | const c_frontends = try manifest.getConfigForKeyAlloc(ctx.arena, "c_frontend", CFrontend); |
| 1292 | const is_test = try manifest.getConfigForKeyAssertSingle("is_test", bool); | 1292 | const is_test = try manifest.getConfigForKeyAssertSingle("is_test", bool); |
| 1293 | const link_libc = try manifest.getConfigForKeyAssertSingle("link_libc", bool); | 1293 | const link_libc = try manifest.getConfigForKeyAssertSingle("link_libc", bool); |
| ... | @@ -1295,12 +1295,12 @@ pub fn main() !void { | ... | @@ -1295,12 +1295,12 @@ pub fn main() !void { |
| 1295 | 1295 | ||
| 1296 | if (manifest.type == .translate_c) { | 1296 | if (manifest.type == .translate_c) { |
| 1297 | for (c_frontends) |c_frontend| { | 1297 | for (c_frontends) |c_frontend| { |
| 1298 | for (targets) |target| { | 1298 | for (targets) |target_query| { |
| 1299 | const output = try manifest.trailingLinesSplit(ctx.arena); | 1299 | const output = try manifest.trailingLinesSplit(ctx.arena); |
| 1300 | try ctx.translate.append(.{ | 1300 | try ctx.translate.append(.{ |
| 1301 | .name = std.fs.path.stem(filename), | 1301 | .name = std.fs.path.stem(filename), |
| 1302 | .c_frontend = c_frontend, | 1302 | .c_frontend = c_frontend, |
| 1303 | .target = target, | 1303 | .target = resolveTargetQuery(target_query), |
| 1304 | .is_test = is_test, | 1304 | .is_test = is_test, |
| 1305 | .link_libc = link_libc, | 1305 | .link_libc = link_libc, |
| 1306 | .input = src, | 1306 | .input = src, |
| ... | @@ -1312,12 +1312,12 @@ pub fn main() !void { | ... | @@ -1312,12 +1312,12 @@ pub fn main() !void { |
| 1312 | } | 1312 | } |
| 1313 | if (manifest.type == .run_translated_c) { | 1313 | if (manifest.type == .run_translated_c) { |
| 1314 | for (c_frontends) |c_frontend| { | 1314 | for (c_frontends) |c_frontend| { |
| 1315 | for (targets) |target| { | 1315 | for (targets) |target_query| { |
| 1316 | const output = try manifest.trailingSplit(ctx.arena); | 1316 | const output = try manifest.trailingSplit(ctx.arena); |
| 1317 | try ctx.translate.append(.{ | 1317 | try ctx.translate.append(.{ |
| 1318 | .name = std.fs.path.stem(filename), | 1318 | .name = std.fs.path.stem(filename), |
| 1319 | .c_frontend = c_frontend, | 1319 | .c_frontend = c_frontend, |
| 1320 | .target = target, | 1320 | .target = resolveTargetQuery(target_query), |
| 1321 | .is_test = is_test, | 1321 | .is_test = is_test, |
| 1322 | .link_libc = link_libc, | 1322 | .link_libc = link_libc, |
| 1323 | .output = output, | 1323 | .output = output, |
| ... | @@ -1385,6 +1385,17 @@ pub fn main() !void { | ... | @@ -1385,6 +1385,17 @@ pub fn main() !void { |
| 1385 | return runCases(&ctx, zig_exe_path); | 1385 | return runCases(&ctx, zig_exe_path); |
| 1386 | } | 1386 | } |
| 1387 | 1387 | ||
| 1388 | fn resolveTargetQuery(query: std.zig.CrossTarget) std.Build.ResolvedTarget { | ||
| 1389 | const result = std.zig.system.NativeTargetInfo.detect(query) catch | ||
| 1390 | @panic("unable to resolve target query"); | ||
| 1391 | |||
| 1392 | return .{ | ||
| 1393 | .query = query, | ||
| 1394 | .target = result.target, | ||
| 1395 | .dynamic_linker = result.dynamic_linker, | ||
| 1396 | }; | ||
| 1397 | } | ||
| 1398 | |||
| 1388 | fn runCases(self: *Cases, zig_exe_path: []const u8) !void { | 1399 | fn runCases(self: *Cases, zig_exe_path: []const u8) !void { |
| 1389 | const host = try std.zig.system.NativeTargetInfo.detect(.{}); | 1400 | const host = try std.zig.system.NativeTargetInfo.detect(.{}); |
| 1390 | 1401 |
test/src/CompareOutput.zig+3-3| ... | @@ -96,7 +96,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { | ... | @@ -96,7 +96,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 96 | 96 | ||
| 97 | const exe = b.addExecutable(.{ | 97 | const exe = b.addExecutable(.{ |
| 98 | .name = "test", | 98 | .name = "test", |
| 99 | .target = .{}, | 99 | .target = b.host, |
| 100 | .optimize = .Debug, | 100 | .optimize = .Debug, |
| 101 | }); | 101 | }); |
| 102 | exe.addAssemblyFile(write_src.files.items[0].getPath()); | 102 | exe.addAssemblyFile(write_src.files.items[0].getPath()); |
| ... | @@ -121,7 +121,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { | ... | @@ -121,7 +121,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 121 | .name = "test", | 121 | .name = "test", |
| 122 | .root_source_file = write_src.files.items[0].getPath(), | 122 | .root_source_file = write_src.files.items[0].getPath(), |
| 123 | .optimize = optimize, | 123 | .optimize = optimize, |
| 124 | .target = .{}, | 124 | .target = b.host, |
| 125 | }); | 125 | }); |
| 126 | if (case.link_libc) { | 126 | if (case.link_libc) { |
| 127 | exe.linkSystemLibrary("c"); | 127 | exe.linkSystemLibrary("c"); |
| ... | @@ -146,7 +146,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { | ... | @@ -146,7 +146,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 146 | const exe = b.addExecutable(.{ | 146 | const exe = b.addExecutable(.{ |
| 147 | .name = "test", | 147 | .name = "test", |
| 148 | .root_source_file = write_src.files.items[0].getPath(), | 148 | .root_source_file = write_src.files.items[0].getPath(), |
| 149 | .target = .{}, | 149 | .target = b.host, |
| 150 | .optimize = .Debug, | 150 | .optimize = .Debug, |
| 151 | }); | 151 | }); |
| 152 | if (case.link_libc) { | 152 | if (case.link_libc) { |
test/src/StackTrace.zig+1-1| ... | @@ -77,7 +77,7 @@ fn addExpect( | ... | @@ -77,7 +77,7 @@ fn addExpect( |
| 77 | .name = "test", | 77 | .name = "test", |
| 78 | .root_source_file = write_src.files.items[0].getPath(), | 78 | .root_source_file = write_src.files.items[0].getPath(), |
| 79 | .optimize = optimize_mode, | 79 | .optimize = optimize_mode, |
| 80 | .target = .{}, | 80 | .target = b.host, |
| 81 | }); | 81 | }); |
| 82 | 82 | ||
| 83 | const run = b.addRunArtifact(exe); | 83 | const run = b.addRunArtifact(exe); |
test/src/run_translated_c.zig+2-2| ... | @@ -11,7 +11,7 @@ pub const RunTranslatedCContext = struct { | ... | @@ -11,7 +11,7 @@ pub const RunTranslatedCContext = struct { |
| 11 | step: *std.Build.Step, | 11 | step: *std.Build.Step, |
| 12 | test_index: usize, | 12 | test_index: usize, |
| 13 | test_filter: ?[]const u8, | 13 | test_filter: ?[]const u8, |
| 14 | target: std.zig.CrossTarget, | 14 | target: std.Build.ResolvedTarget, |
| 15 | 15 | ||
| 16 | const TestCase = struct { | 16 | const TestCase = struct { |
| 17 | name: []const u8, | 17 | name: []const u8, |
| ... | @@ -86,7 +86,7 @@ pub const RunTranslatedCContext = struct { | ... | @@ -86,7 +86,7 @@ pub const RunTranslatedCContext = struct { |
| 86 | } | 86 | } |
| 87 | const translate_c = b.addTranslateC(.{ | 87 | const translate_c = b.addTranslateC(.{ |
| 88 | .source_file = write_src.files.items[0].getPath(), | 88 | .source_file = write_src.files.items[0].getPath(), |
| 89 | .target = .{}, | 89 | .target = b.host, |
| 90 | .optimize = .Debug, | 90 | .optimize = .Debug, |
| 91 | }); | 91 | }); |
| 92 | 92 |
test/src/translate_c.zig+2-2| ... | @@ -18,7 +18,7 @@ pub const TranslateCContext = struct { | ... | @@ -18,7 +18,7 @@ pub const TranslateCContext = struct { |
| 18 | sources: ArrayList(SourceFile), | 18 | sources: ArrayList(SourceFile), |
| 19 | expected_lines: ArrayList([]const u8), | 19 | expected_lines: ArrayList([]const u8), |
| 20 | allow_warnings: bool, | 20 | allow_warnings: bool, |
| 21 | target: CrossTarget = CrossTarget{}, | 21 | target: CrossTarget = .{}, |
| 22 | 22 | ||
| 23 | const SourceFile = struct { | 23 | const SourceFile = struct { |
| 24 | filename: []const u8, | 24 | filename: []const u8, |
| ... | @@ -109,7 +109,7 @@ pub const TranslateCContext = struct { | ... | @@ -109,7 +109,7 @@ pub const TranslateCContext = struct { |
| 109 | 109 | ||
| 110 | const translate_c = b.addTranslateC(.{ | 110 | const translate_c = b.addTranslateC(.{ |
| 111 | .source_file = write_src.files.items[0].getPath(), | 111 | .source_file = write_src.files.items[0].getPath(), |
| 112 | .target = case.target, | 112 | .target = b.resolveTargetQuery(case.target), |
| 113 | .optimize = .Debug, | 113 | .optimize = .Debug, |
| 114 | }); | 114 | }); |
| 115 | 115 |
test/standalone.zig-4| ... | @@ -89,10 +89,6 @@ pub const build_cases = [_]BuildCase{ | ... | @@ -89,10 +89,6 @@ pub const build_cases = [_]BuildCase{ |
| 89 | // .build_root = "test/standalone/issue_13970", | 89 | // .build_root = "test/standalone/issue_13970", |
| 90 | // .import = @import("standalone/issue_13970/build.zig"), | 90 | // .import = @import("standalone/issue_13970/build.zig"), |
| 91 | //}, | 91 | //}, |
| 92 | .{ | ||
| 93 | .build_root = "test/standalone/main_pkg_path", | ||
| 94 | .import = @import("standalone/main_pkg_path/build.zig"), | ||
| 95 | }, | ||
| 96 | .{ | 92 | .{ |
| 97 | .build_root = "test/standalone/shared_library", | 93 | .build_root = "test/standalone/shared_library", |
| 98 | .import = @import("standalone/shared_library/build.zig"), | 94 | .import = @import("standalone/shared_library/build.zig"), |
test/standalone/c_compiler/build.zig+2-2| ... | @@ -23,7 +23,7 @@ fn add( | ... | @@ -23,7 +23,7 @@ fn add( |
| 23 | cpp_name: []const u8, | 23 | cpp_name: []const u8, |
| 24 | optimize: std.builtin.OptimizeMode, | 24 | optimize: std.builtin.OptimizeMode, |
| 25 | ) void { | 25 | ) void { |
| 26 | const target: std.zig.CrossTarget = .{}; | 26 | const target = b.host; |
| 27 | 27 | ||
| 28 | const exe_c = b.addExecutable(.{ | 28 | const exe_c = b.addExecutable(.{ |
| 29 | .name = c_name, | 29 | .name = c_name, |
| ... | @@ -42,7 +42,7 @@ fn add( | ... | @@ -42,7 +42,7 @@ fn add( |
| 42 | exe_cpp.addCSourceFile(.{ .file = .{ .path = "test.cpp" }, .flags = &[0][]const u8{} }); | 42 | exe_cpp.addCSourceFile(.{ .file = .{ .path = "test.cpp" }, .flags = &[0][]const u8{} }); |
| 43 | exe_cpp.linkLibCpp(); | 43 | exe_cpp.linkLibCpp(); |
| 44 | 44 | ||
| 45 | switch (target.getOsTag()) { | 45 | switch (target.target.os.tag) { |
| 46 | .windows => { | 46 | .windows => { |
| 47 | // https://github.com/ziglang/zig/issues/8531 | 47 | // https://github.com/ziglang/zig/issues/8531 |
| 48 | exe_cpp.want_lto = false; | 48 | exe_cpp.want_lto = false; |
test/standalone/child_process/build.zig+1-1| ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { |
| 6 | b.default_step = test_step; | 6 | b.default_step = test_step; |
| 7 | 7 | ||
| 8 | const optimize: std.builtin.OptimizeMode = .Debug; | 8 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 9 | const target: std.zig.CrossTarget = .{}; | 9 | const target = b.host; |
| 10 | 10 | ||
| 11 | if (builtin.os.tag == .wasi) return; | 11 | if (builtin.os.tag == .wasi) return; |
| 12 | 12 |
test/standalone/compiler_rt_panic/build.zig+4-4| ... | @@ -4,16 +4,16 @@ pub fn build(b: *std.Build) void { | ... | @@ -4,16 +4,16 @@ pub fn build(b: *std.Build) void { |
| 4 | const test_step = b.step("test", "Test it"); | 4 | const test_step = b.step("test", "Test it"); |
| 5 | b.default_step = test_step; | 5 | b.default_step = test_step; |
| 6 | 6 | ||
| 7 | const target = b.standardTargetOptions(.{}); | 7 | const resolved_target = b.standardTargetOptions(.{}); |
| 8 | const target = resolved_target.target; | ||
| 8 | const optimize = b.standardOptimizeOption(.{}); | 9 | const optimize = b.standardOptimizeOption(.{}); |
| 9 | 10 | ||
| 10 | const abi = target.getAbi(); | 11 | if (target.ofmt != .elf or !(target.abi.isMusl() or target.abi.isGnu())) return; |
| 11 | if (target.getObjectFormat() != .elf or !(abi.isMusl() or abi.isGnu())) return; | ||
| 12 | 12 | ||
| 13 | const exe = b.addExecutable(.{ | 13 | const exe = b.addExecutable(.{ |
| 14 | .name = "main", | 14 | .name = "main", |
| 15 | .optimize = optimize, | 15 | .optimize = optimize, |
| 16 | .target = target, | 16 | .target = resolved_target, |
| 17 | }); | 17 | }); |
| 18 | exe.linkLibC(); | 18 | exe.linkLibC(); |
| 19 | exe.addCSourceFile(.{ | 19 | exe.addCSourceFile(.{ |
test/standalone/dep_diamond/build.zig+8-7| ... | @@ -7,21 +7,22 @@ pub fn build(b: *std.Build) void { | ... | @@ -7,21 +7,22 @@ pub fn build(b: *std.Build) void { |
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | ||
| 9 | const shared = b.createModule(.{ | 9 | const shared = b.createModule(.{ |
| 10 | .source_file = .{ .path = "shared.zig" }, | 10 | .root_source_file = .{ .path = "shared.zig" }, |
| 11 | }); | 11 | }); |
| 12 | 12 | ||
| 13 | const exe = b.addExecutable(.{ | 13 | const exe = b.addExecutable(.{ |
| 14 | .name = "test", | 14 | .name = "test", |
| 15 | .root_source_file = .{ .path = "test.zig" }, | 15 | .root_source_file = .{ .path = "test.zig" }, |
| 16 | .target = b.host, | ||
| 16 | .optimize = optimize, | 17 | .optimize = optimize, |
| 17 | }); | 18 | }); |
| 18 | exe.addAnonymousModule("foo", .{ | 19 | exe.root_module.addAnonymousImport("foo", .{ |
| 19 | .source_file = .{ .path = "foo.zig" }, | 20 | .root_source_file = .{ .path = "foo.zig" }, |
| 20 | .dependencies = &.{.{ .name = "shared", .module = shared }}, | 21 | .imports = &.{.{ .name = "shared", .module = shared }}, |
| 21 | }); | 22 | }); |
| 22 | exe.addAnonymousModule("bar", .{ | 23 | exe.root_module.addAnonymousImport("bar", .{ |
| 23 | .source_file = .{ .path = "bar.zig" }, | 24 | .root_source_file = .{ .path = "bar.zig" }, |
| 24 | .dependencies = &.{.{ .name = "shared", .module = shared }}, | 25 | .imports = &.{.{ .name = "shared", .module = shared }}, |
| 25 | }); | 26 | }); |
| 26 | 27 | ||
| 27 | const run = b.addRunArtifact(exe); | 28 | const run = b.addRunArtifact(exe); |
test/standalone/dep_mutually_recursive/build.zig+6-5| ... | @@ -7,20 +7,21 @@ pub fn build(b: *std.Build) void { | ... | @@ -7,20 +7,21 @@ pub fn build(b: *std.Build) void { |
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | ||
| 9 | const foo = b.createModule(.{ | 9 | const foo = b.createModule(.{ |
| 10 | .source_file = .{ .path = "foo.zig" }, | 10 | .root_source_file = .{ .path = "foo.zig" }, |
| 11 | }); | 11 | }); |
| 12 | const bar = b.createModule(.{ | 12 | const bar = b.createModule(.{ |
| 13 | .source_file = .{ .path = "bar.zig" }, | 13 | .root_source_file = .{ .path = "bar.zig" }, |
| 14 | }); | 14 | }); |
| 15 | foo.dependencies.put("bar", bar) catch @panic("OOM"); | 15 | foo.addImport("bar", bar); |
| 16 | bar.dependencies.put("foo", foo) catch @panic("OOM"); | 16 | bar.addImport("foo", foo); |
| 17 | 17 | ||
| 18 | const exe = b.addExecutable(.{ | 18 | const exe = b.addExecutable(.{ |
| 19 | .name = "test", | 19 | .name = "test", |
| 20 | .root_source_file = .{ .path = "test.zig" }, | 20 | .root_source_file = .{ .path = "test.zig" }, |
| 21 | .target = b.host, | ||
| 21 | .optimize = optimize, | 22 | .optimize = optimize, |
| 22 | }); | 23 | }); |
| 23 | exe.addModule("foo", foo); | 24 | exe.root_module.addImport("foo", foo); |
| 24 | 25 | ||
| 25 | const run = b.addRunArtifact(exe); | 26 | const run = b.addRunArtifact(exe); |
| 26 | test_step.dependOn(&run.step); | 27 | test_step.dependOn(&run.step); |
test/standalone/dep_recursive/build.zig+4-3| ... | @@ -7,16 +7,17 @@ pub fn build(b: *std.Build) void { | ... | @@ -7,16 +7,17 @@ pub fn build(b: *std.Build) void { |
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | ||
| 9 | const foo = b.createModule(.{ | 9 | const foo = b.createModule(.{ |
| 10 | .source_file = .{ .path = "foo.zig" }, | 10 | .root_source_file = .{ .path = "foo.zig" }, |
| 11 | }); | 11 | }); |
| 12 | foo.dependencies.put("foo", foo) catch @panic("OOM"); | 12 | foo.addImport("foo", foo); |
| 13 | 13 | ||
| 14 | const exe = b.addExecutable(.{ | 14 | const exe = b.addExecutable(.{ |
| 15 | .name = "test", | 15 | .name = "test", |
| 16 | .root_source_file = .{ .path = "test.zig" }, | 16 | .root_source_file = .{ .path = "test.zig" }, |
| 17 | .target = b.host, | ||
| 17 | .optimize = optimize, | 18 | .optimize = optimize, |
| 18 | }); | 19 | }); |
| 19 | exe.addModule("foo", foo); | 20 | exe.root_module.addImport("foo", foo); |
| 20 | 21 | ||
| 21 | const run = b.addRunArtifact(exe); | 22 | const run = b.addRunArtifact(exe); |
| 22 | test_step.dependOn(&run.step); | 23 | test_step.dependOn(&run.step); |
test/standalone/dep_shared_builtin/build.zig+3-2| ... | @@ -9,10 +9,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -9,10 +9,11 @@ pub fn build(b: *std.Build) void { |
| 9 | const exe = b.addExecutable(.{ | 9 | const exe = b.addExecutable(.{ |
| 10 | .name = "test", | 10 | .name = "test", |
| 11 | .root_source_file = .{ .path = "test.zig" }, | 11 | .root_source_file = .{ .path = "test.zig" }, |
| 12 | .target = b.host, | ||
| 12 | .optimize = optimize, | 13 | .optimize = optimize, |
| 13 | }); | 14 | }); |
| 14 | exe.addAnonymousModule("foo", .{ | 15 | exe.root_module.addAnonymousImport("foo", .{ |
| 15 | .source_file = .{ .path = "foo.zig" }, | 16 | .root_source_file = .{ .path = "foo.zig" }, |
| 16 | }); | 17 | }); |
| 17 | 18 | ||
| 18 | const run = b.addRunArtifact(exe); | 19 | const run = b.addRunArtifact(exe); |
test/standalone/dep_triangle/build.zig+6-5| ... | @@ -7,19 +7,20 @@ pub fn build(b: *std.Build) void { | ... | @@ -7,19 +7,20 @@ pub fn build(b: *std.Build) void { |
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | ||
| 9 | const shared = b.createModule(.{ | 9 | const shared = b.createModule(.{ |
| 10 | .source_file = .{ .path = "shared.zig" }, | 10 | .root_source_file = .{ .path = "shared.zig" }, |
| 11 | }); | 11 | }); |
| 12 | 12 | ||
| 13 | const exe = b.addExecutable(.{ | 13 | const exe = b.addExecutable(.{ |
| 14 | .name = "test", | 14 | .name = "test", |
| 15 | .root_source_file = .{ .path = "test.zig" }, | 15 | .root_source_file = .{ .path = "test.zig" }, |
| 16 | .target = b.host, | ||
| 16 | .optimize = optimize, | 17 | .optimize = optimize, |
| 17 | }); | 18 | }); |
| 18 | exe.addAnonymousModule("foo", .{ | 19 | exe.root_module.addAnonymousImport("foo", .{ |
| 19 | .source_file = .{ .path = "foo.zig" }, | 20 | .root_source_file = .{ .path = "foo.zig" }, |
| 20 | .dependencies = &.{.{ .name = "shared", .module = shared }}, | 21 | .imports = &.{.{ .name = "shared", .module = shared }}, |
| 21 | }); | 22 | }); |
| 22 | exe.addModule("shared", shared); | 23 | exe.root_module.addImport("shared", shared); |
| 23 | 24 | ||
| 24 | const run = b.addRunArtifact(exe); | 25 | const run = b.addRunArtifact(exe); |
| 25 | test_step.dependOn(&run.step); | 26 | test_step.dependOn(&run.step); |
test/standalone/embed_generated_file/build.zig+4-4| ... | @@ -7,10 +7,10 @@ pub fn build(b: *std.Build) void { | ... | @@ -7,10 +7,10 @@ pub fn build(b: *std.Build) void { |
| 7 | const bootloader = b.addExecutable(.{ | 7 | const bootloader = b.addExecutable(.{ |
| 8 | .name = "bootloader", | 8 | .name = "bootloader", |
| 9 | .root_source_file = .{ .path = "bootloader.zig" }, | 9 | .root_source_file = .{ .path = "bootloader.zig" }, |
| 10 | .target = .{ | 10 | .target = b.resolveTargetQuery(.{ |
| 11 | .cpu_arch = .x86, | 11 | .cpu_arch = .x86, |
| 12 | .os_tag = .freestanding, | 12 | .os_tag = .freestanding, |
| 13 | }, | 13 | }), |
| 14 | .optimize = .ReleaseSmall, | 14 | .optimize = .ReleaseSmall, |
| 15 | }); | 15 | }); |
| 16 | 16 | ||
| ... | @@ -18,8 +18,8 @@ pub fn build(b: *std.Build) void { | ... | @@ -18,8 +18,8 @@ pub fn build(b: *std.Build) void { |
| 18 | .root_source_file = .{ .path = "main.zig" }, | 18 | .root_source_file = .{ .path = "main.zig" }, |
| 19 | .optimize = .Debug, | 19 | .optimize = .Debug, |
| 20 | }); | 20 | }); |
| 21 | exe.addAnonymousModule("bootloader.elf", .{ | 21 | exe.root_module.addAnonymousImport("bootloader.elf", .{ |
| 22 | .source_file = bootloader.getEmittedBin(), | 22 | .root_source_file = bootloader.getEmittedBin(), |
| 23 | }); | 23 | }); |
| 24 | 24 | ||
| 25 | // TODO: actually check the output | 25 | // TODO: actually check the output |
test/standalone/empty_env/build.zig+1| ... | @@ -15,6 +15,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -15,6 +15,7 @@ pub fn build(b: *std.Build) void { |
| 15 | const main = b.addExecutable(.{ | 15 | const main = b.addExecutable(.{ |
| 16 | .name = "main", | 16 | .name = "main", |
| 17 | .root_source_file = .{ .path = "main.zig" }, | 17 | .root_source_file = .{ .path = "main.zig" }, |
| 18 | .target = b.host, | ||
| 18 | .optimize = optimize, | 19 | .optimize = optimize, |
| 19 | }); | 20 | }); |
| 20 | 21 |
test/standalone/extern/build.zig+1-1| ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { |
| 6 | const obj = b.addObject(.{ | 6 | const obj = b.addObject(.{ |
| 7 | .name = "exports", | 7 | .name = "exports", |
| 8 | .root_source_file = .{ .path = "exports.zig" }, | 8 | .root_source_file = .{ .path = "exports.zig" }, |
| 9 | .target = .{}, | 9 | .target = b.host, |
| 10 | .optimize = optimize, | 10 | .optimize = optimize, |
| 11 | }); | 11 | }); |
| 12 | const main = b.addTest(.{ | 12 | const main = b.addTest(.{ |
test/standalone/global_linkage/build.zig+1-1| ... | @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void { |
| 5 | b.default_step = test_step; | 5 | b.default_step = test_step; |
| 6 | 6 | ||
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | const target: std.zig.CrossTarget = .{}; | 8 | const target = b.host; |
| 9 | 9 | ||
| 10 | const obj1 = b.addStaticLibrary(.{ | 10 | const obj1 = b.addStaticLibrary(.{ |
| 11 | .name = "obj1", | 11 | .name = "obj1", |
test/standalone/install_raw_hex/build.zig+2-2| ... | @@ -5,12 +5,12 @@ pub fn build(b: *std.Build) void { | ... | @@ -5,12 +5,12 @@ pub fn build(b: *std.Build) void { |
| 5 | const test_step = b.step("test", "Test it"); | 5 | const test_step = b.step("test", "Test it"); |
| 6 | b.default_step = test_step; | 6 | b.default_step = test_step; |
| 7 | 7 | ||
| 8 | const target = .{ | 8 | const target = b.resolveTargetQuery(.{ |
| 9 | .cpu_arch = .thumb, | 9 | .cpu_arch = .thumb, |
| 10 | .cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m4 }, | 10 | .cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m4 }, |
| 11 | .os_tag = .freestanding, | 11 | .os_tag = .freestanding, |
| 12 | .abi = .gnueabihf, | 12 | .abi = .gnueabihf, |
| 13 | }; | 13 | }); |
| 14 | 14 | ||
| 15 | const optimize: std.builtin.OptimizeMode = .Debug; | 15 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 16 | 16 |
test/standalone/ios/build.zig+4-4| ... | @@ -8,12 +8,12 @@ pub fn build(b: *std.Build) void { | ... | @@ -8,12 +8,12 @@ pub fn build(b: *std.Build) void { |
| 8 | b.default_step = test_step; | 8 | b.default_step = test_step; |
| 9 | 9 | ||
| 10 | const optimize: std.builtin.OptimizeMode = .Debug; | 10 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 11 | const target: std.zig.CrossTarget = .{ | 11 | const target = b.resolveTargetQuery(.{ |
| 12 | .cpu_arch = .aarch64, | 12 | .cpu_arch = .aarch64, |
| 13 | .os_tag = .ios, | 13 | .os_tag = .ios, |
| 14 | }; | 14 | }); |
| 15 | const target_info = std.zig.system.NativeTargetInfo.detect(target) catch @panic("couldn't detect native target"); | 15 | const sdk = std.zig.system.darwin.getSdk(b.allocator, target.target) orelse |
| 16 | const sdk = std.zig.system.darwin.getSdk(b.allocator, target_info.target) orelse @panic("no iOS SDK found"); | 16 | @panic("no iOS SDK found"); |
| 17 | b.sysroot = sdk; | 17 | b.sysroot = sdk; |
| 18 | 18 | ||
| 19 | const exe = b.addExecutable(.{ | 19 | const exe = b.addExecutable(.{ |
test/standalone/issue_11595/build.zig+1-1| ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { |
| 6 | b.default_step = test_step; | 6 | b.default_step = test_step; |
| 7 | 7 | ||
| 8 | const optimize: std.builtin.OptimizeMode = .Debug; | 8 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 9 | const target: std.zig.CrossTarget = .{}; | 9 | const target = b.host; |
| 10 | 10 | ||
| 11 | if (builtin.os.tag == .windows) { | 11 | if (builtin.os.tag == .windows) { |
| 12 | // https://github.com/ziglang/zig/issues/12419 | 12 | // https://github.com/ziglang/zig/issues/12419 |
test/standalone/issue_12588/build.zig+1-2| ... | @@ -5,13 +5,12 @@ pub fn build(b: *std.Build) void { | ... | @@ -5,13 +5,12 @@ pub fn build(b: *std.Build) void { |
| 5 | b.default_step = test_step; | 5 | b.default_step = test_step; |
| 6 | 6 | ||
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | const target: std.zig.CrossTarget = .{}; | ||
| 9 | 8 | ||
| 10 | const obj = b.addObject(.{ | 9 | const obj = b.addObject(.{ |
| 11 | .name = "main", | 10 | .name = "main", |
| 12 | .root_source_file = .{ .path = "main.zig" }, | 11 | .root_source_file = .{ .path = "main.zig" }, |
| 13 | .optimize = optimize, | 12 | .optimize = optimize, |
| 14 | .target = target, | 13 | .target = b.host, |
| 15 | }); | 14 | }); |
| 16 | _ = obj.getEmittedLlvmIr(); | 15 | _ = obj.getEmittedLlvmIr(); |
| 17 | _ = obj.getEmittedLlvmBc(); | 16 | _ = obj.getEmittedLlvmBc(); |
test/standalone/issue_12706/build.zig+1-2| ... | @@ -1,13 +1,12 @@ | ... | @@ -1,13 +1,12 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | const CrossTarget = std.zig.CrossTarget; | ||
| 4 | 3 | ||
| 5 | pub fn build(b: *std.Build) void { | 4 | pub fn build(b: *std.Build) void { |
| 6 | const test_step = b.step("test", "Test it"); | 5 | const test_step = b.step("test", "Test it"); |
| 7 | b.default_step = test_step; | 6 | b.default_step = test_step; |
| 8 | 7 | ||
| 9 | const optimize: std.builtin.OptimizeMode = .Debug; | 8 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 10 | const target: std.zig.CrossTarget = .{}; | 9 | const target = b.host; |
| 11 | 10 | ||
| 12 | const exe = b.addExecutable(.{ | 11 | const exe = b.addExecutable(.{ |
| 13 | .name = "main", | 12 | .name = "main", |
test/standalone/issue_339/build.zig+1-1| ... | @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void { |
| 5 | b.default_step = test_step; | 5 | b.default_step = test_step; |
| 6 | 6 | ||
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | const target: std.zig.CrossTarget = .{}; | 8 | const target = b.host; |
| 9 | 9 | ||
| 10 | const obj = b.addObject(.{ | 10 | const obj = b.addObject(.{ |
| 11 | .name = "test", | 11 | .name = "test", |
test/standalone/issue_8550/build.zig+2-2| ... | @@ -5,13 +5,13 @@ pub fn build(b: *std.Build) !void { | ... | @@ -5,13 +5,13 @@ pub fn build(b: *std.Build) !void { |
| 5 | b.default_step = test_step; | 5 | b.default_step = test_step; |
| 6 | 6 | ||
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | const target = std.zig.CrossTarget{ | 8 | const target = b.resolveTargetQuery(.{ |
| 9 | .os_tag = .freestanding, | 9 | .os_tag = .freestanding, |
| 10 | .cpu_arch = .arm, | 10 | .cpu_arch = .arm, |
| 11 | .cpu_model = .{ | 11 | .cpu_model = .{ |
| 12 | .explicit = &std.Target.arm.cpu.arm1176jz_s, | 12 | .explicit = &std.Target.arm.cpu.arm1176jz_s, |
| 13 | }, | 13 | }, |
| 14 | }; | 14 | }); |
| 15 | 15 | ||
| 16 | const kernel = b.addExecutable(.{ | 16 | const kernel = b.addExecutable(.{ |
| 17 | .name = "kernel", | 17 | .name = "kernel", |
test/standalone/load_dynamic_library/build.zig+1-1| ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { |
| 6 | b.default_step = test_step; | 6 | b.default_step = test_step; |
| 7 | 7 | ||
| 8 | const optimize: std.builtin.OptimizeMode = .Debug; | 8 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 9 | const target: std.zig.CrossTarget = .{}; | 9 | const target = b.host; |
| 10 | 10 | ||
| 11 | if (builtin.os.tag == .wasi) return; | 11 | if (builtin.os.tag == .wasi) return; |
| 12 | 12 |
test/standalone/main_pkg_path/a/test.zig deleted-5| ... | @@ -1,5 +0,0 @@ | ||
| 1 | const b = @import("../b.zig"); | ||
| 2 | |||
| 3 | test "main pkg path" { | ||
| 4 | b.foo(); | ||
| 5 | } | ||
test/standalone/main_pkg_path/b.zig deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | pub fn foo() void {} | ||
test/standalone/main_pkg_path/build.zig deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | pub fn build(b: *std.Build) void { | ||
| 4 | const test_step = b.step("test", "Test it"); | ||
| 5 | b.default_step = test_step; | ||
| 6 | |||
| 7 | const test_exe = b.addTest(.{ | ||
| 8 | .root_source_file = .{ .path = "a/test.zig" }, | ||
| 9 | .main_pkg_path = .{ .path = "." }, | ||
| 10 | }); | ||
| 11 | |||
| 12 | test_step.dependOn(&b.addRunArtifact(test_exe).step); | ||
| 13 | } | ||
test/standalone/mix_c_files/build.zig+1| ... | @@ -19,6 +19,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -19,6 +19,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 19 | const exe = b.addExecutable(.{ | 19 | const exe = b.addExecutable(.{ |
| 20 | .name = "test", | 20 | .name = "test", |
| 21 | .root_source_file = .{ .path = "main.zig" }, | 21 | .root_source_file = .{ .path = "main.zig" }, |
| 22 | .target = b.host, | ||
| 22 | .optimize = optimize, | 23 | .optimize = optimize, |
| 23 | }); | 24 | }); |
| 24 | exe.addCSourceFile(.{ .file = .{ .path = "test.c" }, .flags = &[_][]const u8{"-std=c11"} }); | 25 | exe.addCSourceFile(.{ .file = .{ .path = "test.c" }, .flags = &[_][]const u8{"-std=c11"} }); |
test/standalone/mix_o_files/build.zig+1-1| ... | @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void { |
| 5 | b.default_step = test_step; | 5 | b.default_step = test_step; |
| 6 | 6 | ||
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | const target: std.zig.CrossTarget = .{}; | 8 | const target = b.host; |
| 9 | 9 | ||
| 10 | const obj = b.addObject(.{ | 10 | const obj = b.addObject(.{ |
| 11 | .name = "base64", | 11 | .name = "base64", |
test/standalone/options/build.zig+1-1| ... | @@ -3,7 +3,7 @@ const std = @import("std"); | ... | @@ -3,7 +3,7 @@ const std = @import("std"); |
| 3 | pub fn build(b: *std.Build) void { | 3 | pub fn build(b: *std.Build) void { |
| 4 | const main = b.addTest(.{ | 4 | const main = b.addTest(.{ |
| 5 | .root_source_file = .{ .path = "src/main.zig" }, | 5 | .root_source_file = .{ .path = "src/main.zig" }, |
| 6 | .target = .{}, | 6 | .target = b.host, |
| 7 | .optimize = .Debug, | 7 | .optimize = .Debug, |
| 8 | }); | 8 | }); |
| 9 | 9 |
test/standalone/pie/build.zig+2-2| ... | @@ -5,10 +5,10 @@ pub fn build(b: *std.Build) void { | ... | @@ -5,10 +5,10 @@ pub fn build(b: *std.Build) void { |
| 5 | b.default_step = test_step; | 5 | b.default_step = test_step; |
| 6 | 6 | ||
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | const target: std.zig.CrossTarget = .{ | 8 | const target = b.resolveTargetQuery(.{ |
| 9 | .os_tag = .linux, | 9 | .os_tag = .linux, |
| 10 | .cpu_arch = .x86_64, | 10 | .cpu_arch = .x86_64, |
| 11 | }; | 11 | }); |
| 12 | 12 | ||
| 13 | const main = b.addTest(.{ | 13 | const main = b.addTest(.{ |
| 14 | .root_source_file = .{ .path = "main.zig" }, | 14 | .root_source_file = .{ .path = "main.zig" }, |
test/standalone/pkg_import/build.zig+2-1| ... | @@ -10,8 +10,9 @@ pub fn build(b: *std.Build) void { | ... | @@ -10,8 +10,9 @@ pub fn build(b: *std.Build) void { |
| 10 | .name = "test", | 10 | .name = "test", |
| 11 | .root_source_file = .{ .path = "test.zig" }, | 11 | .root_source_file = .{ .path = "test.zig" }, |
| 12 | .optimize = optimize, | 12 | .optimize = optimize, |
| 13 | .target = b.host, | ||
| 13 | }); | 14 | }); |
| 14 | exe.addAnonymousModule("my_pkg", .{ .source_file = .{ .path = "pkg.zig" } }); | 15 | exe.root_module.addAnonymousImport("my_pkg", .{ .root_source_file = .{ .path = "pkg.zig" } }); |
| 15 | 16 | ||
| 16 | const run = b.addRunArtifact(exe); | 17 | const run = b.addRunArtifact(exe); |
| 17 | test_step.dependOn(&run.step); | 18 | test_step.dependOn(&run.step); |
test/standalone/self_exe_symlink/build.zig+2-2| ... | @@ -7,11 +7,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -7,11 +7,11 @@ pub fn build(b: *std.Build) void { |
| 7 | b.default_step = test_step; | 7 | b.default_step = test_step; |
| 8 | 8 | ||
| 9 | const optimize: std.builtin.OptimizeMode = .Debug; | 9 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 10 | const target: std.zig.CrossTarget = .{}; | 10 | const target = b.host; |
| 11 | 11 | ||
| 12 | // The test requires getFdPath in order to to get the path of the | 12 | // The test requires getFdPath in order to to get the path of the |
| 13 | // File returned by openSelfExe | 13 | // File returned by openSelfExe |
| 14 | if (!std.os.isGetFdPathSupportedOnTarget(target.getOs())) return; | 14 | if (!std.os.isGetFdPathSupportedOnTarget(target.target.os)) return; |
| 15 | 15 | ||
| 16 | const main = b.addExecutable(.{ | 16 | const main = b.addExecutable(.{ |
| 17 | .name = "main", | 17 | .name = "main", |
test/standalone/shared_library/build.zig+1-1| ... | @@ -10,7 +10,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -10,7 +10,7 @@ pub fn build(b: *std.Build) void { |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | const optimize: std.builtin.OptimizeMode = .Debug; | 12 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 13 | const target: std.zig.CrossTarget = .{}; | 13 | const target = b.host; |
| 14 | const lib = b.addSharedLibrary(.{ | 14 | const lib = b.addSharedLibrary(.{ |
| 15 | .name = "mathtest", | 15 | .name = "mathtest", |
| 16 | .root_source_file = .{ .path = "mathtest.zig" }, | 16 | .root_source_file = .{ .path = "mathtest.zig" }, |
test/standalone/stack_iterator/build.zig+9-10| ... | @@ -22,11 +22,10 @@ pub fn build(b: *std.Build) void { | ... | @@ -22,11 +22,10 @@ pub fn build(b: *std.Build) void { |
| 22 | .root_source_file = .{ .path = "unwind.zig" }, | 22 | .root_source_file = .{ .path = "unwind.zig" }, |
| 23 | .target = target, | 23 | .target = target, |
| 24 | .optimize = optimize, | 24 | .optimize = optimize, |
| 25 | .unwind_tables = target.target.isDarwin(), | ||
| 26 | .omit_frame_pointer = false, | ||
| 25 | }); | 27 | }); |
| 26 | 28 | ||
| 27 | if (target.isDarwin()) exe.unwind_tables = true; | ||
| 28 | exe.omit_frame_pointer = false; | ||
| 29 | |||
| 30 | const run_cmd = b.addRunArtifact(exe); | 29 | const run_cmd = b.addRunArtifact(exe); |
| 31 | test_step.dependOn(&run_cmd.step); | 30 | test_step.dependOn(&run_cmd.step); |
| 32 | } | 31 | } |
| ... | @@ -46,11 +45,10 @@ pub fn build(b: *std.Build) void { | ... | @@ -46,11 +45,10 @@ pub fn build(b: *std.Build) void { |
| 46 | .root_source_file = .{ .path = "unwind.zig" }, | 45 | .root_source_file = .{ .path = "unwind.zig" }, |
| 47 | .target = target, | 46 | .target = target, |
| 48 | .optimize = optimize, | 47 | .optimize = optimize, |
| 48 | .unwind_tables = true, | ||
| 49 | .omit_frame_pointer = true, | ||
| 49 | }); | 50 | }); |
| 50 | 51 | ||
| 51 | exe.omit_frame_pointer = true; | ||
| 52 | exe.unwind_tables = true; | ||
| 53 | |||
| 54 | const run_cmd = b.addRunArtifact(exe); | 52 | const run_cmd = b.addRunArtifact(exe); |
| 55 | test_step.dependOn(&run_cmd.step); | 53 | test_step.dependOn(&run_cmd.step); |
| 56 | } | 54 | } |
| ... | @@ -69,11 +67,12 @@ pub fn build(b: *std.Build) void { | ... | @@ -69,11 +67,12 @@ pub fn build(b: *std.Build) void { |
| 69 | .name = "c_shared_lib", | 67 | .name = "c_shared_lib", |
| 70 | .target = target, | 68 | .target = target, |
| 71 | .optimize = optimize, | 69 | .optimize = optimize, |
| 70 | .strip = false, | ||
| 72 | }); | 71 | }); |
| 73 | 72 | ||
| 74 | if (target.isWindows()) c_shared_lib.defineCMacro("LIB_API", "__declspec(dllexport)"); | 73 | if (target.target.os.tag == .windows) |
| 74 | c_shared_lib.defineCMacro("LIB_API", "__declspec(dllexport)"); | ||
| 75 | 75 | ||
| 76 | c_shared_lib.strip = false; | ||
| 77 | c_shared_lib.addCSourceFile(.{ | 76 | c_shared_lib.addCSourceFile(.{ |
| 78 | .file = .{ .path = "shared_lib.c" }, | 77 | .file = .{ .path = "shared_lib.c" }, |
| 79 | .flags = &.{"-fomit-frame-pointer"}, | 78 | .flags = &.{"-fomit-frame-pointer"}, |
| ... | @@ -85,10 +84,10 @@ pub fn build(b: *std.Build) void { | ... | @@ -85,10 +84,10 @@ pub fn build(b: *std.Build) void { |
| 85 | .root_source_file = .{ .path = "shared_lib_unwind.zig" }, | 84 | .root_source_file = .{ .path = "shared_lib_unwind.zig" }, |
| 86 | .target = target, | 85 | .target = target, |
| 87 | .optimize = optimize, | 86 | .optimize = optimize, |
| 87 | .unwind_tables = target.target.isDarwin(), | ||
| 88 | .omit_frame_pointer = true, | ||
| 88 | }); | 89 | }); |
| 89 | 90 | ||
| 90 | if (target.isDarwin()) exe.unwind_tables = true; | ||
| 91 | exe.omit_frame_pointer = true; | ||
| 92 | exe.linkLibrary(c_shared_lib); | 91 | exe.linkLibrary(c_shared_lib); |
| 93 | 92 | ||
| 94 | const run_cmd = b.addRunArtifact(exe); | 93 | const run_cmd = b.addRunArtifact(exe); |
test/standalone/static_c_lib/build.zig+1-1| ... | @@ -9,7 +9,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -9,7 +9,7 @@ pub fn build(b: *std.Build) void { |
| 9 | const foo = b.addStaticLibrary(.{ | 9 | const foo = b.addStaticLibrary(.{ |
| 10 | .name = "foo", | 10 | .name = "foo", |
| 11 | .optimize = optimize, | 11 | .optimize = optimize, |
| 12 | .target = .{}, | 12 | .target = b.host, |
| 13 | }); | 13 | }); |
| 14 | foo.addCSourceFile(.{ .file = .{ .path = "foo.c" }, .flags = &[_][]const u8{} }); | 14 | foo.addCSourceFile(.{ .file = .{ .path = "foo.c" }, .flags = &[_][]const u8{} }); |
| 15 | foo.addIncludePath(.{ .path = "." }); | 15 | foo.addIncludePath(.{ .path = "." }); |
test/standalone/strip_empty_loop/build.zig+2-2| ... | @@ -5,15 +5,15 @@ pub fn build(b: *std.Build) void { | ... | @@ -5,15 +5,15 @@ pub fn build(b: *std.Build) void { |
| 5 | b.default_step = test_step; | 5 | b.default_step = test_step; |
| 6 | 6 | ||
| 7 | const optimize = std.builtin.OptimizeMode.Debug; | 7 | const optimize = std.builtin.OptimizeMode.Debug; |
| 8 | const target = std.zig.CrossTarget{}; | 8 | const target = b.host; |
| 9 | 9 | ||
| 10 | const main = b.addExecutable(.{ | 10 | const main = b.addExecutable(.{ |
| 11 | .name = "main", | 11 | .name = "main", |
| 12 | .root_source_file = .{ .path = "main.zig" }, | 12 | .root_source_file = .{ .path = "main.zig" }, |
| 13 | .optimize = optimize, | 13 | .optimize = optimize, |
| 14 | .target = target, | 14 | .target = target, |
| 15 | .strip = true, | ||
| 15 | }); | 16 | }); |
| 16 | main.strip = true; | ||
| 17 | 17 | ||
| 18 | // TODO: actually check the output | 18 | // TODO: actually check the output |
| 19 | _ = main.getEmittedBin(); | 19 | _ = main.getEmittedBin(); |
test/standalone/strip_struct_init/build.zig+1-1| ... | @@ -9,8 +9,8 @@ pub fn build(b: *std.Build) void { | ... | @@ -9,8 +9,8 @@ pub fn build(b: *std.Build) void { |
| 9 | const main = b.addTest(.{ | 9 | const main = b.addTest(.{ |
| 10 | .root_source_file = .{ .path = "main.zig" }, | 10 | .root_source_file = .{ .path = "main.zig" }, |
| 11 | .optimize = optimize, | 11 | .optimize = optimize, |
| 12 | .strip = true, | ||
| 12 | }); | 13 | }); |
| 13 | main.strip = true; | ||
| 14 | 14 | ||
| 15 | test_step.dependOn(&b.addRunArtifact(main).step); | 15 | test_step.dependOn(&b.addRunArtifact(main).step); |
| 16 | } | 16 | } |
test/standalone/test_runner_module_imports/build.zig+4-4| ... | @@ -6,13 +6,13 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,13 +6,13 @@ pub fn build(b: *std.Build) void { |
| 6 | .test_runner = "test_runner/main.zig", | 6 | .test_runner = "test_runner/main.zig", |
| 7 | }); | 7 | }); |
| 8 | 8 | ||
| 9 | const module1 = b.createModule(.{ .source_file = .{ .path = "module1/main.zig" } }); | 9 | const module1 = b.createModule(.{ .root_source_file = .{ .path = "module1/main.zig" } }); |
| 10 | const module2 = b.createModule(.{ | 10 | const module2 = b.createModule(.{ |
| 11 | .source_file = .{ .path = "module2/main.zig" }, | 11 | .root_source_file = .{ .path = "module2/main.zig" }, |
| 12 | .dependencies = &.{.{ .name = "module1", .module = module1 }}, | 12 | .imports = &.{.{ .name = "module1", .module = module1 }}, |
| 13 | }); | 13 | }); |
| 14 | 14 | ||
| 15 | t.addModule("module2", module2); | 15 | t.root_module.addImport("module2", module2); |
| 16 | 16 | ||
| 17 | const test_step = b.step("test", "Run unit tests"); | 17 | const test_step = b.step("test", "Run unit tests"); |
| 18 | test_step.dependOn(&b.addRunArtifact(t).step); | 18 | test_step.dependOn(&b.addRunArtifact(t).step); |
test/standalone/windows_resources/build.zig+10-6| ... | @@ -4,21 +4,25 @@ pub fn build(b: *std.Build) void { | ... | @@ -4,21 +4,25 @@ pub fn build(b: *std.Build) void { |
| 4 | const test_step = b.step("test", "Test it"); | 4 | const test_step = b.step("test", "Test it"); |
| 5 | b.default_step = test_step; | 5 | b.default_step = test_step; |
| 6 | 6 | ||
| 7 | const native_target: std.zig.CrossTarget = .{}; | 7 | const cross_target = b.resolveTargetQuery(.{ |
| 8 | const cross_target = .{ | ||
| 9 | .cpu_arch = .x86_64, | 8 | .cpu_arch = .x86_64, |
| 10 | .os_tag = .windows, | 9 | .os_tag = .windows, |
| 11 | .abi = .gnu, | 10 | .abi = .gnu, |
| 12 | }; | 11 | }); |
| 13 | 12 | ||
| 14 | add(b, native_target, .any, test_step); | 13 | add(b, b.host, .any, test_step); |
| 15 | add(b, cross_target, .any, test_step); | 14 | add(b, cross_target, .any, test_step); |
| 16 | 15 | ||
| 17 | add(b, native_target, .gnu, test_step); | 16 | add(b, b.host, .gnu, test_step); |
| 18 | add(b, cross_target, .gnu, test_step); | 17 | add(b, cross_target, .gnu, test_step); |
| 19 | } | 18 | } |
| 20 | 19 | ||
| 21 | fn add(b: *std.Build, target: std.zig.CrossTarget, rc_includes: enum { any, gnu }, test_step: *std.Build.Step) void { | 20 | fn add( |
| 21 | b: *std.Build, | ||
| 22 | target: std.Build.ResolvedTarget, | ||
| 23 | rc_includes: enum { any, gnu }, | ||
| 24 | test_step: *std.Build.Step, | ||
| 25 | ) void { | ||
| 22 | const exe = b.addExecutable(.{ | 26 | const exe = b.addExecutable(.{ |
| 23 | .name = "zig_resource_test", | 27 | .name = "zig_resource_test", |
| 24 | .root_source_file = .{ .path = "main.zig" }, | 28 | .root_source_file = .{ .path = "main.zig" }, |
test/standalone/windows_spawn/build.zig+1-1| ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { |
| 6 | b.default_step = test_step; | 6 | b.default_step = test_step; |
| 7 | 7 | ||
| 8 | const optimize: std.builtin.OptimizeMode = .Debug; | 8 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 9 | const target: std.zig.CrossTarget = .{}; | 9 | const target = b.host; |
| 10 | 10 | ||
| 11 | if (builtin.os.tag != .windows) return; | 11 | if (builtin.os.tag != .windows) return; |
| 12 | 12 |
test/standalone/zerolength_check/build.zig+2-2| ... | @@ -13,11 +13,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,11 +13,11 @@ pub fn build(b: *std.Build) void { |
| 13 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 13 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 14 | const unit_tests = b.addTest(.{ | 14 | const unit_tests = b.addTest(.{ |
| 15 | .root_source_file = .{ .path = "src/main.zig" }, | 15 | .root_source_file = .{ .path = "src/main.zig" }, |
| 16 | .target = .{ | 16 | .target = b.resolveTargetQuery(.{ |
| 17 | .os_tag = .wasi, | 17 | .os_tag = .wasi, |
| 18 | .cpu_arch = .wasm32, | 18 | .cpu_arch = .wasm32, |
| 19 | .cpu_features_add = std.Target.wasm.featureSet(&.{.bulk_memory}), | 19 | .cpu_features_add = std.Target.wasm.featureSet(&.{.bulk_memory}), |
| 20 | }, | 20 | }), |
| 21 | .optimize = optimize, | 21 | .optimize = optimize, |
| 22 | }); | 22 | }); |
| 23 | 23 |
test/tests.zig+34-35| ... | @@ -1,7 +1,6 @@ | ... | @@ -1,7 +1,6 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 4 | const CrossTarget = std.zig.CrossTarget; | ||
| 5 | const mem = std.mem; | 4 | const mem = std.mem; |
| 6 | const OptimizeMode = std.builtin.OptimizeMode; | 5 | const OptimizeMode = std.builtin.OptimizeMode; |
| 7 | const Step = std.Build.Step; | 6 | const Step = std.Build.Step; |
| ... | @@ -22,13 +21,13 @@ pub const CompareOutputContext = @import("src/CompareOutput.zig"); | ... | @@ -22,13 +21,13 @@ pub const CompareOutputContext = @import("src/CompareOutput.zig"); |
| 22 | pub const StackTracesContext = @import("src/StackTrace.zig"); | 21 | pub const StackTracesContext = @import("src/StackTrace.zig"); |
| 23 | 22 | ||
| 24 | const TestTarget = struct { | 23 | const TestTarget = struct { |
| 25 | target: CrossTarget = .{}, | 24 | target: std.zig.CrossTarget = .{}, |
| 26 | optimize_mode: std.builtin.OptimizeMode = .Debug, | 25 | optimize_mode: std.builtin.OptimizeMode = .Debug, |
| 27 | link_libc: ?bool = null, | 26 | link_libc: ?bool = null, |
| 28 | single_threaded: ?bool = null, | 27 | single_threaded: ?bool = null, |
| 29 | use_llvm: ?bool = null, | 28 | use_llvm: ?bool = null, |
| 30 | use_lld: ?bool = null, | 29 | use_lld: ?bool = null, |
| 31 | force_pic: ?bool = null, | 30 | pic: ?bool = null, |
| 32 | strip: ?bool = null, | 31 | strip: ?bool = null, |
| 33 | }; | 32 | }; |
| 34 | 33 | ||
| ... | @@ -105,7 +104,7 @@ const test_targets = blk: { | ... | @@ -105,7 +104,7 @@ const test_targets = blk: { |
| 105 | }, | 104 | }, |
| 106 | .use_llvm = false, | 105 | .use_llvm = false, |
| 107 | .use_lld = false, | 106 | .use_lld = false, |
| 108 | .force_pic = true, | 107 | .pic = true, |
| 109 | }, | 108 | }, |
| 110 | .{ | 109 | .{ |
| 111 | .target = .{ | 110 | .target = .{ |
| ... | @@ -146,7 +145,7 @@ const test_targets = blk: { | ... | @@ -146,7 +145,7 @@ const test_targets = blk: { |
| 146 | //}, | 145 | //}, |
| 147 | // https://github.com/ziglang/zig/issues/13623 | 146 | // https://github.com/ziglang/zig/issues/13623 |
| 148 | //.{ | 147 | //.{ |
| 149 | // .target = CrossTarget.parse(.{ | 148 | // .target = std.zig.CrossTarget.parse(.{ |
| 150 | // .arch_os_abi = "arm-linux-none", | 149 | // .arch_os_abi = "arm-linux-none", |
| 151 | // .cpu_features = "generic+v8a", | 150 | // .cpu_features = "generic+v8a", |
| 152 | // }) catch unreachable, | 151 | // }) catch unreachable, |
| ... | @@ -287,13 +286,13 @@ const test_targets = blk: { | ... | @@ -287,13 +286,13 @@ const test_targets = blk: { |
| 287 | }, | 286 | }, |
| 288 | 287 | ||
| 289 | .{ | 288 | .{ |
| 290 | .target = CrossTarget.parse(.{ | 289 | .target = std.zig.CrossTarget.parse(.{ |
| 291 | .arch_os_abi = "arm-linux-none", | 290 | .arch_os_abi = "arm-linux-none", |
| 292 | .cpu_features = "generic+v8a", | 291 | .cpu_features = "generic+v8a", |
| 293 | }) catch unreachable, | 292 | }) catch unreachable, |
| 294 | }, | 293 | }, |
| 295 | .{ | 294 | .{ |
| 296 | .target = CrossTarget.parse(.{ | 295 | .target = std.zig.CrossTarget.parse(.{ |
| 297 | .arch_os_abi = "arm-linux-musleabihf", | 296 | .arch_os_abi = "arm-linux-musleabihf", |
| 298 | .cpu_features = "generic+v8a", | 297 | .cpu_features = "generic+v8a", |
| 299 | }) catch unreachable, | 298 | }) catch unreachable, |
| ... | @@ -301,7 +300,7 @@ const test_targets = blk: { | ... | @@ -301,7 +300,7 @@ const test_targets = blk: { |
| 301 | }, | 300 | }, |
| 302 | // https://github.com/ziglang/zig/issues/3287 | 301 | // https://github.com/ziglang/zig/issues/3287 |
| 303 | //.{ | 302 | //.{ |
| 304 | // .target = CrossTarget.parse(.{ | 303 | // .target = std.zig.CrossTarget.parse(.{ |
| 305 | // .arch_os_abi = "arm-linux-gnueabihf", | 304 | // .arch_os_abi = "arm-linux-gnueabihf", |
| 306 | // .cpu_features = "generic+v8a", | 305 | // .cpu_features = "generic+v8a", |
| 307 | // }) catch unreachable, | 306 | // }) catch unreachable, |
| ... | @@ -495,10 +494,10 @@ const test_targets = blk: { | ... | @@ -495,10 +494,10 @@ const test_targets = blk: { |
| 495 | }; | 494 | }; |
| 496 | 495 | ||
| 497 | const CAbiTarget = struct { | 496 | const CAbiTarget = struct { |
| 498 | target: CrossTarget = .{}, | 497 | target: std.zig.CrossTarget = .{}, |
| 499 | use_llvm: ?bool = null, | 498 | use_llvm: ?bool = null, |
| 500 | use_lld: ?bool = null, | 499 | use_lld: ?bool = null, |
| 501 | force_pic: ?bool = null, | 500 | pic: ?bool = null, |
| 502 | strip: ?bool = null, | 501 | strip: ?bool = null, |
| 503 | c_defines: []const []const u8 = &.{}, | 502 | c_defines: []const []const u8 = &.{}, |
| 504 | }; | 503 | }; |
| ... | @@ -543,7 +542,7 @@ const c_abi_targets = [_]CAbiTarget{ | ... | @@ -543,7 +542,7 @@ const c_abi_targets = [_]CAbiTarget{ |
| 543 | }, | 542 | }, |
| 544 | .use_llvm = false, | 543 | .use_llvm = false, |
| 545 | .use_lld = false, | 544 | .use_lld = false, |
| 546 | .force_pic = true, | 545 | .pic = true, |
| 547 | .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"}, | 546 | .c_defines = &.{"ZIG_BACKEND_STAGE2_X86_64"}, |
| 548 | }, | 547 | }, |
| 549 | .{ | 548 | .{ |
| ... | @@ -645,7 +644,7 @@ pub fn addStackTraceTests( | ... | @@ -645,7 +644,7 @@ pub fn addStackTraceTests( |
| 645 | const check_exe = b.addExecutable(.{ | 644 | const check_exe = b.addExecutable(.{ |
| 646 | .name = "check-stack-trace", | 645 | .name = "check-stack-trace", |
| 647 | .root_source_file = .{ .path = "test/src/check-stack-trace.zig" }, | 646 | .root_source_file = .{ .path = "test/src/check-stack-trace.zig" }, |
| 648 | .target = .{}, | 647 | .target = b.host, |
| 649 | .optimize = .Debug, | 648 | .optimize = .Debug, |
| 650 | }); | 649 | }); |
| 651 | 650 | ||
| ... | @@ -682,12 +681,14 @@ pub fn addStandaloneTests( | ... | @@ -682,12 +681,14 @@ pub fn addStandaloneTests( |
| 682 | if (os_tag != builtin.os.tag) continue; | 681 | if (os_tag != builtin.os.tag) continue; |
| 683 | } | 682 | } |
| 684 | 683 | ||
| 684 | const resolved_target = b.resolveTargetQuery(case.target); | ||
| 685 | |||
| 685 | if (case.is_exe) { | 686 | if (case.is_exe) { |
| 686 | const exe = b.addExecutable(.{ | 687 | const exe = b.addExecutable(.{ |
| 687 | .name = std.fs.path.stem(case.src_path), | 688 | .name = std.fs.path.stem(case.src_path), |
| 688 | .root_source_file = .{ .path = case.src_path }, | 689 | .root_source_file = .{ .path = case.src_path }, |
| 689 | .optimize = optimize, | 690 | .optimize = optimize, |
| 690 | .target = case.target, | 691 | .target = resolved_target, |
| 691 | }); | 692 | }); |
| 692 | if (case.link_libc) exe.linkLibC(); | 693 | if (case.link_libc) exe.linkLibC(); |
| 693 | 694 | ||
| ... | @@ -701,7 +702,7 @@ pub fn addStandaloneTests( | ... | @@ -701,7 +702,7 @@ pub fn addStandaloneTests( |
| 701 | .name = std.fs.path.stem(case.src_path), | 702 | .name = std.fs.path.stem(case.src_path), |
| 702 | .root_source_file = .{ .path = case.src_path }, | 703 | .root_source_file = .{ .path = case.src_path }, |
| 703 | .optimize = optimize, | 704 | .optimize = optimize, |
| 704 | .target = case.target, | 705 | .target = resolved_target, |
| 705 | }); | 706 | }); |
| 706 | if (case.link_libc) exe.linkLibC(); | 707 | if (case.link_libc) exe.linkLibC(); |
| 707 | 708 | ||
| ... | @@ -1001,7 +1002,7 @@ pub fn addTranslateCTests(b: *std.Build, test_filter: ?[]const u8) *Step { | ... | @@ -1001,7 +1002,7 @@ pub fn addTranslateCTests(b: *std.Build, test_filter: ?[]const u8) *Step { |
| 1001 | pub fn addRunTranslatedCTests( | 1002 | pub fn addRunTranslatedCTests( |
| 1002 | b: *std.Build, | 1003 | b: *std.Build, |
| 1003 | test_filter: ?[]const u8, | 1004 | test_filter: ?[]const u8, |
| 1004 | target: std.zig.CrossTarget, | 1005 | target: std.Build.ResolvedTarget, |
| 1005 | ) *Step { | 1006 | ) *Step { |
| 1006 | const cases = b.allocator.create(RunTranslatedCContext) catch @panic("OOM"); | 1007 | const cases = b.allocator.create(RunTranslatedCContext) catch @panic("OOM"); |
| 1007 | cases.* = .{ | 1008 | cases.* = .{ |
| ... | @@ -1105,7 +1106,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { | ... | @@ -1105,7 +1106,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1105 | const these_tests = b.addTest(.{ | 1106 | const these_tests = b.addTest(.{ |
| 1106 | .root_source_file = .{ .path = options.root_src }, | 1107 | .root_source_file = .{ .path = options.root_src }, |
| 1107 | .optimize = test_target.optimize_mode, | 1108 | .optimize = test_target.optimize_mode, |
| 1108 | .target = test_target.target, | 1109 | .target = b.resolveTargetQuery(test_target.target), |
| 1109 | .max_rss = max_rss, | 1110 | .max_rss = max_rss, |
| 1110 | .filter = options.test_filter, | 1111 | .filter = options.test_filter, |
| 1111 | .link_libc = test_target.link_libc, | 1112 | .link_libc = test_target.link_libc, |
| ... | @@ -1113,9 +1114,9 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { | ... | @@ -1113,9 +1114,9 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1113 | .use_llvm = test_target.use_llvm, | 1114 | .use_llvm = test_target.use_llvm, |
| 1114 | .use_lld = test_target.use_lld, | 1115 | .use_lld = test_target.use_lld, |
| 1115 | .zig_lib_dir = .{ .path = "lib" }, | 1116 | .zig_lib_dir = .{ .path = "lib" }, |
| 1117 | .pic = test_target.pic, | ||
| 1118 | .strip = test_target.strip, | ||
| 1116 | }); | 1119 | }); |
| 1117 | these_tests.force_pic = test_target.force_pic; | ||
| 1118 | these_tests.strip = test_target.strip; | ||
| 1119 | const single_threaded_suffix = if (test_target.single_threaded == true) "-single" else ""; | 1120 | const single_threaded_suffix = if (test_target.single_threaded == true) "-single" else ""; |
| 1120 | const backend_suffix = if (test_target.use_llvm == true) | 1121 | const backend_suffix = if (test_target.use_llvm == true) |
| 1121 | "-llvm" | 1122 | "-llvm" |
| ... | @@ -1126,7 +1127,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { | ... | @@ -1126,7 +1127,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1126 | else | 1127 | else |
| 1127 | ""; | 1128 | ""; |
| 1128 | const use_lld = if (test_target.use_lld == false) "-no-lld" else ""; | 1129 | const use_lld = if (test_target.use_lld == false) "-no-lld" else ""; |
| 1129 | const use_pic = if (test_target.force_pic == true) "-pic" else ""; | 1130 | const use_pic = if (test_target.pic == true) "-pic" else ""; |
| 1130 | 1131 | ||
| 1131 | these_tests.addIncludePath(.{ .path = "test" }); | 1132 | these_tests.addIncludePath(.{ .path = "test" }); |
| 1132 | 1133 | ||
| ... | @@ -1154,7 +1155,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { | ... | @@ -1154,7 +1155,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1154 | const compile_c = b.addExecutable(.{ | 1155 | const compile_c = b.addExecutable(.{ |
| 1155 | .name = qualified_name, | 1156 | .name = qualified_name, |
| 1156 | .link_libc = test_target.link_libc, | 1157 | .link_libc = test_target.link_libc, |
| 1157 | .target = altered_target, | 1158 | .target = b.resolveTargetQuery(altered_target), |
| 1158 | .zig_lib_dir = .{ .path = "lib" }, | 1159 | .zig_lib_dir = .{ .path = "lib" }, |
| 1159 | }); | 1160 | }); |
| 1160 | compile_c.addCSourceFile(.{ | 1161 | compile_c.addCSourceFile(.{ |
| ... | @@ -1229,41 +1230,39 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S | ... | @@ -1229,41 +1230,39 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S |
| 1229 | for (c_abi_targets) |c_abi_target| { | 1230 | for (c_abi_targets) |c_abi_target| { |
| 1230 | if (skip_non_native and !c_abi_target.target.isNative()) continue; | 1231 | if (skip_non_native and !c_abi_target.target.isNative()) continue; |
| 1231 | 1232 | ||
| 1232 | if (c_abi_target.target.isWindows() and c_abi_target.target.getCpuArch() == .aarch64) { | 1233 | const resolved_target = b.resolveTargetQuery(c_abi_target.target); |
| 1234 | const target = resolved_target.target; | ||
| 1235 | |||
| 1236 | if (target.os.tag == .windows and target.cpu.arch == .aarch64) { | ||
| 1233 | // https://github.com/ziglang/zig/issues/14908 | 1237 | // https://github.com/ziglang/zig/issues/14908 |
| 1234 | continue; | 1238 | continue; |
| 1235 | } | 1239 | } |
| 1236 | 1240 | ||
| 1237 | const test_step = b.addTest(.{ | 1241 | const test_step = b.addTest(.{ |
| 1238 | .name = b.fmt("test-c-abi-{s}-{s}-{s}{s}{s}{s}", .{ | 1242 | .name = b.fmt("test-c-abi-{s}-{s}-{s}{s}{s}{s}", .{ |
| 1239 | c_abi_target.target.zigTriple(b.allocator) catch @panic("OOM"), | 1243 | target.zigTriple(b.allocator) catch @panic("OOM"), |
| 1240 | c_abi_target.target.getCpuModel().name, | 1244 | target.cpu.model.name, |
| 1241 | @tagName(optimize_mode), | 1245 | @tagName(optimize_mode), |
| 1242 | if (c_abi_target.use_llvm == true) | 1246 | if (c_abi_target.use_llvm == true) |
| 1243 | "-llvm" | 1247 | "-llvm" |
| 1244 | else if (c_abi_target.target.ofmt == std.Target.ObjectFormat.c) | 1248 | else if (target.ofmt == .c) |
| 1245 | "-cbe" | 1249 | "-cbe" |
| 1246 | else if (c_abi_target.use_llvm == false) | 1250 | else if (c_abi_target.use_llvm == false) |
| 1247 | "-selfhosted" | 1251 | "-selfhosted" |
| 1248 | else | 1252 | else |
| 1249 | "", | 1253 | "", |
| 1250 | if (c_abi_target.use_lld == false) "-no-lld" else "", | 1254 | if (c_abi_target.use_lld == false) "-no-lld" else "", |
| 1251 | if (c_abi_target.force_pic == true) "-pic" else "", | 1255 | if (c_abi_target.pic == true) "-pic" else "", |
| 1252 | }), | 1256 | }), |
| 1253 | .root_source_file = .{ .path = "test/c_abi/main.zig" }, | 1257 | .root_source_file = .{ .path = "test/c_abi/main.zig" }, |
| 1254 | .target = c_abi_target.target, | 1258 | .target = resolved_target, |
| 1255 | .optimize = optimize_mode, | 1259 | .optimize = optimize_mode, |
| 1256 | .link_libc = true, | 1260 | .link_libc = true, |
| 1257 | .use_llvm = c_abi_target.use_llvm, | 1261 | .use_llvm = c_abi_target.use_llvm, |
| 1258 | .use_lld = c_abi_target.use_lld, | 1262 | .use_lld = c_abi_target.use_lld, |
| 1263 | .pic = c_abi_target.pic, | ||
| 1264 | .strip = c_abi_target.strip, | ||
| 1259 | }); | 1265 | }); |
| 1260 | test_step.force_pic = c_abi_target.force_pic; | ||
| 1261 | test_step.strip = c_abi_target.strip; | ||
| 1262 | if (c_abi_target.target.abi != null and c_abi_target.target.abi.?.isMusl()) { | ||
| 1263 | // TODO NativeTargetInfo insists on dynamically linking musl | ||
| 1264 | // for some reason? | ||
| 1265 | test_step.target_info.dynamic_linker.max_byte = null; | ||
| 1266 | } | ||
| 1267 | test_step.addCSourceFile(.{ | 1266 | test_step.addCSourceFile(.{ |
| 1268 | .file = .{ .path = "test/c_abi/cfuncs.c" }, | 1267 | .file = .{ .path = "test/c_abi/cfuncs.c" }, |
| 1269 | .flags = &.{"-std=c99"}, | 1268 | .flags = &.{"-std=c99"}, |
| ... | @@ -1297,8 +1296,8 @@ pub fn addCases( | ... | @@ -1297,8 +1296,8 @@ pub fn addCases( |
| 1297 | var dir = try b.build_root.handle.openDir("test/cases", .{ .iterate = true }); | 1296 | var dir = try b.build_root.handle.openDir("test/cases", .{ .iterate = true }); |
| 1298 | defer dir.close(); | 1297 | defer dir.close(); |
| 1299 | 1298 | ||
| 1300 | cases.addFromDir(dir); | 1299 | cases.addFromDir(dir, b); |
| 1301 | try @import("cases.zig").addCases(&cases, build_options); | 1300 | try @import("cases.zig").addCases(&cases, build_options, b); |
| 1302 | 1301 | ||
| 1303 | const cases_dir_path = try b.build_root.join(b.allocator, &.{ "test", "cases" }); | 1302 | const cases_dir_path = try b.build_root.join(b.allocator, &.{ "test", "cases" }); |
| 1304 | cases.lowerToBuildSteps( | 1303 | cases.lowerToBuildSteps( |