Skip to content
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

Implement support for running MetaCall from python.exe and node.exe. #533

Draft
wants to merge 25 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ac3c3f6
Initial commit, add base for NodeJS and constructor for MetaCall, sti…
viferga Nov 21, 2024
3ed5d23
Implemented cwd and options map.
viferga Nov 21, 2024
8e8fe8b
Add functions for detecting host from loader side.
viferga Nov 22, 2024
355c12f
Improve dynlink, trying to hook dlsym.
viferga Nov 27, 2024
cbbf4a4
Solve issues from detours, plugin manager, fork safety and added supp…
viferga Nov 28, 2024
1927c62
Unified all detours modules, add a destructor in metacall module for …
viferga Nov 28, 2024
d9604dd
Implemented metacall link table.
viferga Nov 28, 2024
83de553
Initialization working properly on NodeJS.
viferga Dec 4, 2024
7779200
Add delayed execution paths in NodeJS.
viferga Dec 4, 2024
55a8553
Add base for destroy in node.
viferga Dec 5, 2024
851cfee
Merge branch 'develop' into feature/run-outside-metacall-cli
viferga Dec 19, 2024
9bbc9a6
Host destruction working properly with nodejs.
viferga Dec 19, 2024
10f72e1
Add preload of sanitizers for node tests with node executable.
viferga Dec 19, 2024
ad08aec
Change metacall_destroy signature, improved bugs with atexit.
viferga Dec 19, 2024
0fe2295
Add NodeJS support for load_from_package and execution_path, add test…
viferga Jan 14, 2025
50c27f2
Add loader config with dependencies.
viferga Jan 29, 2025
3f53257
Use always Python3.
viferga Jan 30, 2025
911e7a3
Solve issues Python 3.13.
viferga Jan 30, 2025
aa13d6c
Implement dependencies for loaders.
viferga Jan 30, 2025
1f48816
Change link options.
viferga Feb 3, 2025
ab80538
Add base for supporting weak symbols on node loader.
viferga Feb 3, 2025
35f656a
Merge branch 'develop' into feature/run-outside-metacall-cli
viferga Feb 3, 2025
cd1cb34
Solve issue of NodeJS with MSVC.
viferga Feb 3, 2025
a6c0144
Add thread safety for metacall link.
viferga Feb 5, 2025
64a6150
Add proper link flags for node_loader on macos.
viferga Feb 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#

# CMake version
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)

# Include cmake modules

Expand Down Expand Up @@ -241,6 +241,9 @@ else()
endif()
endif()

# Export compile commands
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

#
# CTest configuration
#
Expand Down
33 changes: 33 additions & 0 deletions cmake/CompileOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,39 @@ else()
set(SANITIZER_COMPILE_DEFINITIONS)
endif()

if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
if(OPTION_BUILD_THREAD_SANITIZER)
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=libtsan${CMAKE_SHARED_LIBRARY_SUFFIX} OUTPUT_VARIABLE LIBTSAN_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
set(SANITIZER_LIBRARIES_PATH
"${LIBTSAN_PATH}"
)
elseif(OPTION_BUILD_MEMORY_SANITIZER)
set(SANITIZER_LIBRARIES_PATH) # TODO
elseif(OPTION_BUILD_ADDRESS_SANITIZER)
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=libasan${CMAKE_SHARED_LIBRARY_SUFFIX} OUTPUT_VARIABLE LIBASAN_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=libubsan${CMAKE_SHARED_LIBRARY_SUFFIX} OUTPUT_VARIABLE LIBUBSAN_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
set(SANITIZER_LIBRARIES_PATH
"${LIBASAN_PATH}"
"${LIBUBSAN_PATH}"
)
endif()
endif()

if(SANITIZER_LIBRARIES_PATH)
if(PROJECT_OS_LINUX)
list(JOIN SANITIZER_LIBRARIES_PATH " " SANITIZER_LIBRARIES_PATH_JOINED)
set(TESTS_SANITIZER_PRELOAD_ENVIRONMENT_VARIABLES
"LD_PRELOAD=${SANITIZER_LIBRARIES_PATH_JOINED}"
)
elseif(PROJECT_OS_FAMILY MATCHES "macos")
list(JOIN SANITIZER_LIBRARIES_PATH ":" SANITIZER_LIBRARIES_PATH_JOINED)
set(TESTS_SANITIZER_PRELOAD_ENVIRONMENT_VARIABLES
"DYLD_INSERT_LIBRARIES=${SANITIZER_LIBRARIES_PATH_JOINED}"
"DYLD_FORCE_FLAT_NAMESPACE=1"
)
endif()
endif()

if((PROJECT_OS_WIN AND MSVC) OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# MSVC and Clang do not require to link manually the sanitizer libraries
set(SANITIZER_LIBRARIES)
Expand Down
2 changes: 1 addition & 1 deletion source/adt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ target_compile_options(${target}
# Linker options
#

target_link_libraries(${target}
add_link_options(${target}
PRIVATE

PUBLIC
Expand Down
2 changes: 1 addition & 1 deletion source/benchmarks/log_bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ target_compile_options(${target}
# Linker options
#

target_link_libraries(${target}
add_link_options(${target}
PRIVATE
${DEFAULT_LINKER_OPTIONS}
)
Expand Down
2 changes: 1 addition & 1 deletion source/benchmarks/metacall_cs_call_bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ target_compile_options(${target}
# Linker options
#

target_link_libraries(${target}
add_link_options(${target}
PRIVATE
${DEFAULT_LINKER_OPTIONS}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,7 @@ int main(int argc, char **argv)

::benchmark::RunSpecifiedBenchmarks();

return metacall_destroy();
metacall_destroy();

return 0;
}
2 changes: 1 addition & 1 deletion source/benchmarks/metacall_node_call_bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ target_compile_options(${target}
# Linker options
#

target_link_libraries(${target}
add_link_options(${target}
PRIVATE
${DEFAULT_LINKER_OPTIONS}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,7 @@ int main(int argc, char **argv)
}
#endif /* OPTION_BUILD_LOADERS_NODE */

return metacall_destroy();
metacall_destroy();

return 0;
}
2 changes: 1 addition & 1 deletion source/benchmarks/metacall_py_c_api_bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ target_compile_options(${target}
# Linker options
#

target_link_libraries(${target}
add_link_options(${target}
PRIVATE
${DEFAULT_LINKER_OPTIONS}
)
Expand Down
2 changes: 1 addition & 1 deletion source/benchmarks/metacall_py_call_bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ target_compile_options(${target}
# Linker options
#

target_link_libraries(${target}
add_link_options(${target}
PRIVATE
${DEFAULT_LINKER_OPTIONS}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,7 @@ int main(int argc, char *argv[])
::benchmark::RunSpecifiedBenchmarks();
::benchmark::Shutdown();

if (metacall_destroy() != 0)
{
return 4;
}
metacall_destroy();

return 0;
}
2 changes: 1 addition & 1 deletion source/benchmarks/metacall_py_init_bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ target_compile_options(${target}
# Linker options
#

target_link_libraries(${target}
add_link_options(${target}
PRIVATE
${DEFAULT_LINKER_OPTIONS}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ BENCHMARK_DEFINE_F(metacall_py_init_bench, destroy)
/* Python */
#if defined(OPTION_BUILD_LOADERS_PY)
{
if (metacall_destroy() != 0)
{
state.SkipWithError("Error destroying MetaCall");
}
metacall_destroy();
}
#endif /* OPTION_BUILD_LOADERS_PY */
}
Expand Down
2 changes: 1 addition & 1 deletion source/benchmarks/metacall_rb_call_bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ target_compile_options(${target}
# Linker options
#

target_link_libraries(${target}
add_link_options(${target}
PRIVATE
${DEFAULT_LINKER_OPTIONS}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ int main(int argc, char *argv[])
::benchmark::RunSpecifiedBenchmarks();
::benchmark::Shutdown();

if (metacall_destroy() != 0)
{
return 4;
}
metacall_destroy();

return 0;
}
2 changes: 1 addition & 1 deletion source/cli/metacallcli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ target_compile_features(${target}
# Linker options
#

target_link_libraries(${target}
add_link_options(${target}
PRIVATE
${DEFAULT_LINKER_OPTIONS}
)
Expand Down
7 changes: 1 addition & 6 deletions source/cli/metacallcli/source/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,7 @@ application::application(int argc, char *argv[]) :

application::~application()
{
int result = metacall_destroy();

if (result != 0)
{
std::cout << "Error while destroying MetaCall, exit code: " << result << std::endl;
}
metacall_destroy();
}

void application::arguments_parse(std::vector<std::string> &arguments)
Expand Down
2 changes: 1 addition & 1 deletion source/cli/plugins/cli_core_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ target_compile_options(${target}
# Linker options
#

target_link_libraries(${target}
add_link_options(${target}
PRIVATE

PUBLIC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@

#include <cli_core_plugin/cli_core_plugin_api.h>

#include <dynlink/dynlink.h>

#ifdef __cplusplus
extern "C" {
#endif

CLI_CORE_PLUGIN_API int cli_core_plugin(void *loader, void *handle);

DYNLINK_SYMBOL_EXPORT(cli_core_plugin);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion source/cli/plugins/cli_sandbox_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ target_compile_options(${target}
# Linker options
#

target_link_libraries(${target}
add_link_options(${target}
PRIVATE

PUBLIC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@

#include <cli_sandbox_plugin/cli_sandbox_plugin_api.h>

#include <dynlink/dynlink.h>

#ifdef __cplusplus
extern "C" {
#endif

CLI_SANDBOX_PLUGIN_API int cli_sandbox_plugin(void *loader, void *handle);

DYNLINK_SYMBOL_EXPORT(cli_sandbox_plugin);

#ifdef __cplusplus
}
#endif
Expand Down
12 changes: 7 additions & 5 deletions source/configuration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ target_compile_options(${target}
# Linker options
#

target_link_libraries(${target}
add_link_options(${target}
PRIVATE

PUBLIC
Expand All @@ -180,17 +180,19 @@ target_link_libraries(${target}
function(configurations_write config_dir config_path)
set(CONFIGURATION_GLOBAL "{")

if(OPTION_BUILD_LOADERS)
set(CONFIGURATION_GLOBAL_LOADERS 0)
# TODO: Make this automatic for all loaders

if(OPTION_BUILD_LOADERS)
if(OPTION_BUILD_LOADERS_CS)
set(CONFIGURATION_GLOBAL "${CONFIGURATION_GLOBAL}\n\t\"cs_loader\":\"${config_dir}/cs_loader.json\",")
set(CONFIGURATION_GLOBAL_LOADERS 1)
endif()

if(OPTION_BUILD_LOADERS_NODE)
set(CONFIGURATION_GLOBAL "${CONFIGURATION_GLOBAL}\n\t\"node_loader\":\"${config_dir}/node_loader.json\",")
endif()

#if(OPTION_BUILD_LOADERS_JS)
# set(CONFIGURATION_GLOBAL "${CONFIGURATION_GLOBAL}\n\t\"js_loader\":\"${config_dir}/js_loader.json\",")
# set(CONFIGURATION_GLOBAL_LOADERS 1)
#endif()
endif()

Expand Down
2 changes: 1 addition & 1 deletion source/detour/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ target_compile_options(${target}
# Linker options
#

target_link_libraries(${target}
add_link_options(${target}
PRIVATE

PUBLIC
Expand Down
5 changes: 5 additions & 0 deletions source/detour/source/detour.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ const char *detour_name(detour d)

void (*detour_trampoline(detour_handle handle))(void)
{
if (handle == NULL)
{
return NULL;
}

return handle->target;
}

Expand Down
2 changes: 1 addition & 1 deletion source/detours/funchook_detour/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ target_compile_options(${target}
# Linker options
#

target_link_libraries(${target}
add_link_options(${target}
PRIVATE

PUBLIC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

#include <detour/detour_interface.h>

#include <dynlink/dynlink.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -45,8 +43,6 @@ extern "C" {
*/
FUNCHOOK_DETOUR_API detour_interface funchook_detour_impl_interface_singleton(void);

DYNLINK_SYMBOL_EXPORT(funchook_detour_impl_interface_singleton);

/**
* @brief
* Provide the module information
Expand All @@ -57,8 +53,6 @@ DYNLINK_SYMBOL_EXPORT(funchook_detour_impl_interface_singleton);
*/
FUNCHOOK_DETOUR_API const char *funchook_detour_print_info(void);

DYNLINK_SYMBOL_EXPORT(funchook_detour_print_info);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 3 additions & 3 deletions source/detours/funchook_detour/scripts/download.bat.in
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@echo on

rem Download repository if it does not exist
if not exist @FUNCHOOK_SOURCE_DIR@/.git (
if exist @FUNCHOOK_SOURCE_DIR@ (
if not exist "@FUNCHOOK_SOURCE_DIR@/.git" (
if exist "@FUNCHOOK_SOURCE_DIR@" (
rmdir /S /Q "@FUNCHOOK_SOURCE_DIR@"
)
"@GIT_EXECUTABLE@" clone --single-branch --branch v@FUNCHOOK_VERSION@ --recursive https://github.com/kubo/funchook.git @FUNCHOOK_SOURCE_DIR@
"@GIT_EXECUTABLE@" clone --single-branch --branch v@FUNCHOOK_VERSION@ --recursive https://github.com/kubo/funchook.git "@FUNCHOOK_SOURCE_DIR@"
)

rem Write empty CMake file to avoid cmake warnings
Expand Down
10 changes: 4 additions & 6 deletions source/detours/funchook_detour/scripts/download.sh.in
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/usr/bin/env sh

# Download repository if it does not exist
if [ ! -d @FUNCHOOK_SOURCE_DIR@/.git ]
then
if [ -d @FUNCHOOK_SOURCE_DIR@ ]
then
rm -rf @FUNCHOOK_SOURCE_DIR@
if [ ! -d "@FUNCHOOK_SOURCE_DIR@/.git" ]; then
if [ -d "@FUNCHOOK_SOURCE_DIR@" ]; then
rm -rf "@FUNCHOOK_SOURCE_DIR@"
fi
@GIT_EXECUTABLE@ clone --single-branch --branch v@FUNCHOOK_VERSION@ --recursive https://github.com/kubo/funchook.git @FUNCHOOK_SOURCE_DIR@
"@GIT_EXECUTABLE@" clone --single-branch --branch v@FUNCHOOK_VERSION@ --recursive https://github.com/kubo/funchook.git "@FUNCHOOK_SOURCE_DIR@"
fi
Loading
Loading