| author | |
| committer | |
| log | 1d8f33ca98493d63c509e0a23b8dc512f4d7b79f |
| tree | f81c326ceef3cb9a010f85af5092274d908381ad |
| parent | 078a64f8d9b50ad99afe12ba3038afc3e68f507c |
| signature |
If targeting the native OS and the system libc is musl, link against it
dynamically by default.8 files changed, 26 insertions(+), 1 deletions(-)
src/Compilation.zig+17-1| ... | ... | @@ -385,6 +385,7 @@ pub const InitOptions = struct { |
| 385 | 385 | single_threaded: bool = false, |
| 386 | 386 | function_sections: bool = false, |
| 387 | 387 | is_native_os: bool, |
| 388 | is_native_abi: bool, | |
| 388 | 389 | time_report: bool = false, |
| 389 | 390 | stack_report: bool = false, |
| 390 | 391 | link_eh_frame_hdr: bool = false, |
| ... | ... | @@ -600,7 +601,19 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 600 | 601 | |
| 601 | 602 | break :dl false; |
| 602 | 603 | }; |
| 603 | const default_link_mode: std.builtin.LinkMode = if (must_dynamic_link) .Dynamic else .Static; | |
| 604 | const default_link_mode: std.builtin.LinkMode = blk: { | |
| 605 | if (must_dynamic_link) { | |
| 606 | break :blk .Dynamic; | |
| 607 | } else if (is_exe_or_dyn_lib and link_libc and | |
| 608 | options.is_native_abi and options.target.abi.isMusl()) | |
| 609 | { | |
| 610 | // If targeting the system's native ABI and the system's | |
| 611 | // libc is musl, link dynamically by default. | |
| 612 | break :blk .Dynamic; | |
| 613 | } else { | |
| 614 | break :blk .Static; | |
| 615 | } | |
| 616 | }; | |
| 604 | 617 | const link_mode: std.builtin.LinkMode = if (options.link_mode) |lm| blk: { |
| 605 | 618 | if (lm == .Static and must_dynamic_link) { |
| 606 | 619 | return error.UnableToStaticLink; |
| ... | ... | @@ -910,6 +923,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 910 | 923 | .rpath_list = options.rpath_list, |
| 911 | 924 | .strip = strip, |
| 912 | 925 | .is_native_os = options.is_native_os, |
| 926 | .is_native_abi = options.is_native_abi, | |
| 913 | 927 | .function_sections = options.function_sections, |
| 914 | 928 | .allow_shlib_undefined = options.linker_allow_shlib_undefined, |
| 915 | 929 | .bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false, |
| ... | ... | @@ -2778,6 +2792,7 @@ fn buildOutputFromZig( |
| 2778 | 2792 | .emit_h = null, |
| 2779 | 2793 | .strip = comp.bin_file.options.strip, |
| 2780 | 2794 | .is_native_os = comp.bin_file.options.is_native_os, |
| 2795 | .is_native_abi = comp.bin_file.options.is_native_abi, | |
| 2781 | 2796 | .self_exe_path = comp.self_exe_path, |
| 2782 | 2797 | .verbose_cc = comp.verbose_cc, |
| 2783 | 2798 | .verbose_link = comp.bin_file.options.verbose_link, |
| ... | ... | @@ -3148,6 +3163,7 @@ pub fn build_crt_file( |
| 3148 | 3163 | .emit_h = null, |
| 3149 | 3164 | .strip = comp.bin_file.options.strip, |
| 3150 | 3165 | .is_native_os = comp.bin_file.options.is_native_os, |
| 3166 | .is_native_abi = comp.bin_file.options.is_native_abi, | |
| 3151 | 3167 | .self_exe_path = comp.self_exe_path, |
| 3152 | 3168 | .c_source_files = c_source_files, |
| 3153 | 3169 | .verbose_cc = comp.verbose_cc, |
src/glibc.zig+1| ... | ... | @@ -945,6 +945,7 @@ fn buildSharedLib( |
| 945 | 945 | .emit_h = null, |
| 946 | 946 | .strip = comp.bin_file.options.strip, |
| 947 | 947 | .is_native_os = false, |
| 948 | .is_native_abi = false, | |
| 948 | 949 | .self_exe_path = comp.self_exe_path, |
| 949 | 950 | .verbose_cc = comp.verbose_cc, |
| 950 | 951 | .verbose_link = comp.bin_file.options.verbose_link, |
src/libcxx.zig+2| ... | ... | @@ -175,6 +175,7 @@ pub fn buildLibCXX(comp: *Compilation) !void { |
| 175 | 175 | .emit_h = null, |
| 176 | 176 | .strip = comp.bin_file.options.strip, |
| 177 | 177 | .is_native_os = comp.bin_file.options.is_native_os, |
| 178 | .is_native_abi = comp.bin_file.options.is_native_abi, | |
| 178 | 179 | .self_exe_path = comp.self_exe_path, |
| 179 | 180 | .c_source_files = c_source_files.items, |
| 180 | 181 | .verbose_cc = comp.verbose_cc, |
| ... | ... | @@ -293,6 +294,7 @@ pub fn buildLibCXXABI(comp: *Compilation) !void { |
| 293 | 294 | .emit_h = null, |
| 294 | 295 | .strip = comp.bin_file.options.strip, |
| 295 | 296 | .is_native_os = comp.bin_file.options.is_native_os, |
| 297 | .is_native_abi = comp.bin_file.options.is_native_abi, | |
| 296 | 298 | .self_exe_path = comp.self_exe_path, |
| 297 | 299 | .c_source_files = &c_source_files, |
| 298 | 300 | .verbose_cc = comp.verbose_cc, |
src/libunwind.zig+1| ... | ... | @@ -108,6 +108,7 @@ pub fn buildStaticLib(comp: *Compilation) !void { |
| 108 | 108 | .emit_h = null, |
| 109 | 109 | .strip = comp.bin_file.options.strip, |
| 110 | 110 | .is_native_os = comp.bin_file.options.is_native_os, |
| 111 | .is_native_abi = comp.bin_file.options.is_native_abi, | |
| 111 | 112 | .self_exe_path = comp.self_exe_path, |
| 112 | 113 | .c_source_files = &c_source_files, |
| 113 | 114 | .verbose_cc = comp.verbose_cc, |
src/link.zig+1| ... | ... | @@ -71,6 +71,7 @@ pub const Options = struct { |
| 71 | 71 | z_defs: bool, |
| 72 | 72 | bind_global_refs_locally: bool, |
| 73 | 73 | is_native_os: bool, |
| 74 | is_native_abi: bool, | |
| 74 | 75 | pic: bool, |
| 75 | 76 | pie: bool, |
| 76 | 77 | valgrind: bool, |
src/main.zig+2| ... | ... | @@ -1685,6 +1685,7 @@ fn buildOutputType( |
| 1685 | 1685 | .root_name = root_name, |
| 1686 | 1686 | .target = target_info.target, |
| 1687 | 1687 | .is_native_os = cross_target.isNativeOs(), |
| 1688 | .is_native_abi = cross_target.isNativeAbi(), | |
| 1688 | 1689 | .dynamic_linker = target_info.dynamic_linker.get(), |
| 1689 | 1690 | .output_mode = output_mode, |
| 1690 | 1691 | .root_pkg = root_pkg, |
| ... | ... | @@ -2415,6 +2416,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v |
| 2415 | 2416 | .root_name = "build", |
| 2416 | 2417 | .target = target_info.target, |
| 2417 | 2418 | .is_native_os = cross_target.isNativeOs(), |
| 2419 | .is_native_abi = cross_target.isNativeAbi(), | |
| 2418 | 2420 | .dynamic_linker = target_info.dynamic_linker.get(), |
| 2419 | 2421 | .output_mode = .Exe, |
| 2420 | 2422 | .root_pkg = &root_pkg, |
src/musl.zig+1| ... | ... | @@ -210,6 +210,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 210 | 210 | .emit_h = null, |
| 211 | 211 | .strip = comp.bin_file.options.strip, |
| 212 | 212 | .is_native_os = false, |
| 213 | .is_native_abi = false, | |
| 213 | 214 | .self_exe_path = comp.self_exe_path, |
| 214 | 215 | .verbose_cc = comp.verbose_cc, |
| 215 | 216 | .verbose_link = comp.bin_file.options.verbose_link, |
src/test.zig+1| ... | ... | @@ -561,6 +561,7 @@ pub const TestContext = struct { |
| 561 | 561 | .keep_source_files_loaded = true, |
| 562 | 562 | .object_format = ofmt, |
| 563 | 563 | .is_native_os = case.target.isNativeOs(), |
| 564 | .is_native_abi = case.target.isNativeAbi(), | |
| 564 | 565 | }); |
| 565 | 566 | defer comp.destroy(); |
| 566 | 567 |