mciantyre / teensy4-rs

Rust support for the Teensy 4
Apache License 2.0
271 stars 31 forks source link

Use environment to override stack/heap sizes #155

Closed therealbstern closed 5 months ago

therealbstern commented 6 months ago

This allows setting an environment variable at build time to change the stack and/or heap sizes without having to fork teensy4-rs and/or patching build.rs. The variables in question are TEENSY4_HEAP_SIZE and TEENSY4_STACK_SIZE and they default to the current values in build.rs if they're not present or won't parse::<usize>().

It is recommended to set the variables in the [env] section of Cargo.toml but not required.

Note that changing the environment variables doesn't trigger a rebuild without a cargo clean. I'm open to suggestions on how to make rebuilds happen.

therealbstern commented 6 months ago

@mciantyre I'm going to make the changes suggested above; I'll ping you when this is complete.

Unless you have no interest in this PR, in which case you can close it.

therealbstern commented 6 months ago

@mciantyre I think this is ready for you if you are interested in it.

mciantyre commented 6 months ago

I'm interested in the feature, and I'd prefer to maintain it outside of the BSP if possible. I think the main change here could look something like

diff --git a/build.rs b/build.rs
index 201ff96..861d6be 100644
--- a/build.rs
+++ b/build.rs
@@ -10,8 +10,10 @@ fn main() {
         })
         .heap(Memory::Ocram)
         .heap_size(16 * 1024)
+        .heap_size_env_override("TEENSY4_HEAP_SIZE")
         .stack(Memory::Dtcm)
         .stack_size(16 * 1024)
+        .stack_size_env_override("TEENSY4_STACK_SIZE")
         .vectors(Memory::Dtcm)
         .text(Memory::Itcm)
         .data(Memory::Dtcm)

with the behavior described in the PR summary. We move this support into the runtime. imxrt-rs/imxrt-rt#13 proposes the feature.


Note that changing the environment variables doesn't trigger a rebuild without a cargo clean.

Take a look at cargo:rerun-if-env-changed in the build scripts documentation.

therealbstern commented 6 months ago

We move this support into the runtime. imxrt-rs/imxrt-rt#13 proposes the feature.

Great, I'm perfectly happy with you putting it wherever makes the most sense to you.

Take a look at cargo:rerun-if-env-changed in the build scripts documentation.

Thank you, that's ideal.

If you want to close this because it's superseded, that's fine with me.