-
Notifications
You must be signed in to change notification settings - Fork 11
feat: Unified binary (CLI) #917
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
Open
Charlotte-Knight
wants to merge
26
commits into
develop
Choose a base branch
from
unified_binary
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
dcbe7ac
Initial unified binary work
alexanderrichards 626dcca
Fixup
alexanderrichards 56c798e
Adding Diag
alexanderrichards c74285c
fixup
alexanderrichards 9949b93
Implement the GetPenaltyTerm binary
alexanderrichards 0de2a2d
adding MACH3_ERR
alexanderrichards 8435352
allow MACH3_PLUGINS directory
alexanderrichards 6399a50
fix link time optimisation removing vtable
alexanderrichards 9248744
update
alexanderrichards c8648ec
refactoring
alexanderrichards f8e52cb
remane core library
alexanderrichards 7028897
Fix namespace and shared library install
alexanderrichards 7c9a741
implement the explicit options flags
alexanderrichards 353c4a6
fixing the diag app
alexanderrichards 06fbd7c
Adding tab completion
alexanderrichards cd4bb7d
Moving api into cli
alexanderrichards 5ddbade
rename core plugins to modules
alexanderrichards 603bbd6
Move core binaries from plugin to module naming convention
alexanderrichards c110f98
Add specific argparse tag
alexanderrichards 39592fa
moving to upppercase directories
alexanderrichards 84cc8a7
Adding Doxygen comments
alexanderrichards d8121f8
Pull completions for now
alexanderrichards c539201
migrate run -> Run as per Kamils suggestion
alexanderrichards 5b97a69
reinstating missing comments
alexanderrichards 24fe017
restore author info
alexanderrichards d8b72e8
Move Doxygen comments to triple slash format
alexanderrichards File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| include(FetchContent) | ||
| FetchContent_Declare( | ||
| argparse | ||
| GIT_REPOSITORY https://github.com/p-ranav/argparse.git | ||
| GIT_TAG d924b84eba1f0f0adf38b20b7b4829f6f65b6570 | ||
| ) | ||
| FetchContent_MakeAvailable(argparse) | ||
|
|
||
| set(HEADERS | ||
| plugin.hpp | ||
| argparse.hpp | ||
| ) | ||
|
|
||
|
|
||
| add_library(CLIApi INTERFACE) | ||
|
|
||
| target_include_directories(CLIApi INTERFACE ${argparse_SOURCE_DIR}/include) | ||
|
|
||
| target_include_directories(CLIApi | ||
| INTERFACE | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> | ||
| $<INSTALL_INTERFACE:include/CLI/API> | ||
| ) | ||
|
|
||
| set_target_properties(CLIApi PROPERTIES | ||
| PUBLIC_HEADER "${HEADERS}" | ||
| EXPORT_NAME CLIApi) | ||
|
|
||
|
|
||
| install(TARGETS CLIApi | ||
| EXPORT MaCh3-targets | ||
| LIBRARY DESTINATION lib/ | ||
| PUBLIC_HEADER DESTINATION include/CLI/API) | ||
|
|
||
| #install(FILES ${HEADERS} DESTINATION include/api) | ||
| add_library(MaCh3::CLIApi ALIAS CLIApi) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /// @file argparse.hpp | ||
| /// @brief MaCh3 wrapper for argparse library with additional functionality | ||
|
|
||
| #pragma once | ||
| #include <argparse/argparse.hpp> | ||
|
|
||
| using argparse::ArgumentParser; | ||
|
|
||
| namespace M3 { | ||
|
|
||
| /// @class MaCh3ArgumentParser | ||
| /// @brief Extended ArgumentParser with MaCh3-specific functionality | ||
| /// | ||
| /// This class extends the standard ArgumentParser to provide additional | ||
| /// methods for accessing parser name, subparsers, and tracking which | ||
| /// subcommand was used. | ||
| class MaCh3ArgumentParser: public ArgumentParser{ | ||
| public: | ||
| using ArgumentParser::ArgumentParser; | ||
| virtual ~MaCh3ArgumentParser() = default; | ||
|
|
||
| /// @brief Get the name of this parser/subcommand | ||
| /// @return The program or subcommand name | ||
| const std::string name() const{ | ||
| return this->m_program_name; | ||
| } | ||
|
|
||
| /// @brief Get the list of registered subparsers | ||
| /// @return Reference to the list of subparsers | ||
| const std::list<std::reference_wrapper<ArgumentParser>>& subparsers() const{ | ||
| return this->m_subparsers; | ||
| } | ||
|
|
||
| /// @brief Get the subcommand that was used in parsing | ||
| /// | ||
| /// Recursively traverses the subparser hierarchy to find the | ||
| /// deepest subcommand that was actually invoked. | ||
| /// | ||
| /// @return Reference to the MaCh3ArgumentParser of the used subcommand | ||
| const MaCh3ArgumentParser& get_subcommand_used() const{ | ||
| for (const std::reference_wrapper<ArgumentParser>& subparser : this->m_subparsers) { | ||
| if (this->is_subcommand_used(subparser.get())) { | ||
| return static_cast<MaCh3ArgumentParser*>(&(subparser.get()))->get_subcommand_used(); | ||
| } | ||
| } | ||
| return (*this); | ||
| } | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /// @file plugin.hpp | ||
| /// @brief Plugin interface and registration macros for MaCh3 | ||
|
|
||
| #pragma once | ||
| #include "CLI/API/argparse.hpp" | ||
|
|
||
|
|
||
| namespace M3 { | ||
|
|
||
| /// @class IPlugin | ||
| /// @brief Interface for MaCh3 plugins and modules | ||
| /// | ||
| /// All plugins and modules must implement this interface to provide | ||
| /// argument parsing and execution functionality. | ||
| class IPlugin { | ||
| public: | ||
| virtual ~IPlugin() = default; | ||
|
|
||
| /// @brief Execute the plugin's main functionality | ||
| /// @return Exit code (0 on success, non-zero on error) | ||
| virtual int Run() = 0; | ||
|
|
||
| /// @brief Get the argument parser for this plugin | ||
| /// @return Pointer to the plugin's MaCh3ArgumentParser | ||
| virtual MaCh3ArgumentParser* get_parser() = 0; | ||
| }; | ||
|
|
||
| /// @typedef IModule | ||
| /// @brief Alias for IPlugin, used for core modules | ||
| typedef IPlugin IModule; | ||
| }; | ||
|
|
||
| /// @typedef create_plugin_t | ||
| /// @brief Function pointer type for plugin factory function | ||
| extern "C" { | ||
| typedef M3::IPlugin* (*create_plugin_t)(); | ||
|
|
||
| /// @typedef destroy_plugin_t | ||
| /// @brief Function pointer type for plugin destructor function | ||
| typedef void (*destroy_plugin_t)(M3::IPlugin*); | ||
| } | ||
|
|
||
| /// @def MACH3_REGISTER_PLUGIN | ||
| /// @brief Macro to register a plugin class with MaCh3 | ||
| /// | ||
| /// This macro generates the required factory and destructor functions | ||
| /// for a plugin class. Use it in your plugin implementation file. | ||
| /// | ||
| /// @param PluginClass The plugin class that implements M3::IPlugin | ||
| /// | ||
| /// Example usage: | ||
| /// @code | ||
| /// class MyPlugin : public M3::IPlugin { | ||
| /// // ... implementation | ||
| /// }; | ||
| /// MACH3_REGISTER_PLUGIN(MyPlugin) | ||
| /// @endcode | ||
| #define MACH3_REGISTER_PLUGIN(PluginClass) \ | ||
| static_assert(std::is_base_of<M3::IPlugin, PluginClass>::value, "PluginClass must derive from M3::IPlugin"); \ | ||
| extern "C" M3::IPlugin* create_plugin() { \ | ||
| return new PluginClass(); \ | ||
| } \ | ||
| extern "C" void destroy_plugin(M3::IPlugin* p) { \ | ||
| delete p; \ | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| add_subdirectory(API) | ||
| add_subdirectory(Modules) | ||
|
|
||
|
|
||
| add_executable(mach3 | ||
| mach3.cpp | ||
| MaCh3Program.cpp | ||
| ) | ||
|
|
||
| target_link_libraries(mach3 PRIVATE MaCh3::CLIModules MaCh3::All) | ||
|
|
||
| install(TARGETS mach3 DESTINATION bin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /// @file DynamicPlugin.hpp | ||
| /// @brief Wrapper class for dynamically loaded plugins | ||
|
|
||
| #pragma once | ||
| #include <dlfcn.h> | ||
| #include "CLI/API/plugin.hpp" | ||
|
|
||
| namespace M3{ | ||
| /// @class DynamicPlugin | ||
| /// @brief Manages the lifecycle of a dynamically loaded plugin | ||
| /// | ||
| /// This class wraps a plugin loaded from a shared library, maintaining the | ||
| /// library handle and providing cleanup functionality. | ||
| class DynamicPlugin: public IPlugin{ | ||
| public: | ||
| /// @brief Constructor for a dynamic plugin | ||
| /// @param handle Handle to the loaded shared library | ||
| /// @param plugin Pointer to the instantiated plugin | ||
| /// @param destroy_func Function pointer to destroy the plugin | ||
| DynamicPlugin(void* handle, | ||
| IPlugin* plugin, | ||
| destroy_plugin_t destroy_func):m_handle(handle), | ||
| m_plugin(plugin), | ||
| m_destroy_func(destroy_func){} | ||
|
|
||
| /// @brief Run the plugin's main functionality | ||
| /// @return Exit code from the plugin | ||
| int Run() { | ||
| return m_plugin->Run(); | ||
| } | ||
|
|
||
| /// @brief Get the argument parser for this plugin | ||
| /// @return Pointer to the plugin's argument parser | ||
| MaCh3ArgumentParser* get_parser(){ | ||
| return m_plugin->get_parser(); | ||
| } | ||
|
|
||
| /// @brief Destroy the plugin and close the shared library | ||
| /// | ||
| /// Calls the plugin's destroy function and closes the library handle. | ||
| void destroy(){ | ||
| m_destroy_func(m_plugin); | ||
| m_plugin = 0; | ||
| dlclose(m_handle); | ||
| m_handle = 0; | ||
| m_destroy_func = 0; | ||
| } | ||
|
|
||
| private: | ||
| void* m_handle; ///< Handle to the loaded shared library | ||
| IPlugin* m_plugin; ///< Pointer to the plugin instance | ||
| destroy_plugin_t m_destroy_func; ///< Function pointer to destroy the plugin | ||
| }; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.