From e7d8f64a49c3543098a09c69bf208b4a236f804c Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 10 Jul 2024 13:35:01 +0200 Subject: [PATCH] Compile c files to separate directories. Add compressed library to example test project. --- resources/testproject/hello_world.c3 | 2 ++ .../lib/clib.c3l/{hello.c => hello2.c} | 0 resources/testproject/lib/clib.c3l/manifest.json | 2 +- resources/testproject/lib/clib2.c3l | Bin 0 -> 810 bytes resources/testproject/project.json | 2 +- src/compiler/compiler.c | 10 ++++++---- src/compiler/compiler_internal.h | 2 +- src/compiler/linker.c | 5 +++-- 8 files changed, 14 insertions(+), 9 deletions(-) rename resources/testproject/lib/clib.c3l/{hello.c => hello2.c} (100%) create mode 100644 resources/testproject/lib/clib2.c3l diff --git a/resources/testproject/hello_world.c3 b/resources/testproject/hello_world.c3 index 97c720056..495a8acdf 100644 --- a/resources/testproject/hello_world.c3 +++ b/resources/testproject/hello_world.c3 @@ -2,6 +2,7 @@ module hello_world; import std; import bar; import clib; +import clib2; fn int test_doubler(int x) @if(env::WIN32) => x * x; extern fn int test_doubler(int) @if(!env::WIN32); @@ -14,5 +15,6 @@ fn int main() printf("Hello double: %d\n", test_doubler(11)); if ($feature(ABCD)) io::printn("ABCD"); clib::hello_from_c(); + clib2::hello_from_c_zip(); return 0; } \ No newline at end of file diff --git a/resources/testproject/lib/clib.c3l/hello.c b/resources/testproject/lib/clib.c3l/hello2.c similarity index 100% rename from resources/testproject/lib/clib.c3l/hello.c rename to resources/testproject/lib/clib.c3l/hello2.c diff --git a/resources/testproject/lib/clib.c3l/manifest.json b/resources/testproject/lib/clib.c3l/manifest.json index 8169c6505..afaf59e3e 100644 --- a/resources/testproject/lib/clib.c3l/manifest.json +++ b/resources/testproject/lib/clib.c3l/manifest.json @@ -1,6 +1,6 @@ { "provides" : "clib", - "c-sources" : ["hello.c"], + "c-sources" : ["hello2.c"], "targets" : { "macos-x64" : { }, diff --git a/resources/testproject/lib/clib2.c3l b/resources/testproject/lib/clib2.c3l new file mode 100644 index 0000000000000000000000000000000000000000..0e64c8ebaf91f4cb7d4b425c193c4331de064b7f GIT binary patch literal 810 zcmWIWW@Zs#-~hs;#8(jvP~Zoo*%=fVGE#GL^7WEKLwFh3E#vyqisJjyjsxk^3T_5Q zmamKq3_#5c48iBlc%Res^$gvhspom}%=Ob79&4RG?-O{!mo>C!!9YxXy6}&SdTKnsqH^D?@-cJ4bGe%LPxMp&&N|V0E1l zP=*uey5yY9BqP0K<4m~wP5|A8#eJvG`fHx`4D~p7(#L4ivqxTQH9U1s1$&$h*1+n@ z3tOHsft@m?tt8Y0Xc@>t>`u7~l;H(BB{wlIGcC2aL@%p2KM(F4YwXSmJ-3_hkO2?t zg_$+2Pj@CdbTrOw?3FcSG0#b*H!~er{^5a_v_N0Ole@L; zN3GRmcZmNwAS(UZHlH(J(pq`zTcfj?ekTtLu-nRh%NFa7H*#C?^OMrOt$)AlpJE?= z?~3E+1lJ%_pQ9zEmh%fNcOSgCRki=MbH~X=U9VU{!7cnS?q(;@7a*Smcr!AIFe8!! za#Vnl0}L!_1hI%r9O#B32P!BQVPHw)JRpcc ? lib->cc : active_target.cc, lib->csources, lib->cflags, obj_file_next); + obj_file_next += compile_cfiles(lib->cc ? lib->cc : active_target.cc, lib->csources, + lib->cflags, obj_file_next, lib->parent->provides); } Task **tasks = NULL; diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 0afb4dfde..6438c0527 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -3504,7 +3504,7 @@ bool static_lib_linker(const char *output_file, const char **files, unsigned fil bool dynamic_lib_linker(const char *output_file, const char **files, unsigned file_count); bool linker(const char *output_file, const char **files, unsigned file_count); void platform_linker(const char *output_file, const char **files, unsigned file_count); -const char *cc_compiler(const char *cc, const char *file, const char *flags); +const char *cc_compiler(const char *cc, const char *file, const char *flags, const char *output_subdir); const char *arch_to_linker_arch(ArchType arch); #define CAT(a,b) CAT2(a,b) // force expand diff --git a/src/compiler/linker.c b/src/compiler/linker.c index 155f8337a..779e1bf59 100644 --- a/src/compiler/linker.c +++ b/src/compiler/linker.c @@ -761,11 +761,12 @@ void platform_linker(const char *output_file, const char **files, unsigned file_ printf("Program linked to executable '%s'.\n", output_file); } -const char *cc_compiler(const char *cc, const char *file, const char *flags) +const char *cc_compiler(const char *cc, const char *file, const char *flags, const char *output_subdir) { const char *dir = active_target.object_file_dir; if (!dir) dir = active_target.build_dir; - + if (output_subdir) dir = file_append_path(dir, output_subdir); + dir_make(dir); bool is_cl_exe = str_eq(cc, "cl.exe"); char *filename = NULL; bool split_worked = file_namesplit(file, &filename, NULL);