about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJohannes Nixdorf <mixi@exherbo.org>2018-05-02 10:26:00 +0200
committerJohannes Nixdorf <mixi@exherbo.org>2018-05-31 12:01:50 +0200
commit81687c4a7f625f03fe3b15e6cb4647e9fbaa39bd (patch)
tree03a355276e3cd9bdaf822cafa1f92f800cdb80ca /src
parent665d6673d53ae83b9ce1a0cabb63c9cc2b720efe (diff)
downloadrust-81687c4a7f625f03fe3b15e6cb4647e9fbaa39bd.tar.gz
rust-81687c4a7f625f03fe3b15e6cb4647e9fbaa39bd.zip
Add a test for issue 36710.
This still expectedly fails for musl targets with +crt-static.
Diffstat (limited to 'src')
-rw-r--r--src/test/run-make-fulldeps/issue-36710/Makefile21
-rw-r--r--src/test/run-make-fulldeps/issue-36710/foo.cpp25
-rw-r--r--src/test/run-make-fulldeps/issue-36710/foo.rs18
-rw-r--r--src/test/run-make-fulldeps/tools.mk2
4 files changed, 66 insertions, 0 deletions
diff --git a/src/test/run-make-fulldeps/issue-36710/Makefile b/src/test/run-make-fulldeps/issue-36710/Makefile
new file mode 100644
index 00000000000..928bdf532df
--- /dev/null
+++ b/src/test/run-make-fulldeps/issue-36710/Makefile
@@ -0,0 +1,21 @@
+-include ../tools.mk
+
+ifeq (musl,$(findstring musl,$(TARGET)))
+all: skip
+else
+all: test
+endif
+
+test: foo
+	$(call RUN,foo)
+
+skip:
+	echo "expected failure"
+
+foo: foo.rs $(call NATIVE_STATICLIB,foo)
+	$(RUSTC) $< -lfoo $(EXTRACXXFLAGS)
+
+$(TMPDIR)/libfoo.o: foo.cpp
+	$(call COMPILE_OBJ_CXX,$@,$<)
+
+.PHONY: all test skip
diff --git a/src/test/run-make-fulldeps/issue-36710/foo.cpp b/src/test/run-make-fulldeps/issue-36710/foo.cpp
new file mode 100644
index 00000000000..fbd0ead7a50
--- /dev/null
+++ b/src/test/run-make-fulldeps/issue-36710/foo.cpp
@@ -0,0 +1,25 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#include <stdint.h>
+
+struct A {
+    A() { v = 1234; }
+    ~A() { v = 1; }
+    uint32_t v;
+};
+
+A a;
+
+extern "C" {
+    uint32_t get() {
+        return a.v;
+    }
+}
diff --git a/src/test/run-make-fulldeps/issue-36710/foo.rs b/src/test/run-make-fulldeps/issue-36710/foo.rs
new file mode 100644
index 00000000000..6e50566ddfd
--- /dev/null
+++ b/src/test/run-make-fulldeps/issue-36710/foo.rs
@@ -0,0 +1,18 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Tests that linking to C++ code with global destructors works.
+
+extern { fn get() -> u32; }
+
+fn main() {
+    let i = unsafe { get() };
+    assert_eq!(i, 1234);
+}
diff --git a/src/test/run-make-fulldeps/tools.mk b/src/test/run-make-fulldeps/tools.mk
index af1707de6c0..3de358fa500 100644
--- a/src/test/run-make-fulldeps/tools.mk
+++ b/src/test/run-make-fulldeps/tools.mk
@@ -59,12 +59,14 @@ endif
 
 ifdef IS_MSVC
 COMPILE_OBJ = $(CC) -c -Fo:`cygpath -w $(1)` $(2)
+COMPILE_OBJ_CXX = $(CXX) -c -Fo:`cygpath -w $(1)` $(2)
 NATIVE_STATICLIB_FILE = $(1).lib
 NATIVE_STATICLIB = $(TMPDIR)/$(call NATIVE_STATICLIB_FILE,$(1))
 OUT_EXE=-Fe:`cygpath -w $(TMPDIR)/$(call BIN,$(1))` \
 	-Fo:`cygpath -w $(TMPDIR)/$(1).obj`
 else
 COMPILE_OBJ = $(CC) -c -o $(1) $(2)
+COMPILE_OBJ_CXX = $(CXX) -c -o $(1) $(2)
 NATIVE_STATICLIB_FILE = lib$(1).a
 NATIVE_STATICLIB = $(call STATICLIB,$(1))
 OUT_EXE=-o $(TMPDIR)/$(1)