Open imtsuki opened 6 months ago
@imtsuki No need to support plugin written in other languages. It is necessary to provide a build image of the plugin to make a consistent environment, refer to https://d7y.io/docs/next/contribute/development-guide/plugin-builder/.
@gaius-qi I think what @imtsuki mean is if we want to load .so dynamically as what the example doing now, we need to take ffi safety into consideration.
Currently Rust compiler does not provide any guarantee for ABI stability across FFI boundaries, so the calling convention, trait object layout, etc. might be different across compiler versions or even different builds. Some issues in current backend plugin implementation include
register_plugin
is notextern "C"
;register_plugin
returns a trait object, which is not FFI-safe;async_trait
desugars to something likefn () -> Box<dyn Future>
, which also returns a trait object;HeadRequest
are notrepr(C)
.https://github.com/dragonflyoss/client/blob/b2ff71c7b93fba5cf5411142ab34232a4e1f9015/dragonfly-client-backend/examples/plugin/src/lib.rs#L31-L51
I suggest to use some libraries like https://docs.rs/async-ffi/latest/async_ffi/ and https://docs.rs/abi_stable/latest/abi_stable/; or if we want to support plugins written in other languages, we might need to re-consider the interface design, particularly regarding how should we handle async operations like
Future
s.