summaryrefslogtreecommitdiffstats
path: root/tests/run-make/link-cfg
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /tests/run-make/link-cfg
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/run-make/link-cfg')
-rw-r--r--tests/run-make/link-cfg/Makefile23
-rw-r--r--tests/run-make/link-cfg/dep-with-staticlib.rs8
-rw-r--r--tests/run-make/link-cfg/dep.rs8
-rw-r--r--tests/run-make/link-cfg/no-deps.rs20
-rw-r--r--tests/run-make/link-cfg/return1.c6
-rw-r--r--tests/run-make/link-cfg/return2.c6
-rw-r--r--tests/run-make/link-cfg/return3.c6
-rw-r--r--tests/run-make/link-cfg/with-deps.rs14
-rw-r--r--tests/run-make/link-cfg/with-staticlib-deps.rs14
9 files changed, 105 insertions, 0 deletions
diff --git a/tests/run-make/link-cfg/Makefile b/tests/run-make/link-cfg/Makefile
new file mode 100644
index 000000000..a40997011
--- /dev/null
+++ b/tests/run-make/link-cfg/Makefile
@@ -0,0 +1,23 @@
+# ignore-cross-compile
+include ../tools.mk
+
+all: $(call DYLIB,return1) $(call DYLIB,return2) $(call NATIVE_STATICLIB,return3)
+ ls $(TMPDIR)
+ $(BARE_RUSTC) --print cfg --target x86_64-unknown-linux-musl | $(CGREP) crt-static
+
+ $(RUSTC) no-deps.rs --cfg foo
+ $(call RUN,no-deps)
+ $(RUSTC) no-deps.rs --cfg bar
+ $(call RUN,no-deps)
+
+ $(RUSTC) dep.rs
+ $(RUSTC) with-deps.rs --cfg foo
+ $(call RUN,with-deps)
+ $(RUSTC) with-deps.rs --cfg bar
+ $(call RUN,with-deps)
+
+ $(RUSTC) dep-with-staticlib.rs
+ $(RUSTC) with-staticlib-deps.rs --cfg foo
+ $(call RUN,with-staticlib-deps)
+ $(RUSTC) with-staticlib-deps.rs --cfg bar
+ $(call RUN,with-staticlib-deps)
diff --git a/tests/run-make/link-cfg/dep-with-staticlib.rs b/tests/run-make/link-cfg/dep-with-staticlib.rs
new file mode 100644
index 000000000..5ad66475d
--- /dev/null
+++ b/tests/run-make/link-cfg/dep-with-staticlib.rs
@@ -0,0 +1,8 @@
+#![feature(link_cfg)]
+#![crate_type = "rlib"]
+
+#[link(name = "return1", cfg(foo))]
+#[link(name = "return3", kind = "static", cfg(bar))]
+extern "C" {
+ pub fn my_function() -> i32;
+}
diff --git a/tests/run-make/link-cfg/dep.rs b/tests/run-make/link-cfg/dep.rs
new file mode 100644
index 000000000..40de77f05
--- /dev/null
+++ b/tests/run-make/link-cfg/dep.rs
@@ -0,0 +1,8 @@
+#![feature(link_cfg)]
+#![crate_type = "rlib"]
+
+#[link(name = "return1", cfg(foo))]
+#[link(name = "return2", cfg(bar))]
+extern "C" {
+ pub fn my_function() -> i32;
+}
diff --git a/tests/run-make/link-cfg/no-deps.rs b/tests/run-make/link-cfg/no-deps.rs
new file mode 100644
index 000000000..ba5a8711a
--- /dev/null
+++ b/tests/run-make/link-cfg/no-deps.rs
@@ -0,0 +1,20 @@
+#![feature(link_cfg)]
+
+#[link(name = "return1", cfg(foo))]
+#[link(name = "return2", cfg(bar))]
+extern "C" {
+ fn my_function() -> i32;
+}
+
+fn main() {
+ unsafe {
+ let v = my_function();
+ if cfg!(foo) {
+ assert_eq!(v, 1);
+ } else if cfg!(bar) {
+ assert_eq!(v, 2);
+ } else {
+ panic!("unknown");
+ }
+ }
+}
diff --git a/tests/run-make/link-cfg/return1.c b/tests/run-make/link-cfg/return1.c
new file mode 100644
index 000000000..41c2809ad
--- /dev/null
+++ b/tests/run-make/link-cfg/return1.c
@@ -0,0 +1,6 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int my_function() {
+ return 1;
+}
diff --git a/tests/run-make/link-cfg/return2.c b/tests/run-make/link-cfg/return2.c
new file mode 100644
index 000000000..622aeaa29
--- /dev/null
+++ b/tests/run-make/link-cfg/return2.c
@@ -0,0 +1,6 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int my_function() {
+ return 2;
+}
diff --git a/tests/run-make/link-cfg/return3.c b/tests/run-make/link-cfg/return3.c
new file mode 100644
index 000000000..f29dc60d5
--- /dev/null
+++ b/tests/run-make/link-cfg/return3.c
@@ -0,0 +1,6 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int my_function() {
+ return 3;
+}
diff --git a/tests/run-make/link-cfg/with-deps.rs b/tests/run-make/link-cfg/with-deps.rs
new file mode 100644
index 000000000..48b782815
--- /dev/null
+++ b/tests/run-make/link-cfg/with-deps.rs
@@ -0,0 +1,14 @@
+extern crate dep;
+
+fn main() {
+ unsafe {
+ let v = dep::my_function();
+ if cfg!(foo) {
+ assert_eq!(v, 1);
+ } else if cfg!(bar) {
+ assert_eq!(v, 2);
+ } else {
+ panic!("unknown");
+ }
+ }
+}
diff --git a/tests/run-make/link-cfg/with-staticlib-deps.rs b/tests/run-make/link-cfg/with-staticlib-deps.rs
new file mode 100644
index 000000000..23e5926a7
--- /dev/null
+++ b/tests/run-make/link-cfg/with-staticlib-deps.rs
@@ -0,0 +1,14 @@
+extern crate dep_with_staticlib;
+
+fn main() {
+ unsafe {
+ let v = dep_with_staticlib::my_function();
+ if cfg!(foo) {
+ assert_eq!(v, 1);
+ } else if cfg!(bar) {
+ assert_eq!(v, 3);
+ } else {
+ panic!("unknown");
+ }
+ }
+}