Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
39 changes: 29 additions & 10 deletions .github/workflows/size-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ jobs:
toolchain: ${{ env.RUST_TOOLCHAIN }}
components: rustfmt, clippy, rust-src

- name: Setup | Rust no-std target
- name: Setup | Rust no-std Thumbv6 target
run: rustup target add thumbv6m-none-eabi

- name: Setup | Rust no-std Thumbv7 target
run: rustup target add thumbv7em-none-eabi

- name: Setup | Rust no-std Riscv32 target
run: rustup target add riscv32imac-unknown-none-elf

- name: Install libdbus
Expand All @@ -40,26 +46,39 @@ jobs:
with:
gh-context: ${{ toJson(github) }}

- name: Examples
run: cargo build --release --no-default-features --features os,rustcrypto,log
- name: Build | Host binary for size report
run: cd bloat-check; cargo build --release

- name: Build | Thumbv6m binary for size report
run: cd bloat-check; cargo build --release --target thumbv6m-none-eabi -Zbuild-std=core,alloc,panic_abort

- name: Build | Thumbv7em binary for size report
run: cd bloat-check; cargo build --release --target thumbv7em-none-eabi -Zbuild-std=core,alloc,panic_abort

- name: Build | Riscv32imac binary for size report
run: cd bloat-check; cargo build --release --target riscv32imac-unknown-none-elf -Zbuild-std=core,alloc,panic_abort

- name: Prepare bloat report from the previous builds
run: |
python scripts/memory/gh_sizes.py \
linux rs-matter onoff-light \
target/release/onoff_light \
rs-matter-core x86_64-unknown-linux-gnu infologs-optz-ltofat \
bloat-check/target/release/bloat-check \
/tmp/bloat_reports/
python scripts/memory/gh_sizes.py \
rs-matter-core thumbv6m-none-eabi infodefmt-optz-ltofat \
bloat-check/target/thumbv6m-none-eabi/release/bloat-check \
/tmp/bloat_reports/
python scripts/memory/gh_sizes.py \
linux rs-matter dimmable_light \
target/release/dimmable_light \
rs-matter-core thumbv7em-none-eabi infodefmt-optz-ltofat \
bloat-check/target/thumbv7em-none-eabi/release/bloat-check \
/tmp/bloat_reports/
python scripts/memory/gh_sizes.py \
linux rs-matter speaker \
target/release/speaker \
rs-matter-core riscv32imac-unknown-none-elf infodefmt-optz-ltofat \
bloat-check/target/riscv32imac-unknown-none-elf/release/bloat-check \
/tmp/bloat_reports/

- name: Uploading Size Reports
uses: ./.github/actions/upload-size-reports
if: ${{ !env.ACT }}
with:
platform-name: linux
platform-name: cross-platform
10 changes: 10 additions & 0 deletions bloat-check/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[build]
#target = "thumbv7em-none-eabi"

[unstable]
#build-std-features = ["panic_immediate_abort"]
#build-std = ["core", "std", "panic_abort"]

[env]
DEFMT_LOG = "info"
RUST_LOG = "info"
69 changes: 69 additions & 0 deletions bloat-check/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[package]
name = "rs-matter-bloat-check"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"

[[bin]]
name = "bloat-check"

[workspace]

[profile.dev]
debug = true
opt-level = "z"

[profile.release]
opt-level = "z"
debug = 0
debug-assertions = false
codegen-units = 1 # LLVM can perform better optimizations using a single thread
lto = "fat"
incremental = false
overflow-checks = false

[features]
defmt = []
log = []

[dependencies]
embassy-futures = "0.1"
static_cell = "1"
critical-section = "1"
embassy-executor = { version = "0.9", features = ["executor-thread"] }
rs-matter = { path = "../rs-matter", default-features = false, features = ["rustcrypto"] }

[target.'cfg(not(target_os = "none"))'.dependencies]
log = { version = "0.4", features = ["max_level_info"] }
simple_logger = "5"
embassy-sync = { version = "0.7", features = ["log"] }
embassy-time = { version = "0.5", features = ["std", "log"] }
embassy-executor = { version = "0.9", features = ["arch-std", "log"] }
critical-section = { version = "1", features = ["std"] }
rs-matter = { path = "../rs-matter", default-features = false, features = ["log"] }

[target.'cfg(target_os = "none")'.dependencies]
defmt = "0.3"
embassy-sync = { version = "0.7", features = ["defmt"] }
embassy-time = { version = "0.5", features = ["defmt"] }
embassy-executor = { version = "0.9", features = ["defmt"] }
embedded-alloc = "0.6"
rtt-target = { version = "0.6", features = ["defmt"] }
panic-rtt-target = "0.2"
rs-matter = { path = "../rs-matter", default-features = false, features = ["defmt"] }

[target.'cfg(all(target_arch = "arm", target_os = "none"))'.dependencies]
cortex-m = { version = "0.7.6", features = ["critical-section-single-core" ] }
cortex-m-rt = "0.7"
embassy-executor = { version = "0.9", features = ["arch-cortex-m"] }

[target.thumbv7em-none-eabi.dependencies]
hal = { package = "embassy-nrf", version = "0.8", default-features = false, features = ["defmt", "time-driver-rtc1", "time", "nrf52840"] }

[target.thumbv6m-none-eabi.dependencies]
hal = { package = "embassy-rp", version = "0.8", features = ["defmt", "unstable-pac", "time-driver", "rp2040"] }

[target.riscv32imac-unknown-none-elf.dependencies]
hal = { package = "esp-hal", version = "=1.0.0-rc.1", features = ["defmt", "exception-handler", "unstable", "esp32c6"] }
esp-rtos = { version = "0.1.0", features = ["embassy", "esp32c6"] }
#embassy-executor = { version = "0.9", features = ["riscv32"] }
3 changes: 3 additions & 0 deletions bloat-check/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# rs-matter-bloat-check

This project builds an executable which serves as a reference for checking the code and data footprint of `rs-matter`.
56 changes: 56 additions & 0 deletions bloat-check/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//! This build script copies the `memory.x` file from the crate root into
//! a directory where the linker can always find it at build time.
//! For many projects this is optional, as the linker always searches the
//! project root directory -- wherever `Cargo.toml` is. However, if you
//! are using a workspace or have a more complicated build setup, this
//! build script becomes required. Additionally, by requesting that
//! Cargo re-run the build script whenever `memory.x` is changed,
//! updating `memory.x` ensures a rebuild of the application with the
//! new memory settings.

use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;

fn main() {
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();

if target_arch == "arm" {
let target = env::var("TARGET").unwrap();
cortex_m(target == "thumbv7em-none-eabi");
} else if target_arch == "riscv32" {
riscv32();
}
}

fn cortex_m(nrf: bool) {
// Put `memory.x` in our output directory and ensure it's
// on the linker search path.
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x"))
.unwrap()
.write_all(if nrf {
include_bytes!("memory-nrf52.x")
} else {
include_bytes!("memory-rp0.x")
})
.unwrap();
println!("cargo:rustc-link-search={}", out.display());

// By default, Cargo will re-run a build script whenever
// any file in the project changes. By specifying `memory.x`
// here, we ensure the build script is only re-run when
// `memory.x` is changed.
println!("cargo:rerun-if-changed=memory.x");

println!("cargo:rustc-link-arg-bins=--nmagic");
println!("cargo:rustc-link-arg-bins=-Tlink.x");
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
}

fn riscv32() {
println!("cargo:rustc-link-arg=-Tdefmt.x");
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
println!("cargo:rustc-link-arg=-Tlinkall.x");
}
5 changes: 5 additions & 0 deletions bloat-check/memory-nrf52.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MEMORY
{
FLASH : ORIGIN = 0x00000000, LENGTH = 1024K
RAM : ORIGIN = 0x20000000, LENGTH = 256K
}
17 changes: 17 additions & 0 deletions bloat-check/memory-rp0.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
MEMORY {
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100

/* Pick one of the two options for RAM layout */

/* OPTION A: Use all RAM banks as one big block */
/* Reasonable, unless you are doing something */
/* really particular with DMA or other concurrent */
/* access that would benefit from striping */
RAM : ORIGIN = 0x20000000, LENGTH = 264K

/* OPTION B: Keep the unstriped sections separate */
/* RAM: ORIGIN = 0x20000000, LENGTH = 256K */
/* SCRATCH_A: ORIGIN = 0x20040000, LENGTH = 4K */
/* SCRATCH_B: ORIGIN = 0x20041000, LENGTH = 4K */
}
Loading
Loading