1
+ extern crate cc;
2
+
1
3
use std:: env;
2
4
use std:: fs:: File ;
3
5
use std:: io:: Write ;
@@ -7,14 +9,48 @@ fn main() {
7
9
let target = env:: var ( "TARGET" ) . unwrap ( ) ;
8
10
9
11
has_fpu ( & target) ;
10
- is_armv6m ( & target) ;
12
+ let is_armv6m = is_armv6m ( & target) ;
13
+
14
+ if target. starts_with ( "thumbv" ) {
15
+ cc:: Build :: new ( ) . file ( "asm.s" ) . compile ( "asm" ) ;
16
+ }
11
17
12
18
// Put the linker script somewhere the linker can find it
13
19
let out = & PathBuf :: from ( env:: var_os ( "OUT_DIR" ) . unwrap ( ) ) ;
14
- File :: create ( out. join ( "link.x" ) )
15
- . unwrap ( )
16
- . write_all ( include_bytes ! ( "link.x" ) )
17
- . unwrap ( ) ;
20
+ let link_x = include_bytes ! ( "link.x.in" ) ;
21
+ let mut f = if env:: var_os ( "CARGO_FEATURE_DEVICE" ) . is_some ( ) {
22
+ let mut f = File :: create ( out. join ( "link.x" ) ) . unwrap ( ) ;
23
+
24
+ writeln ! (
25
+ f,
26
+ r#"
27
+ /* Provides weak aliases (cf. PROVIDED) for device specific interrupt handlers */
28
+ /* This will usually be provided by a device crate generated using svd2rust (see `device.x`) */
29
+ INCLUDE device.x"#
30
+ ) . unwrap ( ) ;
31
+ f. write_all ( link_x) . unwrap ( ) ;
32
+ f
33
+ } else {
34
+ let mut f = File :: create ( out. join ( "link.x" ) ) . unwrap ( ) ;
35
+ f. write_all ( link_x) . unwrap ( ) ;
36
+ f
37
+ } ;
38
+
39
+ let max_int_handlers = if is_armv6m { 32 } else { 240 } ;
40
+
41
+ // checking the size of the interrupts portion of the vector table is sub-architecture dependent
42
+ writeln ! (
43
+ f,
44
+ r#"
45
+ ASSERT(__einterrupts - __eexceptions <= 0x{:x}, "
46
+ There can't be more than {} interrupt handlers. This may be a bug in
47
+ your device crate, or you may have registered more than 240 interrupt
48
+ handlers.");
49
+ "# ,
50
+ max_int_handlers * 4 ,
51
+ max_int_handlers
52
+ ) . unwrap ( ) ;
53
+
18
54
println ! ( "cargo:rustc-link-search={}" , out. display( ) ) ;
19
55
20
56
println ! ( "cargo:rerun-if-changed=build.rs" ) ;
@@ -27,8 +63,11 @@ fn has_fpu(target: &str) {
27
63
}
28
64
}
29
65
30
- fn is_armv6m ( target : & str ) {
66
+ fn is_armv6m ( target : & str ) -> bool {
31
67
if target. starts_with ( "thumbv6m-" ) {
32
68
println ! ( "cargo:rustc-cfg=armv6m" ) ;
69
+ true
70
+ } else {
71
+ false
33
72
}
34
73
}
0 commit comments