build script taken from runtime to libbuild_zynq, dependencies adjusted

This commit is contained in:
mwojcik 2021-07-26 10:28:44 +02:00
parent a06b485b67
commit e081ea926b
8 changed files with 49 additions and 50 deletions

View File

@ -6,6 +6,9 @@ authors = ["M-Labs"]
[lib] [lib]
name = "libboard_artiq" name = "libboard_artiq"
[build-dependencies]
build_zynq = { path = "../libbuild_zynq" }
[dependencies] [dependencies]
log = "0.4" log = "0.4"
log_buffer = { version = "1.2" } log_buffer = { version = "1.2" }

View File

@ -1,15 +1,5 @@
use std::env; extern crate build_zynq;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
fn main() { fn main() {
let out_dir = env::var("BUILDINC_DIRECTORY").unwrap(); build_zynq::cfg();
let cfg_path = Path::new(&out_dir).join("generated").join("rust-cfg");
println!("cargo:rerun-if-changed={}", cfg_path.to_str().unwrap());
let f = BufReader::new(File::open(&cfg_path).unwrap());
for line in f.lines() {
println!("cargo:rustc-cfg={}", line.unwrap());
}
} }

View File

@ -0,0 +1,8 @@
[package]
authors = ["M-Labs"]
name = "build_zynq"
version = "0.0.0"
[lib]
name = "build_zynq"
path = "lib.rs"

28
src/libbuild_zynq/lib.rs Normal file
View File

@ -0,0 +1,28 @@
use std::env;
use std::fs::File;
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());
// 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";
println!("cargo:rerun-if-changed={}", cfg_path);
let f = BufReader::new(File::open(cfg_path).unwrap());
for line in f.lines() {
println!("cargo:rustc-cfg={}", line.unwrap());
}
}

View File

@ -10,6 +10,9 @@ target_zc706 = ["libboard_zynq/target_zc706", "libsupport_zynq/target_zc706", "l
target_kasli_soc = ["libboard_zynq/target_kasli_soc", "libsupport_zynq/target_kasli_soc", "libconfig/target_kasli_soc"] target_kasli_soc = ["libboard_zynq/target_kasli_soc", "libsupport_zynq/target_kasli_soc", "libconfig/target_kasli_soc"]
default = ["target_zc706"] default = ["target_zc706"]
[build-dependencies]
build_zynq = { path = "../libbuild_zynq" }
[dependencies] [dependencies]
num-traits = { version = "0.2", default-features = false } num-traits = { version = "0.2", default-features = false }
num-derive = "0.3" num-derive = "0.3"

View File

@ -1,28 +1,5 @@
use std::env; extern crate build_zynq;
use std::fs::File;
use std::io::Write;
use std::io::{BufRead, BufReader};
use std::path::PathBuf;
fn main() { fn main() {
// Put the linker script somewhere the linker can find it build_zynq::cfg();
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());
// 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";
println!("cargo:rerun-if-changed={}", cfg_path);
let f = BufReader::new(File::open(cfg_path).unwrap());
for line in f.lines() {
println!("cargo:rustc-cfg={}", line.unwrap());
}
} }

View File

@ -10,7 +10,7 @@ crate-type = ["staticlib"]
path = "main.rs" path = "main.rs"
[build-dependencies] [build-dependencies]
build_misoc = { path = "../libbuild_misoc" } build_zynq = { path = "../libbuild_zynq" }
[dependencies] [dependencies]
log = { version = "0.4", default-features = false } log = { version = "0.4", default-features = false }

View File

@ -1,15 +1,5 @@
use std::env; extern crate build_zynq;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
fn main() { fn main() {
let out_dir = env::var("BUILDINC_DIRECTORY").unwrap(); build_zynq::cfg();
let cfg_path = Path::new(&out_dir).join("generated").join("rust-cfg");
println!("cargo:rerun-if-changed={}", cfg_path.to_str().unwrap());
let f = BufReader::new(File::open(&cfg_path).unwrap());
for line in f.lines() {
println!("cargo:rustc-cfg={}", line.unwrap());
}
} }