Skip to content

Commit da0c3a3

Browse files
committed
add metacall include path to tcc_include_path
add metacall library path to tcc_library_path
1 parent d2cacbf commit da0c3a3

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

source/cli/metacallcli/source/application.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ bool command_cb_load(application &app, tokenizer &t)
454454
}
455455

456456
std::string loaders[] = {
457-
"mock", "py", "node", "rb", "cs", "cob", "ts", "js", "file", "wasm", "rs"
457+
"mock", "py", "node", "rb", "cs", "cob", "ts", "js", "file", "wasm", "rs", "c"
458458
};
459459

460460
// check if invalid loader tag
@@ -544,7 +544,8 @@ void application::parameter_iterator::operator()(const char *parameter)
544544
{ "jsx", "ts" },
545545
{ "tsx", "ts" },
546546
/* Rust Loader */
547-
{ "rs", "rs" }
547+
{ "rs", "rs" },
548+
{ "c", "c" }
548549

549550
/* Note: By default js extension uses NodeJS loader instead of JavaScript V8 */
550551
/* Probably in the future we can differenciate between them, but it is not trivial */

source/loaders/c_loader/source/c_loader_impl.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include <metacall/metacall.h>
3737

38+
#include <iostream>
3839
#include <iterator>
3940
#include <map>
4041
#include <new>
@@ -327,8 +328,21 @@ static loader_impl_c_handle c_loader_impl_handle_create(loader_impl_c c_impl)
327328
/* TODO: Add some warnings? */
328329
/* tcc_set_warning */
329330

330-
/* TODO: Take the c_loader and add the execution paths for include (and library?) folders */
331331
/* tcc_add_include_path, tcc_add_library_path */
332+
const char *loader_lib_path = loader_library_path();
333+
const char *include_dir = "../include";
334+
char join_path[PORTABILITY_PATH_SIZE];
335+
char metacall_incl_path[PORTABILITY_PATH_SIZE];
336+
337+
size_t join_path_size = portability_path_join(loader_lib_path, strlen(loader_lib_path) + 1, include_dir, strlen(include_dir) + 1, join_path, PORTABILITY_PATH_SIZE);
338+
size_t metacall_incl_path_size = portability_path_canonical(join_path, join_path_size, metacall_incl_path, PORTABILITY_PATH_SIZE);
339+
340+
/*Add metacall include path*/
341+
tcc_add_include_path(c_handle->state, metacall_incl_path);
342+
343+
/*Add metacall library path (in other to find libmetacall.so)*/
344+
tcc_add_library_path(c_handle->state, c_impl->libtcc_runtime_path.c_str());
345+
332346
(void)c_impl;
333347

334348
return c_handle;

0 commit comments

Comments
 (0)