diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..abcf183 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,27 @@ +# editor things +.idea/ +.zed/ +.vscode/ + +# misc things +.DS_Store +.gitignore +*.nix + +# python things +pyrightconfig.json +__pycache__/ + +# Added by cargo (rust things) +/target +build/ +dist/ +logs/ + +# protobuf +mod.rs +command_data.rs +serverdata.rs + +# private testing +/privatetest/ diff --git a/.github/workflows/calypso-build.yml b/.github/workflows/calypso-build.yml index 62d53d7..02aea65 100644 --- a/.github/workflows/calypso-build.yml +++ b/.github/workflows/calypso-build.yml @@ -4,7 +4,7 @@ name: Create and publish Calypso docker image on: push: branches: ['Develop'] - path: + paths: - "Dockerfile" workflow_dispatch: diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml index 1ed8c62..76c6d4e 100644 --- a/.github/workflows/rust-ci.yml +++ b/.github/workflows/rust-ci.yml @@ -22,11 +22,11 @@ jobs: - name: Install cargo-audit run: cargo install cargo-audit - name: Build - run: cargo build --verbose + run: cargo build --all --verbose - name: Test run: cargo test --verbose - name: Fmt - run: cargo fmt --check + run: cargo fmt --all --check - name: Clippy run: cargo clippy --verbose --all -- -D warnings - name: Audit diff --git a/Cargo.lock b/Cargo.lock index 7a5d690..85a9123 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,7 +125,6 @@ dependencies = [ "phf", "protobuf", "protobuf-codegen", - "rand", "socketcan", ] @@ -140,13 +139,26 @@ dependencies = [ "thiserror 2.0.9", ] +[[package]] +name = "calypso-simulate" +version = "0.1.0" +dependencies = [ + "calypso", + "calypso-cangen", + "clap", + "daedalus", + "protobuf", + "protobuf-codegen", + "rand", +] + [[package]] name = "cc" -version = "1.0.83" +version = "1.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "8d6dbb628b8f8555f86d0323c2eb39e3ec81901f4b83e091db8a6a76d316a333" dependencies = [ - "libc", + "shlex", ] [[package]] @@ -197,9 +209,9 @@ checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "cmake" -version = "0.1.50" +version = "0.1.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" +checksum = "c682c223677e0e5b6b7f63a64b9351844c3f1b1678a68b7ee617e30fb082620e" dependencies = [ "cc", ] @@ -212,31 +224,27 @@ checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "concurrent-queue" -version = "2.3.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-channel" -version = "0.5.8" +version = "0.5.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +checksum = "06ba6d68e24814cb8de6bb986db8222d3a027d15872cabc0d18817bc3c0e4471" dependencies = [ - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if", -] +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "daedalus" @@ -293,9 +301,9 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "futures" -version = "0.3.29" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" dependencies = [ "futures-channel", "futures-core", @@ -308,9 +316,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.29" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -318,15 +326,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.29" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" -version = "0.3.29" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" dependencies = [ "futures-core", "futures-task", @@ -335,15 +343,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.29" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-macro" -version = "0.3.29" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", @@ -352,27 +360,27 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.29" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.29" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-timer" -version = "3.0.2" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" +checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" [[package]] name = "futures-util" -version = "0.3.29" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -540,9 +548,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "openssl-sys" -version = "0.9.96" +version = "0.9.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3812c071ba60da8b5677cc12bcb1d42989a65553772897a7e0355545a819838f" +checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" dependencies = [ "cc", "libc", @@ -620,9 +628,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.13" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" [[package]] name = "pin-utils" @@ -632,9 +640,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.27" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "ppv-lite86" @@ -833,6 +841,12 @@ dependencies = [ "serde", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "siphasher" version = "0.3.11" diff --git a/Cargo.toml b/Cargo.toml index 1c626d0..62a06b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,40 +1,19 @@ -[package] -name = "calypso" -version = "0.1.0" -edition = "2021" -rust-version = "1.79" -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"] +members = ["daedalus", "calypso-cangen", "calypso-simulate", "calypso"] +default-members = ["calypso"] +resolver = "2" [workspace.dependencies] proc-macro2 = "1.0.92" quote = "1.0.37" serde = { version = "1.0.216", features = ["derive"] } serde_json = "1.0.134" - - -[dependencies] -socketcan = "3.3.1" paho-mqtt = "0.12.5" -protobuf-codegen = "3.5.1" -protobuf = "3.5.1" -bitstream-io = "2.6.0" clap = { version = "4.5.23", 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] protobuf-codegen = "3.5.1" -calypso-cangen = { path = "./libs/calypso-cangen" } +protobuf = "3.5.1" [profile.release] lto = true codegen-units = 1 -panic = "abort" +panic = "abort" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 06a2dfb..beacd1e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,15 +5,15 @@ COPY . . RUN git submodule update --init RUN apt-get update && apt-get install -y libssl-dev build-essential cmake -RUN cargo install --path . +RUN cargo build --all --release FROM debian:bookworm-slim -RUN apt update -RUN apt install openssl -y +RUN apt-get update +RUN apt-get install openssl -y -COPY --from=builder /usr/local/cargo/bin/calypso /usr/local/bin/calypso -COPY --from=builder /usr/local/cargo/bin/simulate /usr/local/bin/simulate +COPY --from=builder /usr/src/calypso/target/release/calypso /usr/local/bin/calypso +COPY --from=builder /usr/src/calypso/target/release/calypso-simulate /usr/local/bin/calypso-simulate -CMD ["simulate"] +CMD ["calypso-simulate"] # START WITH: sudo docker run -d --rm --network host calypso \ No newline at end of file diff --git a/README.md b/README.md index 5a394e7..f65e4d2 100644 --- a/README.md +++ b/README.md @@ -41,29 +41,11 @@ Now view calypso interpret the can message and broadcast it on `mqttui` ### Simulation Mode #### Run from build -- Same setup as above, then use the entry point `simulate` instead of `main` -- ```cargo run --bin simulate``` -- ```cargo run --bin simulate -- -u localhost:1883``` +- Same setup as above, then use the package `calypso-simulate` instead of the default `calypso`. +- ```cargo run -p calypso-simulate``` +- ```cargo run -p calypso-simulate -- -u localhost:1883``` #### Run from Docker - ```docker pull ghcr.io/northeastern-electric-racing/calypso:Develop``` - ```docker run -d --rm --network host ghcr.io/northeastern-electric-racing/calypso:Develop``` -- ```docker run -d --rm -e CALYPSO_SIREN_HOST_URL=127.0.0.1:1883 --network host ghcr.io/northeastern-electric-racing/calypso:Develop``` - - - -### Generate Proto - -#### linux -`apt-get install protobuf-compiler -y` - -#### mac -`brew install protobuf` - -`cargo install protobuf-codegen` - -`PATH="$HOME/.cargo/bin:$PATH"` - -`protoc --rust_out ./src ./src/proto/serverdata.proto` - -delete the `mod.rs` file \ No newline at end of file +- ```docker run -d --rm -e CALYPSO_SIREN_HOST_URL=127.0.0.1:1883 --network host ghcr.io/northeastern-electric-racing/calypso:Develop``` \ No newline at end of file diff --git a/libs/calypso-cangen/Cargo.toml b/calypso-cangen/Cargo.toml similarity index 100% rename from libs/calypso-cangen/Cargo.toml rename to calypso-cangen/Cargo.toml diff --git a/libs/calypso-cangen/src/can_gen_decode.rs b/calypso-cangen/src/can_gen_decode.rs similarity index 100% rename from libs/calypso-cangen/src/can_gen_decode.rs rename to calypso-cangen/src/can_gen_decode.rs diff --git a/libs/calypso-cangen/src/can_gen_encode.rs b/calypso-cangen/src/can_gen_encode.rs similarity index 100% rename from libs/calypso-cangen/src/can_gen_encode.rs rename to calypso-cangen/src/can_gen_encode.rs diff --git a/libs/calypso-cangen/src/can_types.rs b/calypso-cangen/src/can_types.rs similarity index 100% rename from libs/calypso-cangen/src/can_types.rs rename to calypso-cangen/src/can_types.rs diff --git a/libs/calypso-cangen/src/lib.rs b/calypso-cangen/src/lib.rs similarity index 65% rename from libs/calypso-cangen/src/lib.rs rename to calypso-cangen/src/lib.rs index 7cbf95b..ff2e873 100644 --- a/libs/calypso-cangen/src/lib.rs +++ b/calypso-cangen/src/lib.rs @@ -7,4 +7,4 @@ pub mod validate; * Used by all daedalus macros * Filepath is relative to project root (i.e. /Calypso) */ -pub const CANGEN_SPEC_PATH: &str = "./Embedded-Base/cangen/can-messages"; +pub const CANGEN_SPEC_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../Embedded-Base/cangen/can-messages"); diff --git a/libs/calypso-cangen/src/validate.rs b/calypso-cangen/src/validate.rs similarity index 100% rename from libs/calypso-cangen/src/validate.rs rename to calypso-cangen/src/validate.rs diff --git a/calypso-simulate/Cargo.toml b/calypso-simulate/Cargo.toml new file mode 100644 index 0000000..dadb371 --- /dev/null +++ b/calypso-simulate/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "calypso-simulate" +version = "0.1.0" +edition = "2021" + +[dependencies] +clap.workspace = true +rand = "0.8" +calypso = { path = "../calypso" } +daedalus = { path = "../daedalus" } +protobuf.workspace = true + +[build-dependencies] +protobuf-codegen.workspace = true +calypso-cangen = { path = "../calypso-cangen" } \ No newline at end of file diff --git a/calypso-simulate/src/lib.rs b/calypso-simulate/src/lib.rs new file mode 100644 index 0000000..81d6000 --- /dev/null +++ b/calypso-simulate/src/lib.rs @@ -0,0 +1,2 @@ +pub mod simulatable_message; +pub mod simulate_data; diff --git a/src/bin/simulate.rs b/calypso-simulate/src/main.rs similarity index 92% rename from src/bin/simulate.rs rename to calypso-simulate/src/main.rs index 2a4c716..9e03170 100644 --- a/src/bin/simulate.rs +++ b/calypso-simulate/src/main.rs @@ -3,10 +3,9 @@ use std::{ time::{Duration, UNIX_EPOCH}, }; -use calypso::{ - mqtt::MqttClient, serverdata, simulatable_message::SimShared, - simulate_data::create_simulated_components, -}; +use calypso::{mqtt::MqttClient, proto::serverdata}; +use calypso_simulate::simulatable_message::SimShared; +use calypso_simulate::simulate_data::create_simulated_components; use clap::Parser; /// Calypso command line arguments diff --git a/src/simulatable_message.rs b/calypso-simulate/src/simulatable_message.rs similarity index 99% rename from src/simulatable_message.rs rename to calypso-simulate/src/simulatable_message.rs index 794362e..22b3661 100644 --- a/src/simulatable_message.rs +++ b/calypso-simulate/src/simulatable_message.rs @@ -1,4 +1,4 @@ -use super::data::DecodeData; +use calypso::data::DecodeData; use rand::prelude::*; use std::time::Instant; diff --git a/src/simulate_data.rs b/calypso-simulate/src/simulate_data.rs similarity index 100% rename from src/simulate_data.rs rename to calypso-simulate/src/simulate_data.rs diff --git a/calypso/Cargo.toml b/calypso/Cargo.toml new file mode 100644 index 0000000..227de0a --- /dev/null +++ b/calypso/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "calypso" +version = "0.1.0" +edition = "2021" +rust-version = "1.79" +default-run = "calypso" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +socketcan = "3.3.1" +paho-mqtt.workspace = true +protobuf-codegen.workspace = true +protobuf.workspace = true +bitstream-io = "2.6.0" +clap.workspace = true +phf = { version = "0.11.2", features = ["macros"] } +calypso-cangen = { path = "../calypso-cangen" } +daedalus = { path = "../daedalus" } + + +[build-dependencies] +protobuf-codegen = "3.5.1" +calypso-cangen = { path = "../calypso-cangen" } \ No newline at end of file diff --git a/build.rs b/calypso/build.rs similarity index 74% rename from build.rs rename to calypso/build.rs index 68b482c..8650b9f 100644 --- a/build.rs +++ b/calypso/build.rs @@ -3,17 +3,17 @@ use std::process; /* Prebuild script */ fn main() { - println!("cargo:rerun-if-changed=Embedded-Base"); + println!("cargo:rerun-if-changed=src/proto"); protobuf_codegen::Codegen::new() .pure() // All inputs and imports from the inputs must reside in `includes` directories. - .includes(["src/proto"]) + .includes(["../calypso/src/proto"]) // Inputs must reside in some of include paths. - .input("src/proto/command_data.proto") - .input("src/proto/serverdata.proto") + .input("../calypso/src/proto/command_data.proto") + .input("../calypso/src/proto/serverdata.proto") // Specify output directory relative to Cargo output directory. - .out_dir("src") + .out_dir("../calypso/src/proto") .run_from_script(); // Validate CAN spec diff --git a/src/data.rs b/calypso/src/data.rs similarity index 100% rename from src/data.rs rename to calypso/src/data.rs diff --git a/src/decode_data.rs b/calypso/src/decode_data.rs similarity index 100% rename from src/decode_data.rs rename to calypso/src/decode_data.rs diff --git a/src/encode_data.rs b/calypso/src/encode_data.rs similarity index 100% rename from src/encode_data.rs rename to calypso/src/encode_data.rs diff --git a/calypso/src/lib.rs b/calypso/src/lib.rs new file mode 100644 index 0000000..695734d --- /dev/null +++ b/calypso/src/lib.rs @@ -0,0 +1,5 @@ +pub mod data; +pub mod decode_data; +pub mod encode_data; +pub mod mqtt; +pub mod proto; diff --git a/src/main.rs b/calypso/src/main.rs similarity index 98% rename from src/main.rs rename to calypso/src/main.rs index 21ef2ee..fb60b94 100644 --- a/src/main.rs +++ b/calypso/src/main.rs @@ -6,8 +6,11 @@ use std::{ }; use calypso::{ - command_data, data::DecodeData, data::EncodeData, decode_data::*, encode_data::*, - mqtt::MqttClient, serverdata, + data::{DecodeData, EncodeData}, + decode_data::*, + encode_data::*, + mqtt::MqttClient, + proto::{command_data, serverdata}, }; use clap::Parser; use protobuf::Message; diff --git a/src/mqtt.rs b/calypso/src/mqtt.rs similarity index 100% rename from src/mqtt.rs rename to calypso/src/mqtt.rs diff --git a/src/proto/command_data.proto b/calypso/src/proto/command_data.proto similarity index 100% rename from src/proto/command_data.proto rename to calypso/src/proto/command_data.proto diff --git a/src/proto/serverdata.proto b/calypso/src/proto/serverdata.proto similarity index 100% rename from src/proto/serverdata.proto rename to calypso/src/proto/serverdata.proto diff --git a/libs/daedalus/Cargo.toml b/daedalus/Cargo.toml similarity index 100% rename from libs/daedalus/Cargo.toml rename to daedalus/Cargo.toml diff --git a/libs/daedalus/src/lib.rs b/daedalus/src/lib.rs similarity index 100% rename from libs/daedalus/src/lib.rs rename to daedalus/src/lib.rs diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 76ef74e..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,8 +0,0 @@ -pub mod command_data; -pub mod data; -pub mod decode_data; -pub mod encode_data; -pub mod mqtt; -pub mod serverdata; -pub mod simulatable_message; -pub mod simulate_data;