From 36c75fbc976f679ef06bce6243686c9fa719d11e Mon Sep 17 00:00:00 2001 From: August Date: Sat, 28 Nov 2026 17:39:36 -0500 Subject: [PATCH] Initial commit --- .cargo/config.toml | 19 ++++++++++ .envrc | 1 + .github/workflows/rust_ci.yml | 43 +++++++++++++++++++++++ .gitignore | 4 +++ Cargo.toml | 31 ++++++++++++++++ build.rs | 3 ++ flake.lock | 66 +++++++++++++++++++++++++++++++++++ flake.nix | 41 ++++++++++++++++++++++ rust-toolchain.toml | 3 ++ sdkconfig.defaults | 12 +++++++ src/main.rs | 10 ++++++ 11 files changed, 233 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 .envrc create mode 100644 .github/workflows/rust_ci.yml create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 build.rs create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 rust-toolchain.toml create mode 100644 sdkconfig.defaults create mode 100644 src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..94270e4 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,19 @@ +[build] +target = "riscv32imc-esp-espidf" + +[target.'cfg(target_os = "espidf")'] +linker = "ldproxy" +runner = "espflash flash --monitor" +rustflags = [ "--cfg", "espidf_time64"] + +[unstable] +build-std = ["std", "panic_abort"] + +[env] +MCU = "esp32c3" +ESP_IDF_VERSION = "v5.5.3" +ESP_IDF_TOOLS_INSTALL_DIR = "workspace" + +# Uncomment this if you have moved the target dir by setting CARGO_TARGET_DIR or similar. +# Required for now due to embuild limitations. +#CARGO_WORKSPACE_DIR = { value = "", relative = true } diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.github/workflows/rust_ci.yml b/.github/workflows/rust_ci.yml new file mode 100644 index 0000000..a017db1 --- /dev/null +++ b/.github/workflows/rust_ci.yml @@ -0,0 +1,43 @@ +name: Continuous Integration + +on: + push: + branches: + - main + paths-ignore: + - "**/README.md" + pull_request: + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + rust-checks: + name: Rust Checks + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + action: + - command: build + args: --release + - command: fmt + args: --all -- --check --color always + - command: clippy + args: --all-targets --all-features --workspace -- -D warnings + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Setup Rust + uses: dtolnay/rust-toolchain@v1 + with: + toolchain: nightly + components: rust-src rustfmt clippy + - name: Enable caching + uses: Swatinem/rust-cache@v2 + - name: Install ldproxy + run: cargo install ldproxy + - name: Run command + run: cargo ${{ matrix.action.command }} ${{ matrix.action.args }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..73a638b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/.vscode +/.embuild +/target +/Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..a8eec9f --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "esp-propane" +version = "0.1.0" +authors = ["August "] +edition = "2021" +resolver = "2" +rust-version = "1.82" + +[[bin]] +name = "esp-propane" +harness = false # do not use the built-in cargo test harness -> resolve rust-analyzer errors + +[profile.release] +opt-level = "s" + +[profile.dev] +debug = true # Symbols are nice, and they don't increase the size on Flash +opt-level = "z" +[patch.crates-io] +esp-idf-sys = { git = "https://github.com/esp-rs/esp-idf.git" } +esp-idf-hal = { git = "https://github.com/esp-rs/esp-idf.git" } +esp-idf-svc = { git = "https://github.com/esp-rs/esp-idf.git" } + +[dependencies] +log = "0.4" +esp-idf-svc = { version = "0.53", features = ["critical-section", "embassy-time-driver", "embassy-sync"] } +# Remove `generic-queue-8` if you plan to use `embassy-time` WITH `embassy-executor` +embassy-time = { version = "0.5", features = ["generic-queue-8"] } + +[build-dependencies] +embuild = "0.33.5" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..112ec3f --- /dev/null +++ b/build.rs @@ -0,0 +1,3 @@ +fn main() { + embuild::espidf::sysenv::output(); +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..043bec7 --- /dev/null +++ b/flake.lock @@ -0,0 +1,66 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1795879074, + "narHash": "sha256-QAqbRlrmBFayVaAGr+vV/1iU5aVgot96FqTsX/7NdKw=", + "owner": "nix-community", + "repo": "fenix", + "rev": "609e13405ef28bce28bde1715bed15f6585e8ef5", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1780145889, + "narHash": "sha256-md0zn0RnwNvPyASas1yG5YUuwQ4ALA6ucL50l0DvqCo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8c50a710ddca43d7a530fb805ad55bde8d0141c5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "26.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1795770336, + "narHash": "sha256-Im4O82izrAEn69fGbBe3/6q/7bGCXstELUz4PDnzqFM=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "efc6ca74690b36e0b13961537ce043db912363f9", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..16b6ad5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,41 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/26.05"; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { nixpkgs, fenix, ... }: + let + #lib = pkgs.lib; + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + toolchain = fenix.packages.${system}.fromToolchainName { + name = "nightly-2026-10-18"; + #sha256 = lib.fakeSha256; + sha256 = "/cMB/kOBm9HQsV7Kb5N3n1b/ygfsuoNIChEh/jiS3A8="; + }; + in + { + devShells.x86_64-linux.default = pkgs.mkShell { + packages = [ + (toolchain.withComponents [ + "cargo" + "clippy" + "rust-src" + "rustc" + "rustfmt"]) + pkgs.cargo-generate + pkgs.espflash + pkgs.espup + pkgs.ldproxy + (pkgs.python3.withPackages (python-pkgs: with python-pkgs; [ + pip + ])) + ]; + }; + }; +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..f70d225 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly" +components = ["rust-src"] diff --git a/sdkconfig.defaults b/sdkconfig.defaults new file mode 100644 index 0000000..ca7a8a8 --- /dev/null +++ b/sdkconfig.defaults @@ -0,0 +1,12 @@ +# Rust often needs a bit of an extra main task stack size compared to C (the default is 3K) +# You might have to increase this further if you allocate large stack variables in the main task +CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192 + +# Increase a bit these stack sizes as they are also a bit too small by default +CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=4096 +CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=4096 + +# You might have to increase this further if you spawn your own Rust threads +# that allocate large stack variables; or better yet - use +# `std::thread::Builder::new().stack_size(XXX)` for spawning +CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=4096 diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..419e7f7 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,10 @@ +fn main() { + // It is necessary to call this function once. Otherwise, some patches to the runtime + // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 + esp_idf_svc::sys::link_patches(); + + // Bind the log crate to the ESP Logging facilities + esp_idf_svc::log::EspLogger::initialize_default(); + + log::info!("Hello, world!"); +}