Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run-make: enable msvc for link-dedup #128638

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions tests/run-make/link-dedup/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,37 @@
// Without the --cfg flag, there should be a single -ltesta, no more, no less.
// See https://github.com/rust-lang/rust/pull/84794

//@ ignore-msvc
use std::fmt::Write;

use run_make_support::rustc;
use run_make_support::{is_msvc, rustc};

fn main() {
rustc().input("depa.rs").run();
rustc().input("depb.rs").run();
rustc().input("depc.rs").run();

let output = rustc().input("empty.rs").cfg("bar").run_fail();
output.assert_stderr_contains(r#""-ltesta" "-ltestb" "-ltesta""#);
let output = rustc().input("empty.rs").run_fail();
output.assert_stderr_contains(r#""-ltesta""#);
let output = rustc().input("empty.rs").run_fail();
output.assert_stderr_not_contains(r#""-ltestb""#);
output.assert_stderr_contains(needle_from_libs(&["testa", "testb", "testa"]));

let output = rustc().input("empty.rs").run_fail();
output.assert_stderr_not_contains(r#""-ltesta" "-ltesta" "-ltesta""#);
output.assert_stderr_contains(needle_from_libs(&["testa"]));
output.assert_stderr_not_contains(needle_from_libs(&["testb"]));
output.assert_stderr_not_contains(needle_from_libs(&["testa", "testa", "testa"]));
// Adjacent identical native libraries are no longer deduplicated if
// they come from different crates (https://github.com/rust-lang/rust/pull/103311)
// so the following will fail:
//output.assert_stderr_not_contains(needle_from_libs(&["testa", "testa"]));
jieyouxu marked this conversation as resolved.
Show resolved Hide resolved
}

fn needle_from_libs(libs: &[&str]) -> String {
let mut needle = String::new();
for lib in libs {
if is_msvc() {
let _ = needle.write_fmt(format_args!(r#""{lib}.lib" "#));
} else {
let _ = needle.write_fmt(format_args!(r#""-l{lib}" "#));
}
}
needle.pop(); // remove trailing space
needle
}
Loading