add --linux-libc=host option and set default to host (#2636)

* added `--linux-libc=host` and set default to `default_linux` from `src/build/builder.c`

* updated `resources/project_schema.json` for `linux-libc` host build option

* Update how libc is set.

---------

Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
This commit is contained in:
DylanDoesProgramming
2025-12-12 16:53:01 -05:00
committed by GitHub
parent 15662bd32f
commit 0685260454
7 changed files with 23 additions and 20 deletions

View File

@@ -204,9 +204,10 @@
"description": "Set the libc to use for Linux.",
"enum": [
"gnu",
"musl"
"musl",
"host"
],
"default": "gnu"
"default": "host"
},
"x86cpu": {
"type": "string",

View File

@@ -108,6 +108,7 @@ typedef enum
LINUX_LIBC_NOT_SET = -1,
LINUX_LIBC_GNU = 0,
LINUX_LIBC_MUSL = 1,
LINUX_LIBC_HOST = 2,
} LinuxLibc;
typedef enum
@@ -897,7 +898,7 @@ static BuildTarget default_build_target = {
.feature.panic_level = PANIC_NOT_SET,
.win.crt_linking = WIN_CRT_DEFAULT,
.win.def = NULL,
.linuxpaths.libc = LINUX_LIBC_GNU,
.linuxpaths.libc = LINUX_LIBC_NOT_SET,
.switchrange_max_size = DEFAULT_SWITCHRANGE_MAX_SIZE,
.switchjump_max_size = DEFAULT_SWITCH_JUMP_MAX_SIZE,
.quiet = false,
@@ -913,6 +914,7 @@ extern const int manifest_default_keys_count;
extern const char *manifest_target_keys[][2];
extern const int manifest_target_keys_count;
extern const char *arch_os_target[ARCH_OS_TARGET_LAST + 1];
extern LinuxLibc default_libc;
BuildOptions parse_arguments(int argc, const char *argv[]);
ArchOsTarget arch_os_target_from_string(const char *target);

View File

@@ -50,9 +50,10 @@ static const char *optsizes[3] = {
[SIZE_OPTIMIZATION_TINY] = "tiny",
};
static const char *linuxlibc[2] = {
static const char *linuxlibc[3] = {
[LINUX_LIBC_GNU] = "gnu",
[LINUX_LIBC_MUSL] = "musl",
[LINUX_LIBC_HOST] = "host",
};
static const char *linker_kind[3] = {

View File

@@ -217,7 +217,7 @@ static void usage(bool full)
print_opt("--macos-min-version <ver>", "Set the minimum MacOS version to compile for.");
print_opt("--macos-sdk-version <ver>", "Set the MacOS SDK compiled for.");
PRINTF("");
print_opt("--linux-libc=<gnu|musl>", "Set the libc to use on Linux, defaults to gnu.");
print_opt("--linux-libc=<host|gnu|musl>", "Set the libc to use on Linux, defaults to host.");
print_opt("--linux-crt <dir>", "Set the directory to use for finding crt1.o and related files.");
print_opt("--linux-crtbegin <dir>", "Set the directory to use for finding crtbegin.o and related files.");
PRINTF("");

View File

@@ -540,6 +540,7 @@ static void update_build_target_from_options(BuildTarget *target, BuildOptions *
target->emit_asm = options->emit_asm;
target->print_stats = options->verbosity_level >= 2;
if (target->linuxpaths.libc == LINUX_LIBC_NOT_SET) target->linuxpaths.libc = default_libc;
target->benchmarking = options->benchmarking;
target->testing = options->testing;
target->silent = options->verbosity_level < 0;

View File

@@ -32,7 +32,7 @@ const char *project_default_keys[][2] = {
{"linker-search-paths", "Linker search paths."},
{"linux-crt", "Set the directory to use for finding crt1.o and related files."},
{"linux-crtbegin", "Set the directory to use for finding crtbegin.o and related files."},
{"linux-libc", "Set the libc to use for Linux. Valid options are 'gnu' and 'musl', default is 'gnu'"},
{"linux-libc", "Set the libc to use for Linux. Valid options are 'host', 'gnu' and 'musl', default is 'host'"},
{"loop-vectorize", "Force enable/disable loop auto-vectorization."},
{"macos-min-version", "Set the minimum MacOS version to compile for."},
{"macos-sdk-version", "Set the MacOS SDK compiled for." },
@@ -118,7 +118,7 @@ const char* project_target_keys[][2] = {
{"linker-search-paths-override", "Linker search paths for this target, overriding global settings."},
{"linux-crt", "Set the directory to use for finding crt1.o and related files."},
{"linux-crtbegin", "Set the directory to use for finding crtbegin.o and related files."},
{"linux-libc", "Set the libc to use for Linux. Valid options are 'gnu' and 'musl', default is 'gnu'"},
{"linux-libc", "Set the libc to use for Linux. Valid options are 'host', 'gnu' and 'musl', default is 'host'"},
{"loop-vectorize", "Force enable/disable loop auto-vectorization."},
{"macos-min-version", "Set the minimum MacOS version to compile for."},
{"macos-sdk-version", "Set the MacOS SDK compiled for." },
@@ -488,7 +488,7 @@ static void load_into_build_target(BuildParseContext context, JSONObject *json,
target->linuxpaths.crtbegin = get_string(context, json, "linux-crtbegin", target->linuxpaths.crtbegin);
// linux-libc
LinuxLibc linux_libc = GET_SETTING(LinuxLibc, "linux-libc", linuxlibc, "`gnu` or `musl`.");
LinuxLibc linux_libc = GET_SETTING(LinuxLibc, "linux-libc", linuxlibc, "`gnu`, `musl` or `host`.");
if (linux_libc > -1) target->linuxpaths.libc = linux_libc;
// version
@@ -503,7 +503,7 @@ static void load_into_build_target(BuildParseContext context, JSONObject *json,
// testfn
target->testfn = get_string(context, json, "testfn", target->testfn);
// testfn
// benchfn
target->benchfn = get_string(context, json, "benchfn", target->benchfn);
// link-libc

View File

@@ -402,12 +402,10 @@ static const char *find_linux_crt_begin(void)
static const char *find_linux_ld(void)
{
INFO_LOG("Environment Type ID: %d", compiler.platform.environment_type);
switch (compiler.platform.environment_type)
if (compiler.platform.environment_type == ENV_TYPE_ANDROID) return "--dynamic-linker=/system/ld-android.so";
switch (compiler.build.linuxpaths.libc)
{
case ENV_TYPE_MUSL:
case ENV_TYPE_MUSLEABI:
case ENV_TYPE_MUSLEABIHF:
case LINUX_LIBC_MUSL:
switch (compiler.platform.arch)
{
case ARCH_TYPE_ARM: return "--dynamic-linker=/lib/ld-musl-arm.so.1";
@@ -428,10 +426,9 @@ static const char *find_linux_ld(void)
}
UNREACHABLE;
break;
case ENV_TYPE_ANDROID:
return "--dynamic-linker=/system/ld-android.so";
default:
switch (compiler.platform.arch) {
case LINUX_LIBC_GNU:
switch (compiler.platform.arch)
{
case ARCH_TYPE_ARM: return "--dynamic-linker=/lib/ld-linux.so.3";
case ARCH_TYPE_AARCH64: return "--dynamic-linker=/lib/ld-linux-aarch64.so.1";
case ARCH_TYPE_MIPS: return "--dynamic-linker=/lib/ld-linux-mipsn8.so.1";
@@ -443,11 +440,12 @@ static const char *find_linux_ld(void)
case ARCH_TYPE_SPARCV9: return "--dynamic-linker=/lib/ld-linux.so.2";
case ARCH_TYPE_X86: return "--dynamic-linker=/lib64/ld-linux.so.2";
case ARCH_TYPE_X86_64: return "--dynamic-linker=/lib64/ld-linux-x86-64.so.2";
default: return "--dynamic-linkrt=/lib/ld-linux-unknown.so.2"; // another placeholder until we have all of them
default: return "--dynamic-linker=/lib/ld-linux-unknown.so.2"; // another placeholder until we have all of them
}
FALLTHROUGH;
default:
UNREACHABLE;
}
UNREACHABLE;
}
static void linker_setup_linux(const char ***args_ref, Linker linker_type, bool is_dylib)