Support c-file compilation in libraries.

This commit is contained in:
Christoffer Lerno
2024-07-07 02:08:49 +02:00
parent 3f62775f4b
commit 343ccaa2ef
3 changed files with 17 additions and 18 deletions

View File

@@ -45,7 +45,7 @@ jobs:
- name: Build testproject
run: |
set PATH=%PATH%;"C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.40.33807/bin/Hostx64/x64"
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
cd resources/testproject
..\..\build\${{ matrix.build_type }}\c3c.exe --debug-log --emit-llvm run hello_world_win32
dir build\llvm_ir
@@ -56,6 +56,7 @@ jobs:
- name: Build testproject lib
run: |
cd resources/testproject
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
..\..\build\${{ matrix.build_type }}\c3c.exe --debug-log build hello_world_win32_lib
- name: Vendor-fetch
@@ -142,7 +143,7 @@ jobs:
- name: Build testproject lib
run: |
cd resources/testproject
../../build/c3c build hello_world_lib --debug-log
../../build/c3c build hello_world_lib --cc cc --debug-log
- name: run compiler tests
run: |

View File

@@ -20,6 +20,7 @@
"targets": {
"hello_world": {
"type": "executable",
"cc" : "cc",
"c-sources-override": [
"./csource/**"
],
@@ -27,12 +28,12 @@
},
"hello_world_win32": {
"type": "executable",
"cc" : "cl.exe",
"c-sources-override": [
]
},
"hello_world_lib": {
"type": "static-lib",
"cc" : "cc",
"c-sources-override": [
"./csource/**"
]

View File

@@ -782,19 +782,9 @@ const char *cc_compiler(const char *cc, const char *file, const char *flags)
len -= 2;
filename[len] = 0;
}
const char *out_name;
if (is_cl_exe)
{
out_name = dir
? str_printf("/Fo:\"%s\\%s%s\"", dir, filename, get_object_extension())
: str_printf("/Fo:\"%s%s\"", filename, get_object_extension());
}
else
{
out_name = dir
? str_printf("%s/%s%s", dir, filename, get_object_extension())
: str_printf("%s%s", filename, get_object_extension());
}
const char *out_name = dir
? str_printf("%s/%s%s", dir, filename, get_object_extension())
: str_printf("%s%s", filename, get_object_extension());;
const char **parts = NULL;
vec_add(parts, cc);
@@ -812,8 +802,15 @@ const char *cc_compiler(const char *cc, const char *file, const char *flags)
vec_add(parts, is_cl_exe ? "/c" : "-c");
if (flags) vec_add(parts, flags);
vec_add(parts, file);
if (!is_cl_exe) vec_add(parts, "-o");
vec_add(parts, out_name);
if (is_cl_exe)
{
vec_add(parts, str_printf("/Fo:\"%s\"", out_name));
}
else
{
vec_add(parts, "-o");
vec_add(parts, out_name);
}
const char *output = concat_string_parts(parts);
DEBUG_LOG("Compiling c sources using '%s'", output);