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 15 commits into
base: develop
Choose a base branch
from
Draft
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
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
78 changes: 78 additions & 0 deletions cmake/FindLibGit2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#
# CMake Find LibGit2 Library by Parra Studios
# Copyright (C) 2016 - 2025 Vicente Eduardo Ferrer Garcia <[email protected]>
#

# Find libgit2 library and include paths
#
# LibGit2_FOUND - True if LibGit2 was found
# LibGit2_INCLUDE_DIR - LibGit2 headers path
# LibGit2_VERSION - LibGit2 version
# LibGit2_VERSION_MAJOR - LibGit2 major version
# LibGit2_VERSION_MINOR - LibGit2 minor version
# LibGit2_VERSION_REVISION - LibGit2 patch version
# LibGit2_LIBRARY - LibGit2 shared library
# LibGit2_LIBRARY_DIR - LibGit2 shared library folder
#

# Prevent vervosity if already included
if(LibGit2_LIBRARY)
set(LibGit2_FIND_QUIETLY TRUE)
endif()

# Include package manager
include(FindPackageHandleStandardArgs)

# Find via PkgConfig
find_package(PkgConfig QUIET)
pkg_check_modules(PKG_GIT2 QUIET libgit2)

if(NOT LibGit2_DEFINITIONS)
set(LibGit2_DEFINITIONS ${PKG_GIT2_CFLAGS_OTHER})
endif()

if(NOT LibGit2_INCLUDE_DIR)
find_path(LibGit2_INCLUDE_DIR
NAMES git2.h
HINTS ${PKG_GIT2_INCLUDE_DIRS}
)
endif()

if(NOT LibGit2_VERSION AND LibGit2_INCLUDE_DIR)
file(STRINGS "${LibGit2_INCLUDE_DIR}/git2/version.h" LibGit2_VERSION_MAJOR REGEX "^#define LIBGIT2_VER_MAJOR +([0-9]+)")
string(REGEX MATCH "([0-9]+)$" LibGit2_VERSION_MAJOR ${LibGit2_VERSION_MAJOR})

file(STRINGS "${LibGit2_INCLUDE_DIR}/git2/version.h" LibGit2_VERSION_MINOR REGEX "^#define LIBGIT2_VER_MINOR +([0-9]+)")
string(REGEX MATCH "([0-9]+)$" LibGit2_VERSION_MINOR ${LibGit2_VERSION_MINOR})

file(STRINGS "${LibGit2_INCLUDE_DIR}/git2/version.h" LibGit2_VERSION_REVISION REGEX "^#define LIBGIT2_VER_REVISION +([0-9]+)")
string(REGEX MATCH "([0-9]+)$" LibGit2_VERSION_REVISION ${LibGit2_VERSION_REVISION})

set(LibGit2_VERSION "${LibGit2_VERSION_MAJOR}.${LibGit2_VERSION_MINOR}.${LibGit2_VERSION_REVISION}")
endif()

if(NOT LibGit2_LIBRARY)
find_library(LibGit2_LIBRARY
NAMES git2
HINTS ${PKG_GIT2_LIBRARY_DIRS}
)
endif()

set(LibGit2_LIBRARIES ${LibGit2_LIBRARY})
set(LibGit2_INCLUDE_DIRS ${LibGit2_INCLUDE_DIR})
get_filename_component(LibGit2_LIBRARY_DIR ${LibGit2_LIBRARY} DIRECTORY)

# Define package
find_package_handle_standard_args(LibGit2
FOUND_VAR
LibGit2_FOUND
REQUIRED_VARS
LibGit2_LIBRARY
LibGit2_LIBRARY_DIR
LibGit2_INCLUDE_DIR
LibGit2_INCLUDE_DIRS
VERSION_VAR
LibGit2_VERSION
)

mark_as_advanced(LibGit2_LIBRARY LibGit2_LIBRARY_DIR LibGit2_INCLUDE_DIR)
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;
}
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;
}
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;
}
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
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;
}
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
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
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
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
3 changes: 0 additions & 3 deletions source/dynlink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,14 @@ set(headers
${include_path}/dynlink.h
${include_path}/dynlink_flags.h
${include_path}/dynlink_impl.h
${include_path}/dynlink_impl_symbol_${DYNLINK_IMPL_INTERFACE_NAME}.h
${include_path}/dynlink_impl_${DYNLINK_IMPL_INTERFACE_NAME}.h
${include_path}/dynlink_symbol.h
)

set(sources
${source_path}/dynlink.c
${source_path}/dynlink_impl.c
${source_path}/dynlink_impl_${DYNLINK_IMPL_INTERFACE_NAME}.c
${source_path}/dynlink_interface.c
${source_path}/dynlink_symbol.c
)

# Group source files
Expand Down
1 change: 0 additions & 1 deletion source/dynlink/include/dynlink/dynlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include <dynlink/dynlink_flags.h>
#include <dynlink/dynlink_interface.h>
#include <dynlink/dynlink_symbol.h>

#ifdef __cplusplus
extern "C" {
Expand Down
4 changes: 0 additions & 4 deletions source/dynlink/include/dynlink/dynlink_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
extern "C" {
#endif

/* -- Headers -- */

#include <stdlib.h>

/* -- Methods -- */

/**
Expand Down
2 changes: 0 additions & 2 deletions source/dynlink/include/dynlink/dynlink_impl_beos.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

#include <dynlink/dynlink_api.h>

#include <dynlink/dynlink_impl_symbol_beos.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
2 changes: 0 additions & 2 deletions source/dynlink/include/dynlink/dynlink_impl_macos.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

#include <dynlink/dynlink_api.h>

#include <dynlink/dynlink_impl_symbol_macos.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
62 changes: 0 additions & 62 deletions source/dynlink/include/dynlink/dynlink_impl_symbol_beos.h

This file was deleted.

Loading
Loading