Skip to content

Commit b3fac8b

Browse files
committed
Read target cflags from external files
1 parent 6a521b4 commit b3fac8b

File tree

5 files changed

+43
-114
lines changed

5 files changed

+43
-114
lines changed

ledger_secure_sdk_sys/build.rs

Lines changed: 33 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -24,56 +24,6 @@ const SDK_C_FILES: [&str; 13] = [
2424
"io/src/os_io_seph_ux.c",
2525
];
2626

27-
const CFLAGS_NANOSPLUS: [&str; 22] = [
28-
"-Oz",
29-
"-g0",
30-
"-fomit-frame-pointer",
31-
"-momit-leaf-frame-pointer",
32-
"-fno-common",
33-
"-mlittle-endian",
34-
"-std=gnu99",
35-
"-fdata-sections",
36-
"-ffunction-sections",
37-
"-funsigned-char",
38-
"-fshort-enums",
39-
"-mno-unaligned-access",
40-
"-fropi",
41-
"-fno-jump-tables",
42-
"-nostdlib",
43-
"-nodefaultlibs",
44-
"-frwpi",
45-
"--target=armv8m-none-eabi",
46-
"-mcpu=cortex-m35p+nodsp",
47-
"-mthumb",
48-
"-msoft-float",
49-
"-Wno-unused-command-line-argument",
50-
];
51-
const CFLAGS_STAX: [&str; 22] = CFLAGS_NANOSPLUS;
52-
const CFLAGS_FLEX: [&str; 22] = CFLAGS_NANOSPLUS;
53-
const CFLAGS_NANOX: [&str; 21] = [
54-
"-Oz",
55-
"-g0",
56-
"-fomit-frame-pointer",
57-
"-momit-leaf-frame-pointer",
58-
"-fno-common",
59-
"-mlittle-endian",
60-
"-std=gnu99",
61-
"-fdata-sections",
62-
"-ffunction-sections",
63-
"-funsigned-char",
64-
"-fshort-enums",
65-
"-mno-unaligned-access",
66-
"-fropi",
67-
"-fno-jump-tables",
68-
"-nostdlib",
69-
"-nodefaultlibs",
70-
"-frwpi",
71-
"-mthumb",
72-
"--target=armv6m-none-eabi",
73-
"-mcpu=cortex-m0plus",
74-
"-Wno-unused-command-line-argument",
75-
];
76-
7727
#[derive(Debug, Default, PartialEq)]
7828
enum DeviceName {
7929
#[default]
@@ -89,7 +39,7 @@ struct Device<'a> {
8939
pub c_sdk: PathBuf,
9040
pub target: &'a str,
9141
pub defines: Vec<(String, Option<String>)>,
92-
pub cflags: Vec<&'a str>,
42+
pub cflags: Vec<String>,
9343
pub glyphs_folders: Vec<PathBuf>,
9444
pub arm_libs: String,
9545
pub linker_script: &'a str,
@@ -201,7 +151,14 @@ impl SDKBuilder<'_> {
201151
}
202152
v
203153
},
204-
cflags: Vec::from(CFLAGS_NANOSPLUS),
154+
cflags: {
155+
let mut m_path = String::from(env!("CARGO_MANIFEST_DIR"));
156+
m_path.push_str("/c_sdk_build_nanosplus.cflags");
157+
let f = File::open(m_path)
158+
.expect("Failed to open c_sdk_build_nanosplus.cflags file");
159+
let reader = BufReader::new(f);
160+
reader.lines().filter_map(|line| line.ok()).collect::<Vec<String>>()
161+
},
205162
glyphs_folders: Vec::new(),
206163
arm_libs: Default::default(),
207164
linker_script: "nanosplus_layout.ld",
@@ -227,7 +184,14 @@ impl SDKBuilder<'_> {
227184
}
228185
v
229186
},
230-
cflags: Vec::from(CFLAGS_NANOX),
187+
cflags: {
188+
let mut m_path = String::from(env!("CARGO_MANIFEST_DIR"));
189+
m_path.push_str("/c_sdk_build_nanox.cflags");
190+
let f = File::open(m_path)
191+
.expect("Failed to open c_sdk_build_nanox.cflags file");
192+
let reader = BufReader::new(f);
193+
reader.lines().filter_map(|line| line.ok()).collect::<Vec<String>>()
194+
},
231195
glyphs_folders: Vec::new(),
232196
arm_libs: Default::default(),
233197
linker_script: "nanox_layout.ld",
@@ -240,7 +204,14 @@ impl SDKBuilder<'_> {
240204
},
241205
target: "thumbv8m.main-none-eabi",
242206
defines: header2define("csdk_stax.h"),
243-
cflags: Vec::from(CFLAGS_STAX),
207+
cflags: {
208+
let mut m_path = String::from(env!("CARGO_MANIFEST_DIR"));
209+
m_path.push_str("/c_sdk_build_stax.cflags");
210+
let f = File::open(m_path)
211+
.expect("Failed to open c_sdk_build_stax.cflags file");
212+
let reader = BufReader::new(f);
213+
reader.lines().filter_map(|line| line.ok()).collect::<Vec<String>>()
214+
},
244215
glyphs_folders: Vec::new(),
245216
arm_libs: Default::default(),
246217
linker_script: "stax_layout.ld",
@@ -253,7 +224,14 @@ impl SDKBuilder<'_> {
253224
},
254225
target: "thumbv8m.main-none-eabi",
255226
defines: header2define("csdk_flex.h"),
256-
cflags: Vec::from(CFLAGS_FLEX),
227+
cflags: {
228+
let mut m_path = String::from(env!("CARGO_MANIFEST_DIR"));
229+
m_path.push_str("/c_sdk_build_flex.cflags");
230+
let f = File::open(m_path)
231+
.expect("Failed to open c_sdk_build_flex.cflags file");
232+
let reader = BufReader::new(f);
233+
reader.lines().filter_map(|line| line.ok()).collect::<Vec<String>>()
234+
},
257235
glyphs_folders: Vec::new(),
258236
arm_libs: Default::default(),
259237
linker_script: "flex_layout.ld",
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
1-
--sysroot="/usr/arm-none-eabi"
21
-Oz
32
-g0
43
-fomit-frame-pointer
54
-momit-leaf-frame-pointer
65
-fno-common
76
-mlittle-endian
87
-std=gnu99
9-
-Wall
10-
-Wextra
11-
-Wno-main
12-
-Werror=int-to-pointer-cast
13-
-Wno-error=int-conversion
14-
-Wimplicit-fallthrough
15-
-Wvla
16-
-Wundef
17-
-Wshadow
18-
-Wformat=2
19-
-Wformat-security
20-
-Wwrite-strings
218
-fdata-sections
229
-ffunction-sections
2310
-funsigned-char
@@ -28,7 +15,8 @@
2815
-nostdlib
2916
-nodefaultlibs
3017
-frwpi
31-
-mthumb
3218
--target=armv8m-none-eabi
3319
-mcpu=cortex-m35p+nodsp
34-
-msoft-float
20+
-mthumb
21+
-msoft-float
22+
-Wno-unused-command-line-argument
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
1-
--sysroot="/usr/arm-none-eabi"
21
-Oz
32
-g0
43
-fomit-frame-pointer
54
-momit-leaf-frame-pointer
65
-fno-common
76
-mlittle-endian
87
-std=gnu99
9-
-Wall
10-
-Wextra
11-
-Wno-main
12-
-Werror=int-to-pointer-cast
13-
-Wno-error=int-conversion
14-
-Wimplicit-fallthrough
15-
-Wvla
16-
-Wundef
17-
-Wshadow
18-
-Wformat=2
19-
-Wformat-security
20-
-Wwrite-strings
218
-fdata-sections
229
-ffunction-sections
2310
-funsigned-char
@@ -28,7 +15,8 @@
2815
-nostdlib
2916
-nodefaultlibs
3017
-frwpi
31-
-mthumb
3218
--target=armv8m-none-eabi
3319
-mcpu=cortex-m35p+nodsp
34-
-msoft-float
20+
-mthumb
21+
-msoft-float
22+
-Wno-unused-command-line-argument
Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
1-
--sysroot="/usr/arm-none-eabi"
21
-Oz
32
-g0
43
-fomit-frame-pointer
54
-momit-leaf-frame-pointer
65
-fno-common
76
-mlittle-endian
87
-std=gnu99
9-
-Wall
10-
-Wextra
11-
-Wno-main
12-
-Werror=int-to-pointer-cast
13-
-Wno-error=int-conversion
14-
-Wimplicit-fallthrough
15-
-Wvla
16-
-Wundef
17-
-Wshadow
18-
-Wformat=2
19-
-Wformat-security
20-
-Wwrite-strings
218
-fdata-sections
229
-ffunction-sections
2310
-funsigned-char
@@ -31,4 +18,4 @@
3118
-mthumb
3219
--target=armv6m-none-eabi
3320
-mcpu=cortex-m0plus
34-
21+
-Wno-unused-command-line-argument
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
1-
--sysroot="/usr/arm-none-eabi"
21
-Oz
32
-g0
43
-fomit-frame-pointer
54
-momit-leaf-frame-pointer
65
-fno-common
76
-mlittle-endian
87
-std=gnu99
9-
-Wall
10-
-Wextra
11-
-Wno-main
12-
-Werror=int-to-pointer-cast
13-
-Wno-error=int-conversion
14-
-Wimplicit-fallthrough
15-
-Wvla
16-
-Wundef
17-
-Wshadow
18-
-Wformat=2
19-
-Wformat-security
20-
-Wwrite-strings
218
-fdata-sections
229
-ffunction-sections
2310
-funsigned-char
@@ -28,7 +15,8 @@
2815
-nostdlib
2916
-nodefaultlibs
3017
-frwpi
31-
-mthumb
3218
--target=armv8m-none-eabi
3319
-mcpu=cortex-m35p+nodsp
34-
-msoft-float
20+
-mthumb
21+
-msoft-float
22+
-Wno-unused-command-line-argument

0 commit comments

Comments
 (0)