Skip to content

Commit

Permalink
finish up template and remove depgen from workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
wilyle committed Sep 7, 2023
1 parent 3d0511a commit 6360131
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 31 deletions.
15 changes: 0 additions & 15 deletions .github/actions/freyja-depgen/action.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ jobs:
components: clippy rustfmt
- name: Cache Dependencies
uses: Swatinem/rust-cache@v2
- name: Freyja depgen
uses: ./.github/actions/freyja-depgen
- name: Cargo check workspace
uses: actions-rs/cargo@v1
with:
Expand Down Expand Up @@ -71,8 +69,6 @@ jobs:
uses: ./.github/actions/install-rust-toolchain
- name: Cache Dependencies
uses: Swatinem/rust-cache@v2
- name: Freyja depgen
uses: ./.github/actions/freyja-depgen
- name: Build
uses: actions-rs/cargo@v1
with:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/security-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ jobs:
submodules: recursive
- name: Install Rust toolchain
uses: ./.github/actions/install-rust-toolchain
- name: Freyja depgen
uses: ./.github/actions/freyja-depgen
- name: Cargo audit
uses: actions-rs/cargo@v1
with:
Expand Down
16 changes: 11 additions & 5 deletions docs/custom-adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Freyja allows users to bring their own implementations of various traits which i

## How to Author a Custom Adapter

Freyja supports custom implementations of the `DigitalTwinAdapter`, `CloudAdapter`, and `MappingClient` interfaces. To refer to these traits in your implementation, you will need to take a dependency on the `freyja-contracts` crate. It's recommended to use git as the package source as follows:
Freyja supports custom implementations of the `DigitalTwinAdapter`, `CloudAdapter`, and `MappingClient` interfaces. To refer to these traits in your implementation, you will need to take a dependency on the `freyja-contracts` crate. The following `Cargo.toml` snippet shows how you can include this dependency:

```toml
[dependencies]
Expand All @@ -13,10 +13,16 @@ freyja-contracts = { git = "https://github.com/eclipse-ibeji/freyja", rev = "<co

## How to Author a Freyja Application

To avoid the difficulty that comes with trying to statically link unknown external dependencies via Cargo, Freyja relies on users to implement the actual main executable. To do this, you will need to author a new Cargo package with a binary target (e.g., `cargo new --bin my-app`). This package should take as dependencies any crates that contain your adapter implementations or functionality needed for custom setup steps. In addition, you will need to take a dependency on one of two crates from the Freyja repository as mentioned below. These should be added as a dependency in the same way that the `freyja-contracts` crate is used above.
To avoid the difficulty that comes with trying to statically link unknown external dependencies via Cargo, Freyja relies on users to implement the actual main executable. To do this, you will need to author a new Cargo package with a binary target (e.g., `cargo new --bin my-app`). This package should take as dependencies any crates that contain your adapter implementations or functionality needed for custom setup steps. In addition, you will need to take dependencies on the `freyja` and `tokio` crates, including the `macros` feature of the `tokio` crate. The following `Cargo.toml` snippet shows how you can include these dependencies:

A template for a completed Freyja Application can be found in `examples/template`
```toml
[dependencies]
freyja = { git = "https://github.com/eclipse-ibeji/freyja", rev = "<commit hash>" }
tokio = { version = "1.0", features = ["macros"] }
```

A complete sample of the Cargo file for a Freyja application can be found in the [template crate](../examples/template/Cargo.toml).

In most cases, the `main.rs` file can be implemented using the `freyja_main!` macro which will take care of writing some boilerplate code for you. This macro only needs adapter typenames as input and will generate the main function signature and body. This macro is exposed through the `freyja-macros` crate. For an example of how to use this macro, see the code for the [in-memory example](../freyja/examples/in-memory.rs).
In most cases, the `main.rs` file can be implemented using the `freyja_main!` macro which will take care of writing some boilerplate code for you. This macro only needs adapter typenames as input and will generate the main function signature and body. For an example of how to use this macro, see the code for the [in-memory example](../freyja/examples/in-memory.rs) or the [template crate](../examples/template/src/main.rs).

If you have a more complex scenario that requires some additional setup before running the `freyja_main` function, you can instead invoke it manually without using the macro. This function is exposed through the `freyja-core` crate. For an example of how to use this function and how to manually author the main method, see the code for the [in-memory-with-fn example](../freyja/examples/in-memory-with-fn.rs).
If you have a more complex scenario that requires some additional setup before running the `freyja_main` function, you can instead invoke it manually without using the macro. For an example of how to use this function and how to manually author the main method, see the code for the [in-memory-with-fn example](../freyja/examples/in-memory-with-fn.rs).
10 changes: 6 additions & 4 deletions examples/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ edition = "2021"
license = "MIT"

[dependencies]
freyja = { git = "https://github.com/eclipse-ibeji/freyja", branch = "wilyle/test-freyja-lib" }
# These two dependencies are required for anyone implementing a Freyja application
freyja = { git = "file:///home/wilyle/repos/freyja", branch = "wilyle/test-freyja-lib" }
tokio = { version = "1.0", features = ["macros"] }

# Put any dependencies that you need for your adapters down here.
# This template utilizes the in-memory mock adapters as a sample
in-memory-mock-cloud-adapter = { git = "https://github.com/eclipse-ibeji/freyja", branch = "wilyle/test-freyja-lib" }
in-memory-mock-digital-twin-adapter = { git = "https://github.com/eclipse-ibeji/freyja", branch = "wilyle/test-freyja-lib" }
in-memory-mock-mapping-client = { git = "https://github.com/eclipse-ibeji/freyja", branch = "wilyle/test-freyja-lib" }
in-memory-mock-cloud-adapter = { git = "file:///home/wilyle/repos/freyja", branch = "wilyle/test-freyja-lib" }
in-memory-mock-digital-twin-adapter = { git = "file:///home/wilyle/repos/freyja", branch = "wilyle/test-freyja-lib" }
in-memory-mock-mapping-client = { git = "file:///home/wilyle/repos/freyja", branch = "wilyle/test-freyja-lib" }
1 change: 1 addition & 0 deletions freyja/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT

// Re-export this macro for convenience so users don't need different crates for different use cases
pub use proc_macros::freyja_main;

mod cartographer;
Expand Down
2 changes: 1 addition & 1 deletion proc_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use proc_macro::TokenStream;
///
/// `use mock_dt_adapter::DtAdapterImpl;`
#[proc_macro]
#[deprecated = "deprecated in favor of using freyja-depgen"]
#[deprecated = "deprecated in favor of writing a main function which links dependencies together with Freyja"]
pub fn use_env(ts: TokenStream) -> TokenStream {
use_env::use_env(ts.into()).into()
}
Expand Down

0 comments on commit 6360131

Please sign in to comment.