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; extern crate build_zynq;
fn main() { 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::io::{BufRead, BufReader};
use std::path::PathBuf; use std::path::PathBuf;
fn cfg() { pub fn cfg(linker_script: Option<str>) {
// Put the linker script somewhere the linker can find it if let Some(script_file) = &linker_script {
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); // Put the linker script somewhere the linker can find it
File::create(out.join("link.x")) let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
.unwrap() File::create(out.join(script_file))
.write_all(include_bytes!("link.x")) .unwrap()
.unwrap(); .write_all(include_bytes!(script_file))
println!("cargo:rustc-link-search={}", out.display()); .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 // Handle rustc-cfg file
let cfg_path = "../../build/rustc-cfg"; let cfg_path = "../../build/rustc-cfg";

View File

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

View File

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