Skip to content

Commit 357b895

Browse files
Rust crate: only set link-search and link-arg for local repo build
1 parent a3cc721 commit 357b895

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

wrapper/rust/wolfssl-wolfcrypt/build.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use regex::Regex;
44
use std::env;
55
use std::fs;
66
use std::io::{self, Read, Result};
7-
use std::path::PathBuf;
7+
use std::path::{Path,PathBuf};
88

99
/// Perform crate build.
1010
fn main() {
@@ -69,12 +69,19 @@ fn generate_bindings() -> Result<()> {
6969
/// Returns `Ok(())` if successful, or an error if any step fails.
7070
fn setup_wolfssl_link() -> Result<()> {
7171
println!("cargo:rustc-link-lib=wolfssl");
72-
println!("cargo:rustc-link-search={}", wolfssl_lib_dir()?);
73-
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", wolfssl_lib_dir()?);
7472

7573
// TODO: do we need this if only a static library is built?
7674
// println!("cargo:rustc-link-lib=static=wolfssl");
7775

76+
let build_in_repo = Path::new(&wolfssl_lib_dir()?).exists();
77+
if build_in_repo {
78+
// When the crate is built in the wolfssl repository, link with the
79+
// locally build wolfssl library to allow testing any local changes
80+
// and running unit tests even if library is not installed.
81+
println!("cargo:rustc-link-search={}", wolfssl_lib_dir()?);
82+
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", wolfssl_lib_dir()?);
83+
}
84+
7885
Ok(())
7986
}
8087

0 commit comments

Comments
 (0)