From a07ba6391799dfb4f0c903fd24fd77f42ede0419 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 5 Oct 2023 16:31:11 +0200 Subject: [PATCH] Compiling does not leave exe when successful, and also works with generic modules. #1027. For now, silence errors due to the macos linker changes. #1028. Try update `clean` on Windows #456. --- src/build/build.h | 2 ++ src/compiler/compiler.c | 7 +++---- src/compiler/compiler_internal.h | 1 + src/compiler/linker.c | 1 + src/compiler/semantic_analyser.c | 4 ++-- src/utils/file_utils.c | 6 +++--- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/build/build.h b/src/build/build.h index 7aad1e1a2..8d2124d9a 100644 --- a/src/build/build.h +++ b/src/build/build.h @@ -291,6 +291,8 @@ typedef enum ARCH_OS_TARGET_LAST = WINDOWS_X64 } ArchOsTarget; +#define ANY_WINDOWS_ARCH_OS WINDOWS_AARCH64: case WINDOWS_X64: case MINGW_X64 + typedef struct BuildOptions_ { const char *lib_dir[MAX_LIB_DIRS]; diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index 264af124e..5971730cc 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -981,9 +981,7 @@ const char *get_object_extension(void) { switch (active_target.arch_os_target) { - case WINDOWS_X64: - case WINDOWS_AARCH64: - case MINGW_X64: + case ANY_WINDOWS_ARCH_OS: return ".obj"; default: return ".o"; @@ -1045,7 +1043,7 @@ File *compile_and_invoke(const char *file, const char *args) #else const char *output = "__c3exec__"; #endif - scratch_buffer_append(" compile"); + scratch_buffer_append(" compile -g0 --single-module=yes"); StringSlice slice = slice_from_string(file); while (slice.len > 0) { @@ -1072,6 +1070,7 @@ File *compile_and_invoke(const char *file, const char *args) { error_exit("Error invoking script '%s' with arguments %s.", file, args); } + file_delete_file(output); return source_file_text_load(file, out); } diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index f2c0b5363..3fd20a6cb 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -2145,6 +2145,7 @@ INLINE const char *section_from_id(SectionId id); Module *compiler_find_or_create_module(Path *module_name, const char **parameters); Module *global_context_find_module(const char *name); const char *get_object_extension(void); +const char *get_exe_extension(void); CompilationUnit * unit_create(File *file); void unit_register_global_decl(CompilationUnit *unit, Decl *decl); diff --git a/src/compiler/linker.c b/src/compiler/linker.c index 6f50729e7..9d5c9d5cd 100644 --- a/src/compiler/linker.c +++ b/src/compiler/linker.c @@ -283,6 +283,7 @@ static void linker_setup_macos(const char ***args_ref, LinkerType linker_type) add_arg("CoreFoundation"); if (linker_type == LINKER_CC) { + add_arg("-ld_classic"); return; } add_arg("-arch"); diff --git a/src/compiler/semantic_analyser.c b/src/compiler/semantic_analyser.c index 34a88dcc3..46edce2d4 100644 --- a/src/compiler/semantic_analyser.c +++ b/src/compiler/semantic_analyser.c @@ -189,12 +189,12 @@ static void register_generic_decls(CompilationUnit *unit, Decl **decls) case DECL_DECLARRAY: case DECL_ERASED: case DECL_FNTYPE: + case DECL_CT_INCLUDE: + case DECL_CT_EXEC: continue; case DECL_ATTRIBUTE: break; case DECL_BODYPARAM: - case DECL_CT_INCLUDE: - case DECL_CT_EXEC: case DECL_GLOBALS: UNREACHABLE case DECL_MACRO: diff --git a/src/utils/file_utils.c b/src/utils/file_utils.c index d4cb0b448..40430c474 100644 --- a/src/utils/file_utils.c +++ b/src/utils/file_utils.c @@ -485,11 +485,11 @@ bool file_delete_all_files_in_dir_with_suffix(const char *path, const char *suff { assert(path); #if (_MSC_VER) - const char *cmd = "del /q"; + const char *cmd = "del /q %s\\*%s"; #else - const char *cmd = "rm -f"; + const char *cmd = "rm -f %s/*%s"; #endif - return execute_cmd(str_printf("%s %s/*%s", cmd, path, suffix)) == 0; + return execute_cmd(str_printf(cmd, path, suffix)) == 0; } #if (_MSC_VER)