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

Got Rust autogeneration working with Rust prebuild hook! #33

Merged
merged 9 commits into from
Mar 1, 2024
Merged
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
8 changes: 7 additions & 1 deletion .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ jobs:

steps:
- name: Setup Rust
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Python and Pip
run: sudo apt-get install python3 python3-pip
- name: Install ruamel.yaml
run: pip install "ruamel.yaml<0.18.0"
- name: Install cargo-audit
run: cargo install cargo-audit
- name: Build
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ __pycache__/
build/
dist/
logs/
master_mapping.rs
decode_data.rs
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Embedded-Base"]
path = Embedded-Base
url = [email protected]:Northeastern-Electric-Racing/Embedded-Base.git
1 change: 1 addition & 0 deletions Embedded-Base
Submodule Embedded-Base added at 0c828d
20 changes: 20 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::process::Command;

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

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);
},
}
}
35 changes: 35 additions & 0 deletions calypsogen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import importlib.util
import sys

# Full path to the directory containing the cangen module
EMBEDDED_BASE_PATH = "./Embedded-Base"
module_name = "cangen"

# Full path to the cangen module file
module_path = f"{EMBEDDED_BASE_PATH}/{module_name}/__init__.py"

# Add the cangen directory to the system's path
sys.path.append(EMBEDDED_BASE_PATH)

# Load the module
spec = importlib.util.spec_from_file_location(module_name, module_path)
cangen = importlib.util.module_from_spec(spec)
spec.loader.exec_module(cangen)

decode_data = open("./src/decode_data.rs", "w")
master_mapping = open("./src/master_mapping.rs", "w")

bms_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/bms.yaml", "r"))
mpu_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/mpu.yaml", "r"))
wheel_messages = cangen.YAMLParser().parse(open(f"{EMBEDDED_BASE_PATH}/{module_name}/can-messages/wheel.yaml", "r"))

bms_messages.msgs.extend(mpu_messages.msgs)
bms_messages.msgs.extend(wheel_messages.msgs)

result = cangen.RustSynth().parse_messages(bms_messages.msgs)

decode_data.write(result.decode_data)
decode_data.close()

master_mapping.write(result.master_mapping)
master_mapping.close()
158 changes: 0 additions & 158 deletions oxy/RustSynth.py

This file was deleted.

26 changes: 0 additions & 26 deletions oxy/YAMLParser.py

This file was deleted.

Loading
Loading