108 lines
3.6 KiB
Rust
108 lines
3.6 KiB
Rust
use std::env;
|
|
|
|
fn main() -> std::io::Result<()> {
|
|
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
|
|
|
|
if target_arch == "riscv32" {
|
|
linker_be_nice();
|
|
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
|
|
println!("cargo:rustc-link-arg=-Tlinkall.x");
|
|
}
|
|
|
|
// compile protobuf definition to rust code
|
|
let descriptor_path =
|
|
std::path::PathBuf::from(env::var("OUT_DIR").unwrap()).join("proto_descriptor.bin");
|
|
|
|
prost_build::Config::new()
|
|
.file_descriptor_set_path(&descriptor_path)
|
|
.compile_well_known_types()
|
|
.compile_protos(&["docs/c_its-messages.proto"], &["docs/"])?;
|
|
|
|
// get git revision
|
|
println!("cargo:rustc-rerun-if-changed=.git/HEAD");
|
|
|
|
// length:
|
|
// - tag name: 6-8 chars (v0.1.0 to v1.23.42)
|
|
// - offset+hash: 0-12 chars (up to 99 commits from tag + 8 char hash)
|
|
// - SUM: 6-20
|
|
let git_output = std::process::Command::new("git")
|
|
.args(["describe", "--tags", "--match", "v*", "--always"])
|
|
.output()
|
|
.unwrap();
|
|
assert!(
|
|
git_output.stderr.is_empty(),
|
|
"{}",
|
|
String::from_utf8(git_output.stderr).unwrap()
|
|
);
|
|
println!(
|
|
"cargo:rustc-env=GIT_REVISION={}",
|
|
String::from_utf8(git_output.stdout).unwrap()
|
|
);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn linker_be_nice() {
|
|
let args: Vec<String> = std::env::args().collect();
|
|
if args.len() > 1 {
|
|
let kind = &args[1];
|
|
let what = &args[2];
|
|
|
|
match kind.as_str() {
|
|
"undefined-symbol" => match what.as_str() {
|
|
what if what.starts_with("_defmt_") => {
|
|
eprintln!();
|
|
eprintln!(
|
|
"💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`"
|
|
);
|
|
eprintln!();
|
|
}
|
|
"_stack_start" => {
|
|
eprintln!();
|
|
eprintln!("💡 Is the linker script `linkall.x` missing?");
|
|
eprintln!();
|
|
}
|
|
what if what.starts_with("esp_rtos_") => {
|
|
eprintln!();
|
|
eprintln!(
|
|
"💡 `esp-radio` has no scheduler enabled. Make sure you have initialized `esp-rtos` or provided an external scheduler."
|
|
);
|
|
eprintln!();
|
|
}
|
|
"embedded_test_linker_file_not_added_to_rustflags" => {
|
|
eprintln!();
|
|
eprintln!(
|
|
"💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests"
|
|
);
|
|
eprintln!();
|
|
}
|
|
"free"
|
|
| "malloc"
|
|
| "calloc"
|
|
| "get_free_internal_heap_size"
|
|
| "malloc_internal"
|
|
| "realloc_internal"
|
|
| "calloc_internal"
|
|
| "free_internal" => {
|
|
eprintln!();
|
|
eprintln!(
|
|
"💡 Did you forget the `esp-alloc` dependency or didn't enable the `compat` feature on it?"
|
|
);
|
|
eprintln!();
|
|
}
|
|
_ => (),
|
|
},
|
|
// we don't have anything helpful for "missing-lib" yet
|
|
_ => {
|
|
std::process::exit(1);
|
|
}
|
|
}
|
|
|
|
std::process::exit(0);
|
|
}
|
|
|
|
println!(
|
|
"cargo:rustc-link-arg=--error-handling-script={}",
|
|
std::env::current_exe().unwrap().display()
|
|
);
|
|
}
|