Skip to content

Commit bd94bf5

Browse files
committed
Add a test for issue 36710.
1 parent 6d9154a commit bd94bf5

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-include ../tools.mk
2+
3+
all: foo
4+
$(call RUN,foo)
5+
6+
foo: foo.rs $(call NATIVE_STATICLIB,foo)
7+
$(RUSTC) $< -lfoo $(EXTRACXXFLAGS)
8+
9+
$(TMPDIR)/libfoo.o: foo.cpp
10+
$(call COMPILE_OBJ_CXX,$@,$<)
11+
12+
.PHONY: all
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#include <stdint.h>
12+
13+
struct A {
14+
A() { v = 1234; }
15+
~A() { v = 1; }
16+
uint32_t v;
17+
};
18+
19+
A a;
20+
21+
extern "C" {
22+
uint32_t get() {
23+
return a.v;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Tests that linking to C++ code with global destructors works.
12+
13+
extern { fn get() -> u32; }
14+
15+
fn main() {
16+
let i = unsafe { get() };
17+
assert_eq!(i, 1234);
18+
}

src/test/run-make-fulldeps/tools.mk

+2
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ endif
5959

6060
ifdef IS_MSVC
6161
COMPILE_OBJ = $(CC) -c -Fo:`cygpath -w $(1)` $(2)
62+
COMPILE_OBJ_CXX = $(CXX) -c -Fo:`cygpath -w $(1)` $(2)
6263
NATIVE_STATICLIB_FILE = $(1).lib
6364
NATIVE_STATICLIB = $(TMPDIR)/$(call NATIVE_STATICLIB_FILE,$(1))
6465
OUT_EXE=-Fe:`cygpath -w $(TMPDIR)/$(call BIN,$(1))` \
6566
-Fo:`cygpath -w $(TMPDIR)/$(1).obj`
6667
else
6768
COMPILE_OBJ = $(CC) -c -o $(1) $(2)
69+
COMPILE_OBJ_CXX = $(CXX) -c -o $(1) $(2)
6870
NATIVE_STATICLIB_FILE = lib$(1).a
6971
NATIVE_STATICLIB = $(call STATICLIB,$(1))
7072
OUT_EXE=-o $(TMPDIR)/$(1)

0 commit comments

Comments
 (0)