|  | 
|  | 1 | +// This test checks the compatibility of the interaction between `--emit obj` and | 
|  | 2 | +// `#[global_allocator]`, as it is now possible to invoke the latter without the | 
|  | 3 | +// allocator shim since #86844. As this feature is unstable, it should fail if | 
|  | 4 | +// --cfg check_feature_gate is passed. | 
|  | 5 | +// See https://github.com/rust-lang/rust/pull/86844 | 
|  | 6 | + | 
|  | 7 | +//@ ignore-cross-compile | 
|  | 8 | +// Reason: the compiled binary is executed | 
|  | 9 | + | 
|  | 10 | +//@ ignore-msvc | 
|  | 11 | +//FIXME(Oneirical): Getting this to work on MSVC requires passing libcmt.lib to CC, | 
|  | 12 | +// which is not trivial to do. | 
|  | 13 | +// Tracking issue: https://github.com/rust-lang/rust/issues/128602 | 
|  | 14 | +// Discussion: https://github.com/rust-lang/rust/pull/128407#discussion_r1702439172 | 
|  | 15 | + | 
|  | 16 | +use run_make_support::{cc, cwd, has_extension, has_prefix, run, rustc, shallow_find_files}; | 
|  | 17 | + | 
|  | 18 | +fn main() { | 
|  | 19 | +    rustc().input("foo.rs").crate_type("bin").emit("obj").panic("abort").run(); | 
|  | 20 | +    let libdir = rustc().print("target-libdir").run().stdout_utf8(); | 
|  | 21 | +    let libdir = libdir.trim(); | 
|  | 22 | +    let alloc_libs = shallow_find_files(&libdir, |path| { | 
|  | 23 | +        has_prefix(path, "liballoc-") && has_extension(path, "rlib") | 
|  | 24 | +    }); | 
|  | 25 | +    let core_libs = shallow_find_files(libdir, |path| { | 
|  | 26 | +        has_prefix(path, "libcore-") && has_extension(path, "rlib") | 
|  | 27 | +    }); | 
|  | 28 | +    cc().input("foo.o").out_exe("foo").args(&alloc_libs).args(&core_libs).run(); | 
|  | 29 | +    run("foo"); | 
|  | 30 | + | 
|  | 31 | +    // Check that linking without __rust_no_alloc_shim_is_unstable defined fails | 
|  | 32 | +    rustc() | 
|  | 33 | +        .input("foo.rs") | 
|  | 34 | +        .crate_type("bin") | 
|  | 35 | +        .emit("obj") | 
|  | 36 | +        .panic("abort") | 
|  | 37 | +        .cfg("check_feature_gate") | 
|  | 38 | +        .run(); | 
|  | 39 | +    cc().input("foo.o").out_exe("foo").args(&alloc_libs).args(&core_libs).run_fail(); | 
|  | 40 | +} | 
0 commit comments