summaryrefslogtreecommitdiffstats
path: root/tests/run-make/raw-dylib-c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run-make/raw-dylib-c')
-rw-r--r--tests/run-make/raw-dylib-c/Makefile28
-rw-r--r--tests/run-make/raw-dylib-c/driver.rs5
-rw-r--r--tests/run-make/raw-dylib-c/extern_1.c28
-rw-r--r--tests/run-make/raw-dylib-c/extern_2.c6
-rw-r--r--tests/run-make/raw-dylib-c/lib.rs37
-rw-r--r--tests/run-make/raw-dylib-c/output.txt6
6 files changed, 110 insertions, 0 deletions
diff --git a/tests/run-make/raw-dylib-c/Makefile b/tests/run-make/raw-dylib-c/Makefile
new file mode 100644
index 000000000..f47ab24f4
--- /dev/null
+++ b/tests/run-make/raw-dylib-c/Makefile
@@ -0,0 +1,28 @@
+# Test the behavior of #[link(.., kind = "raw-dylib")] on windows-msvc
+
+# only-windows
+
+include ../../run-make-fulldeps/tools.mk
+
+all:
+ $(RUSTC) --crate-type lib --crate-name raw_dylib_test lib.rs
+ $(RUSTC) --crate-type bin driver.rs -L "$(TMPDIR)"
+ $(RUSTC) --crate-type bin --crate-name raw_dylib_test_bin lib.rs
+ $(call COMPILE_OBJ,"$(TMPDIR)"/extern_1.obj,extern_1.c)
+ $(call COMPILE_OBJ,"$(TMPDIR)"/extern_2.obj,extern_2.c)
+ifdef IS_MSVC
+ $(CC) "$(TMPDIR)"/extern_1.obj -link -dll -out:"$(TMPDIR)"/extern_1.dll -noimplib
+ $(CC) "$(TMPDIR)"/extern_2.obj -link -dll -out:"$(TMPDIR)"/extern_2.dll -noimplib
+else
+ $(CC) "$(TMPDIR)"/extern_1.obj -shared -o "$(TMPDIR)"/extern_1.dll
+ $(CC) "$(TMPDIR)"/extern_2.obj -shared -o "$(TMPDIR)"/extern_2.dll
+endif
+ "$(TMPDIR)"/driver > "$(TMPDIR)"/output.txt
+ "$(TMPDIR)"/raw_dylib_test_bin > "$(TMPDIR)"/output_bin.txt
+
+ifdef RUSTC_BLESS_TEST
+ cp "$(TMPDIR)"/output.txt output.txt
+else
+ $(DIFF) output.txt "$(TMPDIR)"/output.txt
+ $(DIFF) output.txt "$(TMPDIR)"/output_bin.txt
+endif
diff --git a/tests/run-make/raw-dylib-c/driver.rs b/tests/run-make/raw-dylib-c/driver.rs
new file mode 100644
index 000000000..4059ede11
--- /dev/null
+++ b/tests/run-make/raw-dylib-c/driver.rs
@@ -0,0 +1,5 @@
+extern crate raw_dylib_test;
+
+fn main() {
+ raw_dylib_test::library_function();
+}
diff --git a/tests/run-make/raw-dylib-c/extern_1.c b/tests/run-make/raw-dylib-c/extern_1.c
new file mode 100644
index 000000000..5d695547d
--- /dev/null
+++ b/tests/run-make/raw-dylib-c/extern_1.c
@@ -0,0 +1,28 @@
+#include <stdio.h>
+
+__declspec(dllexport) int extern_variable = 0;
+
+__declspec(dllexport) void extern_fn_1() {
+ printf("extern_fn_1\n");
+ fflush(stdout);
+}
+
+__declspec(dllexport) void extern_fn_2() {
+ printf("extern_fn_2; didn't get the rename\n");
+ fflush(stdout);
+}
+
+__declspec(dllexport) void print_extern_variable() {
+ printf("extern_variable value: %d\n", extern_variable);
+ fflush(stdout);
+}
+
+__declspec(dllexport) void extern_fn_with_long_name() {
+ printf("extern_fn_with_long_name; got the rename\n");
+ fflush(stdout);
+}
+
+__declspec(dllexport) void extern_fn_4() {
+ printf("extern_fn_4\n");
+ fflush(stdout);
+}
diff --git a/tests/run-make/raw-dylib-c/extern_2.c b/tests/run-make/raw-dylib-c/extern_2.c
new file mode 100644
index 000000000..ae87fc3f8
--- /dev/null
+++ b/tests/run-make/raw-dylib-c/extern_2.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+__declspec(dllexport) void extern_fn_3() {
+ printf("extern_fn_3\n");
+ fflush(stdout);
+}
diff --git a/tests/run-make/raw-dylib-c/lib.rs b/tests/run-make/raw-dylib-c/lib.rs
new file mode 100644
index 000000000..5fb120403
--- /dev/null
+++ b/tests/run-make/raw-dylib-c/lib.rs
@@ -0,0 +1,37 @@
+#![feature(raw_dylib)]
+
+#[link(name = "extern_1.dll", kind = "raw-dylib", modifiers = "+verbatim")]
+extern {
+ fn extern_fn_1();
+}
+
+#[link(name = "extern_2", kind = "raw-dylib")]
+extern {
+ fn extern_fn_3();
+}
+
+pub fn library_function() {
+ #[link(name = "extern_1", kind = "raw-dylib")]
+ extern {
+ fn extern_fn_2();
+ fn print_extern_variable();
+ static mut extern_variable: i32;
+ #[link_name = "extern_fn_4"]
+ fn extern_fn_4_renamed();
+ }
+
+ unsafe {
+ extern_fn_1();
+ extern_fn_2();
+ extern_fn_3();
+ extern_fn_4_renamed();
+ extern_variable = 42;
+ print_extern_variable();
+ extern_variable = -42;
+ print_extern_variable();
+ }
+}
+
+fn main() {
+ library_function();
+}
diff --git a/tests/run-make/raw-dylib-c/output.txt b/tests/run-make/raw-dylib-c/output.txt
new file mode 100644
index 000000000..cc970cef7
--- /dev/null
+++ b/tests/run-make/raw-dylib-c/output.txt
@@ -0,0 +1,6 @@
+extern_fn_1
+extern_fn_2; didn't get the rename
+extern_fn_3
+extern_fn_4
+extern_variable value: 42
+extern_variable value: -42