aboutsummaryrefslogtreecommitdiff
path: root/src/build_settings.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2024-01-29 16:18:38 +0000
committerGitHub <noreply@github.com>2024-01-29 16:18:38 +0000
commitf588593ff15fa13e89bd869a52b2ff9bf9d91341 (patch)
tree8f2c0a32259c405c53396ead12b1c8f3f5c261d0 /src/build_settings.cpp
parenta78f062499c7f0112558872a500904e6fbc6761b (diff)
parenta626adac8e8e0ca0506401cf3376727ad801091c (diff)
Merge pull request #3147 from odin-lang/base-work
`base` library collection work
Diffstat (limited to 'src/build_settings.cpp')
-rw-r--r--src/build_settings.cpp37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/build_settings.cpp b/src/build_settings.cpp
index af518bcb4..c29a012ec 100644
--- a/src/build_settings.cpp
+++ b/src/build_settings.cpp
@@ -323,6 +323,7 @@ struct BuildContext {
bool ODIN_DEBUG; // Odin in debug mode
bool ODIN_DISABLE_ASSERT; // Whether the default 'assert' et al is disabled in code or not
bool ODIN_DEFAULT_TO_NIL_ALLOCATOR; // Whether the default allocator is a "nil" allocator or not (i.e. it does nothing)
+ bool ODIN_DEFAULT_TO_PANIC_ALLOCATOR; // Whether the default allocator is a "panic" allocator or not (i.e. panics on any call to it)
bool ODIN_FOREIGN_ERROR_PROCEDURES;
bool ODIN_VALGRIND_SUPPORT;
@@ -1161,7 +1162,27 @@ gb_internal String get_fullpath_relative(gbAllocator a, String base_dir, String
}
-gb_internal String get_fullpath_core(gbAllocator a, String path) {
+gb_internal String get_fullpath_base_collection(gbAllocator a, String path) {
+ String module_dir = odin_root_dir();
+
+ String base = str_lit("base/");
+
+ isize str_len = module_dir.len + base.len + path.len;
+ u8 *str = gb_alloc_array(heap_allocator(), u8, str_len+1);
+ defer (gb_free(heap_allocator(), str));
+
+ isize i = 0;
+ gb_memmove(str+i, module_dir.text, module_dir.len); i += module_dir.len;
+ gb_memmove(str+i, base.text, base.len); i += base.len;
+ gb_memmove(str+i, path.text, path.len); i += path.len;
+ str[i] = 0;
+
+ String res = make_string(str, i);
+ res = string_trim_whitespace(res);
+ return path_to_fullpath(a, res);
+}
+
+gb_internal String get_fullpath_core_collection(gbAllocator a, String path) {
String module_dir = odin_root_dir();
String core = str_lit("core/");
@@ -1454,6 +1475,16 @@ gb_internal void init_build_context(TargetMetrics *cross_target, Subtarget subta
break;
}
}
+
+ if (bc->metrics.os == TargetOs_freestanding) {
+ bc->ODIN_DEFAULT_TO_NIL_ALLOCATOR = !bc->ODIN_DEFAULT_TO_PANIC_ALLOCATOR;
+ } else if (is_arch_wasm()) {
+ if (bc->metrics.os == TargetOs_js || bc->metrics.os == TargetOs_wasi) {
+ // TODO(bill): Should these even have a default "heap-like" allocator?
+ }
+ bc->ODIN_DEFAULT_TO_PANIC_ALLOCATOR = true;
+ bc->ODIN_DEFAULT_TO_NIL_ALLOCATOR = !bc->ODIN_DEFAULT_TO_PANIC_ALLOCATOR;
+ }
}
#if defined(GB_SYSTEM_WINDOWS)
@@ -1588,8 +1619,8 @@ gb_internal bool init_build_paths(String init_filename) {
produces_output_file = true;
}
-
- if (build_context.ODIN_DEFAULT_TO_NIL_ALLOCATOR) {
+ if (build_context.ODIN_DEFAULT_TO_NIL_ALLOCATOR ||
+ build_context.ODIN_DEFAULT_TO_PANIC_ALLOCATOR) {
bc->no_dynamic_literals = true;
}