mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
compiler: don't error on explicit link_libc=false on requiresLibC() targets
There are various reasons why one might want to still create libc-less compilations on these targets. Case in point: Compiling our bundled crt0 for OpenBSD. We will still default to linking libc on these targets, though.
This commit is contained in:
parent
e4f3eedb8a
commit
7ce50db17d
3 changed files with 3 additions and 16 deletions
|
|
@ -137,7 +137,6 @@ pub const ResolveError = error{
|
||||||
SanitizeThreadRequiresLibCpp,
|
SanitizeThreadRequiresLibCpp,
|
||||||
LibCRequiresLibUnwind,
|
LibCRequiresLibUnwind,
|
||||||
LibCppRequiresLibUnwind,
|
LibCppRequiresLibUnwind,
|
||||||
OsRequiresLibC,
|
|
||||||
LibCppRequiresLibC,
|
LibCppRequiresLibC,
|
||||||
LibUnwindRequiresLibC,
|
LibUnwindRequiresLibC,
|
||||||
TargetCannotDynamicLink,
|
TargetCannotDynamicLink,
|
||||||
|
|
@ -226,10 +225,6 @@ pub fn resolve(options: Options) ResolveError!Config {
|
||||||
};
|
};
|
||||||
|
|
||||||
const link_libc = b: {
|
const link_libc = b: {
|
||||||
if (target_util.osRequiresLibC(target)) {
|
|
||||||
if (options.link_libc == false) return error.OsRequiresLibC;
|
|
||||||
break :b true;
|
|
||||||
}
|
|
||||||
if (link_libcpp) {
|
if (link_libcpp) {
|
||||||
if (options.link_libc == false) return error.LibCppRequiresLibC;
|
if (options.link_libc == false) return error.LibCppRequiresLibC;
|
||||||
break :b true;
|
break :b true;
|
||||||
|
|
@ -250,7 +245,7 @@ pub fn resolve(options: Options) ResolveError!Config {
|
||||||
if (options.ensure_libc_on_non_freestanding and target.os.tag != .freestanding)
|
if (options.ensure_libc_on_non_freestanding and target.os.tag != .freestanding)
|
||||||
break :b true;
|
break :b true;
|
||||||
|
|
||||||
break :b false;
|
break :b target.requiresLibC();
|
||||||
};
|
};
|
||||||
|
|
||||||
const link_mode = b: {
|
const link_mode = b: {
|
||||||
|
|
@ -269,7 +264,7 @@ pub fn resolve(options: Options) ResolveError!Config {
|
||||||
break :b .dynamic;
|
break :b .dynamic;
|
||||||
}
|
}
|
||||||
if (explicitly_exe_or_dyn_lib and link_libc and
|
if (explicitly_exe_or_dyn_lib and link_libc and
|
||||||
(target_util.osRequiresLibC(target) or
|
(target.requiresLibC() or
|
||||||
// For these libcs, Zig can only provide dynamic libc when cross-compiling.
|
// For these libcs, Zig can only provide dynamic libc when cross-compiling.
|
||||||
((target.isGnuLibC() or target.isFreeBSDLibC() or target.isNetBSDLibC()) and
|
((target.isGnuLibC() or target.isFreeBSDLibC() or target.isNetBSDLibC()) and
|
||||||
!options.resolved_target.is_native_abi)))
|
!options.resolved_target.is_native_abi)))
|
||||||
|
|
|
||||||
|
|
@ -3993,7 +3993,6 @@ fn createModule(
|
||||||
error.SanitizeThreadRequiresLibCpp => fatal("thread sanitization is (for now) implemented in C++, so it requires linking libc++", .{}),
|
error.SanitizeThreadRequiresLibCpp => fatal("thread sanitization is (for now) implemented in C++, so it requires linking libc++", .{}),
|
||||||
error.LibCRequiresLibUnwind => fatal("libc of the specified target requires linking libunwind", .{}),
|
error.LibCRequiresLibUnwind => fatal("libc of the specified target requires linking libunwind", .{}),
|
||||||
error.LibCppRequiresLibUnwind => fatal("libc++ requires linking libunwind", .{}),
|
error.LibCppRequiresLibUnwind => fatal("libc++ requires linking libunwind", .{}),
|
||||||
error.OsRequiresLibC => fatal("the target OS requires using libc as the stable syscall interface", .{}),
|
|
||||||
error.LibCppRequiresLibC => fatal("libc++ requires linking libc", .{}),
|
error.LibCppRequiresLibC => fatal("libc++ requires linking libc", .{}),
|
||||||
error.LibUnwindRequiresLibC => fatal("libunwind requires linking libc", .{}),
|
error.LibUnwindRequiresLibC => fatal("libunwind requires linking libc", .{}),
|
||||||
error.TargetCannotDynamicLink => fatal("dynamic linking unavailable on the specified target", .{}),
|
error.TargetCannotDynamicLink => fatal("dynamic linking unavailable on the specified target", .{}),
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,6 @@ pub fn cannotDynamicLink(target: *const std.Target) bool {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// On Darwin, we always link libSystem which contains libc.
|
|
||||||
/// Similarly on FreeBSD and NetBSD we always link system libc
|
|
||||||
/// since this is the stable syscall interface.
|
|
||||||
pub fn osRequiresLibC(target: *const std.Target) bool {
|
|
||||||
return target.requiresLibC();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn libCNeedsLibUnwind(target: *const std.Target, link_mode: std.builtin.LinkMode) bool {
|
pub fn libCNeedsLibUnwind(target: *const std.Target, link_mode: std.builtin.LinkMode) bool {
|
||||||
return target.isGnuLibC() and link_mode == .static;
|
return target.isGnuLibC() and link_mode == .static;
|
||||||
}
|
}
|
||||||
|
|
@ -49,7 +42,7 @@ pub fn libCxxNeedsLibUnwind(target: *const std.Target) bool {
|
||||||
pub fn requiresPIC(target: *const std.Target, linking_libc: bool) bool {
|
pub fn requiresPIC(target: *const std.Target, linking_libc: bool) bool {
|
||||||
return target.abi.isAndroid() or
|
return target.abi.isAndroid() or
|
||||||
target.os.tag == .windows or target.os.tag == .uefi or
|
target.os.tag == .windows or target.os.tag == .uefi or
|
||||||
osRequiresLibC(target) or
|
target.requiresLibC() or
|
||||||
(linking_libc and target.isGnuLibC());
|
(linking_libc and target.isGnuLibC());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue