build.rs 969 B

12345678910111213141516171819202122232425262728
  1. // NOTE: Adapted from cortex-m/build.rs
  2. extern crate riscv_target;
  3. use riscv_target::Target;
  4. use std::env;
  5. use std::fs;
  6. use std::path::PathBuf;
  7. fn main() {
  8. let target = env::var("TARGET").unwrap();
  9. let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
  10. let name = env::var("CARGO_PKG_NAME").unwrap();
  11. if target.starts_with("riscv") {
  12. let mut target = Target::from_target_str(&target);
  13. target.retain_extensions("imfdc");
  14. let archive = format!("bin/{}.a", target.to_string());
  15. fs::copy(&archive, out_dir.join(format!("lib{}.a", name))).unwrap();
  16. println!("cargo:rerun-if-changed={}", archive);
  17. println!("cargo:rustc-link-lib=static={}", name);
  18. }
  19. // Put the linker script somewhere the linker can find it
  20. fs::write(out_dir.join("link.x"), include_bytes!("link.x")).unwrap();
  21. println!("cargo:rustc-link-search={}", out_dir.display());
  22. println!("cargo:rerun-if-changed=link.x");
  23. }