diff options
| author | gingerBill <bill@gingerbill.org> | 2024-05-16 14:27:05 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-05-16 14:27:05 +0100 |
| commit | e71cd871c45d99ce6f593b44002dc0e3ad57593b (patch) | |
| tree | 8af13c496e03f48d0671f78a09bef944780fc332 /src/linker.cpp | |
| parent | f9fd8f0c25bb0b239e5421c39217d2f8c449911f (diff) | |
Reimplement `-build-mode:static`/`-build-mode:lib`
Diffstat (limited to 'src/linker.cpp')
| -rw-r--r-- | src/linker.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/linker.cpp b/src/linker.cpp index 33ca70462..c41f10593 100644 --- a/src/linker.cpp +++ b/src/linker.cpp @@ -212,10 +212,12 @@ gb_internal i32 linker_stage(LinkerData *gen) { link_settings = gb_string_append_fmt(link_settings, " /PDB:\"%.*s\"", LIT(pdb_path)); } - if (build_context.no_crt) { - link_settings = gb_string_append_fmt(link_settings, " /nodefaultlib"); - } else { - link_settings = gb_string_append_fmt(link_settings, " /defaultlib:libcmt"); + if (build_context.build_mode != BuildMode_StaticLibrary) { + if (build_context.no_crt) { + link_settings = gb_string_append_fmt(link_settings, " /nodefaultlib"); + } else { + link_settings = gb_string_append_fmt(link_settings, " /defaultlib:libcmt"); + } } if (build_context.ODIN_DEBUG) { @@ -257,20 +259,31 @@ gb_internal i32 linker_stage(LinkerData *gen) { } } + String linker_name = str_lit("link.exe"); switch (build_context.build_mode) { case BuildMode_Executable: link_settings = gb_string_append_fmt(link_settings, " /NOIMPLIB /NOEXP"); break; } + switch (build_context.build_mode) { + case BuildMode_StaticLibrary: + linker_name = str_lit("lib.exe"); + break; + default: + link_settings = gb_string_append_fmt(link_settings, " /incremental:no /opt:ref"); + break; + } + + result = system_exec_command_line_app("msvc-link", - "\"%.*slink.exe\" %s %.*s -OUT:\"%.*s\" %s " - "/nologo /incremental:no /opt:ref /subsystem:%.*s " + "\"%.*s%.*s\" %s %.*s -OUT:\"%.*s\" %s " + "/nologo /subsystem:%.*s " "%.*s " "%.*s " "%s " "", - LIT(vs_exe_path), object_files, LIT(res_path), LIT(output_filename), + LIT(vs_exe_path), LIT(linker_name), object_files, LIT(res_path), LIT(output_filename), link_settings, LIT(build_context.ODIN_WINDOWS_SUBSYSTEM), LIT(build_context.link_flags), @@ -458,6 +471,10 @@ gb_internal i32 linker_stage(LinkerData *gen) { link_settings = gb_string_append_fmt(link_settings, "-nostdlib "); } + if (build_context.build_mode == BuildMode_StaticLibrary) { + compiler_error("TODO(bill): -build-mode:static on non-windows targets"); + } + // NOTE(dweiler): We use clang as a frontend for the linker as there are // other runtime and compiler support libraries that need to be linked in // very specific orders such as libgcc_s, ld-linux-so, unwind, etc. |