Skip to content

Commit 0bcc4db

Browse files
add build_rs to Generation struct
1 parent 2d4cb76 commit 0bcc4db

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,12 @@ mod generate;
449449
mod util;
450450

451451
pub use util::Target;
452+
use util::build_rs;
452453

453454
pub struct Generation {
454455
pub lib_rs: String,
455456
pub device_x: String,
457+
pub build_rs: String,
456458
}
457459

458460
type Result<T> = std::result::Result<T, SvdError>;
@@ -482,6 +484,7 @@ pub fn generate(xml: &str, target: &Target, nightly: bool) -> Result<Generation>
482484
Ok(Generation {
483485
lib_rs: lib_rs,
484486
device_x: device_x,
487+
build_rs: build_rs().to_string(),
485488
})
486489
}
487490

src/main.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use quote::Tokens;
2323
use clap::{App, Arg};
2424

2525
use errors::*;
26-
use util::Target;
26+
use util::{buld_rs, Target};
2727

2828
fn run() -> Result<()> {
2929
use std::io::Read;
@@ -122,28 +122,3 @@ fn main() {
122122
process::exit(1);
123123
}
124124
}
125-
126-
fn build_rs() -> Tokens {
127-
quote! {
128-
use std::env;
129-
use std::fs::File;
130-
use std::io::Write;
131-
use std::path::PathBuf;
132-
133-
fn main() {
134-
if env::var_os("CARGO_FEATURE_RT").is_some() {
135-
// Put the linker script somewhere the linker can find it
136-
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
137-
File::create(out.join("device.x"))
138-
.unwrap()
139-
.write_all(include_bytes!("device.x"))
140-
.unwrap();
141-
println!("cargo:rustc-link-search={}", out.display());
142-
143-
println!("cargo:rerun-if-changed=device.x");
144-
}
145-
146-
println!("cargo:rerun-if-changed=build.rs");
147-
}
148-
}
149-
}

src/util.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,28 @@ pub fn only_registers(ercs: &[Either<Register, Cluster>]) -> Vec<&Register> {
311311
.collect();
312312
registers
313313
}
314+
315+
pub fn build_rs() -> Tokens {
316+
quote! {
317+
use std::env;
318+
use std::fs::File;
319+
use std::io::Write;
320+
use std::path::PathBuf;
321+
322+
fn main() {
323+
if env::var_os("CARGO_FEATURE_RT").is_some() {
324+
// Put the linker script somewhere the linker can find it
325+
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
326+
File::create(out.join("device.x"))
327+
.unwrap()
328+
.write_all(include_bytes!("device.x"))
329+
.unwrap();
330+
println!("cargo:rustc-link-search={}", out.display());
331+
332+
println!("cargo:rerun-if-changed=device.x");
333+
}
334+
335+
println!("cargo:rerun-if-changed=build.rs");
336+
}
337+
}
338+
}

0 commit comments

Comments
 (0)