Skip to content
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
9 changes: 5 additions & 4 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
name: Build and test (${{ matrix.os }})
compiler: [clang, gcc]
name: Build and test (${{ matrix.os }} - ${{matrix.compiler}})
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
- uses: cachix/install-nix-action@v31
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: CMake configure
run: nix develop --command cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
run: nix develop .#${{matrix.compiler}} --command cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: CMake Build
run: nix develop --command cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j
run: nix develop .#${{matrix.compiler}} --command cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j
- name: CMake Test
working-directory: ${{github.workspace}}/build
run: nix develop --command ctest -C ${{ env.BUILD_TYPE }}
run: nix develop .#${{matrix.compiler}} --command ctest -C ${{ env.BUILD_TYPE }} --output-on-failure
21 changes: 13 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# GCC build struggles on mac and it requires to enforce this variable to empty
# to successfully link agains libraries.
# This option is valid only on Apple architectures
set(CMAKE_OSX_ARCHITECTURES "" CACHE STRING "")

cmake_minimum_required(VERSION 3.31.0)
project(Simo VERSION 0.0.1)
include(CPack)
Expand Down Expand Up @@ -78,19 +83,17 @@ set_target_properties(Simo PROPERTIES
target_compile_options(Simo PRIVATE -fno-exceptions)
target_compile_options(Simo PUBLIC -fno-rtti)

find_package(Boost REQUIRED COMPONENTS unit_test_framework)
find_package(Boost REQUIRED)
message("Boost version: ${Boost_VERSION}")

find_package(glaze REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE glaze::glaze)
target_link_libraries(${PROJECT_NAME} PRIVATE Boost::boost glaze::glaze)


if (DEBUG_CMAKE)
message(STATUS "Boost include dirs: ${Boost_INCLUDE_DIRS}")
endif ()

target_include_directories(Simo SYSTEM PUBLIC ${Boost_INCLUDE_DIRS})

set_target_properties(Simo PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN 1
Expand All @@ -111,6 +114,9 @@ target_include_directories(Simo_includes_only
$<INSTALL_INTERFACE:include>
)
target_link_libraries(Simo_includes_only INTERFACE glaze::glaze)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(Simo_includes_only INTERFACE -fno-gnu-unique)
endif()
target_compile_options(Simo_includes_only INTERFACE -fno-rtti)
# Avoid linking against Simo
if (APPLE)
Expand Down Expand Up @@ -154,9 +160,8 @@ install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/support/cmake/SimoConfig.cmake" "${CM
enable_testing()
function(create_unit_test_executable name)
add_executable("${name}")
target_include_directories("${name}" PRIVATE include)
target_include_directories("${name}" PRIVATE src)
target_link_libraries("${name}" PRIVATE Boost::unit_test_framework)
target_include_directories("${name}" PRIVATE include src tests)
target_link_libraries("${name}" PRIVATE Boost::boost)
add_test("${name}" "${name}")
if (ENABLE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set_tests_properties("${name}" PROPERTIES
Expand Down Expand Up @@ -256,4 +261,4 @@ if (ENABLE_DOCUMENTATION)
doxygen_docs
include src docs tests "${CMAKE_CURRENT_SOURCE_DIR}/README.md"
)
endif()
endif()
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The build is going to be accessible in the `result` folder.
Clone Simo and initialize the submodules:

Build dependencies:
- Clang (recommended)
- Clang (recommended) or gcc
- CMake >= 3.31.0
- Boost ([Boost.Test](https://www.boost.org/libs/test), [Boost.TypeIndex](https://www.boost.org/libs/type_index))
- [Glaze](https://github.com/stephenberry/glaze)
Expand Down Expand Up @@ -69,6 +69,9 @@ This can be achieved with:
- Good documented code
- Proper unit-testing coverage

Default compiler is clang. There is support for gcc build as well. With `nix`, use `nix develop .#gcc` to obtain
a development environment that uses gcc as compiler.

### IDEs
You can see [this guide](./support/ides/clion/README.md) on how to use nix
binaries to build in CLion.
Expand Down
2 changes: 2 additions & 0 deletions docs/guided_examples/1_FirstModule_and_SimoSim/FirstModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ static Simo::Collections::SimoCollection collection{
.factory_list_size = FACTORY_LIST.size(),
};

SIMO_COLLECTION_DECLARATION;

// This exposes the collection
SIMO_PUBLIC const Simo::Collections::SimoCollection* simo_get_collection() {
return &collection;
Expand Down
5 changes: 3 additions & 2 deletions docs/guided_examples/1_FirstModule_and_SimoSim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class FirstModuleParameters : public Parameters {
## Expose modules and parameters for SimoSim

`SimoSim` is an executable able to detect shared libraries at runtime that contains
modules. A shared library needs to expose a function named `simo_get_collection`.
modules. A shared library needs to expose a function named `simo_get_collection`and add `SIMO_COLLECTION_DECLARATION`
**only once per library**.
With this function, `SimoSim` can load a collection of factories. A Factory tells
`SimoSim` how to instantiate a module and the associated parameters.

Expand Down Expand Up @@ -141,4 +142,4 @@ Try to create your own module and pack it into a collection.
A more complete example is the `PingPongCollection` at
`tests/collection/PingPongCollection.cc`.

The second example will show how to deal with module ports.
The second example will show how to deal with module ports.
40 changes: 37 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@
system:
let
pkgs = import nixpkgs { inherit system; };
simoBaseAttributes = {
pname = "simo";
version = "0.0.1";
src = ./.;

nativeBuildInputs = with pkgs; [
# Real build dependencies
cmake
ninja
doxygen
];

buildInputs = with pkgs; [
boost
glaze
];

cmakeFlags = [
"-DPORTABLE_BUILD=ON"
"-DENABLE_RELEASE_LTO=OFF"
"-DCMAKE_CXX_SCAN_FOR_MODULES=OFF"
];

doCheck = true;
checkPhase = ''
ctest --output-on-failure
'';
};
simo = pkgs.clangStdenv.mkDerivation {
pname = "simo";
version = "0.0.1";
Expand Down Expand Up @@ -57,10 +85,16 @@
ctest --output-on-failure
'';
};

derivationAttributes = {
default = pkgs.clangStdenv.mkDerivation simoBaseAttributes;
clang = pkgs.clangStdenv.mkDerivation simoBaseAttributes;
gcc = pkgs.gccStdenv.mkDerivation simoBaseAttributes;
};
in
{
packages.default = simo;
checks.default = simo;
packages = derivationAttributes;
checks = derivationAttributes;

formatter = nixpkgs.legacyPackages.${system}.nixfmt;

Expand All @@ -70,7 +104,7 @@
stdenv = pkgs.clangStdenv;
}
{
inputsFrom = [ simo ];
inputsFrom = [ derivationAttributes.default ];
packages = with pkgs; [
clang-tools
ast-grep
Expand Down
29 changes: 26 additions & 3 deletions include/Simo/collection/Collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,31 @@

#include "Simo/module/Module.h"

#define SIMO_COLLECTION_FUNCTION_NAME_SYMBOL "SIMO_COLLECTION_FUNCTION"
#define SIMO_STRINGIFY_IMPL(x) #x
#define SIMO_STRINGIFY(x) SIMO_STRINGIFY_IMPL(x)

#define SIMO_COLLECTION_FUNCTION_NAME_DEFAULT "simo_get_collection"
#define SIMO_COLLECTION_FUNCTION_NAME_SYMBOL SIMO_COLLECTION_FUNCTION
#define SIMO_COLLECTION_FUNCTION_NAME_SYMBOL_STR \
SIMO_STRINGIFY(SIMO_COLLECTION_FUNCTION_NAME_SYMBOL)

#define SIMO_COLLECTION_FUNCTION_NAME_DEFAULT simo_get_collection
#define SIMO_COLLECTION_FUNCTION_NAME_DEFAULT_STR \
SIMO_STRINGIFY(SIMO_COLLECTION_FUNCTION_NAME_DEFAULT)

#define SIMO_COLLECTION_SECTION_STR ".Simo.collection"

#if defined(__APPLE__)
#define SIMO_COLLECTION_SECTION "__TEXT," SIMO_COLLECTION_SECTION_STR
#else
#define SIMO_COLLECTION_SECTION SIMO_COLLECTION_SECTION_STR
#endif

#define SIMO_COLLECTION_DECLARATION_NAME(name) \
extern SIMO_PUBLIC __attribute__((used, section(SIMO_COLLECTION_SECTION))) \
const char SIMO_COLLECTION_FUNCTION_NAME_SYMBOL[] = SIMO_STRINGIFY(name);

#define SIMO_COLLECTION_DECLARATION \
SIMO_COLLECTION_DECLARATION_NAME(SIMO_COLLECTION_FUNCTION_NAME_DEFAULT)

namespace Simo {
class Module;
Expand Down Expand Up @@ -100,7 +122,8 @@ enum struct SIMO_PUBLIC GET_COLLECTION_ERROR : std::uint8_t {
DLOPEN_FAIL,
NO_FUNCTION_NAME,
NOT_A_DIRECTORY,
ALREADY_LOADED_LIBRARY
ALREADY_LOADED_LIBRARY,
NO_SIMO_COLLECTION_SECTION,
};

struct SIMO_PUBLIC GetCollectionError {
Expand Down
2 changes: 1 addition & 1 deletion include/Simo/module/core/Collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ class Collector : public Module {
};
} // namespace Simo::Modules::Core

#endif // SIMO_COLLECTOR_HH
#endif // SIMO_COLLECTOR_HH
Loading