|
| 1 | +//! `backtrace`'s `cpp_smoke_test` ported to rust-lang/rust. |
| 2 | +//! |
| 3 | +//! A basic smoke test that exercises `backtrace` to see if it can resolve basic C++ templated + |
| 4 | +//! trampolined symbol names. |
| 5 | +
|
| 6 | +//@ ignore-cross-compile (binary needs to run) |
| 7 | +//@ only-nightly |
| 8 | + |
| 9 | +//@ ignore-windows-msvc (test fails due to backtrace symbol mismatches) |
| 10 | +// FIXME: on MSVC, at `-O1`, there are no symbols available. At `-O0`, the test fails looking like: |
| 11 | +// ``` |
| 12 | +// actual names = [ |
| 13 | +// "space::templated_trampoline<void (__cdecl*)(void)>", |
| 14 | +// ] |
| 15 | +// expected names = [ |
| 16 | +// "void space::templated_trampoline<void (*)()>(void (*)())", |
| 17 | +// "cpp_trampoline", |
| 18 | +// ] |
| 19 | +// ``` |
| 20 | + |
| 21 | +use run_make_support::rustc::sysroot; |
| 22 | +use run_make_support::{ |
| 23 | + build_native_static_lib_cxx_optimized, cargo, crate_cc, cwd, path, rfs, run, rustc, |
| 24 | + source_root, target, |
| 25 | +}; |
| 26 | + |
| 27 | +fn main() { |
| 28 | + let target_dir = path("target"); |
| 29 | + let src_root = source_root(); |
| 30 | + let backtrace_submodule = src_root.join("library").join("backtrace"); |
| 31 | + let backtrace_toml = backtrace_submodule.join("Cargo.toml"); |
| 32 | + |
| 33 | + // Build the `backtrace` package (the `library/backtrace` submodule to make sure we exercise the |
| 34 | + // same `backtrace` as shipped with std). |
| 35 | + cargo() |
| 36 | + // NOTE: needed to skip trying to link in `windows.0.52.0.lib` which is pre-built but not |
| 37 | + // available in *this* scenario. |
| 38 | + .env("RUSTFLAGS", "--cfg=windows_raw_dylib") |
| 39 | + .arg("build") |
| 40 | + .args(&["--manifest-path", &backtrace_toml.to_str().unwrap()]) |
| 41 | + .args(&["--target", &target()]) |
| 42 | + .arg("--features=cpp_demangle") |
| 43 | + .env("CARGO_TARGET_DIR", &target_dir) |
| 44 | + // Visual Studio 2022 requires that the LIB env var be set so it can |
| 45 | + // find the Windows SDK. |
| 46 | + .env("LIB", std::env::var("LIB").unwrap_or_default()) |
| 47 | + .run(); |
| 48 | + |
| 49 | + let rlibs_path = target_dir.join(target()).join("debug").join("deps"); |
| 50 | + |
| 51 | + // FIXME: this test is *really* fragile. Even on `x86_64-unknown-linux-gnu`, this fails if a |
| 52 | + // different opt-level is passed. On `-O2` this test fails due to no symbols found. On `-O0` |
| 53 | + // this test fails because it's missing one of the expected symbols. |
| 54 | + build_native_static_lib_cxx_optimized("trampoline", "-O1"); |
| 55 | + |
| 56 | + rustc() |
| 57 | + .input("cpp_smoke_test.rs") |
| 58 | + .library_search_path(&rlibs_path) |
| 59 | + .library_search_path(cwd()) |
| 60 | + .debuginfo("2") |
| 61 | + .arg("-ltrampoline") |
| 62 | + .run(); |
| 63 | + |
| 64 | + run("cpp_smoke_test"); |
| 65 | +} |
0 commit comments