Skip to content

Commit 81687c4

Browse files
committed
Add a test for issue 36710.
This still expectedly fails for musl targets with +crt-static.
1 parent 665d667 commit 81687c4

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-include ../tools.mk
2+
3+
ifeq (musl,$(findstring musl,$(TARGET)))
4+
all: skip
5+
else
6+
all: test
7+
endif
8+
9+
test: foo
10+
$(call RUN,foo)
11+
12+
skip:
13+
echo "expected failure"
14+
15+
foo: foo.rs $(call NATIVE_STATICLIB,foo)
16+
$(RUSTC) $< -lfoo $(EXTRACXXFLAGS)
17+
18+
$(TMPDIR)/libfoo.o: foo.cpp
19+
$(call COMPILE_OBJ_CXX,$@,$<)
20+
21+
.PHONY: all test skip
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)