Add support for static/linked libraries bundles
Support for Static Bundle Libraries
The goal of this ticket is to introduce support for static bundle libraries in Apache Celix. These static libraries, which may or may not include shared libraries, will be linked with an executable and function as bundles for the Apache Celix Framework.
Advantages
-
Simplified Deployment: By allowing the creation of single executable files that can encompass all necessary dependencies, the deployment process can become more straightforward.
-
Less Configuration: Leveraging static libraries reduces the need for additional configuration (bundles dependencies, compiler defines for bundle files, etc), particularly during testing. It could be possible that only a linking to a (static) bundle library is needed.
-
Standard Build Tool Usage: Bundles as static libraries can use the default build tooling facilities (linking, installation, and other build-related tasks).
-
Rust alignment: Using static libraries as bundle is more aligned with development concept used in languages like Rust.
Challenges
-
Maintaining the Open-Close Principle: A challenge is ensuring that static bundle libraries can be integrated without violating the Open-Close Principle. Ideally, developers should be able to include static bundle libraries with minimal changes to the source code. One potential solution to explore is using the compiler attribute
__attribute__((constructor))to handle initialization. -
Handling Resource Files: Static bundle libraries should be capable of containing resource files. A possible approach to address this is by "linking" binary zip files into the static bundle library. This method allows resource files to be embedded within the bundle.
-
Multiple Framework Instances: If the concept of
__attribute__((constructor))is adopted, this will have impact when multiple framework instances are created. Bundles could be added to all instances by default or only the first instance, etc. -
Bundle Activator Setup: The current setup for bundle activators relies on predefined symbol names, which does not function with static bundles. Although not a major issue, it could complicate the creation of two versions of a bundle, one as a static bundle and the other as a zip bundle.
-
Default Delivered Bundle: A final decision must be made regarding the default delivered bundle type for Apache Celix bundles (static bundle, zip bundle or both)
Links
https://docs.cppmicroservices.org/en/stable/framework/doc/static_bundles.html
Example resource zip files attached to a shared (bundle) lib
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/bundle_resources.zip
COMMAND zip -rq ${CMAKE_CURRENT_BINARY_DIR}/bundle_resources.zip *
COMMENT "Packaging Resources"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/resources
)
add_custom_target(create_resources ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/bundle_resources.zip
)
add_library(FooBundle SHARED
....
)
target_include_directories(FooBundle PRIVATE src)
target_link_libraries(FooBundle PUBLIC Celix::framework)
add_dependencies(FooBundle create_resources)
#TODO should eventually be done by a CMake command (i.e. the add_celix_bundle)
if (UNIX AND NOT APPLE)
target_link_libraries(FooBundle PRIVATE -Wl,--format=binary -Wl,bundle_resources.zip -Wl,--format=default)
else ()
target_link_libraries(FooBundle PRIVATE -Wl,-sectcreate -Wl,resources -Wl,bundle_resources -Wl,bundle_resources.zip)
endif ()