David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 1 | // Build mcuboot as a library, based on the requested features. |
| 2 | |
Fabio Utzig | 455cad5 | 2018-10-15 14:36:33 -0700 | [diff] [blame] | 3 | extern crate cc; |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 4 | |
| 5 | use std::env; |
| 6 | use std::fs; |
| 7 | use std::io; |
| 8 | use std::path::Path; |
| 9 | |
| 10 | fn main() { |
| 11 | // Feature flags. |
| 12 | let sig_rsa = env::var("CARGO_FEATURE_SIG_RSA").is_ok(); |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 13 | let sig_rsa3072 = env::var("CARGO_FEATURE_SIG_RSA3072").is_ok(); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 14 | let sig_ecdsa = env::var("CARGO_FEATURE_SIG_ECDSA").is_ok(); |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 15 | let sig_ed25519 = env::var("CARGO_FEATURE_SIG_ED25519").is_ok(); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 16 | let overwrite_only = env::var("CARGO_FEATURE_OVERWRITE_ONLY").is_ok(); |
Fabio Utzig | 031eb7d | 2019-11-28 10:13:14 -0300 | [diff] [blame] | 17 | let swap_move = env::var("CARGO_FEATURE_SWAP_MOVE").is_ok(); |
David Vincze | 2d736ad | 2019-02-18 11:50:22 +0100 | [diff] [blame] | 18 | let validate_primary_slot = |
| 19 | env::var("CARGO_FEATURE_VALIDATE_PRIMARY_SLOT").is_ok(); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 20 | let enc_rsa = env::var("CARGO_FEATURE_ENC_RSA").is_ok(); |
| 21 | let enc_kw = env::var("CARGO_FEATURE_ENC_KW").is_ok(); |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 22 | let enc_ec256 = env::var("CARGO_FEATURE_ENC_EC256").is_ok(); |
Fabio Utzig | 9b97b13 | 2018-12-18 17:21:51 -0200 | [diff] [blame] | 23 | let bootstrap = env::var("CARGO_FEATURE_BOOTSTRAP").is_ok(); |
David Brown | 5e6f5e0 | 2019-04-04 10:50:05 +0700 | [diff] [blame] | 24 | let multiimage = env::var("CARGO_FEATURE_MULTIIMAGE").is_ok(); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 25 | |
Fabio Utzig | 455cad5 | 2018-10-15 14:36:33 -0700 | [diff] [blame] | 26 | let mut conf = cc::Build::new(); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 27 | conf.define("__BOOTSIM__", None); |
Fabio Utzig | 08fcfe9 | 2018-11-26 10:18:18 -0200 | [diff] [blame] | 28 | conf.define("MCUBOOT_HAVE_LOGGING", None); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 29 | conf.define("MCUBOOT_USE_FLASH_AREA_GET_SECTORS", None); |
Marti Bolivar | 248da08 | 2018-04-24 15:11:39 -0400 | [diff] [blame] | 30 | conf.define("MCUBOOT_HAVE_ASSERT_H", None); |
Marti Bolivar | f9bfddd | 2018-04-24 14:28:33 -0400 | [diff] [blame] | 31 | conf.define("MCUBOOT_MAX_IMG_SECTORS", Some("128")); |
David Brown | 5e6f5e0 | 2019-04-04 10:50:05 +0700 | [diff] [blame] | 32 | conf.define("MCUBOOT_IMAGE_NUMBER", Some(if multiimage { "2" } else { "1" })); |
Fabio Utzig | ebdc969 | 2017-11-23 16:28:25 -0200 | [diff] [blame] | 33 | |
Fabio Utzig | 9b97b13 | 2018-12-18 17:21:51 -0200 | [diff] [blame] | 34 | if bootstrap { |
| 35 | conf.define("MCUBOOT_BOOTSTRAP", None); |
| 36 | } |
| 37 | |
David Vincze | 2d736ad | 2019-02-18 11:50:22 +0100 | [diff] [blame] | 38 | if validate_primary_slot { |
| 39 | conf.define("MCUBOOT_VALIDATE_PRIMARY_SLOT", None); |
Fabio Utzig | ebdc969 | 2017-11-23 16:28:25 -0200 | [diff] [blame] | 40 | } |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 41 | |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 42 | // Currently no more than one sig type can be used simultaneously. |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 43 | if vec![sig_rsa, sig_rsa3072, sig_ecdsa, sig_ed25519].iter() |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 44 | .fold(0, |sum, &v| sum + v as i32) > 1 { |
| 45 | panic!("mcuboot does not support more than one sig type at the same time"); |
David Brown | 704ac6f | 2017-07-12 10:14:47 -0600 | [diff] [blame] | 46 | } |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 47 | |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 48 | if sig_rsa || sig_rsa3072 { |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 49 | conf.define("MCUBOOT_SIGN_RSA", None); |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 50 | // The Kconfig style defines must be added here as well because |
| 51 | // they are used internally by "config-rsa.h" |
| 52 | if sig_rsa { |
| 53 | conf.define("MCUBOOT_SIGN_RSA_LEN", "2048"); |
| 54 | conf.define("CONFIG_BOOT_SIGNATURE_TYPE_RSA_2048", None); |
| 55 | } else { |
| 56 | conf.define("MCUBOOT_SIGN_RSA_LEN", "3072"); |
| 57 | conf.define("CONFIG_BOOT_SIGNATURE_TYPE_RSA_3072", None); |
| 58 | } |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 59 | conf.define("MCUBOOT_USE_MBED_TLS", None); |
| 60 | |
David Brown | f984b95 | 2019-10-11 10:32:36 -0600 | [diff] [blame] | 61 | conf.include("../../ext/mbedtls/include"); |
| 62 | conf.file("../../ext/mbedtls/library/sha256.c"); |
Fabio Utzig | 806af0e | 2018-04-26 10:53:54 -0300 | [diff] [blame] | 63 | conf.file("csupport/keys.c"); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 64 | |
David Brown | f984b95 | 2019-10-11 10:32:36 -0600 | [diff] [blame] | 65 | conf.file("../../ext/mbedtls/library/rsa.c"); |
| 66 | conf.file("../../ext/mbedtls/library/bignum.c"); |
| 67 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 68 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 69 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
David Brown | 704ac6f | 2017-07-12 10:14:47 -0600 | [diff] [blame] | 70 | } else if sig_ecdsa { |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 71 | conf.define("MCUBOOT_SIGN_EC256", None); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 72 | conf.define("MCUBOOT_USE_TINYCRYPT", None); |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 73 | |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 74 | if !enc_kw { |
David Brown | b748f6f | 2019-10-11 10:07:31 -0600 | [diff] [blame] | 75 | conf.include("../../ext/mbedtls-asn1/include"); |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 76 | } |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 77 | conf.include("../../ext/tinycrypt/lib/include"); |
| 78 | |
Fabio Utzig | 806af0e | 2018-04-26 10:53:54 -0300 | [diff] [blame] | 79 | conf.file("csupport/keys.c"); |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 80 | |
| 81 | conf.file("../../ext/tinycrypt/lib/source/utils.c"); |
| 82 | conf.file("../../ext/tinycrypt/lib/source/sha256.c"); |
| 83 | conf.file("../../ext/tinycrypt/lib/source/ecc.c"); |
| 84 | conf.file("../../ext/tinycrypt/lib/source/ecc_dsa.c"); |
| 85 | conf.file("../../ext/tinycrypt/lib/source/ecc_platform_specific.c"); |
| 86 | |
David Brown | b748f6f | 2019-10-11 10:07:31 -0600 | [diff] [blame] | 87 | conf.file("../../ext/mbedtls-asn1/src/platform_util.c"); |
| 88 | conf.file("../../ext/mbedtls-asn1/src/asn1parse.c"); |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 89 | } else if sig_ed25519 { |
| 90 | conf.define("MCUBOOT_SIGN_ED25519", None); |
| 91 | conf.define("MCUBOOT_USE_MBED_TLS", None); |
| 92 | |
David Brown | f984b95 | 2019-10-11 10:32:36 -0600 | [diff] [blame] | 93 | conf.include("../../ext/mbedtls/include"); |
| 94 | conf.file("../../ext/mbedtls/library/sha256.c"); |
| 95 | conf.file("../../ext/mbedtls/library/sha512.c"); |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 96 | conf.file("csupport/keys.c"); |
| 97 | conf.file("../../ext/fiat/src/curve25519.c"); |
David Brown | f984b95 | 2019-10-11 10:32:36 -0600 | [diff] [blame] | 98 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 99 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 100 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 101 | } else if !enc_ec256 { |
| 102 | // No signature type, only sha256 validation. The default |
Marti Bolivar | a4818a5 | 2018-04-12 13:02:38 -0400 | [diff] [blame] | 103 | // configuration file bundled with mbedTLS is sufficient. |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 104 | // When using ECIES-P256 rely on Tinycrypt. |
David Brown | 704ac6f | 2017-07-12 10:14:47 -0600 | [diff] [blame] | 105 | conf.define("MCUBOOT_USE_MBED_TLS", None); |
David Brown | f984b95 | 2019-10-11 10:32:36 -0600 | [diff] [blame] | 106 | conf.include("../../ext/mbedtls/include"); |
| 107 | conf.file("../../ext/mbedtls/library/sha256.c"); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | if overwrite_only { |
| 111 | conf.define("MCUBOOT_OVERWRITE_ONLY", None); |
Fabio Utzig | 13d9e35 | 2017-10-05 20:32:31 -0300 | [diff] [blame] | 112 | conf.define("MCUBOOT_OVERWRITE_ONLY_FAST", None); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 113 | } |
| 114 | |
Fabio Utzig | 031eb7d | 2019-11-28 10:13:14 -0300 | [diff] [blame] | 115 | if swap_move { |
| 116 | conf.define("MCUBOOT_SWAP_USING_MOVE", None); |
| 117 | } |
| 118 | |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 119 | if enc_rsa { |
| 120 | conf.define("MCUBOOT_ENCRYPT_RSA", None); |
| 121 | conf.define("MCUBOOT_ENC_IMAGES", None); |
| 122 | conf.define("MCUBOOT_USE_MBED_TLS", None); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 123 | |
| 124 | conf.file("../../boot/bootutil/src/encrypted.c"); |
| 125 | conf.file("csupport/keys.c"); |
| 126 | |
David Brown | f984b95 | 2019-10-11 10:32:36 -0600 | [diff] [blame] | 127 | conf.include("../../ext/mbedtls/include"); |
| 128 | conf.file("../../ext/mbedtls/library/sha256.c"); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 129 | |
David Brown | f984b95 | 2019-10-11 10:32:36 -0600 | [diff] [blame] | 130 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 131 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 132 | conf.file("../../ext/mbedtls/library/rsa.c"); |
| 133 | conf.file("../../ext/mbedtls/library/rsa_internal.c"); |
| 134 | conf.file("../../ext/mbedtls/library/md.c"); |
| 135 | conf.file("../../ext/mbedtls/library/md_wrap.c"); |
| 136 | conf.file("../../ext/mbedtls/library/aes.c"); |
| 137 | conf.file("../../ext/mbedtls/library/bignum.c"); |
| 138 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | if enc_kw { |
| 142 | conf.define("MCUBOOT_ENCRYPT_KW", None); |
| 143 | conf.define("MCUBOOT_ENC_IMAGES", None); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 144 | |
| 145 | conf.file("../../boot/bootutil/src/encrypted.c"); |
| 146 | conf.file("csupport/keys.c"); |
| 147 | |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 148 | if sig_rsa || sig_rsa3072 { |
David Brown | f984b95 | 2019-10-11 10:32:36 -0600 | [diff] [blame] | 149 | conf.file("../../ext/mbedtls/library/sha256.c"); |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 150 | } |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 151 | |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 152 | /* Simulator uses Mbed-TLS to wrap keys */ |
David Brown | f984b95 | 2019-10-11 10:32:36 -0600 | [diff] [blame] | 153 | conf.include("../../ext/mbedtls/include"); |
| 154 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 155 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 156 | conf.file("../../ext/mbedtls/library/nist_kw.c"); |
| 157 | conf.file("../../ext/mbedtls/library/cipher.c"); |
| 158 | conf.file("../../ext/mbedtls/library/cipher_wrap.c"); |
| 159 | conf.file("../../ext/mbedtls/library/aes.c"); |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 160 | |
| 161 | if sig_ecdsa { |
| 162 | conf.define("MCUBOOT_USE_TINYCRYPT", None); |
| 163 | |
| 164 | conf.include("../../ext/tinycrypt/lib/include"); |
| 165 | |
| 166 | conf.file("../../ext/tinycrypt/lib/source/utils.c"); |
| 167 | conf.file("../../ext/tinycrypt/lib/source/sha256.c"); |
| 168 | conf.file("../../ext/tinycrypt/lib/source/aes_encrypt.c"); |
| 169 | conf.file("../../ext/tinycrypt/lib/source/aes_decrypt.c"); |
| 170 | } |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 171 | |
| 172 | if sig_ed25519 { |
| 173 | panic!("ed25519 does not support image encryption with KW yet"); |
| 174 | } |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 175 | } |
| 176 | |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 177 | if enc_ec256 { |
| 178 | conf.define("MCUBOOT_ENCRYPT_EC256", None); |
| 179 | conf.define("MCUBOOT_ENC_IMAGES", None); |
| 180 | conf.define("MCUBOOT_USE_TINYCRYPT", None); |
| 181 | |
| 182 | conf.file("../../boot/bootutil/src/encrypted.c"); |
| 183 | conf.file("csupport/keys.c"); |
| 184 | |
| 185 | conf.include("../../ext/mbedtls-asn1/include"); |
| 186 | conf.include("../../ext/tinycrypt/lib/include"); |
| 187 | |
| 188 | /* FIXME: fail with other signature schemes ? */ |
| 189 | |
| 190 | conf.file("../../ext/tinycrypt/lib/source/utils.c"); |
| 191 | conf.file("../../ext/tinycrypt/lib/source/sha256.c"); |
| 192 | conf.file("../../ext/tinycrypt/lib/source/ecc.c"); |
| 193 | conf.file("../../ext/tinycrypt/lib/source/ecc_dsa.c"); |
| 194 | conf.file("../../ext/tinycrypt/lib/source/ecc_platform_specific.c"); |
| 195 | |
| 196 | conf.file("../../ext/mbedtls-asn1/src/platform_util.c"); |
| 197 | conf.file("../../ext/mbedtls-asn1/src/asn1parse.c"); |
| 198 | |
| 199 | conf.file("../../ext/tinycrypt/lib/source/aes_encrypt.c"); |
| 200 | conf.file("../../ext/tinycrypt/lib/source/aes_decrypt.c"); |
| 201 | conf.file("../../ext/tinycrypt/lib/source/ctr_mode.c"); |
| 202 | conf.file("../../ext/tinycrypt/lib/source/hmac.c"); |
| 203 | conf.file("../../ext/tinycrypt/lib/source/ecc_dh.c"); |
| 204 | } |
| 205 | |
| 206 | |
Fabio Utzig | 251ef1d | 2018-12-18 17:20:19 -0200 | [diff] [blame] | 207 | if sig_rsa && enc_kw { |
| 208 | conf.define("MBEDTLS_CONFIG_FILE", Some("<config-rsa-kw.h>")); |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 209 | } else if sig_rsa || sig_rsa3072 || enc_rsa { |
Fabio Utzig | 04fd63e | 2018-12-14 06:43:31 -0200 | [diff] [blame] | 210 | conf.define("MBEDTLS_CONFIG_FILE", Some("<config-rsa.h>")); |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 211 | } else if (sig_ecdsa || enc_ec256) && !enc_kw { |
Fabio Utzig | 04fd63e | 2018-12-14 06:43:31 -0200 | [diff] [blame] | 212 | conf.define("MBEDTLS_CONFIG_FILE", Some("<config-asn1.h>")); |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 213 | } else if sig_ed25519 { |
| 214 | conf.define("MBEDTLS_CONFIG_FILE", Some("<config-ed25519.h>")); |
Fabio Utzig | 04fd63e | 2018-12-14 06:43:31 -0200 | [diff] [blame] | 215 | } else if enc_kw { |
| 216 | conf.define("MBEDTLS_CONFIG_FILE", Some("<config-kw.h>")); |
| 217 | } |
| 218 | |
David Brown | 704ac6f | 2017-07-12 10:14:47 -0600 | [diff] [blame] | 219 | conf.file("../../boot/bootutil/src/image_validate.c"); |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 220 | if sig_rsa || sig_rsa3072 { |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 221 | conf.file("../../boot/bootutil/src/image_rsa.c"); |
| 222 | } else if sig_ecdsa { |
| 223 | conf.file("../../boot/bootutil/src/image_ec256.c"); |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 224 | } else if sig_ed25519 { |
| 225 | conf.file("../../boot/bootutil/src/image_ed25519.c"); |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 226 | } |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 227 | conf.file("../../boot/bootutil/src/loader.c"); |
Fabio Utzig | 031eb7d | 2019-11-28 10:13:14 -0300 | [diff] [blame] | 228 | conf.file("../../boot/bootutil/src/swap_misc.c"); |
| 229 | conf.file("../../boot/bootutil/src/swap_scratch.c"); |
| 230 | conf.file("../../boot/bootutil/src/swap_move.c"); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 231 | conf.file("../../boot/bootutil/src/caps.c"); |
| 232 | conf.file("../../boot/bootutil/src/bootutil_misc.c"); |
Fabio Utzig | 61fd888 | 2019-09-14 20:00:20 -0300 | [diff] [blame] | 233 | conf.file("../../boot/bootutil/src/tlv.c"); |
David Brown | d2b1853 | 2017-07-12 09:51:31 -0600 | [diff] [blame] | 234 | conf.file("csupport/run.c"); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 235 | conf.include("../../boot/bootutil/include"); |
Fabio Utzig | 57c40f7 | 2017-12-12 21:48:30 -0200 | [diff] [blame] | 236 | conf.include("csupport"); |
Fabio Utzig | 9a4b9ba | 2018-05-07 08:31:27 -0300 | [diff] [blame] | 237 | conf.include("../../boot/zephyr/include"); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 238 | conf.debug(true); |
| 239 | conf.flag("-Wall"); |
David Brown | 0b693c0 | 2017-07-12 12:34:33 -0600 | [diff] [blame] | 240 | conf.flag("-Werror"); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 241 | |
Fabio Utzig | 0bccf9d | 2017-12-07 12:13:57 -0200 | [diff] [blame] | 242 | // FIXME: travis-ci still uses gcc 4.8.4 which defaults to std=gnu90. |
| 243 | // It has incomplete std=c11 and std=c99 support but std=c99 was checked |
| 244 | // to build correctly so leaving it here to updated in the future... |
| 245 | conf.flag("-std=c99"); |
| 246 | |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 247 | conf.compile("libbootutil.a"); |
| 248 | |
| 249 | walk_dir("../../boot").unwrap(); |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 250 | walk_dir("../../ext/tinycrypt/lib/source").unwrap(); |
David Brown | b748f6f | 2019-10-11 10:07:31 -0600 | [diff] [blame] | 251 | walk_dir("../../ext/mbedtls-asn1").unwrap(); |
David Brown | d2b1853 | 2017-07-12 09:51:31 -0600 | [diff] [blame] | 252 | walk_dir("csupport").unwrap(); |
David Brown | f984b95 | 2019-10-11 10:32:36 -0600 | [diff] [blame] | 253 | walk_dir("../../ext/mbedtls/include").unwrap(); |
| 254 | walk_dir("../../ext/mbedtls/library").unwrap(); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | // Output the names of all files within a directory so that Cargo knows when to rebuild. |
| 258 | fn walk_dir<P: AsRef<Path>>(path: P) -> io::Result<()> { |
| 259 | for ent in fs::read_dir(path.as_ref())? { |
| 260 | let ent = ent?; |
| 261 | let p = ent.path(); |
| 262 | if p.is_dir() { |
| 263 | walk_dir(p)?; |
| 264 | } else { |
| 265 | // Note that non-utf8 names will fail. |
| 266 | let name = p.to_str().unwrap(); |
| 267 | if name.ends_with(".c") || name.ends_with(".h") { |
| 268 | println!("cargo:rerun-if-changed={}", name); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | Ok(()) |
| 274 | } |