diff --git a/artiq/firmware/Cargo.lock b/artiq/firmware/Cargo.lock index 71e478a2b..af2449dc6 100644 --- a/artiq/firmware/Cargo.lock +++ b/artiq/firmware/Cargo.lock @@ -17,6 +17,13 @@ dependencies = [ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "build_artiq" +version = "0.0.0" +dependencies = [ + "walkdir 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "byteorder" version = "1.0.0" @@ -75,13 +82,13 @@ version = "0.0.0" dependencies = [ "alloc_artiq 0.0.0", "board 0.0.0", + "build_artiq 0.0.0", "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "fringe 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log_buffer 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "smoltcp 0.2.0 (git+https://github.com/m-labs/smoltcp?rev=b90495f)", "std_artiq 0.0.0", - "walkdir 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -90,10 +97,10 @@ version = "0.0.0" dependencies = [ "alloc_artiq 0.0.0", "board 0.0.0", + "build_artiq 0.0.0", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log_buffer 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "std_artiq 0.0.0", - "walkdir 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/artiq/firmware/libbuild_artiq/Cargo.toml b/artiq/firmware/libbuild_artiq/Cargo.toml new file mode 100644 index 000000000..19e810e99 --- /dev/null +++ b/artiq/firmware/libbuild_artiq/Cargo.toml @@ -0,0 +1,11 @@ +[package] +authors = ["M-Labs"] +name = "build_artiq" +version = "0.0.0" + +[lib] +name = "build_artiq" +path = "lib.rs" + +[dependencies] +walkdir = "1.0" diff --git a/artiq/firmware/libbuild_artiq/lib.rs b/artiq/firmware/libbuild_artiq/lib.rs new file mode 100644 index 000000000..e47374610 --- /dev/null +++ b/artiq/firmware/libbuild_artiq/lib.rs @@ -0,0 +1,48 @@ +extern crate walkdir; + +use std::env; +use std::fs::File; +use std::io::{BufRead, BufReader}; +use std::path::Path; +use std::process::Command; + +use walkdir::WalkDir; + +pub fn git_describe() { + let id = + Command::new("git") + .arg("describe") + .arg("--tags") + .arg("--dirty") + .arg("--always") + .arg("--long") + .output() + .ok() + .and_then(|o| String::from_utf8(o.stdout).ok()) + .map(|mut s| { + let len = s.trim_right().len(); + s.truncate(len); + s + }) + .unwrap(); + let id = id.split("-").collect::>(); + let id = format!("{}+{}.{}", id[0], id[1], id[2]); + println!("cargo:rust-cfg=git_describe={:?}", id); + + println!("cargo:rerun-if-changed=../../../.git/HEAD"); + for entry in WalkDir::new("../../../.git/refs") { + let entry = entry.unwrap(); + println!("cargo:rerun-if-changed={}", entry.path().display()); + } +} + +pub fn misoc_registers() { + 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()); + } +} diff --git a/artiq/firmware/runtime/Cargo.toml b/artiq/firmware/runtime/Cargo.toml index efd43c5cf..16ad8e8b5 100644 --- a/artiq/firmware/runtime/Cargo.toml +++ b/artiq/firmware/runtime/Cargo.toml @@ -4,14 +4,14 @@ name = "runtime" version = "0.0.0" build = "build.rs" -[build-dependencies] -walkdir = "1.0" - [lib] name = "runtime" crate-type = ["staticlib"] path = "lib.rs" +[build-dependencies] +build_artiq = { path = "../libbuild_artiq" } + [dependencies] alloc_artiq = { path = "../liballoc_artiq" } std_artiq = { path = "../libstd_artiq", features = ["alloc"] } diff --git a/artiq/firmware/runtime/build.rs b/artiq/firmware/runtime/build.rs index 5ab08cdd6..f6ab9cf8a 100644 --- a/artiq/firmware/runtime/build.rs +++ b/artiq/firmware/runtime/build.rs @@ -1,53 +1,6 @@ -extern crate walkdir; - -use std::env; -use std::fs::File; -use std::io::{Write, BufRead, BufReader}; -use std::path::Path; -use std::process::Command; - -use walkdir::WalkDir; +extern crate build_artiq; 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()); - } - - let out_dir = env::var("OUT_DIR").unwrap(); - let dest_path = Path::new(&out_dir).join("git_info.rs"); - let mut f = File::create(&dest_path).unwrap(); - - let id = git_describe().unwrap(); - let id = id.split("-").collect::>(); - let id = format!("{}+{}.{}", id[0], id[1], id[2]); - writeln!(f, "const GIT_COMMIT: &'static str = {:?};", id).unwrap(); - - println!("cargo:rerun-if-changed=../../../.git/HEAD"); - for entry in WalkDir::new("../../../.git/refs") { - let entry = entry.unwrap(); - println!("cargo:rerun-if-changed={}", entry.path().display()); - } -} - -// Returns `None` if git is not available. -fn git_describe() -> Option { - Command::new("git") - .arg("describe") - .arg("--tags") - .arg("--dirty") - .arg("--always") - .arg("--long") - .output() - .ok() - .and_then(|o| String::from_utf8(o.stdout).ok()) - .map(|mut s| { - let len = s.trim_right().len(); - s.truncate(len); - s - }) + build_artiq::git_describe(); + build_artiq::misoc_registers(); } diff --git a/artiq/firmware/runtime/lib.rs b/artiq/firmware/runtime/lib.rs index 9a99fb599..497353318 100644 --- a/artiq/firmware/runtime/lib.rs +++ b/artiq/firmware/runtime/lib.rs @@ -93,13 +93,11 @@ mod moninj; #[cfg(has_rtio_analyzer)] mod analyzer; -include!(concat!(env!("OUT_DIR"), "/git_info.rs")); - fn startup() { board::uart::set_speed(921600); board::clock::init(); info!("booting ARTIQ"); - info!("software version {}", GIT_COMMIT); + info!("software version {}", cfg!(git_describe)); info!("gateware version {}", board::ident(&mut [0; 64])); let t = board::clock::get_ms(); diff --git a/artiq/firmware/satman/Cargo.toml b/artiq/firmware/satman/Cargo.toml index c35a67e13..1ff6e1bf5 100644 --- a/artiq/firmware/satman/Cargo.toml +++ b/artiq/firmware/satman/Cargo.toml @@ -4,14 +4,14 @@ name = "satman" version = "0.0.0" build = "build.rs" -[build-dependencies] -walkdir = "1.0" - [lib] name = "satman" crate-type = ["staticlib"] path = "lib.rs" +[build-dependencies] +build_artiq = { path = "../libbuild_artiq" } + [dependencies] alloc_artiq = { path = "../liballoc_artiq" } std_artiq = { path = "../libstd_artiq", features = ["alloc"] } diff --git a/artiq/firmware/satman/build.rs b/artiq/firmware/satman/build.rs index 5ab08cdd6..d4537b9b3 100644 --- a/artiq/firmware/satman/build.rs +++ b/artiq/firmware/satman/build.rs @@ -1,53 +1,6 @@ -extern crate walkdir; - -use std::env; -use std::fs::File; -use std::io::{Write, BufRead, BufReader}; -use std::path::Path; -use std::process::Command; - -use walkdir::WalkDir; +extern crate artiq_build; 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()); - } - - let out_dir = env::var("OUT_DIR").unwrap(); - let dest_path = Path::new(&out_dir).join("git_info.rs"); - let mut f = File::create(&dest_path).unwrap(); - - let id = git_describe().unwrap(); - let id = id.split("-").collect::>(); - let id = format!("{}+{}.{}", id[0], id[1], id[2]); - writeln!(f, "const GIT_COMMIT: &'static str = {:?};", id).unwrap(); - - println!("cargo:rerun-if-changed=../../../.git/HEAD"); - for entry in WalkDir::new("../../../.git/refs") { - let entry = entry.unwrap(); - println!("cargo:rerun-if-changed={}", entry.path().display()); - } -} - -// Returns `None` if git is not available. -fn git_describe() -> Option { - Command::new("git") - .arg("describe") - .arg("--tags") - .arg("--dirty") - .arg("--always") - .arg("--long") - .output() - .ok() - .and_then(|o| String::from_utf8(o.stdout).ok()) - .map(|mut s| { - let len = s.trim_right().len(); - s.truncate(len); - s - }) + artiq_build::git_describe(); + artiq_build::misoc_registers(); } diff --git a/artiq/firmware/satman/lib.rs b/artiq/firmware/satman/lib.rs index b8cd5f7b7..09118cf58 100644 --- a/artiq/firmware/satman/lib.rs +++ b/artiq/firmware/satman/lib.rs @@ -56,8 +56,6 @@ pub extern fn panic_fmt(args: self::core::fmt::Arguments, file: &'static str, li mod logger; -include!(concat!(env!("OUT_DIR"), "/git_info.rs")); - // Allow linking with crates that are built as -Cpanic=unwind even if we use -Cpanic=abort. // This is never called. #[allow(non_snake_case)] @@ -73,7 +71,7 @@ pub unsafe extern fn rust_main() { .register(move || { board::clock::init(); info!("ARTIQ satellite manager starting..."); - info!("software version {}", GIT_COMMIT); + info!("software version {}", cfg!(git_describe)); info!("gateware version {}", board::ident(&mut [0; 64])); loop {