Skip to content

Commit 46b4083

Browse files
committed
rewrite foreign-exceptions to rmake
1 parent 5b44f80 commit 46b4083

File tree

8 files changed

+48
-70
lines changed

8 files changed

+48
-70
lines changed

Diff for: src/tools/run-make-support/src/external_deps/c_build.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
use std::path::PathBuf;
22

3-
<<<<<<< HEAD
43
use super::cygpath::get_windows_path;
54
use crate::artifact_names::{dynamic_lib_name, static_lib_name};
6-
use crate::external_deps::cc::cc;
7-
=======
8-
use crate::artifact_names::static_lib_name;
95
use crate::external_deps::cc::{cc, cxx};
10-
>>>>>>> e3cf7e53339 (rewrite foreign-double-unwind to rmake)
116
use crate::external_deps::llvm::llvm_ar;
127
use crate::path_helpers::path;
138
use crate::targets::{is_darwin, is_msvc, is_windows};

Diff for: src/tools/run-make-support/src/external_deps/cc.rs

-38
Original file line numberDiff line numberDiff line change
@@ -214,41 +214,3 @@ pub fn extra_cxx_flags() -> Vec<&'static str> {
214214
}
215215
}
216216
}
217-
218-
/// `EXTRARSCXXFLAGS`
219-
pub fn extra_rs_cxx_flags() -> Vec<&'static str> {
220-
// Adapted from tools.mk (trimmed):
221-
//
222-
// ```makefile
223-
// ifdef IS_WINDOWS
224-
// ifdef IS_MSVC
225-
// else
226-
// EXTRARSCXXFLAGS := -lstatic:-bundle=stdc++
227-
// endif
228-
// else
229-
// ifeq ($(UNAME),Darwin)
230-
// EXTRARSCXXFLAGS := -lc++
231-
// else
232-
// ifeq ($(UNAME),FreeBSD)
233-
// else
234-
// ifeq ($(UNAME),SunOS)
235-
// else
236-
// ifeq ($(UNAME),OpenBSD)
237-
// else
238-
// EXTRARSCXXFLAGS := -lstdc++
239-
// endif
240-
// endif
241-
// endif
242-
// endif
243-
// endif
244-
// ```
245-
if is_windows() {
246-
if is_msvc() { vec![] } else { vec!["-lstatic:-bundle=stdc++"] }
247-
} else {
248-
match &uname()[..] {
249-
"Darwin" => vec!["-lc++"],
250-
"FreeBSD" | "SunOS" | "OpenBSD" => vec![],
251-
_ => vec!["-lstdc++"],
252-
}
253-
}
254-
}

Diff for: src/tools/run-make-support/src/external_deps/rustc.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::command::Command;
55
use crate::env::env_var;
66
use crate::path_helpers::cwd;
77
use crate::util::set_host_rpath;
8-
use crate::{is_msvc, is_windows, uname};
8+
use crate::{is_darwin, is_msvc, is_windows, uname};
99

1010
/// Construct a new `rustc` invocation. This will automatically set the library
1111
/// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this.
@@ -344,10 +344,26 @@ impl Rustc {
344344
// endif
345345
// ```
346346
let flag = if is_windows() {
347+
// So this is a bit hacky: we can't use the DLL version of libstdc++ because
348+
// it pulls in the DLL version of libgcc, which means that we end up with 2
349+
// instances of the DW2 unwinding implementation. This is a problem on
350+
// i686-pc-windows-gnu because each module (DLL/EXE) needs to register its
351+
// unwind information with the unwinding implementation, and libstdc++'s
352+
// __cxa_throw won't see the unwinding info we registered with our statically
353+
// linked libgcc.
354+
//
355+
// Now, simply statically linking libstdc++ would fix this problem, except
356+
// that it is compiled with the expectation that pthreads is dynamically
357+
// linked as a DLL and will fail to link with a statically linked libpthread.
358+
//
359+
// So we end up with the following hack: we link use static:-bundle to only
360+
// link the parts of libstdc++ that we actually use, which doesn't include
361+
// the dependency on the pthreads DLL.
347362
if is_msvc() { None } else { Some("-lstatic:-bundle=stdc++") }
363+
} else if is_darwin() {
364+
Some("-lc++")
348365
} else {
349366
match &uname()[..] {
350-
"Darwin" => Some("-lc++"),
351367
"FreeBSD" | "SunOS" | "OpenBSD" => None,
352368
_ => Some("-lstdc++"),
353369
}

Diff for: src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ run-make/dep-info-spaces/Makefile
99
run-make/dep-info/Makefile
1010
run-make/emit-to-stdout/Makefile
1111
run-make/extern-fn-reachable/Makefile
12-
run-make/foreign-exceptions/Makefile
1312
run-make/incr-add-rust-src-component/Makefile
1413
run-make/issue-84395-lto-embed-bitcode/Makefile
1514
run-make/issue-88756-default-output/Makefile

Diff for: tests/run-make/cpp-global-destructors/rmake.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
//@ ignore-cross-compile
77
// Reason: the compiled binary is executed
88

9-
// FIXME(Oneirical): are these really necessary? This test is supposed to test a musl
10-
// bug... and it ignores musl? This wasn't part of the original test at its creation, which
11-
// had no ignores.
9+
//@ ignore-none
10+
// Reason: no-std is not supported.
11+
//@ ignore-wasm32
12+
//@ ignore-wasm64
13+
// Reason: compiling C++ to WASM may cause problems.
1214

13-
//# ignore-none no-std is not supported
14-
//# ignore-wasm32 FIXME: don't attempt to compile C++ to WASM
15-
//# ignore-wasm64 FIXME: don't attempt to compile C++ to WASM
16-
//# ignore-nvptx64-nvidia-cuda FIXME: can't find crate for `std`
17-
//# ignore-musl FIXME: this makefile needs teaching how to use a musl toolchain
18-
//# (see dist-i586-gnu-i586-i686-musl Dockerfile)
19-
//# ignore-sgx
15+
// Neither of these are tested in full CI.
16+
//@ ignore-nvptx64-nvidia-cuda
17+
// Reason: can't find crate "std"
18+
//@ ignore-sgx
2019

2120
use run_make_support::{build_native_static_lib_cxx, run, rustc};
2221

Diff for: tests/run-make/foreign-double-unwind/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
//@ ignore-cross-compile
1313
// Reason: the compiled binary is executed
1414

15-
use run_make_support::{build_native_static_lib_cxx, run, rustc};
15+
use run_make_support::{build_native_static_lib_cxx, run_fail, rustc};
1616

1717
fn main() {
1818
build_native_static_lib_cxx("foo");
1919
rustc().input("foo.rs").arg("-lfoo").extra_rs_cxx_flags().run();
20-
run("foo").assert_stdout_not_contains("unreachable");
20+
run_fail("foo").assert_stdout_not_contains("unreachable");
2121
}

Diff for: tests/run-make/foreign-exceptions/Makefile

-12
This file was deleted.

Diff for: tests/run-make/foreign-exceptions/rmake.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This test was created to check that compilation and execution still works
2+
// after the addition of a new feature, in #65646: the ability to unwind panics
3+
// and exceptions back and forth between Rust and C++. This is a basic smoke test,
4+
// this feature being broken in quiet or subtle ways could still result in this test
5+
// passing.
6+
// See https://github.com/rust-lang/rust/pull/65646
7+
8+
//@ needs-unwind
9+
// Reason: this test exercises panic unwinding
10+
//@ ignore-cross-compile
11+
// Reason: the compiled binary is executed
12+
13+
use run_make_support::{build_native_static_lib_cxx, run, rustc};
14+
15+
fn main() {
16+
build_native_static_lib_cxx("foo");
17+
rustc().input("foo.rs").arg("-lfoo").extra_rs_cxx_flags().run();
18+
run("foo");
19+
}

0 commit comments

Comments
 (0)