diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ddc3d3a37..19f4079c1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -216,7 +216,7 @@ jobs: fail-fast: false matrix: build_type: [Release, Debug] - llvm_version: [17, 18, 19] + llvm_version: [17, 18, 19, 20] steps: - uses: actions/checkout@v4 diff --git a/releasenotes.md b/releasenotes.md index be215dc87..5f290dc26 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -9,6 +9,8 @@ - Support `int[*] { 1, 2, 3 }` expressions. - Support inline struct designated init as if inline was anonymous. - Introduce the `.paramsof` property. +- Support environment variable 'C3C_LIB' to find the standard library. +- Support environment variable 'C3C_CC' to find the default C compiler. ### Fixes - Issue where a lambda wasn't correctly registered as external. #1408 diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index 46c9dafb6..bc6b996af 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -270,6 +270,7 @@ static void free_arenas(void) static int compile_cfiles(const char *cc, const char **files, const char *flags, const char **include_dirs, const char **out_files, const char *output_subdir) { + if (!cc) cc = default_c_compiler(); int total = 0; FOREACH(const char *, file, files) { @@ -1453,3 +1454,20 @@ File *compile_and_invoke(const char *file, const char *args, const char *stdin_d return source_file_text_load(file, out); } +const char *default_c_compiler(void) +{ + static const char *cc = NULL; + if (cc) return cc; + const char *cc_env = getenv("C3C_CC"); + if (cc_env && strlen(cc_env) > 0) + { + INFO_LOG("Setting CC to %s from environment variable 'C3C_CC'.", cc_env); + cc = strdup(cc); + return cc; + } +#if PLATFORM_WINDOWS + return cc = "cl.exe"; +#else + return cc = "cc"; +#endif +} \ No newline at end of file diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index caac4ea88..334cbb0fc 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -3747,4 +3747,4 @@ INLINE bool check_module_name(Path *path) return true; } - +const char *default_c_compiler(void); \ No newline at end of file diff --git a/src/compiler/linker.c b/src/compiler/linker.c index 2f08db005..40bdc13fd 100644 --- a/src/compiler/linker.c +++ b/src/compiler/linker.c @@ -853,7 +853,7 @@ void platform_linker(const char *output_file, const char **files, unsigned file_ else { INFO_LOG("Using cc linker."); - vec_add(parts, compiler.build.cc ? compiler.build.cc : "cc"); + vec_add(parts, compiler.build.cc ? compiler.build.cc : default_c_compiler()); append_fpie_pic_options(compiler.platform.reloc_model, &parts); } diff --git a/src/compiler/target.c b/src/compiler/target.c index f22b8630f..836d6b1b1 100644 --- a/src/compiler/target.c +++ b/src/compiler/target.c @@ -1931,10 +1931,6 @@ void target_setup(BuildTarget *target) default: break; } - if (!target->cc) - { - target->cc = compiler.platform.os == OS_TYPE_WIN32 ? "cl.exe" : "cc"; - } compiler.platform.int128 = os_target_supports_int128(compiler.platform.os, compiler.platform.arch); compiler.platform.vec128f = os_target_supports_vec(compiler.platform.os, compiler.platform.arch, 128, false); diff --git a/src/utils/file_utils.c b/src/utils/file_utils.c index c8b371538..1a3f506cc 100644 --- a/src/utils/file_utils.c +++ b/src/utils/file_utils.c @@ -184,8 +184,6 @@ bool file_namesplit(const char *path, char** filename_ptr, char** directory_ptr) return true; } - - const char *file_expand_path(const char *path) { if (path[0] == '~' && path[1] == '/') @@ -377,6 +375,16 @@ const char *find_rel_exe_dir(const char *dir) const char *find_lib_dir(void) { + char *lib_dir_env = getenv("C3C_LIB"); + if (lib_dir_env && strlen(lib_dir_env) > 0) + { + INFO_LOG("Using stdlib library from env 'C3C_LIB': %s.", lib_dir_env); + if (!file_exists(lib_dir_env)) + { + error_exit("Library path from 'C3C_LIB' environment variable: '%s', could not be resolved.", lib_dir_env); + } + return strdup(lib_dir_env); + } char *path = find_executable_path(); INFO_LOG("Detected executable path at %s", path);