Skip to content

Commit e9f45e1

Browse files
committed
rewrite link-cfg to rmake
1 parent 4db3d12 commit e9f45e1

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ run-make/libs-through-symlinks/Makefile
2525
run-make/libtest-json/Makefile
2626
run-make/libtest-junit/Makefile
2727
run-make/libtest-thread-limit/Makefile
28-
run-make/link-cfg/Makefile
2928
run-make/long-linker-command-lines-cmd-exe/Makefile
3029
run-make/long-linker-command-lines/Makefile
3130
run-make/macos-deployment-target/Makefile

tests/run-make/link-cfg/Makefile

-23
This file was deleted.

tests/run-make/link-cfg/rmake.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// The `#[link(cfg(..))]` annotation means that the `#[link]`
2+
// directive is only active in a compilation unit if that `cfg` value is satisfied.
3+
// For example, when compiling an rlib, these directives are just encoded and
4+
// ignored for dylibs, and all staticlibs are continued to be put into the rlib as
5+
// usual. When placing that rlib into a staticlib, executable, or dylib, however,
6+
// the `cfg` is evaluated *as if it were defined in the final artifact* and the
7+
// library is decided to be linked or not.
8+
// This test exercises this new feature by testing it with no dependencies, then
9+
// with only dynamic libraries, then with both a staticlib and dylibs. Compilation
10+
// and execution should be successful.
11+
// See https://github.com/rust-lang/rust/pull/37545
12+
13+
//@ ignore-cross-compile
14+
// Reason: the compiled binary is executed
15+
16+
use run_make_support::{bare_rustc, build_native_dynamic_lib, build_native_static_lib, run, rustc};
17+
18+
fn main() {
19+
build_native_dynamic_lib("return1");
20+
build_native_dynamic_lib("return2");
21+
build_native_static_lib("return3");
22+
bare_rustc()
23+
.print("cfg")
24+
.target("x86_64-unknown-linux-musl")
25+
.run()
26+
.assert_stdout_contains("crt-static");
27+
rustc().input("no-deps.rs").cfg("foo").run();
28+
run("no-deps");
29+
rustc().input("no-deps.rs").cfg("bar").run();
30+
run("no-deps");
31+
32+
rustc().input("dep.rs").run();
33+
rustc().input("with-deps.rs").cfg("foo").run();
34+
run("with-deps");
35+
rustc().input("with-deps.rs").cfg("bar").run();
36+
run("with-deps");
37+
38+
rustc().input("dep-with-staticlib.rs").run();
39+
rustc().input("with-staticlib-deps.rs").cfg("foo").run();
40+
run("with-staticlib-deps");
41+
rustc().input("with-staticlib-deps.rs").cfg("bar").run();
42+
run("with-staticlib-deps");
43+
}

0 commit comments

Comments
 (0)