| 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 | 50 | |
| 51 | 51 | const autodoc_test = b.addObject(.{ |
| 52 | 52 | .name = "std", |
| 53 | .root_source_file = b.path("lib/std/std.zig"), | |
| 54 | .target = target, | |
| 55 | 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 | 60 | const install_std_docs = b.addInstallDirectory(.{ |
| 59 | 61 | .source_dir = autodoc_test.getEmittedDocs(), |
| ... | ... | @@ -234,7 +236,7 @@ pub fn build(b: *std.Build) !void { |
| 234 | 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 | 238 | if (link_libc) { |
| 237 | exe.linkLibC(); | |
| 239 | exe.root_module.link_libc = true; | |
| 238 | 240 | } |
| 239 | 241 | |
| 240 | 242 | const is_debug = optimize == .Debug; |
| ... | ... | @@ -330,15 +332,15 @@ pub fn build(b: *std.Build) !void { |
| 330 | 332 | try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx); |
| 331 | 333 | } else { |
| 332 | 334 | // Here we are -Denable-llvm but no cmake integration. |
| 333 | try addStaticLlvmOptionsToExe(exe); | |
| 335 | try addStaticLlvmOptionsToModule(exe.root_module); | |
| 334 | 336 | } |
| 335 | 337 | if (target.result.os.tag == .windows) { |
| 336 | 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"); | |
| 340 | exe.linkSystemLibrary("uuid"); | |
| 341 | exe.linkSystemLibrary("ole32"); | |
| 341 | exe.root_module.linkSystemLibrary("version", .{}); | |
| 342 | exe.root_module.linkSystemLibrary("uuid", .{}); | |
| 343 | exe.root_module.linkSystemLibrary("ole32", .{}); | |
| 342 | 344 | } |
| 343 | 345 | } |
| 344 | 346 | |
| ... | ... | @@ -364,16 +366,16 @@ pub fn build(b: *std.Build) !void { |
| 364 | 366 | else |
| 365 | 367 | &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }; |
| 366 | 368 | |
| 367 | exe.addIncludePath(.{ .cwd_relative = tracy_path }); | |
| 368 | exe.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags }); | |
| 369 | exe.root_module.addIncludePath(.{ .cwd_relative = tracy_path }); | |
| 370 | exe.root_module.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags }); | |
| 369 | 371 | if (!enable_llvm) { |
| 370 | 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 | 376 | if (target.result.os.tag == .windows) { |
| 375 | exe.linkSystemLibrary("dbghelp"); | |
| 376 | exe.linkSystemLibrary("ws2_32"); | |
| 377 | exe.root_module.linkSystemLibrary("dbghelp", .{}); | |
| 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 | 561 | if (opt_mingw_src_path) |mingw_src_path| { |
| 560 | 562 | const update_mingw_exe = b.addExecutable(.{ |
| 561 | 563 | .name = "update_mingw", |
| 562 | .target = b.graph.host, | |
| 563 | .root_source_file = b.path("tools/update_mingw.zig"), | |
| 564 | .root_module = b.createModule(.{ | |
| 565 | .target = b.graph.host, | |
| 566 | .root_source_file = b.path("tools/update_mingw.zig"), | |
| 567 | }), | |
| 564 | 568 | }); |
| 565 | 569 | const update_mingw_run = b.addRunArtifact(update_mingw_exe); |
| 566 | 570 | update_mingw_run.addDirectoryArg(b.path("lib")); |
| ... | ... | @@ -636,12 +640,10 @@ const AddCompilerStepOptions = struct { |
| 636 | 640 | }; |
| 637 | 641 | |
| 638 | 642 | fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.Step.Compile { |
| 639 | const exe = b.addExecutable(.{ | |
| 640 | .name = "zig", | |
| 643 | const compiler_mod = b.createModule(.{ | |
| 641 | 644 | .root_source_file = b.path("src/main.zig"), |
| 642 | 645 | .target = options.target, |
| 643 | 646 | .optimize = options.optimize, |
| 644 | .max_rss = 7_800_000_000, | |
| 645 | 647 | .strip = options.strip, |
| 646 | 648 | .sanitize_thread = options.sanitize_thread, |
| 647 | 649 | .single_threaded = options.single_threaded, |
| ... | ... | @@ -663,26 +665,28 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St |
| 663 | 665 | .loongarch32, .loongarch64 => .medium, |
| 664 | 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 | 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 | 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); | |
| 685 | exe.root_module.addImport("aro_translate_c", aro_translate_c_module); | |
| 679 | aro_translate_c_mod.addImport("aro", aro_mod); | |
| 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 | 690 | return exe; |
| 687 | 691 | } |
| 688 | 692 | |
| ... | ... | @@ -707,11 +711,15 @@ fn addCmakeCfgOptionsToExe( |
| 707 | 711 | exe: *std.Build.Step.Compile, |
| 708 | 712 | use_zig_libcxx: bool, |
| 709 | 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 | 718 | // useful for package maintainers |
| 712 | 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 | 723 | cfg.cmake_binary_dir, |
| 716 | 724 | "zigcpp", |
| 717 | 725 | b.fmt("{s}{s}{s}", .{ |
| ... | ... | @@ -721,38 +729,38 @@ fn addCmakeCfgOptionsToExe( |
| 721 | 729 | }), |
| 722 | 730 | }) }); |
| 723 | 731 | assert(cfg.lld_include_dir.len != 0); |
| 724 | exe.addIncludePath(.{ .cwd_relative = cfg.lld_include_dir }); | |
| 725 | exe.addIncludePath(.{ .cwd_relative = cfg.llvm_include_dir }); | |
| 726 | exe.addLibraryPath(.{ .cwd_relative = cfg.llvm_lib_dir }); | |
| 727 | addCMakeLibraryList(exe, cfg.clang_libraries); | |
| 728 | addCMakeLibraryList(exe, cfg.lld_libraries); | |
| 729 | addCMakeLibraryList(exe, cfg.llvm_libraries); | |
| 732 | mod.addIncludePath(.{ .cwd_relative = cfg.lld_include_dir }); | |
| 733 | mod.addIncludePath(.{ .cwd_relative = cfg.llvm_include_dir }); | |
| 734 | mod.addLibraryPath(.{ .cwd_relative = cfg.llvm_lib_dir }); | |
| 735 | addCMakeLibraryList(mod, cfg.clang_libraries); | |
| 736 | addCMakeLibraryList(mod, cfg.lld_libraries); | |
| 737 | addCMakeLibraryList(mod, cfg.llvm_libraries); | |
| 730 | 738 | |
| 731 | 739 | if (use_zig_libcxx) { |
| 732 | exe.linkLibCpp(); | |
| 740 | mod.link_libcpp = true; | |
| 733 | 741 | } else { |
| 734 | 742 | // System -lc++ must be used because in this code path we are attempting to link |
| 735 | 743 | // against system-provided LLVM, Clang, LLD. |
| 736 | 744 | const need_cpp_includes = true; |
| 737 | 745 | const static = cfg.llvm_linkage == .static; |
| 738 | const lib_suffix = if (static) exe.rootModuleTarget().staticLibSuffix()[1..] else exe.rootModuleTarget().dynamicLibSuffix()[1..]; | |
| 739 | switch (exe.rootModuleTarget().os.tag) { | |
| 746 | const lib_suffix = if (static) target.staticLibSuffix()[1..] else target.dynamicLibSuffix()[1..]; | |
| 747 | switch (target.os.tag) { | |
| 740 | 748 | .linux => { |
| 741 | 749 | // First we try to link against the detected libcxx name. If that doesn't work, we fall |
| 742 | 750 | // back to -lc++ and cross our fingers. |
| 743 | 751 | addCxxKnownPath(b, cfg, exe, b.fmt("lib{s}.{s}", .{ cfg.system_libcxx, lib_suffix }), "", need_cpp_includes) catch |err| switch (err) { |
| 744 | 752 | error.RequiredLibraryNotFound => { |
| 745 | exe.linkLibCpp(); | |
| 753 | mod.link_libcpp = true; | |
| 746 | 754 | }, |
| 747 | 755 | else => |e| return e, |
| 748 | 756 | }; |
| 749 | exe.linkSystemLibrary("unwind"); | |
| 757 | mod.linkSystemLibrary("unwind", .{}); | |
| 750 | 758 | }, |
| 751 | 759 | .ios, .macos, .watchos, .tvos, .visionos => { |
| 752 | exe.linkLibCpp(); | |
| 760 | mod.link_libcpp = true; | |
| 753 | 761 | }, |
| 754 | 762 | .windows => { |
| 755 | if (exe.rootModuleTarget().abi != .msvc) exe.linkLibCpp(); | |
| 763 | if (target.abi != .msvc) mod.link_libcpp = true; | |
| 756 | 764 | }, |
| 757 | 765 | .freebsd => { |
| 758 | 766 | if (static) { |
| ... | ... | @@ -786,46 +794,46 @@ fn addCmakeCfgOptionsToExe( |
| 786 | 794 | } |
| 787 | 795 | |
| 788 | 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 | 802 | // Adds the Zig C++ sources which both stage1 and stage2 need. |
| 795 | 803 | // |
| 796 | 804 | // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling |
| 797 | 805 | // in a dependency on llvm::cfg::Update<llvm::BasicBlock*>::dump() which is |
| 798 | 806 | // unavailable when LLVM is compiled in Release mode. |
| 799 | 807 | const zig_cpp_cflags = exe_cflags ++ [_][]const u8{"-DNDEBUG=1"}; |
| 800 | exe.addCSourceFiles(.{ | |
| 808 | mod.addCSourceFiles(.{ | |
| 801 | 809 | .files = &zig_cpp_sources, |
| 802 | 810 | .flags = &zig_cpp_cflags, |
| 803 | 811 | }); |
| 804 | 812 | |
| 805 | 813 | for (clang_libs) |lib_name| { |
| 806 | exe.linkSystemLibrary(lib_name); | |
| 814 | mod.linkSystemLibrary(lib_name, .{}); | |
| 807 | 815 | } |
| 808 | 816 | |
| 809 | 817 | for (lld_libs) |lib_name| { |
| 810 | exe.linkSystemLibrary(lib_name); | |
| 818 | mod.linkSystemLibrary(lib_name, .{}); | |
| 811 | 819 | } |
| 812 | 820 | |
| 813 | 821 | for (llvm_libs) |lib_name| { |
| 814 | exe.linkSystemLibrary(lib_name); | |
| 822 | mod.linkSystemLibrary(lib_name, .{}); | |
| 815 | 823 | } |
| 816 | 824 | |
| 817 | exe.linkSystemLibrary("z"); | |
| 818 | exe.linkSystemLibrary("zstd"); | |
| 825 | mod.linkSystemLibrary("z", .{}); | |
| 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 | 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) { | |
| 826 | exe.linkSystemLibrary("version"); | |
| 827 | exe.linkSystemLibrary("uuid"); | |
| 828 | exe.linkSystemLibrary("ole32"); | |
| 833 | if (mod.resolved_target.?.result.os.tag == .windows) { | |
| 834 | mod.linkSystemLibrary("version", .{}); | |
| 835 | mod.linkSystemLibrary("uuid", .{}); | |
| 836 | mod.linkSystemLibrary("ole32", .{}); | |
| 829 | 837 | } |
| 830 | 838 | } |
| 831 | 839 | |
| ... | ... | @@ -862,29 +870,29 @@ fn addCxxKnownPath( |
| 862 | 870 | // but libc++ may very well be one, so force all inputs to be checked when passing |
| 863 | 871 | // an explicit path to libc++. |
| 864 | 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 | 875 | // TODO a way to integrate with system c++ include files here |
| 868 | 876 | // c++ -E -Wp,-v -xc++ /dev/null |
| 869 | 877 | if (need_cpp_includes) { |
| 870 | 878 | // I used these temporarily for testing something but we obviously need a |
| 871 | 879 | // more general purpose solution here. |
| 872 | //exe.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"); | |
| 880 | //exe.root_module.addIncludePath("/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/include/c++/11.3.0"); | |
| 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 | 886 | var it = mem.tokenizeScalar(u8, list, ';'); |
| 879 | 887 | while (it.next()) |lib| { |
| 880 | 888 | if (mem.startsWith(u8, lib, "-l")) { |
| 881 | exe.linkSystemLibrary(lib["-l".len..]); | |
| 882 | } else if (exe.rootModuleTarget().os.tag == .windows and | |
| 889 | mod.linkSystemLibrary(lib["-l".len..], .{}); | |
| 890 | } else if (mod.resolved_target.?.result.os.tag == .windows and | |
| 883 | 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 | 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 | 1314 | fn generateLangRef(b: *std.Build) std.Build.LazyPath { |
| 1307 | 1315 | const doctest_exe = b.addExecutable(.{ |
| 1308 | 1316 | .name = "doctest", |
| 1309 | .root_source_file = b.path("tools/doctest.zig"), | |
| 1310 | .target = b.graph.host, | |
| 1311 | .optimize = .Debug, | |
| 1317 | .root_module = b.createModule(.{ | |
| 1318 | .root_source_file = b.path("tools/doctest.zig"), | |
| 1319 | .target = b.graph.host, | |
| 1320 | .optimize = .Debug, | |
| 1321 | }), | |
| 1312 | 1322 | }); |
| 1313 | 1323 | |
| 1314 | 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 | 1353 | |
| 1344 | 1354 | const docgen_exe = b.addExecutable(.{ |
| 1345 | 1355 | .name = "docgen", |
| 1346 | .root_source_file = b.path("tools/docgen.zig"), | |
| 1347 | .target = b.graph.host, | |
| 1348 | .optimize = .Debug, | |
| 1356 | .root_module = b.createModule(.{ | |
| 1357 | .root_source_file = b.path("tools/docgen.zig"), | |
| 1358 | .target = b.graph.host, | |
| 1359 | .optimize = .Debug, | |
| 1360 | }), | |
| 1349 | 1361 | }); |
| 1350 | 1362 | |
| 1351 | 1363 | const docgen_cmd = b.addRunArtifact(docgen_exe); |
lib/compiler/build_runner.zig+78| ... | ... | @@ -337,6 +337,7 @@ pub fn main() !void { |
| 337 | 337 | var prog_node = main_progress_node.start("Configure", 0); |
| 338 | 338 | defer prog_node.end(); |
| 339 | 339 | try builder.runBuild(root); |
| 340 | createModuleDependencies(builder) catch @panic("OOM"); | |
| 340 | 341 | } |
| 341 | 342 | |
| 342 | 343 | if (graph.needed_lazy_dependencies.entries.len != 0) { |
| ... | ... | @@ -1440,3 +1441,80 @@ fn validateSystemLibraryOptions(b: *std.Build) void { |
| 1440 | 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 | 15 | // set a preferred release mode, allowing the user to decide how to optimize. |
| 16 | 16 | const optimize = b.standardOptimizeOption(.{}); |
| 17 | 17 | |
| 18 | const lib = b.addStaticLibrary(.{ | |
| 19 | .name = "$", | |
| 18 | // This creates a "module", which represents a collection of source files alongside | |
| 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 | 24 | // In this case the main source file is merely a path, however, in more |
| 21 | 25 | // complicated build scripts, this could be a generated file. |
| 22 | 26 | .root_source_file = b.path("src/root.zig"), |
| ... | ... | @@ -24,16 +28,40 @@ pub fn build(b: *std.Build) void { |
| 24 | 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 | 55 | // This declares intent for the library to be installed into the standard |
| 28 | 56 | // location when the user invokes the "install" step (the default step when |
| 29 | 57 | // running `zig build`). |
| 30 | 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 | 62 | const exe = b.addExecutable(.{ |
| 33 | 63 | .name = "$", |
| 34 | .root_source_file = b.path("src/main.zig"), | |
| 35 | .target = target, | |
| 36 | .optimize = optimize, | |
| 64 | .root_module = exe_mod, | |
| 37 | 65 | }); |
| 38 | 66 | |
| 39 | 67 | // This declares intent for the executable to be installed into the |
| ... | ... | @@ -67,17 +95,13 @@ pub fn build(b: *std.Build) void { |
| 67 | 95 | // Creates a step for unit testing. This only builds the test executable |
| 68 | 96 | // but does not run it. |
| 69 | 97 | const lib_unit_tests = b.addTest(.{ |
| 70 | .root_source_file = b.path("src/root.zig"), | |
| 71 | .target = target, | |
| 72 | .optimize = optimize, | |
| 98 | .root_module = lib_mod, | |
| 73 | 99 | }); |
| 74 | 100 | |
| 75 | 101 | const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); |
| 76 | 102 | |
| 77 | 103 | const exe_unit_tests = b.addTest(.{ |
| 78 | .root_source_file = b.path("src/main.zig"), | |
| 79 | .target = target, | |
| 80 | .optimize = optimize, | |
| 104 | .root_module = exe_mod, | |
| 81 | 105 | }); |
| 82 | 106 | |
| 83 | 107 | const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); |
lib/init/src/main.zig+9-1| ... | ... | @@ -1,7 +1,6 @@ |
| 1 | 1 | //! By convention, main.zig is where your main function lives in the case that |
| 2 | 2 | //! you are building an executable. If you are making a library, the convention |
| 3 | 3 | //! is to delete this file and start with root.zig instead. |
| 4 | const std = @import("std"); | |
| 5 | 4 | |
| 6 | 5 | pub fn main() !void { |
| 7 | 6 | // Prints to stderr (it's a shortcut based on `std.io.getStdErr()`) |
| ... | ... | @@ -26,6 +25,10 @@ test "simple test" { |
| 26 | 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 | 32 | test "fuzz example" { |
| 30 | 33 | const global = struct { |
| 31 | 34 | fn testOne(input: []const u8) anyerror!void { |
| ... | ... | @@ -35,3 +38,8 @@ test "fuzz example" { |
| 35 | 38 | }; |
| 36 | 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 | 4 | const std = @import("std"); |
| 5 | 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 | 8 | return a + b; |
| 9 | 9 | } |
| 10 | 10 |
lib/std/Build.zig+180-87| ... | ... | @@ -81,9 +81,6 @@ enable_wine: bool = false, |
| 81 | 81 | /// that contains the path `aarch64-linux-gnu/lib/ld-linux-aarch64.so.1`. |
| 82 | 82 | glibc_runtimes_dir: ?[]const u8 = null, |
| 83 | 83 | |
| 84 | /// Deprecated. Use `b.graph.host`. | |
| 85 | host: ResolvedTarget, | |
| 86 | ||
| 87 | 84 | dep_prefix: []const u8 = "", |
| 88 | 85 | |
| 89 | 86 | modules: std.StringArrayHashMap(*Module), |
| ... | ... | @@ -301,7 +298,6 @@ pub fn create( |
| 301 | 298 | }, |
| 302 | 299 | .install_path = undefined, |
| 303 | 300 | .args = null, |
| 304 | .host = graph.host, | |
| 305 | 301 | .modules = .init(arena), |
| 306 | 302 | .named_writefiles = .init(arena), |
| 307 | 303 | .named_lazy_paths = .init(arena), |
| ... | ... | @@ -393,7 +389,6 @@ fn createChildOnly( |
| 393 | 389 | .enable_wasmtime = parent.enable_wasmtime, |
| 394 | 390 | .enable_wine = parent.enable_wine, |
| 395 | 391 | .glibc_runtimes_dir = parent.glibc_runtimes_dir, |
| 396 | .host = parent.host, | |
| 397 | 392 | .dep_prefix = parent.fmt("{s}{s}.", .{ parent.dep_prefix, dep_name }), |
| 398 | 393 | .modules = .init(allocator), |
| 399 | 394 | .named_writefiles = .init(allocator), |
| ... | ... | @@ -692,24 +687,9 @@ pub fn addOptions(b: *Build) *Step.Options { |
| 692 | 687 | |
| 693 | 688 | pub const ExecutableOptions = struct { |
| 694 | 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 | 690 | version: ?std.SemanticVersion = null, |
| 701 | optimize: std.builtin.OptimizeMode = .Debug, | |
| 702 | code_model: std.builtin.CodeModel = .default, | |
| 703 | 691 | linkage: ?std.builtin.LinkMode = null, |
| 704 | 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 | 693 | use_llvm: ?bool = null, |
| 714 | 694 | use_lld: ?bool = null, |
| 715 | 695 | zig_lib_dir: ?LazyPath = null, |
| ... | ... | @@ -719,14 +699,47 @@ pub const ExecutableOptions = struct { |
| 719 | 699 | /// Can be set regardless of target. The `.manifest` file will be ignored |
| 720 | 700 | /// if the target object format does not support embedded manifests. |
| 721 | 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 | 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 | 739 | .name = options.name, |
| 727 | .root_module = .{ | |
| 740 | .root_module = options.root_module orelse b.createModule(.{ | |
| 728 | 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 | 743 | .optimize = options.optimize, |
| 731 | 744 | .link_libc = options.link_libc, |
| 732 | 745 | .single_threaded = options.single_threaded, |
| ... | ... | @@ -737,7 +750,7 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { |
| 737 | 750 | .sanitize_thread = options.sanitize_thread, |
| 738 | 751 | .error_tracing = options.error_tracing, |
| 739 | 752 | .code_model = options.code_model, |
| 740 | }, | |
| 753 | }), | |
| 741 | 754 | .version = options.version, |
| 742 | 755 | .kind = .exe, |
| 743 | 756 | .linkage = options.linkage, |
| ... | ... | @@ -751,32 +764,51 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { |
| 751 | 764 | |
| 752 | 765 | pub const ObjectOptions = struct { |
| 753 | 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 | 778 | root_source_file: ?LazyPath = null, |
| 755 | /// To choose the same computer as the one building the package, pass the | |
| 756 | /// `host` field of the package's `Build` instance. | |
| 757 | target: ResolvedTarget, | |
| 779 | /// Deprecated; prefer populating `root_module`. | |
| 780 | target: ?ResolvedTarget = null, | |
| 781 | /// Deprecated; prefer populating `root_module`. | |
| 782 | optimize: std.builtin.OptimizeMode = .Debug, | |
| 783 | /// Deprecated; prefer populating `root_module`. | |
| 758 | 784 | code_model: std.builtin.CodeModel = .default, |
| 759 | optimize: std.builtin.OptimizeMode, | |
| 760 | max_rss: usize = 0, | |
| 785 | /// Deprecated; prefer populating `root_module`. | |
| 761 | 786 | link_libc: ?bool = null, |
| 787 | /// Deprecated; prefer populating `root_module`. | |
| 762 | 788 | single_threaded: ?bool = null, |
| 789 | /// Deprecated; prefer populating `root_module`. | |
| 763 | 790 | pic: ?bool = null, |
| 791 | /// Deprecated; prefer populating `root_module`. | |
| 764 | 792 | strip: ?bool = null, |
| 793 | /// Deprecated; prefer populating `root_module`. | |
| 765 | 794 | unwind_tables: ?std.builtin.UnwindTables = null, |
| 795 | /// Deprecated; prefer populating `root_module`. | |
| 766 | 796 | omit_frame_pointer: ?bool = null, |
| 797 | /// Deprecated; prefer populating `root_module`. | |
| 767 | 798 | sanitize_thread: ?bool = null, |
| 799 | /// Deprecated; prefer populating `root_module`. | |
| 768 | 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 | 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 | 808 | .name = options.name, |
| 777 | .root_module = .{ | |
| 809 | .root_module = options.root_module orelse b.createModule(.{ | |
| 778 | 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 | 812 | .optimize = options.optimize, |
| 781 | 813 | .link_libc = options.link_libc, |
| 782 | 814 | .single_threaded = options.single_threaded, |
| ... | ... | @@ -787,7 +819,7 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { |
| 787 | 819 | .sanitize_thread = options.sanitize_thread, |
| 788 | 820 | .error_tracing = options.error_tracing, |
| 789 | 821 | .code_model = options.code_model, |
| 790 | }, | |
| 822 | }), | |
| 791 | 823 | .kind = .obj, |
| 792 | 824 | .max_rss = options.max_rss, |
| 793 | 825 | .use_llvm = options.use_llvm, |
| ... | ... | @@ -798,22 +830,8 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { |
| 798 | 830 | |
| 799 | 831 | pub const SharedLibraryOptions = struct { |
| 800 | 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 | 833 | version: ?std.SemanticVersion = null, |
| 808 | 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 | 835 | use_llvm: ?bool = null, |
| 818 | 836 | use_lld: ?bool = null, |
| 819 | 837 | zig_lib_dir: ?LazyPath = null, |
| ... | ... | @@ -823,13 +841,46 @@ pub const SharedLibraryOptions = struct { |
| 823 | 841 | /// Can be set regardless of target. The `.manifest` file will be ignored |
| 824 | 842 | /// if the target object format does not support embedded manifests. |
| 825 | 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 | 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 | 881 | .name = options.name, |
| 831 | .root_module = .{ | |
| 832 | .target = options.target, | |
| 882 | .root_module = options.root_module orelse b.createModule(.{ | |
| 883 | .target = options.target orelse @panic("`root_module` and `target` cannot both be null"), | |
| 833 | 884 | .optimize = options.optimize, |
| 834 | 885 | .root_source_file = options.root_source_file, |
| 835 | 886 | .link_libc = options.link_libc, |
| ... | ... | @@ -841,7 +892,7 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile |
| 841 | 892 | .sanitize_thread = options.sanitize_thread, |
| 842 | 893 | .error_tracing = options.error_tracing, |
| 843 | 894 | .code_model = options.code_model, |
| 844 | }, | |
| 895 | }), | |
| 845 | 896 | .kind = .lib, |
| 846 | 897 | .linkage = .dynamic, |
| 847 | 898 | .version = options.version, |
| ... | ... | @@ -855,32 +906,51 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile |
| 855 | 906 | |
| 856 | 907 | pub const StaticLibraryOptions = struct { |
| 857 | 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 | 909 | version: ?std.SemanticVersion = null, |
| 865 | 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 | 929 | link_libc: ?bool = null, |
| 930 | /// Deprecated; prefer populating `root_module`. | |
| 867 | 931 | single_threaded: ?bool = null, |
| 932 | /// Deprecated; prefer populating `root_module`. | |
| 868 | 933 | pic: ?bool = null, |
| 934 | /// Deprecated; prefer populating `root_module`. | |
| 869 | 935 | strip: ?bool = null, |
| 936 | /// Deprecated; prefer populating `root_module`. | |
| 870 | 937 | unwind_tables: ?std.builtin.UnwindTables = null, |
| 938 | /// Deprecated; prefer populating `root_module`. | |
| 871 | 939 | omit_frame_pointer: ?bool = null, |
| 940 | /// Deprecated; prefer populating `root_module`. | |
| 872 | 941 | sanitize_thread: ?bool = null, |
| 942 | /// Deprecated; prefer populating `root_module`. | |
| 873 | 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 | 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 | 951 | .name = options.name, |
| 882 | .root_module = .{ | |
| 883 | .target = options.target, | |
| 952 | .root_module = options.root_module orelse b.createModule(.{ | |
| 953 | .target = options.target orelse @panic("`root_module` and `target` cannot both be null"), | |
| 884 | 954 | .optimize = options.optimize, |
| 885 | 955 | .root_source_file = options.root_source_file, |
| 886 | 956 | .link_libc = options.link_libc, |
| ... | ... | @@ -892,7 +962,7 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile |
| 892 | 962 | .sanitize_thread = options.sanitize_thread, |
| 893 | 963 | .error_tracing = options.error_tracing, |
| 894 | 964 | .code_model = options.code_model, |
| 895 | }, | |
| 965 | }), | |
| 896 | 966 | .kind = .lib, |
| 897 | 967 | .linkage = .static, |
| 898 | 968 | .version = options.version, |
| ... | ... | @@ -905,27 +975,46 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile |
| 905 | 975 | |
| 906 | 976 | pub const TestOptions = struct { |
| 907 | 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 | 978 | max_rss: usize = 0, |
| 913 | /// deprecated: use `.filters = &.{filter}` instead of `.filter = filter`. | |
| 979 | /// Deprecated; use `.filters = &.{filter}` instead of `.filter = filter`. | |
| 914 | 980 | filter: ?[]const u8 = null, |
| 915 | 981 | filters: []const []const u8 = &.{}, |
| 916 | 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 | 1001 | link_libc: ?bool = null, |
| 1002 | /// Deprecated; prefer populating `root_module`. | |
| 918 | 1003 | link_libcpp: ?bool = null, |
| 1004 | /// Deprecated; prefer populating `root_module`. | |
| 919 | 1005 | single_threaded: ?bool = null, |
| 1006 | /// Deprecated; prefer populating `root_module`. | |
| 920 | 1007 | pic: ?bool = null, |
| 1008 | /// Deprecated; prefer populating `root_module`. | |
| 921 | 1009 | strip: ?bool = null, |
| 1010 | /// Deprecated; prefer populating `root_module`. | |
| 922 | 1011 | unwind_tables: ?std.builtin.UnwindTables = null, |
| 1012 | /// Deprecated; prefer populating `root_module`. | |
| 923 | 1013 | omit_frame_pointer: ?bool = null, |
| 1014 | /// Deprecated; prefer populating `root_module`. | |
| 924 | 1015 | sanitize_thread: ?bool = null, |
| 1016 | /// Deprecated; prefer populating `root_module`. | |
| 925 | 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 | 1020 | /// Creates an executable containing unit tests. |
| ... | ... | @@ -937,11 +1026,14 @@ pub const TestOptions = struct { |
| 937 | 1026 | /// two steps are separated because they are independently configured and |
| 938 | 1027 | /// cached. |
| 939 | 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 | 1033 | .name = options.name, |
| 942 | 1034 | .kind = .@"test", |
| 943 | .root_module = .{ | |
| 944 | .root_source_file = options.root_source_file, | |
| 1035 | .root_module = options.root_module orelse b.createModule(.{ | |
| 1036 | .root_source_file = options.root_source_file orelse @panic("`root_module` and `root_source_file` cannot both be null"), | |
| 945 | 1037 | .target = options.target orelse b.graph.host, |
| 946 | 1038 | .optimize = options.optimize, |
| 947 | 1039 | .link_libc = options.link_libc, |
| ... | ... | @@ -953,7 +1045,7 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { |
| 953 | 1045 | .omit_frame_pointer = options.omit_frame_pointer, |
| 954 | 1046 | .sanitize_thread = options.sanitize_thread, |
| 955 | 1047 | .error_tracing = options.error_tracing, |
| 956 | }, | |
| 1048 | }), | |
| 957 | 1049 | .max_rss = options.max_rss, |
| 958 | 1050 | .filters = if (options.filter != null and options.filters.len > 0) filters: { |
| 959 | 1051 | const filters = b.allocator.alloc([]const u8, 1 + options.filters.len) catch @panic("OOM"); |
| ... | ... | @@ -979,19 +1071,20 @@ pub const AssemblyOptions = struct { |
| 979 | 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 | 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 | 1083 | .name = options.name, |
| 985 | .kind = .obj, | |
| 986 | .root_module = .{ | |
| 987 | .target = options.target, | |
| 988 | .optimize = options.optimize, | |
| 989 | }, | |
| 990 | 1084 | .max_rss = options.max_rss, |
| 991 | 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 | 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 | 1 | /// The one responsible for creating this module. |
| 2 | 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 | 3 | root_source_file: ?LazyPath, |
| 8 | 4 | /// The modules that are mapped into this module's import table. |
| 9 | 5 | /// Use `addImport` rather than modifying this field directly in order to |
| ... | ... | @@ -41,6 +37,10 @@ link_libcpp: ?bool, |
| 41 | 37 | /// Symbols to be exported when compiling to WebAssembly. |
| 42 | 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 | 44 | pub const RPath = union(enum) { |
| 45 | 45 | lazy_path: LazyPath, |
| 46 | 46 | special: []const u8, |
| ... | ... | @@ -242,59 +242,61 @@ pub const Import = struct { |
| 242 | 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 | 250 | const allocator = owner.allocator; |
| 247 | 251 | |
| 248 | m.* = .{ | |
| 249 | .owner = owner, | |
| 250 | .depending_steps = .{}, | |
| 251 | .root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null, | |
| 252 | .import_table = .{}, | |
| 253 | .resolved_target = options.target, | |
| 254 | .optimize = options.optimize, | |
| 255 | .link_libc = options.link_libc, | |
| 256 | .link_libcpp = options.link_libcpp, | |
| 257 | .dwarf_format = options.dwarf_format, | |
| 258 | .c_macros = .{}, | |
| 259 | .include_dirs = .{}, | |
| 260 | .lib_paths = .{}, | |
| 261 | .rpaths = .{}, | |
| 262 | .frameworks = .{}, | |
| 263 | .link_objects = .{}, | |
| 264 | .strip = options.strip, | |
| 265 | .unwind_tables = options.unwind_tables, | |
| 266 | .single_threaded = options.single_threaded, | |
| 267 | .stack_protector = options.stack_protector, | |
| 268 | .stack_check = options.stack_check, | |
| 269 | .sanitize_c = options.sanitize_c, | |
| 270 | .sanitize_thread = options.sanitize_thread, | |
| 271 | .fuzz = options.fuzz, | |
| 272 | .code_model = options.code_model, | |
| 273 | .valgrind = options.valgrind, | |
| 274 | .pic = options.pic, | |
| 275 | .red_zone = options.red_zone, | |
| 276 | .omit_frame_pointer = options.omit_frame_pointer, | |
| 277 | .error_tracing = options.error_tracing, | |
| 278 | .export_symbol_names = &.{}, | |
| 279 | }; | |
| 280 | ||
| 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 | } | |
| 252 | switch (value) { | |
| 253 | .options => |options| { | |
| 254 | m.* = .{ | |
| 255 | .owner = owner, | |
| 256 | .root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null, | |
| 257 | .import_table = .{}, | |
| 258 | .resolved_target = options.target, | |
| 259 | .optimize = options.optimize, | |
| 260 | .link_libc = options.link_libc, | |
| 261 | .link_libcpp = options.link_libcpp, | |
| 262 | .dwarf_format = options.dwarf_format, | |
| 263 | .c_macros = .{}, | |
| 264 | .include_dirs = .{}, | |
| 265 | .lib_paths = .{}, | |
| 266 | .rpaths = .{}, | |
| 267 | .frameworks = .{}, | |
| 268 | .link_objects = .{}, | |
| 269 | .strip = options.strip, | |
| 270 | .unwind_tables = options.unwind_tables, | |
| 271 | .single_threaded = options.single_threaded, | |
| 272 | .stack_protector = options.stack_protector, | |
| 273 | .stack_check = options.stack_check, | |
| 274 | .sanitize_c = options.sanitize_c, | |
| 275 | .sanitize_thread = options.sanitize_thread, | |
| 276 | .fuzz = options.fuzz, | |
| 277 | .code_model = options.code_model, | |
| 278 | .valgrind = options.valgrind, | |
| 279 | .pic = options.pic, | |
| 280 | .red_zone = options.red_zone, | |
| 281 | .omit_frame_pointer = options.omit_frame_pointer, | |
| 282 | .error_tracing = options.error_tracing, | |
| 283 | .export_symbol_names = &.{}, | |
| 284 | }; | |
| 285 | 285 | |
| 286 | if (compile) |c| { | |
| 287 | m.depending_steps.put(allocator, c, {}) catch @panic("OOM"); | |
| 286 | m.import_table.ensureUnusedCapacity(allocator, options.imports.len) 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 | 297 | pub fn create(owner: *std.Build, options: CreateOptions) *Module { |
| 296 | 298 | const m = owner.allocator.create(Module) catch @panic("OOM"); |
| 297 | m.init(owner, options, null); | |
| 299 | m.init(owner, .{ .options = options }); | |
| 298 | 300 | return m; |
| 299 | 301 | } |
| 300 | 302 | |
| ... | ... | @@ -302,69 +304,6 @@ pub fn create(owner: *std.Build, options: CreateOptions) *Module { |
| 302 | 304 | pub fn addImport(m: *Module, name: []const u8, module: *Module) void { |
| 303 | 305 | const b = m.owner; |
| 304 | 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 | 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 | 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 | 322 | pub const LinkSystemLibraryOptions = struct { |
| 469 | 323 | /// Causes dynamic libraries to be linked regardless of whether they are |
| 470 | 324 | /// actually depended on. When false, dynamic libraries with no referenced |
| ... | ... | @@ -547,7 +401,6 @@ pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void { |
| 547 | 401 | .flags = b.dupeStrings(options.flags), |
| 548 | 402 | }; |
| 549 | 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 | 406 | pub fn addCSourceFile(m: *Module, source: CSourceFile) void { |
| ... | ... | @@ -556,7 +409,6 @@ pub fn addCSourceFile(m: *Module, source: CSourceFile) void { |
| 556 | 409 | const c_source_file = allocator.create(CSourceFile) catch @panic("OOM"); |
| 557 | 410 | c_source_file.* = source.dupe(b); |
| 558 | 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 | 414 | /// Resource files must have the extension `.rc`. |
| ... | ... | @@ -573,22 +425,16 @@ pub fn addWin32ResourceFile(m: *Module, source: RcSourceFile) void { |
| 573 | 425 | const rc_source_file = allocator.create(RcSourceFile) catch @panic("OOM"); |
| 574 | 426 | rc_source_file.* = source.dupe(b); |
| 575 | 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 | 430 | pub fn addAssemblyFile(m: *Module, source: LazyPath) void { |
| 583 | 431 | const b = m.owner; |
| 584 | 432 | m.link_objects.append(b.allocator, .{ .assembly_file = source.dupe(b) }) catch @panic("OOM"); |
| 585 | addLazyPathDependenciesOnly(m, source); | |
| 586 | 433 | } |
| 587 | 434 | |
| 588 | 435 | pub fn addObjectFile(m: *Module, object: LazyPath) void { |
| 589 | 436 | const b = m.owner; |
| 590 | 437 | m.link_objects.append(b.allocator, .{ .static_path = object.dupe(b) }) catch @panic("OOM"); |
| 591 | addLazyPathDependenciesOnly(m, object); | |
| 592 | 438 | } |
| 593 | 439 | |
| 594 | 440 | pub fn addObject(m: *Module, object: *Step.Compile) void { |
| ... | ... | @@ -604,51 +450,43 @@ pub fn linkLibrary(m: *Module, library: *Step.Compile) void { |
| 604 | 450 | pub fn addAfterIncludePath(m: *Module, lazy_path: LazyPath) void { |
| 605 | 451 | const b = m.owner; |
| 606 | 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 | 455 | pub fn addSystemIncludePath(m: *Module, lazy_path: LazyPath) void { |
| 611 | 456 | const b = m.owner; |
| 612 | 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 | 460 | pub fn addIncludePath(m: *Module, lazy_path: LazyPath) void { |
| 617 | 461 | const b = m.owner; |
| 618 | 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 | 465 | pub fn addConfigHeader(m: *Module, config_header: *Step.ConfigHeader) void { |
| 623 | 466 | const allocator = m.owner.allocator; |
| 624 | 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 | 470 | pub fn addSystemFrameworkPath(m: *Module, directory_path: LazyPath) void { |
| 629 | 471 | const b = m.owner; |
| 630 | 472 | m.include_dirs.append(b.allocator, .{ .framework_path_system = directory_path.dupe(b) }) catch |
| 631 | 473 | @panic("OOM"); |
| 632 | addLazyPathDependenciesOnly(m, directory_path); | |
| 633 | 474 | } |
| 634 | 475 | |
| 635 | 476 | pub fn addFrameworkPath(m: *Module, directory_path: LazyPath) void { |
| 636 | 477 | const b = m.owner; |
| 637 | 478 | m.include_dirs.append(b.allocator, .{ .framework_path = directory_path.dupe(b) }) catch |
| 638 | 479 | @panic("OOM"); |
| 639 | addLazyPathDependenciesOnly(m, directory_path); | |
| 640 | 480 | } |
| 641 | 481 | |
| 642 | 482 | pub fn addLibraryPath(m: *Module, directory_path: LazyPath) void { |
| 643 | 483 | const b = m.owner; |
| 644 | 484 | m.lib_paths.append(b.allocator, directory_path.dupe(b)) catch @panic("OOM"); |
| 645 | addLazyPathDependenciesOnly(m, directory_path); | |
| 646 | 485 | } |
| 647 | 486 | |
| 648 | 487 | pub fn addRPath(m: *Module, directory_path: LazyPath) void { |
| 649 | 488 | const b = m.owner; |
| 650 | 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 | 492 | pub fn addRPathSpecial(m: *Module, bytes: []const u8) void { |
| ... | ... | @@ -772,7 +610,6 @@ fn addFlag( |
| 772 | 610 | fn linkLibraryOrObject(m: *Module, other: *Step.Compile) void { |
| 773 | 611 | const allocator = m.owner.allocator; |
| 774 | 612 | _ = other.getEmittedBin(); // Indicate there is a dependency on the outputted binary. |
| 775 | addStepDependenciesOnly(m, &other.step); | |
| 776 | 613 | |
| 777 | 614 | if (other.rootModuleTarget().os.tag == .windows and other.isDynamicLibrary()) { |
| 778 | 615 | _ = other.getEmittedImplib(); // Indicate dependency on the outputted implib. |
| ... | ... | @@ -780,8 +617,6 @@ fn linkLibraryOrObject(m: *Module, other: *Step.Compile) void { |
| 780 | 617 | |
| 781 | 618 | m.link_objects.append(allocator, .{ .other_step = other }) catch @panic("OOM"); |
| 782 | 619 | m.include_dirs.append(allocator, .{ .other_step = other }) catch @panic("OOM"); |
| 783 | ||
| 784 | addLazyPathDependenciesOnly(m, other.getEmittedIncludeTree()); | |
| 785 | 620 | } |
| 786 | 621 | |
| 787 | 622 | fn requireKnownTarget(m: *Module) std.Target { |
| ... | ... | @@ -790,6 +625,46 @@ fn requireKnownTarget(m: *Module) std.Target { |
| 790 | 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 | 668 | const Module = @This(); |
| 794 | 669 | const std = @import("std"); |
| 795 | 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 | 22 | pub const base_id: Step.Id = .compile; |
| 23 | 23 | |
| 24 | 24 | step: Step, |
| 25 | root_module: Module, | |
| 25 | root_module: *Module, | |
| 26 | 26 | |
| 27 | 27 | name: []const u8, |
| 28 | 28 | linker_script: ?LazyPath = null, |
| ... | ... | @@ -262,7 +262,7 @@ pub const Entry = union(enum) { |
| 262 | 262 | |
| 263 | 263 | pub const Options = struct { |
| 264 | 264 | name: []const u8, |
| 265 | root_module: Module.CreateOptions, | |
| 265 | root_module: *Module, | |
| 266 | 266 | kind: Kind, |
| 267 | 267 | linkage: ?std.builtin.LinkMode = null, |
| 268 | 268 | version: ?std.SemanticVersion = null, |
| ... | ... | @@ -359,7 +359,8 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 359 | 359 | else |
| 360 | 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 | 364 | const target = resolved_target.result; |
| 364 | 365 | |
| 365 | 366 | const step_name = owner.fmt("{s} {s}{s} {s}", .{ |
| ... | ... | @@ -388,7 +389,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 388 | 389 | |
| 389 | 390 | const compile = owner.allocator.create(Compile) catch @panic("OOM"); |
| 390 | 391 | compile.* = .{ |
| 391 | .root_module = undefined, | |
| 392 | .root_module = options.root_module, | |
| 392 | 393 | .verbose_link = false, |
| 393 | 394 | .verbose_cc = false, |
| 394 | 395 | .linkage = options.linkage, |
| ... | ... | @@ -432,8 +433,6 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 432 | 433 | .zig_process = null, |
| 433 | 434 | }; |
| 434 | 435 | |
| 435 | compile.root_module.init(owner, options.root_module, compile); | |
| 436 | ||
| 437 | 436 | if (options.zig_lib_dir) |lp| { |
| 438 | 437 | compile.zig_lib_dir = lp.dupe(compile.step.owner); |
| 439 | 438 | lp.addStepDependencies(&compile.step); |
| ... | ... | @@ -583,9 +582,6 @@ pub fn checkObject(compile: *Compile) *Step.CheckObject { |
| 583 | 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 | 585 | pub fn setLinkerScript(compile: *Compile, source: LazyPath) void { |
| 590 | 586 | const b = compile.step.owner; |
| 591 | 587 | compile.linker_script = source.dupe(b); |
| ... | ... | @@ -609,16 +605,17 @@ pub fn dependsOnSystemLibrary(compile: *const Compile, name: []const u8) bool { |
| 609 | 605 | var is_linking_libc = false; |
| 610 | 606 | var is_linking_libcpp = false; |
| 611 | 607 | |
| 612 | var dep_it = compile.root_module.iterateDependencies(compile, true); | |
| 613 | while (dep_it.next()) |module| { | |
| 614 | for (module.link_objects.items) |link_object| { | |
| 615 | switch (link_object) { | |
| 616 | .system_lib => |lib| if (mem.eql(u8, lib.name, name)) return true, | |
| 617 | else => continue, | |
| 608 | for (compile.getCompileDependencies(true)) |some_compile| { | |
| 609 | for (some_compile.root_module.getGraph().modules) |mod| { | |
| 610 | for (mod.link_objects.items) |lo| { | |
| 611 | switch (lo) { | |
| 612 | .system_lib => |lib| if (mem.eql(u8, lib.name, name)) return true, | |
| 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 | 621 | const target = compile.rootModuleTarget(); |
| ... | ... | @@ -675,11 +672,6 @@ pub fn linkLibCpp(compile: *Compile) void { |
| 675 | 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 | 675 | const PkgConfigResult = struct { |
| 684 | 676 | cflags: []const []const u8, |
| 685 | 677 | libs: []const []const u8, |
| ... | ... | @@ -805,16 +797,6 @@ pub fn linkFramework(c: *Compile, name: []const u8) void { |
| 805 | 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 | 800 | /// Handy when you have many C/C++ source files and want them all to have the same flags. |
| 819 | 801 | pub fn addCSourceFiles(compile: *Compile, options: Module.AddCSourceFilesOptions) void { |
| 820 | 802 | compile.root_module.addCSourceFiles(options); |
| ... | ... | @@ -978,23 +960,22 @@ const CliNamedModules = struct { |
| 978 | 960 | .modules = .{}, |
| 979 | 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().?; | |
| 984 | assert(root_module == item.module); | |
| 965 | assert(graph.modules[0] == root_module); | |
| 985 | 966 | try compile.modules.put(arena, root_module, {}); |
| 986 | 967 | try compile.names.put(arena, "root", {}); |
| 987 | 968 | } |
| 988 | while (dep_it.next()) |item| { | |
| 989 | var name = item.name; | |
| 969 | for (graph.modules[1..], graph.names[1..]) |mod, orig_name| { | |
| 970 | var name = orig_name; | |
| 990 | 971 | var n: usize = 0; |
| 991 | 972 | while (true) { |
| 992 | 973 | const gop = try compile.names.getOrPut(arena, name); |
| 993 | 974 | if (!gop.found_existing) { |
| 994 | try compile.modules.putNoClobber(arena, item.module, {}); | |
| 975 | try compile.modules.putNoClobber(arena, mod, {}); | |
| 995 | 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 | 979 | n += 1; |
| 999 | 980 | } |
| 1000 | 981 | } |
| ... | ... | @@ -1097,279 +1078,278 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 { |
| 1097 | 1078 | // emitted if there is nothing to link. |
| 1098 | 1079 | var total_linker_objects: usize = @intFromBool(compile.root_module.root_source_file != null); |
| 1099 | 1080 | |
| 1100 | { | |
| 1101 | // Fully recursive iteration including dynamic libraries to detect | |
| 1102 | // libc and libc++ linkage. | |
| 1103 | var dep_it = compile.root_module.iterateDependencies(compile, true); | |
| 1104 | while (dep_it.next()) |key| { | |
| 1105 | if (key.module.link_libc == true) compile.is_linking_libc = true; | |
| 1106 | if (key.module.link_libcpp == true) compile.is_linking_libcpp = true; | |
| 1081 | // Fully recursive iteration including dynamic libraries to detect | |
| 1082 | // libc and libc++ linkage. | |
| 1083 | for (compile.getCompileDependencies(true)) |some_compile| { | |
| 1084 | for (some_compile.root_module.getGraph().modules) |mod| { | |
| 1085 | if (mod.link_libc == true) compile.is_linking_libc = true; | |
| 1086 | if (mod.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 | 1092 | // For this loop, don't chase dynamic libraries because their link |
| 1113 | 1093 | // objects are already linked. |
| 1114 | var dep_it = compile.root_module.iterateDependencies(compile, false); | |
| 1115 | ||
| 1116 | while (dep_it.next()) |dep| { | |
| 1117 | // While walking transitive dependencies, if a given link object is | |
| 1118 | // already included in a library, it should not redundantly be | |
| 1119 | // placed on the linker line of the dependee. | |
| 1120 | const my_responsibility = dep.compile.? == compile; | |
| 1121 | const already_linked = !my_responsibility and dep.compile.?.isDynamicLibrary(); | |
| 1122 | ||
| 1123 | // Inherit dependencies on darwin frameworks. | |
| 1124 | if (!already_linked) { | |
| 1125 | for (dep.module.frameworks.keys(), dep.module.frameworks.values()) |name, info| { | |
| 1126 | try frameworks.put(arena, name, info); | |
| 1094 | for (compile.getCompileDependencies(false)) |dep_compile| { | |
| 1095 | for (dep_compile.root_module.getGraph().modules) |mod| { | |
| 1096 | // While walking transitive dependencies, if a given link object is | |
| 1097 | // already included in a library, it should not redundantly be | |
| 1098 | // placed on the linker line of the dependee. | |
| 1099 | const my_responsibility = dep_compile == compile; | |
| 1100 | const already_linked = !my_responsibility and dep_compile.isDynamicLibrary(); | |
| 1101 | ||
| 1102 | // Inherit dependencies on darwin frameworks. | |
| 1103 | if (!already_linked) { | |
| 1104 | for (mod.frameworks.keys(), mod.frameworks.values()) |name, info| { | |
| 1105 | try frameworks.put(arena, name, info); | |
| 1106 | } | |
| 1127 | 1107 | } |
| 1128 | } | |
| 1129 | 1108 | |
| 1130 | // Inherit dependencies on system libraries and static libraries. | |
| 1131 | for (dep.module.link_objects.items) |link_object| { | |
| 1132 | switch (link_object) { | |
| 1133 | .static_path => |static_path| { | |
| 1134 | if (my_responsibility) { | |
| 1135 | try zig_args.append(static_path.getPath2(dep.module.owner, step)); | |
| 1136 | total_linker_objects += 1; | |
| 1137 | } | |
| 1138 | }, | |
| 1139 | .system_lib => |system_lib| { | |
| 1140 | const system_lib_gop = try seen_system_libs.getOrPut(arena, system_lib.name); | |
| 1141 | if (system_lib_gop.found_existing) { | |
| 1142 | try zig_args.appendSlice(system_lib_gop.value_ptr.*); | |
| 1143 | continue; | |
| 1144 | } else { | |
| 1145 | 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 | }, | |
| 1109 | // Inherit dependencies on system libraries and static libraries. | |
| 1110 | for (mod.link_objects.items) |link_object| { | |
| 1111 | switch (link_object) { | |
| 1112 | .static_path => |static_path| { | |
| 1113 | if (my_responsibility) { | |
| 1114 | try zig_args.append(static_path.getPath2(mod.owner, step)); | |
| 1115 | total_linker_objects += 1; | |
| 1116 | } | |
| 1117 | }, | |
| 1118 | .system_lib => |system_lib| { | |
| 1119 | const system_lib_gop = try seen_system_libs.getOrPut(arena, system_lib.name); | |
| 1120 | if (system_lib_gop.found_existing) { | |
| 1121 | try zig_args.appendSlice(system_lib_gop.value_ptr.*); | |
| 1122 | continue; | |
| 1123 | } else { | |
| 1124 | system_lib_gop.value_ptr.* = &.{}; | |
| 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: { | |
| 1174 | if (system_lib.needed) break :prefix "-needed-l"; | |
| 1175 | if (system_lib.weak) break :prefix "-weak-l"; | |
| 1176 | break :prefix "-l"; | |
| 1177 | }; | |
| 1178 | switch (system_lib.use_pkg_config) { | |
| 1179 | .no => try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })), | |
| 1180 | .yes, .force => { | |
| 1181 | if (compile.runPkgConfig(system_lib.name)) |result| { | |
| 1182 | try zig_args.appendSlice(result.cflags); | |
| 1183 | try zig_args.appendSlice(result.libs); | |
| 1184 | try seen_system_libs.put(arena, system_lib.name, result.cflags); | |
| 1185 | } else |err| switch (err) { | |
| 1186 | error.PkgConfigInvalidOutput, | |
| 1187 | error.PkgConfigCrashed, | |
| 1188 | error.PkgConfigFailed, | |
| 1189 | error.PkgConfigNotInstalled, | |
| 1190 | error.PackageNotFound, | |
| 1191 | => switch (system_lib.use_pkg_config) { | |
| 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, | |
| 1127 | if (already_linked) | |
| 1128 | continue; | |
| 1129 | ||
| 1130 | if ((system_lib.search_strategy != prev_search_strategy or | |
| 1131 | system_lib.preferred_link_mode != prev_preferred_link_mode) and | |
| 1132 | compile.linkage != .static) | |
| 1133 | { | |
| 1134 | switch (system_lib.search_strategy) { | |
| 1135 | .no_fallback => switch (system_lib.preferred_link_mode) { | |
| 1136 | .dynamic => try zig_args.append("-search_dylibs_only"), | |
| 1137 | .static => try zig_args.append("-search_static_only"), | |
| 1138 | }, | |
| 1139 | .paths_first => switch (system_lib.preferred_link_mode) { | |
| 1140 | .dynamic => try zig_args.append("-search_paths_first"), | |
| 1141 | .static => try zig_args.append("-search_paths_first_static"), | |
| 1142 | }, | |
| 1143 | .mode_first => switch (system_lib.preferred_link_mode) { | |
| 1144 | .dynamic => try zig_args.append("-search_dylibs_first"), | |
| 1145 | .static => try zig_args.append("-search_static_first"), | |
| 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. | |
| 1233 | // For everything else, we directly link | |
| 1234 | // against the library file. | |
| 1235 | const full_path_lib = if (other_produces_implib) | |
| 1236 | other.getGeneratedFilePath("generated_implib", &compile.step) | |
| 1237 | else | |
| 1238 | other.getGeneratedFilePath("generated_bin", &compile.step); | |
| 1152 | const prefix: []const u8 = prefix: { | |
| 1153 | if (system_lib.needed) break :prefix "-needed-l"; | |
| 1154 | if (system_lib.weak) break :prefix "-weak-l"; | |
| 1155 | break :prefix "-l"; | |
| 1156 | }; | |
| 1157 | switch (system_lib.use_pkg_config) { | |
| 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); | |
| 1241 | total_linker_objects += 1; | |
| 1185 | else => |e| return e, | |
| 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 | |
| 1244 | compile.rootModuleTarget().os.tag != .windows) | |
| 1245 | { | |
| 1246 | if (fs.path.dirname(full_path_lib)) |dirname| { | |
| 1247 | try zig_args.append("-rpath"); | |
| 1248 | try zig_args.append(dirname); | |
| 1206 | if (compile.isStaticLibrary() and other_is_static) { | |
| 1207 | // Avoid putting a static library inside a static library. | |
| 1208 | break :l; | |
| 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) { | |
| 1258 | try zig_args.append("-cflags"); | |
| 1259 | try zig_args.append("--"); | |
| 1260 | prev_has_cflags = false; | |
| 1261 | } | |
| 1262 | try zig_args.append(asm_file.getPath2(dep.module.owner, step)); | |
| 1263 | total_linker_objects += 1; | |
| 1264 | }, | |
| 1211 | // For DLLs, we must link against the implib. | |
| 1212 | // For everything else, we directly link | |
| 1213 | // against the library file. | |
| 1214 | const full_path_lib = if (other_produces_implib) | |
| 1215 | other.getGeneratedFilePath("generated_implib", &compile.step) | |
| 1216 | else | |
| 1217 | other.getGeneratedFilePath("generated_bin", &compile.step); | |
| 1265 | 1218 | |
| 1266 | .c_source_file => |c_source_file| l: { | |
| 1267 | if (!my_responsibility) break :l; | |
| 1219 | try zig_args.append(full_path_lib); | |
| 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 | 1236 | if (prev_has_cflags) { |
| 1271 | 1237 | try zig_args.append("-cflags"); |
| 1272 | 1238 | try zig_args.append("--"); |
| 1273 | 1239 | prev_has_cflags = false; |
| 1274 | 1240 | } |
| 1275 | } else { | |
| 1276 | try zig_args.append("-cflags"); | |
| 1277 | for (c_source_file.flags) |arg| { | |
| 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 | }, | |
| 1241 | try zig_args.append(asm_file.getPath2(mod.owner, step)); | |
| 1242 | total_linker_objects += 1; | |
| 1243 | }, | |
| 1286 | 1244 | |
| 1287 | .c_source_files => |c_source_files| l: { | |
| 1288 | if (!my_responsibility) break :l; | |
| 1245 | .c_source_file => |c_source_file| l: { | |
| 1246 | if (!my_responsibility) break :l; | |
| 1289 | 1247 | |
| 1290 | if (c_source_files.flags.len == 0) { | |
| 1291 | if (prev_has_cflags) { | |
| 1248 | if (c_source_file.flags.len == 0) { | |
| 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 | 1255 | try zig_args.append("-cflags"); |
| 1256 | for (c_source_file.flags) |arg| { | |
| 1257 | try zig_args.append(arg); | |
| 1258 | } | |
| 1293 | 1259 | try zig_args.append("--"); |
| 1294 | prev_has_cflags = false; | |
| 1260 | prev_has_cflags = true; | |
| 1295 | 1261 | } |
| 1296 | } else { | |
| 1297 | try zig_args.append("-cflags"); | |
| 1298 | for (c_source_files.flags) |flag| { | |
| 1299 | try zig_args.append(flag); | |
| 1262 | try zig_args.append(c_source_file.file.getPath2(mod.owner, step)); | |
| 1263 | total_linker_objects += 1; | |
| 1264 | }, | |
| 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); | |
| 1306 | for (c_source_files.files) |file| { | |
| 1307 | try zig_args.append(b.pathJoin(&.{ root_path, file })); | |
| 1308 | } | |
| 1284 | const root_path = c_source_files.root.getPath2(mod.owner, step); | |
| 1285 | for (c_source_files.files) |file| { | |
| 1286 | try zig_args.append(b.pathJoin(&.{ root_path, file })); | |
| 1287 | } | |
| 1309 | 1288 | |
| 1310 | total_linker_objects += c_source_files.files.len; | |
| 1311 | }, | |
| 1289 | total_linker_objects += c_source_files.files.len; | |
| 1290 | }, | |
| 1312 | 1291 | |
| 1313 | .win32_resource_file => |rc_source_file| l: { | |
| 1314 | if (!my_responsibility) break :l; | |
| 1292 | .win32_resource_file => |rc_source_file| 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) { | |
| 1317 | if (prev_has_rcflags) { | |
| 1295 | if (rc_source_file.flags.len == 0 and rc_source_file.include_paths.len == 0) { | |
| 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 | 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 | 1310 | try zig_args.append("--"); |
| 1320 | prev_has_rcflags = false; | |
| 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)); | |
| 1311 | prev_has_rcflags = true; | |
| 1330 | 1312 | } |
| 1331 | try zig_args.append("--"); | |
| 1332 | prev_has_rcflags = true; | |
| 1333 | } | |
| 1334 | try zig_args.append(rc_source_file.file.getPath2(dep.module.owner, step)); | |
| 1335 | total_linker_objects += 1; | |
| 1336 | }, | |
| 1313 | try zig_args.append(rc_source_file.file.getPath2(mod.owner, step)); | |
| 1314 | total_linker_objects += 1; | |
| 1315 | }, | |
| 1316 | } | |
| 1337 | 1317 | } |
| 1338 | } | |
| 1339 | 1318 | |
| 1340 | // 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 | |
| 1342 | // this compilation. | |
| 1343 | if (!my_responsibility) continue; | |
| 1344 | if (cli_named_modules.modules.getIndex(dep.module)) |module_cli_index| { | |
| 1345 | const module_cli_name = cli_named_modules.names.keys()[module_cli_index]; | |
| 1346 | try dep.module.appendZigProcessFlags(&zig_args, step); | |
| 1347 | ||
| 1348 | // --dep arguments | |
| 1349 | try zig_args.ensureUnusedCapacity(dep.module.import_table.count() * 2); | |
| 1350 | for (dep.module.import_table.keys(), dep.module.import_table.values()) |name, import| { | |
| 1351 | const import_index = cli_named_modules.modules.getIndex(import).?; | |
| 1352 | const import_cli_name = cli_named_modules.names.keys()[import_index]; | |
| 1353 | zig_args.appendAssumeCapacity("--dep"); | |
| 1354 | if (std.mem.eql(u8, import_cli_name, name)) { | |
| 1355 | zig_args.appendAssumeCapacity(import_cli_name); | |
| 1356 | } else { | |
| 1357 | zig_args.appendAssumeCapacity(b.fmt("{s}={s}", .{ name, import_cli_name })); | |
| 1319 | // We need to emit the --mod argument here so that the above link objects | |
| 1320 | // have the correct parent module, but only if the module is part of | |
| 1321 | // this compilation. | |
| 1322 | if (!my_responsibility) continue; | |
| 1323 | if (cli_named_modules.modules.getIndex(mod)) |module_cli_index| { | |
| 1324 | const module_cli_name = cli_named_modules.names.keys()[module_cli_index]; | |
| 1325 | try mod.appendZigProcessFlags(&zig_args, step); | |
| 1326 | ||
| 1327 | // --dep arguments | |
| 1328 | try zig_args.ensureUnusedCapacity(mod.import_table.count() * 2); | |
| 1329 | for (mod.import_table.keys(), mod.import_table.values()) |name, import| { | |
| 1330 | const import_index = cli_named_modules.modules.getIndex(import).?; | |
| 1331 | const import_cli_name = cli_named_modules.names.keys()[import_index]; | |
| 1332 | zig_args.appendAssumeCapacity("--dep"); | |
| 1333 | if (std.mem.eql(u8, import_cli_name, name)) { | |
| 1334 | zig_args.appendAssumeCapacity(import_cli_name); | |
| 1335 | } else { | |
| 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 | |
| 1362 | // implies the existence of a Zig compilation unit based on | |
| 1363 | // 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 | |
| 1365 | // perhaps a set of linker objects, or C source files instead. | |
| 1366 | // Linker objects are added to the CLI globally, while C source | |
| 1367 | // files must have a module parent. | |
| 1368 | if (dep.module.root_source_file) |lp| { | |
| 1369 | const src = lp.getPath2(dep.module.owner, step); | |
| 1370 | try zig_args.append(b.fmt("-M{s}={s}", .{ module_cli_name, src })); | |
| 1371 | } else if (moduleNeedsCliArg(dep.module)) { | |
| 1372 | try zig_args.append(b.fmt("-M{s}", .{module_cli_name})); | |
| 1340 | // When the CLI sees a -M argument, it determines whether it | |
| 1341 | // implies the existence of a Zig compilation unit based on | |
| 1342 | // whether there is a root source file. If there is no root | |
| 1343 | // source file, then this is not a zig compilation unit - it is | |
| 1344 | // perhaps a set of linker objects, or C source files instead. | |
| 1345 | // Linker objects are added to the CLI globally, while C source | |
| 1346 | // files must have a module parent. | |
| 1347 | if (mod.root_source_file) |lp| { | |
| 1348 | const src = lp.getPath2(mod.owner, step); | |
| 1349 | try zig_args.append(b.fmt("-M{s}={s}", .{ module_cli_name, src })); | |
| 1350 | } else if (moduleNeedsCliArg(mod)) { | |
| 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 | 2061 | else => continue, |
| 2082 | 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 | 135 | return objcopy; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | /// deprecated: use getOutput | |
| 139 | pub const getOutputSource = getOutput; | |
| 140 | ||
| 141 | 138 | pub fn getOutput(objcopy: *const ObjCopy) std.Build.LazyPath { |
| 142 | 139 | return .{ .generated = .{ .file = &objcopy.output_file } }; |
| 143 | 140 | } |
lib/std/Build/Step/Options.zig-8| ... | ... | @@ -390,20 +390,12 @@ pub fn addOptionPath( |
| 390 | 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 | 393 | pub fn createModule(options: *Options) *std.Build.Module { |
| 399 | 394 | return options.step.owner.createModule(.{ |
| 400 | 395 | .root_source_file = options.getOutput(), |
| 401 | 396 | }); |
| 402 | 397 | } |
| 403 | 398 | |
| 404 | /// deprecated: use `getOutput` | |
| 405 | pub const getSource = getOutput; | |
| 406 | ||
| 407 | 399 | /// Returns the main artifact of this Build Step which is a Zig source file |
| 408 | 400 | /// generated from the key-value pairs of the Options. |
| 409 | 401 | pub fn getOutput(options: *Options) LazyPath { |
lib/std/Build/Step/Run.zig+6-22| ... | ... | @@ -43,9 +43,6 @@ stdio: StdIo, |
| 43 | 43 | /// It should be only set using `setStdIn`. |
| 44 | 44 | stdin: StdIn, |
| 45 | 45 | |
| 46 | /// Deprecated: use `addFileInput` | |
| 47 | extra_file_dependencies: []const []const u8, | |
| 48 | ||
| 49 | 46 | /// Additional input files that, when modified, indicate that the Run step |
| 50 | 47 | /// should be re-executed. |
| 51 | 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 | 175 | .disable_zig_progress = false, |
| 179 | 176 | .stdio = .infer_from_args, |
| 180 | 177 | .stdin = .none, |
| 181 | .extra_file_dependencies = &.{}, | |
| 182 | 178 | .file_inputs = .{}, |
| 183 | 179 | .rename_step_with_output_arg = true, |
| 184 | 180 | .skip_foreign_checks = false, |
| ... | ... | @@ -364,16 +360,10 @@ pub fn addPrefixedOutputDirectoryArg( |
| 364 | 360 | return .{ .generated = .{ .file = &output.generated_file } }; |
| 365 | 361 | } |
| 366 | 362 | |
| 367 | /// deprecated: use `addDirectoryArg` | |
| 368 | pub const addDirectorySourceArg = addDirectoryArg; | |
| 369 | ||
| 370 | 363 | pub fn addDirectoryArg(run: *Run, directory_source: std.Build.LazyPath) void { |
| 371 | 364 | run.addPrefixedDirectoryArg("", directory_source); |
| 372 | 365 | } |
| 373 | 366 | |
| 374 | // deprecated: use `addPrefixedDirectoryArg` | |
| 375 | pub const addPrefixedDirectorySourceArg = addPrefixedDirectoryArg; | |
| 376 | ||
| 377 | 367 | pub fn addPrefixedDirectoryArg(run: *Run, prefix: []const u8, directory_source: std.Build.LazyPath) void { |
| 378 | 368 | const b = run.step.owner; |
| 379 | 369 | |
| ... | ... | @@ -698,9 +688,6 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 698 | 688 | |
| 699 | 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 | 691 | for (run.file_inputs.items) |lazy_path| { |
| 705 | 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 | 1719 | |
| 1733 | 1720 | fn addPathForDynLibs(run: *Run, artifact: *Step.Compile) void { |
| 1734 | 1721 | const b = run.step.owner; |
| 1735 | var it = artifact.root_module.iterateDependencies(artifact, true); | |
| 1736 | while (it.next()) |item| { | |
| 1737 | const other = item.compile.?; | |
| 1738 | if (item.module == &other.root_module) { | |
| 1739 | if (item.module.resolved_target.?.result.os.tag == .windows and | |
| 1740 | other.isDynamicLibrary()) | |
| 1741 | { | |
| 1742 | addPathDir(run, fs.path.dirname(other.getEmittedBin().getPath2(b, &run.step)).?); | |
| 1743 | } | |
| 1722 | const compiles = artifact.getCompileDependencies(true); | |
| 1723 | for (compiles) |compile| { | |
| 1724 | if (compile.root_module.resolved_target.?.result.os.tag == .windows and | |
| 1725 | compile.isDynamicLibrary()) | |
| 1726 | { | |
| 1727 | addPathDir(run, fs.path.dirname(compile.getEmittedBin().getPath2(b, &run.step)).?); | |
| 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 | 63 | return .{ .generated = .{ .file = &translate_c.output_file } }; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | /// Deprecated: use `createModule` or `addModule` with `std.Build.addExecutable` instead. | |
| 66 | 67 | /// Creates a step to build an executable from the translated source. |
| 67 | 68 | pub fn addExecutable(translate_c: *TranslateC, options: AddExecutableOptions) *Step.Compile { |
| 68 | 69 | return translate_c.step.owner.addExecutable(.{ |
| ... | ... | @@ -81,6 +82,9 @@ pub fn addExecutable(translate_c: *TranslateC, options: AddExecutableOptions) *S |
| 81 | 82 | pub fn addModule(translate_c: *TranslateC, name: []const u8) *std.Build.Module { |
| 82 | 83 | return translate_c.step.owner.addModule(name, .{ |
| 83 | 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 | 6 | |
| 7 | 7 | const exe = b.addExecutable(.{ |
| 8 | 8 | .name = "bss", |
| 9 | .root_source_file = b.path("main.zig"), | |
| 10 | .target = b.graph.host, | |
| 11 | .optimize = .Debug, | |
| 9 | .root_module = b.createModule(.{ | |
| 10 | .root_source_file = b.path("main.zig"), | |
| 11 | .target = b.graph.host, | |
| 12 | .optimize = .Debug, | |
| 13 | }), | |
| 12 | 14 | }); |
| 13 | 15 | |
| 14 | 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 | 13 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 14 | 14 | const lib_a = b.addStaticLibrary(.{ |
| 15 | 15 | .name = "a", |
| 16 | .optimize = optimize, | |
| 17 | .target = b.graph.host, | |
| 16 | .root_module = b.createModule(.{ | |
| 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 | 23 | .files = &.{ "c.c", "a.c", "b.c" }, |
| 21 | 24 | .flags = &.{"-fcommon"}, |
| 22 | 25 | }); |
| 23 | 26 | |
| 24 | 27 | const test_exe = b.addTest(.{ |
| 25 | .root_source_file = b.path("main.zig"), | |
| 26 | .optimize = optimize, | |
| 28 | .root_module = b.createModule(.{ | |
| 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 | 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 | 13 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 14 | 14 | const lib_a = b.addStaticLibrary(.{ |
| 15 | 15 | .name = "a", |
| 16 | .optimize = optimize, | |
| 17 | .target = b.graph.host, | |
| 16 | .root_module = b.createModule(.{ | |
| 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 | 23 | .files = &.{"a.c"}, |
| 21 | 24 | .flags = &.{"-fcommon"}, |
| 22 | 25 | }); |
| 23 | 26 | |
| 24 | 27 | const test_exe = b.addTest(.{ |
| 25 | .root_source_file = b.path("main.zig"), | |
| 26 | .optimize = optimize, | |
| 28 | .root_module = b.createModule(.{ | |
| 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 | 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 | 14 | for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| { |
| 15 | 15 | const exe = b.addExecutable(.{ |
| 16 | 16 | .name = t, |
| 17 | .target = b.resolveTargetQuery(std.Target.Query.parse( | |
| 18 | .{ .arch_os_abi = t }, | |
| 19 | ) catch unreachable), | |
| 17 | .root_module = b.createModule(.{ | |
| 18 | .root_source_file = null, | |
| 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") }); | |
| 22 | exe.linkLibC(); | |
| 25 | exe.root_module.addCSourceFile(.{ .file = b.path("main.c") }); | |
| 23 | 26 | // TODO: actually test the output |
| 24 | 27 | _ = exe.getEmittedBin(); |
| 25 | 28 | test_step.dependOn(&exe.step); |
| ... | ... | @@ -53,10 +56,13 @@ pub fn build(b: *std.Build) void { |
| 53 | 56 | |
| 54 | 57 | const exe = b.addExecutable(.{ |
| 55 | 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") }); | |
| 59 | exe.linkLibC(); | |
| 65 | exe.root_module.addCSourceFile(.{ .file = b.path("glibc_runtime_check.c") }); | |
| 60 | 66 | |
| 61 | 67 | // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig |
| 62 | 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 | 155 | |
| 150 | 156 | const exe = b.addExecutable(.{ |
| 151 | 157 | .name = t, |
| 152 | .root_source_file = b.path("glibc_runtime_check.zig"), | |
| 153 | .target = target, | |
| 158 | .root_module = b.createModule(.{ | |
| 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 | 165 | // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig |
| 158 | 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 | 13 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 14 | 14 | const lib_a = b.addStaticLibrary(.{ |
| 15 | 15 | .name = "a", |
| 16 | .optimize = optimize, | |
| 17 | .target = b.graph.host, | |
| 16 | .root_module = b.createModule(.{ | |
| 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{} }); | |
| 20 | lib_a.addIncludePath(b.path(".")); | |
| 22 | lib_a.root_module.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} }); | |
| 23 | lib_a.root_module.addIncludePath(b.path(".")); | |
| 21 | 24 | |
| 22 | 25 | const lib_b = b.addStaticLibrary(.{ |
| 23 | 26 | .name = "b", |
| 24 | .optimize = optimize, | |
| 25 | .target = b.graph.host, | |
| 27 | .root_module = b.createModule(.{ | |
| 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{} }); | |
| 28 | lib_b.addIncludePath(b.path(".")); | |
| 33 | lib_b.root_module.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} }); | |
| 34 | lib_b.root_module.addIncludePath(b.path(".")); | |
| 29 | 35 | |
| 30 | 36 | const test_exe = b.addTest(.{ |
| 31 | .root_source_file = b.path("main.zig"), | |
| 32 | .optimize = optimize, | |
| 37 | .root_module = b.createModule(.{ | |
| 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); | |
| 35 | test_exe.linkLibrary(lib_b); | |
| 36 | test_exe.addIncludePath(b.path(".")); | |
| 43 | test_exe.root_module.linkLibrary(lib_a); | |
| 44 | test_exe.root_module.linkLibrary(lib_b); | |
| 45 | test_exe.root_module.addIncludePath(b.path(".")); | |
| 37 | 46 | |
| 38 | 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 | 47 | }; |
| 48 | 48 | |
| 49 | 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 | 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 | 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 | 76 | pub fn addSharedLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile { |
| 62 | return addCompileStep(b, base, overlay, .shared_lib); | |
| 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, .{ | |
| 77 | return b.addSharedLibrary(.{ | |
| 72 | 78 | .name = overlay.name, |
| 73 | .root_module = .{ | |
| 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 | }, | |
| 79 | .root_module = createModule(b, base, overlay), | |
| 84 | 80 | .use_llvm = base.use_llvm, |
| 85 | 81 | .use_lld = base.use_lld, |
| 86 | .kind = switch (kind) { | |
| 87 | .exe => .exe, | |
| 88 | .obj => .obj, | |
| 89 | .shared_lib, .static_lib => .lib, | |
| 90 | }, | |
| 91 | .linkage = switch (kind) { | |
| 92 | .exe, .obj => null, | |
| 93 | .shared_lib => .dynamic, | |
| 94 | .static_lib => .static, | |
| 82 | }); | |
| 83 | } | |
| 84 | ||
| 85 | fn createModule(b: *Build, base: Options, overlay: OverlayOptions) *Build.Module { | |
| 86 | const write_files = b.addWriteFiles(); | |
| 87 | ||
| 88 | const mod = b.createModule(.{ | |
| 89 | .target = base.target, | |
| 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 | 100 | if (overlay.objcpp_source_bytes) |bytes| { |
| 98 | compile_step.addCSourceFile(.{ | |
| 99 | .file = b.addWriteFiles().add("a.mm", bytes), | |
| 101 | mod.addCSourceFile(.{ | |
| 102 | .file = write_files.add("a.mm", bytes), | |
| 100 | 103 | .flags = overlay.objcpp_source_flags, |
| 101 | 104 | }); |
| 102 | 105 | } |
| 103 | 106 | if (overlay.objc_source_bytes) |bytes| { |
| 104 | compile_step.addCSourceFile(.{ | |
| 105 | .file = b.addWriteFiles().add("a.m", bytes), | |
| 107 | mod.addCSourceFile(.{ | |
| 108 | .file = write_files.add("a.m", bytes), | |
| 106 | 109 | .flags = overlay.objc_source_flags, |
| 107 | 110 | }); |
| 108 | 111 | } |
| 109 | 112 | if (overlay.cpp_source_bytes) |bytes| { |
| 110 | compile_step.addCSourceFile(.{ | |
| 111 | .file = b.addWriteFiles().add("a.cpp", bytes), | |
| 113 | mod.addCSourceFile(.{ | |
| 114 | .file = write_files.add("a.cpp", bytes), | |
| 112 | 115 | .flags = overlay.cpp_source_flags, |
| 113 | 116 | }); |
| 114 | 117 | } |
| 115 | 118 | if (overlay.c_source_bytes) |bytes| { |
| 116 | compile_step.addCSourceFile(.{ | |
| 117 | .file = b.addWriteFiles().add("a.c", bytes), | |
| 119 | mod.addCSourceFile(.{ | |
| 120 | .file = write_files.add("a.c", bytes), | |
| 118 | 121 | .flags = overlay.c_source_flags, |
| 119 | 122 | }); |
| 120 | 123 | } |
| 121 | 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 | 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 | 57 | { |
| 58 | 58 | const exe = b.addExecutable(.{ |
| 59 | 59 | .name = "test1", |
| 60 | .root_source_file = b.path("main.zig"), | |
| 61 | .optimize = optimize, | |
| 62 | .target = b.graph.host, | |
| 60 | .root_module = b.createModule(.{ | |
| 61 | .root_source_file = b.path("main.zig"), | |
| 62 | .optimize = optimize, | |
| 63 | .target = b.graph.host, | |
| 64 | }), | |
| 63 | 65 | }); |
| 64 | 66 | |
| 65 | 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 | 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 | 77 | |
| 76 | 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 | 88 | const lib_a = b.addStaticLibrary(.{ |
| 79 | 89 | .name = "test2_a", |
| 80 | .target = b.graph.host, | |
| 81 | .optimize = optimize, | |
| 90 | .root_module = mod_a, | |
| 82 | 91 | }); |
| 83 | 92 | const lib_b = b.addStaticLibrary(.{ |
| 84 | 93 | .name = "test2_b", |
| 85 | .target = b.graph.host, | |
| 86 | .optimize = optimize, | |
| 94 | .root_module = mod_b, | |
| 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 | 97 | const exe = b.addExecutable(.{ |
| 95 | 98 | .name = "test2", |
| 96 | .root_source_file = b.path("main.zig"), | |
| 97 | .target = b.graph.host, | |
| 98 | .optimize = optimize, | |
| 99 | .root_module = b.createModule(.{ | |
| 100 | .root_source_file = b.path("main.zig"), | |
| 101 | .target = b.graph.host, | |
| 102 | .optimize = optimize, | |
| 103 | }), | |
| 99 | 104 | }); |
| 100 | exe.linkLibrary(lib_a); | |
| 101 | exe.linkLibrary(lib_b); | |
| 105 | exe.root_module.linkLibrary(lib_a); | |
| 106 | exe.root_module.linkLibrary(lib_b); | |
| 102 | 107 | |
| 103 | 108 | const run_cmd = b.addRunArtifact(exe); |
| 104 | 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 | 114 | |
| 110 | 115 | // using static librairies and object files |
| 111 | 116 | { |
| 112 | const lib_a = b.addStaticLibrary(.{ | |
| 113 | .name = "test3_a", | |
| 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 | }); | |
| 117 | const mod_a = b.createModule(.{ .target = b.graph.host, .optimize = optimize }); | |
| 118 | const mod_b = b.createModule(.{ .target = b.graph.host, .optimize = optimize }); | |
| 122 | 119 | |
| 123 | 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 | 124 | const obj = b.addObject(.{ |
| 125 | 125 | .name = b.fmt("obj_{}", .{i}), |
| 126 | .target = b.graph.host, | |
| 127 | .optimize = optimize, | |
| 126 | .root_module = obj_mod, | |
| 128 | 127 | }); |
| 129 | obj.addCSourceFile(.{ .file = file, .flags = &flags }); | |
| 130 | 128 | |
| 131 | const lib = if (i & 1 == 0) lib_a else lib_b; | |
| 132 | lib.addObject(obj); | |
| 129 | const lib_mod = if (i & 1 == 0) mod_a else mod_b; | |
| 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 | 142 | const exe = b.addExecutable(.{ |
| 136 | 143 | .name = "test3", |
| 137 | .root_source_file = b.path("main.zig"), | |
| 138 | .target = b.graph.host, | |
| 139 | .optimize = optimize, | |
| 144 | .root_module = b.createModule(.{ | |
| 145 | .root_source_file = b.path("main.zig"), | |
| 146 | .target = b.graph.host, | |
| 147 | .optimize = optimize, | |
| 148 | }), | |
| 140 | 149 | }); |
| 141 | exe.linkLibrary(lib_a); | |
| 142 | exe.linkLibrary(lib_b); | |
| 150 | exe.root_module.linkLibrary(lib_a); | |
| 151 | exe.root_module.linkLibrary(lib_b); | |
| 143 | 152 | |
| 144 | 153 | const run_cmd = b.addRunArtifact(exe); |
| 145 | 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 | 17 | // and therefore link with its archive file. |
| 18 | 18 | const lib = b.addExecutable(.{ |
| 19 | 19 | .name = "main", |
| 20 | .root_source_file = b.path("main.zig"), | |
| 21 | .optimize = optimize, | |
| 22 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 23 | .strip = false, | |
| 20 | .root_module = b.createModule(.{ | |
| 21 | .root_source_file = b.path("main.zig"), | |
| 22 | .optimize = optimize, | |
| 23 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 24 | .strip = false, | |
| 25 | }), | |
| 24 | 26 | }); |
| 25 | 27 | lib.entry = .disabled; |
| 26 | 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 | 6 | // Library with explicitly set cpu features |
| 7 | 7 | const lib = b.addExecutable(.{ |
| 8 | 8 | .name = "lib", |
| 9 | .root_source_file = b.path("main.zig"), | |
| 10 | .optimize = .Debug, | |
| 11 | .target = b.resolveTargetQuery(.{ | |
| 12 | .cpu_arch = .wasm32, | |
| 13 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | |
| 14 | .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}), | |
| 15 | .os_tag = .freestanding, | |
| 9 | .root_module = b.createModule(.{ | |
| 10 | .root_source_file = b.path("main.zig"), | |
| 11 | .optimize = .Debug, | |
| 12 | .target = b.resolveTargetQuery(.{ | |
| 13 | .cpu_arch = .wasm32, | |
| 14 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | |
| 15 | .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}), | |
| 16 | .os_tag = .freestanding, | |
| 17 | }), | |
| 16 | 18 | }), |
| 17 | 19 | }); |
| 18 | 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 | 16 | { |
| 17 | 17 | const lib = b.addExecutable(.{ |
| 18 | 18 | .name = "lib", |
| 19 | .root_source_file = b.path("lib.zig"), | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 21 | .optimize = optimize_mode, | |
| 22 | .strip = false, | |
| 19 | .root_module = b.createModule(.{ | |
| 20 | .root_source_file = b.path("lib.zig"), | |
| 21 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 22 | .optimize = optimize_mode, | |
| 23 | .strip = false, | |
| 24 | }), | |
| 23 | 25 | }); |
| 24 | 26 | lib.entry = .disabled; |
| 25 | 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 | 66 | { |
| 65 | 67 | const lib = b.addExecutable(.{ |
| 66 | 68 | .name = "lib", |
| 67 | .root_source_file = b.path("lib2.zig"), | |
| 68 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 69 | .optimize = optimize_mode, | |
| 70 | .strip = false, | |
| 69 | .root_module = b.createModule(.{ | |
| 70 | .root_source_file = b.path("lib2.zig"), | |
| 71 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 72 | .optimize = optimize_mode, | |
| 73 | .strip = false, | |
| 74 | }), | |
| 71 | 75 | }); |
| 72 | 76 | lib.entry = .disabled; |
| 73 | 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 | 11 | |
| 12 | 12 | const lib = b.addExecutable(.{ |
| 13 | 13 | .name = "lib", |
| 14 | .root_source_file = b.path("lib.zig"), | |
| 15 | .optimize = .ReleaseSafe, // to make the output deterministic in address positions | |
| 16 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 14 | .root_module = b.createModule(.{ | |
| 15 | .root_source_file = b.path("lib.zig"), | |
| 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 | 20 | lib.entry = .disabled; |
| 19 | 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 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | 16 | const no_export = b.addExecutable(.{ |
| 17 | 17 | .name = "no-export", |
| 18 | .root_source_file = b.path("main.zig"), | |
| 19 | .optimize = optimize, | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 18 | .root_module = b.createModule(.{ | |
| 19 | .root_source_file = b.path("main.zig"), | |
| 20 | .optimize = optimize, | |
| 21 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 22 | }), | |
| 21 | 23 | }); |
| 22 | 24 | no_export.entry = .disabled; |
| 23 | 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 | 27 | |
| 26 | 28 | const dynamic_export = b.addExecutable(.{ |
| 27 | 29 | .name = "dynamic", |
| 28 | .root_source_file = b.path("main.zig"), | |
| 29 | .optimize = optimize, | |
| 30 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 30 | .root_module = b.createModule(.{ | |
| 31 | .root_source_file = b.path("main.zig"), | |
| 32 | .optimize = optimize, | |
| 33 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 34 | }), | |
| 31 | 35 | }); |
| 32 | 36 | dynamic_export.entry = .disabled; |
| 33 | 37 | dynamic_export.rdynamic = true; |
| ... | ... | @@ -36,9 +40,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 36 | 40 | |
| 37 | 41 | const force_export = b.addExecutable(.{ |
| 38 | 42 | .name = "force", |
| 39 | .root_source_file = b.path("main.zig"), | |
| 40 | .optimize = optimize, | |
| 41 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 43 | .root_module = b.createModule(.{ | |
| 44 | .root_source_file = b.path("main.zig"), | |
| 45 | .optimize = optimize, | |
| 46 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 47 | }), | |
| 42 | 48 | }); |
| 43 | 49 | force_export.entry = .disabled; |
| 44 | 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 | 13 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 14 | 14 | const lib = b.addExecutable(.{ |
| 15 | 15 | .name = "lib", |
| 16 | .root_source_file = b.path("lib.zig"), | |
| 17 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 18 | .optimize = optimize, | |
| 16 | .root_module = b.createModule(.{ | |
| 17 | .root_source_file = b.path("lib.zig"), | |
| 18 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 19 | .optimize = optimize, | |
| 20 | }), | |
| 19 | 21 | }); |
| 20 | 22 | lib.entry = .disabled; |
| 21 | 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 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | 16 | const exe = b.addExecutable(.{ |
| 17 | 17 | .name = "extern", |
| 18 | .root_source_file = b.path("main.zig"), | |
| 19 | .optimize = optimize, | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }), | |
| 18 | .root_module = b.createModule(.{ | |
| 19 | .root_source_file = b.path("main.zig"), | |
| 20 | .optimize = optimize, | |
| 21 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }), | |
| 22 | }), | |
| 21 | 23 | }); |
| 22 | 24 | exe.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} }); |
| 23 | 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 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | 16 | const import_table = b.addExecutable(.{ |
| 17 | 17 | .name = "import_table", |
| 18 | .root_source_file = b.path("lib.zig"), | |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 20 | .optimize = optimize, | |
| 18 | .root_module = b.createModule(.{ | |
| 19 | .root_source_file = b.path("lib.zig"), | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 21 | .optimize = optimize, | |
| 22 | }), | |
| 21 | 23 | }); |
| 22 | 24 | import_table.entry = .disabled; |
| 23 | 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 | 29 | |
| 28 | 30 | const export_table = b.addExecutable(.{ |
| 29 | 31 | .name = "export_table", |
| 30 | .root_source_file = b.path("lib.zig"), | |
| 31 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 32 | .optimize = optimize, | |
| 32 | .root_module = b.createModule(.{ | |
| 33 | .root_source_file = b.path("lib.zig"), | |
| 34 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 35 | .optimize = optimize, | |
| 36 | }), | |
| 33 | 37 | }); |
| 34 | 38 | export_table.entry = .disabled; |
| 35 | 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 | 43 | |
| 40 | 44 | const regular_table = b.addExecutable(.{ |
| 41 | 45 | .name = "regular_table", |
| 42 | .root_source_file = b.path("lib.zig"), | |
| 43 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 44 | .optimize = optimize, | |
| 46 | .root_module = b.createModule(.{ | |
| 47 | .root_source_file = b.path("lib.zig"), | |
| 48 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 49 | .optimize = optimize, | |
| 50 | }), | |
| 45 | 51 | }); |
| 46 | 52 | regular_table.entry = .disabled; |
| 47 | 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 | 6 | // Wasm Object file which we will use to infer the features from |
| 7 | 7 | const c_obj = b.addObject(.{ |
| 8 | 8 | .name = "c_obj", |
| 9 | .optimize = .Debug, | |
| 10 | .target = b.resolveTargetQuery(.{ | |
| 11 | .cpu_arch = .wasm32, | |
| 12 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge }, | |
| 13 | .os_tag = .freestanding, | |
| 9 | .root_module = b.createModule(.{ | |
| 10 | .root_source_file = null, | |
| 11 | .optimize = .Debug, | |
| 12 | .target = b.resolveTargetQuery(.{ | |
| 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 | 21 | // Wasm library that doesn't have any features specified. This will |
| 19 | 22 | // infer its featureset from other linked object files. |
| 20 | 23 | const lib = b.addExecutable(.{ |
| 21 | 24 | .name = "lib", |
| 22 | .root_source_file = b.path("main.zig"), | |
| 23 | .optimize = .Debug, | |
| 24 | .target = b.resolveTargetQuery(.{ | |
| 25 | .cpu_arch = .wasm32, | |
| 26 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | |
| 27 | .os_tag = .freestanding, | |
| 25 | .root_module = b.createModule(.{ | |
| 26 | .root_source_file = b.path("main.zig"), | |
| 27 | .optimize = .Debug, | |
| 28 | .target = b.resolveTargetQuery(.{ | |
| 29 | .cpu_arch = .wasm32, | |
| 30 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | |
| 31 | .os_tag = .freestanding, | |
| 32 | }), | |
| 28 | 33 | }), |
| 29 | 34 | }); |
| 30 | 35 | lib.entry = .disabled; |
| 31 | 36 | lib.use_llvm = false; |
| 32 | 37 | lib.use_lld = false; |
| 33 | lib.addObject(c_obj); | |
| 38 | lib.root_module.addObject(c_obj); | |
| 34 | 39 | |
| 35 | 40 | // Verify the result contains the features from the C Object file. |
| 36 | 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 | 16 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 17 | 17 | const lib = b.addExecutable(.{ |
| 18 | 18 | .name = "lib", |
| 19 | .root_source_file = b.path("lib.zig"), | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 21 | .optimize = optimize, | |
| 22 | .strip = false, | |
| 19 | .root_module = b.createModule(.{ | |
| 20 | .root_source_file = b.path("lib.zig"), | |
| 21 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 22 | .optimize = optimize, | |
| 23 | .strip = false, | |
| 24 | }), | |
| 23 | 25 | }); |
| 24 | 26 | lib.entry = .disabled; |
| 25 | 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 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | 16 | const lib = b.addExecutable(.{ |
| 17 | 17 | .name = "lib", |
| 18 | .root_source_file = b.path("lib.zig"), | |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 20 | .optimize = optimize, | |
| 21 | .strip = false, | |
| 18 | .root_module = b.createModule(.{ | |
| 19 | .root_source_file = b.path("lib.zig"), | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 21 | .optimize = optimize, | |
| 22 | .strip = false, | |
| 23 | }), | |
| 22 | 24 | }); |
| 23 | 25 | lib.entry = .disabled; |
| 24 | 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 | 13 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode) void { |
| 14 | 14 | const exe = b.addExecutable(.{ |
| 15 | 15 | .name = "lib", |
| 16 | .root_source_file = b.path("lib.zig"), | |
| 17 | .target = b.resolveTargetQuery(.{ | |
| 18 | .cpu_arch = .wasm32, | |
| 19 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | |
| 20 | .cpu_features_add = std.Target.wasm.featureSet(&.{ .atomics, .bulk_memory }), | |
| 21 | .os_tag = .freestanding, | |
| 16 | .root_module = b.createModule(.{ | |
| 17 | .root_source_file = b.path("lib.zig"), | |
| 18 | .target = b.resolveTargetQuery(.{ | |
| 19 | .cpu_arch = .wasm32, | |
| 20 | .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, | |
| 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 | 29 | exe.entry = .disabled; |
| 28 | 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 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | 16 | const lib = b.addExecutable(.{ |
| 17 | 17 | .name = "lib", |
| 18 | .root_source_file = b.path("lib.zig"), | |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 20 | .optimize = optimize, | |
| 21 | .strip = false, | |
| 18 | .root_module = b.createModule(.{ | |
| 19 | .root_source_file = b.path("lib.zig"), | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 21 | .optimize = optimize, | |
| 22 | .strip = false, | |
| 23 | }), | |
| 22 | 24 | }); |
| 23 | 25 | lib.entry = .disabled; |
| 24 | 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 | 15 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 16 | 16 | const exe = b.addExecutable(.{ |
| 17 | 17 | .name = "lib", |
| 18 | .root_source_file = b.path("lib.zig"), | |
| 19 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 20 | .optimize = optimize, | |
| 21 | .strip = false, | |
| 18 | .root_module = b.createModule(.{ | |
| 19 | .root_source_file = b.path("lib.zig"), | |
| 20 | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), | |
| 21 | .optimize = optimize, | |
| 22 | .strip = false, | |
| 23 | }), | |
| 22 | 24 | }); |
| 23 | 25 | exe.entry = .disabled; |
| 24 | 26 | exe.use_llvm = false; |
test/src/Cases.zig+20-20| ... | ... | @@ -572,7 +572,10 @@ pub fn lowerToTranslateCSteps( |
| 572 | 572 | }); |
| 573 | 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 | 579 | run_exe.step.name = b.fmt("{s} build-exe", .{annotated_case_name}); |
| 577 | 580 | run_exe.linkLibC(); |
| 578 | 581 | const run = b.addRunArtifact(run_exe); |
| ... | ... | @@ -660,34 +663,37 @@ pub fn lowerToBuildSteps( |
| 660 | 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 | 667 | .root_source_file = root_source_file, |
| 665 | .name = case.name, | |
| 666 | 668 | .target = case.target, |
| 667 | 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 | 682 | }) else switch (case.output_mode) { |
| 669 | 683 | .Obj => b.addObject(.{ |
| 670 | .root_source_file = root_source_file, | |
| 671 | 684 | .name = case.name, |
| 672 | .target = case.target, | |
| 673 | .optimize = case.optimize_mode, | |
| 685 | .root_module = mod, | |
| 674 | 686 | }), |
| 675 | 687 | .Lib => b.addStaticLibrary(.{ |
| 676 | .root_source_file = root_source_file, | |
| 677 | 688 | .name = case.name, |
| 678 | .target = case.target, | |
| 679 | .optimize = case.optimize_mode, | |
| 689 | .root_module = mod, | |
| 680 | 690 | }), |
| 681 | 691 | .Exe => b.addExecutable(.{ |
| 682 | .root_source_file = root_source_file, | |
| 683 | 692 | .name = case.name, |
| 684 | .target = case.target, | |
| 685 | .optimize = case.optimize_mode, | |
| 693 | .root_module = mod, | |
| 686 | 694 | }), |
| 687 | 695 | }; |
| 688 | 696 | |
| 689 | if (case.link_libc) artifact.linkLibC(); | |
| 690 | if (case.pic) |pic| artifact.root_module.pic = pic; | |
| 691 | 697 | if (case.pie) |pie| artifact.pie = pie; |
| 692 | 698 | |
| 693 | 699 | switch (case.backend) { |
| ... | ... | @@ -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 | 710 | switch (update.case) { |
| 711 | 711 | .Compile => { |
| 712 | 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 | 89 | |
| 90 | 90 | switch (case.special) { |
| 91 | 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 | 93 | case.name, |
| 94 | }) catch @panic("OOM"); | |
| 94 | }); | |
| 95 | 95 | for (self.test_filters) |test_filter| { |
| 96 | 96 | if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break; |
| 97 | 97 | } else if (self.test_filters.len > 0) return; |
| 98 | 98 | |
| 99 | 99 | const exe = b.addExecutable(.{ |
| 100 | 100 | .name = "test", |
| 101 | .target = b.graph.host, | |
| 102 | .optimize = .Debug, | |
| 101 | .root_module = b.createModule(.{ | |
| 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 | 109 | const run = b.addRunArtifact(exe); |
| 107 | 110 | run.setName(annotated_case_name); |
| ... | ... | @@ -112,22 +115,22 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 112 | 115 | }, |
| 113 | 116 | Special.None => { |
| 114 | 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 | 119 | case.name, @tagName(optimize), |
| 117 | }) catch @panic("OOM"); | |
| 120 | }); | |
| 118 | 121 | for (self.test_filters) |test_filter| { |
| 119 | 122 | if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break; |
| 120 | 123 | } else if (self.test_filters.len > 0) return; |
| 121 | 124 | |
| 122 | 125 | const exe = b.addExecutable(.{ |
| 123 | 126 | .name = "test", |
| 124 | .root_source_file = first_file, | |
| 125 | .optimize = optimize, | |
| 126 | .target = b.graph.host, | |
| 127 | .root_module = b.createModule(.{ | |
| 128 | .root_source_file = first_file, | |
| 129 | .optimize = optimize, | |
| 130 | .target = b.graph.host, | |
| 131 | }), | |
| 127 | 132 | }); |
| 128 | if (case.link_libc) { | |
| 129 | exe.linkSystemLibrary("c"); | |
| 130 | } | |
| 133 | if (case.link_libc) exe.root_module.link_libc = true; | |
| 131 | 134 | |
| 132 | 135 | const run = b.addRunArtifact(exe); |
| 133 | 136 | run.setName(annotated_case_name); |
| ... | ... | @@ -140,20 +143,20 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 140 | 143 | Special.RuntimeSafety => { |
| 141 | 144 | // TODO iterate over self.optimize_modes and test this in both |
| 142 | 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 | 147 | for (self.test_filters) |test_filter| { |
| 145 | 148 | if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break; |
| 146 | 149 | } else if (self.test_filters.len > 0) return; |
| 147 | 150 | |
| 148 | 151 | const exe = b.addExecutable(.{ |
| 149 | 152 | .name = "test", |
| 150 | .root_source_file = first_file, | |
| 151 | .target = b.graph.host, | |
| 152 | .optimize = .Debug, | |
| 153 | .root_module = b.createModule(.{ | |
| 154 | .root_source_file = first_file, | |
| 155 | .target = b.graph.host, | |
| 156 | .optimize = .Debug, | |
| 157 | }), | |
| 153 | 158 | }); |
| 154 | if (case.link_libc) { | |
| 155 | exe.linkSystemLibrary("c"); | |
| 156 | } | |
| 159 | if (case.link_libc) exe.root_module.link_libc = true; | |
| 157 | 160 | |
| 158 | 161 | const run = b.addRunArtifact(exe); |
| 159 | 162 | run.setName(annotated_case_name); |
| ... | ... | @@ -168,7 +171,6 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { |
| 168 | 171 | const CompareOutput = @This(); |
| 169 | 172 | const std = @import("std"); |
| 170 | 173 | const ArrayList = std.ArrayList; |
| 171 | const fmt = std.fmt; | |
| 172 | 174 | const mem = std.mem; |
| 173 | 175 | const fs = std.fs; |
| 174 | 176 | const OptimizeMode = std.builtin.OptimizeMode; |
test/src/Debugger.zig+11-5| ... | ... | @@ -2414,8 +2414,8 @@ fn addTest( |
| 2414 | 2414 | } else return; |
| 2415 | 2415 | } |
| 2416 | 2416 | const files_wf = db.b.addWriteFiles(); |
| 2417 | const exe = db.b.addExecutable(.{ | |
| 2418 | .name = name, | |
| 2417 | ||
| 2418 | const mod = db.b.createModule(.{ | |
| 2419 | 2419 | .target = target.resolved, |
| 2420 | 2420 | .root_source_file = files_wf.add(files[0].path, files[0].source), |
| 2421 | 2421 | .optimize = target.optimize_mode, |
| ... | ... | @@ -2423,15 +2423,21 @@ fn addTest( |
| 2423 | 2423 | .single_threaded = target.single_threaded, |
| 2424 | 2424 | .pic = target.pic, |
| 2425 | 2425 | .strip = false, |
| 2426 | .use_llvm = false, | |
| 2427 | .use_lld = false, | |
| 2428 | 2426 | }); |
| 2429 | 2427 | for (files[1..]) |file| { |
| 2430 | 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 | 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 | 2441 | const commands_wf = db.b.addWriteFiles(); |
| 2436 | 2442 | const run = std.Build.Step.Run.create(db.b, db.b.fmt("run {s} {s}", .{ name, target.test_name_suffix })); |
| 2437 | 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 | 84 | }); |
| 85 | 85 | |
| 86 | 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 | 91 | exe.step.name = b.fmt("{s} build-exe", .{annotated_case_name}); |
| 89 | 92 | exe.linkLibC(); |
| 90 | 93 | const run = b.addRunArtifact(exe); |
test/src/StackTrace.zig+8-7| ... | ... | @@ -44,9 +44,9 @@ fn addExpect( |
| 44 | 44 | for (mode_config.exclude_os) |tag| if (tag == builtin.os.tag) return; |
| 45 | 45 | |
| 46 | 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 | 48 | name, @tagName(optimize_mode), |
| 49 | }) catch @panic("OOM"); | |
| 49 | }); | |
| 50 | 50 | for (self.test_filters) |test_filter| { |
| 51 | 51 | if (mem.indexOf(u8, annotated_case_name, test_filter)) |_| break; |
| 52 | 52 | } else if (self.test_filters.len > 0) return; |
| ... | ... | @@ -55,10 +55,12 @@ fn addExpect( |
| 55 | 55 | const source_zig = write_files.add("source.zig", source); |
| 56 | 56 | const exe = b.addExecutable(.{ |
| 57 | 57 | .name = "test", |
| 58 | .root_source_file = source_zig, | |
| 59 | .optimize = optimize_mode, | |
| 60 | .target = b.graph.host, | |
| 61 | .error_tracing = mode_config.error_tracing, | |
| 58 | .root_module = b.createModule(.{ | |
| 59 | .root_source_file = source_zig, | |
| 60 | .optimize = optimize_mode, | |
| 61 | .target = b.graph.host, | |
| 62 | .error_tracing = mode_config.error_tracing, | |
| 63 | }), | |
| 62 | 64 | }); |
| 63 | 65 | |
| 64 | 66 | const run = b.addRunArtifact(exe); |
| ... | ... | @@ -83,5 +85,4 @@ const std = @import("std"); |
| 83 | 85 | const builtin = @import("builtin"); |
| 84 | 86 | const Step = std.Build.Step; |
| 85 | 87 | const OptimizeMode = std.builtin.OptimizeMode; |
| 86 | const fmt = std.fmt; | |
| 87 | 88 | const mem = std.mem; |
test/standalone/build.zig+5-3| ... | ... | @@ -47,9 +47,11 @@ pub fn build(b: *std.Build) void { |
| 47 | 47 | }) |tool_src_path| { |
| 48 | 48 | const tool = b.addTest(.{ |
| 49 | 49 | .name = std.fs.path.stem(tool_src_path), |
| 50 | .root_source_file = b.path(tool_src_path), | |
| 51 | .optimize = .Debug, | |
| 52 | .target = tools_target, | |
| 50 | .root_module = b.createModule(.{ | |
| 51 | .root_source_file = b.path(tool_src_path), | |
| 52 | .optimize = .Debug, | |
| 53 | .target = tools_target, | |
| 54 | }), | |
| 53 | 55 | }); |
| 54 | 56 | const run = b.addRunArtifact(tool); |
| 55 | 57 | tools_tests_step.dependOn(&run.step); |
test/standalone/c_compiler/build.zig+11-8| ... | ... | @@ -20,22 +20,25 @@ fn add( |
| 20 | 20 | ) void { |
| 21 | 21 | const target = b.graph.host; |
| 22 | 22 | |
| 23 | const exe_c = b.addExecutable(.{ | |
| 24 | .name = c_name, | |
| 23 | const c_mod = b.createModule(.{ | |
| 25 | 24 | .optimize = optimize, |
| 26 | 25 | .target = target, |
| 27 | 26 | }); |
| 28 | exe_c.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[0][]const u8{} }); | |
| 29 | exe_c.linkLibC(); | |
| 27 | c_mod.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[0][]const u8{} }); | |
| 28 | c_mod.link_libc = true; | |
| 30 | 29 | |
| 31 | const exe_cpp = b.addExecutable(.{ | |
| 32 | .name = cpp_name, | |
| 30 | const exe_c = b.addExecutable(.{ .name = c_name, .root_module = c_mod }); | |
| 31 | ||
| 32 | const cpp_mod = b.createModule(.{ | |
| 33 | 33 | .optimize = optimize, |
| 34 | 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 | 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 | 43 | switch (target.result.os.tag) { |
| 41 | 44 | .windows => { |
test/standalone/child_process/build.zig+10-6| ... | ... | @@ -12,16 +12,20 @@ pub fn build(b: *std.Build) void { |
| 12 | 12 | |
| 13 | 13 | const child = b.addExecutable(.{ |
| 14 | 14 | .name = "child", |
| 15 | .root_source_file = b.path("child.zig"), | |
| 16 | .optimize = optimize, | |
| 17 | .target = target, | |
| 15 | .root_module = b.createModule(.{ | |
| 16 | .root_source_file = b.path("child.zig"), | |
| 17 | .optimize = optimize, | |
| 18 | .target = target, | |
| 19 | }), | |
| 18 | 20 | }); |
| 19 | 21 | |
| 20 | 22 | const main = b.addExecutable(.{ |
| 21 | 23 | .name = "main", |
| 22 | .root_source_file = b.path("main.zig"), | |
| 23 | .optimize = optimize, | |
| 24 | .target = target, | |
| 24 | .root_module = b.createModule(.{ | |
| 25 | .root_source_file = b.path("main.zig"), | |
| 26 | .optimize = optimize, | |
| 27 | .target = target, | |
| 28 | }), | |
| 25 | 29 | }); |
| 26 | 30 | const run = b.addRunArtifact(main); |
| 27 | 31 | run.addArtifactArg(child); |
test/standalone/coff_dwarf/build.zig+13-8| ... | ... | @@ -14,19 +14,24 @@ pub fn build(b: *std.Build) void { |
| 14 | 14 | |
| 15 | 15 | const exe = b.addExecutable(.{ |
| 16 | 16 | .name = "main", |
| 17 | .root_source_file = b.path("main.zig"), | |
| 18 | .optimize = optimize, | |
| 19 | .target = target, | |
| 17 | .root_module = b.createModule(.{ | |
| 18 | .root_source_file = b.path("main.zig"), | |
| 19 | .optimize = optimize, | |
| 20 | .target = target, | |
| 21 | }), | |
| 20 | 22 | }); |
| 21 | 23 | |
| 22 | 24 | const lib = b.addSharedLibrary(.{ |
| 23 | 25 | .name = "shared_lib", |
| 24 | .optimize = optimize, | |
| 25 | .target = target, | |
| 26 | .root_module = b.createModule(.{ | |
| 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"} }); | |
| 28 | lib.linkLibC(); | |
| 29 | exe.linkLibrary(lib); | |
| 33 | lib.root_module.addCSourceFile(.{ .file = b.path("shared_lib.c"), .flags = &.{"-gdwarf"} }); | |
| 34 | exe.root_module.linkLibrary(lib); | |
| 30 | 35 | |
| 31 | 36 | const run = b.addRunArtifact(exe); |
| 32 | 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 | 12 | |
| 13 | 13 | const exe = b.addExecutable(.{ |
| 14 | 14 | .name = "main", |
| 15 | .optimize = optimize, | |
| 16 | .target = target, | |
| 15 | .root_module = b.createModule(.{ | |
| 16 | .root_source_file = null, | |
| 17 | .optimize = optimize, | |
| 18 | .target = target, | |
| 19 | .link_libc = true, | |
| 20 | }), | |
| 17 | 21 | }); |
| 18 | exe.linkLibC(); | |
| 19 | exe.addCSourceFile(.{ | |
| 22 | exe.root_module.addCSourceFile(.{ | |
| 20 | 23 | .file = b.path("main.c"), |
| 21 | 24 | .flags = &.{}, |
| 22 | 25 | }); |
test/standalone/dep_diamond/build.zig+13-13| ... | ... | @@ -6,23 +6,23 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | |
| 7 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | |
| 9 | const shared = b.createModule(.{ | |
| 10 | .root_source_file = b.path("shared.zig"), | |
| 11 | }); | |
| 12 | ||
| 13 | const exe = b.addExecutable(.{ | |
| 14 | .name = "test", | |
| 9 | const main_mod = b.createModule(.{ | |
| 15 | 10 | .root_source_file = b.path("test.zig"), |
| 16 | 11 | .target = b.graph.host, |
| 17 | 12 | .optimize = optimize, |
| 18 | 13 | }); |
| 19 | exe.root_module.addAnonymousImport("foo", .{ | |
| 20 | .root_source_file = b.path("foo.zig"), | |
| 21 | .imports = &.{.{ .name = "shared", .module = shared }}, | |
| 22 | }); | |
| 23 | exe.root_module.addAnonymousImport("bar", .{ | |
| 24 | .root_source_file = b.path("bar.zig"), | |
| 25 | .imports = &.{.{ .name = "shared", .module = shared }}, | |
| 14 | const shared_mod = b.createModule(.{ .root_source_file = b.path("shared.zig") }); | |
| 15 | const foo_mod = b.createModule(.{ .root_source_file = b.path("foo.zig") }); | |
| 16 | const bar_mod = b.createModule(.{ .root_source_file = b.path("bar.zig") }); | |
| 17 | ||
| 18 | main_mod.addImport("foo", foo_mod); | |
| 19 | main_mod.addImport("bar", bar_mod); | |
| 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 | 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 | 4 | const target = b.standardTargetOptions(.{}); |
| 5 | 5 | const optimize = b.standardOptimizeOption(.{}); |
| 6 | 6 | |
| 7 | const mod = b.addModule("mod", .{ | |
| 7 | const shared_mod = b.createModule(.{ | |
| 8 | 8 | .root_source_file = b.path("mod.zig"), |
| 9 | 9 | .target = target, |
| 10 | 10 | .optimize = optimize, |
| 11 | 11 | }); |
| 12 | ||
| 13 | const lib = b.addStaticLibrary(.{ | |
| 14 | .name = "lib", | |
| 12 | const lib_mod = b.createModule(.{ | |
| 15 | 13 | .root_source_file = b.path("lib.zig"), |
| 16 | 14 | .target = target, |
| 17 | 15 | .optimize = optimize, |
| 18 | 16 | }); |
| 19 | lib.root_module.addImport("mod", mod); | |
| 20 | ||
| 21 | const exe = b.addExecutable(.{ | |
| 22 | .name = "app", | |
| 17 | const exe_mod = b.createModule(.{ | |
| 23 | 18 | .root_source_file = b.path("main.zig"), |
| 24 | 19 | .target = target, |
| 25 | 20 | .optimize = optimize, |
| 26 | 21 | }); |
| 27 | 22 | |
| 28 | exe.root_module.addImport("mod", mod); | |
| 29 | exe.root_module.linkLibrary(lib); | |
| 23 | lib_mod.addImport("mod", shared_mod); | |
| 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 | 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 | 11 | const generated_main_c = write_files.add("main.c", ""); |
| 12 | 12 | const exe = b.addExecutable(.{ |
| 13 | 13 | .name = "test", |
| 14 | .target = b.graph.host, | |
| 15 | .optimize = optimize, | |
| 14 | .root_module = b.createModule(.{ | |
| 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 | 21 | .root = generated_main_c.dirname(), |
| 19 | 22 | .files = &.{"main.c"}, |
| 20 | 23 | }); |
| ... | ... | @@ -26,11 +29,13 @@ pub fn build(b: *std.Build) void { |
| 26 | 29 | const dir = write_files.addCopyDirectory(b.path("inc"), "", .{}); |
| 27 | 30 | const exe = b.addExecutable(.{ |
| 28 | 31 | .name = "test", |
| 29 | .root_source_file = b.path("inctest.zig"), | |
| 30 | .target = b.graph.host, | |
| 31 | .optimize = optimize, | |
| 32 | .root_module = b.createModule(.{ | |
| 33 | .root_source_file = b.path("inctest.zig"), | |
| 34 | .target = b.graph.host, | |
| 35 | .optimize = optimize, | |
| 36 | }), | |
| 32 | 37 | }); |
| 33 | exe.addIncludePath(dir); | |
| 38 | exe.root_module.addIncludePath(dir); | |
| 34 | 39 | b.step("copydir", "").dependOn(&exe.step); |
| 35 | 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 | 6 | |
| 7 | 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 | 15 | .root_source_file = b.path("foo.zig"), |
| 11 | 16 | }); |
| 12 | const bar = b.createModule(.{ | |
| 17 | const bar_mod = b.createModule(.{ | |
| 13 | 18 | .root_source_file = b.path("bar.zig"), |
| 14 | 19 | }); |
| 15 | foo.addImport("bar", bar); | |
| 16 | bar.addImport("foo", foo); | |
| 20 | ||
| 21 | main_mod.addImport("foo", foo_mod); | |
| 22 | foo_mod.addImport("bar", bar_mod); | |
| 23 | bar_mod.addImport("foo", foo_mod); | |
| 17 | 24 | |
| 18 | 25 | const exe = b.addExecutable(.{ |
| 19 | 26 | .name = "test", |
| 20 | .root_source_file = b.path("test.zig"), | |
| 21 | .target = b.graph.host, | |
| 22 | .optimize = optimize, | |
| 27 | .root_module = main_mod, | |
| 23 | 28 | }); |
| 24 | exe.root_module.addImport("foo", foo); | |
| 25 | 29 | |
| 26 | 30 | const run = b.addRunArtifact(exe); |
| 27 | 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 | 6 | |
| 7 | 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 | 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 | 21 | const exe = b.addExecutable(.{ |
| 15 | 22 | .name = "test", |
| 16 | .root_source_file = b.path("test.zig"), | |
| 17 | .target = b.graph.host, | |
| 18 | .optimize = optimize, | |
| 23 | .root_module = main_mod, | |
| 19 | 24 | }); |
| 20 | exe.root_module.addImport("foo", foo); | |
| 21 | 25 | |
| 22 | 26 | const run = b.addRunArtifact(exe); |
| 23 | 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 | 6 | |
| 7 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | |
| 9 | const exe = b.addExecutable(.{ | |
| 10 | .name = "test", | |
| 9 | const main_mod = b.createModule(.{ | |
| 11 | 10 | .root_source_file = b.path("test.zig"), |
| 12 | 11 | .target = b.graph.host, |
| 13 | 12 | .optimize = optimize, |
| 14 | 13 | }); |
| 15 | exe.root_module.addAnonymousImport("foo", .{ | |
| 14 | const foo_mod = b.createModule(.{ | |
| 16 | 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 | 25 | const run = b.addRunArtifact(exe); |
| 20 | 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 | 6 | |
| 7 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | |
| 9 | const shared = b.createModule(.{ | |
| 10 | .root_source_file = b.path("shared.zig"), | |
| 11 | }); | |
| 12 | ||
| 13 | const exe = b.addExecutable(.{ | |
| 14 | .name = "test", | |
| 9 | const main_mod = b.createModule(.{ | |
| 15 | 10 | .root_source_file = b.path("test.zig"), |
| 16 | 11 | .target = b.graph.host, |
| 17 | 12 | .optimize = optimize, |
| 18 | 13 | }); |
| 19 | exe.root_module.addAnonymousImport("foo", .{ | |
| 14 | const foo_mod = b.createModule(.{ | |
| 20 | 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 | 30 | const run = b.addRunArtifact(exe); |
| 26 | 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 | 7 | const target = b.standardTargetOptions(.{}); |
| 8 | 8 | const optimize = b.standardOptimizeOption(.{}); |
| 9 | 9 | |
| 10 | const exe = b.addExecutable(.{ | |
| 11 | .name = "depend_on_main_mod", | |
| 10 | const main_mod = b.createModule(.{ | |
| 12 | 11 | .root_source_file = b.path("src/main.zig"), |
| 13 | 12 | .target = target, |
| 14 | 13 | .optimize = optimize, |
| 15 | 14 | }); |
| 16 | ||
| 17 | const foo_module = b.addModule("foo", .{ | |
| 15 | const foo_mod = b.createModule(.{ | |
| 18 | 16 | .root_source_file = b.path("src/foo.zig"), |
| 19 | 17 | }); |
| 20 | 18 | |
| 21 | foo_module.addImport("root2", &exe.root_module); | |
| 22 | exe.root_module.addImport("foo", foo_module); | |
| 19 | foo_mod.addImport("root2", main_mod); | |
| 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 | 27 | const run_cmd = b.addRunArtifact(exe); |
| 25 | 28 | run_cmd.expectExitCode(0); |
test/standalone/dirname/build.zig+15-9| ... | ... | @@ -10,24 +10,30 @@ pub fn build(b: *std.Build) void { |
| 10 | 10 | |
| 11 | 11 | const touch = b.addExecutable(.{ |
| 12 | 12 | .name = "touch", |
| 13 | .root_source_file = touch_src, | |
| 14 | .optimize = .Debug, | |
| 15 | .target = target, | |
| 13 | .root_module = b.createModule(.{ | |
| 14 | .root_source_file = touch_src, | |
| 15 | .optimize = .Debug, | |
| 16 | .target = target, | |
| 17 | }), | |
| 16 | 18 | }); |
| 17 | 19 | const generated = b.addRunArtifact(touch).addOutputFileArg("subdir" ++ std.fs.path.sep_str ++ "generated.txt"); |
| 18 | 20 | |
| 19 | 21 | const exists_in = b.addExecutable(.{ |
| 20 | 22 | .name = "exists_in", |
| 21 | .root_source_file = b.path("exists_in.zig"), | |
| 22 | .optimize = .Debug, | |
| 23 | .target = target, | |
| 23 | .root_module = b.createModule(.{ | |
| 24 | .root_source_file = b.path("exists_in.zig"), | |
| 25 | .optimize = .Debug, | |
| 26 | .target = target, | |
| 27 | }), | |
| 24 | 28 | }); |
| 25 | 29 | |
| 26 | 30 | const has_basename = b.addExecutable(.{ |
| 27 | 31 | .name = "has_basename", |
| 28 | .root_source_file = b.path("has_basename.zig"), | |
| 29 | .optimize = .Debug, | |
| 30 | .target = target, | |
| 32 | .root_module = b.createModule(.{ | |
| 33 | .root_source_file = b.path("has_basename.zig"), | |
| 34 | .optimize = .Debug, | |
| 35 | .target = target, | |
| 36 | }), | |
| 31 | 37 | }); |
| 32 | 38 | |
| 33 | 39 | // Known path: |
test/standalone/embed_generated_file/build.zig+10-7| ... | ... | @@ -6,18 +6,21 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | |
| 7 | 7 | const bootloader = b.addExecutable(.{ |
| 8 | 8 | .name = "bootloader", |
| 9 | .root_source_file = b.path("bootloader.zig"), | |
| 10 | .target = b.resolveTargetQuery(.{ | |
| 11 | .cpu_arch = .x86, | |
| 12 | .os_tag = .freestanding, | |
| 9 | .root_module = b.createModule(.{ | |
| 10 | .root_source_file = b.path("bootloader.zig"), | |
| 11 | .target = b.resolveTargetQuery(.{ | |
| 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 | 20 | .root_source_file = b.path("main.zig"), |
| 21 | .target = b.graph.host, | |
| 19 | 22 | .optimize = .Debug, |
| 20 | }); | |
| 23 | }) }); | |
| 21 | 24 | exe.root_module.addAnonymousImport("bootloader.elf", .{ |
| 22 | 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 | 4 | const test_step = b.step("test", "Test it"); |
| 5 | 5 | b.default_step = test_step; |
| 6 | 6 | |
| 7 | const main = b.addTest(.{ | |
| 7 | const main = b.addTest(.{ .root_module = b.createModule(.{ | |
| 8 | 8 | .root_source_file = b.path("main.zig"), |
| 9 | .target = b.graph.host, | |
| 9 | 10 | .optimize = b.standardOptimizeOption(.{}), |
| 10 | }); | |
| 11 | }) }); | |
| 11 | 12 | // TODO: actually check these two artifacts for correctness |
| 12 | 13 | _ = main.getEmittedBin(); |
| 13 | 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 | 8 | |
| 9 | 9 | const obj = b.addObject(.{ |
| 10 | 10 | .name = "main", |
| 11 | .root_source_file = b.path("main.zig"), | |
| 12 | .optimize = optimize, | |
| 13 | .target = b.graph.host, | |
| 11 | .root_module = b.createModule(.{ | |
| 12 | .root_source_file = b.path("main.zig"), | |
| 13 | .optimize = optimize, | |
| 14 | .target = b.graph.host, | |
| 15 | }), | |
| 14 | 16 | }); |
| 15 | 17 | _ = obj.getEmittedAsm(); |
| 16 | 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 | 8 | |
| 9 | 9 | const obj = b.addObject(.{ |
| 10 | 10 | .name = "main", |
| 11 | .root_source_file = b.path("main.zig"), | |
| 12 | .optimize = optimize, | |
| 13 | .target = b.graph.host, | |
| 11 | .root_module = b.createModule(.{ | |
| 12 | .root_source_file = b.path("main.zig"), | |
| 13 | .optimize = optimize, | |
| 14 | .target = b.graph.host, | |
| 15 | }), | |
| 14 | 16 | }); |
| 15 | 17 | _ = obj.getEmittedLlvmIr(); |
| 16 | 18 | _ = obj.getEmittedLlvmBc(); |
test/standalone/empty_env/build.zig+5-3| ... | ... | @@ -21,9 +21,11 @@ pub fn build(b: *std.Build) void { |
| 21 | 21 | |
| 22 | 22 | const main = b.addExecutable(.{ |
| 23 | 23 | .name = "main", |
| 24 | .root_source_file = b.path("main.zig"), | |
| 25 | .target = b.graph.host, | |
| 26 | .optimize = optimize, | |
| 24 | .root_module = b.createModule(.{ | |
| 25 | .root_source_file = b.path("main.zig"), | |
| 26 | .target = b.graph.host, | |
| 27 | .optimize = optimize, | |
| 28 | }), | |
| 27 | 29 | }); |
| 28 | 30 | |
| 29 | 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 | 8 | |
| 9 | 9 | const obj = b.addObject(.{ |
| 10 | 10 | .name = "exports", |
| 11 | .root_source_file = b.path("exports.zig"), | |
| 12 | .target = b.graph.host, | |
| 13 | .optimize = optimize, | |
| 11 | .root_module = b.createModule(.{ | |
| 12 | .root_source_file = b.path("exports.zig"), | |
| 13 | .target = b.graph.host, | |
| 14 | .optimize = optimize, | |
| 15 | }), | |
| 14 | 16 | }); |
| 15 | 17 | const shared = b.addSharedLibrary(.{ |
| 16 | 18 | .name = "shared", |
| 17 | .target = b.graph.host, | |
| 18 | .optimize = optimize, | |
| 19 | .link_libc = true, | |
| 19 | .root_module = b.createModule(.{ | |
| 20 | .root_source_file = null, | |
| 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)"); | |
| 22 | shared.addCSourceFile(.{ .file = b.path("shared.c"), .flags = &.{} }); | |
| 23 | const test_exe = b.addTest(.{ | |
| 26 | if (b.graph.host.result.abi == .msvc) shared.root_module.addCMacro("API", "__declspec(dllexport)"); | |
| 27 | shared.root_module.addCSourceFile(.{ .file = b.path("shared.c"), .flags = &.{} }); | |
| 28 | const test_exe = b.addTest(.{ .root_module = b.createModule(.{ | |
| 24 | 29 | .root_source_file = b.path("main.zig"), |
| 30 | .target = b.graph.host, | |
| 25 | 31 | .optimize = optimize, |
| 26 | }); | |
| 32 | }) }); | |
| 27 | 33 | test_exe.addObject(obj); |
| 28 | 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 | 9 | |
| 10 | 10 | const obj1 = b.addStaticLibrary(.{ |
| 11 | 11 | .name = "obj1", |
| 12 | .root_source_file = b.path("obj1.zig"), | |
| 13 | .optimize = optimize, | |
| 14 | .target = target, | |
| 12 | .root_module = b.createModule(.{ | |
| 13 | .root_source_file = b.path("obj1.zig"), | |
| 14 | .optimize = optimize, | |
| 15 | .target = target, | |
| 16 | }), | |
| 15 | 17 | }); |
| 16 | 18 | |
| 17 | 19 | const obj2 = b.addStaticLibrary(.{ |
| 18 | 20 | .name = "obj2", |
| 19 | .root_source_file = b.path("obj2.zig"), | |
| 20 | .optimize = optimize, | |
| 21 | .target = target, | |
| 21 | .root_module = b.createModule(.{ | |
| 22 | .root_source_file = b.path("obj2.zig"), | |
| 23 | .optimize = optimize, | |
| 24 | .target = target, | |
| 25 | }), | |
| 22 | 26 | }); |
| 23 | 27 | |
| 24 | const main = b.addTest(.{ | |
| 28 | const main_mod = b.createModule(.{ | |
| 25 | 29 | .root_source_file = b.path("main.zig"), |
| 30 | .target = b.graph.host, | |
| 26 | 31 | .optimize = optimize, |
| 27 | 32 | }); |
| 28 | main.linkLibrary(obj1); | |
| 29 | main.linkLibrary(obj2); | |
| 33 | main_mod.linkLibrary(obj1); | |
| 34 | main_mod.linkLibrary(obj2); | |
| 30 | 35 | |
| 36 | const main = b.addTest(.{ .root_module = main_mod }); | |
| 31 | 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 | 8 | |
| 9 | 9 | const libfoo = b.addStaticLibrary(.{ |
| 10 | 10 | .name = "foo", |
| 11 | .target = b.resolveTargetQuery(.{}), | |
| 12 | .optimize = .Debug, | |
| 11 | .root_module = b.createModule(.{ | |
| 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 | 19 | const exe = b.addExecutable(.{ |
| 17 | 20 | .name = "exe", |
| 18 | .target = b.resolveTargetQuery(.{}), | |
| 19 | .optimize = .Debug, | |
| 20 | .link_libc = true, | |
| 21 | .root_module = b.createModule(.{ | |
| 22 | .root_source_file = null, | |
| 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 | 29 | \\#include <stdio.h> |
| 24 | 30 | \\#include <foo/a.h> |
| 25 | 31 | \\#include <foo/sub_dir/b.h> |
| ... | ... | @@ -40,9 +46,10 @@ pub fn build(b: *std.Build) void { |
| 40 | 46 | |
| 41 | 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 | 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 | 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 | 63 | |
| 57 | 64 | const libbar = b.addStaticLibrary(.{ |
| 58 | 65 | .name = "bar", |
| 59 | .target = b.resolveTargetQuery(.{}), | |
| 60 | .optimize = .Debug, | |
| 66 | .root_module = b.createModule(.{ | |
| 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 | 73 | libbar.installHeader(b.addWriteFiles().add("bar.h", |
| 64 | 74 | \\#define BAR_X "X" |
| 65 | 75 | \\ |
| ... | ... | @@ -78,9 +88,11 @@ pub fn build(b: *std.Build) void { |
| 78 | 88 | }); |
| 79 | 89 | const check_exists = b.addExecutable(.{ |
| 80 | 90 | .name = "check_exists", |
| 81 | .root_source_file = b.path("check_exists.zig"), | |
| 82 | .target = b.resolveTargetQuery(.{}), | |
| 83 | .optimize = .Debug, | |
| 91 | .root_module = b.createModule(.{ | |
| 92 | .root_source_file = b.path("check_exists.zig"), | |
| 93 | .target = b.resolveTargetQuery(.{}), | |
| 94 | .optimize = .Debug, | |
| 95 | }), | |
| 84 | 96 | }); |
| 85 | 97 | const run_check_exists = b.addRunArtifact(check_exists); |
| 86 | 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 | 16 | |
| 17 | 17 | const elf = b.addExecutable(.{ |
| 18 | 18 | .name = "zig-nrf52-blink.elf", |
| 19 | .root_source_file = b.path("main.zig"), | |
| 20 | .target = target, | |
| 21 | .optimize = optimize, | |
| 19 | .root_module = b.createModule(.{ | |
| 20 | .root_source_file = b.path("main.zig"), | |
| 21 | .target = target, | |
| 22 | .optimize = optimize, | |
| 23 | }), | |
| 22 | 24 | }); |
| 23 | 25 | |
| 24 | 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 | 18 | |
| 19 | 19 | const exe = b.addExecutable(.{ |
| 20 | 20 | .name = "main", |
| 21 | .optimize = optimize, | |
| 22 | .target = target, | |
| 21 | .root_module = b.createModule(.{ | |
| 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 = &.{} }); | |
| 25 | exe.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) }); | |
| 26 | exe.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) }); | |
| 27 | exe.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/lib" }) }); | |
| 28 | exe.linkFramework("Foundation"); | |
| 29 | exe.linkFramework("UIKit"); | |
| 30 | exe.linkLibC(); | |
| 28 | exe.root_module.addCSourceFile(.{ .file = b.path("main.m"), .flags = &.{} }); | |
| 29 | exe.root_module.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) }); | |
| 30 | exe.root_module.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) }); | |
| 31 | exe.root_module.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/lib" }) }); | |
| 32 | exe.root_module.linkFramework("Foundation", .{}); | |
| 33 | exe.root_module.linkFramework("UIKit", .{}); | |
| 31 | 34 | |
| 32 | 35 | const check = exe.checkObject(); |
| 33 | 36 | check.checkInHeaders(); |
test/standalone/issue_11595/build.zig+13-11| ... | ... | @@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void { |
| 15 | 15 | |
| 16 | 16 | const exe = b.addExecutable(.{ |
| 17 | 17 | .name = "zigtest", |
| 18 | .root_source_file = b.path("main.zig"), | |
| 19 | .target = target, | |
| 20 | .optimize = optimize, | |
| 18 | .root_module = b.createModule(.{ | |
| 19 | .root_source_file = b.path("main.zig"), | |
| 20 | .target = target, | |
| 21 | .optimize = optimize, | |
| 22 | }), | |
| 21 | 23 | }); |
| 22 | 24 | b.installArtifact(exe); |
| 23 | 25 | |
| ... | ... | @@ -25,21 +27,21 @@ pub fn build(b: *std.Build) void { |
| 25 | 27 | "test.c", |
| 26 | 28 | }; |
| 27 | 29 | |
| 28 | exe.addCSourceFiles(.{ .files = &c_sources }); | |
| 29 | exe.linkLibC(); | |
| 30 | exe.root_module.addCSourceFiles(.{ .files = &c_sources }); | |
| 31 | exe.root_module.link_libc = true; | |
| 30 | 32 | |
| 31 | 33 | var i: i32 = 0; |
| 32 | 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"); | |
| 37 | exe.defineCMacro("BAR", "\"BAR\""); | |
| 38 | exe.defineCMacro("BAZ", | |
| 38 | exe.root_module.addCMacro("FOO", "42"); | |
| 39 | exe.root_module.addCMacro("BAR", "\"BAR\""); | |
| 40 | exe.root_module.addCMacro("BAZ", | |
| 39 | 41 | \\"\"BAZ\"" |
| 40 | 42 | ); |
| 41 | exe.defineCMacro("QUX", "\"Q\" \"UX\""); | |
| 42 | exe.defineCMacro("QUUX", "\"QU\\\"UX\""); | |
| 43 | exe.root_module.addCMacro("QUX", "\"Q\" \"UX\""); | |
| 44 | exe.root_module.addCMacro("QUUX", "\"QU\\\"UX\""); | |
| 43 | 45 | |
| 44 | 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 | 10 | |
| 11 | 11 | const exe = b.addExecutable(.{ |
| 12 | 12 | .name = "main", |
| 13 | .root_source_file = b.path("main.zig"), | |
| 14 | .optimize = optimize, | |
| 15 | .target = target, | |
| 13 | .root_module = b.createModule(.{ | |
| 14 | .root_source_file = b.path("main.zig"), | |
| 15 | .optimize = optimize, | |
| 16 | .target = target, | |
| 17 | }), | |
| 16 | 18 | }); |
| 17 | 19 | |
| 18 | 20 | const c_sources = [_][]const u8{ |
| 19 | 21 | "test.c", |
| 20 | 22 | }; |
| 21 | exe.addCSourceFiles(.{ .files = &c_sources }); | |
| 22 | exe.linkLibC(); | |
| 23 | exe.root_module.addCSourceFiles(.{ .files = &c_sources }); | |
| 24 | exe.root_module.link_libc = true; | |
| 23 | 25 | |
| 24 | 26 | const run_cmd = b.addRunArtifact(exe); |
| 25 | 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 | 5 | b.default_step = test_step; |
| 6 | 6 | |
| 7 | 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 | 12 | .test_runner = "src/main.zig", |
| 10 | 13 | }); |
| 11 | 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 | 19 | .test_runner = "src/main.zig", |
| 14 | 20 | }); |
| 15 | 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 | 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 | |
| 10 | 10 | const obj = b.addObject(.{ |
| 11 | 11 | .name = "test", |
| 12 | .root_source_file = b.path("test.zig"), | |
| 13 | .target = target, | |
| 14 | .optimize = optimize, | |
| 12 | .root_module = b.createModule(.{ | |
| 13 | .root_source_file = b.path("test.zig"), | |
| 14 | .target = target, | |
| 15 | .optimize = optimize, | |
| 16 | }), | |
| 15 | 17 | }); |
| 16 | 18 | |
| 17 | 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 | 16 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 17 | 17 | const obj = b.addObject(.{ |
| 18 | 18 | .name = "issue_5825", |
| 19 | .root_source_file = b.path("main.zig"), | |
| 20 | .optimize = optimize, | |
| 21 | .target = target, | |
| 19 | .root_module = b.createModule(.{ | |
| 20 | .root_source_file = b.path("main.zig"), | |
| 21 | .optimize = optimize, | |
| 22 | .target = target, | |
| 23 | }), | |
| 22 | 24 | }); |
| 23 | 25 | |
| 24 | 26 | const exe = b.addExecutable(.{ |
| 25 | 27 | .name = "issue_5825", |
| 26 | .optimize = optimize, | |
| 27 | .target = target, | |
| 28 | .root_module = b.createModule(.{ | |
| 29 | .root_source_file = null, | |
| 30 | .optimize = optimize, | |
| 31 | .target = target, | |
| 32 | }), | |
| 28 | 33 | }); |
| 29 | 34 | exe.subsystem = .Console; |
| 30 | exe.linkSystemLibrary("kernel32"); | |
| 31 | exe.linkSystemLibrary("ntdll"); | |
| 32 | exe.addObject(obj); | |
| 35 | exe.root_module.linkSystemLibrary("kernel32", .{}); | |
| 36 | exe.root_module.linkSystemLibrary("ntdll", .{}); | |
| 37 | exe.root_module.addObject(obj); | |
| 33 | 38 | |
| 34 | 39 | // TODO: actually check the output |
| 35 | 40 | _ = exe.getEmittedBin(); |
test/standalone/issue_794/build.zig+3-2| ... | ... | @@ -4,9 +4,10 @@ pub fn build(b: *std.Build) void { |
| 4 | 4 | const test_step = b.step("test", "Test it"); |
| 5 | 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 | 8 | .root_source_file = b.path("main.zig"), |
| 9 | }); | |
| 9 | .target = b.graph.host, | |
| 10 | }) }); | |
| 10 | 11 | test_artifact.addIncludePath(b.path("a_directory")); |
| 11 | 12 | |
| 12 | 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 | 15 | |
| 16 | 16 | const kernel = b.addExecutable(.{ |
| 17 | 17 | .name = "kernel", |
| 18 | .root_source_file = b.path("./main.zig"), | |
| 19 | .optimize = optimize, | |
| 20 | .target = target, | |
| 18 | .root_module = b.createModule(.{ | |
| 19 | .root_source_file = b.path("./main.zig"), | |
| 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 | 25 | kernel.setLinkerScript(b.path("./linker.ld")); |
| 24 | 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 | 11 | { |
| 12 | 12 | const exe = b.addExecutable(.{ |
| 13 | 13 | .name = "mt", |
| 14 | .root_source_file = b.path("mt.zig"), | |
| 15 | .target = target, | |
| 16 | .optimize = optimize, | |
| 14 | .root_module = b.createModule(.{ | |
| 15 | .root_source_file = b.path("mt.zig"), | |
| 16 | .target = target, | |
| 17 | .optimize = optimize, | |
| 18 | .link_libcpp = true, | |
| 19 | }), | |
| 17 | 20 | }); |
| 18 | exe.linkLibCpp(); | |
| 19 | exe.addCSourceFile(.{ .file = b.path("mt_doit.cpp") }); | |
| 21 | exe.root_module.addCSourceFile(.{ .file = b.path("mt_doit.cpp") }); | |
| 20 | 22 | link_step.dependOn(&exe.step); |
| 21 | 23 | b.installArtifact(exe); |
| 22 | 24 | run_step.dependOn(&b.addRunArtifact(exe).step); |
| ... | ... | @@ -24,13 +26,15 @@ pub fn build(b: *std.Build) void { |
| 24 | 26 | { |
| 25 | 27 | const exe = b.addExecutable(.{ |
| 26 | 28 | .name = "st", |
| 27 | .root_source_file = b.path("st.zig"), | |
| 28 | .target = target, | |
| 29 | .optimize = optimize, | |
| 30 | .single_threaded = true, | |
| 29 | .root_module = b.createModule(.{ | |
| 30 | .root_source_file = b.path("st.zig"), | |
| 31 | .target = target, | |
| 32 | .optimize = optimize, | |
| 33 | .link_libcpp = true, | |
| 34 | .single_threaded = true, | |
| 35 | }), | |
| 31 | 36 | }); |
| 32 | exe.linkLibCpp(); | |
| 33 | exe.addCSourceFile(.{ .file = b.path("st_doit.cpp") }); | |
| 37 | exe.root_module.addCSourceFile(.{ .file = b.path("st_doit.cpp") }); | |
| 34 | 38 | link_step.dependOn(&exe.step); |
| 35 | 39 | b.installArtifact(exe); |
| 36 | 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 | 12 | |
| 13 | 13 | const lib = b.addSharedLibrary(.{ |
| 14 | 14 | .name = "add", |
| 15 | .root_source_file = b.path("add.zig"), | |
| 16 | 15 | .version = .{ .major = 1, .minor = 0, .patch = 0 }, |
| 17 | .optimize = optimize, | |
| 18 | .target = target, | |
| 16 | .root_module = b.createModule(.{ | |
| 17 | .root_source_file = b.path("add.zig"), | |
| 18 | .optimize = optimize, | |
| 19 | .target = target, | |
| 20 | }), | |
| 19 | 21 | }); |
| 20 | 22 | |
| 21 | 23 | const main = b.addExecutable(.{ |
| 22 | 24 | .name = "main", |
| 23 | .root_source_file = b.path("main.zig"), | |
| 24 | .optimize = optimize, | |
| 25 | .target = target, | |
| 25 | .root_module = b.createModule(.{ | |
| 26 | .root_source_file = b.path("main.zig"), | |
| 27 | .optimize = optimize, | |
| 28 | .target = target, | |
| 29 | }), | |
| 26 | 30 | }); |
| 27 | 31 | |
| 28 | 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 | 18 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 19 | 19 | const exe = b.addExecutable(.{ |
| 20 | 20 | .name = "test", |
| 21 | .root_source_file = b.path("main.zig"), | |
| 22 | .target = b.graph.host, | |
| 23 | .optimize = optimize, | |
| 21 | .root_module = b.createModule(.{ | |
| 22 | .root_source_file = b.path("main.zig"), | |
| 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"} }); | |
| 26 | exe.linkLibC(); | |
| 28 | exe.root_module.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[_][]const u8{"-std=c11"} }); | |
| 27 | 29 | |
| 28 | 30 | const run_cmd = b.addRunArtifact(exe); |
| 29 | 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 | 9 | |
| 10 | 10 | const obj = b.addObject(.{ |
| 11 | 11 | .name = "base64", |
| 12 | .root_source_file = b.path("base64.zig"), | |
| 13 | .optimize = optimize, | |
| 14 | .target = target, | |
| 12 | .root_module = b.createModule(.{ | |
| 13 | .root_source_file = b.path("base64.zig"), | |
| 14 | .optimize = optimize, | |
| 15 | .target = target, | |
| 16 | }), | |
| 15 | 17 | }); |
| 16 | 18 | |
| 17 | 19 | const exe = b.addExecutable(.{ |
| 18 | 20 | .name = "test", |
| 19 | .optimize = optimize, | |
| 20 | .target = target, | |
| 21 | .root_module = b.createModule(.{ | |
| 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 | 29 | .file = b.path("test.c"), |
| 24 | 30 | .flags = &[_][]const u8{"-std=c99"}, |
| 25 | 31 | }); |
| 26 | exe.addObject(obj); | |
| 27 | exe.linkSystemLibrary("c"); | |
| 32 | exe.root_module.addObject(obj); | |
| 28 | 33 | |
| 29 | 34 | b.default_step.dependOn(&exe.step); |
| 30 | 35 |
test/standalone/options/build.zig+2-2| ... | ... | @@ -1,11 +1,11 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | |
| 3 | 3 | pub fn build(b: *std.Build) void { |
| 4 | const main = b.addTest(.{ | |
| 4 | const main = b.addTest(.{ .root_module = b.createModule(.{ | |
| 5 | 5 | .root_source_file = b.path("src/main.zig"), |
| 6 | 6 | .target = b.graph.host, |
| 7 | 7 | .optimize = .Debug, |
| 8 | }); | |
| 8 | }) }); | |
| 9 | 9 | |
| 10 | 10 | const options = b.addOptions(); |
| 11 | 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 | 11 | }); |
| 12 | 12 | |
| 13 | 13 | const main = b.addTest(.{ |
| 14 | .root_source_file = b.path("main.zig"), | |
| 15 | .optimize = optimize, | |
| 16 | .target = target, | |
| 14 | .root_module = b.createModule(.{ | |
| 15 | .root_source_file = b.path("main.zig"), | |
| 16 | .optimize = optimize, | |
| 17 | .target = target, | |
| 18 | }), | |
| 17 | 19 | }); |
| 18 | 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 | 8 | |
| 9 | 9 | const exe = b.addExecutable(.{ |
| 10 | 10 | .name = "test", |
| 11 | .root_source_file = b.path("test.zig"), | |
| 12 | .optimize = optimize, | |
| 13 | .target = b.graph.host, | |
| 11 | .root_module = b.createModule(.{ | |
| 12 | .root_source_file = b.path("test.zig"), | |
| 13 | .optimize = optimize, | |
| 14 | .target = b.graph.host, | |
| 15 | }), | |
| 14 | 16 | }); |
| 15 | 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 | |
| 10 | 10 | const exe = b.addExecutable(.{ |
| 11 | 11 | .name = "create-file", |
| 12 | .root_source_file = b.path("main.zig"), | |
| 13 | .target = target, | |
| 14 | .optimize = optimize, | |
| 12 | .root_module = b.createModule(.{ | |
| 13 | .root_source_file = b.path("main.zig"), | |
| 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 | |
| 10 | 10 | const create_file_exe = b.addExecutable(.{ |
| 11 | 11 | .name = "create_file", |
| 12 | .root_source_file = b.path("create_file.zig"), | |
| 13 | .target = target, | |
| 14 | .optimize = optimize, | |
| 12 | .root_module = b.createModule(.{ | |
| 13 | .root_source_file = b.path("create_file.zig"), | |
| 14 | .target = target, | |
| 15 | .optimize = optimize, | |
| 16 | }), | |
| 15 | 17 | }); |
| 16 | 18 | |
| 17 | 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 | 15 | |
| 16 | 16 | const main = b.addExecutable(.{ |
| 17 | 17 | .name = "main", |
| 18 | .root_source_file = b.path("main.zig"), | |
| 19 | .optimize = optimize, | |
| 20 | .target = target, | |
| 18 | .root_module = b.createModule(.{ | |
| 19 | .root_source_file = b.path("main.zig"), | |
| 20 | .optimize = optimize, | |
| 21 | .target = target, | |
| 22 | }), | |
| 21 | 23 | }); |
| 22 | 24 | |
| 23 | 25 | const create_symlink_exe = b.addExecutable(.{ |
| 24 | 26 | .name = "create-symlink", |
| 25 | .root_source_file = b.path("create-symlink.zig"), | |
| 26 | .optimize = optimize, | |
| 27 | .target = target, | |
| 27 | .root_module = b.createModule(.{ | |
| 28 | .root_source_file = b.path("create-symlink.zig"), | |
| 29 | .optimize = optimize, | |
| 30 | .target = target, | |
| 31 | }), | |
| 28 | 32 | }); |
| 29 | 33 | |
| 30 | 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 | 8 | const target = b.graph.host; |
| 9 | 9 | const lib = b.addSharedLibrary(.{ |
| 10 | 10 | .name = "mathtest", |
| 11 | .root_source_file = b.path("mathtest.zig"), | |
| 12 | 11 | .version = .{ .major = 1, .minor = 0, .patch = 0 }, |
| 13 | .target = target, | |
| 14 | .optimize = optimize, | |
| 12 | .root_module = b.createModule(.{ | |
| 13 | .root_source_file = b.path("mathtest.zig"), | |
| 14 | .target = target, | |
| 15 | .optimize = optimize, | |
| 16 | }), | |
| 15 | 17 | }); |
| 16 | 18 | |
| 17 | 19 | const exe = b.addExecutable(.{ |
| 18 | 20 | .name = "test", |
| 19 | .target = target, | |
| 20 | .optimize = optimize, | |
| 21 | .root_module = b.createModule(.{ | |
| 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 | 29 | .file = b.path("test.c"), |
| 24 | 30 | .flags = &[_][]const u8{"-std=c99"}, |
| 25 | 31 | }); |
| 26 | exe.linkLibrary(lib); | |
| 27 | exe.linkSystemLibrary("c"); | |
| 32 | exe.root_module.linkLibrary(lib); | |
| 28 | 33 | |
| 29 | 34 | const run_cmd = b.addRunArtifact(exe); |
| 30 | 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 | 42 | if (case.is_exe) { |
| 43 | 43 | const exe = b.addExecutable(.{ |
| 44 | 44 | .name = std.fs.path.stem(case.src_path), |
| 45 | .root_source_file = b.path(case.src_path), | |
| 46 | .optimize = optimize, | |
| 47 | .target = resolved_target, | |
| 45 | .root_module = b.createModule(.{ | |
| 46 | .root_source_file = b.path(case.src_path), | |
| 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 | 53 | _ = exe.getEmittedBin(); |
| 52 | 54 | |
| ... | ... | @@ -56,11 +58,13 @@ pub fn build(b: *std.Build) void { |
| 56 | 58 | if (case.is_test) { |
| 57 | 59 | const exe = b.addTest(.{ |
| 58 | 60 | .name = std.fs.path.stem(case.src_path), |
| 59 | .root_source_file = b.path(case.src_path), | |
| 60 | .optimize = optimize, | |
| 61 | .target = resolved_target, | |
| 61 | .root_module = b.createModule(.{ | |
| 62 | .root_source_file = b.path(case.src_path), | |
| 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 | 69 | const run = b.addRunArtifact(exe); |
| 66 | 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 | 20 | { |
| 21 | 21 | const exe = b.addExecutable(.{ |
| 22 | 22 | .name = "unwind_fp", |
| 23 | .root_source_file = b.path("unwind.zig"), | |
| 24 | .target = target, | |
| 25 | .optimize = optimize, | |
| 26 | .unwind_tables = if (target.result.isDarwin()) .@"async" else null, | |
| 27 | .omit_frame_pointer = false, | |
| 23 | .root_module = b.createModule(.{ | |
| 24 | .root_source_file = b.path("unwind.zig"), | |
| 25 | .target = target, | |
| 26 | .optimize = optimize, | |
| 27 | .unwind_tables = if (target.result.isDarwin()) .@"async" else null, | |
| 28 | .omit_frame_pointer = false, | |
| 29 | }), | |
| 28 | 30 | }); |
| 29 | 31 | |
| 30 | 32 | const run_cmd = b.addRunArtifact(exe); |
| ... | ... | @@ -43,11 +45,13 @@ pub fn build(b: *std.Build) void { |
| 43 | 45 | { |
| 44 | 46 | const exe = b.addExecutable(.{ |
| 45 | 47 | .name = "unwind_nofp", |
| 46 | .root_source_file = b.path("unwind.zig"), | |
| 47 | .target = target, | |
| 48 | .optimize = optimize, | |
| 49 | .unwind_tables = .@"async", | |
| 50 | .omit_frame_pointer = true, | |
| 48 | .root_module = b.createModule(.{ | |
| 49 | .root_source_file = b.path("unwind.zig"), | |
| 50 | .target = target, | |
| 51 | .optimize = optimize, | |
| 52 | .unwind_tables = .@"async", | |
| 53 | .omit_frame_pointer = true, | |
| 54 | }), | |
| 51 | 55 | }); |
| 52 | 56 | |
| 53 | 57 | const run_cmd = b.addRunArtifact(exe); |
| ... | ... | @@ -66,27 +70,32 @@ pub fn build(b: *std.Build) void { |
| 66 | 70 | { |
| 67 | 71 | const c_shared_lib = b.addSharedLibrary(.{ |
| 68 | 72 | .name = "c_shared_lib", |
| 69 | .target = target, | |
| 70 | .optimize = optimize, | |
| 71 | .strip = false, | |
| 73 | .root_module = b.createModule(.{ | |
| 74 | .root_source_file = null, | |
| 75 | .target = target, | |
| 76 | .optimize = optimize, | |
| 77 | .link_libc = true, | |
| 78 | .strip = false, | |
| 79 | }), | |
| 72 | 80 | }); |
| 73 | 81 | |
| 74 | 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 | 86 | .file = b.path("shared_lib.c"), |
| 79 | 87 | .flags = &.{"-fomit-frame-pointer"}, |
| 80 | 88 | }); |
| 81 | c_shared_lib.linkLibC(); | |
| 82 | 89 | |
| 83 | 90 | const exe = b.addExecutable(.{ |
| 84 | 91 | .name = "shared_lib_unwind", |
| 85 | .root_source_file = b.path("shared_lib_unwind.zig"), | |
| 86 | .target = target, | |
| 87 | .optimize = optimize, | |
| 88 | .unwind_tables = if (target.result.isDarwin()) .@"async" else null, | |
| 89 | .omit_frame_pointer = true, | |
| 92 | .root_module = b.createModule(.{ | |
| 93 | .root_source_file = b.path("shared_lib_unwind.zig"), | |
| 94 | .target = target, | |
| 95 | .optimize = optimize, | |
| 96 | .unwind_tables = if (target.result.isDarwin()) .@"async" else null, | |
| 97 | .omit_frame_pointer = true, | |
| 98 | }), | |
| 90 | 99 | }); |
| 91 | 100 | |
| 92 | 101 | exe.linkLibrary(c_shared_lib); |
| ... | ... | @@ -117,14 +126,16 @@ pub fn build(b: *std.Build) void { |
| 117 | 126 | inline for (no_os_targets) |os_tag| { |
| 118 | 127 | const exe = b.addExecutable(.{ |
| 119 | 128 | .name = "unwind_freestanding", |
| 120 | .root_source_file = b.path("unwind_freestanding.zig"), | |
| 121 | .target = b.resolveTargetQuery(.{ | |
| 122 | .cpu_arch = .x86_64, | |
| 123 | .os_tag = os_tag, | |
| 129 | .root_module = b.createModule(.{ | |
| 130 | .root_source_file = b.path("unwind_freestanding.zig"), | |
| 131 | .target = b.resolveTargetQuery(.{ | |
| 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 | 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 | 8 | |
| 9 | 9 | const foo = b.addStaticLibrary(.{ |
| 10 | 10 | .name = "foo", |
| 11 | .optimize = optimize, | |
| 12 | .target = b.graph.host, | |
| 11 | .root_module = b.createModule(.{ | |
| 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{} }); | |
| 15 | foo.addIncludePath(b.path(".")); | |
| 17 | foo.root_module.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &[_][]const u8{} }); | |
| 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 | 21 | .root_source_file = b.path("foo.zig"), |
| 22 | .target = b.graph.host, | |
| 19 | 23 | .optimize = optimize, |
| 20 | }); | |
| 21 | test_exe.linkLibrary(foo); | |
| 22 | test_exe.addIncludePath(b.path(".")); | |
| 24 | }) }); | |
| 25 | test_exe.root_module.linkLibrary(foo); | |
| 26 | test_exe.root_module.addIncludePath(b.path(".")); | |
| 23 | 27 | |
| 24 | 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 | 9 | |
| 10 | 10 | const main = b.addExecutable(.{ |
| 11 | 11 | .name = "main", |
| 12 | .root_source_file = b.path("main.zig"), | |
| 13 | .optimize = optimize, | |
| 14 | .target = target, | |
| 15 | .strip = true, | |
| 12 | .root_module = b.createModule(.{ | |
| 13 | .root_source_file = b.path("main.zig"), | |
| 14 | .optimize = optimize, | |
| 15 | .target = target, | |
| 16 | .strip = true, | |
| 17 | }), | |
| 16 | 18 | }); |
| 17 | 19 | |
| 18 | 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 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | |
| 9 | 9 | const main = b.addTest(.{ |
| 10 | .root_source_file = b.path("main.zig"), | |
| 11 | .optimize = optimize, | |
| 12 | .strip = true, | |
| 10 | .root_module = b.createModule(.{ | |
| 11 | .root_source_file = b.path("main.zig"), | |
| 12 | .target = b.graph.host, | |
| 13 | .optimize = optimize, | |
| 14 | .strip = true, | |
| 15 | }), | |
| 13 | 16 | }); |
| 14 | 17 | |
| 15 | 18 | test_step.dependOn(&b.addRunArtifact(main).step); |
test/standalone/test_runner_module_imports/build.zig+10-8| ... | ... | @@ -1,18 +1,20 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | |
| 3 | 3 | pub fn build(b: *std.Build) void { |
| 4 | const t = b.addTest(.{ | |
| 4 | const test_mod = b.createModule(.{ | |
| 5 | 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 | 8 | const module1 = b.createModule(.{ .root_source_file = b.path("module1/main.zig") }); |
| 10 | const module2 = b.createModule(.{ | |
| 11 | .root_source_file = b.path("module2/main.zig"), | |
| 12 | .imports = &.{.{ .name = "module1", .module = module1 }}, | |
| 13 | }); | |
| 9 | const module2 = b.createModule(.{ .root_source_file = b.path("module2/main.zig") }); | |
| 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 | 19 | const test_step = b.step("test", "Run unit tests"); |
| 18 | 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 | 6 | const test_step = b.step("test", "Test the program"); |
| 7 | 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 | 11 | .root_source_file = b.path("test.zig"), |
| 11 | }); | |
| 12 | }) }); | |
| 12 | 13 | test_exe.test_runner = b.path("test_runner.zig"); |
| 13 | 14 | |
| 14 | 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 | 6 | |
| 7 | 7 | const optimize: std.builtin.OptimizeMode = .Debug; |
| 8 | 8 | |
| 9 | const main = b.addTest(.{ | |
| 9 | const main = b.addTest(.{ .root_module = b.createModule(.{ | |
| 10 | 10 | .root_source_file = b.path("main.zig"), |
| 11 | .target = b.graph.host, | |
| 11 | 12 | .optimize = optimize, |
| 12 | }); | |
| 13 | main.addIncludePath(b.path(".")); | |
| 13 | }) }); | |
| 14 | main.root_module.addIncludePath(b.path(".")); | |
| 14 | 15 | |
| 15 | 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 | 11 | |
| 12 | 12 | const lib_gnu = b.addStaticLibrary(.{ |
| 13 | 13 | .name = "toargv-gnu", |
| 14 | .root_source_file = b.path("lib.zig"), | |
| 15 | .target = b.resolveTargetQuery(.{ | |
| 16 | .abi = .gnu, | |
| 14 | .root_module = b.createModule(.{ | |
| 15 | .root_source_file = b.path("lib.zig"), | |
| 16 | .target = b.resolveTargetQuery(.{ | |
| 17 | .abi = .gnu, | |
| 18 | }), | |
| 19 | .optimize = optimize, | |
| 17 | 20 | }), |
| 18 | .optimize = optimize, | |
| 19 | 21 | }); |
| 20 | 22 | const verify_gnu = b.addExecutable(.{ |
| 21 | 23 | .name = "verify-gnu", |
| 22 | .target = b.resolveTargetQuery(.{ | |
| 23 | .abi = .gnu, | |
| 24 | .root_module = b.createModule(.{ | |
| 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 | 33 | .file = b.path("verify.c"), |
| 29 | 34 | .flags = &.{ "-DUNICODE", "-D_UNICODE" }, |
| 30 | 35 | }); |
| 31 | 36 | verify_gnu.mingw_unicode_entry_point = true; |
| 32 | verify_gnu.linkLibrary(lib_gnu); | |
| 33 | verify_gnu.linkLibC(); | |
| 37 | verify_gnu.root_module.linkLibrary(lib_gnu); | |
| 38 | verify_gnu.root_module.link_libc = true; | |
| 34 | 39 | |
| 35 | 40 | const fuzz = b.addExecutable(.{ |
| 36 | 41 | .name = "fuzz", |
| 37 | .root_source_file = b.path("fuzz.zig"), | |
| 38 | .target = b.graph.host, | |
| 39 | .optimize = optimize, | |
| 42 | .root_module = b.createModule(.{ | |
| 43 | .root_source_file = b.path("fuzz.zig"), | |
| 44 | .target = b.graph.host, | |
| 45 | .optimize = optimize, | |
| 46 | }), | |
| 40 | 47 | }); |
| 41 | 48 | |
| 42 | 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 | 76 | if (has_msvc) { |
| 70 | 77 | const lib_msvc = b.addStaticLibrary(.{ |
| 71 | 78 | .name = "toargv-msvc", |
| 72 | .root_source_file = b.path("lib.zig"), | |
| 73 | .target = b.resolveTargetQuery(.{ | |
| 74 | .abi = .msvc, | |
| 79 | .root_module = b.createModule(.{ | |
| 80 | .root_source_file = b.path("lib.zig"), | |
| 81 | .target = b.resolveTargetQuery(.{ | |
| 82 | .abi = .msvc, | |
| 83 | }), | |
| 84 | .optimize = optimize, | |
| 75 | 85 | }), |
| 76 | .optimize = optimize, | |
| 77 | 86 | }); |
| 78 | 87 | const verify_msvc = b.addExecutable(.{ |
| 79 | 88 | .name = "verify-msvc", |
| 80 | .target = b.resolveTargetQuery(.{ | |
| 81 | .abi = .msvc, | |
| 89 | .root_module = b.createModule(.{ | |
| 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 | 98 | .file = b.path("verify.c"), |
| 87 | 99 | .flags = &.{ "-DUNICODE", "-D_UNICODE" }, |
| 88 | 100 | }); |
| 89 | verify_msvc.linkLibrary(lib_msvc); | |
| 90 | verify_msvc.linkLibC(); | |
| 101 | verify_msvc.root_module.linkLibrary(lib_msvc); | |
| 102 | verify_msvc.root_module.link_libc = true; | |
| 91 | 103 | |
| 92 | 104 | const run_msvc = b.addRunArtifact(fuzz); |
| 93 | 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 | 12 | |
| 13 | 13 | const echo_args = b.addExecutable(.{ |
| 14 | 14 | .name = "echo-args", |
| 15 | .root_source_file = b.path("echo-args.zig"), | |
| 16 | .optimize = optimize, | |
| 17 | .target = target, | |
| 15 | .root_module = b.createModule(.{ | |
| 16 | .root_source_file = b.path("echo-args.zig"), | |
| 17 | .optimize = optimize, | |
| 18 | .target = target, | |
| 19 | }), | |
| 18 | 20 | }); |
| 19 | 21 | |
| 20 | 22 | const test_exe = b.addExecutable(.{ |
| 21 | 23 | .name = "test", |
| 22 | .root_source_file = b.path("test.zig"), | |
| 23 | .optimize = optimize, | |
| 24 | .target = target, | |
| 24 | .root_module = b.createModule(.{ | |
| 25 | .root_source_file = b.path("test.zig"), | |
| 26 | .optimize = optimize, | |
| 27 | .target = target, | |
| 28 | }), | |
| 25 | 29 | }); |
| 26 | 30 | |
| 27 | 31 | const run = b.addRunArtifact(test_exe); |
| ... | ... | @@ -33,9 +37,11 @@ pub fn build(b: *std.Build) !void { |
| 33 | 37 | |
| 34 | 38 | const fuzz = b.addExecutable(.{ |
| 35 | 39 | .name = "fuzz", |
| 36 | .root_source_file = b.path("fuzz.zig"), | |
| 37 | .optimize = optimize, | |
| 38 | .target = target, | |
| 40 | .root_module = b.createModule(.{ | |
| 41 | .root_source_file = b.path("fuzz.zig"), | |
| 42 | .optimize = optimize, | |
| 43 | .target = target, | |
| 44 | }), | |
| 39 | 45 | }); |
| 40 | 46 | |
| 41 | 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 | 13 | { |
| 14 | 14 | const exe = b.addExecutable(.{ |
| 15 | 15 | .name = "main", |
| 16 | .target = target, | |
| 17 | .optimize = .Debug, | |
| 18 | .link_libc = true, | |
| 16 | .root_module = b.createModule(.{ | |
| 17 | .root_source_file = null, | |
| 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 | 25 | _ = exe.getEmittedBin(); |
| 23 | 26 | test_step.dependOn(&exe.step); |
| ... | ... | @@ -26,12 +29,15 @@ pub fn build(b: *std.Build) void { |
| 26 | 29 | { |
| 27 | 30 | const exe = b.addExecutable(.{ |
| 28 | 31 | .name = "wmain", |
| 29 | .target = target, | |
| 30 | .optimize = .Debug, | |
| 31 | .link_libc = true, | |
| 32 | .root_module = b.createModule(.{ | |
| 33 | .root_source_file = null, | |
| 34 | .target = target, | |
| 35 | .optimize = .Debug, | |
| 36 | .link_libc = true, | |
| 37 | }), | |
| 32 | 38 | }); |
| 33 | 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 | 42 | _ = exe.getEmittedBin(); |
| 37 | 43 | test_step.dependOn(&exe.step); |
| ... | ... | @@ -40,12 +46,15 @@ pub fn build(b: *std.Build) void { |
| 40 | 46 | { |
| 41 | 47 | const exe = b.addExecutable(.{ |
| 42 | 48 | .name = "winmain", |
| 43 | .target = target, | |
| 44 | .optimize = .Debug, | |
| 45 | .link_libc = true, | |
| 49 | .root_module = b.createModule(.{ | |
| 50 | .root_source_file = null, | |
| 51 | .target = target, | |
| 52 | .optimize = .Debug, | |
| 53 | .link_libc = true, | |
| 54 | }), | |
| 46 | 55 | }); |
| 47 | 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 | 59 | _ = exe.getEmittedBin(); |
| 51 | 60 | test_step.dependOn(&exe.step); |
| ... | ... | @@ -54,13 +63,16 @@ pub fn build(b: *std.Build) void { |
| 54 | 63 | { |
| 55 | 64 | const exe = b.addExecutable(.{ |
| 56 | 65 | .name = "wwinmain", |
| 57 | .target = target, | |
| 58 | .optimize = .Debug, | |
| 59 | .link_libc = true, | |
| 66 | .root_module = b.createModule(.{ | |
| 67 | .root_source_file = null, | |
| 68 | .target = target, | |
| 69 | .optimize = .Debug, | |
| 70 | .link_libc = true, | |
| 71 | }), | |
| 60 | 72 | }); |
| 61 | 73 | exe.mingw_unicode_entry_point = true; |
| 62 | 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 | 77 | _ = exe.getEmittedBin(); |
| 66 | 78 | test_step.dependOn(&exe.step); |
test/standalone/windows_resources/build.zig+6-4| ... | ... | @@ -28,11 +28,13 @@ fn add( |
| 28 | 28 | ) void { |
| 29 | 29 | const exe = b.addExecutable(.{ |
| 30 | 30 | .name = "zig_resource_test", |
| 31 | .root_source_file = b.path("main.zig"), | |
| 32 | .target = target, | |
| 33 | .optimize = .Debug, | |
| 31 | .root_module = b.createModule(.{ | |
| 32 | .root_source_file = b.path("main.zig"), | |
| 33 | .target = target, | |
| 34 | .optimize = .Debug, | |
| 35 | }), | |
| 34 | 36 | }); |
| 35 | exe.addWin32ResourceFile(.{ | |
| 37 | exe.root_module.addWin32ResourceFile(.{ | |
| 36 | 38 | .file = b.path("res/zig.rc"), |
| 37 | 39 | .flags = &.{"/c65001"}, // UTF-8 code page |
| 38 | 40 | .include_paths = &.{ |
test/standalone/windows_spawn/build.zig+10-6| ... | ... | @@ -12,16 +12,20 @@ pub fn build(b: *std.Build) void { |
| 12 | 12 | |
| 13 | 13 | const hello = b.addExecutable(.{ |
| 14 | 14 | .name = "hello", |
| 15 | .root_source_file = b.path("hello.zig"), | |
| 16 | .optimize = optimize, | |
| 17 | .target = target, | |
| 15 | .root_module = b.createModule(.{ | |
| 16 | .root_source_file = b.path("hello.zig"), | |
| 17 | .optimize = optimize, | |
| 18 | .target = target, | |
| 19 | }), | |
| 18 | 20 | }); |
| 19 | 21 | |
| 20 | 22 | const main = b.addExecutable(.{ |
| 21 | 23 | .name = "main", |
| 22 | .root_source_file = b.path("main.zig"), | |
| 23 | .optimize = optimize, | |
| 24 | .target = target, | |
| 24 | .root_module = b.createModule(.{ | |
| 25 | .root_source_file = b.path("main.zig"), | |
| 26 | .optimize = optimize, | |
| 27 | .target = target, | |
| 28 | }), | |
| 25 | 29 | }); |
| 26 | 30 | |
| 27 | 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 | 11 | } |
| 12 | 12 | |
| 13 | 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 | 15 | .root_source_file = b.path("src/main.zig"), |
| 16 | 16 | .target = b.resolveTargetQuery(.{ |
| 17 | 17 | .os_tag = .wasi, |
| ... | ... | @@ -19,7 +19,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 19 | 19 | .cpu_features_add = std.Target.wasm.featureSet(&.{.bulk_memory}), |
| 20 | 20 | }), |
| 21 | 21 | .optimize = optimize, |
| 22 | }); | |
| 22 | }) }); | |
| 23 | 23 | |
| 24 | 24 | const run_unit_tests = b.addRunArtifact(unit_tests); |
| 25 | 25 | run_unit_tests.skip_foreign_checks = true; |
test/tests.zig+51-36| ... | ... | @@ -1106,9 +1106,11 @@ pub fn addStackTraceTests( |
| 1106 | 1106 | ) *Step { |
| 1107 | 1107 | const check_exe = b.addExecutable(.{ |
| 1108 | 1108 | .name = "check-stack-trace", |
| 1109 | .root_source_file = b.path("test/src/check-stack-trace.zig"), | |
| 1110 | .target = b.graph.host, | |
| 1111 | .optimize = .Debug, | |
| 1109 | .root_module = b.createModule(.{ | |
| 1110 | .root_source_file = b.path("test/src/check-stack-trace.zig"), | |
| 1111 | .target = b.graph.host, | |
| 1112 | .optimize = .Debug, | |
| 1113 | }), | |
| 1112 | 1114 | }); |
| 1113 | 1115 | |
| 1114 | 1116 | const cases = b.allocator.create(StackTracesContext) catch @panic("OOM"); |
| ... | ... | @@ -1330,7 +1332,7 @@ pub fn addCliTests(b: *std.Build) *Step { |
| 1330 | 1332 | run5.step.dependOn(&run4.step); |
| 1331 | 1333 | |
| 1332 | 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 | 1336 | const write6 = b.addUpdateSourceFiles(); |
| 1335 | 1337 | write6.addBytesToSource(unformatted_code_utf16, fmt6_path); |
| 1336 | 1338 | write6.step.dependOn(&run5.step); |
| ... | ... | @@ -1514,18 +1516,20 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1514 | 1516 | options.max_rss; |
| 1515 | 1517 | |
| 1516 | 1518 | const these_tests = b.addTest(.{ |
| 1517 | .root_source_file = b.path(options.root_src), | |
| 1518 | .optimize = test_target.optimize_mode, | |
| 1519 | .target = resolved_target, | |
| 1519 | .root_module = b.createModule(.{ | |
| 1520 | .root_source_file = b.path(options.root_src), | |
| 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 | 1528 | .max_rss = max_rss, |
| 1521 | 1529 | .filters = options.test_filters, |
| 1522 | .link_libc = test_target.link_libc, | |
| 1523 | .single_threaded = test_target.single_threaded, | |
| 1524 | 1530 | .use_llvm = test_target.use_llvm, |
| 1525 | 1531 | .use_lld = test_target.use_lld, |
| 1526 | 1532 | .zig_lib_dir = b.path("lib"), |
| 1527 | .pic = test_target.pic, | |
| 1528 | .strip = test_target.strip, | |
| 1529 | 1533 | }); |
| 1530 | 1534 | if (options.no_builtin) these_tests.no_builtin = true; |
| 1531 | 1535 | if (options.build_options) |build_options| { |
| ... | ... | @@ -1561,12 +1565,17 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1561 | 1565 | var altered_query = test_target.target; |
| 1562 | 1566 | altered_query.ofmt = null; |
| 1563 | 1567 | |
| 1564 | const compile_c = b.addExecutable(.{ | |
| 1565 | .name = qualified_name, | |
| 1568 | const compile_c = b.createModule(.{ | |
| 1569 | .root_source_file = null, | |
| 1566 | 1570 | .link_libc = test_target.link_libc, |
| 1567 | 1571 | .target = b.resolveTargetQuery(altered_query), |
| 1572 | }); | |
| 1573 | const compile_c_exe = b.addExecutable(.{ | |
| 1574 | .name = qualified_name, | |
| 1575 | .root_module = compile_c, | |
| 1568 | 1576 | .zig_lib_dir = b.path("lib"), |
| 1569 | 1577 | }); |
| 1578 | ||
| 1570 | 1579 | compile_c.addCSourceFile(.{ |
| 1571 | 1580 | .file = these_tests.getEmittedBin(), |
| 1572 | 1581 | .flags = &.{ |
| ... | ... | @@ -1611,22 +1620,22 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1611 | 1620 | continue; |
| 1612 | 1621 | } |
| 1613 | 1622 | if (test_target.link_libc == false) { |
| 1614 | compile_c.subsystem = .Console; | |
| 1615 | compile_c.linkSystemLibrary("kernel32"); | |
| 1616 | compile_c.linkSystemLibrary("ntdll"); | |
| 1623 | compile_c_exe.subsystem = .Console; | |
| 1624 | compile_c.linkSystemLibrary("kernel32", .{}); | |
| 1625 | compile_c.linkSystemLibrary("ntdll", .{}); | |
| 1617 | 1626 | } |
| 1618 | 1627 | if (mem.eql(u8, options.name, "std")) { |
| 1619 | 1628 | if (test_target.link_libc == false) { |
| 1620 | compile_c.linkSystemLibrary("shell32"); | |
| 1621 | compile_c.linkSystemLibrary("advapi32"); | |
| 1629 | compile_c.linkSystemLibrary("shell32", .{}); | |
| 1630 | compile_c.linkSystemLibrary("advapi32", .{}); | |
| 1622 | 1631 | } |
| 1623 | compile_c.linkSystemLibrary("crypt32"); | |
| 1624 | compile_c.linkSystemLibrary("ws2_32"); | |
| 1625 | compile_c.linkSystemLibrary("ole32"); | |
| 1632 | compile_c.linkSystemLibrary("crypt32", .{}); | |
| 1633 | compile_c.linkSystemLibrary("ws2_32", .{}); | |
| 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 | 1639 | run.skip_foreign_checks = true; |
| 1631 | 1640 | run.enableTestRunnerMode(); |
| 1632 | 1641 | run.setName(b.fmt("run test {s}", .{qualified_name})); |
| ... | ... | @@ -1675,6 +1684,20 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step { |
| 1675 | 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 | 1701 | const test_step = b.addTest(.{ |
| 1679 | 1702 | .name = b.fmt("test-c-abi-{s}-{s}-{s}{s}{s}{s}", .{ |
| 1680 | 1703 | triple_txt, |
| ... | ... | @@ -1691,20 +1714,10 @@ pub fn addCAbiTests(b: *std.Build, options: CAbiTestOptions) *Step { |
| 1691 | 1714 | if (c_abi_target.use_lld == false) "-no-lld" else "", |
| 1692 | 1715 | if (c_abi_target.pic == true) "-pic" else "", |
| 1693 | 1716 | }), |
| 1694 | .root_source_file = b.path("test/c_abi/main.zig"), | |
| 1695 | .target = resolved_target, | |
| 1696 | .optimize = optimize_mode, | |
| 1697 | .link_libc = true, | |
| 1717 | .root_module = test_mod, | |
| 1698 | 1718 | .use_llvm = c_abi_target.use_llvm, |
| 1699 | 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 | 1722 | // This test is intentionally trying to check if the external ABI is |
| 1710 | 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 | 1797 | pub fn addIncrementalTests(b: *std.Build, test_step: *Step) !void { |
| 1785 | 1798 | const incr_check = b.addExecutable(.{ |
| 1786 | 1799 | .name = "incr-check", |
| 1787 | .root_source_file = b.path("tools/incr-check.zig"), | |
| 1788 | .target = b.graph.host, | |
| 1789 | .optimize = .Debug, | |
| 1800 | .root_module = b.createModule(.{ | |
| 1801 | .root_source_file = b.path("tools/incr-check.zig"), | |
| 1802 | .target = b.graph.host, | |
| 1803 | .optimize = .Debug, | |
| 1804 | }), | |
| 1790 | 1805 | }); |
| 1791 | 1806 | |
| 1792 | 1807 | var dir = try b.build_root.handle.openDir("test/incremental", .{ .iterate = true }); |