Skip to content

Add metacall include path and metacall library path in c loader #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions source/cli/metacallcli/source/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ bool command_cb_load(application &app, tokenizer &t)
}

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

// check if invalid loader tag
Expand Down Expand Up @@ -544,7 +544,8 @@ void application::parameter_iterator::operator()(const char *parameter)
{ "jsx", "ts" },
{ "tsx", "ts" },
/* Rust Loader */
{ "rs", "rs" }
{ "rs", "rs" },
{ "c", "c" }

/* Note: By default js extension uses NodeJS loader instead of JavaScript V8 */
/* Probably in the future we can differenciate between them, but it is not trivial */
Expand Down
16 changes: 15 additions & 1 deletion source/loaders/c_loader/source/c_loader_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include <metacall/metacall.h>

#include <iostream>
#include <iterator>
#include <map>
#include <new>
Expand Down Expand Up @@ -327,8 +328,21 @@ static loader_impl_c_handle c_loader_impl_handle_create(loader_impl_c c_impl)
/* TODO: Add some warnings? */
/* tcc_set_warning */

/* TODO: Take the c_loader and add the execution paths for include (and library?) folders */
/* tcc_add_include_path, tcc_add_library_path */
const char *loader_lib_path = loader_library_path();
const char *include_dir = "../include";
char join_path[PORTABILITY_PATH_SIZE];
char metacall_incl_path[PORTABILITY_PATH_SIZE];

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);
(void)portability_path_canonical(join_path, join_path_size, metacall_incl_path, PORTABILITY_PATH_SIZE);

/*Add metacall include path*/
tcc_add_include_path(c_handle->state, metacall_incl_path);

/*Add metacall library path (in other to find libmetacall.so)*/
tcc_add_library_path(c_handle->state, c_impl->libtcc_runtime_path.c_str());

(void)c_impl;

return c_handle;
Expand Down