Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Codegen in Rust with Daedalus #67

Merged
merged 9 commits into from
Nov 5, 2024
Merged

Dynamic Codegen in Rust with Daedalus #67

merged 9 commits into from
Nov 5, 2024

Conversation

harrison-e
Copy link
Contributor

Changes

Daedalus:

  • Replaces the Python format string codegen from Embedded-Base/cangen with Rust proc macros
  • Generates decode functions, decode master mapping, encode functions, encode master mapping, encoder key list, and simulate function body, based off of CAN spec in Embedded-Base/cangen/can-messages, with a single macro call in src/decode_data.rs, src/encode_data.rs, and src/simulate_data.rs respectively.

Cangen:

  • Replaces the Python datatypes from Embedded-Base/cangen with equivalent Rust structs
  • Contains helper traits for Daedalus

Calypso:

  • decode_data.rs, encode_data.rs, and simulate_data.rs are now generated with Daedalus macros. Since they're only 5 lines (pre-expansion), I've begun tracking them.
  • Master mappings are now phf hash maps, instead of a struct wrapping a giant match function.
  • FormatData struct is no longer dynamically generated in format_data.rs. Instead, is now hardcoded in data.rs, and format_data.rs is removed. I hardcoded this since I assume that it will change very rarely. In the event that a new format is added, though, it will need to be added to data.rs.
  • Changed main.rs to work with Daedalus-generated code.
  • Added new dependencies to Cargo.toml and Cargo.lock.
  • Removed calypsogen.py and its call in build.rs.
  • Removed deprecated exports from lib.rs.
  • Removed deprecated files from .gitignore.

Test Cases

  • Tested with mosquitto, mqttui, and cansend, working as expected
  • Tested with cargo run --bin simulate, working as expected

To Do

Any remaining things that need to get done

  • switch to new CAN typing (acquiesce NetField and CANPoint)

Checklist

It can be helpful to check the Checks and Files changed tabs.
Please reach out to your Project Lead if anything is unclear.
Please request reviewers and ping on slack only after you've gone through this whole checklist.

  • No merge conflicts
  • All checks passing
  • Remove any non-applicable sections of this template
  • Assign the PR to yourself
  • Request reviewers & ping on Slack
  • PR is linked to the ticket (fill in the closes line below)

Closes #53

…code, and simulate functions and mappings at compile time
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
@harrison-e harrison-e added the epic A Feature Requiring Many Tasks to Complete label Nov 1, 2024
@harrison-e harrison-e requested a review from jr1221 November 1, 2024 00:00
@harrison-e harrison-e self-assigned this Nov 1, 2024
Copy link
Contributor

@jr1221 jr1221 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will approve once tested Sunday. Really really cool. I do see room for improvement by deviating from how the python used to look and getting dynamicly into the bitreader logic a little more, but that is a task for a future PR.

.gitignore Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
libs/cangen/Cargo.toml Outdated Show resolved Hide resolved
libs/cangen/src/can_types.rs Outdated Show resolved Hide resolved
libs/daedalus/Cargo.toml Outdated Show resolved Hide resolved
libs/cangen/src/can_gen_decode.rs Outdated Show resolved Hide resolved
libs/cangen/src/can_gen_decode.rs Outdated Show resolved Hide resolved
libs/cangen/src/can_gen_encode.rs Outdated Show resolved Hide resolved
src/encode_data.rs Outdated Show resolved Hide resolved
src/simulatable_message.rs Outdated Show resolved Hide resolved
@jr1221
Copy link
Contributor

jr1221 commented Nov 3, 2024

Running cargo clippy locally can show u anything the CI linter will fail on.

@harrison-e harrison-e removed the epic A Feature Requiring Many Tasks to Complete label Nov 3, 2024
@jr1221 jr1221 merged commit 74d3aa1 into Develop Nov 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hard and takes a while: Switch to proc macros
2 participants