mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Merge pull request #3297 from laytan/linker-improvements
linker improvements
This commit is contained in:
+25
-2
@@ -1191,13 +1191,24 @@ gb_internal String path_to_fullpath(gbAllocator a, String s, bool *ok_) {
|
|||||||
char *p;
|
char *p;
|
||||||
mutex_lock(&fullpath_mutex);
|
mutex_lock(&fullpath_mutex);
|
||||||
p = realpath(cast(char *)s.text, 0);
|
p = realpath(cast(char *)s.text, 0);
|
||||||
|
defer (free(p));
|
||||||
mutex_unlock(&fullpath_mutex);
|
mutex_unlock(&fullpath_mutex);
|
||||||
if(p == nullptr) {
|
if(p == nullptr) {
|
||||||
if (ok_) *ok_ = false;
|
if (ok_) *ok_ = false;
|
||||||
return String{};
|
|
||||||
|
// Path doesn't exist or is malformed, Windows's `GetFullPathNameW` does not check for
|
||||||
|
// existence of the file where `realpath` does, which causes different behaviour between platforms.
|
||||||
|
// Two things could be done here:
|
||||||
|
// 1. clean the path and resolve it manually, just like the Windows function does,
|
||||||
|
// probably requires porting `filepath.clean` from Odin and doing some more processing.
|
||||||
|
// 2. just return a copy of the original path.
|
||||||
|
//
|
||||||
|
// I have opted for 2 because it is much simpler + we already return `ok = false` + further
|
||||||
|
// checks and processes will use the path and cause errors (which we want).
|
||||||
|
return copy_string(a, s);
|
||||||
}
|
}
|
||||||
if (ok_) *ok_ = true;
|
if (ok_) *ok_ = true;
|
||||||
return make_string_c(p);
|
return copy_string(a, make_string_c(p));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#error Implement system
|
#error Implement system
|
||||||
@@ -1947,6 +1958,18 @@ gb_internal bool init_build_paths(String init_filename) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (build_context.no_crt && !build_context.ODIN_DEFAULT_TO_NIL_ALLOCATOR && !build_context.ODIN_DEFAULT_TO_PANIC_ALLOCATOR) {
|
||||||
|
switch (build_context.metrics.os) {
|
||||||
|
case TargetOs_linux:
|
||||||
|
case TargetOs_darwin:
|
||||||
|
case TargetOs_essence:
|
||||||
|
case TargetOs_freebsd:
|
||||||
|
case TargetOs_openbsd:
|
||||||
|
case TargetOs_haiku:
|
||||||
|
gb_printf_err("-no-crt on unix systems requires either -default-to-nil-allocator or -default-to-panic-allocator to also be present because the default allocator requires crt\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (bc->target_features_string.len != 0) {
|
if (bc->target_features_string.len != 0) {
|
||||||
enable_target_feature({}, bc->target_features_string);
|
enable_target_feature({}, bc->target_features_string);
|
||||||
|
|||||||
+11
-3
@@ -376,6 +376,10 @@ gb_internal i32 linker_stage(LinkerData *gen) {
|
|||||||
LIT(obj_file),
|
LIT(obj_file),
|
||||||
LIT(build_context.extra_assembler_flags)
|
LIT(build_context.extra_assembler_flags)
|
||||||
);
|
);
|
||||||
|
if (!result) {
|
||||||
|
gb_printf_err("executing `nasm` to assemble foreing import of %.*s failed.\n\tSuggestion: `nasm` does not ship with the compiler and should be installed with your system's package manager.\n", LIT(asm_file));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
array_add(&gen->output_object_paths, obj_file);
|
array_add(&gen->output_object_paths, obj_file);
|
||||||
} else {
|
} else {
|
||||||
@@ -383,9 +387,13 @@ gb_internal i32 linker_stage(LinkerData *gen) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(zangent): Sometimes, you have to use -framework on MacOS.
|
// Do not add libc again, this is added later already, and omitted with
|
||||||
// This allows you to specify '-f' in a #foreign_system_library,
|
// the `-no-crt` flag, not skipping here would cause duplicate library
|
||||||
// without having to implement any new syntax specifically for MacOS.
|
// warnings when linking on darwin and might link libc silently even with `-no-crt`.
|
||||||
|
if (lib == str_lit("System.framework") || lib == str_lit("c")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (build_context.metrics.os == TargetOs_darwin) {
|
if (build_context.metrics.os == TargetOs_darwin) {
|
||||||
if (string_ends_with(lib, str_lit(".framework"))) {
|
if (string_ends_with(lib, str_lit(".framework"))) {
|
||||||
// framework thingie
|
// framework thingie
|
||||||
|
|||||||
Reference in New Issue
Block a user