Merge pull request #1597 from odin-lang/nix-linker-flags-improvement

Refactor link flag creation for nix systems
This commit is contained in:
gingerBill
2022-03-08 17:12:28 +00:00
committed by GitHub
+24 -19
View File
@@ -475,34 +475,39 @@ i32 linker_stage(lbGenerator *gen) {
} }
} }
result = system_exec_command_line_app("ld-link", gbString platform_lib_str = gb_string_make(heap_allocator(), "");
"clang -Wno-unused-command-line-argument %s -o \"%.*s%.*s\" %s " defer (gb_string_free(platform_lib_str));
" %s " #if defined(GB_SYSTEM_OSX)
" %.*s " platform_lib_str = gb_string_appendc(platform_lib_str, "-lSystem -lm -Wl,-syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -L/usr/local/lib");
" %.*s " #else
" %s " platform_lib_str = gb_string_appendc(platform_lib_str, "-lc -lm");
#endif
#if defined(GB_SYSTEM_OSX) #if defined(GB_SYSTEM_OSX)
// This sets a requirement of Mountain Lion and up, but the compiler doesn't work without this limit. // This sets a requirement of Mountain Lion and up, but the compiler doesn't work without this limit.
// NOTE: If you change this (although this minimum is as low as you can go with Odin working) // NOTE: If you change this (although this minimum is as low as you can go with Odin working)
// make sure to also change the 'mtriple' param passed to 'opt' // make sure to also change the 'mtriple' param passed to 'opt'
#if defined(GB_CPU_ARM) #if defined(GB_CPU_ARM)
" -mmacosx-version-min=12.0.0 " link_settings = gb_string_appendc(link_settings, " -mmacosx-version-min=12.0.0 ");
#else #else
" -mmacosx-version-min=10.8.0 " link_settings = gb_string_appendc(link_settings, " -mmacosx-version-min=10.8.0 ");
#endif #endif
// This points the linker to where the entry point is // This points the linker to where the entry point is
" -e _main " link_settings = gb_string_appendc(link_settings, " -e _main ");
#endif #endif
, object_files, LIT(output_base), LIT(output_ext),
#if defined(GB_SYSTEM_OSX) gbString link_command_line = gb_string_make(heap_allocator(), "clang -Wno-unused-command-line-argument ");
"-lSystem -lm -Wl,-syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -L/usr/local/lib", defer (gb_string_free(link_command_line));
#else
"-lc -lm", link_command_line = gb_string_appendc(link_command_line, object_files);
#endif link_command_line = gb_string_append_fmt(link_command_line, " -o \"%.*s%.*s\" ", LIT(output_base), LIT(output_ext));
lib_str, link_command_line = gb_string_append_fmt(link_command_line, " %s ", platform_lib_str);
LIT(build_context.link_flags), link_command_line = gb_string_append_fmt(link_command_line, " %s ", lib_str);
LIT(build_context.extra_linker_flags), link_command_line = gb_string_append_fmt(link_command_line, " %.*s ", LIT(build_context.link_flags));
link_settings); link_command_line = gb_string_append_fmt(link_command_line, " %.*s ", LIT(build_context.extra_linker_flags));
link_command_line = gb_string_append_fmt(link_command_line, " %s ", link_settings);
result = system_exec_command_line_app("ld-link", link_command_line);
if (result) { if (result) {
return result; return result;