Skip to content

XPlugin Integration #283

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

Draft
wants to merge 2 commits into
base: main
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
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ option(XEUS_CPP_USE_SHARED_XEUS "Link xcpp with the xeus shared library (instea
option(XEUS_CPP_USE_SHARED_XEUS_CPP "Link xcpp with the xeus shared library (instead of the static library)" ON)
option(XEUS_CPP_EMSCRIPTEN_WASM_BUILD "Build for wasm with emscripten" OFF)

# Plugin system option
option(XEUS_CPP_XPLUGIN "Enable xplugin integration" OFF)

# Test options
option(XEUS_CPP_BUILD_TESTS "xeus-cpp test suite" ON)
option(XEUS_CPP_ENABLE_CODE_COVERAGE "xeus-cpp test suite" OFF)
Expand Down Expand Up @@ -108,6 +111,15 @@ endif()
find_package(argparse REQUIRED)
find_package(pugixml REQUIRED)

if(XEUS_CPP_XPLUGIN)
message(STATUS "xplugin integration is enabled.")

# Find the xplugin library
find_package(xplugin REQUIRED)
else()
message(STATUS "xplugin integration is disabled.")
endif()

# Configuration
# =============

Expand Down Expand Up @@ -367,6 +379,17 @@ macro(xeus_cpp_create_target target_name linkage output_name)
target_link_libraries(${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse)
endif()

if(XEUS_CPP_XPLUGIN)
# Add xplugin include directories
target_include_directories(${target_name} PRIVATE ${xplugin_INCLUDE_DIRS})

# Link the xplugin library
target_link_libraries(${target_name} PRIVATE xplugin)

# Define a macro to enable plugin-related code
target_compile_definitions(${target_name} PRIVATE XEUS_CPP_XPLUGIN)
endif()

if (WIN32 OR CYGWIN)
#
elseif (APPLE)
Expand Down
27 changes: 26 additions & 1 deletion src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
#include "xparser.hpp"
#include "xsystem.hpp"

#ifdef XEUS_CPP_XPLUGIN
#include "xplugin/xplugin_registry.hpp"
#include "xplugin/xfactory.hpp"
#include "xplugin/xshared_library.hpp"
#include "xplugin/xmagics.hpp"
#include "xplugin/os.hpp"
#endif

using Args = std::vector<const char*>;

void* createInterpreter(const Args &ExtraArgs = {}) {
Expand Down Expand Up @@ -114,6 +122,18 @@ __get_cxx_version ()
redirect_output();
init_preamble();
init_magic();

#ifdef XEUS_CPP_XPLUGIN
// Initialize the xplugin registry
using base_type = plugin::PluginBase;
using factory_base_type = xp::xfactory_base<base_type, int, std::string>;
using plugin_registry_type = xp::xplugin_registry<factory_base_type>;

m_plugin_registry = std::make_unique<plugin_registry_type>();

// Load plugins from a directory
m_plugin_registry->load_plugins("/path/to/plugins");
#endif
}

interpreter::~interpreter()
Expand Down Expand Up @@ -367,14 +387,19 @@ __get_cxx_version ()

void interpreter::init_magic()
{
// preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("executable",
// preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("executable",
// executable(m_interpreter));
// preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("timeit",
// timeit(&m_interpreter));
// preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("python", pythonexec());
preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("file", writefile());

#ifndef EMSCRIPTEN
preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("xassist", xassist());
#endif

#ifdef XEUS_CPP_XPLUGIN
preamble_manager["magics"].get_cast<xp::xmagics_manager>().register_magic("file", xp::writefile());
#endif
}
}
Loading