From e081ea926b5fc0eeb8a488b049a30a486289ab5e Mon Sep 17 00:00:00 2001 From: mwojcik Date: Mon, 26 Jul 2021 10:28:44 +0200 Subject: [PATCH] build script taken from runtime to libbuild_zynq, dependencies adjusted --- src/libboard_artiq/Cargo.toml | 3 +++ src/libboard_artiq/build.rs | 14 ++------------ src/libbuild_zynq/Cargo.toml | 8 ++++++++ src/libbuild_zynq/lib.rs | 28 ++++++++++++++++++++++++++++ src/runtime/Cargo.toml | 3 +++ src/runtime/build.rs | 27 ++------------------------- src/satman/Cargo.toml | 2 +- src/satman/build.rs | 14 ++------------ 8 files changed, 49 insertions(+), 50 deletions(-) create mode 100644 src/libbuild_zynq/Cargo.toml create mode 100644 src/libbuild_zynq/lib.rs diff --git a/src/libboard_artiq/Cargo.toml b/src/libboard_artiq/Cargo.toml index ac70ee15..ddc5bbde 100644 --- a/src/libboard_artiq/Cargo.toml +++ b/src/libboard_artiq/Cargo.toml @@ -6,6 +6,9 @@ authors = ["M-Labs"] [lib] name = "libboard_artiq" +[build-dependencies] +build_zynq = { path = "../libbuild_zynq" } + [dependencies] log = "0.4" log_buffer = { version = "1.2" } diff --git a/src/libboard_artiq/build.rs b/src/libboard_artiq/build.rs index a513a7bb..ba3b31b8 100644 --- a/src/libboard_artiq/build.rs +++ b/src/libboard_artiq/build.rs @@ -1,15 +1,5 @@ -use std::env; -use std::fs::File; -use std::io::{BufRead, BufReader}; -use std::path::Path; +extern crate build_zynq; fn main() { - let out_dir = env::var("BUILDINC_DIRECTORY").unwrap(); - 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()); - } + build_zynq::cfg(); } diff --git a/src/libbuild_zynq/Cargo.toml b/src/libbuild_zynq/Cargo.toml new file mode 100644 index 00000000..b5cc9e66 --- /dev/null +++ b/src/libbuild_zynq/Cargo.toml @@ -0,0 +1,8 @@ +[package] +authors = ["M-Labs"] +name = "build_zynq" +version = "0.0.0" + +[lib] +name = "build_zynq" +path = "lib.rs" diff --git a/src/libbuild_zynq/lib.rs b/src/libbuild_zynq/lib.rs new file mode 100644 index 00000000..3386cd16 --- /dev/null +++ b/src/libbuild_zynq/lib.rs @@ -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()); + } +} diff --git a/src/runtime/Cargo.toml b/src/runtime/Cargo.toml index e87897e4..1b64b9f0 100644 --- a/src/runtime/Cargo.toml +++ b/src/runtime/Cargo.toml @@ -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"] default = ["target_zc706"] +[build-dependencies] +build_zynq = { path = "../libbuild_zynq" } + [dependencies] num-traits = { version = "0.2", default-features = false } num-derive = "0.3" diff --git a/src/runtime/build.rs b/src/runtime/build.rs index e0fdb0c1..ba3b31b8 100644 --- a/src/runtime/build.rs +++ b/src/runtime/build.rs @@ -1,28 +1,5 @@ -use std::env; -use std::fs::File; -use std::io::Write; -use std::io::{BufRead, BufReader}; -use std::path::PathBuf; +extern crate build_zynq; fn main() { - // 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()); - } + build_zynq::cfg(); } diff --git a/src/satman/Cargo.toml b/src/satman/Cargo.toml index 08199d13..bb3a5ce3 100644 --- a/src/satman/Cargo.toml +++ b/src/satman/Cargo.toml @@ -10,7 +10,7 @@ crate-type = ["staticlib"] path = "main.rs" [build-dependencies] -build_misoc = { path = "../libbuild_misoc" } +build_zynq = { path = "../libbuild_zynq" } [dependencies] log = { version = "0.4", default-features = false } diff --git a/src/satman/build.rs b/src/satman/build.rs index a513a7bb..ba3b31b8 100644 --- a/src/satman/build.rs +++ b/src/satman/build.rs @@ -1,15 +1,5 @@ -use std::env; -use std::fs::File; -use std::io::{BufRead, BufReader}; -use std::path::Path; +extern crate build_zynq; fn main() { - let out_dir = env::var("BUILDINC_DIRECTORY").unwrap(); - 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()); - } + build_zynq::cfg(); }