Skip to content
Open
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
640 changes: 553 additions & 87 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ CLI tool to generate bindings for WIT documents and the component model.
[workspace]
members = [
"crates/test-rust-wasm",
"crates/cpp/tests/native_mesh/rust/mesh",
"crates/cpp/tests/native_mesh/rust/component_a",
"crates/cpp/tests/native_mesh/rust/component_b",
]
resolver = "2"

Expand Down
18 changes: 9 additions & 9 deletions crates/cpp/tests/native_mesh/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

all:
make -C component_b $@
make -C mesh $@
make -C component_a $@
make -C cpp/component_b $@
make -C cpp/mesh $@
make -C cpp/component_a $@

bindgen:
make -C component_b $@
make -C mesh $@
make -C component_a $@
make -C cpp/component_b $@
make -C cpp/mesh $@
make -C cpp/component_a $@

clean:
make -C component_b $@
make -C mesh $@
make -C component_a $@
make -C cpp/component_b $@
make -C cpp/mesh $@
make -C cpp/component_a $@

108 changes: 108 additions & 0 deletions crates/cpp/tests/native_mesh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Introduction

The native-mesh example contains two components, `component_a` and `component_b`.
Both these components communicate to each other using `mesh`.

This example has been implemented in C++ as well as Rust.

# Building

To build the C++ version, use the make file.

Since the `wit-bindgen` does not create the complete code for `Rust`, the bindings are
generated, hand patched and stored with the code.

To build each and every individual components, use `cargo build` inside that specific directory.
Or
Just do `cargo build component_a`, will build all the dependent components and the binary.

Build the `component_b`, `mesh` and `component_a` in that order.

The actual binary is `component_a` and will be present in `wit-bindgen/target/debug`.

# Running

To run the application use `caro run` inside the `component_a`
Or
once the build is successful, run the binary from `./wit-bindgen/target/debug/component_a`

```

The code directory structure looks as below

├── Makefile
├── cpp
│ ├── component_a
│ │ ├── Makefile
│ │ ├── a.cpp
│ │ ├── a_cpp.h
│ │ ├── component_a
│ │ ├── libcomponent_b.so -> ../component_b/libcomponent_b.so
│ │ ├── libmesh.so -> ../mesh/libmesh.so
│ │ └── main.cpp
│ ├── component_b
│ │ ├── Makefile
│ │ ├── b.cpp
│ │ ├── b_cpp.h
│ │ ├── exports-foo-foo-resources-R.h
│ │ ├── impl.cpp
│ │ └── libcomponent_b.so
│ └── mesh
│ ├── Makefile
│ ├── impl.cpp
│ ├── libcomponent_b.so -> ../component_b/libcomponent_b.so
│ ├── libmesh.so
│ ├── mesh-exports-foo-foo-resources-R.h
│ ├── mesh-exports-foo-foo-resources.h
│ ├── mesh_cpp_native.h
│ └── mesh_native.cpp
├── rust
│ ├── README.md
│ ├── component_a
│ │ ├── Cargo.lock
│ │ ├── Cargo.toml
│ │ └── src
│ │ ├── a.rs
│ │ ├── a_impl.rs
│ │ └── main.rs
│ ├── component_b
│ │ ├── Cargo.lock
│ │ ├── Cargo.toml
│ │ └── src
│ │ ├── b.rs
│ │ ├── b_impl.rs
│ │ ├── lib.rs
│ │ └── resource_table.rs
│ └── mesh
│ ├── Cargo.lock
│ ├── Cargo.toml
│ └── src
│ ├── impl_mesh.rs
│ ├── lib.rs
│ └── mesh.rs
└── wit
└── resources_simple.wit ( Contains the wit interface definitions for the components and the mesh)

```

# Internal working

`component_b` export three interfaces `create`, `add` and `consume`. `component_a` uses those `interfaces`.

The `component_a` askes for creating a resource in `component_b` address space through the `mesh`.
So, `component_a` a receive the created object through `mesh`.
The `mesh` acts like a transport between the two components.
`mesh` stores the `resource` in its table and pass the `reference` to that object.

The same functionality happens for all the three apis that are exported by the `component_b`.


Note: Rust does not build the .so objects for the libraries, it uses the `crates` mechanism to share the interfaces
with other components.







Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CXXFLAGS=-g -O0 -I../../../helper-types
CXXFLAGS=-g -O0 -I../../../../helper-types -std=c++1z

all: component_a

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CXXFLAGS=-fPIC -g -O0 -I../../../helper-types
CXXFLAGS=-fPIC -g -O0 -I../../../../helper-types -std=c++1z

all: libcomponent_b.so

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CXXFLAGS=-fPIC -g -O0 -I../../../helper-types
CXXFLAGS=-fPIC -g -O0 -I../../../../helper-types -std=c++1z

all: libmesh.so

Expand Down
Binary file added crates/cpp/tests/native_mesh/cpp/mesh/libmesh.so
Binary file not shown.
Loading