Skip to content

Commit

Permalink
rewrite foreign-exceptions to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jul 26, 2024
1 parent f8d1cab commit 0e9fa9b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 60 deletions.
5 changes: 0 additions & 5 deletions src/tools/run-make-support/src/external_deps/c_build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
use std::path::PathBuf;

<<<<<<< HEAD
use super::cygpath::get_windows_path;
use crate::artifact_names::{dynamic_lib_name, static_lib_name};
use crate::external_deps::cc::cc;
=======
use crate::artifact_names::static_lib_name;
use crate::external_deps::cc::{cc, cxx};
>>>>>>> e3cf7e53339 (rewrite foreign-double-unwind to rmake)
use crate::external_deps::llvm::llvm_ar;
use crate::path_helpers::path;
use crate::targets::{is_darwin, is_msvc, is_windows};
Expand Down
38 changes: 0 additions & 38 deletions src/tools/run-make-support/src/external_deps/cc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,41 +215,3 @@ pub fn extra_cxx_flags() -> Vec<&'static str> {
}
}
}

/// `EXTRARSCXXFLAGS`
pub fn extra_rs_cxx_flags() -> Vec<&'static str> {
// Adapted from tools.mk (trimmed):
//
// ```makefile
// ifdef IS_WINDOWS
// ifdef IS_MSVC
// else
// EXTRARSCXXFLAGS := -lstatic:-bundle=stdc++
// endif
// else
// ifeq ($(UNAME),Darwin)
// EXTRARSCXXFLAGS := -lc++
// else
// ifeq ($(UNAME),FreeBSD)
// else
// ifeq ($(UNAME),SunOS)
// else
// ifeq ($(UNAME),OpenBSD)
// else
// EXTRARSCXXFLAGS := -lstdc++
// endif
// endif
// endif
// endif
// endif
// ```
if is_windows() {
if is_msvc() { vec![] } else { vec!["-lstatic:-bundle=stdc++"] }
} else {
match &uname()[..] {
"Darwin" => vec!["-lc++"],
"FreeBSD" | "SunOS" | "OpenBSD" => vec![],
_ => vec!["-lstdc++"],
}
}
}
20 changes: 18 additions & 2 deletions src/tools/run-make-support/src/external_deps/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::command::Command;
use crate::env::env_var;
use crate::path_helpers::cwd;
use crate::util::set_host_rpath;
use crate::{is_msvc, is_windows, uname};
use crate::{is_darwin, is_msvc, is_windows, uname};

/// Construct a new `rustc` invocation. This will automatically set the library
/// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this.
Expand Down Expand Up @@ -344,10 +344,26 @@ impl Rustc {
// endif
// ```
let flag = if is_windows() {
// So this is a bit hacky: we can't use the DLL version of libstdc++ because
// it pulls in the DLL version of libgcc, which means that we end up with 2
// instances of the DW2 unwinding implementation. This is a problem on
// i686-pc-windows-gnu because each module (DLL/EXE) needs to register its
// unwind information with the unwinding implementation, and libstdc++'s
// __cxa_throw won't see the unwinding info we registered with our statically
// linked libgcc.
//
// Now, simply statically linking libstdc++ would fix this problem, except
// that it is compiled with the expectation that pthreads is dynamically
// linked as a DLL and will fail to link with a statically linked libpthread.
//
// So we end up with the following hack: we link use static:-bundle to only
// link the parts of libstdc++ that we actually use, which doesn't include
// the dependency on the pthreads DLL.
if is_msvc() { None } else { Some("-lstatic:-bundle=stdc++") }
} else if is_darwin() {
Some("-lc++")
} else {
match &uname()[..] {
"Darwin" => Some("-lc++"),
"FreeBSD" | "SunOS" | "OpenBSD" => None,
_ => Some("-lstdc++"),
}
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ run-make/dep-info/Makefile
run-make/emit-to-stdout/Makefile
run-make/extern-fn-reachable/Makefile
run-make/fmt-write-bloat/Makefile
run-make/foreign-exceptions/Makefile
run-make/incr-add-rust-src-component/Makefile
run-make/issue-35164/Makefile
run-make/issue-47551/Makefile
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/foreign-double-unwind/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
//@ ignore-cross-compile
// Reason: the compiled binary is executed

use run_make_support::{build_native_static_lib_cxx, run, rustc};
use run_make_support::{build_native_static_lib_cxx, run_fail, rustc};

fn main() {
build_native_static_lib_cxx("foo");
rustc().input("foo.rs").arg("-lfoo").extra_rs_cxx_flags().run();
run("foo").assert_stdout_not_contains("unreachable");
run_fail("foo").assert_stdout_not_contains("unreachable");
}
12 changes: 0 additions & 12 deletions tests/run-make/foreign-exceptions/Makefile

This file was deleted.

18 changes: 18 additions & 0 deletions tests/run-make/foreign-exceptions/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This test was created to check that compilation and execution still works
// after the addition of a new feature, in #65646: the ability to unwind panics
// and exceptions back and forth between Rust and C++. Should this feature be broken,
// the test should fail.
// See https://github.com/rust-lang/rust/pull/65646

//@ needs-unwind
// Reason: this test exercises panic unwinding
//@ ignore-cross-compile
// Reason: the compiled binary is executed

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

fn main() {
build_native_static_lib_cxx("foo");
rustc().input("foo.rs").arg("-lfoo").extra_rs_cxx_flags().run();
run("foo");
}

0 comments on commit 0e9fa9b

Please sign in to comment.