Skip to content

Commit

Permalink
Try to fix linker paths issue with deps using native deps (#1652)
Browse files Browse the repository at this point in the history
* Try to fix linker paths issue with deps using native deps

* Just try something

* Try to fix paths

* Update changelog
  • Loading branch information
xd009642 authored Nov 28, 2024
1 parent 619b8e2 commit 189ca9c
Show file tree
Hide file tree
Showing 10 changed files with 9,186 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
From 2019 onwards, all notable changes to tarpaulin will be documented in this
file.

## [Unreleased]
### Changed
- For `LD_LIBRARY_PATH` get all link paths from build script outputs
- Use `PATH` on windows and `DYLIB_LIBRARY_PATH` for mac instead of `LD_LIBRARY_PATH`

## [0.31.3] 2024-10-10
### Added
- The `CARGO_TARPAULIN_CONFIG_FILE` environment variable may be used to set the
Expand Down
26 changes: 22 additions & 4 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ use walkdir::{DirEntry, WalkDir};

const BUILD_PROFRAW: &str = "build_rs_cov.profraw";

cfg_if::cfg_if! {
if #[cfg(target_os = "windows")] {
pub const LD_PATH_VAR: &'static str ="PATH";
} else if #[cfg(any(target_os = "macos", target_os = "ios"))] {
pub const LD_PATH_VAR: &'static str = "DYLD_LIBRARY_PATH";
} else {
pub const LD_PATH_VAR: &'static str = "LD_LIBRARY_PATH";
}
}

#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
enum Channel {
Stable,
Expand Down Expand Up @@ -118,14 +128,22 @@ impl TestBinary {
/// Convert linker paths to an LD_LIBRARY_PATH.
/// TODO this won't work for windows when it's implemented
pub fn ld_library_path(&self) -> String {
cfg_if::cfg_if! {
if #[cfg(windows)] {
const PATH_SEP: &str = ";";
} else {
const PATH_SEP: &str = ":";
}
}

let mut new_vals = self
.linker_paths
.iter()
.map(|x| x.display().to_string())
.collect::<Vec<String>>()
.join(":");
if let Ok(ld) = env::var("LD_LIBRARY_PATH") {
new_vals.push(':');
.join(PATH_SEP);
if let Ok(ld) = env::var(LD_PATH_VAR) {
new_vals.push_str(PATH_SEP);
new_vals.push_str(ld.as_str());
}
new_vals
Expand Down Expand Up @@ -293,7 +311,7 @@ fn run_cargo(
_ => {}
},
Ok(Message::BuildScriptExecuted(bs))
if !(bs.linked_libs.is_empty() || bs.linked_paths.is_empty()) =>
if !(bs.linked_libs.is_empty() && bs.linked_paths.is_empty()) =>
{
let temp_paths = bs.linked_paths.iter().filter_map(|x| {
if x.as_std_path().exists() {
Expand Down
12 changes: 6 additions & 6 deletions src/process_handling/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cargo::rust_flags;
use crate::cargo::{rust_flags, LD_PATH_VAR};
use crate::config::Color;
use crate::generate_tracemap;
use crate::path_utils::get_profile_walker;
Expand Down Expand Up @@ -181,7 +181,7 @@ fn get_env_vars(test: &TestBinary, config: &Config) -> Vec<(String, String)> {

for (key, value) in env::vars() {
// Avoid adding it twice
if key == "LD_LIBRARY_PATH" && test.has_linker_paths() || key == "RUSTFLAGS" {
if key == LD_PATH_VAR && test.has_linker_paths() || key == "RUSTFLAGS" {
continue;
}
envars.push((key.to_string(), value.to_string()));
Expand All @@ -202,7 +202,7 @@ fn get_env_vars(test: &TestBinary, config: &Config) -> Vec<(String, String)> {
envars.push(("CARGO_MANIFEST_DIR".to_string(), s.display().to_string()));
}
if test.has_linker_paths() {
envars.push(("LD_LIBRARY_PATH".to_string(), test.ld_library_path()));
envars.push((LD_PATH_VAR.to_string(), test.ld_library_path()));
}
envars.push(("RUSTFLAGS".to_string(), rust_flags(config)));

Expand Down Expand Up @@ -299,10 +299,10 @@ mod tests {

if let Some(ld) = vars
.iter()
.find(|(key, _)| key == "LD_LIBRARY_PATH")
.find(|(key, _)| key == LD_PATH_VAR)
.map(|(_, val)| val)
{
let sys = env::var("LD_LIBRARY_PATH").unwrap();
let sys = env::var(LD_PATH_VAR).unwrap();
assert_eq!(ld, &sys);
}

Expand All @@ -313,7 +313,7 @@ mod tests {
let vars = get_env_vars(&binary, &default_config);
let res = vars
.iter()
.find(|(key, _)| key == "LD_LIBRARY_PATH")
.find(|(key, _)| key == LD_PATH_VAR)
.map(|(_, val)| val);

assert!(res.is_some());
Expand Down
Loading

0 comments on commit 189ca9c

Please sign in to comment.