| author | |
| committer | |
| log | 12d64c456b7590b1486717232f77c6d3700813a6 |
| tree | ca604dbab15963d63216650d77d76f14c6156e91 |
| parent | debba652a3f5af76840517321d389a2ec98a88f4 |
| parent | afc77f0603395d9c1829a49081e198b0fa255abc |
| signature |
std.Build: add new functions to create artifacts/Step.Compile from existing module95 files changed, 1775 insertions(+), 1370 deletions(-)
build.zig+86-74| ... | @@ -50,10 +50,12 @@ pub fn build(b: *std.Build) !void { | ... | @@ -50,10 +50,12 @@ pub fn build(b: *std.Build) !void { |
| 50 | 50 | ||
| 51 | const autodoc_test = b.addObject(.{ | 51 | const autodoc_test = b.addObject(.{ |
| 52 | .name = "std", | 52 | .name = "std", |
| 53 | .root_source_file = b.path("lib/std/std.zig"), | ||
| 54 | .target = target, | ||
| 55 | .zig_lib_dir = b.path("lib"), | 53 | .zig_lib_dir = b.path("lib"), |
| 56 | .optimize = .Debug, | 54 | .root_module = b.createModule(.{ |
| 55 | .root_source_file = b.path("lib/std/std.zig"), | ||
| 56 | .target = target, | ||
| 57 | .optimize = .Debug, | ||
| 58 | }), | ||
| 57 | }); | 59 | }); |
| 58 | const install_std_docs = b.addInstallDirectory(.{ | 60 | const install_std_docs = b.addInstallDirectory(.{ |
| 59 | .source_dir = autodoc_test.getEmittedDocs(), | 61 | .source_dir = autodoc_test.getEmittedDocs(), |
| ... | @@ -234,7 +236,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -234,7 +236,7 @@ pub fn build(b: *std.Build) !void { |
| 234 | exe_options.addOption(DevEnv, "dev", b.option(DevEnv, "dev", "Build a compiler with a reduced feature set for development of specific features") orelse if (only_c) .bootstrap else .full); | 236 | exe_options.addOption(DevEnv, "dev", b.option(DevEnv, "dev", "Build a compiler with a reduced feature set for development of specific features") orelse if (only_c) .bootstrap else .full); |
| 235 | 237 | ||
| 236 | if (link_libc) { | 238 | if (link_libc) { |
| 237 | exe.linkLibC(); | 239 | exe.root_module.link_libc = true; |
| 238 | } | 240 | } |
| 239 | 241 | ||
| 240 | const is_debug = optimize == .Debug; | 242 | const is_debug = optimize == .Debug; |
| ... | @@ -330,15 +332,15 @@ pub fn build(b: *std.Build) !void { | ... | @@ -330,15 +332,15 @@ pub fn build(b: *std.Build) !void { |
| 330 | try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx); | 332 | try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx); |
| 331 | } else { | 333 | } else { |
| 332 | // Here we are -Denable-llvm but no cmake integration. | 334 | // Here we are -Denable-llvm but no cmake integration. |
| 333 | try addStaticLlvmOptionsToExe(exe); | 335 | try addStaticLlvmOptionsToModule(exe.root_module); |
| 334 | } | 336 | } |
| 335 | if (target.result.os.tag == .windows) { | 337 | if (target.result.os.tag == .windows) { |
| 336 | // LLVM depends on networking as of version 18. | 338 | // LLVM depends on networking as of version 18. |
| 337 | exe.linkSystemLibrary("ws2_32"); | 339 | exe.root_module.linkSystemLibrary("ws2_32", .{}); |
| 338 | 340 | ||
| 339 | exe.linkSystemLibrary("version"); | 341 | exe.root_module.linkSystemLibrary("version", .{}); |
| 340 | exe.linkSystemLibrary("uuid"); | 342 | exe.root_module.linkSystemLibrary("uuid", .{}); |
| 341 | exe.linkSystemLibrary("ole32"); | 343 | exe.root_module.linkSystemLibrary("ole32", .{}); |
| 342 | } | 344 | } |
| 343 | } | 345 | } |
| 344 | 346 | ||
| ... | @@ -364,16 +366,16 @@ pub fn build(b: *std.Build) !void { | ... | @@ -364,16 +366,16 @@ pub fn build(b: *std.Build) !void { |
| 364 | else | 366 | else |
| 365 | &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }; | 367 | &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }; |
| 366 | 368 | ||
| 367 | exe.addIncludePath(.{ .cwd_relative = tracy_path }); | 369 | exe.root_module.addIncludePath(.{ .cwd_relative = tracy_path }); |
| 368 | exe.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags }); | 370 | exe.root_module.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags }); |
| 369 | if (!enable_llvm) { | 371 | if (!enable_llvm) { |
| 370 | exe.root_module.linkSystemLibrary("c++", .{ .use_pkg_config = .no }); | 372 | exe.root_module.linkSystemLibrary("c++", .{ .use_pkg_config = .no }); |
| 371 | } | 373 | } |
| 372 | exe.linkLibC(); | 374 | exe.root_module.link_libc = true; |
| 373 | 375 | ||
| 374 | if (target.result.os.tag == .windows) { | 376 | if (target.result.os.tag == .windows) { |
| 375 | exe.linkSystemLibrary("dbghelp"); | 377 | exe.root_module.linkSystemLibrary("dbghelp", .{}); |
| 376 | exe.linkSystemLibrary("ws2_32"); | 378 | exe.root_module.linkSystemLibrary("ws2_32", .{}); |
| 377 | } | 379 | } |
| 378 | } | 380 | } |
| 379 | 381 | ||
| ... | @@ -559,8 +561,10 @@ pub fn build(b: *std.Build) !void { | ... | @@ -559,8 +561,10 @@ pub fn build(b: *std.Build) !void { |
| 559 | if (opt_mingw_src_path) |mingw_src_path| { | 561 | if (opt_mingw_src_path) |mingw_src_path| { |
| 560 | const update_mingw_exe = b.addExecutable(.{ | 562 | const update_mingw_exe = b.addExecutable(.{ |
| 561 | .name = "update_mingw", | 563 | .name = "update_mingw", |
| 562 | .target = b.graph.host, | 564 | .root_module = b.createModule(.{ |
| 563 | .root_source_file = b.path("tools/update_mingw.zig"), | 565 | .target = b.graph.host, |
| 566 | .root_source_file = b.path("tools/update_mingw.zig"), | ||
| 567 | }), | ||
| 564 | }); | 568 | }); |
| 565 | const update_mingw_run = b.addRunArtifact(update_mingw_exe); | 569 | const update_mingw_run = b.addRunArtifact(update_mingw_exe); |
| 566 | update_mingw_run.addDirectoryArg(b.path("lib")); | 570 | update_mingw_run.addDirectoryArg(b.path("lib")); |
| ... | @@ -636,12 +640,10 @@ const AddCompilerStepOptions = struct { | ... | @@ -636,12 +640,10 @@ const AddCompilerStepOptions = struct { |
| 636 | }; | 640 | }; |
| 637 | 641 | ||
| 638 | fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.Step.Compile { | 642 | fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.Step.Compile { |
| 639 | const exe = b.addExecutable(.{ | 643 | const compiler_mod = b.createModule(.{ |
| 640 | .name = "zig", | ||
| 641 | .root_source_file = b.path("src/main.zig"), | 644 | .root_source_file = b.path("src/main.zig"), |
| 642 | .target = options.target, | 645 | .target = options.target, |
| 643 | .optimize = options.optimize, | 646 | .optimize = options.optimize, |
| 644 | .max_rss = 7_800_000_000, | ||
| 645 | .strip = options.strip, | 647 | .strip = options.strip, |
| 646 | .sanitize_thread = options.sanitize_thread, | 648 | .sanitize_thread = options.sanitize_thread, |
| 647 | .single_threaded = options.single_threaded, | 649 | .single_threaded = options.single_threaded, |
| ... | @@ -663,26 +665,28 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St | ... | @@ -663,26 +665,28 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St |
| 663 | .loongarch32, .loongarch64 => .medium, | 665 | .loongarch32, .loongarch64 => .medium, |
| 664 | else => .default, | 666 | else => .default, |
| 665 | }, | 667 | }, |
| 668 | .valgrind = options.valgrind, | ||
| 666 | }); | 669 | }); |
| 667 | exe.root_module.valgrind = options.valgrind; | ||
| 668 | exe.stack_size = stack_size; | ||
| 669 | 670 | ||
| 670 | const aro_module = b.createModule(.{ | 671 | const aro_mod = b.createModule(.{ |
| 671 | .root_source_file = b.path("lib/compiler/aro/aro.zig"), | 672 | .root_source_file = b.path("lib/compiler/aro/aro.zig"), |
| 672 | }); | 673 | }); |
| 673 | 674 | ||
| 674 | const aro_translate_c_module = b.createModule(.{ | 675 | const aro_translate_c_mod = b.createModule(.{ |
| 675 | .root_source_file = b.path("lib/compiler/aro_translate_c.zig"), | 676 | .root_source_file = b.path("lib/compiler/aro_translate_c.zig"), |
| 676 | .imports = &.{ | ||
| 677 | .{ | ||
| 678 | .name = "aro", | ||
| 679 | .module = aro_module, | ||
| 680 | }, | ||
| 681 | }, | ||
| 682 | }); | 677 | }); |
| 683 | 678 | ||
| 684 | exe.root_module.addImport("aro", aro_module); | 679 | aro_translate_c_mod.addImport("aro", aro_mod); |
| 685 | exe.root_module.addImport("aro_translate_c", aro_translate_c_module); | 680 | compiler_mod.addImport("aro", aro_mod); |
| 681 | compiler_mod.addImport("aro_translate_c", aro_translate_c_mod); | ||
| 682 | |||
| 683 | const exe = b.addExecutable(.{ | ||
| 684 | .name = "zig", | ||
| 685 | .max_rss = 7_800_000_000, | ||
| 686 | .root_module = compiler_mod, | ||
| 687 | }); | ||
| 688 | exe.stack_size = stack_size; | ||
| 689 | |||
| 686 | return exe; | 690 | return exe; |
| 687 | } | 691 | } |
| 688 | 692 | ||
| ... | @@ -707,11 +711,15 @@ fn addCmakeCfgOptionsToExe( | ... | @@ -707,11 +711,15 @@ fn addCmakeCfgOptionsToExe( |
| 707 | exe: *std.Build.Step.Compile, | 711 | exe: *std.Build.Step.Compile, |
| 708 | use_zig_libcxx: bool, | 712 | use_zig_libcxx: bool, |
| 709 | ) !void { | 713 | ) !void { |
| 710 | if (exe.rootModuleTarget().isDarwin()) { | 714 | const mod = exe.root_module; |
| 715 | const target = mod.resolved_target.?.result; | ||
| 716 | |||
| 717 | if (target.isDarwin()) { | ||
| 711 | // useful for package maintainers | 718 | // useful for package maintainers |
| 712 | exe.headerpad_max_install_names = true; | 719 | exe.headerpad_max_install_names = true; |
| 713 | } | 720 | } |
| 714 | exe.addObjectFile(.{ .cwd_relative = b.pathJoin(&[_][]const u8{ | 721 | |
| 722 | mod.addObjectFile(.{ .cwd_relative = b.pathJoin(&.{ | ||
| 715 | cfg.cmake_binary_dir, | 723 | cfg.cmake_binary_dir, |
| 716 | "zigcpp", | 724 | "zigcpp", |
| 717 | b.fmt("{s}{s}{s}", .{ | 725 | b.fmt("{s}{s}{s}", .{ |
| ... | @@ -721,38 +729,38 @@ fn addCmakeCfgOptionsToExe( | ... | @@ -721,38 +729,38 @@ fn addCmakeCfgOptionsToExe( |
| 721 | }), | 729 | }), |
| 722 | }) }); | 730 | }) }); |
| 723 | assert(cfg.lld_include_dir.len != 0); | 731 | assert(cfg.lld_include_dir.len != 0); |
| 724 | exe.addIncludePath(.{ .cwd_relative = cfg.lld_include_dir }); | 732 | mod.addIncludePath(.{ .cwd_relative = cfg.lld_include_dir }); |
| 725 | exe.addIncludePath(.{ .cwd_relative = cfg.llvm_include_dir }); | 733 | mod.addIncludePath(.{ .cwd_relative = cfg.llvm_include_dir }); |
| 726 | exe.addLibraryPath(.{ .cwd_relative = cfg.llvm_lib_dir }); | 734 | mod.addLibraryPath(.{ .cwd_relative = cfg.llvm_lib_dir }); |
| 727 | addCMakeLibraryList(exe, cfg.clang_libraries); | 735 | addCMakeLibraryList(mod, cfg.clang_libraries); |
| 728 | addCMakeLibraryList(exe, cfg.lld_libraries); | 736 | addCMakeLibraryList(mod, cfg.lld_libraries); |
| 729 | addCMakeLibraryList(exe, cfg.llvm_libraries); | 737 | addCMakeLibraryList(mod, cfg.llvm_libraries); |
| 730 | 738 | ||
| 731 | if (use_zig_libcxx) { | 739 | if (use_zig_libcxx) { |
| 732 | exe.linkLibCpp(); | 740 | mod.link_libcpp = true; |
| 733 | } else { | 741 | } else { |
| 734 | // System -lc++ must be used because in this code path we are attempting to link | 742 | // System -lc++ must be used because in this code path we are attempting to link |
| 735 | // against system-provided LLVM, Clang, LLD. | 743 | // against system-provided LLVM, Clang, LLD. |
| 736 | const need_cpp_includes = true; | 744 | const need_cpp_includes = true; |
| 737 | const static = cfg.llvm_linkage == .static; | 745 | const static = cfg.llvm_linkage == .static; |
| 738 | const lib_suffix = if (static) exe.rootModuleTarget().staticLibSuffix()[1..] else exe.rootModuleTarget().dynamicLibSuffix()[1..]; | 746 | const lib_suffix = if (static) target.staticLibSuffix()[1..] else target.dynamicLibSuffix()[1..]; |
| 739 | switch (exe.rootModuleTarget().os.tag) { | 747 | switch (target.os.tag) { |
| 740 | .linux => { | 748 | .linux => { |
| 741 | // First we try to link against the detected libcxx name. If that doesn't work, we fall | 749 | // First we try to link against the detected libcxx name. If that doesn't work, we fall |
| 742 | // back to -lc++ and cross our fingers. | 750 | // back to -lc++ and cross our fingers. |
| 743 | addCxxKnownPath(b, cfg, exe, b.fmt("lib{s}.{s}", .{ cfg.system_libcxx, lib_suffix }), "", need_cpp_includes) catch |err| switch (err) { | 751 | addCxxKnownPath(b, cfg, exe, b.fmt("lib{s}.{s}", .{ cfg.system_libcxx, lib_suffix }), "", need_cpp_includes) catch |err| switch (err) { |
| 744 | error.RequiredLibraryNotFound => { | 752 | error.RequiredLibraryNotFound => { |
| 745 | exe.linkLibCpp(); | 753 | mod.link_libcpp = true; |
| 746 | }, | 754 | }, |
| 747 | else => |e| return e, | 755 | else => |e| return e, |
| 748 | }; | 756 | }; |
| 749 | exe.linkSystemLibrary("unwind"); | 757 | mod.linkSystemLibrary("unwind", .{}); |
| 750 | }, | 758 | }, |
| 751 | .ios, .macos, .watchos, .tvos, .visionos => { | 759 | .ios, .macos, .watchos, .tvos, .visionos => { |
| 752 | exe.linkLibCpp(); | 760 | mod.link_libcpp = true; |
| 753 | }, | 761 | }, |
| 754 | .windows => { | 762 | .windows => { |
| 755 | if (exe.rootModuleTarget().abi != .msvc) exe.linkLibCpp(); | 763 | if (target.abi != .msvc) mod.link_libcpp = true; |
| 756 | }, | 764 | }, |
| 757 | .freebsd => { | 765 | .freebsd => { |
| 758 | if (static) { | 766 | if (static) { |
| ... | @@ -786,46 +794,46 @@ fn addCmakeCfgOptionsToExe( | ... | @@ -786,46 +794,46 @@ fn addCmakeCfgOptionsToExe( |
| 786 | } | 794 | } |
| 787 | 795 | ||
| 788 | if (cfg.dia_guids_lib.len != 0) { | 796 | if (cfg.dia_guids_lib.len != 0) { |
| 789 | exe.addObjectFile(.{ .cwd_relative = cfg.dia_guids_lib }); | 797 | mod.addObjectFile(.{ .cwd_relative = cfg.dia_guids_lib }); |
| 790 | } | 798 | } |
| 791 | } | 799 | } |
| 792 | 800 | ||
| 793 | fn addStaticLlvmOptionsToExe(exe: *std.Build.Step.Compile) !void { | 801 | fn addStaticLlvmOptionsToModule(mod: *std.Build.Module) !void { |
| 794 | // Adds the Zig C++ sources which both stage1 and stage2 need. | 802 | // Adds the Zig C++ sources which both stage1 and stage2 need. |
| 795 | // | 803 | // |
| 796 | // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling | 804 | // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling |
| 797 | // in a dependency on llvm::cfg::Update<llvm::BasicBlock*>::dump() which is | 805 | // in a dependency on llvm::cfg::Update<llvm::BasicBlock*>::dump() which is |
| 798 | // unavailable when LLVM is compiled in Release mode. | 806 | // unavailable when LLVM is compiled in Release mode. |
| 799 | const zig_cpp_cflags = exe_cflags ++ [_][]const u8{"-DNDEBUG=1"}; | 807 | const zig_cpp_cflags = exe_cflags ++ [_][]const u8{"-DNDEBUG=1"}; |
| 800 | exe.addCSourceFiles(.{ | 808 | mod.addCSourceFiles(.{ |
| 801 | .files = &zig_cpp_sources, | 809 | .files = &zig_cpp_sources, |
| 802 | .flags = &zig_cpp_cflags, | 810 | .flags = &zig_cpp_cflags, |
| 803 | }); | 811 | }); |
| 804 | 812 | ||
| 805 | for (clang_libs) |lib_name| { | 813 | for (clang_libs) |lib_name| { |
| 806 | exe.linkSystemLibrary(lib_name); | 814 | mod.linkSystemLibrary(lib_name, .{}); |
| 807 | } | 815 | } |
| 808 | 816 | ||
| 809 | for (lld_libs) |lib_name| { | 817 | for (lld_libs) |lib_name| { |
| 810 | exe.linkSystemLibrary(lib_name); | 818 | mod.linkSystemLibrary(lib_name, .{}); |
| 811 | } | 819 | } |
| 812 | 820 | ||
| 813 | for (llvm_libs) |lib_name| { | 821 | for (llvm_libs) |lib_name| { |
| 814 | exe.linkSystemLibrary(lib_name); | 822 | mod.linkSystemLibrary(lib_name, .{}); |
| 815 | } | 823 | } |
| 816 | 824 | ||
| 817 | exe.linkSystemLibrary("z"); | 825 | mod.linkSystemLibrary("z", .{}); |
| 818 | exe.linkSystemLibrary("zstd"); | 826 | mod.linkSystemLibrary("zstd", .{}); |
| 819 | 827 | ||
| 820 | if (exe.rootModuleTarget().os.tag != .windows or exe.rootModuleTarget().abi != .msvc) { | 828 | if (mod.resolved_target.?.result.os.tag != .windows or mod.resolved_target.?.result.abi != .msvc) { |
| 821 | // This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries. | 829 | // This means we rely on clang-or-zig-built LLVM, Clang, LLD libraries. |
| 822 | exe.linkSystemLibrary("c++"); | 830 | mod.linkSystemLibrary("c++", .{}); |
| 823 | } | 831 | } |
| 824 | 832 | ||
| 825 | if (exe.rootModuleTarget().os.tag == .windows) { | 833 | if (mod.resolved_target.?.result.os.tag == .windows) { |
| 826 | exe.linkSystemLibrary("version"); | 834 | mod.linkSystemLibrary("version", .{}); |
| 827 | exe.linkSystemLibrary("uuid"); | 835 | mod.linkSystemLibrary("uuid", .{}); |
| 828 | exe.linkSystemLibrary("ole32"); | 836 | mod.linkSystemLibrary("ole32", .{}); |
| 829 | } | 837 | } |
| 830 | } | 838 | } |
| 831 | 839 | ||
| ... | @@ -862,29 +870,29 @@ fn addCxxKnownPath( | ... | @@ -862,29 +870,29 @@ fn addCxxKnownPath( |
| 862 | // but libc++ may very well be one, so force all inputs to be checked when passing | 870 | // but libc++ may very well be one, so force all inputs to be checked when passing |
| 863 | // an explicit path to libc++. | 871 | // an explicit path to libc++. |
| 864 | exe.allow_so_scripts = true; | 872 | exe.allow_so_scripts = true; |
| 865 | exe.addObjectFile(.{ .cwd_relative = path_unpadded }); | 873 | exe.root_module.addObjectFile(.{ .cwd_relative = path_unpadded }); |
| 866 | 874 | ||
| 867 | // TODO a way to integrate with system c++ include files here | 875 | // TODO a way to integrate with system c++ include files here |
| 868 | // c++ -E -Wp,-v -xc++ /dev/null | 876 | // c++ -E -Wp,-v -xc++ /dev/null |
| 869 | if (need_cpp_includes) { | 877 | if (need_cpp_includes) { |
| 870 | // I used these temporarily for testing something but we obviously need a | 878 | // I used these temporarily for testing something but we obviously need a |
| 871 | // more general purpose solution here. | 879 | // more general purpose solution here. |
| 872 | //exe.addIncludePath("/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/include/c++/11.3.0"); | 880 | //exe.root_module.addIncludePath("/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/include/c++/11.3.0"); |
| 873 | //exe.addIncludePath("/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/include/c++/11.3.0/x86_64-unknown-linux-gnu"); | 881 | //exe.root_module.addIncludePath("/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/include/c++/11.3.0/x86_64-unknown-linux-gnu"); |
| 874 | } | 882 | } |
| 875 | } | 883 | } |
| 876 | 884 | ||
| 877 | fn addCMakeLibraryList(exe: *std.Build.Step.Compile, list: []const u8) void { | 885 | fn addCMakeLibraryList(mod: *std.Build.Module, list: []const u8) void { |
| 878 | var it = mem.tokenizeScalar(u8, list, ';'); | 886 | var it = mem.tokenizeScalar(u8, list, ';'); |
| 879 | while (it.next()) |lib| { | 887 | while (it.next()) |lib| { |
| 880 | if (mem.startsWith(u8, lib, "-l")) { | 888 | if (mem.startsWith(u8, lib, "-l")) { |
| 881 | exe.linkSystemLibrary(lib["-l".len..]); | 889 | mod.linkSystemLibrary(lib["-l".len..], .{}); |
| 882 | } else if (exe.rootModuleTarget().os.tag == .windows and | 890 | } else if (mod.resolved_target.?.result.os.tag == .windows and |
| 883 | mem.endsWith(u8, lib, ".lib") and !fs.path.isAbsolute(lib)) | 891 | mem.endsWith(u8, lib, ".lib") and !fs.path.isAbsolute(lib)) |
| 884 | { | 892 | { |
| 885 | exe.linkSystemLibrary(lib[0 .. lib.len - ".lib".len]); | 893 | mod.linkSystemLibrary(lib[0 .. lib.len - ".lib".len], .{}); |
| 886 | } else { | 894 | } else { |
| 887 | exe.addObjectFile(.{ .cwd_relative = lib }); | 895 | mod.addObjectFile(.{ .cwd_relative = lib }); |
| 888 | } | 896 | } |
| 889 | } | 897 | } |
| 890 | } | 898 | } |
| ... | @@ -1306,9 +1314,11 @@ const llvm_libs = [_][]const u8{ | ... | @@ -1306,9 +1314,11 @@ const llvm_libs = [_][]const u8{ |
| 1306 | fn generateLangRef(b: *std.Build) std.Build.LazyPath { | 1314 | fn generateLangRef(b: *std.Build) std.Build.LazyPath { |
| 1307 | const doctest_exe = b.addExecutable(.{ | 1315 | const doctest_exe = b.addExecutable(.{ |
| 1308 | .name = "doctest", | 1316 | .name = "doctest", |
| 1309 | .root_source_file = b.path("tools/doctest.zig"), | 1317 | .root_module = b.createModule(.{ |
| 1310 | .target = b.graph.host, | 1318 | .root_source_file = b.path("tools/doctest.zig"), |
| 1311 | .optimize = .Debug, | 1319 | .target = b.graph.host, |
| 1320 | .optimize = .Debug, | ||
| 1321 | }), | ||
| 1312 | }); | 1322 | }); |
| 1313 | 1323 | ||
| 1314 | var dir = b.build_root.handle.openDir("doc/langref", .{ .iterate = true }) catch |err| { | 1324 | var dir = b.build_root.handle.openDir("doc/langref", .{ .iterate = true }) catch |err| { |
| ... | @@ -1343,9 +1353,11 @@ fn generateLangRef(b: *std.Build) std.Build.LazyPath { | ... | @@ -1343,9 +1353,11 @@ fn generateLangRef(b: *std.Build) std.Build.LazyPath { |
| 1343 | 1353 | ||
| 1344 | const docgen_exe = b.addExecutable(.{ | 1354 | const docgen_exe = b.addExecutable(.{ |
| 1345 | .name = "docgen", | 1355 | .name = "docgen", |
| 1346 | .root_source_file = b.path("tools/docgen.zig"), | 1356 | .root_module = b.createModule(.{ |
| 1347 | .target = b.graph.host, | 1357 | .root_source_file = b.path("tools/docgen.zig"), |
| 1348 | .optimize = .Debug, | 1358 | .target = b.graph.host, |
| 1359 | .optimize = .Debug, | ||
| 1360 | }), | ||
| 1349 | }); | 1361 | }); |
| 1350 | 1362 | ||
| 1351 | const docgen_cmd = b.addRunArtifact(docgen_exe); | 1363 | const docgen_cmd = b.addRunArtifact(docgen_exe); |
lib/compiler/build_runner.zig+78| ... | @@ -337,6 +337,7 @@ pub fn main() !void { | ... | @@ -337,6 +337,7 @@ pub fn main() !void { |
| 337 | var prog_node = main_progress_node.start("Configure", 0); | 337 | var prog_node = main_progress_node.start("Configure", 0); |
| 338 | defer prog_node.end(); | 338 | defer prog_node.end(); |
| 339 | try builder.runBuild(root); | 339 | try builder.runBuild(root); |
| 340 | createModuleDependencies(builder) catch @panic("OOM"); | ||
| 340 | } | 341 | } |
| 341 | 342 | ||
| 342 | if (graph.needed_lazy_dependencies.entries.len != 0) { | 343 | if (graph.needed_lazy_dependencies.entries.len != 0) { |
| ... | @@ -1440,3 +1441,80 @@ fn validateSystemLibraryOptions(b: *std.Build) void { | ... | @@ -1440,3 +1441,80 @@ fn validateSystemLibraryOptions(b: *std.Build) void { |
| 1440 | process.exit(1); | 1441 | process.exit(1); |
| 1441 | } | 1442 | } |
| 1442 | } | 1443 | } |
| 1444 | |||
| 1445 | /// Starting from all top-level steps in `b`, traverses the entire step graph | ||
| 1446 | /// and adds all step dependencies implied by module graphs. | ||
| 1447 | fn createModuleDependencies(b: *std.Build) Allocator.Error!void { | ||
| 1448 | const arena = b.graph.arena; | ||
| 1449 | |||
| 1450 | var all_steps: std.AutoArrayHashMapUnmanaged(*Step, void) = .empty; | ||
| 1451 | var next_step_idx: usize = 0; | ||
| 1452 | |||
| 1453 | try all_steps.ensureUnusedCapacity(arena, b.top_level_steps.count()); | ||
| 1454 | for (b.top_level_steps.values()) |tls| { | ||
| 1455 | all_steps.putAssumeCapacityNoClobber(&tls.step, {}); | ||
| 1456 | } | ||
| 1457 | |||
| 1458 | while (next_step_idx < all_steps.count()) { | ||
| 1459 | const step = all_steps.keys()[next_step_idx]; | ||
| 1460 | next_step_idx += 1; | ||
| 1461 | |||
| 1462 | // Set up any implied dependencies for this step. It's important that we do this first, so | ||
| 1463 | // that the loop below discovers steps implied by the module graph. | ||
| 1464 | try createModuleDependenciesForStep(step); | ||
| 1465 | |||
| 1466 | try all_steps.ensureUnusedCapacity(arena, step.dependencies.items.len); | ||
| 1467 | for (step.dependencies.items) |other_step| { | ||
| 1468 | all_steps.putAssumeCapacity(other_step, {}); | ||
| 1469 | } | ||
| 1470 | } | ||
| 1471 | } | ||
| 1472 | |||
| 1473 | /// If the given `Step` is a `Step.Compile`, adds any dependencies for that step which | ||
| 1474 | /// are implied by the module graph rooted at `step.cast(Step.Compile).?.root_module`. | ||
| 1475 | fn createModuleDependenciesForStep(step: *Step) Allocator.Error!void { | ||
| 1476 | const root_module = if (step.cast(Step.Compile)) |cs| root: { | ||
| 1477 | break :root cs.root_module; | ||
| 1478 | } else return; // not a compile step so no module dependencies | ||
| 1479 | |||
| 1480 | // Starting from `root_module`, discover all modules in this graph. | ||
| 1481 | const modules = root_module.getGraph().modules; | ||
| 1482 | |||
| 1483 | // For each of those modules, set up the implied step dependencies. | ||
| 1484 | for (modules) |mod| { | ||
| 1485 | if (mod.root_source_file) |lp| lp.addStepDependencies(step); | ||
| 1486 | for (mod.include_dirs.items) |include_dir| switch (include_dir) { | ||
| 1487 | .path, | ||
| 1488 | .path_system, | ||
| 1489 | .path_after, | ||
| 1490 | .framework_path, | ||
| 1491 | .framework_path_system, | ||
| 1492 | => |lp| lp.addStepDependencies(step), | ||
| 1493 | |||
| 1494 | .other_step => |other| { | ||
| 1495 | other.getEmittedIncludeTree().addStepDependencies(step); | ||
| 1496 | step.dependOn(&other.step); | ||
| 1497 | }, | ||
| 1498 | |||
| 1499 | .config_header_step => |other| step.dependOn(&other.step), | ||
| 1500 | }; | ||
| 1501 | for (mod.lib_paths.items) |lp| lp.addStepDependencies(step); | ||
| 1502 | for (mod.rpaths.items) |rpath| switch (rpath) { | ||
| 1503 | .lazy_path => |lp| lp.addStepDependencies(step), | ||
| 1504 | .special => {}, | ||
| 1505 | }; | ||
| 1506 | for (mod.link_objects.items) |link_object| switch (link_object) { | ||
| 1507 | .static_path, | ||
| 1508 | .assembly_file, | ||
| 1509 | => |lp| lp.addStepDependencies(step), | ||
| 1510 | .other_step => |other| step.dependOn(&other.step), | ||
| 1511 | .system_lib => {}, | ||
| 1512 | .c_source_file => |source| source.file.addStepDependencies(step), | ||
| 1513 | .c_source_files => |source_files| source_files.root.addStepDependencies(step), | ||
| 1514 | .win32_resource_file => |rc_source| { | ||
| 1515 | rc_source.file.addStepDependencies(step); | ||
| 1516 | for (rc_source.include_paths) |lp| lp.addStepDependencies(step); | ||
| 1517 | }, | ||
| 1518 | }; | ||
| 1519 | } | ||
| 1520 | } |
lib/init/build.zig+35-11| ... | @@ -15,8 +15,12 @@ pub fn build(b: *std.Build) void { | ... | @@ -15,8 +15,12 @@ pub fn build(b: *std.Build) void { |
| 15 | // set a preferred release mode, allowing the user to decide how to optimize. | 15 | // set a preferred release mode, allowing the user to decide how to optimize. |
| 16 | const optimize = b.standardOptimizeOption(.{}); | 16 | const optimize = b.standardOptimizeOption(.{}); |
| 17 | 17 | ||
| 18 | const lib = b.addStaticLibrary(.{ | 18 | // This creates a "module", which represents a collection of source files alongside |
| 19 | .name = "$", | 19 | // some compilation options, such as optimization mode and linked system libraries. |
| 20 | // Every executable or library we compile will be based on one or more modules. | ||
| 21 | const lib_mod = b.createModule(.{ | ||
| 22 | // `root_source_file` is the Zig "entry point" of the module. If a module | ||
| 23 | // only contains e.g. external object files, you can make this `null`. | ||
| 20 | // In this case the main source file is merely a path, however, in more | 24 | // In this case the main source file is merely a path, however, in more |
| 21 | // complicated build scripts, this could be a generated file. | 25 | // complicated build scripts, this could be a generated file. |
| 22 | .root_source_file = b.path("src/root.zig"), | 26 | .root_source_file = b.path("src/root.zig"), |
| ... | @@ -24,16 +28,40 @@ pub fn build(b: *std.Build) void { | ... | @@ -24,16 +28,40 @@ pub fn build(b: *std.Build) void { |
| 24 | .optimize = optimize, | 28 | .optimize = optimize, |
| 25 | }); | 29 | }); |
| 26 | 30 | ||
| 31 | // We will also create a module for our other entry point, 'main.zig'. | ||
| 32 | const exe_mod = b.createModule(.{ | ||
| 33 | // `root_source_file` is the Zig "entry point" of the module. If a module | ||
| 34 | // only contains e.g. external object files, you can make this `null`. | ||
| 35 | // In this case the main source file is merely a path, however, in more | ||
| 36 | // complicated build scripts, this could be a generated file. | ||
| 37 | .root_source_file = b.path("src/main.zig"), | ||
| 38 | .target = target, | ||
| 39 | .optimize = optimize, | ||
| 40 | }); | ||
| 41 | |||
| 42 | // Modules can depend on one another using the `std.Build.Module.addImport` function. | ||
| 43 | // This is what allows Zig source code to use `@import("foo")` where 'foo' is not a | ||
| 44 | // file path. In this case, we set up `exe_mod` to import `lib_mod`. | ||
| 45 | exe_mod.addImport("$_lib", lib_mod); | ||
| 46 | |||
| 47 | // Now, we will create a static library based on the module we created above. | ||
| 48 | // This creates a `std.Build.Step.Compile`, which is the build step responsible | ||
| 49 | // for actually invoking the compiler. | ||
| 50 | const lib = b.addStaticLibrary(.{ | ||
| 51 | .name = "$", | ||
| 52 | .root_module = lib_mod, | ||
| 53 | }); | ||
| 54 | |||
| 27 | // This declares intent for the library to be installed into the standard | 55 | // This declares intent for the library to be installed into the standard |
| 28 | // location when the user invokes the "install" step (the default step when | 56 | // location when the user invokes the "install" step (the default step when |
| 29 | // running `zig build`). | 57 | // running `zig build`). |
| 30 | b.installArtifact(lib); | 58 | b.installArtifact(lib); |
| 31 | 59 | ||
| 60 | // This creates another `std.Build.Step.Compile`, but this one builds an executable | ||
| 61 | // rather than a static library. | ||
| 32 | const exe = b.addExecutable(.{ | 62 | const exe = b.addExecutable(.{ |
| 33 | .name = "$", | 63 | .name = "$", |
| 34 | .root_source_file = b.path("src/main.zig"), | 64 | .root_module = exe_mod, |
| 35 | .target = target, | ||
| 36 | .optimize = optimize, | ||
| 37 | }); | 65 | }); |
| 38 | 66 | ||
| 39 | // This declares intent for the executable to be installed into the | 67 | // This declares intent for the executable to be installed into the |
| ... | @@ -67,17 +95,13 @@ pub fn build(b: *std.Build) void { | ... | @@ -67,17 +95,13 @@ pub fn build(b: *std.Build) void { |
| 67 | // Creates a step for unit testing. This only builds the test executable | 95 | // Creates a step for unit testing. This only builds the test executable |
| 68 | // but does not run it. | 96 | // but does not run it. |
| 69 | const lib_unit_tests = b.addTest(.{ | 97 | const lib_unit_tests = b.addTest(.{ |
| 70 | .root_source_file = b.path("src/root.zig"), | 98 | .root_module = lib_mod, |
| 71 | .target = target, | ||
| 72 | .optimize = optimize, | ||
| 73 | }); | 99 | }); |
| 74 | 100 | ||
| 75 | const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); | 101 | const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); |
| 76 | 102 | ||
| 77 | const exe_unit_tests = b.addTest(.{ | 103 | const exe_unit_tests = b.addTest(.{ |
| 78 | .root_source_file = b.path("src/main.zig"), | 104 | .root_module = exe_mod, |
| 79 | .target = target, | ||
| 80 | .optimize = optimize, | ||
| 81 | }); | 105 | }); |
| 82 | 106 | ||
| 83 | const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); | 107 | const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); |
lib/init/src/main.zig+9-1| ... | @@ -1,7 +1,6 @@ | ... | @@ -1,7 +1,6 @@ |
| 1 | //! By convention, main.zig is where your main function lives in the case that | 1 | //! By convention, main.zig is where your main function lives in the case that |
| 2 | //! you are building an executable. If you are making a library, the convention | 2 | //! you are building an executable. If you are making a library, the convention |
| 3 | //! is to delete this file and start with root.zig instead. | 3 | //! is to delete this file and start with root.zig instead. |
| 4 | const std = @import("std"); | ||
| 5 | 4 | ||
| 6 | pub fn main() !void { | 5 | pub fn main() !void { |
| 7 | // Prints to stderr (it's a shortcut based on `std.io.getStdErr()`) | 6 | // Prints to stderr (it's a shortcut based on `std.io.getStdErr()`) |
| ... | @@ -26,6 +25,10 @@ test "simple test" { | ... | @@ -26,6 +25,10 @@ test "simple test" { |
| 26 | try std.testing.expectEqual(@as(i32, 42), list.pop()); | 25 | try std.testing.expectEqual(@as(i32, 42), list.pop()); |
| 27 | } | 26 | } |
| 28 | 27 | ||
| 28 | test "use other module" { | ||
| 29 | try std.testing.expectEqual(@as(i32, 150), lib.add(100, 50)); | ||
| 30 | } | ||
| 31 | |||
| 29 | test "fuzz example" { | 32 | test "fuzz example" { |
| 30 | const global = struct { | 33 | const global = struct { |
| 31 | fn testOne(input: []const u8) anyerror!void { | 34 | fn testOne(input: []const u8) anyerror!void { |
| ... | @@ -35,3 +38,8 @@ test "fuzz example" { | ... | @@ -35,3 +38,8 @@ test "fuzz example" { |
| 35 | }; | 38 | }; |
| 36 | try std.testing.fuzz(global.testOne, .{}); | 39 | try std.testing.fuzz(global.testOne, .{}); |
| 37 | } | 40 | } |
| 41 | |||
| 42 | const std = @import("std"); | ||
| 43 | |||
| 44 | /// This imports the separate module containing `root.zig`. Take a look in `build.zig` for details. | ||
| 45 | const lib = @import("$_lib"); |
lib/init/src/root.zig+1-1| ... | @@ -4,7 +4,7 @@ | ... | @@ -4,7 +4,7 @@ |
| 4 | const std = @import("std"); | 4 | const std = @import("std"); |
| 5 | const testing = std.testing; | 5 | const testing = std.testing; |
| 6 | 6 | ||
| 7 | export fn add(a: i32, b: i32) i32 { | 7 | pub export fn add(a: i32, b: i32) i32 { |
| 8 | return a + b; | 8 | return a + b; |
| 9 | } | 9 | } |
| 10 | 10 |
lib/std/Build.zig+180-87| ... | @@ -81,9 +81,6 @@ enable_wine: bool = false, | ... | @@ -81,9 +81,6 @@ enable_wine: bool = false, |
| 81 | /// that contains the path `aarch64-linux-gnu/lib/ld-linux-aarch64.so.1`. | 81 | /// that contains the path `aarch64-linux-gnu/lib/ld-linux-aarch64.so.1`. |
| 82 | glibc_runtimes_dir: ?[]const u8 = null, | 82 | glibc_runtimes_dir: ?[]const u8 = null, |
| 83 | 83 | ||
| 84 | /// Deprecated. Use `b.graph.host`. | ||
| 85 | host: ResolvedTarget, | ||
| 86 | |||
| 87 | dep_prefix: []const u8 = "", | 84 | dep_prefix: []const u8 = "", |
| 88 | 85 | ||
| 89 | modules: std.StringArrayHashMap(*Module), | 86 | modules: std.StringArrayHashMap(*Module), |
| ... | @@ -301,7 +298,6 @@ pub fn create( | ... | @@ -301,7 +298,6 @@ pub fn create( |
| 301 | }, | 298 | }, |
| 302 | .install_path = undefined, | 299 | .install_path = undefined, |
| 303 | .args = null, | 300 | .args = null, |
| 304 | .host = graph.host, | ||
| 305 | .modules = .init(arena), | 301 | .modules = .init(arena), |
| 306 | .named_writefiles = .init(arena), | 302 | .named_writefiles = .init(arena), |
| 307 | .named_lazy_paths = .init(arena), | 303 | .named_lazy_paths = .init(arena), |
| ... | @@ -393,7 +389,6 @@ fn createChildOnly( | ... | @@ -393,7 +389,6 @@ fn createChildOnly( |
| 393 | .enable_wasmtime = parent.enable_wasmtime, | 389 | .enable_wasmtime = parent.enable_wasmtime, |
| 394 | .enable_wine = parent.enable_wine, | 390 | .enable_wine = parent.enable_wine, |
| 395 | .glibc_runtimes_dir = parent.glibc_runtimes_dir, | 391 | .glibc_runtimes_dir = parent.glibc_runtimes_dir, |
| 396 | .host = parent.host, | ||
| 397 | .dep_prefix = parent.fmt("{s}{s}.", .{ parent.dep_prefix, dep_name }), | 392 | .dep_prefix = parent.fmt("{s}{s}.", .{ parent.dep_prefix, dep_name }), |
| 398 | .modules = .init(allocator), | 393 | .modules = .init(allocator), |
| 399 | .named_writefiles = .init(allocator), | 394 | .named_writefiles = .init(allocator), |
| ... | @@ -692,24 +687,9 @@ pub fn addOptions(b: *Build) *Step.Options { | ... | @@ -692,24 +687,9 @@ pub fn addOptions(b: *Build) *Step.Options { |
| 692 | 687 | ||
| 693 | pub const ExecutableOptions = struct { | 688 | pub const ExecutableOptions = struct { |
| 694 | name: []const u8, | 689 | name: []const u8, |
| 695 | /// If you want the executable to run on the same computer as the one | ||
| 696 | /// building the package, pass the `host` field of the package's `Build` | ||
| 697 | /// instance. | ||
| 698 | target: ResolvedTarget, | ||
| 699 | root_source_file: ?LazyPath = null, | ||
| 700 | version: ?std.SemanticVersion = null, | 690 | version: ?std.SemanticVersion = null, |
| 701 | optimize: std.builtin.OptimizeMode = .Debug, | ||
| 702 | code_model: std.builtin.CodeModel = .default, | ||
| 703 | linkage: ?std.builtin.LinkMode = null, | 691 | linkage: ?std.builtin.LinkMode = null, |
| 704 | max_rss: usize = 0, | 692 | max_rss: usize = 0, |
| 705 | link_libc: ?bool = null, | ||
| 706 | single_threaded: ?bool = null, | ||
| 707 | pic: ?bool = null, | ||
| 708 | strip: ?bool = null, | ||
| 709 | unwind_tables: ?std.builtin.UnwindTables = null, | ||
| 710 | omit_frame_pointer: ?bool = null, | ||
| 711 | sanitize_thread: ?bool = null, | ||
| 712 | error_tracing: ?bool = null, | ||
| 713 | use_llvm: ?bool = null, | 693 | use_llvm: ?bool = null, |
| 714 | use_lld: ?bool = null, | 694 | use_lld: ?bool = null, |
| 715 | zig_lib_dir: ?LazyPath = null, | 695 | zig_lib_dir: ?LazyPath = null, |
| ... | @@ -719,14 +699,47 @@ pub const ExecutableOptions = struct { | ... | @@ -719,14 +699,47 @@ pub const ExecutableOptions = struct { |
| 719 | /// Can be set regardless of target. The `.manifest` file will be ignored | 699 | /// Can be set regardless of target. The `.manifest` file will be ignored |
| 720 | /// if the target object format does not support embedded manifests. | 700 | /// if the target object format does not support embedded manifests. |
| 721 | win32_manifest: ?LazyPath = null, | 701 | win32_manifest: ?LazyPath = null, |
| 702 | |||
| 703 | /// Prefer populating this field (using e.g. `createModule`) instead of populating | ||
| 704 | /// the following fields (`root_source_file` etc). In a future release, those fields | ||
| 705 | /// will be removed, and this field will become non-optional. | ||
| 706 | root_module: ?*Module = null, | ||
| 707 | |||
| 708 | /// Deprecated; prefer populating `root_module`. | ||
| 709 | root_source_file: ?LazyPath = null, | ||
| 710 | /// Deprecated; prefer populating `root_module`. | ||
| 711 | target: ?ResolvedTarget = null, | ||
| 712 | /// Deprecated; prefer populating `root_module`. | ||
| 713 | optimize: std.builtin.OptimizeMode = .Debug, | ||
| 714 | /// Deprecated; prefer populating `root_module`. | ||
| 715 | code_model: std.builtin.CodeModel = .default, | ||
| 716 | /// Deprecated; prefer populating `root_module`. | ||
| 717 | link_libc: ?bool = null, | ||
| 718 | /// Deprecated; prefer populating `root_module`. | ||
| 719 | single_threaded: ?bool = null, | ||
| 720 | /// Deprecated; prefer populating `root_module`. | ||
| 721 | pic: ?bool = null, | ||
| 722 | /// Deprecated; prefer populating `root_module`. | ||
| 723 | strip: ?bool = null, | ||
| 724 | /// Deprecated; prefer populating `root_module`. | ||
| 725 | unwind_tables: ?std.builtin.UnwindTables = null, | ||
| 726 | /// Deprecated; prefer populating `root_module`. | ||
| 727 | omit_frame_pointer: ?bool = null, | ||
| 728 | /// Deprecated; prefer populating `root_module`. | ||
| 729 | sanitize_thread: ?bool = null, | ||
| 730 | /// Deprecated; prefer populating `root_module`. | ||
| 731 | error_tracing: ?bool = null, | ||
| 722 | }; | 732 | }; |
| 723 | 733 | ||
| 724 | pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { | 734 | pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { |
| 725 | return Step.Compile.create(b, .{ | 735 | if (options.root_module != null and options.target != null) { |
| 736 | @panic("`root_module` and `target` cannot both be populated"); | ||
| 737 | } | ||
| 738 | return .create(b, .{ | ||
| 726 | .name = options.name, | 739 | .name = options.name, |
| 727 | .root_module = .{ | 740 | .root_module = options.root_module orelse b.createModule(.{ |
| 728 | .root_source_file = options.root_source_file, | 741 | .root_source_file = options.root_source_file, |
| 729 | .target = options.target, | 742 | .target = options.target orelse @panic("`root_module` and `target` cannot both be null"), |
| 730 | .optimize = options.optimize, | 743 | .optimize = options.optimize, |
| 731 | .link_libc = options.link_libc, | 744 | .link_libc = options.link_libc, |
| 732 | .single_threaded = options.single_threaded, | 745 | .single_threaded = options.single_threaded, |
| ... | @@ -737,7 +750,7 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { | ... | @@ -737,7 +750,7 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { |
| 737 | .sanitize_thread = options.sanitize_thread, | 750 | .sanitize_thread = options.sanitize_thread, |
| 738 | .error_tracing = options.error_tracing, | 751 | .error_tracing = options.error_tracing, |
| 739 | .code_model = options.code_model, | 752 | .code_model = options.code_model, |
| 740 | }, | 753 | }), |
| 741 | .version = options.version, | 754 | .version = options.version, |
| 742 | .kind = .exe, | 755 | .kind = .exe, |
| 743 | .linkage = options.linkage, | 756 | .linkage = options.linkage, |
| ... | @@ -751,32 +764,51 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { | ... | @@ -751,32 +764,51 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { |
| 751 | 764 | ||
| 752 | pub const ObjectOptions = struct { | 765 | pub const ObjectOptions = struct { |
| 753 | name: []const u8, | 766 | name: []const u8, |
| 767 | max_rss: usize = 0, | ||
| 768 | use_llvm: ?bool = null, | ||
| 769 | use_lld: ?bool = null, | ||
| 770 | zig_lib_dir: ?LazyPath = null, | ||
| 771 | |||
| 772 | /// Prefer populating this field (using e.g. `createModule`) instead of populating | ||
| 773 | /// the following fields (`root_source_file` etc). In a future release, those fields | ||
| 774 | /// will be removed, and this field will become non-optional. | ||
| 775 | root_module: ?*Module = null, | ||
| 776 | |||
| 777 | /// Deprecated; prefer populating `root_module`. | ||
| 754 | root_source_file: ?LazyPath = null, | 778 | root_source_file: ?LazyPath = null, |
| 755 | /// To choose the same computer as the one building the package, pass the | 779 | /// Deprecated; prefer populating `root_module`. |
| 756 | /// `host` field of the package's `Build` instance. | 780 | target: ?ResolvedTarget = null, |
| 757 | target: ResolvedTarget, | 781 | /// Deprecated; prefer populating `root_module`. |
| 782 | optimize: std.builtin.OptimizeMode = .Debug, | ||
| 783 | /// Deprecated; prefer populating `root_module`. | ||
| 758 | code_model: std.builtin.CodeModel = .default, | 784 | code_model: std.builtin.CodeModel = .default, |
| 759 | optimize: std.builtin.OptimizeMode, | 785 | /// Deprecated; prefer populating `root_module`. |
| 760 | max_rss: usize = 0, | ||
| 761 | link_libc: ?bool = null, | 786 | link_libc: ?bool = null, |
| 787 | /// Deprecated; prefer populating `root_module`. | ||
| 762 | single_threaded: ?bool = null, | 788 | single_threaded: ?bool = null, |
| 789 | /// Deprecated; prefer populating `root_module`. | ||
| 763 | pic: ?bool = null, | 790 | pic: ?bool = null, |
| 791 | /// Deprecated; prefer populating `root_module`. | ||
| 764 | strip: ?bool = null, | 792 | strip: ?bool = null, |
| 793 | /// Deprecated; prefer populating `root_module`. | ||
| 765 | unwind_tables: ?std.builtin.UnwindTables = null, | 794 | unwind_tables: ?std.builtin.UnwindTables = null, |
| 795 | /// Deprecated; prefer populating `root_module`. | ||
| 766 | omit_frame_pointer: ?bool = null, | 796 | omit_frame_pointer: ?bool = null, |
| 797 | /// Deprecated; prefer populating `root_module`. | ||
| 767 | sanitize_thread: ?bool = null, | 798 | sanitize_thread: ?bool = null, |
| 799 | /// Deprecated; prefer populating `root_module`. | ||
| 768 | error_tracing: ?bool = null, | 800 | error_tracing: ?bool = null, |
| 769 | use_llvm: ?bool = null, | ||
| 770 | use_lld: ?bool = null, | ||
| 771 | zig_lib_dir: ?LazyPath = null, | ||
| 772 | }; | 801 | }; |
| 773 | 802 | ||
| 774 | pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { | 803 | pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { |
| 775 | return Step.Compile.create(b, .{ | 804 | if (options.root_module != null and options.target != null) { |
| 805 | @panic("`root_module` and `target` cannot both be populated"); | ||
| 806 | } | ||
| 807 | return .create(b, .{ | ||
| 776 | .name = options.name, | 808 | .name = options.name, |
| 777 | .root_module = .{ | 809 | .root_module = options.root_module orelse b.createModule(.{ |
| 778 | .root_source_file = options.root_source_file, | 810 | .root_source_file = options.root_source_file, |
| 779 | .target = options.target, | 811 | .target = options.target orelse @panic("`root_module` and `target` cannot both be null"), |
| 780 | .optimize = options.optimize, | 812 | .optimize = options.optimize, |
| 781 | .link_libc = options.link_libc, | 813 | .link_libc = options.link_libc, |
| 782 | .single_threaded = options.single_threaded, | 814 | .single_threaded = options.single_threaded, |
| ... | @@ -787,7 +819,7 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { | ... | @@ -787,7 +819,7 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { |
| 787 | .sanitize_thread = options.sanitize_thread, | 819 | .sanitize_thread = options.sanitize_thread, |
| 788 | .error_tracing = options.error_tracing, | 820 | .error_tracing = options.error_tracing, |
| 789 | .code_model = options.code_model, | 821 | .code_model = options.code_model, |
| 790 | }, | 822 | }), |
| 791 | .kind = .obj, | 823 | .kind = .obj, |
| 792 | .max_rss = options.max_rss, | 824 | .max_rss = options.max_rss, |
| 793 | .use_llvm = options.use_llvm, | 825 | .use_llvm = options.use_llvm, |
| ... | @@ -798,22 +830,8 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { | ... | @@ -798,22 +830,8 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { |
| 798 | 830 | ||
| 799 | pub const SharedLibraryOptions = struct { | 831 | pub const SharedLibraryOptions = struct { |
| 800 | name: []const u8, | 832 | name: []const u8, |
| 801 | /// To choose the same computer as the one building the package, pass the | ||
| 802 | /// `host` field of the package's `Build` instance. | ||
| 803 | target: ResolvedTarget, | ||
| 804 | optimize: std.builtin.OptimizeMode, | ||
| 805 | code_model: std.builtin.CodeModel = .default, | ||
| 806 | root_source_file: ?LazyPath = null, | ||
| 807 | version: ?std.SemanticVersion = null, | 833 | version: ?std.SemanticVersion = null, |
| 808 | max_rss: usize = 0, | 834 | max_rss: usize = 0, |
| 809 | link_libc: ?bool = null, | ||
| 810 | single_threaded: ?bool = null, | ||
| 811 | pic: ?bool = null, | ||
| 812 | strip: ?bool = null, | ||
| 813 | unwind_tables: ?std.builtin.UnwindTables = null, | ||
| 814 | omit_frame_pointer: ?bool = null, | ||
| 815 | sanitize_thread: ?bool = null, | ||
| 816 | error_tracing: ?bool = null, | ||
| 817 | use_llvm: ?bool = null, | 835 | use_llvm: ?bool = null, |
| 818 | use_lld: ?bool = null, | 836 | use_lld: ?bool = null, |
| 819 | zig_lib_dir: ?LazyPath = null, | 837 | zig_lib_dir: ?LazyPath = null, |
| ... | @@ -823,13 +841,46 @@ pub const SharedLibraryOptions = struct { | ... | @@ -823,13 +841,46 @@ pub const SharedLibraryOptions = struct { |
| 823 | /// Can be set regardless of target. The `.manifest` file will be ignored | 841 | /// Can be set regardless of target. The `.manifest` file will be ignored |
| 824 | /// if the target object format does not support embedded manifests. | 842 | /// if the target object format does not support embedded manifests. |
| 825 | win32_manifest: ?LazyPath = null, | 843 | win32_manifest: ?LazyPath = null, |
| 844 | |||
| 845 | /// Prefer populating this field (using e.g. `createModule`) instead of populating | ||
| 846 | /// the following fields (`root_source_file` etc). In a future release, those fields | ||
| 847 | /// will be removed, and this field will become non-optional. | ||
| 848 | root_module: ?*Module = null, | ||
| 849 | |||
| 850 | /// Deprecated; prefer populating `root_module`. | ||
| 851 | root_source_file: ?LazyPath = null, | ||
| 852 | /// Deprecated; prefer populating `root_module`. | ||
| 853 | target: ?ResolvedTarget = null, | ||
| 854 | /// Deprecated; prefer populating `root_module`. | ||
| 855 | optimize: std.builtin.OptimizeMode = .Debug, | ||
| 856 | /// Deprecated; prefer populating `root_module`. | ||
| 857 | code_model: std.builtin.CodeModel = .default, | ||
| 858 | /// Deprecated; prefer populating `root_module`. | ||
| 859 | link_libc: ?bool = null, | ||
| 860 | /// Deprecated; prefer populating `root_module`. | ||
| 861 | single_threaded: ?bool = null, | ||
| 862 | /// Deprecated; prefer populating `root_module`. | ||
| 863 | pic: ?bool = null, | ||
| 864 | /// Deprecated; prefer populating `root_module`. | ||
| 865 | strip: ?bool = null, | ||
| 866 | /// Deprecated; prefer populating `root_module`. | ||
| 867 | unwind_tables: ?std.builtin.UnwindTables = null, | ||
| 868 | /// Deprecated; prefer populating `root_module`. | ||
| 869 | omit_frame_pointer: ?bool = null, | ||
| 870 | /// Deprecated; prefer populating `root_module`. | ||
| 871 | sanitize_thread: ?bool = null, | ||
| 872 | /// Deprecated; prefer populating `root_module`. | ||
| 873 | error_tracing: ?bool = null, | ||
| 826 | }; | 874 | }; |
| 827 | 875 | ||
| 828 | pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile { | 876 | pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile { |
| 829 | return Step.Compile.create(b, .{ | 877 | if (options.root_module != null and options.target != null) { |
| 878 | @panic("`root_module` and `target` cannot both be populated"); | ||
| 879 | } | ||
| 880 | return .create(b, .{ | ||
| 830 | .name = options.name, | 881 | .name = options.name, |
| 831 | .root_module = .{ | 882 | .root_module = options.root_module orelse b.createModule(.{ |
| 832 | .target = options.target, | 883 | .target = options.target orelse @panic("`root_module` and `target` cannot both be null"), |
| 833 | .optimize = options.optimize, | 884 | .optimize = options.optimize, |
| 834 | .root_source_file = options.root_source_file, | 885 | .root_source_file = options.root_source_file, |
| 835 | .link_libc = options.link_libc, | 886 | .link_libc = options.link_libc, |
| ... | @@ -841,7 +892,7 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile | ... | @@ -841,7 +892,7 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile |
| 841 | .sanitize_thread = options.sanitize_thread, | 892 | .sanitize_thread = options.sanitize_thread, |
| 842 | .error_tracing = options.error_tracing, | 893 | .error_tracing = options.error_tracing, |
| 843 | .code_model = options.code_model, | 894 | .code_model = options.code_model, |
| 844 | }, | 895 | }), |
| 845 | .kind = .lib, | 896 | .kind = .lib, |
| 846 | .linkage = .dynamic, | 897 | .linkage = .dynamic, |
| 847 | .version = options.version, | 898 | .version = options.version, |
| ... | @@ -855,32 +906,51 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile | ... | @@ -855,32 +906,51 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile |
| 855 | 906 | ||
| 856 | pub const StaticLibraryOptions = struct { | 907 | pub const StaticLibraryOptions = struct { |
| 857 | name: []const u8, | 908 | name: []const u8, |
| 858 | root_source_file: ?LazyPath = null, | ||
| 859 | /// To choose the same computer as the one building the package, pass the | ||
| 860 | /// `host` field of the package's `Build` instance. | ||
| 861 | target: ResolvedTarget, | ||
| 862 | optimize: std.builtin.OptimizeMode, | ||
| 863 | code_model: std.builtin.CodeModel = .default, | ||
| 864 | version: ?std.SemanticVersion = null, | 909 | version: ?std.SemanticVersion = null, |
| 865 | max_rss: usize = 0, | 910 | max_rss: usize = 0, |
| 911 | use_llvm: ?bool = null, | ||
| 912 | use_lld: ?bool = null, | ||
| 913 | zig_lib_dir: ?LazyPath = null, | ||
| 914 | |||
| 915 | /// Prefer populating this field (using e.g. `createModule`) instead of populating | ||
| 916 | /// the following fields (`root_source_file` etc). In a future release, those fields | ||
| 917 | /// will be removed, and this field will become non-optional. | ||
| 918 | root_module: ?*Module = null, | ||
| 919 | |||
| 920 | /// Deprecated; prefer populating `root_module`. | ||
| 921 | root_source_file: ?LazyPath = null, | ||
| 922 | /// Deprecated; prefer populating `root_module`. | ||
| 923 | target: ?ResolvedTarget = null, | ||
| 924 | /// Deprecated; prefer populating `root_module`. | ||
| 925 | optimize: std.builtin.OptimizeMode = .Debug, | ||
| 926 | /// Deprecated; prefer populating `root_module`. | ||
| 927 | code_model: std.builtin.CodeModel = .default, | ||
| 928 | /// Deprecated; prefer populating `root_module`. | ||
| 866 | link_libc: ?bool = null, | 929 | link_libc: ?bool = null, |
| 930 | /// Deprecated; prefer populating `root_module`. | ||
| 867 | single_threaded: ?bool = null, | 931 | single_threaded: ?bool = null, |
| 932 | /// Deprecated; prefer populating `root_module`. | ||
| 868 | pic: ?bool = null, | 933 | pic: ?bool = null, |
| 934 | /// Deprecated; prefer populating `root_module`. | ||
| 869 | strip: ?bool = null, | 935 | strip: ?bool = null, |
| 936 | /// Deprecated; prefer populating `root_module`. | ||
| 870 | unwind_tables: ?std.builtin.UnwindTables = null, | 937 | unwind_tables: ?std.builtin.UnwindTables = null, |
| 938 | /// Deprecated; prefer populating `root_module`. | ||
| 871 | omit_frame_pointer: ?bool = null, | 939 | omit_frame_pointer: ?bool = null, |
| 940 | /// Deprecated; prefer populating `root_module`. | ||
| 872 | sanitize_thread: ?bool = null, | 941 | sanitize_thread: ?bool = null, |
| 942 | /// Deprecated; prefer populating `root_module`. | ||
| 873 | error_tracing: ?bool = null, | 943 | error_tracing: ?bool = null, |
| 874 | use_llvm: ?bool = null, | ||
| 875 | use_lld: ?bool = null, | ||
| 876 | zig_lib_dir: ?LazyPath = null, | ||
| 877 | }; | 944 | }; |
| 878 | 945 | ||
| 879 | pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile { | 946 | pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile { |
| 880 | return Step.Compile.create(b, .{ | 947 | if (options.root_module != null and options.target != null) { |
| 948 | @panic("`root_module` and `target` cannot both be populated"); | ||
| 949 | } | ||
| 950 | return .create(b, .{ | ||
| 881 | .name = options.name, | 951 | .name = options.name, |
| 882 | .root_module = .{ | 952 | .root_module = options.root_module orelse b.createModule(.{ |
| 883 | .target = options.target, | 953 | .target = options.target orelse @panic("`root_module` and `target` cannot both be null"), |
| 884 | .optimize = options.optimize, | 954 | .optimize = options.optimize, |
| 885 | .root_source_file = options.root_source_file, | 955 | .root_source_file = options.root_source_file, |
| 886 | .link_libc = options.link_libc, | 956 | .link_libc = options.link_libc, |
| ... | @@ -892,7 +962,7 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile | ... | @@ -892,7 +962,7 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile |
| 892 | .sanitize_thread = options.sanitize_thread, | 962 | .sanitize_thread = options.sanitize_thread, |
| 893 | .error_tracing = options.error_tracing, | 963 | .error_tracing = options.error_tracing, |
| 894 | .code_model = options.code_model, | 964 | .code_model = options.code_model, |
| 895 | }, | 965 | }), |
| 896 | .kind = .lib, | 966 | .kind = .lib, |
| 897 | .linkage = .static, | 967 | .linkage = .static, |
| 898 | .version = options.version, | 968 | .version = options.version, |
| ... | @@ -905,27 +975,46 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile | ... | @@ -905,27 +975,46 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile |
| 905 | 975 | ||
| 906 | pub const TestOptions = struct { | 976 | pub const TestOptions = struct { |
| 907 | name: []const u8 = "test", | 977 | name: []const u8 = "test", |
| 908 | root_source_file: LazyPath, | ||
| 909 | target: ?ResolvedTarget = null, | ||
| 910 | optimize: std.builtin.OptimizeMode = .Debug, | ||
| 911 | version: ?std.SemanticVersion = null, | ||
| 912 | max_rss: usize = 0, | 978 | max_rss: usize = 0, |
| 913 | /// deprecated: use `.filters = &.{filter}` instead of `.filter = filter`. | 979 | /// Deprecated; use `.filters = &.{filter}` instead of `.filter = filter`. |
| 914 | filter: ?[]const u8 = null, | 980 | filter: ?[]const u8 = null, |
| 915 | filters: []const []const u8 = &.{}, | 981 | filters: []const []const u8 = &.{}, |
| 916 | test_runner: ?LazyPath = null, | 982 | test_runner: ?LazyPath = null, |
| 983 | use_llvm: ?bool = null, | ||
| 984 | use_lld: ?bool = null, | ||
| 985 | zig_lib_dir: ?LazyPath = null, | ||
| 986 | |||
| 987 | /// Prefer populating this field (using e.g. `createModule`) instead of populating | ||
| 988 | /// the following fields (`root_source_file` etc). In a future release, those fields | ||
| 989 | /// will be removed, and this field will become non-optional. | ||
| 990 | root_module: ?*Module = null, | ||
| 991 | |||
| 992 | /// Deprecated; prefer populating `root_module`. | ||
| 993 | root_source_file: ?LazyPath = null, | ||
| 994 | /// Deprecated; prefer populating `root_module`. | ||
| 995 | target: ?ResolvedTarget = null, | ||
| 996 | /// Deprecated; prefer populating `root_module`. | ||
| 997 | optimize: std.builtin.OptimizeMode = .Debug, | ||
| 998 | /// Deprecated; prefer populating `root_module`. | ||
| 999 | version: ?std.SemanticVersion = null, | ||
| 1000 | /// Deprecated; prefer populating `root_module`. | ||
| 917 | link_libc: ?bool = null, | 1001 | link_libc: ?bool = null, |
| 1002 | /// Deprecated; prefer populating `root_module`. | ||
| 918 | link_libcpp: ?bool = null, | 1003 | link_libcpp: ?bool = null, |
| 1004 | /// Deprecated; prefer populating `root_module`. | ||
| 919 | single_threaded: ?bool = null, | 1005 | single_threaded: ?bool = null, |
| 1006 | /// Deprecated; prefer populating `root_module`. | ||
| 920 | pic: ?bool = null, | 1007 | pic: ?bool = null, |
| 1008 | /// Deprecated; prefer populating `root_module`. | ||
| 921 | strip: ?bool = null, | 1009 | strip: ?bool = null, |
| 1010 | /// Deprecated; prefer populating `root_module`. | ||
| 922 | unwind_tables: ?std.builtin.UnwindTables = null, | 1011 | unwind_tables: ?std.builtin.UnwindTables = null, |
| 1012 | /// Deprecated; prefer populating `root_module`. | ||
| 923 | omit_frame_pointer: ?bool = null, | 1013 | omit_frame_pointer: ?bool = null, |
| 1014 | /// Deprecated; prefer populating `root_module`. | ||
| 924 | sanitize_thread: ?bool = null, | 1015 | sanitize_thread: ?bool = null, |
| 1016 | /// Deprecated; prefer populating `root_module`. | ||
| 925 | error_tracing: ?bool = null, | 1017 | error_tracing: ?bool = null, |
| 926 | use_llvm: ?bool = null, | ||
| 927 | use_lld: ?bool = null, | ||
| 928 | zig_lib_dir: ?LazyPath = null, | ||
| 929 | }; | 1018 | }; |
| 930 | 1019 | ||
| 931 | /// Creates an executable containing unit tests. | 1020 | /// Creates an executable containing unit tests. |
| ... | @@ -937,11 +1026,14 @@ pub const TestOptions = struct { | ... | @@ -937,11 +1026,14 @@ pub const TestOptions = struct { |
| 937 | /// two steps are separated because they are independently configured and | 1026 | /// two steps are separated because they are independently configured and |
| 938 | /// cached. | 1027 | /// cached. |
| 939 | pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { | 1028 | pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { |
| 940 | return Step.Compile.create(b, .{ | 1029 | if (options.root_module != null and options.root_source_file != null) { |
| 1030 | @panic("`root_module` and `root_source_file` cannot both be populated"); | ||
| 1031 | } | ||
| 1032 | return .create(b, .{ | ||
| 941 | .name = options.name, | 1033 | .name = options.name, |
| 942 | .kind = .@"test", | 1034 | .kind = .@"test", |
| 943 | .root_module = .{ | 1035 | .root_module = options.root_module orelse b.createModule(.{ |
| 944 | .root_source_file = options.root_source_file, | 1036 | .root_source_file = options.root_source_file orelse @panic("`root_module` and `root_source_file` cannot both be null"), |
| 945 | .target = options.target orelse b.graph.host, | 1037 | .target = options.target orelse b.graph.host, |
| 946 | .optimize = options.optimize, | 1038 | .optimize = options.optimize, |
| 947 | .link_libc = options.link_libc, | 1039 | .link_libc = options.link_libc, |
| ... | @@ -953,7 +1045,7 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { | ... | @@ -953,7 +1045,7 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { |
| 953 | .omit_frame_pointer = options.omit_frame_pointer, | 1045 | .omit_frame_pointer = options.omit_frame_pointer, |
| 954 | .sanitize_thread = options.sanitize_thread, | 1046 | .sanitize_thread = options.sanitize_thread, |
| 955 | .error_tracing = options.error_tracing, | 1047 | .error_tracing = options.error_tracing, |
| 956 | }, | 1048 | }), |
| 957 | .max_rss = options.max_rss, | 1049 | .max_rss = options.max_rss, |
| 958 | .filters = if (options.filter != null and options.filters.len > 0) filters: { | 1050 | .filters = if (options.filter != null and options.filters.len > 0) filters: { |
| 959 | const filters = b.allocator.alloc([]const u8, 1 + options.filters.len) catch @panic("OOM"); | 1051 | const filters = b.allocator.alloc([]const u8, 1 + options.filters.len) catch @panic("OOM"); |
| ... | @@ -979,19 +1071,20 @@ pub const AssemblyOptions = struct { | ... | @@ -979,19 +1071,20 @@ pub const AssemblyOptions = struct { |
| 979 | zig_lib_dir: ?LazyPath = null, | 1071 | zig_lib_dir: ?LazyPath = null, |
| 980 | }; | 1072 | }; |
| 981 | 1073 | ||
| 1074 | /// Deprecated; prefer using `addObject` where the `root_module` has an empty | ||
| 1075 | /// `root_source_file` and contains an assembly file via `Module.addAssemblyFile`. | ||
| 982 | pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile { | 1076 | pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile { |
| 983 | const obj_step = Step.Compile.create(b, .{ | 1077 | const root_module = b.createModule(.{ |
| 1078 | .target = options.target, | ||
| 1079 | .optimize = options.optimize, | ||
| 1080 | }); | ||
| 1081 | root_module.addAssemblyFile(options.source_file); | ||
| 1082 | return b.addObject(.{ | ||
| 984 | .name = options.name, | 1083 | .name = options.name, |
| 985 | .kind = .obj, | ||
| 986 | .root_module = .{ | ||
| 987 | .target = options.target, | ||
| 988 | .optimize = options.optimize, | ||
| 989 | }, | ||
| 990 | .max_rss = options.max_rss, | 1084 | .max_rss = options.max_rss, |
| 991 | .zig_lib_dir = options.zig_lib_dir, | 1085 | .zig_lib_dir = options.zig_lib_dir, |
| 1086 | .root_module = root_module, | ||
| 992 | }); | 1087 | }); |
| 993 | obj_step.addAssemblyFile(options.source_file); | ||
| 994 | return obj_step; | ||
| 995 | } | 1088 | } |
| 996 | 1089 | ||
| 997 | /// This function creates a module and adds it to the package's module set, making | 1090 | /// This function creates a module and adds it to the package's module set, making |
lib/std/Build/Module.zig+91-216| ... | @@ -1,9 +1,5 @@ | ... | @@ -1,9 +1,5 @@ |
| 1 | /// The one responsible for creating this module. | 1 | /// The one responsible for creating this module. |
| 2 | owner: *std.Build, | 2 | owner: *std.Build, |
| 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` | ||
| 5 | /// objects, respective `Step` dependencies can be added. | ||
| 6 | depending_steps: std.AutoArrayHashMapUnmanaged(*Step.Compile, void), | ||
| 7 | root_source_file: ?LazyPath, | 3 | root_source_file: ?LazyPath, |
| 8 | /// The modules that are mapped into this module's import table. | 4 | /// The modules that are mapped into this module's import table. |
| 9 | /// Use `addImport` rather than modifying this field directly in order to | 5 | /// Use `addImport` rather than modifying this field directly in order to |
| ... | @@ -41,6 +37,10 @@ link_libcpp: ?bool, | ... | @@ -41,6 +37,10 @@ link_libcpp: ?bool, |
| 41 | /// Symbols to be exported when compiling to WebAssembly. | 37 | /// Symbols to be exported when compiling to WebAssembly. |
| 42 | export_symbol_names: []const []const u8 = &.{}, | 38 | export_symbol_names: []const []const u8 = &.{}, |
| 43 | 39 | ||
| 40 | /// Caches the result of `getGraph` when called multiple times. | ||
| 41 | /// Use `getGraph` instead of accessing this field directly. | ||
| 42 | cached_graph: Graph = .{ .modules = &.{}, .names = &.{} }, | ||
| 43 | |||
| 44 | pub const RPath = union(enum) { | 44 | pub const RPath = union(enum) { |
| 45 | lazy_path: LazyPath, | 45 | lazy_path: LazyPath, |
| 46 | special: []const u8, | 46 | special: []const u8, |
| ... | @@ -242,59 +242,61 @@ pub const Import = struct { | ... | @@ -242,59 +242,61 @@ pub const Import = struct { |
| 242 | module: *Module, | 242 | module: *Module, |
| 243 | }; | 243 | }; |
| 244 | 244 | ||
| 245 | pub fn init(m: *Module, owner: *std.Build, options: CreateOptions, compile: ?*Step.Compile) void { | 245 | pub fn init( |
| 246 | m: *Module, | ||
| 247 | owner: *std.Build, | ||
| 248 | value: union(enum) { options: CreateOptions, existing: *const Module }, | ||
| 249 | ) void { | ||
| 246 | const allocator = owner.allocator; | 250 | const allocator = owner.allocator; |
| 247 | 251 | ||
| 248 | m.* = .{ | 252 | switch (value) { |
| 249 | .owner = owner, | 253 | .options => |options| { |
| 250 | .depending_steps = .{}, | 254 | m.* = .{ |
| 251 | .root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null, | 255 | .owner = owner, |
| 252 | .import_table = .{}, | 256 | .root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null, |
| 253 | .resolved_target = options.target, | 257 | .import_table = .{}, |
| 254 | .optimize = options.optimize, | 258 | .resolved_target = options.target, |
| 255 | .link_libc = options.link_libc, | 259 | .optimize = options.optimize, |
| 256 | .link_libcpp = options.link_libcpp, | 260 | .link_libc = options.link_libc, |
| 257 | .dwarf_format = options.dwarf_format, | 261 | .link_libcpp = options.link_libcpp, |
| 258 | .c_macros = .{}, | 262 | .dwarf_format = options.dwarf_format, |
| 259 | .include_dirs = .{}, | 263 | .c_macros = .{}, |
| 260 | .lib_paths = .{}, | 264 | .include_dirs = .{}, |
| 261 | .rpaths = .{}, | 265 | .lib_paths = .{}, |
| 262 | .frameworks = .{}, | 266 | .rpaths = .{}, |
| 263 | .link_objects = .{}, | 267 | .frameworks = .{}, |
| 264 | .strip = options.strip, | 268 | .link_objects = .{}, |
| 265 | .unwind_tables = options.unwind_tables, | 269 | .strip = options.strip, |
| 266 | .single_threaded = options.single_threaded, | 270 | .unwind_tables = options.unwind_tables, |
| 267 | .stack_protector = options.stack_protector, | 271 | .single_threaded = options.single_threaded, |
| 268 | .stack_check = options.stack_check, | 272 | .stack_protector = options.stack_protector, |
| 269 | .sanitize_c = options.sanitize_c, | 273 | .stack_check = options.stack_check, |
| 270 | .sanitize_thread = options.sanitize_thread, | 274 | .sanitize_c = options.sanitize_c, |
| 271 | .fuzz = options.fuzz, | 275 | .sanitize_thread = options.sanitize_thread, |
| 272 | .code_model = options.code_model, | 276 | .fuzz = options.fuzz, |
| 273 | .valgrind = options.valgrind, | 277 | .code_model = options.code_model, |
| 274 | .pic = options.pic, | 278 | .valgrind = options.valgrind, |
| 275 | .red_zone = options.red_zone, | 279 | .pic = options.pic, |
| 276 | .omit_frame_pointer = options.omit_frame_pointer, | 280 | .red_zone = options.red_zone, |
| 277 | .error_tracing = options.error_tracing, | 281 | .omit_frame_pointer = options.omit_frame_pointer, |
| 278 | .export_symbol_names = &.{}, | 282 | .error_tracing = options.error_tracing, |
| 279 | }; | 283 | .export_symbol_names = &.{}, |
| 280 | 284 | }; | |
| 281 | m.import_table.ensureUnusedCapacity(allocator, options.imports.len) catch @panic("OOM"); | ||
| 282 | for (options.imports) |dep| { | ||
| 283 | m.import_table.putAssumeCapacity(dep.name, dep.module); | ||
| 284 | } | ||
| 285 | 285 | ||
| 286 | if (compile) |c| { | 286 | m.import_table.ensureUnusedCapacity(allocator, options.imports.len) catch @panic("OOM"); |
| 287 | m.depending_steps.put(allocator, c, {}) catch @panic("OOM"); | 287 | for (options.imports) |dep| { |
| 288 | m.import_table.putAssumeCapacity(dep.name, dep.module); | ||
| 289 | } | ||
| 290 | }, | ||
| 291 | .existing => |existing| { | ||
| 292 | m.* = existing.*; | ||
| 293 | }, | ||
| 288 | } | 294 | } |
| 289 | |||
| 290 | // This logic accesses `depending_steps` which was just modified above. | ||
| 291 | var it = m.iterateDependencies(null, false); | ||
| 292 | while (it.next()) |item| addShallowDependencies(m, item.module); | ||
| 293 | } | 295 | } |
| 294 | 296 | ||
| 295 | pub fn create(owner: *std.Build, options: CreateOptions) *Module { | 297 | pub fn create(owner: *std.Build, options: CreateOptions) *Module { |
| 296 | const m = owner.allocator.create(Module) catch @panic("OOM"); | 298 | const m = owner.allocator.create(Module) catch @panic("OOM"); |
| 297 | m.init(owner, options, null); | 299 | m.init(owner, .{ .options = options }); |
| 298 | return m; | 300 | return m; |
| 299 | } | 301 | } |
| 300 | 302 | ||
| ... | @@ -302,69 +304,6 @@ pub fn create(owner: *std.Build, options: CreateOptions) *Module { | ... | @@ -302,69 +304,6 @@ pub fn create(owner: *std.Build, options: CreateOptions) *Module { |
| 302 | pub fn addImport(m: *Module, name: []const u8, module: *Module) void { | 304 | pub fn addImport(m: *Module, name: []const u8, module: *Module) void { |
| 303 | const b = m.owner; | 305 | const b = m.owner; |
| 304 | m.import_table.put(b.allocator, b.dupe(name), module) catch @panic("OOM"); | 306 | m.import_table.put(b.allocator, b.dupe(name), module) catch @panic("OOM"); |
| 305 | |||
| 306 | var it = module.iterateDependencies(null, false); | ||
| 307 | while (it.next()) |item| addShallowDependencies(m, item.module); | ||
| 308 | } | ||
| 309 | |||
| 310 | /// Creates step dependencies and updates `depending_steps` of `dependee` so that | ||
| 311 | /// subsequent calls to `addImport` on `dependee` will additionally create step | ||
| 312 | /// dependencies on `m`'s `depending_steps`. | ||
| 313 | fn addShallowDependencies(m: *Module, dependee: *Module) void { | ||
| 314 | if (dependee.root_source_file) |lazy_path| addLazyPathDependencies(m, dependee, lazy_path); | ||
| 315 | for (dependee.lib_paths.items) |lib_path| addLazyPathDependencies(m, dependee, lib_path); | ||
| 316 | for (dependee.rpaths.items) |rpath| switch (rpath) { | ||
| 317 | .lazy_path => |lp| addLazyPathDependencies(m, dependee, lp), | ||
| 318 | .special => {}, | ||
| 319 | }; | ||
| 320 | |||
| 321 | for (dependee.link_objects.items) |link_object| switch (link_object) { | ||
| 322 | .other_step => |compile| { | ||
| 323 | addStepDependencies(m, dependee, &compile.step); | ||
| 324 | addLazyPathDependenciesOnly(m, compile.getEmittedIncludeTree()); | ||
| 325 | }, | ||
| 326 | |||
| 327 | .static_path, | ||
| 328 | .assembly_file, | ||
| 329 | => |lp| addLazyPathDependencies(m, dependee, lp), | ||
| 330 | |||
| 331 | .c_source_file => |x| addLazyPathDependencies(m, dependee, x.file), | ||
| 332 | .win32_resource_file => |x| addLazyPathDependencies(m, dependee, x.file), | ||
| 333 | |||
| 334 | .c_source_files, | ||
| 335 | .system_lib, | ||
| 336 | => {}, | ||
| 337 | }; | ||
| 338 | } | ||
| 339 | |||
| 340 | fn addLazyPathDependencies(m: *Module, module: *Module, lazy_path: LazyPath) void { | ||
| 341 | addLazyPathDependenciesOnly(m, lazy_path); | ||
| 342 | if (m != module) { | ||
| 343 | for (m.depending_steps.keys()) |compile| { | ||
| 344 | module.depending_steps.put(m.owner.allocator, compile, {}) catch @panic("OOM"); | ||
| 345 | } | ||
| 346 | } | ||
| 347 | } | ||
| 348 | |||
| 349 | fn addLazyPathDependenciesOnly(m: *Module, lazy_path: LazyPath) void { | ||
| 350 | for (m.depending_steps.keys()) |compile| { | ||
| 351 | lazy_path.addStepDependencies(&compile.step); | ||
| 352 | } | ||
| 353 | } | ||
| 354 | |||
| 355 | fn addStepDependencies(m: *Module, module: *Module, dependee: *Step) void { | ||
| 356 | addStepDependenciesOnly(m, dependee); | ||
| 357 | if (m != module) { | ||
| 358 | for (m.depending_steps.keys()) |compile| { | ||
| 359 | module.depending_steps.put(m.owner.allocator, compile, {}) catch @panic("OOM"); | ||
| 360 | } | ||
| 361 | } | ||
| 362 | } | ||
| 363 | |||
| 364 | fn addStepDependenciesOnly(m: *Module, dependee: *Step) void { | ||
| 365 | for (m.depending_steps.keys()) |compile| { | ||
| 366 | compile.step.dependOn(dependee); | ||
| 367 | } | ||
| 368 | } | 307 | } |
| 369 | 308 | ||
| 370 | /// Creates a new module and adds it to be used with `@import`. | 309 | /// Creates a new module and adds it to be used with `@import`. |
| ... | @@ -380,91 +319,6 @@ pub fn addOptions(m: *Module, module_name: []const u8, options: *Step.Options) v | ... | @@ -380,91 +319,6 @@ pub fn addOptions(m: *Module, module_name: []const u8, options: *Step.Options) v |
| 380 | addImport(m, module_name, options.createModule()); | 319 | addImport(m, module_name, options.createModule()); |
| 381 | } | 320 | } |
| 382 | 321 | ||
| 383 | pub const DependencyIterator = struct { | ||
| 384 | allocator: std.mem.Allocator, | ||
| 385 | index: usize, | ||
| 386 | set: std.AutoArrayHashMapUnmanaged(Key, []const u8), | ||
| 387 | chase_dyn_libs: bool, | ||
| 388 | |||
| 389 | pub const Key = struct { | ||
| 390 | /// The compilation that contains the `Module`. Note that a `Module` might be | ||
| 391 | /// used by more than one compilation. | ||
| 392 | compile: ?*Step.Compile, | ||
| 393 | module: *Module, | ||
| 394 | }; | ||
| 395 | |||
| 396 | pub const Item = struct { | ||
| 397 | /// The compilation that contains the `Module`. Note that a `Module` might be | ||
| 398 | /// used by more than one compilation. | ||
| 399 | compile: ?*Step.Compile, | ||
| 400 | module: *Module, | ||
| 401 | name: []const u8, | ||
| 402 | }; | ||
| 403 | |||
| 404 | pub fn deinit(it: *DependencyIterator) void { | ||
| 405 | it.set.deinit(it.allocator); | ||
| 406 | it.* = undefined; | ||
| 407 | } | ||
| 408 | |||
| 409 | pub fn next(it: *DependencyIterator) ?Item { | ||
| 410 | if (it.index >= it.set.count()) { | ||
| 411 | it.set.clearAndFree(it.allocator); | ||
| 412 | return null; | ||
| 413 | } | ||
| 414 | const key = it.set.keys()[it.index]; | ||
| 415 | const name = it.set.values()[it.index]; | ||
| 416 | it.index += 1; | ||
| 417 | const module = key.module; | ||
| 418 | it.set.ensureUnusedCapacity(it.allocator, module.import_table.count()) catch | ||
| 419 | @panic("OOM"); | ||
| 420 | for (module.import_table.keys(), module.import_table.values()) |dep_name, dep| { | ||
| 421 | it.set.putAssumeCapacity(.{ | ||
| 422 | .module = dep, | ||
| 423 | .compile = key.compile, | ||
| 424 | }, dep_name); | ||
| 425 | } | ||
| 426 | |||
| 427 | if (key.compile != null) { | ||
| 428 | for (module.link_objects.items) |link_object| switch (link_object) { | ||
| 429 | .other_step => |compile| { | ||
| 430 | if (!it.chase_dyn_libs and compile.isDynamicLibrary()) continue; | ||
| 431 | |||
| 432 | it.set.put(it.allocator, .{ | ||
| 433 | .module = &compile.root_module, | ||
| 434 | .compile = compile, | ||
| 435 | }, "root") catch @panic("OOM"); | ||
| 436 | }, | ||
| 437 | else => {}, | ||
| 438 | }; | ||
| 439 | } | ||
| 440 | |||
| 441 | return .{ | ||
| 442 | .compile = key.compile, | ||
| 443 | .module = key.module, | ||
| 444 | .name = name, | ||
| 445 | }; | ||
| 446 | } | ||
| 447 | }; | ||
| 448 | |||
| 449 | pub fn iterateDependencies( | ||
| 450 | m: *Module, | ||
| 451 | chase_steps: ?*Step.Compile, | ||
| 452 | chase_dyn_libs: bool, | ||
| 453 | ) DependencyIterator { | ||
| 454 | var it: DependencyIterator = .{ | ||
| 455 | .allocator = m.owner.allocator, | ||
| 456 | .index = 0, | ||
| 457 | .set = .{}, | ||
| 458 | .chase_dyn_libs = chase_dyn_libs, | ||
| 459 | }; | ||
| 460 | it.set.ensureUnusedCapacity(m.owner.allocator, m.import_table.count() + 1) catch @panic("OOM"); | ||
| 461 | it.set.putAssumeCapacity(.{ | ||
| 462 | .module = m, | ||
| 463 | .compile = chase_steps, | ||
| 464 | }, "root"); | ||
| 465 | return it; | ||
| 466 | } | ||
| 467 | |||
| 468 | pub const LinkSystemLibraryOptions = struct { | 322 | pub const LinkSystemLibraryOptions = struct { |
| 469 | /// Causes dynamic libraries to be linked regardless of whether they are | 323 | /// Causes dynamic libraries to be linked regardless of whether they are |
| 470 | /// actually depended on. When false, dynamic libraries with no referenced | 324 | /// actually depended on. When false, dynamic libraries with no referenced |
| ... | @@ -547,7 +401,6 @@ pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void { | ... | @@ -547,7 +401,6 @@ pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void { |
| 547 | .flags = b.dupeStrings(options.flags), | 401 | .flags = b.dupeStrings(options.flags), |
| 548 | }; | 402 | }; |
| 549 | m.link_objects.append(allocator, .{ .c_source_files = c_source_files }) catch @panic("OOM"); | 403 | m.link_objects.append(allocator, .{ .c_source_files = c_source_files }) catch @panic("OOM"); |
| 550 | addLazyPathDependenciesOnly(m, c_source_files.root); | ||
| 551 | } | 404 | } |
| 552 | 405 | ||
| 553 | pub fn addCSourceFile(m: *Module, source: CSourceFile) void { | 406 | pub fn addCSourceFile(m: *Module, source: CSourceFile) void { |
| ... | @@ -556,7 +409,6 @@ pub fn addCSourceFile(m: *Module, source: CSourceFile) void { | ... | @@ -556,7 +409,6 @@ pub fn addCSourceFile(m: *Module, source: CSourceFile) void { |
| 556 | const c_source_file = allocator.create(CSourceFile) catch @panic("OOM"); | 409 | const c_source_file = allocator.create(CSourceFile) catch @panic("OOM"); |
| 557 | c_source_file.* = source.dupe(b); | 410 | c_source_file.* = source.dupe(b); |
| 558 | m.link_objects.append(allocator, .{ .c_source_file = c_source_file }) catch @panic("OOM"); | 411 | m.link_objects.append(allocator, .{ .c_source_file = c_source_file }) catch @panic("OOM"); |
| 559 | addLazyPathDependenciesOnly(m, source.file); | ||
| 560 | } | 412 | } |
| 561 | 413 | ||
| 562 | /// Resource files must have the extension `.rc`. | 414 | /// Resource files must have the extension `.rc`. |
| ... | @@ -573,22 +425,16 @@ pub fn addWin32ResourceFile(m: *Module, source: RcSourceFile) void { | ... | @@ -573,22 +425,16 @@ pub fn addWin32ResourceFile(m: *Module, source: RcSourceFile) void { |
| 573 | const rc_source_file = allocator.create(RcSourceFile) catch @panic("OOM"); | 425 | const rc_source_file = allocator.create(RcSourceFile) catch @panic("OOM"); |
| 574 | rc_source_file.* = source.dupe(b); | 426 | rc_source_file.* = source.dupe(b); |
| 575 | m.link_objects.append(allocator, .{ .win32_resource_file = rc_source_file }) catch @panic("OOM"); | 427 | m.link_objects.append(allocator, .{ .win32_resource_file = rc_source_file }) catch @panic("OOM"); |
| 576 | addLazyPathDependenciesOnly(m, source.file); | ||
| 577 | for (source.include_paths) |include_path| { | ||
| 578 | addLazyPathDependenciesOnly(m, include_path); | ||
| 579 | } | ||
| 580 | } | 428 | } |
| 581 | 429 | ||
| 582 | pub fn addAssemblyFile(m: *Module, source: LazyPath) void { | 430 | pub fn addAssemblyFile(m: *Module, source: LazyPath) void { |
| 583 | const b = m.owner; | 431 | const b = m.owner; |
| 584 | m.link_objects.append(b.allocator, .{ .assembly_file = source.dupe(b) }) catch @panic("OOM"); | 432 | m.link_objects.append(b.allocator, .{ .assembly_file = source.dupe(b) }) catch @panic("OOM"); |
| 585 | addLazyPathDependenciesOnly(m, source); | ||
| 586 | } | 433 | } |
| 587 | 434 | ||
| 588 | pub fn addObjectFile(m: *Module, object: LazyPath) void { | 435 | pub fn addObjectFile(m: *Module, object: LazyPath) void { |
| 589 | const b = m.owner; | 436 | const b = m.owner; |
| 590 | m.link_objects.append(b.allocator, .{ .static_path = object.dupe(b) }) catch @panic("OOM"); | 437 | m.link_objects.append(b.allocator, .{ .static_path = object.dupe(b) }) catch @panic("OOM"); |
| 591 | addLazyPathDependenciesOnly(m, object); | ||
| 592 | } | 438 | } |
| 593 | 439 | ||
| 594 | pub fn addObject(m: *Module, object: *Step.Compile) void { | 440 | pub fn addObject(m: *Module, object: *Step.Compile) void { |
| ... | @@ -604,51 +450,43 @@ pub fn linkLibrary(m: *Module, library: *Step.Compile) void { | ... | @@ -604,51 +450,43 @@ pub fn linkLibrary(m: *Module, library: *Step.Compile) void { |
| 604 | pub fn addAfterIncludePath(m: *Module, lazy_path: LazyPath) void { | 450 | pub fn addAfterIncludePath(m: *Module, lazy_path: LazyPath) void { |
| 605 | const b = m.owner; | 451 | const b = m.owner; |
| 606 | m.include_dirs.append(b.allocator, .{ .path_after = lazy_path.dupe(b) }) catch @panic("OOM"); | 452 | m.include_dirs.append(b.allocator, .{ .path_after = lazy_path.dupe(b) }) catch @panic("OOM"); |
| 607 | addLazyPathDependenciesOnly(m, lazy_path); | ||
| 608 | } | 453 | } |
| 609 | 454 | ||
| 610 | pub fn addSystemIncludePath(m: *Module, lazy_path: LazyPath) void { | 455 | pub fn addSystemIncludePath(m: *Module, lazy_path: LazyPath) void { |
| 611 | const b = m.owner; | 456 | const b = m.owner; |
| 612 | m.include_dirs.append(b.allocator, .{ .path_system = lazy_path.dupe(b) }) catch @panic("OOM"); | 457 | m.include_dirs.append(b.allocator, .{ .path_system = lazy_path.dupe(b) }) catch @panic("OOM"); |
| 613 | addLazyPathDependenciesOnly(m, lazy_path); | ||
| 614 | } | 458 | } |
| 615 | 459 | ||
| 616 | pub fn addIncludePath(m: *Module, lazy_path: LazyPath) void { | 460 | pub fn addIncludePath(m: *Module, lazy_path: LazyPath) void { |
| 617 | const b = m.owner; | 461 | const b = m.owner; |
| 618 | m.include_dirs.append(b.allocator, .{ .path = lazy_path.dupe(b) }) catch @panic("OOM"); | 462 | m.include_dirs.append(b.allocator, .{ .path = lazy_path.dupe(b) }) catch @panic("OOM"); |
| 619 | addLazyPathDependenciesOnly(m, lazy_path); | ||
| 620 | } | 463 | } |
| 621 | 464 | ||
| 622 | pub fn addConfigHeader(m: *Module, config_header: *Step.ConfigHeader) void { | 465 | pub fn addConfigHeader(m: *Module, config_header: *Step.ConfigHeader) void { |
| 623 | const allocator = m.owner.allocator; | 466 | const allocator = m.owner.allocator; |
| 624 | m.include_dirs.append(allocator, .{ .config_header_step = config_header }) catch @panic("OOM"); | 467 | m.include_dirs.append(allocator, .{ .config_header_step = config_header }) catch @panic("OOM"); |
| 625 | addStepDependenciesOnly(m, &config_header.step); | ||
| 626 | } | 468 | } |
| 627 | 469 | ||
| 628 | pub fn addSystemFrameworkPath(m: *Module, directory_path: LazyPath) void { | 470 | pub fn addSystemFrameworkPath(m: *Module, directory_path: LazyPath) void { |
| 629 | const b = m.owner; | 471 | const b = m.owner; |
| 630 | m.include_dirs.append(b.allocator, .{ .framework_path_system = directory_path.dupe(b) }) catch | 472 | m.include_dirs.append(b.allocator, .{ .framework_path_system = directory_path.dupe(b) }) catch |
| 631 | @panic("OOM"); | 473 | @panic("OOM"); |
| 632 | addLazyPathDependenciesOnly(m, directory_path); | ||
| 633 | } | 474 | } |
| 634 | 475 | ||
| 635 | pub fn addFrameworkPath(m: *Module, directory_path: LazyPath) void { | 476 | pub fn addFrameworkPath(m: *Module, directory_path: LazyPath) void { |
| 636 | const b = m.owner; | 477 | const b = m.owner; |
| 637 | m.include_dirs.append(b.allocator, .{ .framework_path = directory_path.dupe(b) }) catch | 478 | m.include_dirs.append(b.allocator, .{ .framework_path = directory_path.dupe(b) }) catch |
| 638 | @panic("OOM"); | 479 | @panic("OOM"); |
| 639 | addLazyPathDependenciesOnly(m, directory_path); | ||
| 640 | } | 480 | } |
| 641 | 481 | ||
| 642 | pub fn addLibraryPath(m: *Module, directory_path: LazyPath) void { | 482 | pub fn addLibraryPath(m: *Module, directory_path: LazyPath) void { |
| 643 | const b = m.owner; | 483 | const b = m.owner; |
| 644 | m.lib_paths.append(b.allocator, directory_path.dupe(b)) catch @panic("OOM"); | 484 | m.lib_paths.append(b.allocator, directory_path.dupe(b)) catch @panic("OOM"); |
| 645 | addLazyPathDependenciesOnly(m, directory_path); | ||
| 646 | } | 485 | } |
| 647 | 486 | ||
| 648 | pub fn addRPath(m: *Module, directory_path: LazyPath) void { | 487 | pub fn addRPath(m: *Module, directory_path: LazyPath) void { |
| 649 | const b = m.owner; | 488 | const b = m.owner; |
| 650 | m.rpaths.append(b.allocator, .{ .lazy_path = directory_path.dupe(b) }) catch @panic("OOM"); | 489 | m.rpaths.append(b.allocator, .{ .lazy_path = directory_path.dupe(b) }) catch @panic("OOM"); |
| 651 | addLazyPathDependenciesOnly(m, directory_path); | ||
| 652 | } | 490 | } |
| 653 | 491 | ||
| 654 | pub fn addRPathSpecial(m: *Module, bytes: []const u8) void { | 492 | pub fn addRPathSpecial(m: *Module, bytes: []const u8) void { |
| ... | @@ -772,7 +610,6 @@ fn addFlag( | ... | @@ -772,7 +610,6 @@ fn addFlag( |
| 772 | fn linkLibraryOrObject(m: *Module, other: *Step.Compile) void { | 610 | fn linkLibraryOrObject(m: *Module, other: *Step.Compile) void { |
| 773 | const allocator = m.owner.allocator; | 611 | const allocator = m.owner.allocator; |
| 774 | _ = other.getEmittedBin(); // Indicate there is a dependency on the outputted binary. | 612 | _ = other.getEmittedBin(); // Indicate there is a dependency on the outputted binary. |
| 775 | addStepDependenciesOnly(m, &other.step); | ||
| 776 | 613 | ||
| 777 | if (other.rootModuleTarget().os.tag == .windows and other.isDynamicLibrary()) { | 614 | if (other.rootModuleTarget().os.tag == .windows and other.isDynamicLibrary()) { |
| 778 | _ = other.getEmittedImplib(); // Indicate dependency on the outputted implib. | 615 | _ = other.getEmittedImplib(); // Indicate dependency on the outputted implib. |
| ... | @@ -780,8 +617,6 @@ fn linkLibraryOrObject(m: *Module, other: *Step.Compile) void { | ... | @@ -780,8 +617,6 @@ fn linkLibraryOrObject(m: *Module, other: *Step.Compile) void { |
| 780 | 617 | ||
| 781 | m.link_objects.append(allocator, .{ .other_step = other }) catch @panic("OOM"); | 618 | m.link_objects.append(allocator, .{ .other_step = other }) catch @panic("OOM"); |
| 782 | m.include_dirs.append(allocator, .{ .other_step = other }) catch @panic("OOM"); | 619 | m.include_dirs.append(allocator, .{ .other_step = other }) catch @panic("OOM"); |
| 783 | |||
| 784 | addLazyPathDependenciesOnly(m, other.getEmittedIncludeTree()); | ||
| 785 | } | 620 | } |
| 786 | 621 | ||
| 787 | fn requireKnownTarget(m: *Module) std.Target { | 622 | fn requireKnownTarget(m: *Module) std.Target { |
| ... | @@ -790,6 +625,46 @@ fn requireKnownTarget(m: *Module) std.Target { | ... | @@ -790,6 +625,46 @@ fn requireKnownTarget(m: *Module) std.Target { |
| 790 | return resolved_target.result; | 625 | return resolved_target.result; |
| 791 | } | 626 | } |
| 792 | 627 | ||
| 628 | /// Elements of `modules` and `names` are matched one-to-one. | ||
| 629 | pub const Graph = struct { | ||
| 630 | modules: []const *Module, | ||
| 631 | names: []const []const u8, | ||
| 632 | }; | ||
| 633 | |||
| 634 | /// Intended to be used during the make phase only. | ||
| 635 | /// | ||
| 636 | /// Given that `root` is the root `Module` of a compilation, return all `Module`s | ||
| 637 | /// in the module graph, including `root` itself. `root` is guaranteed to be the | ||
| 638 | /// first module in the returned slice. | ||
| 639 | pub fn getGraph(root: *Module) Graph { | ||
| 640 | if (root.cached_graph.modules.len != 0) { | ||
| 641 | return root.cached_graph; | ||
| 642 | } | ||
| 643 | |||
| 644 | const arena = root.owner.graph.arena; | ||
| 645 | |||
| 646 | var modules: std.AutoArrayHashMapUnmanaged(*std.Build.Module, []const u8) = .empty; | ||
| 647 | var next_idx: usize = 0; | ||
| 648 | |||
| 649 | modules.putNoClobber(arena, root, "root") catch @panic("OOM"); | ||
| 650 | |||
| 651 | while (next_idx < modules.count()) { | ||
| 652 | const mod = modules.keys()[next_idx]; | ||
| 653 | next_idx += 1; | ||
| 654 | modules.ensureUnusedCapacity(arena, mod.import_table.count()) catch @panic("OOM"); | ||
| 655 | for (mod.import_table.keys(), mod.import_table.values()) |import_name, other_mod| { | ||
| 656 | modules.putAssumeCapacity(other_mod, import_name); | ||
| 657 | } | ||
| 658 | } | ||
| 659 | |||
| 660 | const result: Graph = .{ | ||
| 661 | .modules = modules.keys(), | ||
| 662 | .names = modules.values(), | ||
| 663 | }; | ||
| 664 | root.cached_graph = result; | ||
| 665 | return result; | ||
| 666 | } | ||
| 667 | |||
| 793 | const Module = @This(); | 668 | const Module = @This(); |
| 794 | const std = @import("std"); | 669 | const std = @import("std"); |
| 795 | const assert = std.debug.assert; | 670 | const assert = std.debug.assert; |
lib/std/Build/Step/Compile.zig+283-271| ... | @@ -22,7 +22,7 @@ const Path = std.Build.Cache.Path; | ... | @@ -22,7 +22,7 @@ const Path = std.Build.Cache.Path; |
| 22 | pub const base_id: Step.Id = .compile; | 22 | pub const base_id: Step.Id = .compile; |
| 23 | 23 | ||
| 24 | step: Step, | 24 | step: Step, |
| 25 | root_module: Module, | 25 | root_module: *Module, |
| 26 | 26 | ||
| 27 | name: []const u8, | 27 | name: []const u8, |
| 28 | linker_script: ?LazyPath = null, | 28 | linker_script: ?LazyPath = null, |
| ... | @@ -262,7 +262,7 @@ pub const Entry = union(enum) { | ... | @@ -262,7 +262,7 @@ pub const Entry = union(enum) { |
| 262 | 262 | ||
| 263 | pub const Options = struct { | 263 | pub const Options = struct { |
| 264 | name: []const u8, | 264 | name: []const u8, |
| 265 | root_module: Module.CreateOptions, | 265 | root_module: *Module, |
| 266 | kind: Kind, | 266 | kind: Kind, |
| 267 | linkage: ?std.builtin.LinkMode = null, | 267 | linkage: ?std.builtin.LinkMode = null, |
| 268 | version: ?std.SemanticVersion = null, | 268 | version: ?std.SemanticVersion = null, |
| ... | @@ -359,7 +359,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -359,7 +359,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 359 | else | 359 | else |
| 360 | owner.fmt("{s} ", .{name}); | 360 | owner.fmt("{s} ", .{name}); |
| 361 | 361 | ||
| 362 | const resolved_target = options.root_module.target.?; | 362 | const resolved_target = options.root_module.resolved_target orelse |
| 363 | @panic("the root Module of a Compile step must be created with a known 'target' field"); | ||
| 363 | const target = resolved_target.result; | 364 | const target = resolved_target.result; |
| 364 | 365 | ||
| 365 | const step_name = owner.fmt("{s} {s}{s} {s}", .{ | 366 | const step_name = owner.fmt("{s} {s}{s} {s}", .{ |
| ... | @@ -388,7 +389,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -388,7 +389,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 388 | 389 | ||
| 389 | const compile = owner.allocator.create(Compile) catch @panic("OOM"); | 390 | const compile = owner.allocator.create(Compile) catch @panic("OOM"); |
| 390 | compile.* = .{ | 391 | compile.* = .{ |
| 391 | .root_module = undefined, | 392 | .root_module = options.root_module, |
| 392 | .verbose_link = false, | 393 | .verbose_link = false, |
| 393 | .verbose_cc = false, | 394 | .verbose_cc = false, |
| 394 | .linkage = options.linkage, | 395 | .linkage = options.linkage, |
| ... | @@ -432,8 +433,6 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -432,8 +433,6 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 432 | .zig_process = null, | 433 | .zig_process = null, |
| 433 | }; | 434 | }; |
| 434 | 435 | ||
| 435 | compile.root_module.init(owner, options.root_module, compile); | ||
| 436 | |||
| 437 | if (options.zig_lib_dir) |lp| { | 436 | if (options.zig_lib_dir) |lp| { |
| 438 | compile.zig_lib_dir = lp.dupe(compile.step.owner); | 437 | compile.zig_lib_dir = lp.dupe(compile.step.owner); |
| 439 | lp.addStepDependencies(&compile.step); | 438 | lp.addStepDependencies(&compile.step); |
| ... | @@ -583,9 +582,6 @@ pub fn checkObject(compile: *Compile) *Step.CheckObject { | ... | @@ -583,9 +582,6 @@ pub fn checkObject(compile: *Compile) *Step.CheckObject { |
| 583 | return Step.CheckObject.create(compile.step.owner, compile.getEmittedBin(), compile.rootModuleTarget().ofmt); | 582 | return Step.CheckObject.create(compile.step.owner, compile.getEmittedBin(), compile.rootModuleTarget().ofmt); |
| 584 | } | 583 | } |
| 585 | 584 | ||
| 586 | /// deprecated: use `setLinkerScript` | ||
| 587 | pub const setLinkerScriptPath = setLinkerScript; | ||
| 588 | |||
| 589 | pub fn setLinkerScript(compile: *Compile, source: LazyPath) void { | 585 | pub fn setLinkerScript(compile: *Compile, source: LazyPath) void { |
| 590 | const b = compile.step.owner; | 586 | const b = compile.step.owner; |
| 591 | compile.linker_script = source.dupe(b); | 587 | compile.linker_script = source.dupe(b); |
| ... | @@ -609,16 +605,17 @@ pub fn dependsOnSystemLibrary(compile: *const Compile, name: []const u8) bool { | ... | @@ -609,16 +605,17 @@ pub fn dependsOnSystemLibrary(compile: *const Compile, name: []const u8) bool { |
| 609 | var is_linking_libc = false; | 605 | var is_linking_libc = false; |
| 610 | var is_linking_libcpp = false; | 606 | var is_linking_libcpp = false; |
| 611 | 607 | ||
| 612 | var dep_it = compile.root_module.iterateDependencies(compile, true); | 608 | for (compile.getCompileDependencies(true)) |some_compile| { |
| 613 | while (dep_it.next()) |module| { | 609 | for (some_compile.root_module.getGraph().modules) |mod| { |
| 614 | for (module.link_objects.items) |link_object| { | 610 | for (mod.link_objects.items) |lo| { |
| 615 | switch (link_object) { | 611 | switch (lo) { |
| 616 | .system_lib => |lib| if (mem.eql(u8, lib.name, name)) return true, | 612 | .system_lib => |lib| if (mem.eql(u8, lib.name, name)) return true, |
| 617 | else => continue, | 613 | else => {}, |
| 614 | } | ||
| 618 | } | 615 | } |
| 616 | if (mod.link_libc) is_linking_libc = true; | ||
| 617 | if (mod.link_libcpp) is_linking_libcpp = true; | ||
| 619 | } | 618 | } |
| 620 | is_linking_libc = is_linking_libc or module.link_libc == true; | ||
| 621 | is_linking_libcpp = is_linking_libcpp or module.link_libcpp == true; | ||
| 622 | } | 619 | } |
| 623 | 620 | ||
| 624 | const target = compile.rootModuleTarget(); | 621 | const target = compile.rootModuleTarget(); |
| ... | @@ -675,11 +672,6 @@ pub fn linkLibCpp(compile: *Compile) void { | ... | @@ -675,11 +672,6 @@ pub fn linkLibCpp(compile: *Compile) void { |
| 675 | compile.root_module.link_libcpp = true; | 672 | compile.root_module.link_libcpp = true; |
| 676 | } | 673 | } |
| 677 | 674 | ||
| 678 | /// Deprecated. Use `c.root_module.addCMacro`. | ||
| 679 | pub fn defineCMacro(c: *Compile, name: []const u8, value: ?[]const u8) void { | ||
| 680 | c.root_module.addCMacro(name, value orelse "1"); | ||
| 681 | } | ||
| 682 | |||
| 683 | const PkgConfigResult = struct { | 675 | const PkgConfigResult = struct { |
| 684 | cflags: []const []const u8, | 676 | cflags: []const []const u8, |
| 685 | libs: []const []const u8, | 677 | libs: []const []const u8, |
| ... | @@ -805,16 +797,6 @@ pub fn linkFramework(c: *Compile, name: []const u8) void { | ... | @@ -805,16 +797,6 @@ pub fn linkFramework(c: *Compile, name: []const u8) void { |
| 805 | c.root_module.linkFramework(name, .{}); | 797 | c.root_module.linkFramework(name, .{}); |
| 806 | } | 798 | } |
| 807 | 799 | ||
| 808 | /// Deprecated. Use `c.root_module.linkFramework`. | ||
| 809 | pub fn linkFrameworkNeeded(c: *Compile, name: []const u8) void { | ||
| 810 | c.root_module.linkFramework(name, .{ .needed = true }); | ||
| 811 | } | ||
| 812 | |||
| 813 | /// Deprecated. Use `c.root_module.linkFramework`. | ||
| 814 | pub fn linkFrameworkWeak(c: *Compile, name: []const u8) void { | ||
| 815 | c.root_module.linkFramework(name, .{ .weak = true }); | ||
| 816 | } | ||
| 817 | |||
| 818 | /// Handy when you have many C/C++ source files and want them all to have the same flags. | 800 | /// Handy when you have many C/C++ source files and want them all to have the same flags. |
| 819 | pub fn addCSourceFiles(compile: *Compile, options: Module.AddCSourceFilesOptions) void { | 801 | pub fn addCSourceFiles(compile: *Compile, options: Module.AddCSourceFilesOptions) void { |
| 820 | compile.root_module.addCSourceFiles(options); | 802 | compile.root_module.addCSourceFiles(options); |
| ... | @@ -978,23 +960,22 @@ const CliNamedModules = struct { | ... | @@ -978,23 +960,22 @@ const CliNamedModules = struct { |
| 978 | .modules = .{}, | 960 | .modules = .{}, |
| 979 | .names = .{}, | 961 | .names = .{}, |
| 980 | }; | 962 | }; |
| 981 | var dep_it = root_module.iterateDependencies(null, false); | 963 | const graph = root_module.getGraph(); |
| 982 | { | 964 | { |
| 983 | const item = dep_it.next().?; | 965 | assert(graph.modules[0] == root_module); |
| 984 | assert(root_module == item.module); | ||
| 985 | try compile.modules.put(arena, root_module, {}); | 966 | try compile.modules.put(arena, root_module, {}); |
| 986 | try compile.names.put(arena, "root", {}); | 967 | try compile.names.put(arena, "root", {}); |
| 987 | } | 968 | } |
| 988 | while (dep_it.next()) |item| { | 969 | for (graph.modules[1..], graph.names[1..]) |mod, orig_name| { |
| 989 | var name = item.name; | 970 | var name = orig_name; |
| 990 | var n: usize = 0; | 971 | var n: usize = 0; |
| 991 | while (true) { | 972 | while (true) { |
| 992 | const gop = try compile.names.getOrPut(arena, name); | 973 | const gop = try compile.names.getOrPut(arena, name); |
| 993 | if (!gop.found_existing) { | 974 | if (!gop.found_existing) { |
| 994 | try compile.modules.putNoClobber(arena, item.module, {}); | 975 | try compile.modules.putNoClobber(arena, mod, {}); |
| 995 | break; | 976 | break; |
| 996 | } | 977 | } |
| 997 | name = try std.fmt.allocPrint(arena, "{s}{d}", .{ item.name, n }); | 978 | name = try std.fmt.allocPrint(arena, "{s}{d}", .{ orig_name, n }); |
| 998 | n += 1; | 979 | n += 1; |
| 999 | } | 980 | } |
| 1000 | } | 981 | } |
| ... | @@ -1097,279 +1078,278 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 { | ... | @@ -1097,279 +1078,278 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 { |
| 1097 | // emitted if there is nothing to link. | 1078 | // emitted if there is nothing to link. |
| 1098 | var total_linker_objects: usize = @intFromBool(compile.root_module.root_source_file != null); | 1079 | var total_linker_objects: usize = @intFromBool(compile.root_module.root_source_file != null); |
| 1099 | 1080 | ||
| 1100 | { | 1081 | // Fully recursive iteration including dynamic libraries to detect |
| 1101 | // Fully recursive iteration including dynamic libraries to detect | 1082 | // libc and libc++ linkage. |
| 1102 | // libc and libc++ linkage. | 1083 | for (compile.getCompileDependencies(true)) |some_compile| { |
| 1103 | var dep_it = compile.root_module.iterateDependencies(compile, true); | 1084 | for (some_compile.root_module.getGraph().modules) |mod| { |
| 1104 | while (dep_it.next()) |key| { | 1085 | if (mod.link_libc == true) compile.is_linking_libc = true; |
| 1105 | if (key.module.link_libc == true) compile.is_linking_libc = true; | 1086 | if (mod.link_libcpp == true) compile.is_linking_libcpp = true; |
| 1106 | if (key.module.link_libcpp == true) compile.is_linking_libcpp = true; | ||
| 1107 | } | 1087 | } |
| 1108 | } | 1088 | } |
| 1109 | 1089 | ||
| 1110 | var cli_named_modules = try CliNamedModules.init(arena, &compile.root_module); | 1090 | var cli_named_modules = try CliNamedModules.init(arena, compile.root_module); |
| 1111 | 1091 | ||
| 1112 | // For this loop, don't chase dynamic libraries because their link | 1092 | // For this loop, don't chase dynamic libraries because their link |
| 1113 | // objects are already linked. | 1093 | // objects are already linked. |
| 1114 | var dep_it = compile.root_module.iterateDependencies(compile, false); | 1094 | for (compile.getCompileDependencies(false)) |dep_compile| { |
| 1115 | 1095 | for (dep_compile.root_module.getGraph().modules) |mod| { | |
| 1116 | while (dep_it.next()) |dep| { | 1096 | // While walking transitive dependencies, if a given link object is |
| 1117 | // While walking transitive dependencies, if a given link object is | 1097 | // already included in a library, it should not redundantly be |
| 1118 | // already included in a library, it should not redundantly be | 1098 | // placed on the linker line of the dependee. |
| 1119 | // placed on the linker line of the dependee. | 1099 | const my_responsibility = dep_compile == compile; |
| 1120 | const my_responsibility = dep.compile.? == compile; | 1100 | const already_linked = !my_responsibility and dep_compile.isDynamicLibrary(); |
| 1121 | const already_linked = !my_responsibility and dep.compile.?.isDynamicLibrary(); | 1101 | |
| 1122 | 1102 | // Inherit dependencies on darwin frameworks. | |
| 1123 | // Inherit dependencies on darwin frameworks. | 1103 | if (!already_linked) { |
| 1124 | if (!already_linked) { | 1104 | for (mod.frameworks.keys(), mod.frameworks.values()) |name, info| { |
| 1125 | for (dep.module.frameworks.keys(), dep.module.frameworks.values()) |name, info| { | 1105 | try frameworks.put(arena, name, info); |
| 1126 | try frameworks.put(arena, name, info); | 1106 | } |
| 1127 | } | 1107 | } |
| 1128 | } | ||
| 1129 | 1108 | ||
| 1130 | // Inherit dependencies on system libraries and static libraries. | 1109 | // Inherit dependencies on system libraries and static libraries. |
| 1131 | for (dep.module.link_objects.items) |link_object| { | 1110 | for (mod.link_objects.items) |link_object| { |
| 1132 | switch (link_object) { | 1111 | switch (link_object) { |
| 1133 | .static_path => |static_path| { | 1112 | .static_path => |static_path| { |
| 1134 | if (my_responsibility) { | 1113 | if (my_responsibility) { |
| 1135 | try zig_args.append(static_path.getPath2(dep.module.owner, step)); | 1114 | try zig_args.append(static_path.getPath2(mod.owner, step)); |
| 1136 | total_linker_objects += 1; | 1115 | total_linker_objects += 1; |
| 1137 | } | 1116 | } |
| 1138 | }, | 1117 | }, |
| 1139 | .system_lib => |system_lib| { | 1118 | .system_lib => |system_lib| { |
| 1140 | const system_lib_gop = try seen_system_libs.getOrPut(arena, system_lib.name); | 1119 | const system_lib_gop = try seen_system_libs.getOrPut(arena, system_lib.name); |
| 1141 | if (system_lib_gop.found_existing) { | 1120 | if (system_lib_gop.found_existing) { |
| 1142 | try zig_args.appendSlice(system_lib_gop.value_ptr.*); | 1121 | try zig_args.appendSlice(system_lib_gop.value_ptr.*); |
| 1143 | continue; | 1122 | continue; |
| 1144 | } else { | 1123 | } else { |
| 1145 | system_lib_gop.value_ptr.* = &.{}; | 1124 | system_lib_gop.value_ptr.* = &.{}; |
| 1146 | } | ||
| 1147 | |||
| 1148 | if (already_linked) | ||
| 1149 | continue; | ||
| 1150 | |||
| 1151 | if ((system_lib.search_strategy != prev_search_strategy or | ||
| 1152 | system_lib.preferred_link_mode != prev_preferred_link_mode) and | ||
| 1153 | compile.linkage != .static) | ||
| 1154 | { | ||
| 1155 | switch (system_lib.search_strategy) { | ||
| 1156 | .no_fallback => switch (system_lib.preferred_link_mode) { | ||
| 1157 | .dynamic => try zig_args.append("-search_dylibs_only"), | ||
| 1158 | .static => try zig_args.append("-search_static_only"), | ||
| 1159 | }, | ||
| 1160 | .paths_first => switch (system_lib.preferred_link_mode) { | ||
| 1161 | .dynamic => try zig_args.append("-search_paths_first"), | ||
| 1162 | .static => try zig_args.append("-search_paths_first_static"), | ||
| 1163 | }, | ||
| 1164 | .mode_first => switch (system_lib.preferred_link_mode) { | ||
| 1165 | .dynamic => try zig_args.append("-search_dylibs_first"), | ||
| 1166 | .static => try zig_args.append("-search_static_first"), | ||
| 1167 | }, | ||
| 1168 | } | 1125 | } |
| 1169 | prev_search_strategy = system_lib.search_strategy; | ||
| 1170 | prev_preferred_link_mode = system_lib.preferred_link_mode; | ||
| 1171 | } | ||
| 1172 | 1126 | ||
| 1173 | const prefix: []const u8 = prefix: { | 1127 | if (already_linked) |
| 1174 | if (system_lib.needed) break :prefix "-needed-l"; | 1128 | continue; |
| 1175 | if (system_lib.weak) break :prefix "-weak-l"; | 1129 | |
| 1176 | break :prefix "-l"; | 1130 | if ((system_lib.search_strategy != prev_search_strategy or |
| 1177 | }; | 1131 | system_lib.preferred_link_mode != prev_preferred_link_mode) and |
| 1178 | switch (system_lib.use_pkg_config) { | 1132 | compile.linkage != .static) |
| 1179 | .no => try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })), | 1133 | { |
| 1180 | .yes, .force => { | 1134 | switch (system_lib.search_strategy) { |
| 1181 | if (compile.runPkgConfig(system_lib.name)) |result| { | 1135 | .no_fallback => switch (system_lib.preferred_link_mode) { |
| 1182 | try zig_args.appendSlice(result.cflags); | 1136 | .dynamic => try zig_args.append("-search_dylibs_only"), |
| 1183 | try zig_args.appendSlice(result.libs); | 1137 | .static => try zig_args.append("-search_static_only"), |
| 1184 | try seen_system_libs.put(arena, system_lib.name, result.cflags); | 1138 | }, |
| 1185 | } else |err| switch (err) { | 1139 | .paths_first => switch (system_lib.preferred_link_mode) { |
| 1186 | error.PkgConfigInvalidOutput, | 1140 | .dynamic => try zig_args.append("-search_paths_first"), |
| 1187 | error.PkgConfigCrashed, | 1141 | .static => try zig_args.append("-search_paths_first_static"), |
| 1188 | error.PkgConfigFailed, | 1142 | }, |
| 1189 | error.PkgConfigNotInstalled, | 1143 | .mode_first => switch (system_lib.preferred_link_mode) { |
| 1190 | error.PackageNotFound, | 1144 | .dynamic => try zig_args.append("-search_dylibs_first"), |
| 1191 | => switch (system_lib.use_pkg_config) { | 1145 | .static => try zig_args.append("-search_static_first"), |
| 1192 | .yes => { | ||
| 1193 | // pkg-config failed, so fall back to linking the library | ||
| 1194 | // by name directly. | ||
| 1195 | try zig_args.append(b.fmt("{s}{s}", .{ | ||
| 1196 | prefix, | ||
| 1197 | system_lib.name, | ||
| 1198 | })); | ||
| 1199 | }, | ||
| 1200 | .force => { | ||
| 1201 | panic("pkg-config failed for library {s}", .{system_lib.name}); | ||
| 1202 | }, | ||
| 1203 | .no => unreachable, | ||
| 1204 | }, | 1146 | }, |
| 1205 | |||
| 1206 | else => |e| return e, | ||
| 1207 | } | ||
| 1208 | }, | ||
| 1209 | } | ||
| 1210 | }, | ||
| 1211 | .other_step => |other| { | ||
| 1212 | switch (other.kind) { | ||
| 1213 | .exe => return step.fail("cannot link with an executable build artifact", .{}), | ||
| 1214 | .@"test" => return step.fail("cannot link with a test", .{}), | ||
| 1215 | .obj => { | ||
| 1216 | const included_in_lib_or_obj = !my_responsibility and | ||
| 1217 | (dep.compile.?.kind == .lib or dep.compile.?.kind == .obj); | ||
| 1218 | if (!already_linked and !included_in_lib_or_obj) { | ||
| 1219 | try zig_args.append(other.getEmittedBin().getPath2(b, step)); | ||
| 1220 | total_linker_objects += 1; | ||
| 1221 | } | ||
| 1222 | }, | ||
| 1223 | .lib => l: { | ||
| 1224 | const other_produces_implib = other.producesImplib(); | ||
| 1225 | const other_is_static = other_produces_implib or other.isStaticLibrary(); | ||
| 1226 | |||
| 1227 | if (compile.isStaticLibrary() and other_is_static) { | ||
| 1228 | // Avoid putting a static library inside a static library. | ||
| 1229 | break :l; | ||
| 1230 | } | 1147 | } |
| 1148 | prev_search_strategy = system_lib.search_strategy; | ||
| 1149 | prev_preferred_link_mode = system_lib.preferred_link_mode; | ||
| 1150 | } | ||
| 1231 | 1151 | ||
| 1232 | // For DLLs, we must link against the implib. | 1152 | const prefix: []const u8 = prefix: { |
| 1233 | // For everything else, we directly link | 1153 | if (system_lib.needed) break :prefix "-needed-l"; |
| 1234 | // against the library file. | 1154 | if (system_lib.weak) break :prefix "-weak-l"; |
| 1235 | const full_path_lib = if (other_produces_implib) | 1155 | break :prefix "-l"; |
| 1236 | other.getGeneratedFilePath("generated_implib", &compile.step) | 1156 | }; |
| 1237 | else | 1157 | switch (system_lib.use_pkg_config) { |
| 1238 | other.getGeneratedFilePath("generated_bin", &compile.step); | 1158 | .no => try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })), |
| 1159 | .yes, .force => { | ||
| 1160 | if (compile.runPkgConfig(system_lib.name)) |result| { | ||
| 1161 | try zig_args.appendSlice(result.cflags); | ||
| 1162 | try zig_args.appendSlice(result.libs); | ||
| 1163 | try seen_system_libs.put(arena, system_lib.name, result.cflags); | ||
| 1164 | } else |err| switch (err) { | ||
| 1165 | error.PkgConfigInvalidOutput, | ||
| 1166 | error.PkgConfigCrashed, | ||
| 1167 | error.PkgConfigFailed, | ||
| 1168 | error.PkgConfigNotInstalled, | ||
| 1169 | error.PackageNotFound, | ||
| 1170 | => switch (system_lib.use_pkg_config) { | ||
| 1171 | .yes => { | ||
| 1172 | // pkg-config failed, so fall back to linking the library | ||
| 1173 | // by name directly. | ||
| 1174 | try zig_args.append(b.fmt("{s}{s}", .{ | ||
| 1175 | prefix, | ||
| 1176 | system_lib.name, | ||
| 1177 | })); | ||
| 1178 | }, | ||
| 1179 | .force => { | ||
| 1180 | panic("pkg-config failed for library {s}", .{system_lib.name}); | ||
| 1181 | }, | ||
| 1182 | .no => unreachable, | ||
| 1183 | }, | ||
| 1239 | 1184 | ||
| 1240 | try zig_args.append(full_path_lib); | 1185 | else => |e| return e, |
| 1241 | total_linker_objects += 1; | 1186 | } |
| 1187 | }, | ||
| 1188 | } | ||
| 1189 | }, | ||
| 1190 | .other_step => |other| { | ||
| 1191 | switch (other.kind) { | ||
| 1192 | .exe => return step.fail("cannot link with an executable build artifact", .{}), | ||
| 1193 | .@"test" => return step.fail("cannot link with a test", .{}), | ||
| 1194 | .obj => { | ||
| 1195 | const included_in_lib_or_obj = !my_responsibility and | ||
| 1196 | (dep_compile.kind == .lib or dep_compile.kind == .obj); | ||
| 1197 | if (!already_linked and !included_in_lib_or_obj) { | ||
| 1198 | try zig_args.append(other.getEmittedBin().getPath2(b, step)); | ||
| 1199 | total_linker_objects += 1; | ||
| 1200 | } | ||
| 1201 | }, | ||
| 1202 | .lib => l: { | ||
| 1203 | const other_produces_implib = other.producesImplib(); | ||
| 1204 | const other_is_static = other_produces_implib or other.isStaticLibrary(); | ||
| 1242 | 1205 | ||
| 1243 | if (other.linkage == .dynamic and | 1206 | if (compile.isStaticLibrary() and other_is_static) { |
| 1244 | compile.rootModuleTarget().os.tag != .windows) | 1207 | // Avoid putting a static library inside a static library. |
| 1245 | { | 1208 | break :l; |
| 1246 | if (fs.path.dirname(full_path_lib)) |dirname| { | ||
| 1247 | try zig_args.append("-rpath"); | ||
| 1248 | try zig_args.append(dirname); | ||
| 1249 | } | 1209 | } |
| 1250 | } | ||
| 1251 | }, | ||
| 1252 | } | ||
| 1253 | }, | ||
| 1254 | .assembly_file => |asm_file| l: { | ||
| 1255 | if (!my_responsibility) break :l; | ||
| 1256 | 1210 | ||
| 1257 | if (prev_has_cflags) { | 1211 | // For DLLs, we must link against the implib. |
| 1258 | try zig_args.append("-cflags"); | 1212 | // For everything else, we directly link |
| 1259 | try zig_args.append("--"); | 1213 | // against the library file. |
| 1260 | prev_has_cflags = false; | 1214 | const full_path_lib = if (other_produces_implib) |
| 1261 | } | 1215 | other.getGeneratedFilePath("generated_implib", &compile.step) |
| 1262 | try zig_args.append(asm_file.getPath2(dep.module.owner, step)); | 1216 | else |
| 1263 | total_linker_objects += 1; | 1217 | other.getGeneratedFilePath("generated_bin", &compile.step); |
| 1264 | }, | ||
| 1265 | 1218 | ||
| 1266 | .c_source_file => |c_source_file| l: { | 1219 | try zig_args.append(full_path_lib); |
| 1267 | if (!my_responsibility) break :l; | 1220 | total_linker_objects += 1; |
| 1221 | |||
| 1222 | if (other.linkage == .dynamic and | ||
| 1223 | compile.rootModuleTarget().os.tag != .windows) | ||
| 1224 | { | ||
| 1225 | if (fs.path.dirname(full_path_lib)) |dirname| { | ||
| 1226 | try zig_args.append("-rpath"); | ||
| 1227 | try zig_args.append(dirname); | ||
| 1228 | } | ||
| 1229 | } | ||
| 1230 | }, | ||
| 1231 | } | ||
| 1232 | }, | ||
| 1233 | .assembly_file => |asm_file| l: { | ||
| 1234 | if (!my_responsibility) break :l; | ||
| 1268 | 1235 | ||
| 1269 | if (c_source_file.flags.len == 0) { | ||
| 1270 | if (prev_has_cflags) { | 1236 | if (prev_has_cflags) { |
| 1271 | try zig_args.append("-cflags"); | 1237 | try zig_args.append("-cflags"); |
| 1272 | try zig_args.append("--"); | 1238 | try zig_args.append("--"); |
| 1273 | prev_has_cflags = false; | 1239 | prev_has_cflags = false; |
| 1274 | } | 1240 | } |
| 1275 | } else { | 1241 | try zig_args.append(asm_file.getPath2(mod.owner, step)); |
| 1276 | try zig_args.append("-cflags"); | 1242 | total_linker_objects += 1; |
| 1277 | for (c_source_file.flags) |arg| { | 1243 | }, |
| 1278 | try zig_args.append(arg); | ||
| 1279 | } | ||
| 1280 | try zig_args.append("--"); | ||
| 1281 | prev_has_cflags = true; | ||
| 1282 | } | ||
| 1283 | try zig_args.append(c_source_file.file.getPath2(dep.module.owner, step)); | ||
| 1284 | total_linker_objects += 1; | ||
| 1285 | }, | ||
| 1286 | 1244 | ||
| 1287 | .c_source_files => |c_source_files| l: { | 1245 | .c_source_file => |c_source_file| l: { |
| 1288 | if (!my_responsibility) break :l; | 1246 | if (!my_responsibility) break :l; |
| 1289 | 1247 | ||
| 1290 | if (c_source_files.flags.len == 0) { | 1248 | if (c_source_file.flags.len == 0) { |
| 1291 | if (prev_has_cflags) { | 1249 | if (prev_has_cflags) { |
| 1250 | try zig_args.append("-cflags"); | ||
| 1251 | try zig_args.append("--"); | ||
| 1252 | prev_has_cflags = false; | ||
| 1253 | } | ||
| 1254 | } else { | ||
| 1292 | try zig_args.append("-cflags"); | 1255 | try zig_args.append("-cflags"); |
| 1256 | for (c_source_file.flags) |arg| { | ||
| 1257 | try zig_args.append(arg); | ||
| 1258 | } | ||
| 1293 | try zig_args.append("--"); | 1259 | try zig_args.append("--"); |
| 1294 | prev_has_cflags = false; | 1260 | prev_has_cflags = true; |
| 1295 | } | 1261 | } |
| 1296 | } else { | 1262 | try zig_args.append(c_source_file.file.getPath2(mod.owner, step)); |
| 1297 | try zig_args.append("-cflags"); | 1263 | total_linker_objects += 1; |
| 1298 | for (c_source_files.flags) |flag| { | 1264 | }, |
| 1299 | try zig_args.append(flag); | 1265 | |
| 1266 | .c_source_files => |c_source_files| l: { | ||
| 1267 | if (!my_responsibility) break :l; | ||
| 1268 | |||
| 1269 | if (c_source_files.flags.len == 0) { | ||
| 1270 | if (prev_has_cflags) { | ||
| 1271 | try zig_args.append("-cflags"); | ||
| 1272 | try zig_args.append("--"); | ||
| 1273 | prev_has_cflags = false; | ||
| 1274 | } | ||
| 1275 | } else { | ||
| 1276 | try zig_args.append("-cflags"); | ||
| 1277 | for (c_source_files.flags) |flag| { | ||
| 1278 | try zig_args.append(flag); | ||
| 1279 | } | ||
| 1280 | try zig_args.append("--"); | ||
| 1281 | prev_has_cflags = true; | ||
| 1300 | } | 1282 | } |
| 1301 | try zig_args.append("--"); | ||
| 1302 | prev_has_cflags = true; | ||
| 1303 | } | ||
| 1304 | 1283 | ||
| 1305 | const root_path = c_source_files.root.getPath2(dep.module.owner, step); | 1284 | const root_path = c_source_files.root.getPath2(mod.owner, step); |
| 1306 | for (c_source_files.files) |file| { | 1285 | for (c_source_files.files) |file| { |
| 1307 | try zig_args.append(b.pathJoin(&.{ root_path, file })); | 1286 | try zig_args.append(b.pathJoin(&.{ root_path, file })); |
| 1308 | } | 1287 | } |
| 1309 | 1288 | ||
| 1310 | total_linker_objects += c_source_files.files.len; | 1289 | total_linker_objects += c_source_files.files.len; |
| 1311 | }, | 1290 | }, |
| 1312 | 1291 | ||
| 1313 | .win32_resource_file => |rc_source_file| l: { | 1292 | .win32_resource_file => |rc_source_file| l: { |
| 1314 | if (!my_responsibility) break :l; | 1293 | if (!my_responsibility) break :l; |
| 1315 | 1294 | ||
| 1316 | if (rc_source_file.flags.len == 0 and rc_source_file.include_paths.len == 0) { | 1295 | if (rc_source_file.flags.len == 0 and rc_source_file.include_paths.len == 0) { |
| 1317 | if (prev_has_rcflags) { | 1296 | if (prev_has_rcflags) { |
| 1297 | try zig_args.append("-rcflags"); | ||
| 1298 | try zig_args.append("--"); | ||
| 1299 | prev_has_rcflags = false; | ||
| 1300 | } | ||
| 1301 | } else { | ||
| 1318 | try zig_args.append("-rcflags"); | 1302 | try zig_args.append("-rcflags"); |
| 1303 | for (rc_source_file.flags) |arg| { | ||
| 1304 | try zig_args.append(arg); | ||
| 1305 | } | ||
| 1306 | for (rc_source_file.include_paths) |include_path| { | ||
| 1307 | try zig_args.append("/I"); | ||
| 1308 | try zig_args.append(include_path.getPath2(mod.owner, step)); | ||
| 1309 | } | ||
| 1319 | try zig_args.append("--"); | 1310 | try zig_args.append("--"); |
| 1320 | prev_has_rcflags = false; | 1311 | prev_has_rcflags = true; |
| 1321 | } | ||
| 1322 | } else { | ||
| 1323 | try zig_args.append("-rcflags"); | ||
| 1324 | for (rc_source_file.flags) |arg| { | ||
| 1325 | try zig_args.append(arg); | ||
| 1326 | } | ||
| 1327 | for (rc_source_file.include_paths) |include_path| { | ||
| 1328 | try zig_args.append("/I"); | ||
| 1329 | try zig_args.append(include_path.getPath2(dep.module.owner, step)); | ||
| 1330 | } | 1312 | } |
| 1331 | try zig_args.append("--"); | 1313 | try zig_args.append(rc_source_file.file.getPath2(mod.owner, step)); |
| 1332 | prev_has_rcflags = true; | 1314 | total_linker_objects += 1; |
| 1333 | } | 1315 | }, |
| 1334 | try zig_args.append(rc_source_file.file.getPath2(dep.module.owner, step)); | 1316 | } |
| 1335 | total_linker_objects += 1; | ||
| 1336 | }, | ||
| 1337 | } | 1317 | } |
| 1338 | } | ||
| 1339 | 1318 | ||
| 1340 | // We need to emit the --mod argument here so that the above link objects | 1319 | // We need to emit the --mod argument here so that the above link objects |
| 1341 | // have the correct parent module, but only if the module is part of | 1320 | // have the correct parent module, but only if the module is part of |
| 1342 | // this compilation. | 1321 | // this compilation. |
| 1343 | if (!my_responsibility) continue; | 1322 | if (!my_responsibility) continue; |
| 1344 | if (cli_named_modules.modules.getIndex(dep.module)) |module_cli_index| { | 1323 | if (cli_named_modules.modules.getIndex(mod)) |module_cli_index| { |
| 1345 | const module_cli_name = cli_named_modules.names.keys()[module_cli_index]; | 1324 | const module_cli_name = cli_named_modules.names.keys()[module_cli_index]; |
| 1346 | try dep.module.appendZigProcessFlags(&zig_args, step); | 1325 | try mod.appendZigProcessFlags(&zig_args, step); |
| 1347 | 1326 | ||
| 1348 | // --dep arguments | 1327 | // --dep arguments |
| 1349 | try zig_args.ensureUnusedCapacity(dep.module.import_table.count() * 2); | 1328 | try zig_args.ensureUnusedCapacity(mod.import_table.count() * 2); |
| 1350 | for (dep.module.import_table.keys(), dep.module.import_table.values()) |name, import| { | 1329 | for (mod.import_table.keys(), mod.import_table.values()) |name, import| { |
| 1351 | const import_index = cli_named_modules.modules.getIndex(import).?; | 1330 | const import_index = cli_named_modules.modules.getIndex(import).?; |
| 1352 | const import_cli_name = cli_named_modules.names.keys()[import_index]; | 1331 | const import_cli_name = cli_named_modules.names.keys()[import_index]; |
| 1353 | zig_args.appendAssumeCapacity("--dep"); | 1332 | zig_args.appendAssumeCapacity("--dep"); |
| 1354 | if (std.mem.eql(u8, import_cli_name, name)) { | 1333 | if (std.mem.eql(u8, import_cli_name, name)) { |
| 1355 | zig_args.appendAssumeCapacity(import_cli_name); | 1334 | zig_args.appendAssumeCapacity(import_cli_name); |
| 1356 | } else { | 1335 | } else { |
| 1357 | zig_args.appendAssumeCapacity(b.fmt("{s}={s}", .{ name, import_cli_name })); | 1336 | zig_args.appendAssumeCapacity(b.fmt("{s}={s}", .{ name, import_cli_name })); |
| 1337 | } | ||
| 1358 | } | 1338 | } |
| 1359 | } | ||
| 1360 | 1339 | ||
| 1361 | // When the CLI sees a -M argument, it determines whether it | 1340 | // When the CLI sees a -M argument, it determines whether it |
| 1362 | // implies the existence of a Zig compilation unit based on | 1341 | // implies the existence of a Zig compilation unit based on |
| 1363 | // whether there is a root source file. If there is no root | 1342 | // whether there is a root source file. If there is no root |
| 1364 | // source file, then this is not a zig compilation unit - it is | 1343 | // source file, then this is not a zig compilation unit - it is |
| 1365 | // perhaps a set of linker objects, or C source files instead. | 1344 | // perhaps a set of linker objects, or C source files instead. |
| 1366 | // Linker objects are added to the CLI globally, while C source | 1345 | // Linker objects are added to the CLI globally, while C source |
| 1367 | // files must have a module parent. | 1346 | // files must have a module parent. |
| 1368 | if (dep.module.root_source_file) |lp| { | 1347 | if (mod.root_source_file) |lp| { |
| 1369 | const src = lp.getPath2(dep.module.owner, step); | 1348 | const src = lp.getPath2(mod.owner, step); |
| 1370 | try zig_args.append(b.fmt("-M{s}={s}", .{ module_cli_name, src })); | 1349 | try zig_args.append(b.fmt("-M{s}={s}", .{ module_cli_name, src })); |
| 1371 | } else if (moduleNeedsCliArg(dep.module)) { | 1350 | } else if (moduleNeedsCliArg(mod)) { |
| 1372 | try zig_args.append(b.fmt("-M{s}", .{module_cli_name})); | 1351 | try zig_args.append(b.fmt("-M{s}", .{module_cli_name})); |
| 1352 | } | ||
| 1373 | } | 1353 | } |
| 1374 | } | 1354 | } |
| 1375 | } | 1355 | } |
| ... | @@ -2081,3 +2061,35 @@ fn moduleNeedsCliArg(mod: *const Module) bool { | ... | @@ -2081,3 +2061,35 @@ fn moduleNeedsCliArg(mod: *const Module) bool { |
| 2081 | else => continue, | 2061 | else => continue, |
| 2082 | } else false; | 2062 | } else false; |
| 2083 | } | 2063 | } |
| 2064 | |||
| 2065 | /// Return the full set of `Step.Compile` which `start` depends on, recursively. `start` itself is | ||
| 2066 | /// always returned as the first element. If `chase_dynamic` is `false`, then dynamic libraries are | ||
| 2067 | /// not included, and their dependencies are not considered; if `chase_dynamic` is `true`, dynamic | ||
| 2068 | /// libraries are treated the same as other linked `Compile`s. | ||
| 2069 | pub fn getCompileDependencies(start: *Compile, chase_dynamic: bool) []const *Compile { | ||
| 2070 | const arena = start.step.owner.graph.arena; | ||
| 2071 | |||
| 2072 | var compiles: std.AutoArrayHashMapUnmanaged(*Compile, void) = .empty; | ||
| 2073 | var next_idx: usize = 0; | ||
| 2074 | |||
| 2075 | compiles.putNoClobber(arena, start, {}) catch @panic("OOM"); | ||
| 2076 | |||
| 2077 | while (next_idx < compiles.count()) { | ||
| 2078 | const compile = compiles.keys()[next_idx]; | ||
| 2079 | next_idx += 1; | ||
| 2080 | |||
| 2081 | for (compile.root_module.getGraph().modules) |mod| { | ||
| 2082 | for (mod.link_objects.items) |lo| { | ||
| 2083 | switch (lo) { | ||
| 2084 | .other_step => |other_compile| { | ||
| 2085 | if (!chase_dynamic and other_compile.isDynamicLibrary()) continue; | ||
| 2086 | compiles.put(arena, other_compile, {}) catch @panic("OOM"); | ||
| 2087 | }, | ||
| 2088 | else => {}, | ||
| 2089 | } | ||
| 2090 | } | ||
| 2091 | } | ||
| 2092 | } | ||
| 2093 | |||
| 2094 | return compiles.keys(); | ||
| 2095 | } |
lib/std/Build/Step/ObjCopy.zig-3| ... | @@ -135,9 +135,6 @@ pub fn create( | ... | @@ -135,9 +135,6 @@ pub fn create( |
| 135 | return objcopy; | 135 | return objcopy; |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | /// deprecated: use getOutput | ||
| 139 | pub const getOutputSource = getOutput; | ||
| 140 | |||
| 141 | pub fn getOutput(objcopy: *const ObjCopy) std.Build.LazyPath { | 138 | pub fn getOutput(objcopy: *const ObjCopy) std.Build.LazyPath { |
| 142 | return .{ .generated = .{ .file = &objcopy.output_file } }; | 139 | return .{ .generated = .{ .file = &objcopy.output_file } }; |
| 143 | } | 140 | } |
lib/std/Build/Step/Options.zig-8| ... | @@ -390,20 +390,12 @@ pub fn addOptionPath( | ... | @@ -390,20 +390,12 @@ pub fn addOptionPath( |
| 390 | path.addStepDependencies(&options.step); | 390 | path.addStepDependencies(&options.step); |
| 391 | } | 391 | } |
| 392 | 392 | ||
| 393 | /// Deprecated: use `addOptionPath(options, name, artifact.getEmittedBin())` instead. | ||
| 394 | pub fn addOptionArtifact(options: *Options, name: []const u8, artifact: *Step.Compile) void { | ||
| 395 | return addOptionPath(options, name, artifact.getEmittedBin()); | ||
| 396 | } | ||
| 397 | |||
| 398 | pub fn createModule(options: *Options) *std.Build.Module { | 393 | pub fn createModule(options: *Options) *std.Build.Module { |
| 399 | return options.step.owner.createModule(.{ | 394 | return options.step.owner.createModule(.{ |
| 400 | .root_source_file = options.getOutput(), | 395 | .root_source_file = options.getOutput(), |
| 401 | }); | 396 | }); |
| 402 | } | 397 | } |
| 403 | 398 | ||
| 404 | /// deprecated: use `getOutput` | ||
| 405 | pub const getSource = getOutput; | ||
| 406 | |||
| 407 | /// Returns the main artifact of this Build Step which is a Zig source file | 399 | /// Returns the main artifact of this Build Step which is a Zig source file |
| 408 | /// generated from the key-value pairs of the Options. | 400 | /// generated from the key-value pairs of the Options. |
| 409 | pub fn getOutput(options: *Options) LazyPath { | 401 | pub fn getOutput(options: *Options) LazyPath { |
lib/std/Build/Step/Run.zig+6-22| ... | @@ -43,9 +43,6 @@ stdio: StdIo, | ... | @@ -43,9 +43,6 @@ stdio: StdIo, |
| 43 | /// It should be only set using `setStdIn`. | 43 | /// It should be only set using `setStdIn`. |
| 44 | stdin: StdIn, | 44 | stdin: StdIn, |
| 45 | 45 | ||
| 46 | /// Deprecated: use `addFileInput` | ||
| 47 | extra_file_dependencies: []const []const u8, | ||
| 48 | |||
| 49 | /// Additional input files that, when modified, indicate that the Run step | 46 | /// Additional input files that, when modified, indicate that the Run step |
| 50 | /// should be re-executed. | 47 | /// should be re-executed. |
| 51 | /// If the Run step is determined to have side-effects, the Run step is always | 48 | /// If the Run step is determined to have side-effects, the Run step is always |
| ... | @@ -178,7 +175,6 @@ pub fn create(owner: *std.Build, name: []const u8) *Run { | ... | @@ -178,7 +175,6 @@ pub fn create(owner: *std.Build, name: []const u8) *Run { |
| 178 | .disable_zig_progress = false, | 175 | .disable_zig_progress = false, |
| 179 | .stdio = .infer_from_args, | 176 | .stdio = .infer_from_args, |
| 180 | .stdin = .none, | 177 | .stdin = .none, |
| 181 | .extra_file_dependencies = &.{}, | ||
| 182 | .file_inputs = .{}, | 178 | .file_inputs = .{}, |
| 183 | .rename_step_with_output_arg = true, | 179 | .rename_step_with_output_arg = true, |
| 184 | .skip_foreign_checks = false, | 180 | .skip_foreign_checks = false, |
| ... | @@ -364,16 +360,10 @@ pub fn addPrefixedOutputDirectoryArg( | ... | @@ -364,16 +360,10 @@ pub fn addPrefixedOutputDirectoryArg( |
| 364 | return .{ .generated = .{ .file = &output.generated_file } }; | 360 | return .{ .generated = .{ .file = &output.generated_file } }; |
| 365 | } | 361 | } |
| 366 | 362 | ||
| 367 | /// deprecated: use `addDirectoryArg` | ||
| 368 | pub const addDirectorySourceArg = addDirectoryArg; | ||
| 369 | |||
| 370 | pub fn addDirectoryArg(run: *Run, directory_source: std.Build.LazyPath) void { | 363 | pub fn addDirectoryArg(run: *Run, directory_source: std.Build.LazyPath) void { |
| 371 | run.addPrefixedDirectoryArg("", directory_source); | 364 | run.addPrefixedDirectoryArg("", directory_source); |
| 372 | } | 365 | } |
| 373 | 366 | ||
| 374 | // deprecated: use `addPrefixedDirectoryArg` | ||
| 375 | pub const addPrefixedDirectorySourceArg = addPrefixedDirectoryArg; | ||
| 376 | |||
| 377 | pub fn addPrefixedDirectoryArg(run: *Run, prefix: []const u8, directory_source: std.Build.LazyPath) void { | 367 | pub fn addPrefixedDirectoryArg(run: *Run, prefix: []const u8, directory_source: std.Build.LazyPath) void { |
| 378 | const b = run.step.owner; | 368 | const b = run.step.owner; |
| 379 | 369 | ||
| ... | @@ -698,9 +688,6 @@ fn make(step: *Step, options: Step.MakeOptions) !void { | ... | @@ -698,9 +688,6 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 698 | 688 | ||
| 699 | hashStdIo(&man.hash, run.stdio); | 689 | hashStdIo(&man.hash, run.stdio); |
| 700 | 690 | ||
| 701 | for (run.extra_file_dependencies) |file_path| { | ||
| 702 | _ = try man.addFile(b.pathFromRoot(file_path), null); | ||
| 703 | } | ||
| 704 | for (run.file_inputs.items) |lazy_path| { | 691 | for (run.file_inputs.items) |lazy_path| { |
| 705 | _ = try man.addFile(lazy_path.getPath2(b, step), null); | 692 | _ = try man.addFile(lazy_path.getPath2(b, step), null); |
| 706 | } | 693 | } |
| ... | @@ -1732,15 +1719,12 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult { | ... | @@ -1732,15 +1719,12 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !StdIoResult { |
| 1732 | 1719 | ||
| 1733 | fn addPathForDynLibs(run: *Run, artifact: *Step.Compile) void { | 1720 | fn addPathForDynLibs(run: *Run, artifact: *Step.Compile) void { |
| 1734 | const b = run.step.owner; | 1721 | const b = run.step.owner; |
| 1735 | var it = artifact.root_module.iterateDependencies(artifact, true); | 1722 | const compiles = artifact.getCompileDependencies(true); |
| 1736 | while (it.next()) |item| { | 1723 | for (compiles) |compile| { |
| 1737 | const other = item.compile.?; | 1724 | if (compile.root_module.resolved_target.?.result.os.tag == .windows and |
| 1738 | if (item.module == &other.root_module) { | 1725 | compile.isDynamicLibrary()) |
| 1739 | if (item.module.resolved_target.?.result.os.tag == .windows and | 1726 | { |
| 1740 | other.isDynamicLibrary()) | 1727 | addPathDir(run, fs.path.dirname(compile.getEmittedBin().getPath2(b, &run.step)).?); |
| 1741 | { | ||
| 1742 | addPathDir(run, fs.path.dirname(other.getEmittedBin().getPath2(b, &run.step)).?); | ||
| 1743 | } | ||
| 1744 | } | 1728 | } |
| 1745 | } | 1729 | } |
| 1746 | } | 1730 | } |
lib/std/Build/Step/TranslateC.zig+4| ... | @@ -63,6 +63,7 @@ pub fn getOutput(translate_c: *TranslateC) std.Build.LazyPath { | ... | @@ -63,6 +63,7 @@ pub fn getOutput(translate_c: *TranslateC) std.Build.LazyPath { |
| 63 | return .{ .generated = .{ .file = &translate_c.output_file } }; | 63 | return .{ .generated = .{ .file = &translate_c.output_file } }; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | /// Deprecated: use `createModule` or `addModule` with `std.Build.addExecutable` instead. | ||
| 66 | /// Creates a step to build an executable from the translated source. | 67 | /// Creates a step to build an executable from the translated source. |
| 67 | pub fn addExecutable(translate_c: *TranslateC, options: AddExecutableOptions) *Step.Compile { | 68 | pub fn addExecutable(translate_c: *TranslateC, options: AddExecutableOptions) *Step.Compile { |
| 68 | return translate_c.step.owner.addExecutable(.{ | 69 | return translate_c.step.owner.addExecutable(.{ |
| ... | @@ -81,6 +82,9 @@ pub fn addExecutable(translate_c: *TranslateC, options: AddExecutableOptions) *S | ... | @@ -81,6 +82,9 @@ pub fn addExecutable(translate_c: *TranslateC, options: AddExecutableOptions) *S |
| 81 | pub fn addModule(translate_c: *TranslateC, name: []const u8) *std.Build.Module { | 82 | pub fn addModule(translate_c: *TranslateC, name: []const u8) *std.Build.Module { |
| 82 | return translate_c.step.owner.addModule(name, .{ | 83 | return translate_c.step.owner.addModule(name, .{ |
| 83 | .root_source_file = translate_c.getOutput(), | 84 | .root_source_file = translate_c.getOutput(), |
| 85 | .target = translate_c.target, | ||
| 86 | .optimize = translate_c.optimize, | ||
| 87 | .link_libc = translate_c.link_libc, | ||
| 84 | }); | 88 | }); |
| 85 | } | 89 | } |
| 86 | 90 |
test/link/bss/build.zig+5-3| ... | @@ -6,9 +6,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,9 +6,11 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | ||
| 7 | const exe = b.addExecutable(.{ | 7 | const exe = b.addExecutable(.{ |
| 8 | .name = "bss", | 8 | .name = "bss", |
| 9 | .root_source_file = b.path("main.zig"), | 9 | .root_module = b.createModule(.{ |
| 10 | .target = b.graph.host, | 10 | .root_source_file = b.path("main.zig"), |
| 11 | .optimize = .Debug, | 11 | .target = b.graph.host, |
| 12 | .optimize = .Debug, | ||
| 13 | }), | ||
| 12 | }); | 14 | }); |
| 13 | 15 | ||
| 14 | const run = b.addRunArtifact(exe); | 16 | const run = b.addRunArtifact(exe); |
test/link/common_symbols/build.zig+11-6| ... | @@ -13,19 +13,24 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,19 +13,24 @@ 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 lib_a = b.addStaticLibrary(.{ | 14 | const lib_a = b.addStaticLibrary(.{ |
| 15 | .name = "a", | 15 | .name = "a", |
| 16 | .optimize = optimize, | 16 | .root_module = b.createModule(.{ |
| 17 | .target = b.graph.host, | 17 | .root_source_file = null, |
| 18 | .optimize = optimize, | ||
| 19 | .target = b.graph.host, | ||
| 20 | }), | ||
| 18 | }); | 21 | }); |
| 19 | lib_a.addCSourceFiles(.{ | 22 | lib_a.root_module.addCSourceFiles(.{ |
| 20 | .files = &.{ "c.c", "a.c", "b.c" }, | 23 | .files = &.{ "c.c", "a.c", "b.c" }, |
| 21 | .flags = &.{"-fcommon"}, | 24 | .flags = &.{"-fcommon"}, |
| 22 | }); | 25 | }); |
| 23 | 26 | ||
| 24 | const test_exe = b.addTest(.{ | 27 | const test_exe = b.addTest(.{ |
| 25 | .root_source_file = b.path("main.zig"), | 28 | .root_module = b.createModule(.{ |
| 26 | .optimize = optimize, | 29 | .root_source_file = b.path("main.zig"), |
| 30 | .optimize = optimize, | ||
| 31 | }), | ||
| 27 | }); | 32 | }); |
| 28 | test_exe.linkLibrary(lib_a); | 33 | test_exe.root_module.linkLibrary(lib_a); |
| 29 | 34 | ||
| 30 | test_step.dependOn(&b.addRunArtifact(test_exe).step); | 35 | test_step.dependOn(&b.addRunArtifact(test_exe).step); |
| 31 | } | 36 | } |
test/link/common_symbols_alignment/build.zig+12-6| ... | @@ -13,19 +13,25 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,19 +13,25 @@ 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 lib_a = b.addStaticLibrary(.{ | 14 | const lib_a = b.addStaticLibrary(.{ |
| 15 | .name = "a", | 15 | .name = "a", |
| 16 | .optimize = optimize, | 16 | .root_module = b.createModule(.{ |
| 17 | .target = b.graph.host, | 17 | .root_source_file = null, |
| 18 | .optimize = optimize, | ||
| 19 | .target = b.graph.host, | ||
| 20 | }), | ||
| 18 | }); | 21 | }); |
| 19 | lib_a.addCSourceFiles(.{ | 22 | lib_a.root_module.addCSourceFiles(.{ |
| 20 | .files = &.{"a.c"}, | 23 | .files = &.{"a.c"}, |
| 21 | .flags = &.{"-fcommon"}, | 24 | .flags = &.{"-fcommon"}, |
| 22 | }); | 25 | }); |
| 23 | 26 | ||
| 24 | const test_exe = b.addTest(.{ | 27 | const test_exe = b.addTest(.{ |
| 25 | .root_source_file = b.path("main.zig"), | 28 | .root_module = b.createModule(.{ |
| 26 | .optimize = optimize, | 29 | .root_source_file = b.path("main.zig"), |
| 30 | .target = b.graph.host, | ||
| 31 | .optimize = optimize, | ||
| 32 | }), | ||
| 27 | }); | 33 | }); |
| 28 | test_exe.linkLibrary(lib_a); | 34 | test_exe.root_module.linkLibrary(lib_a); |
| 29 | 35 | ||
| 30 | test_step.dependOn(&b.addRunArtifact(test_exe).step); | 36 | test_step.dependOn(&b.addRunArtifact(test_exe).step); |
| 31 | } | 37 | } |
test/link/glibc_compat/build.zig+19-11| ... | @@ -14,12 +14,15 @@ pub fn build(b: *std.Build) void { | ... | @@ -14,12 +14,15 @@ pub fn build(b: *std.Build) void { |
| 14 | for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| { | 14 | for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| { |
| 15 | const exe = b.addExecutable(.{ | 15 | const exe = b.addExecutable(.{ |
| 16 | .name = t, | 16 | .name = t, |
| 17 | .target = b.resolveTargetQuery(std.Target.Query.parse( | 17 | .root_module = b.createModule(.{ |
| 18 | .{ .arch_os_abi = t }, | 18 | .root_source_file = null, |
| 19 | ) catch unreachable), | 19 | .target = b.resolveTargetQuery(std.Target.Query.parse( |
| 20 | .{ .arch_os_abi = t }, | ||
| 21 | ) catch unreachable), | ||
| 22 | .link_libc = true, | ||
| 23 | }), | ||
| 20 | }); | 24 | }); |
| 21 | exe.addCSourceFile(.{ .file = b.path("main.c") }); | 25 | exe.root_module.addCSourceFile(.{ .file = b.path("main.c") }); |
| 22 | exe.linkLibC(); | ||
| 23 | // TODO: actually test the output | 26 | // TODO: actually test the output |
| 24 | _ = exe.getEmittedBin(); | 27 | _ = exe.getEmittedBin(); |
| 25 | test_step.dependOn(&exe.step); | 28 | test_step.dependOn(&exe.step); |
| ... | @@ -53,10 +56,13 @@ pub fn build(b: *std.Build) void { | ... | @@ -53,10 +56,13 @@ pub fn build(b: *std.Build) void { |
| 53 | 56 | ||
| 54 | const exe = b.addExecutable(.{ | 57 | const exe = b.addExecutable(.{ |
| 55 | .name = t, | 58 | .name = t, |
| 56 | .target = target, | 59 | .root_module = b.createModule(.{ |
| 60 | .root_source_file = null, | ||
| 61 | .target = target, | ||
| 62 | .link_libc = true, | ||
| 63 | }), | ||
| 57 | }); | 64 | }); |
| 58 | exe.addCSourceFile(.{ .file = b.path("glibc_runtime_check.c") }); | 65 | exe.root_module.addCSourceFile(.{ .file = b.path("glibc_runtime_check.c") }); |
| 59 | exe.linkLibC(); | ||
| 60 | 66 | ||
| 61 | // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig | 67 | // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig |
| 62 | // test runner would be able to check this, but see https://github.com/ziglang/zig/pull/17702#issuecomment-1831310453 | 68 | // test runner would be able to check this, but see https://github.com/ziglang/zig/pull/17702#issuecomment-1831310453 |
| ... | @@ -149,10 +155,12 @@ pub fn build(b: *std.Build) void { | ... | @@ -149,10 +155,12 @@ pub fn build(b: *std.Build) void { |
| 149 | 155 | ||
| 150 | const exe = b.addExecutable(.{ | 156 | const exe = b.addExecutable(.{ |
| 151 | .name = t, | 157 | .name = t, |
| 152 | .root_source_file = b.path("glibc_runtime_check.zig"), | 158 | .root_module = b.createModule(.{ |
| 153 | .target = target, | 159 | .root_source_file = b.path("glibc_runtime_check.zig"), |
| 160 | .target = target, | ||
| 161 | .link_libc = true, | ||
| 162 | }), | ||
| 154 | }); | 163 | }); |
| 155 | exe.linkLibC(); | ||
| 156 | 164 | ||
| 157 | // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig | 165 | // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig |
| 158 | // test runner would be able to check this, but see https://github.com/ziglang/zig/pull/17702#issuecomment-1831310453 | 166 | // test runner would be able to check this, but see https://github.com/ziglang/zig/pull/17702#issuecomment-1831310453 |
test/link/interdependent_static_c_libs/build.zig+22-13| ... | @@ -13,27 +13,36 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,27 +13,36 @@ 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 lib_a = b.addStaticLibrary(.{ | 14 | const lib_a = b.addStaticLibrary(.{ |
| 15 | .name = "a", | 15 | .name = "a", |
| 16 | .optimize = optimize, | 16 | .root_module = b.createModule(.{ |
| 17 | .target = b.graph.host, | 17 | .root_source_file = null, |
| 18 | .optimize = optimize, | ||
| 19 | .target = b.graph.host, | ||
| 20 | }), | ||
| 18 | }); | 21 | }); |
| 19 | lib_a.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} }); | 22 | lib_a.root_module.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} }); |
| 20 | lib_a.addIncludePath(b.path(".")); | 23 | lib_a.root_module.addIncludePath(b.path(".")); |
| 21 | 24 | ||
| 22 | const lib_b = b.addStaticLibrary(.{ | 25 | const lib_b = b.addStaticLibrary(.{ |
| 23 | .name = "b", | 26 | .name = "b", |
| 24 | .optimize = optimize, | 27 | .root_module = b.createModule(.{ |
| 25 | .target = b.graph.host, | 28 | .root_source_file = null, |
| 29 | .optimize = optimize, | ||
| 30 | .target = b.graph.host, | ||
| 31 | }), | ||
| 26 | }); | 32 | }); |
| 27 | lib_b.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} }); | 33 | lib_b.root_module.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} }); |
| 28 | lib_b.addIncludePath(b.path(".")); | 34 | lib_b.root_module.addIncludePath(b.path(".")); |
| 29 | 35 | ||
| 30 | const test_exe = b.addTest(.{ | 36 | const test_exe = b.addTest(.{ |
| 31 | .root_source_file = b.path("main.zig"), | 37 | .root_module = b.createModule(.{ |
| 32 | .optimize = optimize, | 38 | .root_source_file = b.path("main.zig"), |
| 39 | .target = b.graph.host, | ||
| 40 | .optimize = optimize, | ||
| 41 | }), | ||
| 33 | }); | 42 | }); |
| 34 | test_exe.linkLibrary(lib_a); | 43 | test_exe.root_module.linkLibrary(lib_a); |
| 35 | test_exe.linkLibrary(lib_b); | 44 | test_exe.root_module.linkLibrary(lib_b); |
| 36 | test_exe.addIncludePath(b.path(".")); | 45 | test_exe.root_module.addIncludePath(b.path(".")); |
| 37 | 46 | ||
| 38 | test_step.dependOn(&b.addRunArtifact(test_exe).step); | 47 | test_step.dependOn(&b.addRunArtifact(test_exe).step); |
| 39 | } | 48 | } |
test/link/link.zig+47-43| ... | @@ -47,81 +47,85 @@ const OverlayOptions = struct { | ... | @@ -47,81 +47,85 @@ const OverlayOptions = struct { |
| 47 | }; | 47 | }; |
| 48 | 48 | ||
| 49 | pub fn addExecutable(b: *std.Build, base: Options, overlay: OverlayOptions) *Compile { | 49 | pub fn addExecutable(b: *std.Build, base: Options, overlay: OverlayOptions) *Compile { |
| 50 | return addCompileStep(b, base, overlay, .exe); | 50 | return b.addExecutable(.{ |
| 51 | .name = overlay.name, | ||
| 52 | .root_module = createModule(b, base, overlay), | ||
| 53 | .use_llvm = base.use_llvm, | ||
| 54 | .use_lld = base.use_lld, | ||
| 55 | }); | ||
| 51 | } | 56 | } |
| 52 | 57 | ||
| 53 | pub fn addObject(b: *Build, base: Options, overlay: OverlayOptions) *Compile { | 58 | pub fn addObject(b: *Build, base: Options, overlay: OverlayOptions) *Compile { |
| 54 | return addCompileStep(b, base, overlay, .obj); | 59 | return b.addObject(.{ |
| 60 | .name = overlay.name, | ||
| 61 | .root_module = createModule(b, base, overlay), | ||
| 62 | .use_llvm = base.use_llvm, | ||
| 63 | .use_lld = base.use_lld, | ||
| 64 | }); | ||
| 55 | } | 65 | } |
| 56 | 66 | ||
| 57 | pub fn addStaticLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile { | 67 | pub fn addStaticLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile { |
| 58 | return addCompileStep(b, base, overlay, .static_lib); | 68 | return b.addStaticLibrary(.{ |
| 69 | .name = overlay.name, | ||
| 70 | .root_module = createModule(b, base, overlay), | ||
| 71 | .use_llvm = base.use_llvm, | ||
| 72 | .use_lld = base.use_lld, | ||
| 73 | }); | ||
| 59 | } | 74 | } |
| 60 | 75 | ||
| 61 | pub fn addSharedLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile { | 76 | pub fn addSharedLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile { |
| 62 | return addCompileStep(b, base, overlay, .shared_lib); | 77 | return b.addSharedLibrary(.{ |
| 63 | } | ||
| 64 | |||
| 65 | fn addCompileStep( | ||
| 66 | b: *Build, | ||
| 67 | base: Options, | ||
| 68 | overlay: OverlayOptions, | ||
| 69 | kind: enum { exe, obj, shared_lib, static_lib }, | ||
| 70 | ) *Compile { | ||
| 71 | const compile_step = Compile.create(b, .{ | ||
| 72 | .name = overlay.name, | 78 | .name = overlay.name, |
| 73 | .root_module = .{ | 79 | .root_module = createModule(b, base, overlay), |
| 74 | .target = base.target, | ||
| 75 | .optimize = base.optimize, | ||
| 76 | .root_source_file = rsf: { | ||
| 77 | const bytes = overlay.zig_source_bytes orelse break :rsf null; | ||
| 78 | const name = b.fmt("{s}.zig", .{overlay.name}); | ||
| 79 | break :rsf b.addWriteFiles().add(name, bytes); | ||
| 80 | }, | ||
| 81 | .pic = overlay.pic, | ||
| 82 | .strip = if (base.strip) |s| s else overlay.strip, | ||
| 83 | }, | ||
| 84 | .use_llvm = base.use_llvm, | 80 | .use_llvm = base.use_llvm, |
| 85 | .use_lld = base.use_lld, | 81 | .use_lld = base.use_lld, |
| 86 | .kind = switch (kind) { | 82 | }); |
| 87 | .exe => .exe, | 83 | } |
| 88 | .obj => .obj, | 84 | |
| 89 | .shared_lib, .static_lib => .lib, | 85 | fn createModule(b: *Build, base: Options, overlay: OverlayOptions) *Build.Module { |
| 90 | }, | 86 | const write_files = b.addWriteFiles(); |
| 91 | .linkage = switch (kind) { | 87 | |
| 92 | .exe, .obj => null, | 88 | const mod = b.createModule(.{ |
| 93 | .shared_lib => .dynamic, | 89 | .target = base.target, |
| 94 | .static_lib => .static, | 90 | .optimize = base.optimize, |
| 91 | .root_source_file = rsf: { | ||
| 92 | const bytes = overlay.zig_source_bytes orelse break :rsf null; | ||
| 93 | const name = b.fmt("{s}.zig", .{overlay.name}); | ||
| 94 | break :rsf write_files.add(name, bytes); | ||
| 95 | }, | 95 | }, |
| 96 | .pic = overlay.pic, | ||
| 97 | .strip = if (base.strip) |s| s else overlay.strip, | ||
| 96 | }); | 98 | }); |
| 99 | |||
| 97 | if (overlay.objcpp_source_bytes) |bytes| { | 100 | if (overlay.objcpp_source_bytes) |bytes| { |
| 98 | compile_step.addCSourceFile(.{ | 101 | mod.addCSourceFile(.{ |
| 99 | .file = b.addWriteFiles().add("a.mm", bytes), | 102 | .file = write_files.add("a.mm", bytes), |
| 100 | .flags = overlay.objcpp_source_flags, | 103 | .flags = overlay.objcpp_source_flags, |
| 101 | }); | 104 | }); |
| 102 | } | 105 | } |
| 103 | if (overlay.objc_source_bytes) |bytes| { | 106 | if (overlay.objc_source_bytes) |bytes| { |
| 104 | compile_step.addCSourceFile(.{ | 107 | mod.addCSourceFile(.{ |
| 105 | .file = b.addWriteFiles().add("a.m", bytes), | 108 | .file = write_files.add("a.m", bytes), |
| 106 | .flags = overlay.objc_source_flags, | 109 | .flags = overlay.objc_source_flags, |
| 107 | }); | 110 | }); |
| 108 | } | 111 | } |
| 109 | if (overlay.cpp_source_bytes) |bytes| { | 112 | if (overlay.cpp_source_bytes) |bytes| { |
| 110 | compile_step.addCSourceFile(.{ | 113 | mod.addCSourceFile(.{ |
| 111 | .file = b.addWriteFiles().add("a.cpp", bytes), | 114 | .file = write_files.add("a.cpp", bytes), |
| 112 | .flags = overlay.cpp_source_flags, | 115 | .flags = overlay.cpp_source_flags, |
| 113 | }); | 116 | }); |
| 114 | } | 117 | } |
| 115 | if (overlay.c_source_bytes) |bytes| { | 118 | if (overlay.c_source_bytes) |bytes| { |
| 116 | compile_step.addCSourceFile(.{ | 119 | mod.addCSourceFile(.{ |
| 117 | .file = b.addWriteFiles().add("a.c", bytes), | 120 | .file = write_files.add("a.c", bytes), |
| 118 | .flags = overlay.c_source_flags, | 121 | .flags = overlay.c_source_flags, |
| 119 | }); | 122 | }); |
| 120 | } | 123 | } |
| 121 | if (overlay.asm_source_bytes) |bytes| { | 124 | if (overlay.asm_source_bytes) |bytes| { |
| 122 | compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes)); | 125 | mod.addAssemblyFile(write_files.add("a.s", bytes)); |
| 123 | } | 126 | } |
| 124 | return compile_step; | 127 | |
| 128 | return mod; | ||
| 125 | } | 129 | } |
| 126 | 130 | ||
| 127 | pub fn addRunArtifact(comp: *Compile) *Run { | 131 | pub fn addRunArtifact(comp: *Compile) *Run { |
test/link/static_libs_from_object_files/build.zig+47-38| ... | @@ -57,13 +57,15 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built | ... | @@ -57,13 +57,15 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 57 | { | 57 | { |
| 58 | const exe = b.addExecutable(.{ | 58 | const exe = b.addExecutable(.{ |
| 59 | .name = "test1", | 59 | .name = "test1", |
| 60 | .root_source_file = b.path("main.zig"), | 60 | .root_module = b.createModule(.{ |
| 61 | .optimize = optimize, | 61 | .root_source_file = b.path("main.zig"), |
| 62 | .target = b.graph.host, | 62 | .optimize = optimize, |
| 63 | .target = b.graph.host, | ||
| 64 | }), | ||
| 63 | }); | 65 | }); |
| 64 | 66 | ||
| 65 | for (files) |file| { | 67 | for (files) |file| { |
| 66 | exe.addCSourceFile(.{ .file = file, .flags = &flags }); | 68 | exe.root_module.addCSourceFile(.{ .file = file, .flags = &flags }); |
| 67 | } | 69 | } |
| 68 | 70 | ||
| 69 | const run_cmd = b.addRunArtifact(exe); | 71 | const run_cmd = b.addRunArtifact(exe); |
| ... | @@ -75,30 +77,33 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built | ... | @@ -75,30 +77,33 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 75 | 77 | ||
| 76 | // using static librairies | 78 | // using static librairies |
| 77 | { | 79 | { |
| 80 | const mod_a = b.createModule(.{ .target = b.graph.host, .optimize = optimize }); | ||
| 81 | const mod_b = b.createModule(.{ .target = b.graph.host, .optimize = optimize }); | ||
| 82 | |||
| 83 | for (files, 1..) |file, i| { | ||
| 84 | const mod = if (i & 1 == 0) mod_a else mod_b; | ||
| 85 | mod.addCSourceFile(.{ .file = file, .flags = &flags }); | ||
| 86 | } | ||
| 87 | |||
| 78 | const lib_a = b.addStaticLibrary(.{ | 88 | const lib_a = b.addStaticLibrary(.{ |
| 79 | .name = "test2_a", | 89 | .name = "test2_a", |
| 80 | .target = b.graph.host, | 90 | .root_module = mod_a, |
| 81 | .optimize = optimize, | ||
| 82 | }); | 91 | }); |
| 83 | const lib_b = b.addStaticLibrary(.{ | 92 | const lib_b = b.addStaticLibrary(.{ |
| 84 | .name = "test2_b", | 93 | .name = "test2_b", |
| 85 | .target = b.graph.host, | 94 | .root_module = mod_b, |
| 86 | .optimize = optimize, | ||
| 87 | }); | 95 | }); |
| 88 | 96 | ||
| 89 | for (files, 1..) |file, i| { | ||
| 90 | const lib = if (i & 1 == 0) lib_a else lib_b; | ||
| 91 | lib.addCSourceFile(.{ .file = file, .flags = &flags }); | ||
| 92 | } | ||
| 93 | |||
| 94 | const exe = b.addExecutable(.{ | 97 | const exe = b.addExecutable(.{ |
| 95 | .name = "test2", | 98 | .name = "test2", |
| 96 | .root_source_file = b.path("main.zig"), | 99 | .root_module = b.createModule(.{ |
| 97 | .target = b.graph.host, | 100 | .root_source_file = b.path("main.zig"), |
| 98 | .optimize = optimize, | 101 | .target = b.graph.host, |
| 102 | .optimize = optimize, | ||
| 103 | }), | ||
| 99 | }); | 104 | }); |
| 100 | exe.linkLibrary(lib_a); | 105 | exe.root_module.linkLibrary(lib_a); |
| 101 | exe.linkLibrary(lib_b); | 106 | exe.root_module.linkLibrary(lib_b); |
| 102 | 107 | ||
| 103 | const run_cmd = b.addRunArtifact(exe); | 108 | const run_cmd = b.addRunArtifact(exe); |
| 104 | run_cmd.skip_foreign_checks = true; | 109 | run_cmd.skip_foreign_checks = true; |
| ... | @@ -109,37 +114,41 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built | ... | @@ -109,37 +114,41 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built |
| 109 | 114 | ||
| 110 | // using static librairies and object files | 115 | // using static librairies and object files |
| 111 | { | 116 | { |
| 112 | const lib_a = b.addStaticLibrary(.{ | 117 | const mod_a = b.createModule(.{ .target = b.graph.host, .optimize = optimize }); |
| 113 | .name = "test3_a", | 118 | const mod_b = b.createModule(.{ .target = b.graph.host, .optimize = optimize }); |
| 114 | .target = b.graph.host, | ||
| 115 | .optimize = optimize, | ||
| 116 | }); | ||
| 117 | const lib_b = b.addStaticLibrary(.{ | ||
| 118 | .name = "test3_b", | ||
| 119 | .target = b.graph.host, | ||
| 120 | .optimize = optimize, | ||
| 121 | }); | ||
| 122 | 119 | ||
| 123 | for (files, 1..) |file, i| { | 120 | for (files, 1..) |file, i| { |
| 121 | const obj_mod = b.createModule(.{ .target = b.graph.host, .optimize = optimize }); | ||
| 122 | obj_mod.addCSourceFile(.{ .file = file, .flags = &flags }); | ||
| 123 | |||
| 124 | const obj = b.addObject(.{ | 124 | const obj = b.addObject(.{ |
| 125 | .name = b.fmt("obj_{}", .{i}), | 125 | .name = b.fmt("obj_{}", .{i}), |
| 126 | .target = b.graph.host, | 126 | .root_module = obj_mod, |
| 127 | .optimize = optimize, | ||
| 128 | }); | 127 | }); |
| 129 | obj.addCSourceFile(.{ .file = file, .flags = &flags }); | ||
| 130 | 128 | ||
| 131 | const lib = if (i & 1 == 0) lib_a else lib_b; | 129 | const lib_mod = if (i & 1 == 0) mod_a else mod_b; |
| 132 | lib.addObject(obj); | 130 | lib_mod.addObject(obj); |
| 133 | } | 131 | } |
| 134 | 132 | ||
| 133 | const lib_a = b.addStaticLibrary(.{ | ||
| 134 | .name = "test3_a", | ||
| 135 | .root_module = mod_a, | ||
| 136 | }); | ||
| 137 | const lib_b = b.addStaticLibrary(.{ | ||
| 138 | .name = "test3_b", | ||
| 139 | .root_module = mod_b, | ||
| 140 | }); | ||
| 141 | |||
| 135 | const exe = b.addExecutable(.{ | 142 | const exe = b.addExecutable(.{ |
| 136 | .name = "test3", | 143 | .name = "test3", |
| 137 | .root_source_file = b.path("main.zig"), | 144 | .root_module = b.createModule(.{ |
| 138 | .target = b.graph.host, | 145 | .root_source_file = b.path("main.zig"), |
| 139 | .optimize = optimize, | 146 | .target = b.graph.host, |
| 147 | .optimize = optimize, | ||
| 148 | }), | ||
| 140 | }); | 149 | }); |
| 141 | exe.linkLibrary(lib_a); | 150 | exe.root_module.linkLibrary(lib_a); |
| 142 | exe.linkLibrary(lib_b); | 151 | exe.root_module.linkLibrary(lib_b); |
| 143 | 152 | ||
| 144 | const run_cmd = b.addRunArtifact(exe); | 153 | const run_cmd = b.addRunArtifact(exe); |
| 145 | run_cmd.skip_foreign_checks = true; | 154 | run_cmd.skip_foreign_checks = true; |
test/link/wasm/archive/build.zig+6-4| ... | @@ -17,10 +17,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -17,10 +17,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 17 | // and therefore link with its archive file. | 17 | // and therefore link with its archive file. |
| 18 | const lib = b.addExecutable(.{ | 18 | const lib = b.addExecutable(.{ |
| 19 | .name = "main", | 19 | .name = "main", |
| 20 | .root_source_file = b.path("main.zig"), | 20 | .root_module = b.createModule(.{ |
| 21 | .optimize = optimize, | 21 | .root_source_file = b.path("main.zig"), |
| 22 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | 22 | .optimize = optimize, |
| 23 | .strip = false, | 23 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 24 | .strip = false, | ||
| 25 | }), | ||
| 24 | }); | 26 | }); |
| 25 | lib.entry = .disabled; | 27 | lib.entry = .disabled; |
| 26 | lib.use_llvm = false; | 28 | lib.use_llvm = false; |
test/link/wasm/basic-features/build.zig+9-7| ... | @@ -6,13 +6,15 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,13 +6,15 @@ pub fn build(b: *std.Build) void { |
| 6 | // Library with explicitly set cpu features | 6 | // Library with explicitly set cpu features |
| 7 | const lib = b.addExecutable(.{ | 7 | const lib = b.addExecutable(.{ |
| 8 | .name = "lib", | 8 | .name = "lib", |
| 9 | .root_source_file = b.path("main.zig"), | 9 | .root_module = b.createModule(.{ |
| 10 | .optimize = .Debug, | 10 | .root_source_file = b.path("main.zig"), |
| 11 | .target = b.resolveTargetQuery(.{ | 11 | .optimize = .Debug, |
| 12 | .cpu_arch = .wasm32, | 12 | .target = b.resolveTargetQuery(.{ |
| 13 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | 13 | .cpu_arch = .wasm32, |
| 14 | .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}), | 14 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, |
| 15 | .os_tag = .freestanding, | 15 | .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}), |
| 16 | .os_tag = .freestanding, | ||
| 17 | }), | ||
| 16 | }), | 18 | }), |
| 17 | }); | 19 | }); |
| 18 | lib.entry = .disabled; | 20 | lib.entry = .disabled; |
test/link/wasm/bss/build.zig+12-8| ... | @@ -16,10 +16,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt | ... | @@ -16,10 +16,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt |
| 16 | { | 16 | { |
| 17 | const lib = b.addExecutable(.{ | 17 | const lib = b.addExecutable(.{ |
| 18 | .name = "lib", | 18 | .name = "lib", |
| 19 | .root_source_file = b.path("lib.zig"), | 19 | .root_module = b.createModule(.{ |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | 20 | .root_source_file = b.path("lib.zig"), |
| 21 | .optimize = optimize_mode, | 21 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 22 | .strip = false, | 22 | .optimize = optimize_mode, |
| 23 | .strip = false, | ||
| 24 | }), | ||
| 23 | }); | 25 | }); |
| 24 | lib.entry = .disabled; | 26 | lib.entry = .disabled; |
| 25 | lib.use_llvm = false; | 27 | lib.use_llvm = false; |
| ... | @@ -64,10 +66,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt | ... | @@ -64,10 +66,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt |
| 64 | { | 66 | { |
| 65 | const lib = b.addExecutable(.{ | 67 | const lib = b.addExecutable(.{ |
| 66 | .name = "lib", | 68 | .name = "lib", |
| 67 | .root_source_file = b.path("lib2.zig"), | 69 | .root_module = b.createModule(.{ |
| 68 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | 70 | .root_source_file = b.path("lib2.zig"), |
| 69 | .optimize = optimize_mode, | 71 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 70 | .strip = false, | 72 | .optimize = optimize_mode, |
| 73 | .strip = false, | ||
| 74 | }), | ||
| 71 | }); | 75 | }); |
| 72 | lib.entry = .disabled; | 76 | lib.entry = .disabled; |
| 73 | lib.use_llvm = false; | 77 | lib.use_llvm = false; |
test/link/wasm/export-data/build.zig+5-3| ... | @@ -11,9 +11,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -11,9 +11,11 @@ pub fn build(b: *std.Build) void { |
| 11 | 11 | ||
| 12 | const lib = b.addExecutable(.{ | 12 | const lib = b.addExecutable(.{ |
| 13 | .name = "lib", | 13 | .name = "lib", |
| 14 | .root_source_file = b.path("lib.zig"), | 14 | .root_module = b.createModule(.{ |
| 15 | .optimize = .ReleaseSafe, // to make the output deterministic in address positions | 15 | .root_source_file = b.path("lib.zig"), |
| 16 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | 16 | .optimize = .ReleaseSafe, // to make the output deterministic in address positions |
| 17 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | ||
| 18 | }), | ||
| 17 | }); | 19 | }); |
| 18 | lib.entry = .disabled; | 20 | lib.entry = .disabled; |
| 19 | lib.use_lld = false; | 21 | lib.use_lld = false; |
test/link/wasm/export/build.zig+15-9| ... | @@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void { |
| 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 no_export = b.addExecutable(.{ | 16 | const no_export = b.addExecutable(.{ |
| 17 | .name = "no-export", | 17 | .name = "no-export", |
| 18 | .root_source_file = b.path("main.zig"), | 18 | .root_module = b.createModule(.{ |
| 19 | .optimize = optimize, | 19 | .root_source_file = b.path("main.zig"), |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | 20 | .optimize = optimize, |
| 21 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | ||
| 22 | }), | ||
| 21 | }); | 23 | }); |
| 22 | no_export.entry = .disabled; | 24 | no_export.entry = .disabled; |
| 23 | no_export.use_llvm = false; | 25 | no_export.use_llvm = false; |
| ... | @@ -25,9 +27,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -25,9 +27,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 25 | 27 | ||
| 26 | const dynamic_export = b.addExecutable(.{ | 28 | const dynamic_export = b.addExecutable(.{ |
| 27 | .name = "dynamic", | 29 | .name = "dynamic", |
| 28 | .root_source_file = b.path("main.zig"), | 30 | .root_module = b.createModule(.{ |
| 29 | .optimize = optimize, | 31 | .root_source_file = b.path("main.zig"), |
| 30 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | 32 | .optimize = optimize, |
| 33 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | ||
| 34 | }), | ||
| 31 | }); | 35 | }); |
| 32 | dynamic_export.entry = .disabled; | 36 | dynamic_export.entry = .disabled; |
| 33 | dynamic_export.rdynamic = true; | 37 | dynamic_export.rdynamic = true; |
| ... | @@ -36,9 +40,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -36,9 +40,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 36 | 40 | ||
| 37 | const force_export = b.addExecutable(.{ | 41 | const force_export = b.addExecutable(.{ |
| 38 | .name = "force", | 42 | .name = "force", |
| 39 | .root_source_file = b.path("main.zig"), | 43 | .root_module = b.createModule(.{ |
| 40 | .optimize = optimize, | 44 | .root_source_file = b.path("main.zig"), |
| 41 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | 45 | .optimize = optimize, |
| 46 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | ||
| 47 | }), | ||
| 42 | }); | 48 | }); |
| 43 | force_export.entry = .disabled; | 49 | force_export.entry = .disabled; |
| 44 | force_export.root_module.export_symbol_names = &.{"foo"}; | 50 | force_export.root_module.export_symbol_names = &.{"foo"}; |
test/link/wasm/extern-mangle/build.zig+5-3| ... | @@ -13,9 +13,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,9 +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 lib = b.addExecutable(.{ | 14 | const lib = b.addExecutable(.{ |
| 15 | .name = "lib", | 15 | .name = "lib", |
| 16 | .root_source_file = b.path("lib.zig"), | 16 | .root_module = b.createModule(.{ |
| 17 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | 17 | .root_source_file = b.path("lib.zig"), |
| 18 | .optimize = optimize, | 18 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 19 | .optimize = optimize, | ||
| 20 | }), | ||
| 19 | }); | 21 | }); |
| 20 | lib.entry = .disabled; | 22 | lib.entry = .disabled; |
| 21 | lib.import_symbols = true; // import `a` and `b` | 23 | lib.import_symbols = true; // import `a` and `b` |
test/link/wasm/extern/build.zig+5-3| ... | @@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void { |
| 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 exe = b.addExecutable(.{ | 16 | const exe = b.addExecutable(.{ |
| 17 | .name = "extern", | 17 | .name = "extern", |
| 18 | .root_source_file = b.path("main.zig"), | 18 | .root_module = b.createModule(.{ |
| 19 | .optimize = optimize, | 19 | .root_source_file = b.path("main.zig"), |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }), | 20 | .optimize = optimize, |
| 21 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }), | ||
| 22 | }), | ||
| 21 | }); | 23 | }); |
| 22 | exe.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} }); | 24 | exe.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} }); |
| 23 | exe.use_llvm = false; | 25 | exe.use_llvm = false; |
test/link/wasm/function-table/build.zig+15-9| ... | @@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void { |
| 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 import_table = b.addExecutable(.{ | 16 | const import_table = b.addExecutable(.{ |
| 17 | .name = "import_table", | 17 | .name = "import_table", |
| 18 | .root_source_file = b.path("lib.zig"), | 18 | .root_module = b.createModule(.{ |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | 19 | .root_source_file = b.path("lib.zig"), |
| 20 | .optimize = optimize, | 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 21 | .optimize = optimize, | ||
| 22 | }), | ||
| 21 | }); | 23 | }); |
| 22 | import_table.entry = .disabled; | 24 | import_table.entry = .disabled; |
| 23 | import_table.use_llvm = false; | 25 | import_table.use_llvm = false; |
| ... | @@ -27,9 +29,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -27,9 +29,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 27 | 29 | ||
| 28 | const export_table = b.addExecutable(.{ | 30 | const export_table = b.addExecutable(.{ |
| 29 | .name = "export_table", | 31 | .name = "export_table", |
| 30 | .root_source_file = b.path("lib.zig"), | 32 | .root_module = b.createModule(.{ |
| 31 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | 33 | .root_source_file = b.path("lib.zig"), |
| 32 | .optimize = optimize, | 34 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 35 | .optimize = optimize, | ||
| 36 | }), | ||
| 33 | }); | 37 | }); |
| 34 | export_table.entry = .disabled; | 38 | export_table.entry = .disabled; |
| 35 | export_table.use_llvm = false; | 39 | export_table.use_llvm = false; |
| ... | @@ -39,9 +43,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -39,9 +43,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 39 | 43 | ||
| 40 | const regular_table = b.addExecutable(.{ | 44 | const regular_table = b.addExecutable(.{ |
| 41 | .name = "regular_table", | 45 | .name = "regular_table", |
| 42 | .root_source_file = b.path("lib.zig"), | 46 | .root_module = b.createModule(.{ |
| 43 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | 47 | .root_source_file = b.path("lib.zig"), |
| 44 | .optimize = optimize, | 48 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 49 | .optimize = optimize, | ||
| 50 | }), | ||
| 45 | }); | 51 | }); |
| 46 | regular_table.entry = .disabled; | 52 | regular_table.entry = .disabled; |
| 47 | regular_table.use_llvm = false; | 53 | regular_table.use_llvm = false; |
test/link/wasm/infer-features/build.zig+18-13| ... | @@ -6,31 +6,36 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,31 +6,36 @@ pub fn build(b: *std.Build) void { |
| 6 | // Wasm Object file which we will use to infer the features from | 6 | // Wasm Object file which we will use to infer the features from |
| 7 | const c_obj = b.addObject(.{ | 7 | const c_obj = b.addObject(.{ |
| 8 | .name = "c_obj", | 8 | .name = "c_obj", |
| 9 | .optimize = .Debug, | 9 | .root_module = b.createModule(.{ |
| 10 | .target = b.resolveTargetQuery(.{ | 10 | .root_source_file = null, |
| 11 | .cpu_arch = .wasm32, | 11 | .optimize = .Debug, |
| 12 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge }, | 12 | .target = b.resolveTargetQuery(.{ |
| 13 | .os_tag = .freestanding, | 13 | .cpu_arch = .wasm32, |
| 14 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge }, | ||
| 15 | .os_tag = .freestanding, | ||
| 16 | }), | ||
| 14 | }), | 17 | }), |
| 15 | }); | 18 | }); |
| 16 | c_obj.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} }); | 19 | c_obj.root_module.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} }); |
| 17 | 20 | ||
| 18 | // Wasm library that doesn't have any features specified. This will | 21 | // Wasm library that doesn't have any features specified. This will |
| 19 | // infer its featureset from other linked object files. | 22 | // infer its featureset from other linked object files. |
| 20 | const lib = b.addExecutable(.{ | 23 | const lib = b.addExecutable(.{ |
| 21 | .name = "lib", | 24 | .name = "lib", |
| 22 | .root_source_file = b.path("main.zig"), | 25 | .root_module = b.createModule(.{ |
| 23 | .optimize = .Debug, | 26 | .root_source_file = b.path("main.zig"), |
| 24 | .target = b.resolveTargetQuery(.{ | 27 | .optimize = .Debug, |
| 25 | .cpu_arch = .wasm32, | 28 | .target = b.resolveTargetQuery(.{ |
| 26 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | 29 | .cpu_arch = .wasm32, |
| 27 | .os_tag = .freestanding, | 30 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, |
| 31 | .os_tag = .freestanding, | ||
| 32 | }), | ||
| 28 | }), | 33 | }), |
| 29 | }); | 34 | }); |
| 30 | lib.entry = .disabled; | 35 | lib.entry = .disabled; |
| 31 | lib.use_llvm = false; | 36 | lib.use_llvm = false; |
| 32 | lib.use_lld = false; | 37 | lib.use_lld = false; |
| 33 | lib.addObject(c_obj); | 38 | lib.root_module.addObject(c_obj); |
| 34 | 39 | ||
| 35 | // Verify the result contains the features from the C Object file. | 40 | // Verify the result contains the features from the C Object file. |
| 36 | const check = lib.checkObject(); | 41 | const check = lib.checkObject(); |
test/link/wasm/producers/build.zig+6-4| ... | @@ -16,10 +16,12 @@ pub fn build(b: *std.Build) void { | ... | @@ -16,10 +16,12 @@ pub fn build(b: *std.Build) void { |
| 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 lib = b.addExecutable(.{ | 17 | const lib = b.addExecutable(.{ |
| 18 | .name = "lib", | 18 | .name = "lib", |
| 19 | .root_source_file = b.path("lib.zig"), | 19 | .root_module = b.createModule(.{ |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | 20 | .root_source_file = b.path("lib.zig"), |
| 21 | .optimize = optimize, | 21 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 22 | .strip = false, | 22 | .optimize = optimize, |
| 23 | .strip = false, | ||
| 24 | }), | ||
| 23 | }); | 25 | }); |
| 24 | lib.entry = .disabled; | 26 | lib.entry = .disabled; |
| 25 | lib.use_llvm = false; | 27 | lib.use_llvm = false; |
test/link/wasm/segments/build.zig+6-4| ... | @@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void { | ... | @@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void { |
| 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 lib = b.addExecutable(.{ | 16 | const lib = b.addExecutable(.{ |
| 17 | .name = "lib", | 17 | .name = "lib", |
| 18 | .root_source_file = b.path("lib.zig"), | 18 | .root_module = b.createModule(.{ |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | 19 | .root_source_file = b.path("lib.zig"), |
| 20 | .optimize = optimize, | 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 21 | .strip = false, | 21 | .optimize = optimize, |
| 22 | .strip = false, | ||
| 23 | }), | ||
| 22 | }); | 24 | }); |
| 23 | lib.entry = .disabled; | 25 | lib.entry = .disabled; |
| 24 | lib.use_llvm = false; | 26 | lib.use_llvm = false; |
test/link/wasm/shared-memory/build.zig+11-9| ... | @@ -13,16 +13,18 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,16 +13,18 @@ pub fn build(b: *std.Build) void { |
| 13 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode) void { | 13 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode) void { |
| 14 | const exe = b.addExecutable(.{ | 14 | const exe = b.addExecutable(.{ |
| 15 | .name = "lib", | 15 | .name = "lib", |
| 16 | .root_source_file = b.path("lib.zig"), | 16 | .root_module = b.createModule(.{ |
| 17 | .target = b.resolveTargetQuery(.{ | 17 | .root_source_file = b.path("lib.zig"), |
| 18 | .cpu_arch = .wasm32, | 18 | .target = b.resolveTargetQuery(.{ |
| 19 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | 19 | .cpu_arch = .wasm32, |
| 20 | .cpu_features_add = std.Target.wasm.featureSet(&.{ .atomics, .bulk_memory }), | 20 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, |
| 21 | .os_tag = .freestanding, | 21 | .cpu_features_add = std.Target.wasm.featureSet(&.{ .atomics, .bulk_memory }), |
| 22 | .os_tag = .freestanding, | ||
| 23 | }), | ||
| 24 | .optimize = optimize_mode, | ||
| 25 | .strip = false, | ||
| 26 | .single_threaded = false, | ||
| 22 | }), | 27 | }), |
| 23 | .optimize = optimize_mode, | ||
| 24 | .strip = false, | ||
| 25 | .single_threaded = false, | ||
| 26 | }); | 28 | }); |
| 27 | exe.entry = .disabled; | 29 | exe.entry = .disabled; |
| 28 | exe.use_lld = false; | 30 | exe.use_lld = false; |
test/link/wasm/stack_pointer/build.zig+6-4| ... | @@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void { | ... | @@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void { |
| 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 lib = b.addExecutable(.{ | 16 | const lib = b.addExecutable(.{ |
| 17 | .name = "lib", | 17 | .name = "lib", |
| 18 | .root_source_file = b.path("lib.zig"), | 18 | .root_module = b.createModule(.{ |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | 19 | .root_source_file = b.path("lib.zig"), |
| 20 | .optimize = optimize, | 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 21 | .strip = false, | 21 | .optimize = optimize, |
| 22 | .strip = false, | ||
| 23 | }), | ||
| 22 | }); | 24 | }); |
| 23 | lib.entry = .disabled; | 25 | lib.entry = .disabled; |
| 24 | lib.use_llvm = false; | 26 | lib.use_llvm = false; |
test/link/wasm/type/build.zig+6-4| ... | @@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void { | ... | @@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void { |
| 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 exe = b.addExecutable(.{ | 16 | const exe = b.addExecutable(.{ |
| 17 | .name = "lib", | 17 | .name = "lib", |
| 18 | .root_source_file = b.path("lib.zig"), | 18 | .root_module = b.createModule(.{ |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | 19 | .root_source_file = b.path("lib.zig"), |
| 20 | .optimize = optimize, | 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 21 | .strip = false, | 21 | .optimize = optimize, |
| 22 | .strip = false, | ||
| 23 | }), | ||
| 22 | }); | 24 | }); |
| 23 | exe.entry = .disabled; | 25 | exe.entry = .disabled; |
| 24 | exe.use_llvm = false; | 26 | exe.use_llvm = false; |
test/src/Cases.zig+20-20| ... | @@ -572,7 +572,10 @@ pub fn lowerToTranslateCSteps( | ... | @@ -572,7 +572,10 @@ pub fn lowerToTranslateCSteps( |
| 572 | }); | 572 | }); |
| 573 | translate_c.step.name = b.fmt("{s} translate-c", .{annotated_case_name}); | 573 | translate_c.step.name = b.fmt("{s} translate-c", .{annotated_case_name}); |
| 574 | 574 | ||
| 575 | const run_exe = translate_c.addExecutable(.{}); | 575 | const run_exe = b.addExecutable(.{ |
| 576 | .name = "translated_c", | ||
| 577 | .root_module = translate_c.createModule(), | ||
| 578 | }); | ||
| 576 | run_exe.step.name = b.fmt("{s} build-exe", .{annotated_case_name}); | 579 | run_exe.step.name = b.fmt("{s} build-exe", .{annotated_case_name}); |
| 577 | run_exe.linkLibC(); | 580 | run_exe.linkLibC(); |
| 578 | const run = b.addRunArtifact(run_exe); | 581 | const run = b.addRunArtifact(run_exe); |
| ... | @@ -660,34 +663,37 @@ pub fn lowerToBuildSteps( | ... | @@ -660,34 +663,37 @@ pub fn lowerToBuildSteps( |
| 660 | file_sources.put(file.path, writefiles.add(file.path, file.src)) catch @panic("OOM"); | 663 | file_sources.put(file.path, writefiles.add(file.path, file.src)) catch @panic("OOM"); |
| 661 | } | 664 | } |
| 662 | 665 | ||
| 663 | const artifact = if (case.is_test) b.addTest(.{ | 666 | const mod = b.createModule(.{ |
| 664 | .root_source_file = root_source_file, | 667 | .root_source_file = root_source_file, |
| 665 | .name = case.name, | ||
| 666 | .target = case.target, | 668 | .target = case.target, |
| 667 | .optimize = case.optimize_mode, | 669 | .optimize = case.optimize_mode, |
| 670 | }); | ||
| 671 | if (case.link_libc) mod.link_libc = true; | ||
| 672 | if (case.pic) |pic| mod.pic = pic; | ||
| 673 | for (case.deps.items) |dep| { | ||
| 674 | mod.addAnonymousImport(dep.name, .{ | ||
| 675 | .root_source_file = file_sources.get(dep.path).?, | ||
| 676 | }); | ||
| 677 | } | ||
| 678 | |||
| 679 | const artifact = if (case.is_test) b.addTest(.{ | ||
| 680 | .name = case.name, | ||
| 681 | .root_module = mod, | ||
| 668 | }) else switch (case.output_mode) { | 682 | }) else switch (case.output_mode) { |
| 669 | .Obj => b.addObject(.{ | 683 | .Obj => b.addObject(.{ |
| 670 | .root_source_file = root_source_file, | ||
| 671 | .name = case.name, | 684 | .name = case.name, |
| 672 | .target = case.target, | 685 | .root_module = mod, |
| 673 | .optimize = case.optimize_mode, | ||
| 674 | }), | 686 | }), |
| 675 | .Lib => b.addStaticLibrary(.{ | 687 | .Lib => b.addStaticLibrary(.{ |
| 676 | .root_source_file = root_source_file, | ||
| 677 | .name = case.name, | 688 | .name = case.name, |
| 678 | .target = case.target, | 689 | .root_module = mod, |
| 679 | .optimize = case.optimize_mode, | ||
| 680 | }), | 690 | }), |
| 681 | .Exe => b.addExecutable(.{ | 691 | .Exe => b.addExecutable(.{ |
| 682 | .root_source_file = root_source_file, | ||
| 683 | .name = case.name, | 692 | .name = case.name, |
| 684 | .target = case.target, | 693 | .root_module = mod, |
| 685 | .optimize = case.optimize_mode, | ||
| 686 | }), | 694 | }), |
| 687 | }; | 695 | }; |
| 688 | 696 | ||
| 689 | if (case.link_libc) artifact.linkLibC(); | ||
| 690 | if (case.pic) |pic| artifact.root_module.pic = pic; | ||
| 691 | if (case.pie) |pie| artifact.pie = pie; | 697 | if (case.pie) |pie| artifact.pie = pie; |
| 692 | 698 | ||
| 693 | switch (case.backend) { | 699 | switch (case.backend) { |
| ... | @@ -701,12 +707,6 @@ pub fn lowerToBuildSteps( | ... | @@ -701,12 +707,6 @@ pub fn lowerToBuildSteps( |
| 701 | }, | 707 | }, |
| 702 | } | 708 | } |
| 703 | 709 | ||
| 704 | for (case.deps.items) |dep| { | ||
| 705 | artifact.root_module.addAnonymousImport(dep.name, .{ | ||
| 706 | .root_source_file = file_sources.get(dep.path).?, | ||
| 707 | }); | ||
| 708 | } | ||
| 709 | |||
| 710 | switch (update.case) { | 710 | switch (update.case) { |
| 711 | .Compile => { | 711 | .Compile => { |
| 712 | // Force the binary to be emitted if requested. | 712 | // Force the binary to be emitted if requested. |
test/src/CompareOutput.zig+23-21| ... | @@ -89,19 +89,22 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { | ... | @@ -89,19 +89,22 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 89 | 89 | ||
| 90 | switch (case.special) { | 90 | switch (case.special) { |
| 91 | Special.Asm => { | 91 | Special.Asm => { |
| 92 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "run assemble-and-link {s}", .{ | 92 | const annotated_case_name = b.fmt("run assemble-and-link {s}", .{ |
| 93 | case.name, | 93 | case.name, |
| 94 | }) catch @panic("OOM"); | 94 | }); |
| 95 | for (self.test_filters) |test_filter| { | 95 | for (self.test_filters) |test_filter| { |
| 96 | if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break; | 96 | if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break; |
| 97 | } else if (self.test_filters.len > 0) return; | 97 | } else if (self.test_filters.len > 0) return; |
| 98 | 98 | ||
| 99 | const exe = b.addExecutable(.{ | 99 | const exe = b.addExecutable(.{ |
| 100 | .name = "test", | 100 | .name = "test", |
| 101 | .target = b.graph.host, | 101 | .root_module = b.createModule(.{ |
| 102 | .optimize = .Debug, | 102 | .root_source_file = null, |
| 103 | .target = b.graph.host, | ||
| 104 | .optimize = .Debug, | ||
| 105 | }), | ||
| 103 | }); | 106 | }); |
| 104 | exe.addAssemblyFile(first_file); | 107 | exe.root_module.addAssemblyFile(first_file); |
| 105 | 108 | ||
| 106 | const run = b.addRunArtifact(exe); | 109 | const run = b.addRunArtifact(exe); |
| 107 | run.setName(annotated_case_name); | 110 | run.setName(annotated_case_name); |
| ... | @@ -112,22 +115,22 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { | ... | @@ -112,22 +115,22 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 112 | }, | 115 | }, |
| 113 | Special.None => { | 116 | Special.None => { |
| 114 | for (self.optimize_modes) |optimize| { | 117 | for (self.optimize_modes) |optimize| { |
| 115 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "run compare-output {s} ({s})", .{ | 118 | const annotated_case_name = b.fmt("run compare-output {s} ({s})", .{ |
| 116 | case.name, @tagName(optimize), | 119 | case.name, @tagName(optimize), |
| 117 | }) catch @panic("OOM"); | 120 | }); |
| 118 | for (self.test_filters) |test_filter| { | 121 | for (self.test_filters) |test_filter| { |
| 119 | if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break; | 122 | if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break; |
| 120 | } else if (self.test_filters.len > 0) return; | 123 | } else if (self.test_filters.len > 0) return; |
| 121 | 124 | ||
| 122 | const exe = b.addExecutable(.{ | 125 | const exe = b.addExecutable(.{ |
| 123 | .name = "test", | 126 | .name = "test", |
| 124 | .root_source_file = first_file, | 127 | .root_module = b.createModule(.{ |
| 125 | .optimize = optimize, | 128 | .root_source_file = first_file, |
| 126 | .target = b.graph.host, | 129 | .optimize = optimize, |
| 130 | .target = b.graph.host, | ||
| 131 | }), | ||
| 127 | }); | 132 | }); |
| 128 | if (case.link_libc) { | 133 | if (case.link_libc) exe.root_module.link_libc = true; |
| 129 | exe.linkSystemLibrary("c"); | ||
| 130 | } | ||
| 131 | 134 | ||
| 132 | const run = b.addRunArtifact(exe); | 135 | const run = b.addRunArtifact(exe); |
| 133 | run.setName(annotated_case_name); | 136 | run.setName(annotated_case_name); |
| ... | @@ -140,20 +143,20 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { | ... | @@ -140,20 +143,20 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 140 | Special.RuntimeSafety => { | 143 | Special.RuntimeSafety => { |
| 141 | // TODO iterate over self.optimize_modes and test this in both | 144 | // TODO iterate over self.optimize_modes and test this in both |
| 142 | // debug and release safe mode | 145 | // debug and release safe mode |
| 143 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "run safety {s}", .{case.name}) catch @panic("OOM"); | 146 | const annotated_case_name = b.fmt("run safety {s}", .{case.name}); |
| 144 | for (self.test_filters) |test_filter| { | 147 | for (self.test_filters) |test_filter| { |
| 145 | if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break; | 148 | if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break; |
| 146 | } else if (self.test_filters.len > 0) return; | 149 | } else if (self.test_filters.len > 0) return; |
| 147 | 150 | ||
| 148 | const exe = b.addExecutable(.{ | 151 | const exe = b.addExecutable(.{ |
| 149 | .name = "test", | 152 | .name = "test", |
| 150 | .root_source_file = first_file, | 153 | .root_module = b.createModule(.{ |
| 151 | .target = b.graph.host, | 154 | .root_source_file = first_file, |
| 152 | .optimize = .Debug, | 155 | .target = b.graph.host, |
| 156 | .optimize = .Debug, | ||
| 157 | }), | ||
| 153 | }); | 158 | }); |
| 154 | if (case.link_libc) { | 159 | if (case.link_libc) exe.root_module.link_libc = true; |
| 155 | exe.linkSystemLibrary("c"); | ||
| 156 | } | ||
| 157 | 160 | ||
| 158 | const run = b.addRunArtifact(exe); | 161 | const run = b.addRunArtifact(exe); |
| 159 | run.setName(annotated_case_name); | 162 | run.setName(annotated_case_name); |
| ... | @@ -168,7 +171,6 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { | ... | @@ -168,7 +171,6 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 168 | const CompareOutput = @This(); | 171 | const CompareOutput = @This(); |
| 169 | const std = @import("std"); | 172 | const std = @import("std"); |
| 170 | const ArrayList = std.ArrayList; | 173 | const ArrayList = std.ArrayList; |
| 171 | const fmt = std.fmt; | ||
| 172 | const mem = std.mem; | 174 | const mem = std.mem; |
| 173 | const fs = std.fs; | 175 | const fs = std.fs; |
| 174 | const OptimizeMode = std.builtin.OptimizeMode; | 176 | const OptimizeMode = std.builtin.OptimizeMode; |
test/src/Debugger.zig+11-5| ... | @@ -2414,8 +2414,8 @@ fn addTest( | ... | @@ -2414,8 +2414,8 @@ fn addTest( |
| 2414 | } else return; | 2414 | } else return; |
| 2415 | } | 2415 | } |
| 2416 | const files_wf = db.b.addWriteFiles(); | 2416 | const files_wf = db.b.addWriteFiles(); |
| 2417 | const exe = db.b.addExecutable(.{ | 2417 | |
| 2418 | .name = name, | 2418 | const mod = db.b.createModule(.{ |
| 2419 | .target = target.resolved, | 2419 | .target = target.resolved, |
| 2420 | .root_source_file = files_wf.add(files[0].path, files[0].source), | 2420 | .root_source_file = files_wf.add(files[0].path, files[0].source), |
| 2421 | .optimize = target.optimize_mode, | 2421 | .optimize = target.optimize_mode, |
| ... | @@ -2423,15 +2423,21 @@ fn addTest( | ... | @@ -2423,15 +2423,21 @@ fn addTest( |
| 2423 | .single_threaded = target.single_threaded, | 2423 | .single_threaded = target.single_threaded, |
| 2424 | .pic = target.pic, | 2424 | .pic = target.pic, |
| 2425 | .strip = false, | 2425 | .strip = false, |
| 2426 | .use_llvm = false, | ||
| 2427 | .use_lld = false, | ||
| 2428 | }); | 2426 | }); |
| 2429 | for (files[1..]) |file| { | 2427 | for (files[1..]) |file| { |
| 2430 | const path = files_wf.add(file.path, file.source); | 2428 | const path = files_wf.add(file.path, file.source); |
| 2431 | if (file.import) |import| exe.root_module.addImport(import, db.b.createModule(.{ | 2429 | if (file.import) |import| mod.addImport(import, db.b.createModule(.{ |
| 2432 | .root_source_file = path, | 2430 | .root_source_file = path, |
| 2433 | })); | 2431 | })); |
| 2434 | } | 2432 | } |
| 2433 | |||
| 2434 | const exe = db.b.addExecutable(.{ | ||
| 2435 | .name = name, | ||
| 2436 | .root_module = mod, | ||
| 2437 | .use_llvm = false, | ||
| 2438 | .use_lld = false, | ||
| 2439 | }); | ||
| 2440 | |||
| 2435 | const commands_wf = db.b.addWriteFiles(); | 2441 | const commands_wf = db.b.addWriteFiles(); |
| 2436 | const run = std.Build.Step.Run.create(db.b, db.b.fmt("run {s} {s}", .{ name, target.test_name_suffix })); | 2442 | const run = std.Build.Step.Run.create(db.b, db.b.fmt("run {s} {s}", .{ name, target.test_name_suffix })); |
| 2437 | run.addArgs(db_argv1); | 2443 | run.addArgs(db_argv1); |
test/src/RunTranslatedC.zig+4-1| ... | @@ -84,7 +84,10 @@ pub fn addCase(self: *RunTranslatedCContext, case: *const TestCase) void { | ... | @@ -84,7 +84,10 @@ pub fn addCase(self: *RunTranslatedCContext, case: *const TestCase) void { |
| 84 | }); | 84 | }); |
| 85 | 85 | ||
| 86 | translate_c.step.name = b.fmt("{s} translate-c", .{annotated_case_name}); | 86 | translate_c.step.name = b.fmt("{s} translate-c", .{annotated_case_name}); |
| 87 | const exe = translate_c.addExecutable(.{}); | 87 | const exe = b.addExecutable(.{ |
| 88 | .name = "translated_c", | ||
| 89 | .root_module = translate_c.createModule(), | ||
| 90 | }); | ||
| 88 | exe.step.name = b.fmt("{s} build-exe", .{annotated_case_name}); | 91 | exe.step.name = b.fmt("{s} build-exe", .{annotated_case_name}); |
| 89 | exe.linkLibC(); | 92 | exe.linkLibC(); |
| 90 | const run = b.addRunArtifact(exe); | 93 | const run = b.addRunArtifact(exe); |
test/src/StackTrace.zig+8-7| ... | @@ -44,9 +44,9 @@ fn addExpect( | ... | @@ -44,9 +44,9 @@ fn addExpect( |
| 44 | for (mode_config.exclude_os) |tag| if (tag == builtin.os.tag) return; | 44 | for (mode_config.exclude_os) |tag| if (tag == builtin.os.tag) return; |
| 45 | 45 | ||
| 46 | const b = self.b; | 46 | const b = self.b; |
| 47 | const annotated_case_name = fmt.allocPrint(b.allocator, "check {s} ({s})", .{ | 47 | const annotated_case_name = b.fmt("check {s} ({s})", .{ |
| 48 | name, @tagName(optimize_mode), | 48 | name, @tagName(optimize_mode), |
| 49 | }) catch @panic("OOM"); | 49 | }); |
| 50 | for (self.test_filters) |test_filter| { | 50 | for (self.test_filters) |test_filter| { |
| 51 | if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break; | 51 | if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break; |
| 52 | } else if (self.test_filters.len > 0) return; | 52 | } else if (self.test_filters.len > 0) return; |
| ... | @@ -55,10 +55,12 @@ fn addExpect( | ... | @@ -55,10 +55,12 @@ fn addExpect( |
| 55 | const source_zig = write_files.add("source.zig", source); | 55 | const source_zig = write_files.add("source.zig", source); |
| 56 | const exe = b.addExecutable(.{ | 56 | const exe = b.addExecutable(.{ |
| 57 | .name = "test", | 57 | .name = "test", |
| 58 | .root_source_file = source_zig, | 58 | .root_module = b.createModule(.{ |
| 59 | .optimize = optimize_mode, | 59 | .root_source_file = source_zig, |
| 60 | .target = b.graph.host, | 60 | .optimize = optimize_mode, |
| 61 | .error_tracing = mode_config.error_tracing, | 61 | .target = b.graph.host, |
| 62 | .error_tracing = mode_config.error_tracing, | ||
| 63 | }), | ||
| 62 | }); | 64 | }); |
| 63 | 65 | ||
| 64 | const run = b.addRunArtifact(exe); | 66 | const run = b.addRunArtifact(exe); |
| ... | @@ -83,5 +85,4 @@ const std = @import("std"); | ... | @@ -83,5 +85,4 @@ const std = @import("std"); |
| 83 | const builtin = @import("builtin"); | 85 | const builtin = @import("builtin"); |
| 84 | const Step = std.Build.Step; | 86 | const Step = std.Build.Step; |
| 85 | const OptimizeMode = std.builtin.OptimizeMode; | 87 | const OptimizeMode = std.builtin.OptimizeMode; |
| 86 | const fmt = std.fmt; | ||
| 87 | const mem = std.mem; | 88 | const mem = std.mem; |
test/standalone/build.zig+5-3| ... | @@ -47,9 +47,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -47,9 +47,11 @@ pub fn build(b: *std.Build) void { |
| 47 | }) |tool_src_path| { | 47 | }) |tool_src_path| { |
| 48 | const tool = b.addTest(.{ | 48 | const tool = b.addTest(.{ |
| 49 | .name = std.fs.path.stem(tool_src_path), | 49 | .name = std.fs.path.stem(tool_src_path), |
| 50 | .root_source_file = b.path(tool_src_path), | 50 | .root_module = b.createModule(.{ |
| 51 | .optimize = .Debug, | 51 | .root_source_file = b.path(tool_src_path), |
| 52 | .target = tools_target, | 52 | .optimize = .Debug, |
| 53 | .target = tools_target, | ||
| 54 | }), | ||
| 53 | }); | 55 | }); |
| 54 | const run = b.addRunArtifact(tool); | 56 | const run = b.addRunArtifact(tool); |
| 55 | tools_tests_step.dependOn(&run.step); | 57 | tools_tests_step.dependOn(&run.step); |
test/standalone/c_compiler/build.zig+11-8| ... | @@ -20,22 +20,25 @@ fn add( | ... | @@ -20,22 +20,25 @@ fn add( |
| 20 | ) void { | 20 | ) void { |
| 21 | const target = b.graph.host; | 21 | const target = b.graph.host; |
| 22 | 22 | ||
| 23 | const exe_c = b.addExecutable(.{ | 23 | const c_mod = b.createModule(.{ |
| 24 | .name = c_name, | ||
| 25 | .optimize = optimize, | 24 | .optimize = optimize, |
| 26 | .target = target, | 25 | .target = target, |
| 27 | }); | 26 | }); |
| 28 | exe_c.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[0][]const u8{} }); | 27 | c_mod.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[0][]const u8{} }); |
| 29 | exe_c.linkLibC(); | 28 | c_mod.link_libc = true; |
| 30 | 29 | ||
| 31 | const exe_cpp = b.addExecutable(.{ | 30 | const exe_c = b.addExecutable(.{ .name = c_name, .root_module = c_mod }); |
| 32 | .name = cpp_name, | 31 | |
| 32 | const cpp_mod = b.createModule(.{ | ||
| 33 | .optimize = optimize, | 33 | .optimize = optimize, |
| 34 | .target = target, | 34 | .target = target, |
| 35 | }); | 35 | }); |
| 36 | cpp_mod.addCSourceFile(.{ .file = b.path("test.cpp"), .flags = &[0][]const u8{} }); | ||
| 37 | cpp_mod.link_libcpp = true; | ||
| 38 | |||
| 39 | const exe_cpp = b.addExecutable(.{ .name = cpp_name, .root_module = cpp_mod }); | ||
| 40 | |||
| 36 | b.default_step.dependOn(&exe_cpp.step); | 41 | b.default_step.dependOn(&exe_cpp.step); |
| 37 | exe_cpp.addCSourceFile(.{ .file = b.path("test.cpp"), .flags = &[0][]const u8{} }); | ||
| 38 | exe_cpp.linkLibCpp(); | ||
| 39 | 42 | ||
| 40 | switch (target.result.os.tag) { | 43 | switch (target.result.os.tag) { |
| 41 | .windows => { | 44 | .windows => { |
test/standalone/child_process/build.zig+10-6| ... | @@ -12,16 +12,20 @@ pub fn build(b: *std.Build) void { | ... | @@ -12,16 +12,20 @@ pub fn build(b: *std.Build) void { |
| 12 | 12 | ||
| 13 | const child = b.addExecutable(.{ | 13 | const child = b.addExecutable(.{ |
| 14 | .name = "child", | 14 | .name = "child", |
| 15 | .root_source_file = b.path("child.zig"), | 15 | .root_module = b.createModule(.{ |
| 16 | .optimize = optimize, | 16 | .root_source_file = b.path("child.zig"), |
| 17 | .target = target, | 17 | .optimize = optimize, |
| 18 | .target = target, | ||
| 19 | }), | ||
| 18 | }); | 20 | }); |
| 19 | 21 | ||
| 20 | const main = b.addExecutable(.{ | 22 | const main = b.addExecutable(.{ |
| 21 | .name = "main", | 23 | .name = "main", |
| 22 | .root_source_file = b.path("main.zig"), | 24 | .root_module = b.createModule(.{ |
| 23 | .optimize = optimize, | 25 | .root_source_file = b.path("main.zig"), |
| 24 | .target = target, | 26 | .optimize = optimize, |
| 27 | .target = target, | ||
| 28 | }), | ||
| 25 | }); | 29 | }); |
| 26 | const run = b.addRunArtifact(main); | 30 | const run = b.addRunArtifact(main); |
| 27 | run.addArtifactArg(child); | 31 | run.addArtifactArg(child); |
test/standalone/coff_dwarf/build.zig+13-8| ... | @@ -14,19 +14,24 @@ pub fn build(b: *std.Build) void { | ... | @@ -14,19 +14,24 @@ pub fn build(b: *std.Build) void { |
| 14 | 14 | ||
| 15 | const exe = b.addExecutable(.{ | 15 | const exe = b.addExecutable(.{ |
| 16 | .name = "main", | 16 | .name = "main", |
| 17 | .root_source_file = b.path("main.zig"), | 17 | .root_module = b.createModule(.{ |
| 18 | .optimize = optimize, | 18 | .root_source_file = b.path("main.zig"), |
| 19 | .target = target, | 19 | .optimize = optimize, |
| 20 | .target = target, | ||
| 21 | }), | ||
| 20 | }); | 22 | }); |
| 21 | 23 | ||
| 22 | const lib = b.addSharedLibrary(.{ | 24 | const lib = b.addSharedLibrary(.{ |
| 23 | .name = "shared_lib", | 25 | .name = "shared_lib", |
| 24 | .optimize = optimize, | 26 | .root_module = b.createModule(.{ |
| 25 | .target = target, | 27 | .root_source_file = null, |
| 28 | .optimize = optimize, | ||
| 29 | .target = target, | ||
| 30 | .link_libc = true, | ||
| 31 | }), | ||
| 26 | }); | 32 | }); |
| 27 | lib.addCSourceFile(.{ .file = b.path("shared_lib.c"), .flags = &.{"-gdwarf"} }); | 33 | lib.root_module.addCSourceFile(.{ .file = b.path("shared_lib.c"), .flags = &.{"-gdwarf"} }); |
| 28 | lib.linkLibC(); | 34 | exe.root_module.linkLibrary(lib); |
| 29 | exe.linkLibrary(lib); | ||
| 30 | 35 | ||
| 31 | const run = b.addRunArtifact(exe); | 36 | const run = b.addRunArtifact(exe); |
| 32 | run.expectExitCode(0); | 37 | run.expectExitCode(0); |
test/standalone/compiler_rt_panic/build.zig+7-4| ... | @@ -12,11 +12,14 @@ pub fn build(b: *std.Build) void { | ... | @@ -12,11 +12,14 @@ pub fn build(b: *std.Build) void { |
| 12 | 12 | ||
| 13 | const exe = b.addExecutable(.{ | 13 | const exe = b.addExecutable(.{ |
| 14 | .name = "main", | 14 | .name = "main", |
| 15 | .optimize = optimize, | 15 | .root_module = b.createModule(.{ |
| 16 | .target = target, | 16 | .root_source_file = null, |
| 17 | .optimize = optimize, | ||
| 18 | .target = target, | ||
| 19 | .link_libc = true, | ||
| 20 | }), | ||
| 17 | }); | 21 | }); |
| 18 | exe.linkLibC(); | 22 | exe.root_module.addCSourceFile(.{ |
| 19 | exe.addCSourceFile(.{ | ||
| 20 | .file = b.path("main.c"), | 23 | .file = b.path("main.c"), |
| 21 | .flags = &.{}, | 24 | .flags = &.{}, |
| 22 | }); | 25 | }); |
test/standalone/dep_diamond/build.zig+13-13| ... | @@ -6,23 +6,23 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,23 +6,23 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | ||
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | ||
| 9 | const shared = b.createModule(.{ | 9 | const main_mod = b.createModule(.{ |
| 10 | .root_source_file = b.path("shared.zig"), | ||
| 11 | }); | ||
| 12 | |||
| 13 | const exe = b.addExecutable(.{ | ||
| 14 | .name = "test", | ||
| 15 | .root_source_file = b.path("test.zig"), | 10 | .root_source_file = b.path("test.zig"), |
| 16 | .target = b.graph.host, | 11 | .target = b.graph.host, |
| 17 | .optimize = optimize, | 12 | .optimize = optimize, |
| 18 | }); | 13 | }); |
| 19 | exe.root_module.addAnonymousImport("foo", .{ | 14 | const shared_mod = b.createModule(.{ .root_source_file = b.path("shared.zig") }); |
| 20 | .root_source_file = b.path("foo.zig"), | 15 | const foo_mod = b.createModule(.{ .root_source_file = b.path("foo.zig") }); |
| 21 | .imports = &.{.{ .name = "shared", .module = shared }}, | 16 | const bar_mod = b.createModule(.{ .root_source_file = b.path("bar.zig") }); |
| 22 | }); | 17 | |
| 23 | exe.root_module.addAnonymousImport("bar", .{ | 18 | main_mod.addImport("foo", foo_mod); |
| 24 | .root_source_file = b.path("bar.zig"), | 19 | main_mod.addImport("bar", bar_mod); |
| 25 | .imports = &.{.{ .name = "shared", .module = shared }}, | 20 | foo_mod.addImport("shared", shared_mod); |
| 21 | bar_mod.addImport("shared", shared_mod); | ||
| 22 | |||
| 23 | const exe = b.addExecutable(.{ | ||
| 24 | .name = "test", | ||
| 25 | .root_module = main_mod, | ||
| 26 | }); | 26 | }); |
| 27 | 27 | ||
| 28 | const run = b.addRunArtifact(exe); | 28 | const run = b.addRunArtifact(exe); |
test/standalone/dep_duplicate_module/build.zig+17-10| ... | @@ -4,29 +4,36 @@ pub fn build(b: *std.Build) void { | ... | @@ -4,29 +4,36 @@ pub fn build(b: *std.Build) void { |
| 4 | const target = b.standardTargetOptions(.{}); | 4 | const target = b.standardTargetOptions(.{}); |
| 5 | const optimize = b.standardOptimizeOption(.{}); | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | 6 | ||
| 7 | const mod = b.addModule("mod", .{ | 7 | const shared_mod = b.createModule(.{ |
| 8 | .root_source_file = b.path("mod.zig"), | 8 | .root_source_file = b.path("mod.zig"), |
| 9 | .target = target, | 9 | .target = target, |
| 10 | .optimize = optimize, | 10 | .optimize = optimize, |
| 11 | }); | 11 | }); |
| 12 | 12 | const lib_mod = b.createModule(.{ | |
| 13 | const lib = b.addStaticLibrary(.{ | ||
| 14 | .name = "lib", | ||
| 15 | .root_source_file = b.path("lib.zig"), | 13 | .root_source_file = b.path("lib.zig"), |
| 16 | .target = target, | 14 | .target = target, |
| 17 | .optimize = optimize, | 15 | .optimize = optimize, |
| 18 | }); | 16 | }); |
| 19 | lib.root_module.addImport("mod", mod); | 17 | const exe_mod = b.createModule(.{ |
| 20 | |||
| 21 | const exe = b.addExecutable(.{ | ||
| 22 | .name = "app", | ||
| 23 | .root_source_file = b.path("main.zig"), | 18 | .root_source_file = b.path("main.zig"), |
| 24 | .target = target, | 19 | .target = target, |
| 25 | .optimize = optimize, | 20 | .optimize = optimize, |
| 26 | }); | 21 | }); |
| 27 | 22 | ||
| 28 | exe.root_module.addImport("mod", mod); | 23 | lib_mod.addImport("mod", shared_mod); |
| 29 | exe.root_module.linkLibrary(lib); | 24 | exe_mod.addImport("mod", shared_mod); |
| 25 | |||
| 26 | const lib = b.addStaticLibrary(.{ | ||
| 27 | .name = "lib", | ||
| 28 | .root_module = lib_mod, | ||
| 29 | }); | ||
| 30 | |||
| 31 | exe_mod.linkLibrary(lib); | ||
| 32 | |||
| 33 | const exe = b.addExecutable(.{ | ||
| 34 | .name = "app", | ||
| 35 | .root_module = exe_mod, | ||
| 36 | }); | ||
| 30 | 37 | ||
| 31 | b.installArtifact(exe); | 38 | b.installArtifact(exe); |
| 32 | } | 39 | } |
test/standalone/dep_lazypath/build.zig+12-7| ... | @@ -11,10 +11,13 @@ pub fn build(b: *std.Build) void { | ... | @@ -11,10 +11,13 @@ pub fn build(b: *std.Build) void { |
| 11 | const generated_main_c = write_files.add("main.c", ""); | 11 | const generated_main_c = write_files.add("main.c", ""); |
| 12 | const exe = b.addExecutable(.{ | 12 | const exe = b.addExecutable(.{ |
| 13 | .name = "test", | 13 | .name = "test", |
| 14 | .target = b.graph.host, | 14 | .root_module = b.createModule(.{ |
| 15 | .optimize = optimize, | 15 | .root_source_file = null, |
| 16 | .target = b.graph.host, | ||
| 17 | .optimize = optimize, | ||
| 18 | }), | ||
| 16 | }); | 19 | }); |
| 17 | exe.addCSourceFiles(.{ | 20 | exe.root_module.addCSourceFiles(.{ |
| 18 | .root = generated_main_c.dirname(), | 21 | .root = generated_main_c.dirname(), |
| 19 | .files = &.{"main.c"}, | 22 | .files = &.{"main.c"}, |
| 20 | }); | 23 | }); |
| ... | @@ -26,11 +29,13 @@ pub fn build(b: *std.Build) void { | ... | @@ -26,11 +29,13 @@ pub fn build(b: *std.Build) void { |
| 26 | const dir = write_files.addCopyDirectory(b.path("inc"), "", .{}); | 29 | const dir = write_files.addCopyDirectory(b.path("inc"), "", .{}); |
| 27 | const exe = b.addExecutable(.{ | 30 | const exe = b.addExecutable(.{ |
| 28 | .name = "test", | 31 | .name = "test", |
| 29 | .root_source_file = b.path("inctest.zig"), | 32 | .root_module = b.createModule(.{ |
| 30 | .target = b.graph.host, | 33 | .root_source_file = b.path("inctest.zig"), |
| 31 | .optimize = optimize, | 34 | .target = b.graph.host, |
| 35 | .optimize = optimize, | ||
| 36 | }), | ||
| 32 | }); | 37 | }); |
| 33 | exe.addIncludePath(dir); | 38 | exe.root_module.addIncludePath(dir); |
| 34 | b.step("copydir", "").dependOn(&exe.step); | 39 | b.step("copydir", "").dependOn(&exe.step); |
| 35 | test_step.dependOn(&exe.step); | 40 | test_step.dependOn(&exe.step); |
| 36 | } | 41 | } |
test/standalone/dep_mutually_recursive/build.zig+12-8| ... | @@ -6,22 +6,26 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,22 +6,26 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | ||
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | ||
| 9 | const foo = b.createModule(.{ | 9 | const main_mod = b.createModule(.{ |
| 10 | .root_source_file = b.path("test.zig"), | ||
| 11 | .target = b.graph.host, | ||
| 12 | .optimize = optimize, | ||
| 13 | }); | ||
| 14 | const foo_mod = b.createModule(.{ | ||
| 10 | .root_source_file = b.path("foo.zig"), | 15 | .root_source_file = b.path("foo.zig"), |
| 11 | }); | 16 | }); |
| 12 | const bar = b.createModule(.{ | 17 | const bar_mod = b.createModule(.{ |
| 13 | .root_source_file = b.path("bar.zig"), | 18 | .root_source_file = b.path("bar.zig"), |
| 14 | }); | 19 | }); |
| 15 | foo.addImport("bar", bar); | 20 | |
| 16 | bar.addImport("foo", foo); | 21 | main_mod.addImport("foo", foo_mod); |
| 22 | foo_mod.addImport("bar", bar_mod); | ||
| 23 | bar_mod.addImport("foo", foo_mod); | ||
| 17 | 24 | ||
| 18 | const exe = b.addExecutable(.{ | 25 | const exe = b.addExecutable(.{ |
| 19 | .name = "test", | 26 | .name = "test", |
| 20 | .root_source_file = b.path("test.zig"), | 27 | .root_module = main_mod, |
| 21 | .target = b.graph.host, | ||
| 22 | .optimize = optimize, | ||
| 23 | }); | 28 | }); |
| 24 | exe.root_module.addImport("foo", foo); | ||
| 25 | 29 | ||
| 26 | const run = b.addRunArtifact(exe); | 30 | const run = b.addRunArtifact(exe); |
| 27 | test_step.dependOn(&run.step); | 31 | test_step.dependOn(&run.step); |
test/standalone/dep_recursive/build.zig+10-6| ... | @@ -6,18 +6,22 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,18 +6,22 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | ||
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | ||
| 9 | const foo = b.createModule(.{ | 9 | const main_mod = b.createModule(.{ |
| 10 | .root_source_file = b.path("test.zig"), | ||
| 11 | .target = b.graph.host, | ||
| 12 | .optimize = optimize, | ||
| 13 | }); | ||
| 14 | const foo_mod = b.createModule(.{ | ||
| 10 | .root_source_file = b.path("foo.zig"), | 15 | .root_source_file = b.path("foo.zig"), |
| 11 | }); | 16 | }); |
| 12 | foo.addImport("foo", foo); | 17 | |
| 18 | main_mod.addImport("foo", foo_mod); | ||
| 19 | foo_mod.addImport("foo", foo_mod); | ||
| 13 | 20 | ||
| 14 | const exe = b.addExecutable(.{ | 21 | const exe = b.addExecutable(.{ |
| 15 | .name = "test", | 22 | .name = "test", |
| 16 | .root_source_file = b.path("test.zig"), | 23 | .root_module = main_mod, |
| 17 | .target = b.graph.host, | ||
| 18 | .optimize = optimize, | ||
| 19 | }); | 24 | }); |
| 20 | exe.root_module.addImport("foo", foo); | ||
| 21 | 25 | ||
| 22 | const run = b.addRunArtifact(exe); | 26 | const run = b.addRunArtifact(exe); |
| 23 | test_step.dependOn(&run.step); | 27 | test_step.dependOn(&run.step); |
test/standalone/dep_shared_builtin/build.zig+9-3| ... | @@ -6,16 +6,22 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,16 +6,22 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | ||
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | ||
| 9 | const exe = b.addExecutable(.{ | 9 | const main_mod = b.createModule(.{ |
| 10 | .name = "test", | ||
| 11 | .root_source_file = b.path("test.zig"), | 10 | .root_source_file = b.path("test.zig"), |
| 12 | .target = b.graph.host, | 11 | .target = b.graph.host, |
| 13 | .optimize = optimize, | 12 | .optimize = optimize, |
| 14 | }); | 13 | }); |
| 15 | exe.root_module.addAnonymousImport("foo", .{ | 14 | const foo_mod = b.createModule(.{ |
| 16 | .root_source_file = b.path("foo.zig"), | 15 | .root_source_file = b.path("foo.zig"), |
| 17 | }); | 16 | }); |
| 18 | 17 | ||
| 18 | main_mod.addImport("foo", foo_mod); | ||
| 19 | |||
| 20 | const exe = b.addExecutable(.{ | ||
| 21 | .name = "test", | ||
| 22 | .root_module = main_mod, | ||
| 23 | }); | ||
| 24 | |||
| 19 | const run = b.addRunArtifact(exe); | 25 | const run = b.addRunArtifact(exe); |
| 20 | test_step.dependOn(&run.step); | 26 | test_step.dependOn(&run.step); |
| 21 | } | 27 | } |
test/standalone/dep_triangle/build.zig+14-9| ... | @@ -6,21 +6,26 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,21 +6,26 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | ||
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | ||
| 9 | const shared = b.createModule(.{ | 9 | const main_mod = b.createModule(.{ |
| 10 | .root_source_file = b.path("shared.zig"), | ||
| 11 | }); | ||
| 12 | |||
| 13 | const exe = b.addExecutable(.{ | ||
| 14 | .name = "test", | ||
| 15 | .root_source_file = b.path("test.zig"), | 10 | .root_source_file = b.path("test.zig"), |
| 16 | .target = b.graph.host, | 11 | .target = b.graph.host, |
| 17 | .optimize = optimize, | 12 | .optimize = optimize, |
| 18 | }); | 13 | }); |
| 19 | exe.root_module.addAnonymousImport("foo", .{ | 14 | const foo_mod = b.createModule(.{ |
| 20 | .root_source_file = b.path("foo.zig"), | 15 | .root_source_file = b.path("foo.zig"), |
| 21 | .imports = &.{.{ .name = "shared", .module = shared }}, | ||
| 22 | }); | 16 | }); |
| 23 | exe.root_module.addImport("shared", shared); | 17 | const shared_mod = b.createModule(.{ |
| 18 | .root_source_file = b.path("shared.zig"), | ||
| 19 | }); | ||
| 20 | |||
| 21 | main_mod.addImport("foo", foo_mod); | ||
| 22 | main_mod.addImport("shared", shared_mod); | ||
| 23 | foo_mod.addImport("shared", shared_mod); | ||
| 24 | |||
| 25 | const exe = b.addExecutable(.{ | ||
| 26 | .name = "test", | ||
| 27 | .root_module = main_mod, | ||
| 28 | }); | ||
| 24 | 29 | ||
| 25 | const run = b.addRunArtifact(exe); | 30 | const run = b.addRunArtifact(exe); |
| 26 | test_step.dependOn(&run.step); | 31 | test_step.dependOn(&run.step); |
test/standalone/depend_on_main_mod/build.zig+9-6| ... | @@ -7,19 +7,22 @@ pub fn build(b: *std.Build) void { | ... | @@ -7,19 +7,22 @@ pub fn build(b: *std.Build) void { |
| 7 | const target = b.standardTargetOptions(.{}); | 7 | const target = b.standardTargetOptions(.{}); |
| 8 | const optimize = b.standardOptimizeOption(.{}); | 8 | const optimize = b.standardOptimizeOption(.{}); |
| 9 | 9 | ||
| 10 | const exe = b.addExecutable(.{ | 10 | const main_mod = b.createModule(.{ |
| 11 | .name = "depend_on_main_mod", | ||
| 12 | .root_source_file = b.path("src/main.zig"), | 11 | .root_source_file = b.path("src/main.zig"), |
| 13 | .target = target, | 12 | .target = target, |
| 14 | .optimize = optimize, | 13 | .optimize = optimize, |
| 15 | }); | 14 | }); |
| 16 | 15 | const foo_mod = b.createModule(.{ | |
| 17 | const foo_module = b.addModule("foo", .{ | ||
| 18 | .root_source_file = b.path("src/foo.zig"), | 16 | .root_source_file = b.path("src/foo.zig"), |
| 19 | }); | 17 | }); |
| 20 | 18 | ||
| 21 | foo_module.addImport("root2", &exe.root_module); | 19 | foo_mod.addImport("root2", main_mod); |
| 22 | exe.root_module.addImport("foo", foo_module); | 20 | main_mod.addImport("foo", foo_mod); |
| 21 | |||
| 22 | const exe = b.addExecutable(.{ | ||
| 23 | .name = "depend_on_main_mod", | ||
| 24 | .root_module = main_mod, | ||
| 25 | }); | ||
| 23 | 26 | ||
| 24 | const run_cmd = b.addRunArtifact(exe); | 27 | const run_cmd = b.addRunArtifact(exe); |
| 25 | run_cmd.expectExitCode(0); | 28 | run_cmd.expectExitCode(0); |
test/standalone/dirname/build.zig+15-9| ... | @@ -10,24 +10,30 @@ pub fn build(b: *std.Build) void { | ... | @@ -10,24 +10,30 @@ pub fn build(b: *std.Build) void { |
| 10 | 10 | ||
| 11 | const touch = b.addExecutable(.{ | 11 | const touch = b.addExecutable(.{ |
| 12 | .name = "touch", | 12 | .name = "touch", |
| 13 | .root_source_file = touch_src, | 13 | .root_module = b.createModule(.{ |
| 14 | .optimize = .Debug, | 14 | .root_source_file = touch_src, |
| 15 | .target = target, | 15 | .optimize = .Debug, |
| 16 | .target = target, | ||
| 17 | }), | ||
| 16 | }); | 18 | }); |
| 17 | const generated = b.addRunArtifact(touch).addOutputFileArg("subdir" ++ std.fs.path.sep_str ++ "generated.txt"); | 19 | const generated = b.addRunArtifact(touch).addOutputFileArg("subdir" ++ std.fs.path.sep_str ++ "generated.txt"); |
| 18 | 20 | ||
| 19 | const exists_in = b.addExecutable(.{ | 21 | const exists_in = b.addExecutable(.{ |
| 20 | .name = "exists_in", | 22 | .name = "exists_in", |
| 21 | .root_source_file = b.path("exists_in.zig"), | 23 | .root_module = b.createModule(.{ |
| 22 | .optimize = .Debug, | 24 | .root_source_file = b.path("exists_in.zig"), |
| 23 | .target = target, | 25 | .optimize = .Debug, |
| 26 | .target = target, | ||
| 27 | }), | ||
| 24 | }); | 28 | }); |
| 25 | 29 | ||
| 26 | const has_basename = b.addExecutable(.{ | 30 | const has_basename = b.addExecutable(.{ |
| 27 | .name = "has_basename", | 31 | .name = "has_basename", |
| 28 | .root_source_file = b.path("has_basename.zig"), | 32 | .root_module = b.createModule(.{ |
| 29 | .optimize = .Debug, | 33 | .root_source_file = b.path("has_basename.zig"), |
| 30 | .target = target, | 34 | .optimize = .Debug, |
| 35 | .target = target, | ||
| 36 | }), | ||
| 31 | }); | 37 | }); |
| 32 | 38 | ||
| 33 | // Known path: | 39 | // Known path: |
test/standalone/embed_generated_file/build.zig+10-7| ... | @@ -6,18 +6,21 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,18 +6,21 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | ||
| 7 | const bootloader = b.addExecutable(.{ | 7 | const bootloader = b.addExecutable(.{ |
| 8 | .name = "bootloader", | 8 | .name = "bootloader", |
| 9 | .root_source_file = b.path("bootloader.zig"), | 9 | .root_module = b.createModule(.{ |
| 10 | .target = b.resolveTargetQuery(.{ | 10 | .root_source_file = b.path("bootloader.zig"), |
| 11 | .cpu_arch = .x86, | 11 | .target = b.resolveTargetQuery(.{ |
| 12 | .os_tag = .freestanding, | 12 | .cpu_arch = .x86, |
| 13 | .os_tag = .freestanding, | ||
| 14 | }), | ||
| 15 | .optimize = .ReleaseSmall, | ||
| 13 | }), | 16 | }), |
| 14 | .optimize = .ReleaseSmall, | ||
| 15 | }); | 17 | }); |
| 16 | 18 | ||
| 17 | const exe = b.addTest(.{ | 19 | const exe = b.addTest(.{ .root_module = b.createModule(.{ |
| 18 | .root_source_file = b.path("main.zig"), | 20 | .root_source_file = b.path("main.zig"), |
| 21 | .target = b.graph.host, | ||
| 19 | .optimize = .Debug, | 22 | .optimize = .Debug, |
| 20 | }); | 23 | }) }); |
| 21 | exe.root_module.addAnonymousImport("bootloader.elf", .{ | 24 | exe.root_module.addAnonymousImport("bootloader.elf", .{ |
| 22 | .root_source_file = bootloader.getEmittedBin(), | 25 | .root_source_file = bootloader.getEmittedBin(), |
| 23 | }); | 26 | }); |
test/standalone/emit_asm_and_bin/build.zig+3-2| ... | @@ -4,10 +4,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -4,10 +4,11 @@ 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 main = b.addTest(.{ | 7 | const main = b.addTest(.{ .root_module = b.createModule(.{ |
| 8 | .root_source_file = b.path("main.zig"), | 8 | .root_source_file = b.path("main.zig"), |
| 9 | .target = b.graph.host, | ||
| 9 | .optimize = b.standardOptimizeOption(.{}), | 10 | .optimize = b.standardOptimizeOption(.{}), |
| 10 | }); | 11 | }) }); |
| 11 | // TODO: actually check these two artifacts for correctness | 12 | // TODO: actually check these two artifacts for correctness |
| 12 | _ = main.getEmittedBin(); | 13 | _ = main.getEmittedBin(); |
| 13 | _ = main.getEmittedAsm(); | 14 | _ = main.getEmittedAsm(); |
test/standalone/emit_asm_no_bin/build.zig+5-3| ... | @@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void { |
| 8 | 8 | ||
| 9 | const obj = b.addObject(.{ | 9 | const obj = b.addObject(.{ |
| 10 | .name = "main", | 10 | .name = "main", |
| 11 | .root_source_file = b.path("main.zig"), | 11 | .root_module = b.createModule(.{ |
| 12 | .optimize = optimize, | 12 | .root_source_file = b.path("main.zig"), |
| 13 | .target = b.graph.host, | 13 | .optimize = optimize, |
| 14 | .target = b.graph.host, | ||
| 15 | }), | ||
| 14 | }); | 16 | }); |
| 15 | _ = obj.getEmittedAsm(); | 17 | _ = obj.getEmittedAsm(); |
| 16 | b.default_step.dependOn(&obj.step); | 18 | b.default_step.dependOn(&obj.step); |
test/standalone/emit_llvm_no_bin/build.zig+5-3| ... | @@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void { |
| 8 | 8 | ||
| 9 | const obj = b.addObject(.{ | 9 | const obj = b.addObject(.{ |
| 10 | .name = "main", | 10 | .name = "main", |
| 11 | .root_source_file = b.path("main.zig"), | 11 | .root_module = b.createModule(.{ |
| 12 | .optimize = optimize, | 12 | .root_source_file = b.path("main.zig"), |
| 13 | .target = b.graph.host, | 13 | .optimize = optimize, |
| 14 | .target = b.graph.host, | ||
| 15 | }), | ||
| 14 | }); | 16 | }); |
| 15 | _ = obj.getEmittedLlvmIr(); | 17 | _ = obj.getEmittedLlvmIr(); |
| 16 | _ = obj.getEmittedLlvmBc(); | 18 | _ = obj.getEmittedLlvmBc(); |
test/standalone/empty_env/build.zig+5-3| ... | @@ -21,9 +21,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -21,9 +21,11 @@ pub fn build(b: *std.Build) void { |
| 21 | 21 | ||
| 22 | const main = b.addExecutable(.{ | 22 | const main = b.addExecutable(.{ |
| 23 | .name = "main", | 23 | .name = "main", |
| 24 | .root_source_file = b.path("main.zig"), | 24 | .root_module = b.createModule(.{ |
| 25 | .target = b.graph.host, | 25 | .root_source_file = b.path("main.zig"), |
| 26 | .optimize = optimize, | 26 | .target = b.graph.host, |
| 27 | .optimize = optimize, | ||
| 28 | }), | ||
| 27 | }); | 29 | }); |
| 28 | 30 | ||
| 29 | const run = b.addRunArtifact(main); | 31 | const run = b.addRunArtifact(main); |
test/standalone/extern/build.zig+16-10| ... | @@ -8,22 +8,28 @@ pub fn build(b: *std.Build) void { | ... | @@ -8,22 +8,28 @@ pub fn build(b: *std.Build) void { |
| 8 | 8 | ||
| 9 | const obj = b.addObject(.{ | 9 | const obj = b.addObject(.{ |
| 10 | .name = "exports", | 10 | .name = "exports", |
| 11 | .root_source_file = b.path("exports.zig"), | 11 | .root_module = b.createModule(.{ |
| 12 | .target = b.graph.host, | 12 | .root_source_file = b.path("exports.zig"), |
| 13 | .optimize = optimize, | 13 | .target = b.graph.host, |
| 14 | .optimize = optimize, | ||
| 15 | }), | ||
| 14 | }); | 16 | }); |
| 15 | const shared = b.addSharedLibrary(.{ | 17 | const shared = b.addSharedLibrary(.{ |
| 16 | .name = "shared", | 18 | .name = "shared", |
| 17 | .target = b.graph.host, | 19 | .root_module = b.createModule(.{ |
| 18 | .optimize = optimize, | 20 | .root_source_file = null, |
| 19 | .link_libc = true, | 21 | .target = b.graph.host, |
| 22 | .optimize = optimize, | ||
| 23 | .link_libc = true, | ||
| 24 | }), | ||
| 20 | }); | 25 | }); |
| 21 | if (b.graph.host.result.abi == .msvc) shared.defineCMacro("API", "__declspec(dllexport)"); | 26 | if (b.graph.host.result.abi == .msvc) shared.root_module.addCMacro("API", "__declspec(dllexport)"); |
| 22 | shared.addCSourceFile(.{ .file = b.path("shared.c"), .flags = &.{} }); | 27 | shared.root_module.addCSourceFile(.{ .file = b.path("shared.c"), .flags = &.{} }); |
| 23 | const test_exe = b.addTest(.{ | 28 | const test_exe = b.addTest(.{ .root_module = b.createModule(.{ |
| 24 | .root_source_file = b.path("main.zig"), | 29 | .root_source_file = b.path("main.zig"), |
| 30 | .target = b.graph.host, | ||
| 25 | .optimize = optimize, | 31 | .optimize = optimize, |
| 26 | }); | 32 | }) }); |
| 27 | test_exe.addObject(obj); | 33 | test_exe.addObject(obj); |
| 28 | test_exe.linkLibrary(shared); | 34 | test_exe.linkLibrary(shared); |
| 29 | 35 |
test/standalone/global_linkage/build.zig+15-9| ... | @@ -9,24 +9,30 @@ pub fn build(b: *std.Build) void { | ... | @@ -9,24 +9,30 @@ pub fn build(b: *std.Build) void { |
| 9 | 9 | ||
| 10 | const obj1 = b.addStaticLibrary(.{ | 10 | const obj1 = b.addStaticLibrary(.{ |
| 11 | .name = "obj1", | 11 | .name = "obj1", |
| 12 | .root_source_file = b.path("obj1.zig"), | 12 | .root_module = b.createModule(.{ |
| 13 | .optimize = optimize, | 13 | .root_source_file = b.path("obj1.zig"), |
| 14 | .target = target, | 14 | .optimize = optimize, |
| 15 | .target = target, | ||
| 16 | }), | ||
| 15 | }); | 17 | }); |
| 16 | 18 | ||
| 17 | const obj2 = b.addStaticLibrary(.{ | 19 | const obj2 = b.addStaticLibrary(.{ |
| 18 | .name = "obj2", | 20 | .name = "obj2", |
| 19 | .root_source_file = b.path("obj2.zig"), | 21 | .root_module = b.createModule(.{ |
| 20 | .optimize = optimize, | 22 | .root_source_file = b.path("obj2.zig"), |
| 21 | .target = target, | 23 | .optimize = optimize, |
| 24 | .target = target, | ||
| 25 | }), | ||
| 22 | }); | 26 | }); |
| 23 | 27 | ||
| 24 | const main = b.addTest(.{ | 28 | const main_mod = b.createModule(.{ |
| 25 | .root_source_file = b.path("main.zig"), | 29 | .root_source_file = b.path("main.zig"), |
| 30 | .target = b.graph.host, | ||
| 26 | .optimize = optimize, | 31 | .optimize = optimize, |
| 27 | }); | 32 | }); |
| 28 | main.linkLibrary(obj1); | 33 | main_mod.linkLibrary(obj1); |
| 29 | main.linkLibrary(obj2); | 34 | main_mod.linkLibrary(obj2); |
| 30 | 35 | ||
| 36 | const main = b.addTest(.{ .root_module = main_mod }); | ||
| 31 | test_step.dependOn(&b.addRunArtifact(main).step); | 37 | test_step.dependOn(&b.addRunArtifact(main).step); |
| 32 | } | 38 | } |
test/standalone/install_headers/build.zig+27-15| ... | @@ -8,18 +8,24 @@ pub fn build(b: *std.Build) void { | ... | @@ -8,18 +8,24 @@ pub fn build(b: *std.Build) void { |
| 8 | 8 | ||
| 9 | const libfoo = b.addStaticLibrary(.{ | 9 | const libfoo = b.addStaticLibrary(.{ |
| 10 | .name = "foo", | 10 | .name = "foo", |
| 11 | .target = b.resolveTargetQuery(.{}), | 11 | .root_module = b.createModule(.{ |
| 12 | .optimize = .Debug, | 12 | .root_source_file = null, |
| 13 | .target = b.resolveTargetQuery(.{}), | ||
| 14 | .optimize = .Debug, | ||
| 15 | }), | ||
| 13 | }); | 16 | }); |
| 14 | libfoo.addCSourceFile(.{ .file = empty_c }); | 17 | libfoo.root_module.addCSourceFile(.{ .file = empty_c }); |
| 15 | 18 | ||
| 16 | const exe = b.addExecutable(.{ | 19 | const exe = b.addExecutable(.{ |
| 17 | .name = "exe", | 20 | .name = "exe", |
| 18 | .target = b.resolveTargetQuery(.{}), | 21 | .root_module = b.createModule(.{ |
| 19 | .optimize = .Debug, | 22 | .root_source_file = null, |
| 20 | .link_libc = true, | 23 | .target = b.resolveTargetQuery(.{}), |
| 24 | .optimize = .Debug, | ||
| 25 | .link_libc = true, | ||
| 26 | }), | ||
| 21 | }); | 27 | }); |
| 22 | exe.addCSourceFile(.{ .file = b.addWriteFiles().add("main.c", | 28 | exe.root_module.addCSourceFile(.{ .file = b.addWriteFiles().add("main.c", |
| 23 | \\#include <stdio.h> | 29 | \\#include <stdio.h> |
| 24 | \\#include <foo/a.h> | 30 | \\#include <foo/a.h> |
| 25 | \\#include <foo/sub_dir/b.h> | 31 | \\#include <foo/sub_dir/b.h> |
| ... | @@ -40,9 +46,10 @@ pub fn build(b: *std.Build) void { | ... | @@ -40,9 +46,10 @@ pub fn build(b: *std.Build) void { |
| 40 | 46 | ||
| 41 | if (libfoo.installed_headers_include_tree != null) std.debug.panic("include tree step was created before linking", .{}); | 47 | if (libfoo.installed_headers_include_tree != null) std.debug.panic("include tree step was created before linking", .{}); |
| 42 | 48 | ||
| 43 | // Link before we have registered all headers for installation, | 49 | // Link (and get the include tree) before we have registered all headers for installation, |
| 44 | // to verify that the lazily created write files step is properly taken into account. | 50 | // to verify that the lazily created write files step is properly taken into account. |
| 45 | exe.linkLibrary(libfoo); | 51 | exe.root_module.linkLibrary(libfoo); |
| 52 | _ = libfoo.getEmittedIncludeTree(); | ||
| 46 | 53 | ||
| 47 | if (libfoo.installed_headers_include_tree == null) std.debug.panic("include tree step was not created after linking", .{}); | 54 | if (libfoo.installed_headers_include_tree == null) std.debug.panic("include tree step was not created after linking", .{}); |
| 48 | 55 | ||
| ... | @@ -56,10 +63,13 @@ pub fn build(b: *std.Build) void { | ... | @@ -56,10 +63,13 @@ pub fn build(b: *std.Build) void { |
| 56 | 63 | ||
| 57 | const libbar = b.addStaticLibrary(.{ | 64 | const libbar = b.addStaticLibrary(.{ |
| 58 | .name = "bar", | 65 | .name = "bar", |
| 59 | .target = b.resolveTargetQuery(.{}), | 66 | .root_module = b.createModule(.{ |
| 60 | .optimize = .Debug, | 67 | .root_source_file = null, |
| 68 | .target = b.resolveTargetQuery(.{}), | ||
| 69 | .optimize = .Debug, | ||
| 70 | }), | ||
| 61 | }); | 71 | }); |
| 62 | libbar.addCSourceFile(.{ .file = empty_c }); | 72 | libbar.root_module.addCSourceFile(.{ .file = empty_c }); |
| 63 | libbar.installHeader(b.addWriteFiles().add("bar.h", | 73 | libbar.installHeader(b.addWriteFiles().add("bar.h", |
| 64 | \\#define BAR_X "X" | 74 | \\#define BAR_X "X" |
| 65 | \\ | 75 | \\ |
| ... | @@ -78,9 +88,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -78,9 +88,11 @@ pub fn build(b: *std.Build) void { |
| 78 | }); | 88 | }); |
| 79 | const check_exists = b.addExecutable(.{ | 89 | const check_exists = b.addExecutable(.{ |
| 80 | .name = "check_exists", | 90 | .name = "check_exists", |
| 81 | .root_source_file = b.path("check_exists.zig"), | 91 | .root_module = b.createModule(.{ |
| 82 | .target = b.resolveTargetQuery(.{}), | 92 | .root_source_file = b.path("check_exists.zig"), |
| 83 | .optimize = .Debug, | 93 | .target = b.resolveTargetQuery(.{}), |
| 94 | .optimize = .Debug, | ||
| 95 | }), | ||
| 84 | }); | 96 | }); |
| 85 | const run_check_exists = b.addRunArtifact(check_exists); | 97 | const run_check_exists = b.addRunArtifact(check_exists); |
| 86 | run_check_exists.addArgs(&.{ | 98 | run_check_exists.addArgs(&.{ |
test/standalone/install_raw_hex/build.zig+5-3| ... | @@ -16,9 +16,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -16,9 +16,11 @@ pub fn build(b: *std.Build) void { |
| 16 | 16 | ||
| 17 | const elf = b.addExecutable(.{ | 17 | const elf = b.addExecutable(.{ |
| 18 | .name = "zig-nrf52-blink.elf", | 18 | .name = "zig-nrf52-blink.elf", |
| 19 | .root_source_file = b.path("main.zig"), | 19 | .root_module = b.createModule(.{ |
| 20 | .target = target, | 20 | .root_source_file = b.path("main.zig"), |
| 21 | .optimize = optimize, | 21 | .target = target, |
| 22 | .optimize = optimize, | ||
| 23 | }), | ||
| 22 | }); | 24 | }); |
| 23 | 25 | ||
| 24 | const hex_step = elf.addObjCopy(.{ | 26 | const hex_step = elf.addObjCopy(.{ |
test/standalone/ios/build.zig+12-9| ... | @@ -18,16 +18,19 @@ pub fn build(b: *std.Build) void { | ... | @@ -18,16 +18,19 @@ pub fn build(b: *std.Build) void { |
| 18 | 18 | ||
| 19 | const exe = b.addExecutable(.{ | 19 | const exe = b.addExecutable(.{ |
| 20 | .name = "main", | 20 | .name = "main", |
| 21 | .optimize = optimize, | 21 | .root_module = b.createModule(.{ |
| 22 | .target = target, | 22 | .root_source_file = null, |
| 23 | .optimize = optimize, | ||
| 24 | .target = target, | ||
| 25 | .link_libc = true, | ||
| 26 | }), | ||
| 23 | }); | 27 | }); |
| 24 | exe.addCSourceFile(.{ .file = b.path("main.m"), .flags = &.{} }); | 28 | exe.root_module.addCSourceFile(.{ .file = b.path("main.m"), .flags = &.{} }); |
| 25 | exe.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) }); | 29 | exe.root_module.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) }); |
| 26 | exe.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) }); | 30 | exe.root_module.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) }); |
| 27 | exe.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/lib" }) }); | 31 | exe.root_module.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/lib" }) }); |
| 28 | exe.linkFramework("Foundation"); | 32 | exe.root_module.linkFramework("Foundation", .{}); |
| 29 | exe.linkFramework("UIKit"); | 33 | exe.root_module.linkFramework("UIKit", .{}); |
| 30 | exe.linkLibC(); | ||
| 31 | 34 | ||
| 32 | const check = exe.checkObject(); | 35 | const check = exe.checkObject(); |
| 33 | check.checkInHeaders(); | 36 | check.checkInHeaders(); |
test/standalone/issue_11595/build.zig+13-11| ... | @@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void { |
| 15 | 15 | ||
| 16 | const exe = b.addExecutable(.{ | 16 | const exe = b.addExecutable(.{ |
| 17 | .name = "zigtest", | 17 | .name = "zigtest", |
| 18 | .root_source_file = b.path("main.zig"), | 18 | .root_module = b.createModule(.{ |
| 19 | .target = target, | 19 | .root_source_file = b.path("main.zig"), |
| 20 | .optimize = optimize, | 20 | .target = target, |
| 21 | .optimize = optimize, | ||
| 22 | }), | ||
| 21 | }); | 23 | }); |
| 22 | b.installArtifact(exe); | 24 | b.installArtifact(exe); |
| 23 | 25 | ||
| ... | @@ -25,21 +27,21 @@ pub fn build(b: *std.Build) void { | ... | @@ -25,21 +27,21 @@ pub fn build(b: *std.Build) void { |
| 25 | "test.c", | 27 | "test.c", |
| 26 | }; | 28 | }; |
| 27 | 29 | ||
| 28 | exe.addCSourceFiles(.{ .files = &c_sources }); | 30 | exe.root_module.addCSourceFiles(.{ .files = &c_sources }); |
| 29 | exe.linkLibC(); | 31 | exe.root_module.link_libc = true; |
| 30 | 32 | ||
| 31 | var i: i32 = 0; | 33 | var i: i32 = 0; |
| 32 | while (i < 1000) : (i += 1) { | 34 | while (i < 1000) : (i += 1) { |
| 33 | exe.defineCMacro("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); | 35 | exe.root_module.addCMacro("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); |
| 34 | } | 36 | } |
| 35 | 37 | ||
| 36 | exe.defineCMacro("FOO", "42"); | 38 | exe.root_module.addCMacro("FOO", "42"); |
| 37 | exe.defineCMacro("BAR", "\"BAR\""); | 39 | exe.root_module.addCMacro("BAR", "\"BAR\""); |
| 38 | exe.defineCMacro("BAZ", | 40 | exe.root_module.addCMacro("BAZ", |
| 39 | \\"\"BAZ\"" | 41 | \\"\"BAZ\"" |
| 40 | ); | 42 | ); |
| 41 | exe.defineCMacro("QUX", "\"Q\" \"UX\""); | 43 | exe.root_module.addCMacro("QUX", "\"Q\" \"UX\""); |
| 42 | exe.defineCMacro("QUUX", "\"QU\\\"UX\""); | 44 | exe.root_module.addCMacro("QUUX", "\"QU\\\"UX\""); |
| 43 | 45 | ||
| 44 | b.default_step.dependOn(&exe.step); | 46 | b.default_step.dependOn(&exe.step); |
| 45 | 47 |
test/standalone/issue_12706/build.zig+7-5| ... | @@ -10,16 +10,18 @@ pub fn build(b: *std.Build) void { | ... | @@ -10,16 +10,18 @@ pub fn build(b: *std.Build) void { |
| 10 | 10 | ||
| 11 | const exe = b.addExecutable(.{ | 11 | const exe = b.addExecutable(.{ |
| 12 | .name = "main", | 12 | .name = "main", |
| 13 | .root_source_file = b.path("main.zig"), | 13 | .root_module = b.createModule(.{ |
| 14 | .optimize = optimize, | 14 | .root_source_file = b.path("main.zig"), |
| 15 | .target = target, | 15 | .optimize = optimize, |
| 16 | .target = target, | ||
| 17 | }), | ||
| 16 | }); | 18 | }); |
| 17 | 19 | ||
| 18 | const c_sources = [_][]const u8{ | 20 | const c_sources = [_][]const u8{ |
| 19 | "test.c", | 21 | "test.c", |
| 20 | }; | 22 | }; |
| 21 | exe.addCSourceFiles(.{ .files = &c_sources }); | 23 | exe.root_module.addCSourceFiles(.{ .files = &c_sources }); |
| 22 | exe.linkLibC(); | 24 | exe.root_module.link_libc = true; |
| 23 | 25 | ||
| 24 | const run_cmd = b.addRunArtifact(exe); | 26 | const run_cmd = b.addRunArtifact(exe); |
| 25 | run_cmd.expectExitCode(0); | 27 | run_cmd.expectExitCode(0); |
test/standalone/issue_13970/build.zig+12-3| ... | @@ -5,15 +5,24 @@ pub fn build(b: *std.Build) void { | ... | @@ -5,15 +5,24 @@ pub fn build(b: *std.Build) void { |
| 5 | b.default_step = test_step; | 5 | b.default_step = test_step; |
| 6 | 6 | ||
| 7 | const test1 = b.addTest(.{ | 7 | const test1 = b.addTest(.{ |
| 8 | .root_source_file = b.path("test_root/empty.zig"), | 8 | .root_module = b.createModule(.{ |
| 9 | .root_source_file = b.path("test_root/empty.zig"), | ||
| 10 | .target = b.graph.host, | ||
| 11 | }), | ||
| 9 | .test_runner = "src/main.zig", | 12 | .test_runner = "src/main.zig", |
| 10 | }); | 13 | }); |
| 11 | const test2 = b.addTest(.{ | 14 | const test2 = b.addTest(.{ |
| 12 | .root_source_file = b.path("src/empty.zig"), | 15 | .root_module = b.createModule(.{ |
| 16 | .root_source_file = b.path("src/empty.zig"), | ||
| 17 | .target = b.graph.host, | ||
| 18 | }), | ||
| 13 | .test_runner = "src/main.zig", | 19 | .test_runner = "src/main.zig", |
| 14 | }); | 20 | }); |
| 15 | const test3 = b.addTest(.{ | 21 | const test3 = b.addTest(.{ |
| 16 | .root_source_file = b.path("empty.zig"), | 22 | .root_module = b.createModule(.{ |
| 23 | .root_source_file = b.path("empty.zig"), | ||
| 24 | .target = b.graph.host, | ||
| 25 | }), | ||
| 17 | .test_runner = "src/main.zig", | 26 | .test_runner = "src/main.zig", |
| 18 | }); | 27 | }); |
| 19 | 28 |
test/standalone/issue_339/build.zig+5-3| ... | @@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void { |
| 9 | 9 | ||
| 10 | const obj = b.addObject(.{ | 10 | const obj = b.addObject(.{ |
| 11 | .name = "test", | 11 | .name = "test", |
| 12 | .root_source_file = b.path("test.zig"), | 12 | .root_module = b.createModule(.{ |
| 13 | .target = target, | 13 | .root_source_file = b.path("test.zig"), |
| 14 | .optimize = optimize, | 14 | .target = target, |
| 15 | .optimize = optimize, | ||
| 16 | }), | ||
| 15 | }); | 17 | }); |
| 16 | 18 | ||
| 17 | // TODO: actually check the output | 19 | // TODO: actually check the output |
test/standalone/issue_5825/build.zig+13-8| ... | @@ -16,20 +16,25 @@ pub fn build(b: *std.Build) void { | ... | @@ -16,20 +16,25 @@ pub fn build(b: *std.Build) void { |
| 16 | const optimize: std.builtin.OptimizeMode = .Debug; | 16 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 17 | const obj = b.addObject(.{ | 17 | const obj = b.addObject(.{ |
| 18 | .name = "issue_5825", | 18 | .name = "issue_5825", |
| 19 | .root_source_file = b.path("main.zig"), | 19 | .root_module = b.createModule(.{ |
| 20 | .optimize = optimize, | 20 | .root_source_file = b.path("main.zig"), |
| 21 | .target = target, | 21 | .optimize = optimize, |
| 22 | .target = target, | ||
| 23 | }), | ||
| 22 | }); | 24 | }); |
| 23 | 25 | ||
| 24 | const exe = b.addExecutable(.{ | 26 | const exe = b.addExecutable(.{ |
| 25 | .name = "issue_5825", | 27 | .name = "issue_5825", |
| 26 | .optimize = optimize, | 28 | .root_module = b.createModule(.{ |
| 27 | .target = target, | 29 | .root_source_file = null, |
| 30 | .optimize = optimize, | ||
| 31 | .target = target, | ||
| 32 | }), | ||
| 28 | }); | 33 | }); |
| 29 | exe.subsystem = .Console; | 34 | exe.subsystem = .Console; |
| 30 | exe.linkSystemLibrary("kernel32"); | 35 | exe.root_module.linkSystemLibrary("kernel32", .{}); |
| 31 | exe.linkSystemLibrary("ntdll"); | 36 | exe.root_module.linkSystemLibrary("ntdll", .{}); |
| 32 | exe.addObject(obj); | 37 | exe.root_module.addObject(obj); |
| 33 | 38 | ||
| 34 | // TODO: actually check the output | 39 | // TODO: actually check the output |
| 35 | _ = exe.getEmittedBin(); | 40 | _ = exe.getEmittedBin(); |
test/standalone/issue_794/build.zig+3-2| ... | @@ -4,9 +4,10 @@ pub fn build(b: *std.Build) void { | ... | @@ -4,9 +4,10 @@ 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 test_artifact = b.addTest(.{ | 7 | const test_artifact = b.addTest(.{ .root_module = b.createModule(.{ |
| 8 | .root_source_file = b.path("main.zig"), | 8 | .root_source_file = b.path("main.zig"), |
| 9 | }); | 9 | .target = b.graph.host, |
| 10 | }) }); | ||
| 10 | test_artifact.addIncludePath(b.path("a_directory")); | 11 | test_artifact.addIncludePath(b.path("a_directory")); |
| 11 | 12 | ||
| 12 | // TODO: actually check the output | 13 | // TODO: actually check the output |
test/standalone/issue_8550/build.zig+6-4| ... | @@ -15,11 +15,13 @@ pub fn build(b: *std.Build) !void { | ... | @@ -15,11 +15,13 @@ pub fn build(b: *std.Build) !void { |
| 15 | 15 | ||
| 16 | const kernel = b.addExecutable(.{ | 16 | const kernel = b.addExecutable(.{ |
| 17 | .name = "kernel", | 17 | .name = "kernel", |
| 18 | .root_source_file = b.path("./main.zig"), | 18 | .root_module = b.createModule(.{ |
| 19 | .optimize = optimize, | 19 | .root_source_file = b.path("./main.zig"), |
| 20 | .target = target, | 20 | .optimize = optimize, |
| 21 | .target = target, | ||
| 22 | }), | ||
| 21 | }); | 23 | }); |
| 22 | kernel.addObjectFile(b.path("./boot.S")); | 24 | kernel.root_module.addObjectFile(b.path("./boot.S")); |
| 23 | kernel.setLinkerScript(b.path("./linker.ld")); | 25 | kernel.setLinkerScript(b.path("./linker.ld")); |
| 24 | b.installArtifact(kernel); | 26 | b.installArtifact(kernel); |
| 25 | 27 |
test/standalone/libcxx/build.zig+15-11| ... | @@ -11,12 +11,14 @@ pub fn build(b: *std.Build) void { | ... | @@ -11,12 +11,14 @@ pub fn build(b: *std.Build) void { |
| 11 | { | 11 | { |
| 12 | const exe = b.addExecutable(.{ | 12 | const exe = b.addExecutable(.{ |
| 13 | .name = "mt", | 13 | .name = "mt", |
| 14 | .root_source_file = b.path("mt.zig"), | 14 | .root_module = b.createModule(.{ |
| 15 | .target = target, | 15 | .root_source_file = b.path("mt.zig"), |
| 16 | .optimize = optimize, | 16 | .target = target, |
| 17 | .optimize = optimize, | ||
| 18 | .link_libcpp = true, | ||
| 19 | }), | ||
| 17 | }); | 20 | }); |
| 18 | exe.linkLibCpp(); | 21 | exe.root_module.addCSourceFile(.{ .file = b.path("mt_doit.cpp") }); |
| 19 | exe.addCSourceFile(.{ .file = b.path("mt_doit.cpp") }); | ||
| 20 | link_step.dependOn(&exe.step); | 22 | link_step.dependOn(&exe.step); |
| 21 | b.installArtifact(exe); | 23 | b.installArtifact(exe); |
| 22 | run_step.dependOn(&b.addRunArtifact(exe).step); | 24 | run_step.dependOn(&b.addRunArtifact(exe).step); |
| ... | @@ -24,13 +26,15 @@ pub fn build(b: *std.Build) void { | ... | @@ -24,13 +26,15 @@ pub fn build(b: *std.Build) void { |
| 24 | { | 26 | { |
| 25 | const exe = b.addExecutable(.{ | 27 | const exe = b.addExecutable(.{ |
| 26 | .name = "st", | 28 | .name = "st", |
| 27 | .root_source_file = b.path("st.zig"), | 29 | .root_module = b.createModule(.{ |
| 28 | .target = target, | 30 | .root_source_file = b.path("st.zig"), |
| 29 | .optimize = optimize, | 31 | .target = target, |
| 30 | .single_threaded = true, | 32 | .optimize = optimize, |
| 33 | .link_libcpp = true, | ||
| 34 | .single_threaded = true, | ||
| 35 | }), | ||
| 31 | }); | 36 | }); |
| 32 | exe.linkLibCpp(); | 37 | exe.root_module.addCSourceFile(.{ .file = b.path("st_doit.cpp") }); |
| 33 | exe.addCSourceFile(.{ .file = b.path("st_doit.cpp") }); | ||
| 34 | link_step.dependOn(&exe.step); | 38 | link_step.dependOn(&exe.step); |
| 35 | b.installArtifact(exe); | 39 | b.installArtifact(exe); |
| 36 | run_step.dependOn(&b.addRunArtifact(exe).step); | 40 | run_step.dependOn(&b.addRunArtifact(exe).step); |
test/standalone/load_dynamic_library/build.zig+10-6| ... | @@ -12,17 +12,21 @@ pub fn build(b: *std.Build) void { | ... | @@ -12,17 +12,21 @@ pub fn build(b: *std.Build) void { |
| 12 | 12 | ||
| 13 | const lib = b.addSharedLibrary(.{ | 13 | const lib = b.addSharedLibrary(.{ |
| 14 | .name = "add", | 14 | .name = "add", |
| 15 | .root_source_file = b.path("add.zig"), | ||
| 16 | .version = .{ .major = 1, .minor = 0, .patch = 0 }, | 15 | .version = .{ .major = 1, .minor = 0, .patch = 0 }, |
| 17 | .optimize = optimize, | 16 | .root_module = b.createModule(.{ |
| 18 | .target = target, | 17 | .root_source_file = b.path("add.zig"), |
| 18 | .optimize = optimize, | ||
| 19 | .target = target, | ||
| 20 | }), | ||
| 19 | }); | 21 | }); |
| 20 | 22 | ||
| 21 | const main = b.addExecutable(.{ | 23 | const main = b.addExecutable(.{ |
| 22 | .name = "main", | 24 | .name = "main", |
| 23 | .root_source_file = b.path("main.zig"), | 25 | .root_module = b.createModule(.{ |
| 24 | .optimize = optimize, | 26 | .root_source_file = b.path("main.zig"), |
| 25 | .target = target, | 27 | .optimize = optimize, |
| 28 | .target = target, | ||
| 29 | }), | ||
| 26 | }); | 30 | }); |
| 27 | 31 | ||
| 28 | const run = b.addRunArtifact(main); | 32 | const run = b.addRunArtifact(main); |
test/standalone/mix_c_files/build.zig+7-5| ... | @@ -18,12 +18,14 @@ pub fn build(b: *std.Build) void { | ... | @@ -18,12 +18,14 @@ pub fn build(b: *std.Build) void { |
| 18 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { | 18 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 19 | const exe = b.addExecutable(.{ | 19 | const exe = b.addExecutable(.{ |
| 20 | .name = "test", | 20 | .name = "test", |
| 21 | .root_source_file = b.path("main.zig"), | 21 | .root_module = b.createModule(.{ |
| 22 | .target = b.graph.host, | 22 | .root_source_file = b.path("main.zig"), |
| 23 | .optimize = optimize, | 23 | .target = b.graph.host, |
| 24 | .optimize = optimize, | ||
| 25 | .link_libc = true, | ||
| 26 | }), | ||
| 24 | }); | 27 | }); |
| 25 | exe.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[_][]const u8{"-std=c11"} }); | 28 | exe.root_module.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[_][]const u8{"-std=c11"} }); |
| 26 | exe.linkLibC(); | ||
| 27 | 29 | ||
| 28 | const run_cmd = b.addRunArtifact(exe); | 30 | const run_cmd = b.addRunArtifact(exe); |
| 29 | run_cmd.skip_foreign_checks = true; | 31 | run_cmd.skip_foreign_checks = true; |
test/standalone/mix_o_files/build.zig+13-8| ... | @@ -9,22 +9,27 @@ pub fn build(b: *std.Build) void { | ... | @@ -9,22 +9,27 @@ pub fn build(b: *std.Build) void { |
| 9 | 9 | ||
| 10 | const obj = b.addObject(.{ | 10 | const obj = b.addObject(.{ |
| 11 | .name = "base64", | 11 | .name = "base64", |
| 12 | .root_source_file = b.path("base64.zig"), | 12 | .root_module = b.createModule(.{ |
| 13 | .optimize = optimize, | 13 | .root_source_file = b.path("base64.zig"), |
| 14 | .target = target, | 14 | .optimize = optimize, |
| 15 | .target = target, | ||
| 16 | }), | ||
| 15 | }); | 17 | }); |
| 16 | 18 | ||
| 17 | const exe = b.addExecutable(.{ | 19 | const exe = b.addExecutable(.{ |
| 18 | .name = "test", | 20 | .name = "test", |
| 19 | .optimize = optimize, | 21 | .root_module = b.createModule(.{ |
| 20 | .target = target, | 22 | .root_source_file = null, |
| 23 | .optimize = optimize, | ||
| 24 | .target = target, | ||
| 25 | .link_libc = true, | ||
| 26 | }), | ||
| 21 | }); | 27 | }); |
| 22 | exe.addCSourceFile(.{ | 28 | exe.root_module.addCSourceFile(.{ |
| 23 | .file = b.path("test.c"), | 29 | .file = b.path("test.c"), |
| 24 | .flags = &[_][]const u8{"-std=c99"}, | 30 | .flags = &[_][]const u8{"-std=c99"}, |
| 25 | }); | 31 | }); |
| 26 | exe.addObject(obj); | 32 | exe.root_module.addObject(obj); |
| 27 | exe.linkSystemLibrary("c"); | ||
| 28 | 33 | ||
| 29 | b.default_step.dependOn(&exe.step); | 34 | b.default_step.dependOn(&exe.step); |
| 30 | 35 |
test/standalone/options/build.zig+2-2| ... | @@ -1,11 +1,11 @@ | ... | @@ -1,11 +1,11 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 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(.{ .root_module = b.createModule(.{ |
| 5 | .root_source_file = b.path("src/main.zig"), | 5 | .root_source_file = b.path("src/main.zig"), |
| 6 | .target = b.graph.host, | 6 | .target = b.graph.host, |
| 7 | .optimize = .Debug, | 7 | .optimize = .Debug, |
| 8 | }); | 8 | }) }); |
| 9 | 9 | ||
| 10 | const options = b.addOptions(); | 10 | const options = b.addOptions(); |
| 11 | main.addOptions("build_options", options); | 11 | main.addOptions("build_options", options); |
test/standalone/pie/build.zig+5-3| ... | @@ -11,9 +11,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -11,9 +11,11 @@ pub fn build(b: *std.Build) void { |
| 11 | }); | 11 | }); |
| 12 | 12 | ||
| 13 | const main = b.addTest(.{ | 13 | const main = b.addTest(.{ |
| 14 | .root_source_file = b.path("main.zig"), | 14 | .root_module = b.createModule(.{ |
| 15 | .optimize = optimize, | 15 | .root_source_file = b.path("main.zig"), |
| 16 | .target = target, | 16 | .optimize = optimize, |
| 17 | .target = target, | ||
| 18 | }), | ||
| 17 | }); | 19 | }); |
| 18 | main.pie = true; | 20 | main.pie = true; |
| 19 | 21 |
test/standalone/pkg_import/build.zig+5-3| ... | @@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void { |
| 8 | 8 | ||
| 9 | const exe = b.addExecutable(.{ | 9 | const exe = b.addExecutable(.{ |
| 10 | .name = "test", | 10 | .name = "test", |
| 11 | .root_source_file = b.path("test.zig"), | 11 | .root_module = b.createModule(.{ |
| 12 | .optimize = optimize, | 12 | .root_source_file = b.path("test.zig"), |
| 13 | .target = b.graph.host, | 13 | .optimize = optimize, |
| 14 | .target = b.graph.host, | ||
| 15 | }), | ||
| 14 | }); | 16 | }); |
| 15 | exe.root_module.addAnonymousImport("my_pkg", .{ .root_source_file = b.path("pkg.zig") }); | 17 | exe.root_module.addAnonymousImport("my_pkg", .{ .root_source_file = b.path("pkg.zig") }); |
| 16 | 18 |
test/standalone/run_output_caching/build.zig+5-3| ... | @@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void { |
| 9 | 9 | ||
| 10 | const exe = b.addExecutable(.{ | 10 | const exe = b.addExecutable(.{ |
| 11 | .name = "create-file", | 11 | .name = "create-file", |
| 12 | .root_source_file = b.path("main.zig"), | 12 | .root_module = b.createModule(.{ |
| 13 | .target = target, | 13 | .root_source_file = b.path("main.zig"), |
| 14 | .optimize = optimize, | 14 | .target = target, |
| 15 | .optimize = optimize, | ||
| 16 | }), | ||
| 15 | }); | 17 | }); |
| 16 | 18 | ||
| 17 | { | 19 | { |
test/standalone/run_output_paths/build.zig+5-3| ... | @@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void { | ... | @@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void { |
| 9 | 9 | ||
| 10 | const create_file_exe = b.addExecutable(.{ | 10 | const create_file_exe = b.addExecutable(.{ |
| 11 | .name = "create_file", | 11 | .name = "create_file", |
| 12 | .root_source_file = b.path("create_file.zig"), | 12 | .root_module = b.createModule(.{ |
| 13 | .target = target, | 13 | .root_source_file = b.path("create_file.zig"), |
| 14 | .optimize = optimize, | 14 | .target = target, |
| 15 | .optimize = optimize, | ||
| 16 | }), | ||
| 15 | }); | 17 | }); |
| 16 | 18 | ||
| 17 | const create_first = b.addRunArtifact(create_file_exe); | 19 | const create_first = b.addRunArtifact(create_file_exe); |
test/standalone/self_exe_symlink/build.zig+10-6| ... | @@ -15,16 +15,20 @@ pub fn build(b: *std.Build) void { | ... | @@ -15,16 +15,20 @@ pub fn build(b: *std.Build) void { |
| 15 | 15 | ||
| 16 | const main = b.addExecutable(.{ | 16 | const main = b.addExecutable(.{ |
| 17 | .name = "main", | 17 | .name = "main", |
| 18 | .root_source_file = b.path("main.zig"), | 18 | .root_module = b.createModule(.{ |
| 19 | .optimize = optimize, | 19 | .root_source_file = b.path("main.zig"), |
| 20 | .target = target, | 20 | .optimize = optimize, |
| 21 | .target = target, | ||
| 22 | }), | ||
| 21 | }); | 23 | }); |
| 22 | 24 | ||
| 23 | const create_symlink_exe = b.addExecutable(.{ | 25 | const create_symlink_exe = b.addExecutable(.{ |
| 24 | .name = "create-symlink", | 26 | .name = "create-symlink", |
| 25 | .root_source_file = b.path("create-symlink.zig"), | 27 | .root_module = b.createModule(.{ |
| 26 | .optimize = optimize, | 28 | .root_source_file = b.path("create-symlink.zig"), |
| 27 | .target = target, | 29 | .optimize = optimize, |
| 30 | .target = target, | ||
| 31 | }), | ||
| 28 | }); | 32 | }); |
| 29 | 33 | ||
| 30 | var run_create_symlink = b.addRunArtifact(create_symlink_exe); | 34 | var run_create_symlink = b.addRunArtifact(create_symlink_exe); |
test/standalone/shared_library/build.zig+13-8| ... | @@ -8,23 +8,28 @@ pub fn build(b: *std.Build) void { | ... | @@ -8,23 +8,28 @@ pub fn build(b: *std.Build) void { |
| 8 | const target = b.graph.host; | 8 | const target = b.graph.host; |
| 9 | const lib = b.addSharedLibrary(.{ | 9 | const lib = b.addSharedLibrary(.{ |
| 10 | .name = "mathtest", | 10 | .name = "mathtest", |
| 11 | .root_source_file = b.path("mathtest.zig"), | ||
| 12 | .version = .{ .major = 1, .minor = 0, .patch = 0 }, | 11 | .version = .{ .major = 1, .minor = 0, .patch = 0 }, |
| 13 | .target = target, | 12 | .root_module = b.createModule(.{ |
| 14 | .optimize = optimize, | 13 | .root_source_file = b.path("mathtest.zig"), |
| 14 | .target = target, | ||
| 15 | .optimize = optimize, | ||
| 16 | }), | ||
| 15 | }); | 17 | }); |
| 16 | 18 | ||
| 17 | const exe = b.addExecutable(.{ | 19 | const exe = b.addExecutable(.{ |
| 18 | .name = "test", | 20 | .name = "test", |
| 19 | .target = target, | 21 | .root_module = b.createModule(.{ |
| 20 | .optimize = optimize, | 22 | .root_source_file = null, |
| 23 | .target = target, | ||
| 24 | .optimize = optimize, | ||
| 25 | .link_libc = true, | ||
| 26 | }), | ||
| 21 | }); | 27 | }); |
| 22 | exe.addCSourceFile(.{ | 28 | exe.root_module.addCSourceFile(.{ |
| 23 | .file = b.path("test.c"), | 29 | .file = b.path("test.c"), |
| 24 | .flags = &[_][]const u8{"-std=c99"}, | 30 | .flags = &[_][]const u8{"-std=c99"}, |
| 25 | }); | 31 | }); |
| 26 | exe.linkLibrary(lib); | 32 | exe.root_module.linkLibrary(lib); |
| 27 | exe.linkSystemLibrary("c"); | ||
| 28 | 33 | ||
| 29 | const run_cmd = b.addRunArtifact(exe); | 34 | const run_cmd = b.addRunArtifact(exe); |
| 30 | test_step.dependOn(&run_cmd.step); | 35 | test_step.dependOn(&run_cmd.step); |
test/standalone/simple/build.zig+12-8| ... | @@ -42,11 +42,13 @@ pub fn build(b: *std.Build) void { | ... | @@ -42,11 +42,13 @@ pub fn build(b: *std.Build) void { |
| 42 | if (case.is_exe) { | 42 | if (case.is_exe) { |
| 43 | const exe = b.addExecutable(.{ | 43 | const exe = b.addExecutable(.{ |
| 44 | .name = std.fs.path.stem(case.src_path), | 44 | .name = std.fs.path.stem(case.src_path), |
| 45 | .root_source_file = b.path(case.src_path), | 45 | .root_module = b.createModule(.{ |
| 46 | .optimize = optimize, | 46 | .root_source_file = b.path(case.src_path), |
| 47 | .target = resolved_target, | 47 | .optimize = optimize, |
| 48 | .target = resolved_target, | ||
| 49 | }), | ||
| 48 | }); | 50 | }); |
| 49 | if (case.link_libc) exe.linkLibC(); | 51 | if (case.link_libc) exe.root_module.link_libc = true; |
| 50 | 52 | ||
| 51 | _ = exe.getEmittedBin(); | 53 | _ = exe.getEmittedBin(); |
| 52 | 54 | ||
| ... | @@ -56,11 +58,13 @@ pub fn build(b: *std.Build) void { | ... | @@ -56,11 +58,13 @@ pub fn build(b: *std.Build) void { |
| 56 | if (case.is_test) { | 58 | if (case.is_test) { |
| 57 | const exe = b.addTest(.{ | 59 | const exe = b.addTest(.{ |
| 58 | .name = std.fs.path.stem(case.src_path), | 60 | .name = std.fs.path.stem(case.src_path), |
| 59 | .root_source_file = b.path(case.src_path), | 61 | .root_module = b.createModule(.{ |
| 60 | .optimize = optimize, | 62 | .root_source_file = b.path(case.src_path), |
| 61 | .target = resolved_target, | 63 | .optimize = optimize, |
| 64 | .target = resolved_target, | ||
| 65 | }), | ||
| 62 | }); | 66 | }); |
| 63 | if (case.link_libc) exe.linkLibC(); | 67 | if (case.link_libc) exe.root_module.link_libc = true; |
| 64 | 68 | ||
| 65 | const run = b.addRunArtifact(exe); | 69 | const run = b.addRunArtifact(exe); |
| 66 | step.dependOn(&run.step); | 70 | step.dependOn(&run.step); |
test/standalone/stack_iterator/build.zig+39-28| ... | @@ -20,11 +20,13 @@ pub fn build(b: *std.Build) void { | ... | @@ -20,11 +20,13 @@ pub fn build(b: *std.Build) void { |
| 20 | { | 20 | { |
| 21 | const exe = b.addExecutable(.{ | 21 | const exe = b.addExecutable(.{ |
| 22 | .name = "unwind_fp", | 22 | .name = "unwind_fp", |
| 23 | .root_source_file = b.path("unwind.zig"), | 23 | .root_module = b.createModule(.{ |
| 24 | .target = target, | 24 | .root_source_file = b.path("unwind.zig"), |
| 25 | .optimize = optimize, | 25 | .target = target, |
| 26 | .unwind_tables = if (target.result.isDarwin()) .@"async" else null, | 26 | .optimize = optimize, |
| 27 | .omit_frame_pointer = false, | 27 | .unwind_tables = if (target.result.isDarwin()) .@"async" else null, |
| 28 | .omit_frame_pointer = false, | ||
| 29 | }), | ||
| 28 | }); | 30 | }); |
| 29 | 31 | ||
| 30 | const run_cmd = b.addRunArtifact(exe); | 32 | const run_cmd = b.addRunArtifact(exe); |
| ... | @@ -43,11 +45,13 @@ pub fn build(b: *std.Build) void { | ... | @@ -43,11 +45,13 @@ pub fn build(b: *std.Build) void { |
| 43 | { | 45 | { |
| 44 | const exe = b.addExecutable(.{ | 46 | const exe = b.addExecutable(.{ |
| 45 | .name = "unwind_nofp", | 47 | .name = "unwind_nofp", |
| 46 | .root_source_file = b.path("unwind.zig"), | 48 | .root_module = b.createModule(.{ |
| 47 | .target = target, | 49 | .root_source_file = b.path("unwind.zig"), |
| 48 | .optimize = optimize, | 50 | .target = target, |
| 49 | .unwind_tables = .@"async", | 51 | .optimize = optimize, |
| 50 | .omit_frame_pointer = true, | 52 | .unwind_tables = .@"async", |
| 53 | .omit_frame_pointer = true, | ||
| 54 | }), | ||
| 51 | }); | 55 | }); |
| 52 | 56 | ||
| 53 | const run_cmd = b.addRunArtifact(exe); | 57 | const run_cmd = b.addRunArtifact(exe); |
| ... | @@ -66,27 +70,32 @@ pub fn build(b: *std.Build) void { | ... | @@ -66,27 +70,32 @@ pub fn build(b: *std.Build) void { |
| 66 | { | 70 | { |
| 67 | const c_shared_lib = b.addSharedLibrary(.{ | 71 | const c_shared_lib = b.addSharedLibrary(.{ |
| 68 | .name = "c_shared_lib", | 72 | .name = "c_shared_lib", |
| 69 | .target = target, | 73 | .root_module = b.createModule(.{ |
| 70 | .optimize = optimize, | 74 | .root_source_file = null, |
| 71 | .strip = false, | 75 | .target = target, |
| 76 | .optimize = optimize, | ||
| 77 | .link_libc = true, | ||
| 78 | .strip = false, | ||
| 79 | }), | ||
| 72 | }); | 80 | }); |
| 73 | 81 | ||
| 74 | if (target.result.os.tag == .windows) | 82 | if (target.result.os.tag == .windows) |
| 75 | c_shared_lib.defineCMacro("LIB_API", "__declspec(dllexport)"); | 83 | c_shared_lib.root_module.addCMacro("LIB_API", "__declspec(dllexport)"); |
| 76 | 84 | ||
| 77 | c_shared_lib.addCSourceFile(.{ | 85 | c_shared_lib.root_module.addCSourceFile(.{ |
| 78 | .file = b.path("shared_lib.c"), | 86 | .file = b.path("shared_lib.c"), |
| 79 | .flags = &.{"-fomit-frame-pointer"}, | 87 | .flags = &.{"-fomit-frame-pointer"}, |
| 80 | }); | 88 | }); |
| 81 | c_shared_lib.linkLibC(); | ||
| 82 | 89 | ||
| 83 | const exe = b.addExecutable(.{ | 90 | const exe = b.addExecutable(.{ |
| 84 | .name = "shared_lib_unwind", | 91 | .name = "shared_lib_unwind", |
| 85 | .root_source_file = b.path("shared_lib_unwind.zig"), | 92 | .root_module = b.createModule(.{ |
| 86 | .target = target, | 93 | .root_source_file = b.path("shared_lib_unwind.zig"), |
| 87 | .optimize = optimize, | 94 | .target = target, |
| 88 | .unwind_tables = if (target.result.isDarwin()) .@"async" else null, | 95 | .optimize = optimize, |
| 89 | .omit_frame_pointer = true, | 96 | .unwind_tables = if (target.result.isDarwin()) .@"async" else null, |
| 97 | .omit_frame_pointer = true, | ||
| 98 | }), | ||
| 90 | }); | 99 | }); |
| 91 | 100 | ||
| 92 | exe.linkLibrary(c_shared_lib); | 101 | exe.linkLibrary(c_shared_lib); |
| ... | @@ -117,14 +126,16 @@ pub fn build(b: *std.Build) void { | ... | @@ -117,14 +126,16 @@ pub fn build(b: *std.Build) void { |
| 117 | inline for (no_os_targets) |os_tag| { | 126 | inline for (no_os_targets) |os_tag| { |
| 118 | const exe = b.addExecutable(.{ | 127 | const exe = b.addExecutable(.{ |
| 119 | .name = "unwind_freestanding", | 128 | .name = "unwind_freestanding", |
| 120 | .root_source_file = b.path("unwind_freestanding.zig"), | 129 | .root_module = b.createModule(.{ |
| 121 | .target = b.resolveTargetQuery(.{ | 130 | .root_source_file = b.path("unwind_freestanding.zig"), |
| 122 | .cpu_arch = .x86_64, | 131 | .target = b.resolveTargetQuery(.{ |
| 123 | .os_tag = os_tag, | 132 | .cpu_arch = .x86_64, |
| 133 | .os_tag = os_tag, | ||
| 134 | }), | ||
| 135 | .optimize = optimize, | ||
| 136 | .unwind_tables = null, | ||
| 137 | .omit_frame_pointer = false, | ||
| 124 | }), | 138 | }), |
| 125 | .optimize = optimize, | ||
| 126 | .unwind_tables = null, | ||
| 127 | .omit_frame_pointer = false, | ||
| 128 | }); | 139 | }); |
| 129 | 140 | ||
| 130 | // This "freestanding" binary is runnable because it invokes the | 141 | // This "freestanding" binary is runnable because it invokes the |
test/standalone/static_c_lib/build.zig+12-8| ... | @@ -8,18 +8,22 @@ pub fn build(b: *std.Build) void { | ... | @@ -8,18 +8,22 @@ pub fn build(b: *std.Build) void { |
| 8 | 8 | ||
| 9 | const foo = b.addStaticLibrary(.{ | 9 | const foo = b.addStaticLibrary(.{ |
| 10 | .name = "foo", | 10 | .name = "foo", |
| 11 | .optimize = optimize, | 11 | .root_module = b.createModule(.{ |
| 12 | .target = b.graph.host, | 12 | .root_source_file = null, |
| 13 | .optimize = optimize, | ||
| 14 | .target = b.graph.host, | ||
| 15 | }), | ||
| 13 | }); | 16 | }); |
| 14 | foo.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &[_][]const u8{} }); | 17 | foo.root_module.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &[_][]const u8{} }); |
| 15 | foo.addIncludePath(b.path(".")); | 18 | foo.root_module.addIncludePath(b.path(".")); |
| 16 | 19 | ||
| 17 | const test_exe = b.addTest(.{ | 20 | const test_exe = b.addTest(.{ .root_module = b.createModule(.{ |
| 18 | .root_source_file = b.path("foo.zig"), | 21 | .root_source_file = b.path("foo.zig"), |
| 22 | .target = b.graph.host, | ||
| 19 | .optimize = optimize, | 23 | .optimize = optimize, |
| 20 | }); | 24 | }) }); |
| 21 | test_exe.linkLibrary(foo); | 25 | test_exe.root_module.linkLibrary(foo); |
| 22 | test_exe.addIncludePath(b.path(".")); | 26 | test_exe.root_module.addIncludePath(b.path(".")); |
| 23 | 27 | ||
| 24 | test_step.dependOn(&b.addRunArtifact(test_exe).step); | 28 | test_step.dependOn(&b.addRunArtifact(test_exe).step); |
| 25 | } | 29 | } |
test/standalone/strip_empty_loop/build.zig+6-4| ... | @@ -9,10 +9,12 @@ pub fn build(b: *std.Build) void { | ... | @@ -9,10 +9,12 @@ pub fn build(b: *std.Build) void { |
| 9 | 9 | ||
| 10 | const main = b.addExecutable(.{ | 10 | const main = b.addExecutable(.{ |
| 11 | .name = "main", | 11 | .name = "main", |
| 12 | .root_source_file = b.path("main.zig"), | 12 | .root_module = b.createModule(.{ |
| 13 | .optimize = optimize, | 13 | .root_source_file = b.path("main.zig"), |
| 14 | .target = target, | 14 | .optimize = optimize, |
| 15 | .strip = true, | 15 | .target = target, |
| 16 | .strip = true, | ||
| 17 | }), | ||
| 16 | }); | 18 | }); |
| 17 | 19 | ||
| 18 | // TODO: actually check the output | 20 | // TODO: actually check the output |
test/standalone/strip_struct_init/build.zig+6-3| ... | @@ -7,9 +7,12 @@ pub fn build(b: *std.Build) void { | ... | @@ -7,9 +7,12 @@ 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 main = b.addTest(.{ | 9 | const main = b.addTest(.{ |
| 10 | .root_source_file = b.path("main.zig"), | 10 | .root_module = b.createModule(.{ |
| 11 | .optimize = optimize, | 11 | .root_source_file = b.path("main.zig"), |
| 12 | .strip = true, | 12 | .target = b.graph.host, |
| 13 | .optimize = optimize, | ||
| 14 | .strip = true, | ||
| 15 | }), | ||
| 13 | }); | 16 | }); |
| 14 | 17 | ||
| 15 | test_step.dependOn(&b.addRunArtifact(main).step); | 18 | test_step.dependOn(&b.addRunArtifact(main).step); |
test/standalone/test_runner_module_imports/build.zig+10-8| ... | @@ -1,18 +1,20 @@ | ... | @@ -1,18 +1,20 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | pub fn build(b: *std.Build) void { | 3 | pub fn build(b: *std.Build) void { |
| 4 | const t = b.addTest(.{ | 4 | const test_mod = b.createModule(.{ |
| 5 | .root_source_file = b.path("src/main.zig"), | 5 | .root_source_file = b.path("src/main.zig"), |
| 6 | .test_runner = b.path("test_runner/main.zig"), | 6 | .target = b.graph.host, |
| 7 | }); | 7 | }); |
| 8 | |||
| 9 | const module1 = b.createModule(.{ .root_source_file = b.path("module1/main.zig") }); | 8 | const module1 = b.createModule(.{ .root_source_file = b.path("module1/main.zig") }); |
| 10 | const module2 = b.createModule(.{ | 9 | const module2 = b.createModule(.{ .root_source_file = b.path("module2/main.zig") }); |
| 11 | .root_source_file = b.path("module2/main.zig"), | ||
| 12 | .imports = &.{.{ .name = "module1", .module = module1 }}, | ||
| 13 | }); | ||
| 14 | 10 | ||
| 15 | t.root_module.addImport("module2", module2); | 11 | module2.addImport("module1", module1); |
| 12 | test_mod.addImport("module2", module2); | ||
| 13 | |||
| 14 | const t = b.addTest(.{ | ||
| 15 | .root_module = test_mod, | ||
| 16 | .test_runner = b.path("test_runner/main.zig"), | ||
| 17 | }); | ||
| 16 | 18 | ||
| 17 | const test_step = b.step("test", "Run unit tests"); | 19 | const test_step = b.step("test", "Run unit tests"); |
| 18 | test_step.dependOn(&b.addRunArtifact(t).step); | 20 | test_step.dependOn(&b.addRunArtifact(t).step); |
test/standalone/test_runner_path/build.zig+3-2| ... | @@ -6,9 +6,10 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,9 +6,10 @@ pub fn build(b: *std.Build) void { |
| 6 | const test_step = b.step("test", "Test the program"); | 6 | const test_step = b.step("test", "Test the program"); |
| 7 | b.default_step = test_step; | 7 | b.default_step = test_step; |
| 8 | 8 | ||
| 9 | const test_exe = b.addTest(.{ | 9 | const test_exe = b.addTest(.{ .root_module = b.createModule(.{ |
| 10 | .target = b.graph.host, | ||
| 10 | .root_source_file = b.path("test.zig"), | 11 | .root_source_file = b.path("test.zig"), |
| 11 | }); | 12 | }) }); |
| 12 | test_exe.test_runner = b.path("test_runner.zig"); | 13 | test_exe.test_runner = b.path("test_runner.zig"); |
| 13 | 14 | ||
| 14 | const test_run = b.addRunArtifact(test_exe); | 15 | const test_run = b.addRunArtifact(test_exe); |
test/standalone/use_alias/build.zig+4-3| ... | @@ -6,11 +6,12 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,11 +6,12 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | ||
| 7 | const optimize: std.builtin.OptimizeMode = .Debug; | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | ||
| 9 | const main = b.addTest(.{ | 9 | const main = b.addTest(.{ .root_module = b.createModule(.{ |
| 10 | .root_source_file = b.path("main.zig"), | 10 | .root_source_file = b.path("main.zig"), |
| 11 | .target = b.graph.host, | ||
| 11 | .optimize = optimize, | 12 | .optimize = optimize, |
| 12 | }); | 13 | }) }); |
| 13 | main.addIncludePath(b.path(".")); | 14 | main.root_module.addIncludePath(b.path(".")); |
| 14 | 15 | ||
| 15 | test_step.dependOn(&b.addRunArtifact(main).step); | 16 | test_step.dependOn(&b.addRunArtifact(main).step); |
| 16 | } | 17 | } |
test/standalone/windows_argv/build.zig+35-23| ... | @@ -11,32 +11,39 @@ pub fn build(b: *std.Build) !void { | ... | @@ -11,32 +11,39 @@ pub fn build(b: *std.Build) !void { |
| 11 | 11 | ||
| 12 | const lib_gnu = b.addStaticLibrary(.{ | 12 | const lib_gnu = b.addStaticLibrary(.{ |
| 13 | .name = "toargv-gnu", | 13 | .name = "toargv-gnu", |
| 14 | .root_source_file = b.path("lib.zig"), | 14 | .root_module = b.createModule(.{ |
| 15 | .target = b.resolveTargetQuery(.{ | 15 | .root_source_file = b.path("lib.zig"), |
| 16 | .abi = .gnu, | 16 | .target = b.resolveTargetQuery(.{ |
| 17 | .abi = .gnu, | ||
| 18 | }), | ||
| 19 | .optimize = optimize, | ||
| 17 | }), | 20 | }), |
| 18 | .optimize = optimize, | ||
| 19 | }); | 21 | }); |
| 20 | const verify_gnu = b.addExecutable(.{ | 22 | const verify_gnu = b.addExecutable(.{ |
| 21 | .name = "verify-gnu", | 23 | .name = "verify-gnu", |
| 22 | .target = b.resolveTargetQuery(.{ | 24 | .root_module = b.createModule(.{ |
| 23 | .abi = .gnu, | 25 | .root_source_file = null, |
| 26 | .target = b.resolveTargetQuery(.{ | ||
| 27 | .abi = .gnu, | ||
| 28 | }), | ||
| 29 | .optimize = optimize, | ||
| 24 | }), | 30 | }), |
| 25 | .optimize = optimize, | ||
| 26 | }); | 31 | }); |
| 27 | verify_gnu.addCSourceFile(.{ | 32 | verify_gnu.root_module.addCSourceFile(.{ |
| 28 | .file = b.path("verify.c"), | 33 | .file = b.path("verify.c"), |
| 29 | .flags = &.{ "-DUNICODE", "-D_UNICODE" }, | 34 | .flags = &.{ "-DUNICODE", "-D_UNICODE" }, |
| 30 | }); | 35 | }); |
| 31 | verify_gnu.mingw_unicode_entry_point = true; | 36 | verify_gnu.mingw_unicode_entry_point = true; |
| 32 | verify_gnu.linkLibrary(lib_gnu); | 37 | verify_gnu.root_module.linkLibrary(lib_gnu); |
| 33 | verify_gnu.linkLibC(); | 38 | verify_gnu.root_module.link_libc = true; |
| 34 | 39 | ||
| 35 | const fuzz = b.addExecutable(.{ | 40 | const fuzz = b.addExecutable(.{ |
| 36 | .name = "fuzz", | 41 | .name = "fuzz", |
| 37 | .root_source_file = b.path("fuzz.zig"), | 42 | .root_module = b.createModule(.{ |
| 38 | .target = b.graph.host, | 43 | .root_source_file = b.path("fuzz.zig"), |
| 39 | .optimize = optimize, | 44 | .target = b.graph.host, |
| 45 | .optimize = optimize, | ||
| 46 | }), | ||
| 40 | }); | 47 | }); |
| 41 | 48 | ||
| 42 | const fuzz_max_iterations = b.option(u64, "iterations", "The max fuzz iterations (default: 100)") orelse 100; | 49 | const fuzz_max_iterations = b.option(u64, "iterations", "The max fuzz iterations (default: 100)") orelse 100; |
| ... | @@ -69,25 +76,30 @@ pub fn build(b: *std.Build) !void { | ... | @@ -69,25 +76,30 @@ pub fn build(b: *std.Build) !void { |
| 69 | if (has_msvc) { | 76 | if (has_msvc) { |
| 70 | const lib_msvc = b.addStaticLibrary(.{ | 77 | const lib_msvc = b.addStaticLibrary(.{ |
| 71 | .name = "toargv-msvc", | 78 | .name = "toargv-msvc", |
| 72 | .root_source_file = b.path("lib.zig"), | 79 | .root_module = b.createModule(.{ |
| 73 | .target = b.resolveTargetQuery(.{ | 80 | .root_source_file = b.path("lib.zig"), |
| 74 | .abi = .msvc, | 81 | .target = b.resolveTargetQuery(.{ |
| 82 | .abi = .msvc, | ||
| 83 | }), | ||
| 84 | .optimize = optimize, | ||
| 75 | }), | 85 | }), |
| 76 | .optimize = optimize, | ||
| 77 | }); | 86 | }); |
| 78 | const verify_msvc = b.addExecutable(.{ | 87 | const verify_msvc = b.addExecutable(.{ |
| 79 | .name = "verify-msvc", | 88 | .name = "verify-msvc", |
| 80 | .target = b.resolveTargetQuery(.{ | 89 | .root_module = b.createModule(.{ |
| 81 | .abi = .msvc, | 90 | .root_source_file = null, |
| 91 | .target = b.resolveTargetQuery(.{ | ||
| 92 | .abi = .msvc, | ||
| 93 | }), | ||
| 94 | .optimize = optimize, | ||
| 82 | }), | 95 | }), |
| 83 | .optimize = optimize, | ||
| 84 | }); | 96 | }); |
| 85 | verify_msvc.addCSourceFile(.{ | 97 | verify_msvc.root_module.addCSourceFile(.{ |
| 86 | .file = b.path("verify.c"), | 98 | .file = b.path("verify.c"), |
| 87 | .flags = &.{ "-DUNICODE", "-D_UNICODE" }, | 99 | .flags = &.{ "-DUNICODE", "-D_UNICODE" }, |
| 88 | }); | 100 | }); |
| 89 | verify_msvc.linkLibrary(lib_msvc); | 101 | verify_msvc.root_module.linkLibrary(lib_msvc); |
| 90 | verify_msvc.linkLibC(); | 102 | verify_msvc.root_module.link_libc = true; |
| 91 | 103 | ||
| 92 | const run_msvc = b.addRunArtifact(fuzz); | 104 | const run_msvc = b.addRunArtifact(fuzz); |
| 93 | run_msvc.setName("fuzz-msvc"); | 105 | run_msvc.setName("fuzz-msvc"); |
test/standalone/windows_bat_args/build.zig+15-9| ... | @@ -12,16 +12,20 @@ pub fn build(b: *std.Build) !void { | ... | @@ -12,16 +12,20 @@ pub fn build(b: *std.Build) !void { |
| 12 | 12 | ||
| 13 | const echo_args = b.addExecutable(.{ | 13 | const echo_args = b.addExecutable(.{ |
| 14 | .name = "echo-args", | 14 | .name = "echo-args", |
| 15 | .root_source_file = b.path("echo-args.zig"), | 15 | .root_module = b.createModule(.{ |
| 16 | .optimize = optimize, | 16 | .root_source_file = b.path("echo-args.zig"), |
| 17 | .target = target, | 17 | .optimize = optimize, |
| 18 | .target = target, | ||
| 19 | }), | ||
| 18 | }); | 20 | }); |
| 19 | 21 | ||
| 20 | const test_exe = b.addExecutable(.{ | 22 | const test_exe = b.addExecutable(.{ |
| 21 | .name = "test", | 23 | .name = "test", |
| 22 | .root_source_file = b.path("test.zig"), | 24 | .root_module = b.createModule(.{ |
| 23 | .optimize = optimize, | 25 | .root_source_file = b.path("test.zig"), |
| 24 | .target = target, | 26 | .optimize = optimize, |
| 27 | .target = target, | ||
| 28 | }), | ||
| 25 | }); | 29 | }); |
| 26 | 30 | ||
| 27 | const run = b.addRunArtifact(test_exe); | 31 | const run = b.addRunArtifact(test_exe); |
| ... | @@ -33,9 +37,11 @@ pub fn build(b: *std.Build) !void { | ... | @@ -33,9 +37,11 @@ pub fn build(b: *std.Build) !void { |
| 33 | 37 | ||
| 34 | const fuzz = b.addExecutable(.{ | 38 | const fuzz = b.addExecutable(.{ |
| 35 | .name = "fuzz", | 39 | .name = "fuzz", |
| 36 | .root_source_file = b.path("fuzz.zig"), | 40 | .root_module = b.createModule(.{ |
| 37 | .optimize = optimize, | 41 | .root_source_file = b.path("fuzz.zig"), |
| 38 | .target = target, | 42 | .optimize = optimize, |
| 43 | .target = target, | ||
| 44 | }), | ||
| 39 | }); | 45 | }); |
| 40 | 46 | ||
| 41 | const fuzz_max_iterations = b.option(u64, "iterations", "The max fuzz iterations (default: 100)") orelse 100; | 47 | const fuzz_max_iterations = b.option(u64, "iterations", "The max fuzz iterations (default: 100)") orelse 100; |
test/standalone/windows_entry_points/build.zig+28-16| ... | @@ -13,11 +13,14 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,11 +13,14 @@ pub fn build(b: *std.Build) void { |
| 13 | { | 13 | { |
| 14 | const exe = b.addExecutable(.{ | 14 | const exe = b.addExecutable(.{ |
| 15 | .name = "main", | 15 | .name = "main", |
| 16 | .target = target, | 16 | .root_module = b.createModule(.{ |
| 17 | .optimize = .Debug, | 17 | .root_source_file = null, |
| 18 | .link_libc = true, | 18 | .target = target, |
| 19 | .optimize = .Debug, | ||
| 20 | .link_libc = true, | ||
| 21 | }), | ||
| 19 | }); | 22 | }); |
| 20 | exe.addCSourceFile(.{ .file = b.path("main.c") }); | 23 | exe.root_module.addCSourceFile(.{ .file = b.path("main.c") }); |
| 21 | 24 | ||
| 22 | _ = exe.getEmittedBin(); | 25 | _ = exe.getEmittedBin(); |
| 23 | test_step.dependOn(&exe.step); | 26 | test_step.dependOn(&exe.step); |
| ... | @@ -26,12 +29,15 @@ pub fn build(b: *std.Build) void { | ... | @@ -26,12 +29,15 @@ pub fn build(b: *std.Build) void { |
| 26 | { | 29 | { |
| 27 | const exe = b.addExecutable(.{ | 30 | const exe = b.addExecutable(.{ |
| 28 | .name = "wmain", | 31 | .name = "wmain", |
| 29 | .target = target, | 32 | .root_module = b.createModule(.{ |
| 30 | .optimize = .Debug, | 33 | .root_source_file = null, |
| 31 | .link_libc = true, | 34 | .target = target, |
| 35 | .optimize = .Debug, | ||
| 36 | .link_libc = true, | ||
| 37 | }), | ||
| 32 | }); | 38 | }); |
| 33 | exe.mingw_unicode_entry_point = true; | 39 | exe.mingw_unicode_entry_point = true; |
| 34 | exe.addCSourceFile(.{ .file = b.path("wmain.c") }); | 40 | exe.root_module.addCSourceFile(.{ .file = b.path("wmain.c") }); |
| 35 | 41 | ||
| 36 | _ = exe.getEmittedBin(); | 42 | _ = exe.getEmittedBin(); |
| 37 | test_step.dependOn(&exe.step); | 43 | test_step.dependOn(&exe.step); |
| ... | @@ -40,12 +46,15 @@ pub fn build(b: *std.Build) void { | ... | @@ -40,12 +46,15 @@ pub fn build(b: *std.Build) void { |
| 40 | { | 46 | { |
| 41 | const exe = b.addExecutable(.{ | 47 | const exe = b.addExecutable(.{ |
| 42 | .name = "winmain", | 48 | .name = "winmain", |
| 43 | .target = target, | 49 | .root_module = b.createModule(.{ |
| 44 | .optimize = .Debug, | 50 | .root_source_file = null, |
| 45 | .link_libc = true, | 51 | .target = target, |
| 52 | .optimize = .Debug, | ||
| 53 | .link_libc = true, | ||
| 54 | }), | ||
| 46 | }); | 55 | }); |
| 47 | // Note: `exe.subsystem = .Windows;` is not necessary | 56 | // Note: `exe.subsystem = .Windows;` is not necessary |
| 48 | exe.addCSourceFile(.{ .file = b.path("winmain.c") }); | 57 | exe.root_module.addCSourceFile(.{ .file = b.path("winmain.c") }); |
| 49 | 58 | ||
| 50 | _ = exe.getEmittedBin(); | 59 | _ = exe.getEmittedBin(); |
| 51 | test_step.dependOn(&exe.step); | 60 | test_step.dependOn(&exe.step); |
| ... | @@ -54,13 +63,16 @@ pub fn build(b: *std.Build) void { | ... | @@ -54,13 +63,16 @@ pub fn build(b: *std.Build) void { |
| 54 | { | 63 | { |
| 55 | const exe = b.addExecutable(.{ | 64 | const exe = b.addExecutable(.{ |
| 56 | .name = "wwinmain", | 65 | .name = "wwinmain", |
| 57 | .target = target, | 66 | .root_module = b.createModule(.{ |
| 58 | .optimize = .Debug, | 67 | .root_source_file = null, |
| 59 | .link_libc = true, | 68 | .target = target, |
| 69 | .optimize = .Debug, | ||
| 70 | .link_libc = true, | ||
| 71 | }), | ||
| 60 | }); | 72 | }); |
| 61 | exe.mingw_unicode_entry_point = true; | 73 | exe.mingw_unicode_entry_point = true; |
| 62 | // Note: `exe.subsystem = .Windows;` is not necessary | 74 | // Note: `exe.subsystem = .Windows;` is not necessary |
| 63 | exe.addCSourceFile(.{ .file = b.path("wwinmain.c") }); | 75 | exe.root_module.addCSourceFile(.{ .file = b.path("wwinmain.c") }); |
| 64 | 76 | ||
| 65 | _ = exe.getEmittedBin(); | 77 | _ = exe.getEmittedBin(); |
| 66 | test_step.dependOn(&exe.step); | 78 | test_step.dependOn(&exe.step); |
test/standalone/windows_resources/build.zig+6-4| ... | @@ -28,11 +28,13 @@ fn add( | ... | @@ -28,11 +28,13 @@ fn add( |
| 28 | ) void { | 28 | ) void { |
| 29 | const exe = b.addExecutable(.{ | 29 | const exe = b.addExecutable(.{ |
| 30 | .name = "zig_resource_test", | 30 | .name = "zig_resource_test", |
| 31 | .root_source_file = b.path("main.zig"), | 31 | .root_module = b.createModule(.{ |
| 32 | .target = target, | 32 | .root_source_file = b.path("main.zig"), |
| 33 | .optimize = .Debug, | 33 | .target = target, |
| 34 | .optimize = .Debug, | ||
| 35 | }), | ||
| 34 | }); | 36 | }); |
| 35 | exe.addWin32ResourceFile(.{ | 37 | exe.root_module.addWin32ResourceFile(.{ |
| 36 | .file = b.path("res/zig.rc"), | 38 | .file = b.path("res/zig.rc"), |
| 37 | .flags = &.{"/c65001"}, // UTF-8 code page | 39 | .flags = &.{"/c65001"}, // UTF-8 code page |
| 38 | .include_paths = &.{ | 40 | .include_paths = &.{ |
test/standalone/windows_spawn/build.zig+10-6| ... | @@ -12,16 +12,20 @@ pub fn build(b: *std.Build) void { | ... | @@ -12,16 +12,20 @@ pub fn build(b: *std.Build) void { |
| 12 | 12 | ||
| 13 | const hello = b.addExecutable(.{ | 13 | const hello = b.addExecutable(.{ |
| 14 | .name = "hello", | 14 | .name = "hello", |
| 15 | .root_source_file = b.path("hello.zig"), | 15 | .root_module = b.createModule(.{ |
| 16 | .optimize = optimize, | 16 | .root_source_file = b.path("hello.zig"), |
| 17 | .target = target, | 17 | .optimize = optimize, |
| 18 | .target = target, | ||
| 19 | }), | ||
| 18 | }); | 20 | }); |
| 19 | 21 | ||
| 20 | const main = b.addExecutable(.{ | 22 | const main = b.addExecutable(.{ |
| 21 | .name = "main", | 23 | .name = "main", |
| 22 | .root_source_file = b.path("main.zig"), | 24 | .root_module = b.createModule(.{ |
| 23 | .optimize = optimize, | 25 | .root_source_file = b.path("main.zig"), |
| 24 | .target = target, | 26 | .optimize = optimize, |
| 27 | .target = target, | ||
| 28 | }), | ||
| 25 | }); | 29 | }); |
| 26 | 30 | ||
| 27 | const run = b.addRunArtifact(main); | 31 | const run = b.addRunArtifact(main); |
test/standalone/zerolength_check/build.zig+2-2| ... | @@ -11,7 +11,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -11,7 +11,7 @@ pub fn build(b: *std.Build) void { |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 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(.{ .root_module = b.createModule(.{ |
| 15 | .root_source_file = b.path("src/main.zig"), | 15 | .root_source_file = b.path("src/main.zig"), |
| 16 | .target = b.resolveTargetQuery(.{ | 16 | .target = b.resolveTargetQuery(.{ |
| 17 | .os_tag = .wasi, | 17 | .os_tag = .wasi, |
| ... | @@ -19,7 +19,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -19,7 +19,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 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 | ||
| 24 | const run_unit_tests = b.addRunArtifact(unit_tests); | 24 | const run_unit_tests = b.addRunArtifact(unit_tests); |
| 25 | run_unit_tests.skip_foreign_checks = true; | 25 | run_unit_tests.skip_foreign_checks = true; |
test/tests.zig+51-36| ... | @@ -1106,9 +1106,11 @@ pub fn addStackTraceTests( | ... | @@ -1106,9 +1106,11 @@ pub fn addStackTraceTests( |
| 1106 | ) *Step { | 1106 | ) *Step { |
| 1107 | const check_exe = b.addExecutable(.{ | 1107 | const check_exe = b.addExecutable(.{ |
| 1108 | .name = "check-stack-trace", | 1108 | .name = "check-stack-trace", |
| 1109 | .root_source_file = b.path("test/src/check-stack-trace.zig"), | 1109 | .root_module = b.createModule(.{ |
| 1110 | .target = b.graph.host, | 1110 | .root_source_file = b.path("test/src/check-stack-trace.zig"), |
| 1111 | .optimize = .Debug, | 1111 | .target = b.graph.host, |
| 1112 | .optimize = .Debug, | ||
| 1113 | }), | ||
| 1112 | }); | 1114 | }); |
| 1113 | 1115 | ||
| 1114 | const cases = b.allocator.create(StackTracesContext) catch @panic("OOM"); | 1116 | const cases = b.allocator.create(StackTracesContext) catch @panic("OOM"); |
| ... | @@ -1330,7 +1332,7 @@ pub fn addCliTests(b: *std.Build) *Step { | ... | @@ -1330,7 +1332,7 @@ pub fn addCliTests(b: *std.Build) *Step { |
| 1330 | run5.step.dependOn(&run4.step); | 1332 | run5.step.dependOn(&run4.step); |
| 1331 | 1333 | ||
| 1332 | const unformatted_code_utf16 = "\xff\xfe \x00 \x00 \x00 \x00/\x00/\x00 \x00n\x00o\x00 \x00r\x00e\x00a\x00s\x00o\x00n\x00"; | 1334 | const unformatted_code_utf16 = "\xff\xfe \x00 \x00 \x00 \x00/\x00/\x00 \x00n\x00o\x00 \x00r\x00e\x00a\x00s\x00o\x00n\x00"; |
| 1333 | const fmt6_path = std.fs.path.join(b.allocator, &.{ tmp_path, "fmt6.zig" }) catch @panic("OOM"); | 1335 | const fmt6_path = b.pathJoin(&.{ tmp_path, "fmt6.zig" }); |
| 1334 | const write6 = b.addUpdateSourceFiles(); | 1336 | const write6 = b.addUpdateSourceFiles(); |
| 1335 | write6.addBytesToSource(unformatted_code_utf16, fmt6_path); | 1337 | write6.addBytesToSource(unformatted_code_utf16, fmt6_path); |
| 1336 | write6.step.dependOn(&run5.step); | 1338 | write6.step.dependOn(&run5.step); |
| ... | @@ -1514,18 +1516,20 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { | ... | @@ -1514,18 +1516,20 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1514 | options.max_rss; | 1516 | options.max_rss; |
| 1515 | 1517 | ||
| 1516 | const these_tests = b.addTest(.{ | 1518 | const these_tests = b.addTest(.{ |
| 1517 | .root_source_file = b.path(options.root_src), | 1519 | .root_module = b.createModule(.{ |
| 1518 | .optimize = test_target.optimize_mode, | 1520 | .root_source_file = b.path(options.root_src), |
| 1519 | .target = resolved_target, | 1521 | .optimize = test_target.optimize_mode, |
| 1522 | .target = resolved_target, | ||
| 1523 | .link_libc = test_target.link_libc, | ||
| 1524 | .pic = test_target.pic, | ||
| 1525 | .strip = test_target.strip, | ||
| 1526 | .single_threaded = test_target.single_threaded, | ||
| 1527 | }), | ||
| 1520 | .max_rss = max_rss, | 1528 | .max_rss = max_rss, |
| 1521 | .filters = options.test_filters, | 1529 | .filters = options.test_filters, |
| 1522 | .link_libc = test_target.link_libc, | ||
| 1523 | .single_threaded = test_target.single_threaded, | ||
| 1524 | .use_llvm = test_target.use_llvm, | 1530 | .use_llvm = test_target.use_llvm, |
| 1525 | .use_lld = test_target.use_lld, | 1531 | .use_lld = test_target.use_lld, |
| 1526 | .zig_lib_dir = b.path("lib"), | 1532 | .zig_lib_dir = b.path("lib"), |
| 1527 | .pic = test_target.pic, | ||
| 1528 | .strip = test_target.strip, | ||
| 1529 | }); | 1533 | }); |
| 1530 | if (options.no_builtin) these_tests.no_builtin = true; | 1534 | if (options.no_builtin) these_tests.no_builtin = true; |
| 1531 | if (options.build_options) |build_options| { | 1535 | if (options.build_options) |build_options| { |
| ... | @@ -1561,12 +1565,17 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { | ... | @@ -1561,12 +1565,17 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1561 | var altered_query = test_target.target; | 1565 | var altered_query = test_target.target; |
| 1562 | altered_query.ofmt = null; | 1566 | altered_query.ofmt = null; |
| 1563 | 1567 | ||
| 1564 | const compile_c = b.addExecutable(.{ | 1568 | const compile_c = b.createModule(.{ |
| 1565 | .name = qualified_name, | 1569 | .root_source_file = null, |
| 1566 | .link_libc = test_target.link_libc, | 1570 | .link_libc = test_target.link_libc, |
| 1567 | .target = b.resolveTargetQuery(altered_query), | 1571 | .target = b.resolveTargetQuery(altered_query), |
| 1572 | }); | ||
| 1573 | const compile_c_exe = b.addExecutable(.{ | ||
| 1574 | .name = qualified_name, | ||
| 1575 | .root_module = compile_c, | ||
| 1568 | .zig_lib_dir = b.path("lib"), | 1576 | .zig_lib_dir = b.path("lib"), |
| 1569 | }); | 1577 | }); |
| 1578 | |||
| 1570 | compile_c.addCSourceFile(.{ | 1579 | compile_c.addCSourceFile(.{ |
| 1571 | .file = these_tests.getEmittedBin(), | 1580 | .file = these_tests.getEmittedBin(), |
| 1572 | .flags = &.{ | 1581 | .flags = &.{ |
| ... | @@ -1611,22 +1620,22 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { | ... | @@ -1611,22 +1620,22 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1611 | continue; | 1620 | continue; |
| 1612 | } | 1621 | } |
| 1613 | if (test_target.link_libc == false) { | 1622 | if (test_target.link_libc == false) { |
| 1614 | compile_c.subsystem = .Console; | 1623 | compile_c_exe.subsystem = .Console; |
| 1615 | compile_c.linkSystemLibrary("kernel32"); | 1624 | compile_c.linkSystemLibrary("kernel32", .{}); |
| 1616 | compile_c.linkSystemLibrary("ntdll"); | 1625 | compile_c.linkSystemLibrary("ntdll", .{}); |
| 1617 | } | 1626 | } |
| 1618 | if (mem.eql(u8, options.name, "std")) { | 1627 | if (mem.eql(u8, options.name, "std")) { |
| 1619 | if (test_target.link_libc == false) { | 1628 | if (test_target.link_libc == false) { |
| 1620 | compile_c.linkSystemLibrary("shell32"); | 1629 | compile_c.linkSystemLibrary("shell32", .{}); |
| 1621 | compile_c.linkSystemLibrary("advapi32"); | 1630 | compile_c.linkSystemLibrary("advapi32", .{}); |
| 1622 | } | 1631 | } |
| 1623 | compile_c.linkSystemLibrary("crypt32"); | 1632 | compile_c.linkSystemLibrary("crypt32", .{}); |
| 1624 | compile_c.linkSystemLibrary("ws2_32"); | 1633 | compile_c.linkSystemLibrary("ws2_32", .{}); |
| 1625 | compile_c.linkSystemLibrary("ole32"); | 1634 | compile_c.linkSystemLibrary("ole32", .{}); |
| 1626 | } | 1635 | } |
| 1627 | } | 1636 | } |
| 1628 | 1637 | ||
| 1629 | const run = b.addRunArtifact(compile_c); | 1638 | const run = b.addRunArtifact(compile_c_exe); |
| 1630 | run.skip_foreign_checks = true; | 1639 | run.skip_foreign_checks = true; |
| 1631 | run.enableTestRunnerMode(); | 1640 | run.enableTestRunnerMode(); |
| 1632 | run.setName(b.fmt("run test {s}", .{qualified_name})); | 1641 | run.setName(b.fmt("run test {s}", .{qualified_name})); |
| ... | @@ -1675,6 +1684,20 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step { | ... | @@ -1675,6 +1684,20 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step { |
| 1675 | continue; | 1684 | continue; |
| 1676 | } | 1685 | } |
| 1677 | 1686 | ||
| 1687 | const test_mod = b.createModule(.{ | ||
| 1688 | .root_source_file = b.path("test/c_abi/main.zig"), | ||
| 1689 | .target = resolved_target, | ||
| 1690 | .optimize = optimize_mode, | ||
| 1691 | .link_libc = true, | ||
| 1692 | .pic = c_abi_target.pic, | ||
| 1693 | .strip = c_abi_target.strip, | ||
| 1694 | }); | ||
| 1695 | test_mod.addCSourceFile(.{ | ||
| 1696 | .file = b.path("test/c_abi/cfuncs.c"), | ||
| 1697 | .flags = &.{"-std=c99"}, | ||
| 1698 | }); | ||
| 1699 | for (c_abi_target.c_defines) |define| test_mod.addCMacro(define, "1"); | ||
| 1700 | |||
| 1678 | const test_step = b.addTest(.{ | 1701 | const test_step = b.addTest(.{ |
| 1679 | .name = b.fmt("test-c-abi-{s}-{s}-{s}{s}{s}{s}", .{ | 1702 | .name = b.fmt("test-c-abi-{s}-{s}-{s}{s}{s}{s}", .{ |
| 1680 | triple_txt, | 1703 | triple_txt, |
| ... | @@ -1691,20 +1714,10 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step { | ... | @@ -1691,20 +1714,10 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step { |
| 1691 | if (c_abi_target.use_lld == false) "-no-lld" else "", | 1714 | if (c_abi_target.use_lld == false) "-no-lld" else "", |
| 1692 | if (c_abi_target.pic == true) "-pic" else "", | 1715 | if (c_abi_target.pic == true) "-pic" else "", |
| 1693 | }), | 1716 | }), |
| 1694 | .root_source_file = b.path("test/c_abi/main.zig"), | 1717 | .root_module = test_mod, |
| 1695 | .target = resolved_target, | ||
| 1696 | .optimize = optimize_mode, | ||
| 1697 | .link_libc = true, | ||
| 1698 | .use_llvm = c_abi_target.use_llvm, | 1718 | .use_llvm = c_abi_target.use_llvm, |
| 1699 | .use_lld = c_abi_target.use_lld, | 1719 | .use_lld = c_abi_target.use_lld, |
| 1700 | .pic = c_abi_target.pic, | ||
| 1701 | .strip = c_abi_target.strip, | ||
| 1702 | }); | 1720 | }); |
| 1703 | test_step.addCSourceFile(.{ | ||
| 1704 | .file = b.path("test/c_abi/cfuncs.c"), | ||
| 1705 | .flags = &.{"-std=c99"}, | ||
| 1706 | }); | ||
| 1707 | for (c_abi_target.c_defines) |define| test_step.defineCMacro(define, null); | ||
| 1708 | 1721 | ||
| 1709 | // This test is intentionally trying to check if the external ABI is | 1722 | // This test is intentionally trying to check if the external ABI is |
| 1710 | // done properly. LTO would be a hindrance to this. | 1723 | // done properly. LTO would be a hindrance to this. |
| ... | @@ -1784,9 +1797,11 @@ pub fn addDebuggerTests(b: *std.Build, options: DebuggerContext.Options) ?*Step | ... | @@ -1784,9 +1797,11 @@ pub fn addDebuggerTests(b: *std.Build, options: DebuggerContext.Options) ?*Step |
| 1784 | pub fn addIncrementalTests(b: *std.Build, test_step: *Step) !void { | 1797 | pub fn addIncrementalTests(b: *std.Build, test_step: *Step) !void { |
| 1785 | const incr_check = b.addExecutable(.{ | 1798 | const incr_check = b.addExecutable(.{ |
| 1786 | .name = "incr-check", | 1799 | .name = "incr-check", |
| 1787 | .root_source_file = b.path("tools/incr-check.zig"), | 1800 | .root_module = b.createModule(.{ |
| 1788 | .target = b.graph.host, | 1801 | .root_source_file = b.path("tools/incr-check.zig"), |
| 1789 | .optimize = .Debug, | 1802 | .target = b.graph.host, |
| 1803 | .optimize = .Debug, | ||
| 1804 | }), | ||
| 1790 | }); | 1805 | }); |
| 1791 | 1806 | ||
| 1792 | var dir = try b.build_root.handle.openDir("test/incremental", .{ .iterate = true }); | 1807 | var dir = try b.build_root.handle.openDir("test/incremental", .{ .iterate = true }); |