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 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 5 | use std::collections::BTreeSet; |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 6 | use std::env; |
| 7 | use std::fs; |
| 8 | use std::io; |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 9 | use std::path::{Path, PathBuf}; |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 10 | |
| 11 | fn main() { |
| 12 | // Feature flags. |
| 13 | let sig_rsa = env::var("CARGO_FEATURE_SIG_RSA").is_ok(); |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 14 | let sig_rsa3072 = env::var("CARGO_FEATURE_SIG_RSA3072").is_ok(); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 15 | let sig_ecdsa = env::var("CARGO_FEATURE_SIG_ECDSA").is_ok(); |
David Brown | 641af45 | 2021-02-19 12:16:48 -0700 | [diff] [blame] | 16 | let sig_ecdsa_mbedtls = env::var("CARGO_FEATURE_SIG_ECDSA_MBEDTLS").is_ok(); |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 17 | let sig_ed25519 = env::var("CARGO_FEATURE_SIG_ED25519").is_ok(); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 18 | let overwrite_only = env::var("CARGO_FEATURE_OVERWRITE_ONLY").is_ok(); |
Fabio Utzig | 031eb7d | 2019-11-28 10:13:14 -0300 | [diff] [blame] | 19 | let swap_move = env::var("CARGO_FEATURE_SWAP_MOVE").is_ok(); |
Roman Okhrimenko | 13f79ed | 2021-03-11 19:05:41 +0200 | [diff] [blame] | 20 | let swap_status = env::var("CARGO_FEATURE_SWAP_STATUS").is_ok(); |
David Vincze | 2d736ad | 2019-02-18 11:50:22 +0100 | [diff] [blame] | 21 | let validate_primary_slot = |
| 22 | env::var("CARGO_FEATURE_VALIDATE_PRIMARY_SLOT").is_ok(); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 23 | let enc_rsa = env::var("CARGO_FEATURE_ENC_RSA").is_ok(); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 24 | let enc_aes256_rsa = env::var("CARGO_FEATURE_ENC_AES256_RSA").is_ok(); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 25 | let enc_kw = env::var("CARGO_FEATURE_ENC_KW").is_ok(); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 26 | let enc_aes256_kw = env::var("CARGO_FEATURE_ENC_AES256_KW").is_ok(); |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 27 | let enc_ec256 = env::var("CARGO_FEATURE_ENC_EC256").is_ok(); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 28 | let enc_ec256_mbedtls = env::var("CARGO_FEATURE_ENC_EC256_MBEDTLS").is_ok(); |
| 29 | let enc_aes256_ec256 = env::var("CARGO_FEATURE_ENC_AES256_EC256").is_ok(); |
Fabio Utzig | 3fa72ca | 2020-04-02 11:20:37 -0300 | [diff] [blame] | 30 | let enc_x25519 = env::var("CARGO_FEATURE_ENC_X25519").is_ok(); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 31 | let enc_aes256_x25519 = env::var("CARGO_FEATURE_ENC_AES256_X25519").is_ok(); |
Fabio Utzig | 9b97b13 | 2018-12-18 17:21:51 -0200 | [diff] [blame] | 32 | let bootstrap = env::var("CARGO_FEATURE_BOOTSTRAP").is_ok(); |
David Brown | 5e6f5e0 | 2019-04-04 10:50:05 +0700 | [diff] [blame] | 33 | let multiimage = env::var("CARGO_FEATURE_MULTIIMAGE").is_ok(); |
David Brown | 2ee5f7f | 2020-01-13 14:04:01 -0700 | [diff] [blame] | 34 | let downgrade_prevention = env::var("CARGO_FEATURE_DOWNGRADE_PREVENTION").is_ok(); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 35 | let ram_load = env::var("CARGO_FEATURE_RAM_LOAD").is_ok(); |
| 36 | let direct_xip = env::var("CARGO_FEATURE_DIRECT_XIP").is_ok(); |
Roman Okhrimenko | dc0ca08 | 2023-06-21 20:49:51 +0300 | [diff] [blame] | 37 | let max_align_32 = env::var("CARGO_FEATURE_MAX_ALIGN_32").is_ok(); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 38 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 39 | let mut conf = CachedBuild::new(); |
| 40 | conf.conf.define("__BOOTSIM__", None); |
| 41 | conf.conf.define("MCUBOOT_HAVE_LOGGING", None); |
| 42 | conf.conf.define("MCUBOOT_USE_FLASH_AREA_GET_SECTORS", None); |
| 43 | conf.conf.define("MCUBOOT_HAVE_ASSERT_H", None); |
| 44 | conf.conf.define("MCUBOOT_MAX_IMG_SECTORS", Some("128")); |
INFINEON\DovhalA | 21babb7 | 2025-07-18 10:36:03 +0300 | [diff] [blame] | 45 | conf.conf.define("MCUBOOT_DEPENDENCY_CHECK", None); |
| 46 | |
Roman Okhrimenko | dc0ca08 | 2023-06-21 20:49:51 +0300 | [diff] [blame] | 47 | if max_align_32 { |
| 48 | conf.conf.define("MCUBOOT_BOOT_MAX_ALIGN", Some("32")); |
| 49 | } else { |
| 50 | conf.conf.define("MCUBOOT_BOOT_MAX_ALIGN", Some("8")); |
| 51 | } |
| 52 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 53 | conf.conf.define("MCUBOOT_IMAGE_NUMBER", Some(if multiimage { "2" } else { "1" })); |
Fabio Utzig | ebdc969 | 2017-11-23 16:28:25 -0200 | [diff] [blame] | 54 | |
David Brown | 2ee5f7f | 2020-01-13 14:04:01 -0700 | [diff] [blame] | 55 | if downgrade_prevention && !overwrite_only { |
| 56 | panic!("Downgrade prevention requires overwrite only"); |
| 57 | } |
| 58 | |
Fabio Utzig | 9b97b13 | 2018-12-18 17:21:51 -0200 | [diff] [blame] | 59 | if bootstrap { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 60 | conf.conf.define("MCUBOOT_BOOTSTRAP", None); |
| 61 | conf.conf.define("MCUBOOT_OVERWRITE_ONLY_FAST", None); |
Fabio Utzig | 9b97b13 | 2018-12-18 17:21:51 -0200 | [diff] [blame] | 62 | } |
| 63 | |
David Vincze | 2d736ad | 2019-02-18 11:50:22 +0100 | [diff] [blame] | 64 | if validate_primary_slot { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 65 | conf.conf.define("MCUBOOT_VALIDATE_PRIMARY_SLOT", None); |
Fabio Utzig | ebdc969 | 2017-11-23 16:28:25 -0200 | [diff] [blame] | 66 | } |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 67 | |
David Brown | 2ee5f7f | 2020-01-13 14:04:01 -0700 | [diff] [blame] | 68 | if downgrade_prevention { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 69 | conf.conf.define("MCUBOOT_DOWNGRADE_PREVENTION", None); |
| 70 | } |
| 71 | |
| 72 | if ram_load { |
| 73 | conf.conf.define("MCUBOOT_RAM_LOAD", None); |
| 74 | } |
| 75 | |
| 76 | if direct_xip { |
| 77 | conf.conf.define("MCUBOOT_DIRECT_XIP", None); |
David Brown | 2ee5f7f | 2020-01-13 14:04:01 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 80 | // Currently no more than one sig type can be used simultaneously. |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 81 | if vec![sig_rsa, sig_rsa3072, sig_ecdsa, sig_ed25519].iter() |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 82 | .fold(0, |sum, &v| sum + v as i32) > 1 { |
| 83 | 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] | 84 | } |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 85 | |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 86 | if sig_rsa || sig_rsa3072 { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 87 | conf.conf.define("MCUBOOT_SIGN_RSA", None); |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 88 | // The Kconfig style defines must be added here as well because |
| 89 | // they are used internally by "config-rsa.h" |
| 90 | if sig_rsa { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 91 | conf.conf.define("MCUBOOT_SIGN_RSA_LEN", "2048"); |
| 92 | conf.conf.define("CONFIG_BOOT_SIGNATURE_TYPE_RSA_LEN", "2048"); |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 93 | } else { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 94 | conf.conf.define("MCUBOOT_SIGN_RSA_LEN", "3072"); |
| 95 | conf.conf.define("CONFIG_BOOT_SIGNATURE_TYPE_RSA_LEN", "3072"); |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 96 | } |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 97 | conf.conf.define("MCUBOOT_USE_MBED_TLS", None); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 98 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 99 | conf.conf.include("../../ext/mbedtls/include"); |
| 100 | conf.file("../../ext/mbedtls/library/sha256.c"); |
Fabio Utzig | 806af0e | 2018-04-26 10:53:54 -0300 | [diff] [blame] | 101 | conf.file("csupport/keys.c"); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 102 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 103 | conf.file("../../ext/mbedtls/library/rsa.c"); |
INFINEON\DovhalA | 21babb7 | 2025-07-18 10:36:03 +0300 | [diff] [blame] | 104 | conf.file("../../ext/mbedtls/library/hash_info.c"); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 105 | conf.file("../../ext/mbedtls/library/bignum.c"); |
INFINEON\DovhalA | 21babb7 | 2025-07-18 10:36:03 +0300 | [diff] [blame] | 106 | conf.file("../../ext/mbedtls/library/bignum_core.c"); |
| 107 | conf.file("../../ext/mbedtls/library/bignum_mod_raw.c"); |
| 108 | conf.file("../../ext/mbedtls/library/constant_time.c"); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 109 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 110 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 111 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
David Brown | 704ac6f | 2017-07-12 10:14:47 -0600 | [diff] [blame] | 112 | } else if sig_ecdsa { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 113 | conf.conf.define("MCUBOOT_SIGN_EC256", None); |
| 114 | conf.conf.define("MCUBOOT_USE_TINYCRYPT", None); |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 115 | |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 116 | if !enc_kw { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 117 | conf.conf.include("../../ext/mbedtls/include"); |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 118 | } |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 119 | conf.conf.include("../../ext/tinycrypt/lib/include"); |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 120 | |
Fabio Utzig | 806af0e | 2018-04-26 10:53:54 -0300 | [diff] [blame] | 121 | conf.file("csupport/keys.c"); |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 122 | |
| 123 | conf.file("../../ext/tinycrypt/lib/source/utils.c"); |
| 124 | conf.file("../../ext/tinycrypt/lib/source/sha256.c"); |
| 125 | conf.file("../../ext/tinycrypt/lib/source/ecc.c"); |
| 126 | conf.file("../../ext/tinycrypt/lib/source/ecc_dsa.c"); |
| 127 | conf.file("../../ext/tinycrypt/lib/source/ecc_platform_specific.c"); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 128 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 129 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
David Brown | 641af45 | 2021-02-19 12:16:48 -0700 | [diff] [blame] | 130 | } else if sig_ecdsa_mbedtls { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 131 | conf.conf.define("MCUBOOT_SIGN_EC256", None); |
| 132 | conf.conf.define("MCUBOOT_USE_MBED_TLS", None); |
David Brown | 641af45 | 2021-02-19 12:16:48 -0700 | [diff] [blame] | 133 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 134 | conf.conf.include("../../ext/mbedtls/include"); |
| 135 | conf.file("../../ext/mbedtls/library/sha256.c"); |
David Brown | 641af45 | 2021-02-19 12:16:48 -0700 | [diff] [blame] | 136 | conf.file("csupport/keys.c"); |
| 137 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 138 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
| 139 | conf.file("../../ext/mbedtls/library/bignum.c"); |
INFINEON\DovhalA | 21babb7 | 2025-07-18 10:36:03 +0300 | [diff] [blame] | 140 | conf.file("../../ext/mbedtls/library/bignum_core.c"); |
| 141 | conf.file("../../ext/mbedtls/library/bignum_mod_raw.c"); |
| 142 | conf.file("../../ext/mbedtls/library/constant_time.c"); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 143 | conf.file("../../ext/mbedtls/library/ecdsa.c"); |
| 144 | conf.file("../../ext/mbedtls/library/ecp.c"); |
| 145 | conf.file("../../ext/mbedtls/library/ecp_curves.c"); |
| 146 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 147 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 148 | } else if sig_ed25519 { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 149 | conf.conf.define("MCUBOOT_SIGN_ED25519", None); |
| 150 | conf.conf.define("MCUBOOT_USE_TINYCRYPT", None); |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 151 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 152 | conf.conf.include("../../ext/tinycrypt/lib/include"); |
| 153 | conf.conf.include("../../ext/tinycrypt-sha512/lib/include"); |
| 154 | conf.conf.include("../../ext/mbedtls/include"); |
Fabio Utzig | a1c142d | 2020-01-03 08:28:11 -0300 | [diff] [blame] | 155 | conf.file("../../ext/tinycrypt/lib/source/sha256.c"); |
| 156 | conf.file("../../ext/tinycrypt-sha512/lib/source/sha512.c"); |
| 157 | conf.file("../../ext/tinycrypt/lib/source/utils.c"); |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 158 | conf.file("csupport/keys.c"); |
| 159 | conf.file("../../ext/fiat/src/curve25519.c"); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 160 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 161 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
Fabio Utzig | 3fa72ca | 2020-04-02 11:20:37 -0300 | [diff] [blame] | 162 | } else if !enc_ec256 && !enc_x25519 { |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 163 | // No signature type, only sha256 validation. The default |
Marti Bolivar | a4818a5 | 2018-04-12 13:02:38 -0400 | [diff] [blame] | 164 | // configuration file bundled with mbedTLS is sufficient. |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 165 | // When using ECIES-P256 rely on Tinycrypt. |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 166 | conf.conf.define("MCUBOOT_USE_MBED_TLS", None); |
| 167 | conf.conf.include("../../ext/mbedtls/include"); |
| 168 | conf.file("../../ext/mbedtls/library/sha256.c"); |
| 169 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | if overwrite_only { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 173 | conf.conf.define("MCUBOOT_OVERWRITE_ONLY", None); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 174 | } |
| 175 | |
Fabio Utzig | 031eb7d | 2019-11-28 10:13:14 -0300 | [diff] [blame] | 176 | if swap_move { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 177 | conf.conf.define("MCUBOOT_SWAP_USING_MOVE", None); |
| 178 | } else if !overwrite_only { |
| 179 | conf.conf.define("CONFIG_BOOT_SWAP_USING_SCRATCH", None); |
| 180 | conf.conf.define("MCUBOOT_SWAP_USING_SCRATCH", None); |
Roman Okhrimenko | 13f79ed | 2021-03-11 19:05:41 +0200 | [diff] [blame] | 181 | } |
Roman Okhrimenko | dc0ca08 | 2023-06-21 20:49:51 +0300 | [diff] [blame] | 182 | |
Roman Okhrimenko | 13f79ed | 2021-03-11 19:05:41 +0200 | [diff] [blame] | 183 | if swap_status { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 184 | conf.conf.define("MCUBOOT_SWAP_USING_STATUS", None); |
Roman Okhrimenko | dc0ca08 | 2023-06-21 20:49:51 +0300 | [diff] [blame] | 185 | conf.conf.define("MEMORY_ALIGN", "512"); |
| 186 | conf.conf.define("PLATFORM_MAX_TRAILER_PAGE_SIZE", "512"); |
| 187 | conf.conf.define("SLOTS_FOR_IMAGE", "2"); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 188 | conf.conf.file("../../boot/bootutil/src/swap_status.c"); |
| 189 | conf.conf.file("../../boot/bootutil/src/swap_status_part.c"); |
| 190 | conf.conf.file("../../boot/bootutil/src/swap_status_misc.c"); |
| 191 | conf.conf.file("../../boot/bootutil/src/crc32c.c"); |
Fabio Utzig | 031eb7d | 2019-11-28 10:13:14 -0300 | [diff] [blame] | 192 | } |
| 193 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 194 | if enc_rsa || enc_aes256_rsa { |
| 195 | if enc_aes256_rsa { |
| 196 | conf.conf.define("MCUBOOT_AES_256", None); |
| 197 | } |
| 198 | conf.conf.define("MCUBOOT_ENCRYPT_RSA", None); |
| 199 | conf.conf.define("MCUBOOT_ENC_IMAGES", None); |
| 200 | conf.conf.define("MCUBOOT_USE_MBED_TLS", None); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 201 | |
| 202 | conf.file("../../boot/bootutil/src/encrypted.c"); |
| 203 | conf.file("csupport/keys.c"); |
| 204 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 205 | conf.conf.include("../../ext/mbedtls/include"); |
| 206 | conf.conf.include("../../ext/mbedtls/library"); |
| 207 | conf.file("../../ext/mbedtls/library/sha256.c"); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 208 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 209 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 210 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 211 | conf.file("../../ext/mbedtls/library/rsa.c"); |
INFINEON\DovhalA | 21babb7 | 2025-07-18 10:36:03 +0300 | [diff] [blame] | 212 | conf.file("../../ext/mbedtls/library/hash_info.c"); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 213 | conf.file("../../ext/mbedtls/library/rsa_alt_helpers.c"); |
| 214 | conf.file("../../ext/mbedtls/library/md.c"); |
| 215 | conf.file("../../ext/mbedtls/library/aes.c"); |
| 216 | conf.file("../../ext/mbedtls/library/bignum.c"); |
INFINEON\DovhalA | 21babb7 | 2025-07-18 10:36:03 +0300 | [diff] [blame] | 217 | conf.file("../../ext/mbedtls/library/bignum_core.c"); |
| 218 | conf.file("../../ext/mbedtls/library/bignum_mod_raw.c"); |
| 219 | conf.file("../../ext/mbedtls/library/constant_time.c"); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 220 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 221 | } |
| 222 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 223 | if enc_kw || enc_aes256_kw { |
| 224 | if enc_aes256_kw { |
| 225 | conf.conf.define("MCUBOOT_AES_256", None); |
| 226 | } |
| 227 | conf.conf.define("MCUBOOT_ENCRYPT_KW", None); |
| 228 | conf.conf.define("MCUBOOT_ENC_IMAGES", None); |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 229 | |
| 230 | conf.file("../../boot/bootutil/src/encrypted.c"); |
| 231 | conf.file("csupport/keys.c"); |
| 232 | |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 233 | if sig_rsa || sig_rsa3072 { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 234 | conf.file("../../ext/mbedtls/library/sha256.c"); |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 235 | } |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 236 | |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 237 | /* Simulator uses Mbed-TLS to wrap keys */ |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 238 | conf.conf.include("../../ext/mbedtls/include"); |
| 239 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 240 | conf.conf.include("../../ext/mbedtls/library"); |
| 241 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 242 | conf.file("../../ext/mbedtls/library/nist_kw.c"); |
INFINEON\DovhalA | 21babb7 | 2025-07-18 10:36:03 +0300 | [diff] [blame] | 243 | conf.file("../../ext/mbedtls/library/constant_time.c"); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 244 | conf.file("../../ext/mbedtls/library/cipher.c"); |
| 245 | conf.file("../../ext/mbedtls/library/cipher_wrap.c"); |
| 246 | conf.file("../../ext/mbedtls/library/aes.c"); |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 247 | |
| 248 | if sig_ecdsa { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 249 | conf.conf.define("MCUBOOT_USE_TINYCRYPT", None); |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 250 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 251 | conf.conf.include("../../ext/tinycrypt/lib/include"); |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 252 | |
| 253 | conf.file("../../ext/tinycrypt/lib/source/utils.c"); |
| 254 | conf.file("../../ext/tinycrypt/lib/source/sha256.c"); |
| 255 | conf.file("../../ext/tinycrypt/lib/source/aes_encrypt.c"); |
| 256 | conf.file("../../ext/tinycrypt/lib/source/aes_decrypt.c"); |
Blaž Hrastnik | 4f4833d | 2020-09-14 13:53:31 +0900 | [diff] [blame] | 257 | conf.file("../../ext/tinycrypt/lib/source/ctr_mode.c"); |
Fabio Utzig | b4d20c8 | 2018-12-27 16:08:39 -0200 | [diff] [blame] | 258 | } |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 259 | |
| 260 | if sig_ed25519 { |
| 261 | panic!("ed25519 does not support image encryption with KW yet"); |
| 262 | } |
Fabio Utzig | 1e48b91 | 2018-09-18 09:04:18 -0300 | [diff] [blame] | 263 | } |
| 264 | |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 265 | if enc_ec256 { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 266 | conf.conf.define("MCUBOOT_ENCRYPT_EC256", None); |
| 267 | conf.conf.define("MCUBOOT_ENC_IMAGES", None); |
| 268 | conf.conf.define("MCUBOOT_USE_TINYCRYPT", None); |
| 269 | conf.conf.define("MCUBOOT_SWAP_SAVE_ENCTLV", None); |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 270 | |
| 271 | conf.file("../../boot/bootutil/src/encrypted.c"); |
| 272 | conf.file("csupport/keys.c"); |
| 273 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 274 | conf.conf.include("../../ext/mbedtls/include"); |
| 275 | conf.conf.include("../../ext/tinycrypt/lib/include"); |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 276 | |
| 277 | /* FIXME: fail with other signature schemes ? */ |
| 278 | |
| 279 | conf.file("../../ext/tinycrypt/lib/source/utils.c"); |
| 280 | conf.file("../../ext/tinycrypt/lib/source/sha256.c"); |
| 281 | conf.file("../../ext/tinycrypt/lib/source/ecc.c"); |
| 282 | conf.file("../../ext/tinycrypt/lib/source/ecc_dsa.c"); |
| 283 | conf.file("../../ext/tinycrypt/lib/source/ecc_platform_specific.c"); |
| 284 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 285 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 286 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 287 | |
| 288 | conf.file("../../ext/tinycrypt/lib/source/aes_encrypt.c"); |
| 289 | conf.file("../../ext/tinycrypt/lib/source/aes_decrypt.c"); |
| 290 | conf.file("../../ext/tinycrypt/lib/source/ctr_mode.c"); |
| 291 | conf.file("../../ext/tinycrypt/lib/source/hmac.c"); |
| 292 | conf.file("../../ext/tinycrypt/lib/source/ecc_dh.c"); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 293 | } else if enc_ec256_mbedtls || enc_aes256_ec256 { |
| 294 | if enc_aes256_ec256 { |
| 295 | conf.conf.define("MCUBOOT_AES_256", None); |
| 296 | } |
| 297 | conf.conf.define("MCUBOOT_ENCRYPT_EC256", None); |
| 298 | conf.conf.define("MCUBOOT_ENC_IMAGES", None); |
| 299 | conf.conf.define("MCUBOOT_USE_MBED_TLS", None); |
| 300 | conf.conf.define("MCUBOOT_SWAP_SAVE_ENCTLV", None); |
| 301 | |
| 302 | conf.conf.include("../../ext/mbedtls/include"); |
| 303 | |
| 304 | conf.file("../../boot/bootutil/src/encrypted.c"); |
| 305 | conf.file("../../ext/mbedtls/library/sha256.c"); |
| 306 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
| 307 | conf.file("../../ext/mbedtls/library/bignum.c"); |
INFINEON\DovhalA | 21babb7 | 2025-07-18 10:36:03 +0300 | [diff] [blame] | 308 | conf.file("../../ext/mbedtls/library/bignum_core.c"); |
| 309 | conf.file("../../ext/mbedtls/library/bignum_mod_raw.c"); |
| 310 | conf.file("../../ext/mbedtls/library/constant_time.c"); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 311 | conf.file("../../ext/mbedtls/library/ecdh.c"); |
| 312 | conf.file("../../ext/mbedtls/library/md.c"); |
| 313 | conf.file("../../ext/mbedtls/library/aes.c"); |
| 314 | conf.file("../../ext/mbedtls/library/ecp.c"); |
| 315 | conf.file("../../ext/mbedtls/library/ecp_curves.c"); |
| 316 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 317 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 318 | conf.file("csupport/keys.c"); |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 319 | } |
| 320 | |
Fabio Utzig | 3fa72ca | 2020-04-02 11:20:37 -0300 | [diff] [blame] | 321 | if enc_x25519 { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 322 | conf.conf.define("MCUBOOT_ENCRYPT_X25519", None); |
| 323 | conf.conf.define("MCUBOOT_ENC_IMAGES", None); |
| 324 | conf.conf.define("MCUBOOT_USE_TINYCRYPT", None); |
| 325 | conf.conf.define("MCUBOOT_SWAP_SAVE_ENCTLV", None); |
Fabio Utzig | 3fa72ca | 2020-04-02 11:20:37 -0300 | [diff] [blame] | 326 | |
| 327 | conf.file("../../boot/bootutil/src/encrypted.c"); |
| 328 | conf.file("csupport/keys.c"); |
| 329 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 330 | conf.conf.include("../../ext/mbedtls/include"); |
| 331 | conf.conf.include("../../ext/tinycrypt/lib/include"); |
| 332 | conf.conf.include("../../ext/tinycrypt-sha512/lib/include"); |
Fabio Utzig | 3fa72ca | 2020-04-02 11:20:37 -0300 | [diff] [blame] | 333 | |
| 334 | conf.file("../../ext/fiat/src/curve25519.c"); |
| 335 | |
| 336 | conf.file("../../ext/tinycrypt/lib/source/utils.c"); |
| 337 | conf.file("../../ext/tinycrypt/lib/source/sha256.c"); |
| 338 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 339 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 340 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
Fabio Utzig | 3fa72ca | 2020-04-02 11:20:37 -0300 | [diff] [blame] | 341 | |
| 342 | conf.file("../../ext/tinycrypt/lib/source/aes_encrypt.c"); |
| 343 | conf.file("../../ext/tinycrypt/lib/source/aes_decrypt.c"); |
| 344 | conf.file("../../ext/tinycrypt/lib/source/ctr_mode.c"); |
| 345 | conf.file("../../ext/tinycrypt/lib/source/hmac.c"); |
| 346 | } |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 347 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 348 | else if enc_aes256_x25519 { |
| 349 | conf.conf.define("MCUBOOT_AES_256", None); |
| 350 | conf.conf.define("MCUBOOT_ENCRYPT_X25519", None); |
| 351 | conf.conf.define("MCUBOOT_ENC_IMAGES", None); |
| 352 | conf.conf.define("MCUBOOT_USE_MBED_TLS", None); |
| 353 | conf.conf.define("MCUBOOT_SWAP_SAVE_ENCTLV", None); |
| 354 | |
| 355 | conf.file("../../boot/bootutil/src/encrypted.c"); |
| 356 | conf.file("csupport/keys.c"); |
| 357 | |
| 358 | conf.conf.include("../../ext/mbedtls/include"); |
| 359 | conf.file("../../ext/fiat/src/curve25519.c"); |
| 360 | conf.file("../../ext/mbedtls/library/asn1parse.c"); |
| 361 | conf.file("../../ext/mbedtls/library/platform.c"); |
| 362 | conf.file("../../ext/mbedtls/library/platform_util.c"); |
| 363 | conf.file("../../ext/mbedtls/library/aes.c"); |
| 364 | conf.file("../../ext/mbedtls/library/sha256.c"); |
| 365 | conf.file("../../ext/mbedtls/library/md.c"); |
| 366 | conf.file("../../ext/mbedtls/library/sha512.c"); |
| 367 | } |
| 368 | |
Fabio Utzig | 251ef1d | 2018-12-18 17:20:19 -0200 | [diff] [blame] | 369 | if sig_rsa && enc_kw { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 370 | conf.conf.define("MBEDTLS_CONFIG_FILE", Some("<config-rsa-kw.h>")); |
| 371 | } else if sig_rsa || sig_rsa3072 || enc_rsa || enc_aes256_rsa { |
| 372 | conf.conf.define("MBEDTLS_CONFIG_FILE", Some("<config-rsa.h>")); |
| 373 | } else if sig_ecdsa_mbedtls || enc_ec256_mbedtls || enc_aes256_ec256 { |
| 374 | conf.conf.define("MBEDTLS_CONFIG_FILE", Some("<config-ec.h>")); |
Fabio Utzig | 90f449e | 2019-10-24 07:43:53 -0300 | [diff] [blame] | 375 | } else if (sig_ecdsa || enc_ec256) && !enc_kw { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 376 | conf.conf.define("MBEDTLS_CONFIG_FILE", Some("<config-asn1.h>")); |
Fabio Utzig | 3fa72ca | 2020-04-02 11:20:37 -0300 | [diff] [blame] | 377 | } else if sig_ed25519 || enc_x25519 { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 378 | conf.conf.define("MBEDTLS_CONFIG_FILE", Some("<config-asn1.h>")); |
| 379 | } else if enc_kw || enc_aes256_kw { |
| 380 | conf.conf.define("MBEDTLS_CONFIG_FILE", Some("<config-kw.h>")); |
| 381 | } else if enc_aes256_x25519 { |
| 382 | conf.conf.define("MBEDTLS_CONFIG_FILE", Some("<config-ed25519.h>")); |
Fabio Utzig | 04fd63e | 2018-12-14 06:43:31 -0200 | [diff] [blame] | 383 | } |
| 384 | |
David Brown | 704ac6f | 2017-07-12 10:14:47 -0600 | [diff] [blame] | 385 | conf.file("../../boot/bootutil/src/image_validate.c"); |
Fabio Utzig | 3929743 | 2019-05-08 18:51:10 -0300 | [diff] [blame] | 386 | if sig_rsa || sig_rsa3072 { |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 387 | conf.file("../../boot/bootutil/src/image_rsa.c"); |
David Brown | 641af45 | 2021-02-19 12:16:48 -0700 | [diff] [blame] | 388 | } else if sig_ecdsa || sig_ecdsa_mbedtls { |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 389 | conf.conf.include("../../ext/mbedtls/include"); |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 390 | conf.file("../../boot/bootutil/src/image_ec256.c"); |
Fabio Utzig | 9771028 | 2019-05-24 17:44:49 -0300 | [diff] [blame] | 391 | } else if sig_ed25519 { |
| 392 | conf.file("../../boot/bootutil/src/image_ed25519.c"); |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 393 | } |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 394 | conf.file("../../boot/bootutil/src/loader.c"); |
Fabio Utzig | 031eb7d | 2019-11-28 10:13:14 -0300 | [diff] [blame] | 395 | conf.file("../../boot/bootutil/src/swap_misc.c"); |
| 396 | conf.file("../../boot/bootutil/src/swap_scratch.c"); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 397 | conf.file("../../boot/bootutil/src/swap_move.c"); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 398 | conf.file("../../boot/bootutil/src/caps.c"); |
| 399 | conf.file("../../boot/bootutil/src/bootutil_misc.c"); |
Andrzej Puzdrowski | f573b39 | 2020-11-10 14:35:15 +0100 | [diff] [blame] | 400 | conf.file("../../boot/bootutil/src/bootutil_public.c"); |
Fabio Utzig | 61fd888 | 2019-09-14 20:00:20 -0300 | [diff] [blame] | 401 | conf.file("../../boot/bootutil/src/tlv.c"); |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 402 | conf.file("../../boot/bootutil/src/fault_injection_hardening.c"); |
David Brown | d2b1853 | 2017-07-12 09:51:31 -0600 | [diff] [blame] | 403 | conf.file("csupport/run.c"); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 404 | conf.conf.include("../../boot/bootutil/include"); |
Roman Okhrimenko | dc0ca08 | 2023-06-21 20:49:51 +0300 | [diff] [blame] | 405 | conf.conf.include("../../boot/boot/bootutil/include/bootutil/fault_injection_hardening.h"); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 406 | conf.conf.include("csupport"); |
| 407 | conf.conf.include("../../boot/zephyr/include"); |
| 408 | conf.conf.debug(true); |
| 409 | conf.conf.flag("-Wall"); |
INFINEON\DovhalA | 21babb7 | 2025-07-18 10:36:03 +0300 | [diff] [blame] | 410 | |
Fabio Utzig | 0bccf9d | 2017-12-07 12:13:57 -0200 | [diff] [blame] | 411 | // FIXME: travis-ci still uses gcc 4.8.4 which defaults to std=gnu90. |
| 412 | // It has incomplete std=c11 and std=c99 support but std=c99 was checked |
| 413 | // to build correctly so leaving it here to updated in the future... |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 414 | conf.conf.flag("-std=c99"); |
Fabio Utzig | 0bccf9d | 2017-12-07 12:13:57 -0200 | [diff] [blame] | 415 | |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 416 | conf.conf.compile("libbootutil.a"); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 417 | |
| 418 | walk_dir("../../boot").unwrap(); |
Fabio Utzig | c786540 | 2017-12-05 08:50:52 -0200 | [diff] [blame] | 419 | walk_dir("../../ext/tinycrypt/lib/source").unwrap(); |
David Brown | b748f6f | 2019-10-11 10:07:31 -0600 | [diff] [blame] | 420 | walk_dir("../../ext/mbedtls-asn1").unwrap(); |
David Brown | d2b1853 | 2017-07-12 09:51:31 -0600 | [diff] [blame] | 421 | walk_dir("csupport").unwrap(); |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 422 | walk_dir("../../ext/mbedtls/include").unwrap(); |
| 423 | walk_dir("../../ext/mbedtls/library").unwrap(); |
David Brown | 6390277 | 2017-07-12 09:47:49 -0600 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | // Output the names of all files within a directory so that Cargo knows when to rebuild. |
| 427 | fn walk_dir<P: AsRef<Path>>(path: P) -> io::Result<()> { |
| 428 | for ent in fs::read_dir(path.as_ref())? { |
| 429 | let ent = ent?; |
| 430 | let p = ent.path(); |
| 431 | if p.is_dir() { |
| 432 | walk_dir(p)?; |
| 433 | } else { |
| 434 | // Note that non-utf8 names will fail. |
| 435 | let name = p.to_str().unwrap(); |
| 436 | if name.ends_with(".c") || name.ends_with(".h") { |
| 437 | println!("cargo:rerun-if-changed={}", name); |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | Ok(()) |
| 443 | } |
Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame] | 444 | |
| 445 | /// Wrap the cc::Build type so that we can make sure that files are only added a single time. |
| 446 | /// Other methods can be passed through as needed. |
| 447 | struct CachedBuild { |
| 448 | conf: cc::Build, |
| 449 | seen: BTreeSet<PathBuf>, |
| 450 | } |
| 451 | |
| 452 | impl CachedBuild { |
| 453 | fn new() -> CachedBuild { |
| 454 | CachedBuild { |
| 455 | conf: cc::Build::new(), |
| 456 | seen: BTreeSet::new(), |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | /// Works like `file` in the Build, but doesn't add a file if the same path has already been |
| 461 | /// given. |
| 462 | fn file<P: AsRef<Path>>(&mut self, p: P) -> &mut CachedBuild { |
| 463 | let p = p.as_ref(); |
| 464 | if !self.seen.contains(p) { |
| 465 | self.conf.file(p); |
| 466 | self.seen.insert(p.to_owned()); |
| 467 | } |
| 468 | self |
| 469 | } |
| 470 | } |