|
16 | 16 | //! The builder discovers wolfSSL sources in order: |
17 | 17 | //! 1. `source_dir()` programmatic override |
18 | 18 | //! 2. `WOLFSSL_SRC` environment variable |
19 | | -//! 3. `pkg-config` (looks for a `wolfssl` package whose prefix contains source files) |
| 19 | +//! 3. Bundled submodule at `wolfssl-src/wolfssl/` (present after `git submodule update --init`) |
| 20 | +//! 4. `pkg-config` (looks for a `wolfssl` package whose prefix contains source files) |
20 | 21 |
|
21 | 22 | use std::collections::HashSet; |
22 | 23 | use std::env; |
@@ -52,7 +53,7 @@ impl Build { |
52 | 53 | } |
53 | 54 |
|
54 | 55 | /// Set the path to the wolfSSL source tree. |
55 | | - /// If not set, defaults to `WOLFSSL_SRC` env var, then `pkg-config`. |
| 56 | + /// If not set, defaults to `WOLFSSL_SRC` env var, then the bundled submodule, then `pkg-config`. |
56 | 57 | pub fn source_dir(&mut self, dir: PathBuf) -> &mut Self { |
57 | 58 | self.source_dir = Some(dir); |
58 | 59 | self |
@@ -227,23 +228,31 @@ impl Build { |
227 | 228 |
|
228 | 229 | // 2. WOLFSSL_SRC env var |
229 | 230 | if let Ok(dir) = env::var("WOLFSSL_SRC") { |
230 | | - let path = PathBuf::from(&dir); |
231 | | - if !path.exists() { |
232 | | - panic!("WOLFSSL_SRC={dir} does not exist"); |
| 231 | + if !dir.is_empty() { |
| 232 | + let path = PathBuf::from(&dir); |
| 233 | + if !path.exists() { |
| 234 | + panic!("WOLFSSL_SRC={dir} does not exist"); |
| 235 | + } |
| 236 | + return path; |
233 | 237 | } |
234 | | - return path; |
235 | 238 | } |
236 | 239 |
|
237 | | - // 3. pkg-config |
| 240 | + // 3. Bundled submodule (wolfssl-src/wolfssl/ inside this crate) |
| 241 | + let bundled = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("wolfssl"); |
| 242 | + if bundled.join("wolfcrypt/src").exists() { |
| 243 | + return bundled; |
| 244 | + } |
| 245 | + |
| 246 | + // 4. pkg-config |
238 | 247 | if let Some(dir) = Self::find_via_pkg_config() { |
239 | 248 | return dir; |
240 | 249 | } |
241 | 250 |
|
242 | 251 | panic!( |
243 | 252 | "wolfSSL source not found. Either:\n \ |
| 253 | + - Run: git submodule update --init\n \ |
244 | 254 | - Set WOLFSSL_SRC to the path of your wolfssl checkout\n \ |
245 | | - - Install wolfssl-dev so that pkg-config can find it\n \ |
246 | | - - Clone it: git clone https://github.com/wolfSSL/wolfssl.git" |
| 255 | + - Install wolfssl-dev so that pkg-config can find it" |
247 | 256 | ); |
248 | 257 | } |
249 | 258 |
|
|
0 commit comments