build.rs (2653B)
1 fn main() { 2 linker_be_nice(); 3 println!("cargo:rustc-link-arg-tests=-Tembedded-test.x"); 4 println!("cargo:rustc-link-arg=-Tdefmt.x"); 5 // make sure linkall.x is the last linker script (otherwise might cause problems with flip-link) 6 println!("cargo:rustc-link-arg=-Tlinkall.x"); 7 } 8 9 fn linker_be_nice() { 10 let args: Vec<String> = std::env::args().collect(); 11 if args.len() > 1 { 12 let kind = &args[1]; 13 let what = &args[2]; 14 15 match kind.as_str() { 16 "undefined-symbol" => match what.as_str() { 17 what if what.starts_with("_defmt_") => { 18 eprintln!(); 19 eprintln!( 20 "💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`" 21 ); 22 eprintln!(); 23 } 24 "_stack_start" => { 25 eprintln!(); 26 eprintln!("💡 Is the linker script `linkall.x` missing?"); 27 eprintln!(); 28 } 29 what if what.starts_with("esp_rtos_") => { 30 eprintln!(); 31 eprintln!( 32 "💡 `esp-radio` has no scheduler enabled. Make sure you have initialized `esp-rtos` or provided an external scheduler." 33 ); 34 eprintln!(); 35 } 36 "embedded_test_linker_file_not_added_to_rustflags" => { 37 eprintln!(); 38 eprintln!( 39 "💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests" 40 ); 41 eprintln!(); 42 } 43 "free" 44 | "malloc" 45 | "calloc" 46 | "get_free_internal_heap_size" 47 | "malloc_internal" 48 | "realloc_internal" 49 | "calloc_internal" 50 | "free_internal" => { 51 eprintln!(); 52 eprintln!( 53 "💡 Did you forget the `esp-alloc` dependency or didn't enable the `compat` feature on it?" 54 ); 55 eprintln!(); 56 } 57 _ => (), 58 }, 59 // we don't have anything helpful for "missing-lib" yet 60 _ => { 61 std::process::exit(1); 62 } 63 } 64 65 std::process::exit(0); 66 } 67 68 println!( 69 "cargo:rustc-link-arg=--error-handling-script={}", 70 std::env::current_exe().unwrap().display() 71 ); 72 }