initial import
Some checks failed
Continuous Integration / Rust Checks (map[args:--all -- --check --color always command:fmt]) (push) Has been cancelled
Continuous Integration / Rust Checks (map[args:--all-targets --all-features --workspace -- -D warnings command:clippy]) (push) Has been cancelled
Continuous Integration / Rust Checks (map[args:--release command:build]) (push) Has been cancelled

This commit is contained in:
Moritz Bitsch 2024-07-01 23:13:19 +02:00
commit c0ae8ab13d
No known key found for this signature in database
13 changed files with 8985 additions and 0 deletions

18
.cargo/config Normal file
View file

@ -0,0 +1,18 @@
[build]
target = "riscv32imac-esp-espidf"
[target.riscv32imac-esp-espidf]
linker = "ldproxy"
runner = "espflash flash --monitor" # Select this runner for espflash v3.x.x
rustflags = [ "--cfg", "espidf_time64"] # Extending time_t for ESP IDF 5: https://github.com/esp-rs/rust/issues/110
[unstable]
build-std = ["std", "panic_abort"]
[env]
MCU="esp32c6"
# Note: this variable is not used by the pio builder (`cargo build --features pio`)
ESP_IDF_VERSION = "v5.2.2"
# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
CRATE_CC_NO_DEFAULTS = "1"

1
.cargo/config.toml Symbolic link
View file

@ -0,0 +1 @@
config

39
.github/workflows/rust_ci.yml vendored Normal file
View file

@ -0,0 +1,39 @@
name: Continuous Integration
on:
push:
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
- name: Enable caching
uses: Swatinem/rust-cache@v2
- name: Run command
run: cargo ${{ matrix.action.command }} ${{ matrix.action.args }}

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
/.vscode
/.embuild
/target

1906
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

35
Cargo.toml Normal file
View file

@ -0,0 +1,35 @@
[package]
name = "flake-test"
version = "0.1.0"
authors = ["Moritz Bitsch"]
edition = "2021"
resolver = "2"
rust-version = "1.77"
[[bin]]
name = "flake-test"
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"
[features]
default = ["std", "embassy", "esp-idf-svc/native"]
pio = ["esp-idf-svc/pio"]
std = ["alloc", "esp-idf-svc/binstart", "esp-idf-svc/std"]
alloc = ["esp-idf-svc/alloc"]
nightly = ["esp-idf-svc/nightly"]
experimental = ["esp-idf-svc/experimental"]
embassy = ["esp-idf-svc/embassy-sync", "esp-idf-svc/critical-section", "esp-idf-svc/embassy-time-driver"]
[dependencies]
log = { version = "0.4", default-features = false }
esp-idf-svc = { version = "0.49", default-features = false }
[build-dependencies]
embuild = "0.32.0"

3
build.rs Normal file
View file

@ -0,0 +1,3 @@
fn main() {
embuild::espidf::sysenv::output();
}

194
flake.lock Normal file
View file

@ -0,0 +1,194 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1719745305,
"narHash": "sha256-xwgjVUpqSviudEkpQnioeez1Uo2wzrsMaJKJClh+Bls=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "c3c5ecc05edc7dafba779c6c1a61cd08ac6583e9",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"naersk": {
"inputs": {
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1718727675,
"narHash": "sha256-uFsCwWYI2pUpt0awahSBorDUrUfBhaAiyz+BPTS2MHk=",
"owner": "nix-community",
"repo": "naersk",
"rev": "941ce6dc38762a7cfb90b5add223d584feed299b",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "naersk",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1719468428,
"narHash": "sha256-vN5xJAZ4UGREEglh3lfbbkIj+MPEYMuqewMn4atZFaQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "1e3deb3d8a86a870d925760db1a5adecc64d329d",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs-esp-dev": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1714376097,
"narHash": "sha256-WVEt2342JBVUNjxROT8vr8Me8lgH07GeWwbb07PdQtc=",
"owner": "madmo",
"repo": "nixpkgs-esp-dev",
"rev": "970f693bfaf9b20c8aabdcf6409fc60c9f76b360",
"type": "github"
},
"original": {
"owner": "madmo",
"repo": "nixpkgs-esp-dev",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1717284937,
"narHash": "sha256-lIbdfCsf8LMFloheeE6N31+BMIeixqyQWbSr2vk79EQ=",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1719506693,
"narHash": "sha256-C8e9S7RzshSdHB7L+v9I51af1gDM5unhJ2xO1ywxNH8=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "b2852eb9365c6de48ffb0dc2c9562591f652242a",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1707205916,
"narHash": "sha256-fmRJilYGlB7VCt3XsdYxrA0u8e/K84O5xYucerUY0iM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "8cc79aa39bbc6eaedaf286ae655b224c71e02907",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixpkgs-unstable",
"type": "indirect"
}
},
"nixpkgs_4": {
"locked": {
"lastModified": 1718428119,
"narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e6cea36f83499eb4e9cd184c8a8e823296b50ad5",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"naersk": "naersk",
"nixpkgs": "nixpkgs_2",
"nixpkgs-esp-dev": "nixpkgs-esp-dev",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"nixpkgs": "nixpkgs_4"
},
"locked": {
"lastModified": 1719714047,
"narHash": "sha256-MeNPopLLv63EZj5L43j4TZkmW4wj1ouoc/h/E20sl/U=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "cb216719ce89a43dfb3d1b86a9575e89f4b727a4",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

107
flake.nix Normal file
View file

@ -0,0 +1,107 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
naersk.url = "github:nix-community/naersk";
rust-overlay = { url = "github:oxalica/rust-overlay"; };
nixpkgs-esp-dev.url = "github:madmo/nixpkgs-esp-dev";
};
outputs = inputs@{ self, nixpkgs, flake-parts, rust-overlay, naersk
, nixpkgs-esp-dev, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" ];
perSystem = { config, self', inputs', pkgs, system, ... }:
let
toolchain = (pkgs.rust-bin.selectLatestNightlyWith (toolchain:
toolchain.minimal.override {
extensions = [ "rust-src" "rustfmt" "clippy" ];
targets = [ "riscv32imac-unknown-none-elf" ];
}));
naersk' = pkgs.callPackage naersk {
cargo = toolchain;
rustc = toolchain;
};
ldproxy = pkgs.rustPlatform.buildRustPackage rec {
pname = "ldproxy";
version = "0.3.4";
src = pkgs.fetchFromGitHub {
owner = "esp-rs";
repo = "embuild";
rev = "${pname}-v${version}";
sha256 = "sha256-axqlh3wexGQ4pjphkR04k4Cr4f1ytan0y+HYJuTtYa8=";
};
buildAndTestSubdir = "ldproxy";
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ pkgs.udev ];
cargoSha256 = "sha256-GuxmLGcbjuWCAucWzjfJD85ERGhqdnUGLLCcq7bbr6g=";
meta = with pkgs.lib; {
description =
"Build support for embedded Rust: Cargo integration with other embedded build ecosystems & tools, like PlatformIO, CMake and kconfig";
homepage = "https://github.com/esp-rs/embuild";
license = with licenses; [
mit # or
asl20
];
maintainers = with maintainers; [ matthiasbeyer ];
};
};
esp-idf = (pkgs.esp-idf-esp32c6.override {
rev = "v5.1.3";
sha256 = "sha256-0QsIFOcSx1N15t5po3TyOaNvpzBUfKaFdsRODOBoXCI=";
});
git-safe-dir-hook = pkgs.callPackage ({ }:
pkgs.makeSetupHook {
name = "git-safe-dir-hook";
propagatedBuildInputs = [ pkgs.git esp-idf ];
substitutions = { shell = "${pkgs.bash}/bin/bash"; };
} (pkgs.writeScript "git-safe-dir-hook.sh" ''
export GIT_CONFIG_GLOBAL=$(realpath .gitconfig)
${pkgs.git}/bin/git config --global --add safe.directory \
'${esp-idf}'
'')) { };
in rec {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
(import rust-overlay)
(import "${nixpkgs-esp-dev}/overlay.nix")
];
config = { };
};
packages.default = naersk'.buildPackage rec {
src = ./.;
additionalCargoLock = ./rustlib-Cargo.lock;
copyBins = false;
copyTarget = true;
singleStep = true;
nativeBuildInputs = [ git-safe-dir-hook esp-idf ldproxy ];
LIBCLANG_PATH = pkgs.llvmPackages.libclang.lib + "/lib/";
};
devShells.default = pkgs.mkShell {
nativeBuildInputs =
[ toolchain esp-idf ldproxy pkgs.llvmPackages.libclang ];
shellHook = ''
export LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib/"
'';
};
};
flake = {
};
};
}

3
rust-toolchain.toml Normal file
View file

@ -0,0 +1,3 @@
[toolchain]
channel = "nightly"
components = ["rust-src"]

6656
rustlib-Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

10
sdkconfig.defaults Normal file
View file

@ -0,0 +1,10 @@
# Rust often needs a bit of an extra main task stack size compared to C (the default is 3K)
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8000
# Use this to set FreeRTOS kernel tick frequency to 1000 Hz (100 Hz by default).
# This allows to use 1 ms granuality for thread sleeps (10 ms by default).
#CONFIG_FREERTOS_HZ=1000
# Workaround for https://github.com/espressif/esp-idf/issues/7631
#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=n
#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=n

10
src/main.rs Normal file
View file

@ -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!");
}