From 056c62acadc6e0a9c0d0e5ff552594a301498ab8 Mon Sep 17 00:00:00 2001 From: servostar Date: Thu, 18 Jul 2024 21:59:29 +0200 Subject: [PATCH] added custom import and link paths to build.toml --- src/cfg/opt.c | 24 +++++++++++++++++++++++- src/llvm/link/lld.c | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/cfg/opt.c b/src/cfg/opt.c index 22f0e98..b29475d 100644 --- a/src/cfg/opt.c +++ b/src/cfg/opt.c @@ -103,7 +103,7 @@ TargetConfig* default_target_config() { config->output_directory = mem_strdup(MemoryNamespaceOpt, "bin"); config->optimization_level = 1; config->root_module = NULL; - config->link_search_paths = g_array_new(FALSE, FALSE, sizeof(char*)); + config->link_search_paths = mem_new_g_array(MemoryNamespaceOpt, sizeof(char*)); config->lld_fatal_warnings = FALSE; config->gsc_fatal_warnings = FALSE; config->import_paths = mem_new_g_array(MemoryNamespaceOpt, sizeof(char*)); @@ -311,6 +311,21 @@ static void get_int(int* integer, const toml_table_t *table, const char* name) { } } +static void get_array(GArray* array, const toml_table_t *table, const char* name) { + const toml_array_t* toml_array = toml_array_in(table, name); + + if (toml_array) { + for (int i = 0; i < toml_array_nelem(toml_array); i++) { + toml_datum_t value = toml_string_at(toml_array, i); + + if (value.ok) { + char* copy = mem_strdup(MemoryNamespaceOpt, value.u.s); + g_array_append_val(array, copy); + } + } + } +} + static int parse_project_table(ProjectConfig *config, const toml_table_t *project_table) { DEBUG("parsing project table..."); @@ -387,6 +402,13 @@ static int parse_target(const ProjectConfig *config, const toml_table_t *target_ if (err != PROJECT_OK) { return err; } + char* cwd = g_get_current_dir(); + + g_array_append_val(target_config->link_search_paths, cwd); + get_array(target_config->link_search_paths, target_table, "link-paths"); + + g_array_append_val(target_config->import_paths, cwd); + get_array(target_config->import_paths, target_table, "import-paths"); g_hash_table_insert(config->targets, target_config->name, target_config); diff --git a/src/llvm/link/lld.c b/src/llvm/link/lld.c index 801aa6a..0d3bf09 100644 --- a/src/llvm/link/lld.c +++ b/src/llvm/link/lld.c @@ -13,6 +13,8 @@ const char* get_absolute_link_path(const TargetConfig* config, const char* link_ for (guint i = 0; i < config->link_search_paths->len; i++) { const char* link_directory_path = g_array_index(config->link_search_paths, char*, i); + INFO("searching at: %s", link_directory_path); + char* path = g_build_filename(link_directory_path, link_target_name, NULL); char* cwd = g_get_current_dir(); char* canonical = g_canonicalize_filename(path, cwd);