Skip to content

Commit

Permalink
Dynamic Codegen in Rust with Daedalus (#67)
Browse files Browse the repository at this point in the history
* Added libs/cangen, to move the CAN types and some of the CAN codegen logic into Calypso from Embedded-Base

* Added libs/daedalus, which exports proc macros to generate decode, encode, and simulate functions and mappings at compile time

* Changed main to work with new code generated by daedalus macros

format_data.rs is no longer generated, FormatData struct now hardcoded into data.rs

Removed deprecated exports from lib.rs

Removed calypsogen.py and its call in build.rs

Changed Cargo.toml/.lock to include new dependencies (phf, cangen, daedalus)

Removed deprecated files from .gitignore

Now tracking decode_/encode_/simulate_data.rs, as they contain macro calls

* Fixed bugs, now building and working

* Implemented PR changes, refactored calypso-cangen traits for readability

* Fixed for clippy

* Allow clippy

* Begrudging clippy compliance

* Bug fix for reading small little endian values
  • Loading branch information
harrison-e authored Nov 5, 2024
1 parent ea52c5f commit 74d3aa1
Show file tree
Hide file tree
Showing 20 changed files with 1,047 additions and 220 deletions.
13 changes: 2 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,5 @@ mod.rs
command_data.rs
serverdata.rs

# cangen files generaed by calypsogen.py
decode_master_mapping.rs
decode_data.rs
encode_data.rs
encode_master_mapping.rs
format_data.rs
simulate_data.rs

# my dumb script
./format
/privatetest/
# private testing
/privatetest/
124 changes: 109 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ default-run = "calypso"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace]
members = ["libs/daedalus", "libs/calypso-cangen"]

[workspace.dependencies]
proc-macro2 = "1.0.89"
quote = "1.0.37"
serde = { version = "1.0.214", features = ["derive"] }
serde_json = "1.0.132"


[dependencies]
socketcan = "3.3.0"
paho-mqtt = "0.12.5"
Expand All @@ -15,6 +25,9 @@ protobuf = "3.5.1"
bitstream-io = "2.5.3"
clap = { version = "4.5.20", features = ["derive", "env"] }
rand = "0.8"
phf = { version = "0.11.2", features = ["macros"] }
calypso-cangen = { path = "./libs/calypso-cangen" }
daedalus = { path = "./libs/daedalus" }


[build-dependencies]
Expand Down
16 changes: 0 additions & 16 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
use std::process::Command;

/* Prebuild script */
fn main() {
println!("cargo:rerun-if-changed=Embedded-Base");

match Command::new("python3").arg("./calypsogen.py").status() {
Ok(status) if status.success() => {
println!("Python script executed successfully");
}
Ok(status) => {
eprintln!("Python script exited with status: {}", status);
std::process::exit(1);
}
Err(e) => {
eprintln!("Failed to execute Python script: {}", e);
std::process::exit(1);
}
}

protobuf_codegen::Codegen::new()
.pure()
// All inputs and imports from the inputs must reside in `includes` directories.
Expand Down
66 changes: 0 additions & 66 deletions calypsogen.py

This file was deleted.

9 changes: 9 additions & 0 deletions libs/calypso-cangen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "calypso-cangen"
version = "0.1.0"
edition = "2021"

[dependencies]
proc-macro2.workspace = true
quote.workspace = true
serde = { workspace = true, features = ["derive"] }
Loading

0 comments on commit 74d3aa1

Please sign in to comment.