| ... | @@ -28,6 +28,7 @@ const target_util = @import("target.zig"); | ... | @@ -28,6 +28,7 @@ const target_util = @import("target.zig"); |
| 28 | const crash_report = @import("crash_report.zig"); | 28 | const crash_report = @import("crash_report.zig"); |
| 29 | const Module = @import("Module.zig"); | 29 | const Module = @import("Module.zig"); |
| 30 | const AstGen = @import("AstGen.zig"); | 30 | const AstGen = @import("AstGen.zig"); |
| | 31 | const mingw = @import("mingw.zig"); |
| 31 | const Server = std.zig.Server; | 32 | const Server = std.zig.Server; |
| 32 | | 33 | |
| 33 | pub const std_options = struct { | 34 | pub const std_options = struct { |
| ... | @@ -477,6 +478,8 @@ const usage_build_generic = | ... | @@ -477,6 +478,8 @@ const usage_build_generic = |
| 477 | \\ -needed-l[lib], Link against system library (even if unused) | 478 | \\ -needed-l[lib], Link against system library (even if unused) |
| 478 | \\ --needed-library [lib] | 479 | \\ --needed-library [lib] |
| 479 | \\ -L[d], --library-directory [d] Add a directory to the library search path | 480 | \\ -L[d], --library-directory [d] Add a directory to the library search path |
| | 481 | \\ -search_paths_first Search each library search path for dynamic libs then static libs |
| | 482 | \\ -search_dylibs_first Search for dynamic libs in each library search path, then static libs. |
| 480 | \\ -T[script], --script [script] Use a custom linker script | 483 | \\ -T[script], --script [script] Use a custom linker script |
| 481 | \\ --version-script [path] Provide a version .map file | 484 | \\ --version-script [path] Provide a version .map file |
| 482 | \\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so) | 485 | \\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so) |
| ... | @@ -537,8 +540,6 @@ const usage_build_generic = | ... | @@ -537,8 +540,6 @@ const usage_build_generic = |
| 537 | \\ -install_name=[value] (Darwin) add dylib's install name | 540 | \\ -install_name=[value] (Darwin) add dylib's install name |
| 538 | \\ --entitlements [path] (Darwin) add path to entitlements file for embedding in code signature | 541 | \\ --entitlements [path] (Darwin) add path to entitlements file for embedding in code signature |
| 539 | \\ -pagezero_size [value] (Darwin) size of the __PAGEZERO segment in hexadecimal notation | 542 | \\ -pagezero_size [value] (Darwin) size of the __PAGEZERO segment in hexadecimal notation |
| 540 | \\ -search_paths_first (Darwin) search each dir in library search paths for `libx.dylib` then `libx.a` | | |
| 541 | \\ -search_dylibs_first (Darwin) search `libx.dylib` in each dir in library search paths, then `libx.a` | | |
| 542 | \\ -headerpad [value] (Darwin) set minimum space for future expansion of the load commands in hexadecimal notation | 543 | \\ -headerpad [value] (Darwin) set minimum space for future expansion of the load commands in hexadecimal notation |
| 543 | \\ -headerpad_max_install_names (Darwin) set enough space as if all paths were MAXPATHLEN | 544 | \\ -headerpad_max_install_names (Darwin) set enough space as if all paths were MAXPATHLEN |
| 544 | \\ -dead_strip (Darwin) remove functions and data that are unreachable by the entry point or exported symbols | 545 | \\ -dead_strip (Darwin) remove functions and data that are unreachable by the entry point or exported symbols |
| ... | @@ -2567,6 +2568,34 @@ fn buildOutputType( | ... | @@ -2567,6 +2568,34 @@ fn buildOutputType( |
| 2567 | } | 2568 | } |
| 2568 | lib_dir_args = undefined; // From here we use lib_dirs instead. | 2569 | lib_dir_args = undefined; // From here we use lib_dirs instead. |
| 2569 | | 2570 | |
| | 2571 | const self_exe_path: ?[]const u8 = if (!process.can_spawn) |
| | 2572 | null |
| | 2573 | else |
| | 2574 | introspect.findZigExePath(arena) catch |err| { |
| | 2575 | fatal("unable to find zig self exe path: {s}", .{@errorName(err)}); |
| | 2576 | }; |
| | 2577 | |
| | 2578 | var zig_lib_directory: Compilation.Directory = d: { |
| | 2579 | if (override_lib_dir) |unresolved_lib_dir| { |
| | 2580 | const lib_dir = try introspect.resolvePath(arena, unresolved_lib_dir); |
| | 2581 | break :d .{ |
| | 2582 | .path = lib_dir, |
| | 2583 | .handle = fs.cwd().openDir(lib_dir, .{}) catch |err| { |
| | 2584 | fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) }); |
| | 2585 | }, |
| | 2586 | }; |
| | 2587 | } else if (builtin.os.tag == .wasi) { |
| | 2588 | break :d getWasiPreopen("/lib"); |
| | 2589 | } else if (self_exe_path) |p| { |
| | 2590 | break :d introspect.findZigLibDirFromSelfExe(arena, p) catch |err| { |
| | 2591 | fatal("unable to find zig installation directory: {s}", .{@errorName(err)}); |
| | 2592 | }; |
| | 2593 | } else { |
| | 2594 | unreachable; |
| | 2595 | } |
| | 2596 | }; |
| | 2597 | defer zig_lib_directory.handle.close(); |
| | 2598 | |
| 2570 | // Now that we have target info, we can find out if any of the system libraries | 2599 | // Now that we have target info, we can find out if any of the system libraries |
| 2571 | // are part of libc or libc++. We remove them from the list and communicate their | 2600 | // are part of libc or libc++. We remove them from the list and communicate their |
| 2572 | // existence via flags instead. | 2601 | // existence via flags instead. |
| ... | @@ -2612,6 +2641,25 @@ fn buildOutputType( | ... | @@ -2612,6 +2641,25 @@ fn buildOutputType( |
| 2612 | }, | 2641 | }, |
| 2613 | } | 2642 | } |
| 2614 | | 2643 | |
| | 2644 | if (target_info.target.os.tag == .windows) { |
| | 2645 | const exists = mingw.libExists(arena, target_info.target, zig_lib_directory, lib_name) catch |err| { |
| | 2646 | fatal("failed to check zig installation for DLL import libs: {s}", .{ |
| | 2647 | @errorName(err), |
| | 2648 | }); |
| | 2649 | }; |
| | 2650 | if (exists) { |
| | 2651 | try resolved_system_libs.append(arena, .{ |
| | 2652 | .name = lib_name, |
| | 2653 | .lib = .{ |
| | 2654 | .needed = true, |
| | 2655 | .weak = false, |
| | 2656 | .path = undefined, |
| | 2657 | }, |
| | 2658 | }); |
| | 2659 | continue; |
| | 2660 | } |
| | 2661 | } |
| | 2662 | |
| 2615 | if (fs.path.isAbsolute(lib_name)) { | 2663 | if (fs.path.isAbsolute(lib_name)) { |
| 2616 | fatal("cannot use absolute path as a system library: {s}", .{lib_name}); | 2664 | fatal("cannot use absolute path as a system library: {s}", .{lib_name}); |
| 2617 | } | 2665 | } |
| ... | @@ -2758,9 +2806,13 @@ fn buildOutputType( | ... | @@ -2758,9 +2806,13 @@ fn buildOutputType( |
| 2758 | | 2806 | |
| 2759 | if (failed_libs.items.len > 0) { | 2807 | if (failed_libs.items.len > 0) { |
| 2760 | for (failed_libs.items) |f| { | 2808 | for (failed_libs.items) |f| { |
| | 2809 | const searched_paths = if (f.checked_paths.len == 0) " none" else f.checked_paths; |
| 2761 | std.log.err("unable to find {s} system library '{s}' using strategy '{s}'. searched paths:{s}", .{ | 2810 | std.log.err("unable to find {s} system library '{s}' using strategy '{s}'. searched paths:{s}", .{ |
| 2762 | @tagName(f.preferred_mode), f.name, @tagName(f.strategy), f.checked_paths, | 2811 | @tagName(f.preferred_mode), f.name, @tagName(f.strategy), searched_paths, |
| 2763 | }); | 2812 | }); |
| | 2813 | if (f.preferred_mode == .Dynamic and f.strategy == .no_fallback) { |
| | 2814 | std.log.info("to link statically, pass the library as a positional argument", .{}); |
| | 2815 | } |
| 2764 | } | 2816 | } |
| 2765 | process.exit(1); | 2817 | process.exit(1); |
| 2766 | } | 2818 | } |
| ... | @@ -3079,35 +3131,6 @@ fn buildOutputType( | ... | @@ -3079,35 +3131,6 @@ fn buildOutputType( |
| 3079 | } | 3131 | } |
| 3080 | } | 3132 | } |
| 3081 | | 3133 | |
| 3082 | const self_exe_path: ?[]const u8 = if (!process.can_spawn) | | |
| 3083 | null | | |
| 3084 | else | | |
| 3085 | introspect.findZigExePath(arena) catch |err| { | | |
| 3086 | fatal("unable to find zig self exe path: {s}", .{@errorName(err)}); | | |
| 3087 | }; | | |
| 3088 | | | |
| 3089 | var zig_lib_directory: Compilation.Directory = d: { | | |
| 3090 | if (override_lib_dir) |unresolved_lib_dir| { | | |
| 3091 | const lib_dir = try introspect.resolvePath(arena, unresolved_lib_dir); | | |
| 3092 | break :d .{ | | |
| 3093 | .path = lib_dir, | | |
| 3094 | .handle = fs.cwd().openDir(lib_dir, .{}) catch |err| { | | |
| 3095 | fatal("unable to open zig lib directory '{s}': {s}", .{ lib_dir, @errorName(err) }); | | |
| 3096 | }, | | |
| 3097 | }; | | |
| 3098 | } else if (builtin.os.tag == .wasi) { | | |
| 3099 | break :d getWasiPreopen("/lib"); | | |
| 3100 | } else if (self_exe_path) |p| { | | |
| 3101 | break :d introspect.findZigLibDirFromSelfExe(arena, p) catch |err| { | | |
| 3102 | fatal("unable to find zig installation directory: {s}", .{@errorName(err)}); | | |
| 3103 | }; | | |
| 3104 | } else { | | |
| 3105 | unreachable; | | |
| 3106 | } | | |
| 3107 | }; | | |
| 3108 | | | |
| 3109 | defer zig_lib_directory.handle.close(); | | |
| 3110 | | | |
| 3111 | var thread_pool: ThreadPool = undefined; | 3134 | var thread_pool: ThreadPool = undefined; |
| 3112 | try thread_pool.init(.{ .allocator = gpa }); | 3135 | try thread_pool.init(.{ .allocator = gpa }); |
| 3113 | defer thread_pool.deinit(); | 3136 | defer thread_pool.deinit(); |