2 releases
0.1.1 | Aug 6, 2023 |
---|---|
0.1.0 | Aug 5, 2023 |
#23 in #idl
33KB
510 lines
Nucom
Nucom provides a cross-platform implementation of the Component Object Model (COM) architecture found on the Windows platform, for C, C++, and Rust.
The project contains C/C++ code, but the Rust crates do not need a C compiler to work. Compiling the C/C++ library however does need a Rust compiler, since the IDL compiler, nuidl, is written in Rust.
Example code: Here's test code to ensure calling methods on COM classes written in C/C++/Rust from those three languages works.
How to use
From C/C++: Use the Nix package manager to get the library. The Nix flake URL for this repository is "git+https://git.dblsaiko.net/nucom". Best support is with the CMake build system, which also provides support to build IDL files, but a pkg-config file is also provided by the Nix package.
From Rust: Add the nucomcore and nuidl crates to your project. To enable auto-detection for IDL include paths, add a build.rs file with this content:
fn main() {
nuidl::cargo::use_cargo_deps();
}
Why?
Initially this started as part of an effort to port a Windows application heavily using COM interfaces to Linux. It has since outgrown that project.
A full COM implementation is a one-stop shop for these:
- object model for C, which maps 1:1 onto C++ classes and can be adapted to work for various other languages like Rust
- stable C ABI
- IPC and network transparency
Specifically for Rust, this means that in the absence of a stable Rust ABI, it can be used as that, for example as part of a plugin interface. This also doesn't limit plugin implementers to any particular language, rather, anything that can use C types could in theory be used. It's also yet another way to achieve C++ to Rust interop.
(Personally I also just think it's really neat.)
Goals
- Documentation -- :))))
- Support for creating COM classes in C/C++ -- done
- Support for creating COM classes in Rust -- works but not nice to use yet
- Support for Win32's standard COM base interfaces -- partially done
- IDL compiler for Rust, C++ and C -- usable for basic IDL files
- Binary compatibility with libraries written for Win32 COM -- not done, not currently testing anything on Windows
- RPC -- not done, this is a huge protocol
- Marshalling and DCOM -- not done, needs RPC
Undecided
- Windows concepts of COM servers and automatic activation -- this is kinda cursed and also requires a system-wide registry of some kind
Non-Goals
- 1:1 source compatibility for C/C++ or IDL (rather, this tries to improve upon Win32's API)
Related Projects
- The Wine project, which implements the entirety of COM as it exists on Windows
- intercom, a Rust crate for cross-platform COM
- windows-rs, Rust bindings to the Windows API
- DCE/RPC, the RPC protocol used in DCOM, implementation written in C
Dependencies
~5–14MB
~171K SLoC