Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First go at conditionals #3

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
Binary file added .DS_Store
Binary file not shown.
12 changes: 10 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
[build]
target = "thumbv7em-none-eabihf"
#target = "thumbv7em-none-eabihf"
[target.xtensa-esp32s3-none-elf]
runner = "espflash flash --monitor"

rustflags = [
"-C", "link-arg=-Tlinkall.x",
"-C", "link-arg=-nostartfiles",
"-C", "link-arg=-Trom_functions.x",
"-C", "target-feature=-loop",
]
65 changes: 46 additions & 19 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
use core::panic;
use std::ffi::OsStr;
use std::fs;
use std::path::PathBuf;
use std::{env, fs};

fn main() {
let target = env::var("TARGET").unwrap(); // the right way of doing it.
println!("Target we received from the system is: {}", target);
//This whole match statement and the forcing of the target shouldn't be here.
let target = match target.as_str() {
"thumbv7em-none-eabihf" => "thumbv7em-none-eabihf",
"xtensa-esp32s3-none-elf" => "xtensa-esp32s3-none-elf",
_ => "thumbv7em-none-eabihf",
};
println!("Target we are using: {}", target);
env::set_var("TARGET", target);

let xmpath = PathBuf::from("rss")
.canonicalize()
.expect("rss directory not found");

cc::Build::new()
.file("c_src/wrapper.c")
.include("c_src")
.flag("-mfloat-abi=hard")
.flag("-mfpu=fpv4-sp-d16")
.warnings_into_errors(true)
.extra_warnings(true)
.compile("log");

// Assuming 'lib' directory contains the compiled library for ARM architecture
let lib = xmpath.join("lib");
let lib = if target.eq("thumbv7em-none-eabihf") {
cc::Build::new()
.file("c_src/wrapper.c")
.include("c_src")
.flag("-mfloat-abi=hard")
.flag("-mfpu=fpv4-sp-d16")
.warnings_into_errors(true)
.extra_warnings(true)
.compile("log");
xmpath.join("lib/arm")
} else if target.eq("xtensa-esp32s3-none-elf") {
cc::Build::new().file("c_src/wrapper.c").include("c_src");
xmpath.join("lib/xtensa")
} else {
panic!("Target is not set or not supported.");
};

println!("cargo:rustc-link-search={}", lib.display());
println!("cargo:rustc-link-lib=static=acconeer_a121");
Expand All @@ -32,12 +48,23 @@ fn main() {
panic!("headers not found");
}

let mut bindings = bindgen::Builder::default()
.clang_arg("--target=arm-none-eabihf")
.clang_arg(format!("-I{}", headers.display()))
.layout_tests(false)
.generate_cstr(true)
.use_core();
let mut bindings = if target.eq("thumbv7em-none-eabihf") {
bindgen::Builder::default()
.clang_arg("--target=arm-none-eabihf")
.clang_arg(format!("-I{}", headers.display()))
.layout_tests(false)
.generate_cstr(true)
.use_core()
} else if target.eq("xtensa-esp32s3-none-elf") {
bindgen::Builder::default()
.clang_arg("--target=xtensa-esp32s3-none-elf")
.clang_arg(format!("-I{}", headers.display()))
.layout_tests(false)
.generate_cstr(true)
.use_core()
} else {
panic!("Target is not set or not supported.");
};

for entry in fs::read_dir(&headers).unwrap() {
let entry = entry.unwrap();
Expand Down
Binary file added rss/.DS_Store
Binary file not shown.
Binary file added rss/lib/.DS_Store
Binary file not shown.
File renamed without changes.
Binary file added rss/lib/xtensa/libacc_detector_distance_a121.a
Binary file not shown.
Binary file added rss/lib/xtensa/libacc_detector_presence_a121.a
Binary file not shown.
Binary file added rss/lib/xtensa/libacconeer_a121.a
Binary file not shown.
Loading