build.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // NOTE: Adapted from cortex-m/build.rs
  2. use riscv_target::Target;
  3. use std::env;
  4. use std::fs;
  5. use std::path::PathBuf;
  6. fn main() {
  7. let target = env::var("TARGET").unwrap();
  8. let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
  9. let _name = env::var("CARGO_PKG_NAME").unwrap();
  10. // set configuration flags depending on the target
  11. if target.starts_with("riscv") {
  12. println!("cargo:rustc-cfg=riscv");
  13. let target = Target::from_target_str(&target);
  14. match target.bits {
  15. 32 => {
  16. println!("cargo:rustc-cfg=riscv32");
  17. }
  18. 64 => {
  19. println!("cargo:rustc-cfg=riscv64");
  20. }
  21. _ => panic!("Unsupported bit width"),
  22. }
  23. if target.has_extension('m') {
  24. println!("cargo:rustc-cfg=riscvm"); // we can expose extensions this way
  25. }
  26. }
  27. // Put the linker script somewhere the linker can find it
  28. fs::write(out_dir.join("link.x"), include_bytes!("link.x")).unwrap();
  29. println!("cargo:rustc-link-search={}", out_dir.display());
  30. println!("cargo:rerun-if-changed=link.x");
  31. }