experimental: build script with linker file arg

This commit is contained in:
mwojcik 2021-07-26 13:57:37 +02:00
parent 8b780ec83b
commit 2c3091e792
4 changed files with 17 additions and 14 deletions

View File

@ -1,5 +1,5 @@
extern crate build_zynq;
fn main() {
build_zynq::cfg();
build_zynq::cfg(None);
}

View File

@ -4,18 +4,21 @@ use std::io::Write;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
fn cfg() {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("link.x"))
.unwrap()
.write_all(include_bytes!("link.x"))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());
pub fn cfg(linker_script: Option<str>) {
if let Some(script_file) = &linker_script {
// Put the linker script somewhere the linker can find it
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join(script_file))
.unwrap()
.write_all(include_bytes!(script_file))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());
// Only re-run the build script when link.x is changed,
// instead of when any part of the source code changes.
println!("cargo:rerun-if-changed={}". script_file);
}
// Only re-run the build script when link.x is changed,
// instead of when any part of the source code changes.
println!("cargo:rerun-if-changed=link.x");
// Handle rustc-cfg file
let cfg_path = "../../build/rustc-cfg";

View File

@ -1,5 +1,5 @@
extern crate build_zynq;
fn main() {
build_zynq::cfg();
build_zynq::cfg(Some("link.x"));
}

View File

@ -1,5 +1,5 @@
extern crate build_zynq;
fn main() {
build_zynq::cfg();
build_zynq::cfg(Some("satman.ld"));
}