From 9b4c1ddc8e25f04f7a25569100964fd76102ff9e Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 3 Jan 2017 21:39:40 +0100 Subject: [PATCH] libboard: use --cfg --- artiq/firmware/libboard/Cargo.toml | 1 + artiq/firmware/libboard/build.rs | 17 +++++++++++++++++ artiq/firmware/libboard/lib.rs | 8 ++++---- 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 artiq/firmware/libboard/build.rs diff --git a/artiq/firmware/libboard/Cargo.toml b/artiq/firmware/libboard/Cargo.toml index b4b992825..bb9a80f96 100644 --- a/artiq/firmware/libboard/Cargo.toml +++ b/artiq/firmware/libboard/Cargo.toml @@ -2,6 +2,7 @@ authors = ["M-Labs"] name = "board" version = "0.0.0" +build = "build.rs" [lib] name = "board" diff --git a/artiq/firmware/libboard/build.rs b/artiq/firmware/libboard/build.rs new file mode 100644 index 000000000..4bb8665df --- /dev/null +++ b/artiq/firmware/libboard/build.rs @@ -0,0 +1,17 @@ +use std::env; +use std::path::Path; +use std::io::{BufRead, BufReader}; +use std::fs::File; + +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()); + } + + println!("cargo:rustc-cfg={}", "board"); +} diff --git a/artiq/firmware/libboard/lib.rs b/artiq/firmware/libboard/lib.rs index 783e9ea88..bf865efb9 100644 --- a/artiq/firmware/libboard/lib.rs +++ b/artiq/firmware/libboard/lib.rs @@ -11,15 +11,15 @@ include!(concat!(env!("BUILDINC_DIRECTORY"), "/generated/csr.rs")); pub mod spr; pub mod irq; pub mod clock; -// XXX #[cfg(has_ad9516)] +#[cfg(has_ad9516)] #[allow(dead_code)] mod ad9516_reg; -// XXX #[cfg(has_ad9516)] +#[cfg(has_ad9516)] pub mod ad9516; -// XXX #[cfg(has_converter_spi)] +#[cfg(has_converter_spi)] #[allow(dead_code)] mod ad9154_reg; -// XXX #[cfg(has_converter_spi)] +#[cfg(has_converter_spi)] pub mod ad9154; extern {