fix: flexible build.rs for algorithms (support both host and stm32)
This commit is contained in:
parent
727800ba2f
commit
0316298825
6 changed files with 46 additions and 18 deletions
|
@ -1,7 +1,6 @@
|
|||
[target.thumbv6m-none-eabi]
|
||||
runner = 'probe-rs run --chip STM32L053R8'
|
||||
|
||||
|
||||
[alias]
|
||||
arun = "run --target thumbv6m-none-eabi"
|
||||
atest = "test --target x86_64-unknown-linux-gnu"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Algorithms-c
|
||||
|
||||
This subproject contains all C Code for the benchmarking. It is built with
|
||||
[ceedling](https://www.throwtheswitch.org/ceedling), a more modern build tool
|
||||
This subproject contains all C Code for the benchmarking. It is built with
|
||||
[ceedling](https://www.throwtheswitch.org/ceedling), a more modern build tool
|
||||
for C projects that also integrates well with the Unity framework.
|
||||
|
||||
## Compiler
|
||||
|
@ -12,9 +12,13 @@ To compile for STM32, you need to crosscompile
|
|||
# apt install binutils-arm-none-eabi gcc-arm-none-eabi
|
||||
```
|
||||
|
||||
Then, use your tool with an `arm-none-eabi-` prefix: `arm-none-eabi-gcc`. This
|
||||
project has been configured to use `arm-none-eabi-gcc` to compile modules and to
|
||||
"link" the object files into a static library with `arm-none-eabi-ar`.
|
||||
Then, use your tool with an `arm-none-eabi-` prefix: `arm-none-eabi-gcc`. This
|
||||
project has been configured to use the compiler specified in `$CC` to compile modules and `$AR` to
|
||||
"link" the object files (this should be `ar` for a static library like this).
|
||||
|
||||
The unit tests will be compiled with `gcc` to be ran on the host computer, not
|
||||
on the STM32.
|
||||
```bash
|
||||
# compile for STM32
|
||||
CC=arm-none-eabi-gcc AR=arm-none-eabi-ar ceedling release
|
||||
# compile for this computer
|
||||
CC=gcc AR=ar ceedling release
|
||||
```
|
||||
|
|
|
@ -381,7 +381,7 @@
|
|||
# :name:
|
||||
# :optional: FALSE
|
||||
:release_compiler:
|
||||
:executable: arm-none-eabi-gcc
|
||||
:executable: "#{ENV['CC']}"
|
||||
:arguments:
|
||||
- "-g"
|
||||
- "-Wall"
|
||||
|
@ -391,7 +391,7 @@
|
|||
- "${2}"
|
||||
:optional: FALSE
|
||||
:release_linker:
|
||||
:executable: arm-none-eabi-ar
|
||||
:executable: "#{ENV['AR']}"
|
||||
:arguments:
|
||||
- "-rcs"
|
||||
- "${2}"
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use crc::{Crc, Crc32, ffi};
|
||||
use algorithms::crc::{CHECK_DATA, Crc, Crc32, ffi};
|
||||
use criterion::{Criterion, black_box, criterion_group, criterion_main};
|
||||
|
||||
pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("crc32", |b| {
|
||||
b.iter(|| Crc32::checksum(black_box(&crc::CHECK_DATA)))
|
||||
b.iter(|| Crc32::checksum(black_box(&CHECK_DATA)))
|
||||
});
|
||||
c.bench_function("ffi::crc32", |b| {
|
||||
b.iter(|| ffi::Crc32::checksum(black_box(&crc::CHECK_DATA)))
|
||||
b.iter(|| ffi::Crc32::checksum(black_box(&CHECK_DATA)))
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use crc::{Crc, Crc32, ffi};
|
||||
use algorithms::crc::{CHECK_DATA, Crc, Crc32, ffi};
|
||||
use iai::black_box;
|
||||
|
||||
fn iai_benchmark_native() -> <Crc32 as Crc>::Checksum {
|
||||
Crc32::checksum(black_box(&crc::CHECK_DATA))
|
||||
Crc32::checksum(black_box(&CHECK_DATA))
|
||||
}
|
||||
fn iai_benchmark_ffi() -> <Crc32 as Crc>::Checksum {
|
||||
ffi::Crc32::checksum(black_box(&crc::CHECK_DATA))
|
||||
ffi::Crc32::checksum(black_box(&CHECK_DATA))
|
||||
}
|
||||
|
||||
iai::main!(iai_benchmark_native, iai_benchmark_ffi);
|
||||
|
|
|
@ -1,6 +1,31 @@
|
|||
fn env(s: &str) -> String {
|
||||
std::env::var(s).unwrap()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let status = std::process::Command::new("ceedling")
|
||||
.arg("release")
|
||||
std::process::Command::new("ceedling")
|
||||
.arg("clobber")
|
||||
.current_dir("./algorithms-c/")
|
||||
.status()
|
||||
.expect("could not cleanup old algorithms-c files");
|
||||
|
||||
let mut cmd = std::process::Command::new("ceedling");
|
||||
cmd.arg("release");
|
||||
|
||||
let arch = env("CARGO_CFG_TARGET_ARCH");
|
||||
let pw = env("CARGO_CFG_TARGET_POINTER_WIDTH");
|
||||
let os = env("CARGO_CFG_TARGET_OS");
|
||||
|
||||
if arch == "arm" && pw == "32" && os == "none" {
|
||||
cmd.env("CC", "arm-none-eabi-gcc")
|
||||
.env("AR", "arm-none-eabi-ar");
|
||||
} else if os == "linux" {
|
||||
cmd.env("CC", "gcc").env("AR", "ar");
|
||||
} else {
|
||||
panic!("Unsupported build target")
|
||||
}
|
||||
|
||||
let status = cmd
|
||||
.current_dir("./algorithms-c/")
|
||||
.status()
|
||||
.expect("could not make c stuff");
|
||||
|
|
Loading…
Add table
Reference in a new issue