-
Notifications
You must be signed in to change notification settings - Fork 13
Add optional static TinyMemory module exports #166
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
81d76fd
Add optional linked TinyMemory module exports
senamakel 5c861b0
Permit scoped unsafe linked-host test calls
senamakel 5c85aca
Exercise linked TinyMemory through the bus host
senamakel 5024c3d
Keep dynamic loader tests in dynamic mode
senamakel 7238e07
Measure dynamic module dispatch coverage
senamakel 90a8c07
Cover both TinyMemory module export modes
senamakel 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,63 @@ | ||
| //! Public linked-module entry points remain callable by a Rust host. | ||
|
|
||
| #![cfg(feature = "static-link")] | ||
|
senamakel marked this conversation as resolved.
|
||
|
|
||
| use tinybus::broker::Broker; | ||
| use tinybus::module::abi::{TbModuleInit, TbSlice, ABI_MAGIC}; | ||
| use tinybus::module::manifest::ModuleManifest; | ||
| use tinybus::module::ModuleHost; | ||
| use tinybus::transport::memory::MemoryBus; | ||
| use tinybus::Connection; | ||
| use tinymemory_module::{ | ||
| tinybus_module_init_v1, tinybus_module_manifest_v1, BUS_NAME, OBJECT_PATH, | ||
| TINYBUS_MODULE_ABI_V1, | ||
| }; | ||
|
|
||
| #[test] | ||
| fn linked_module_exposes_its_descriptor_manifest_and_initializer() { | ||
| assert_eq!(TINYBUS_MODULE_ABI_V1.magic, ABI_MAGIC); | ||
| let manifest: extern "C" fn() -> TbSlice = tinybus_module_manifest_v1; | ||
| let slice = manifest(); | ||
| assert!(!slice.ptr.is_null()); | ||
| assert!(slice.len > 0); | ||
| let initialize: TbModuleInit = tinybus_module_init_v1; | ||
| assert_ne!(initialize as usize, 0); | ||
| } | ||
|
|
||
| #[allow(unsafe_code)] | ||
|
senamakel marked this conversation as resolved.
|
||
| #[tokio::test] | ||
| async fn linked_module_serves_memory_calls_through_tinybus( | ||
| ) -> Result<(), Box<dyn std::error::Error>> { | ||
| let workspace = tempfile::tempdir()?; | ||
| let bus = MemoryBus::new(); | ||
| let broker = Broker::new(); | ||
| let _broker_task = broker.spawn(bus.clone()); | ||
| let host = ModuleHost::new(broker); | ||
|
|
||
| let slice = tinybus_module_manifest_v1(); | ||
| // SAFETY: the generated manifest owns its bytes in a process-lifetime | ||
| // OnceLock; its non-null pointer and length remain valid during parsing. | ||
| let bytes = unsafe { std::slice::from_raw_parts(slice.ptr, slice.len) }; | ||
| let manifest: ModuleManifest = serde_json::from_slice(bytes)?; | ||
| let config = serde_json::json!({ "workspace_dir": workspace.path() }); | ||
|
|
||
| // SAFETY: these three entries come from the linked module in this process. | ||
| // They remain mapped and callable until exit, including all callbacks the | ||
| // host retains after initialization. | ||
| let loaded = unsafe { | ||
| host.attach_raw_with_config( | ||
|
senamakel marked this conversation as resolved.
senamakel marked this conversation as resolved.
|
||
| "linked-tinymemory", | ||
| TINYBUS_MODULE_ABI_V1, | ||
| manifest, | ||
| tinybus_module_init_v1, | ||
| config, | ||
| ) | ||
| }?; | ||
| assert_eq!(loaded.manifest.bus_name.as_str(), BUS_NAME); | ||
|
|
||
| let client = Connection::connect(bus.connect().await?).await?; | ||
| let proxy = client.proxy(BUS_NAME, OBJECT_PATH, "ai.tinyhumans.tinymemory.Memory")?; | ||
| let driver_id: String = proxy.call("DriverId", ()).await?; | ||
| assert_eq!(driver_id, "tinycortex"); | ||
| Ok(()) | ||
| } | ||
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
Submodule tinybus
updated
11 files
| +3 −3 | Cargo.lock | |
| +4 −4 | Cargo.toml | |
| +3 −0 | crates/tinybus-module/Cargo.toml | |
| +188 −40 | crates/tinybus-module/src/lib.rs | |
| +161 −0 | crates/tinybus-module/src/static_link_tests.rs | |
| +80 −4 | crates/tinybus/src/module/host.rs | |
| +61 −0 | crates/tinybus/src/module/host_test.rs | |
| +9 −6 | crates/tinybus/src/module/loader.rs | |
| +7 −1 | crates/tinybus/src/module/transport.rs | |
| +4 −1 | docs/modules/module/README.md | |
| +2 −252 | examples/Cargo.lock |
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.