Skip to content

Commit

Permalink
Add the lib dir to the linker paths to try and fix procmacro crates (#…
Browse files Browse the repository at this point in the history
…1680)

* Add the lib dir to the linker paths to try and fix procmacro crates

* Fix test

* Update changelog prep for release
  • Loading branch information
xd009642 authored Jan 16, 2025
1 parent 7c454c4 commit fdc9c09
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
From 2019 onwards, all notable changes to tarpaulin will be documented in this
file.

## [Unreleased]
## [0.31.5] 2025-01-16
### Changed
- ASLR detection was slightly broken - although it wouldn't break anything unless setting was broken as well.
- Detect the libdir path by rustc and link to it to enable proc-macro test binaries to run without error #1642

## [0.31.4] 2024-12-31
### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-tarpaulin"
version = "0.31.4"
version = "0.31.5"
authors = ["Daniel McKenna <[email protected]>"]
description = "Cargo-Tarpaulin is a tool to determine code coverage achieved via tests"
repository = "https://github.com/xd009642/tarpaulin"
Expand Down
39 changes: 36 additions & 3 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ fn run_cargo(
trace!("Running command {:?}", cmd);
let mut child = cmd.spawn().map_err(|e| RunError::Cargo(e.to_string()))?;
let update_from = result.test_binaries.len();
let mut paths = vec![];
let mut paths = match get_libdir(ty) {
Some(path) => vec![path],
None => vec![],
};

if ty != Some(RunType::Doctests) {
let mut package_ids = vec![None; result.test_binaries.len()];
Expand Down Expand Up @@ -514,7 +517,7 @@ fn find_str_in_file(file: &Path, value: &str) -> io::Result<Vec<usize>> {
Ok(lines)
}

fn create_command(manifest_path: &str, config: &Config, ty: Option<RunType>) -> Command {
fn start_cargo_command(ty: Option<RunType>) -> Command {
let mut test_cmd = Command::new("cargo");
let bootstrap = matches!(env::var("RUSTC_BOOTSTRAP").as_deref(), Ok("1"));
let override_toolchain = if cfg!(windows) {
Expand All @@ -541,13 +544,37 @@ fn create_command(manifest_path: &str, config: &Config, ty: Option<RunType>) ->
test_cmd.args(["+nightly"]);
}
}
test_cmd.args(["test"]);
} else {
if override_toolchain {
if let Ok(toolchain) = env::var("RUSTUP_TOOLCHAIN") {
test_cmd.arg(format!("+{toolchain}"));
}
}
}
test_cmd
}

fn get_libdir(ty: Option<RunType>) -> Option<PathBuf> {
let mut test_cmd = start_cargo_command(ty);
test_cmd.env("RUSTC_BOOTSTRAP", "1");
test_cmd.args(["rustc", "-Z", "unstable-options", "--print=target-libdir"]);

let output = match test_cmd.output() {
Ok(output) => String::from_utf8_lossy(&output.stdout).trim().to_string(),
Err(e) => {
debug!("Unable to run cargo rustc command: {}", e);
warn!("Unable to get target libdir proc macro crates in the workspace may not work. Consider adding `--exclude` to remove them from compilation");
return None;
}
};
Some(PathBuf::from(output))
}

fn create_command(manifest_path: &str, config: &Config, ty: Option<RunType>) -> Command {
let mut test_cmd = start_cargo_command(ty);
if ty == Some(RunType::Doctests) {
test_cmd.args(["test"]);
} else {
if config.command == Mode::Test {
test_cmd.args(["test", "--no-run"]);
} else {
Expand Down Expand Up @@ -913,6 +940,12 @@ mod tests {
use super::*;
use toml::toml;

#[test]
fn can_get_libdir() {
let path = get_libdir(Some(RunType::Tests)).unwrap();
assert!(path.exists(), "{} doesn't exist", path.display());
}

#[test]
#[cfg(not(windows))]
fn check_dead_code_flags() {
Expand Down

0 comments on commit fdc9c09

Please sign in to comment.