| ... | ... | @@ -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); |