File: rmake.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie, trixie-backports, trixie-proposed-updates
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (55 lines) | stat: -rw-r--r-- 1,971 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// This test checks the compatibility of the interaction between `--emit obj` and
// `#[global_allocator]`, as it is now possible to invoke the latter without the
// allocator shim since #86844. As this feature is unstable, it should fail if
// --cfg check_feature_gate is passed.
// See https://github.com/rust-lang/rust/pull/86844

//@ ignore-cross-compile
// Reason: the compiled binary is executed

//@ ignore-msvc
//FIXME(Oneirical): Getting this to work on MSVC requires passing libcmt.lib to CC,
// which is not trivial to do.
// Tracking issue: https://github.com/rust-lang/rust/issues/128602
// Discussion: https://github.com/rust-lang/rust/pull/128407#discussion_r1702439172

use run_make_support::{cc, has_extension, has_prefix, run, rustc, shallow_find_files};

fn main() {
    rustc().input("foo.rs").crate_type("bin").emit("obj").panic("abort").run();
    let libdir = rustc().print("target-libdir").run().stdout_utf8();
    let libdir = libdir.trim();

    let alloc_libs = shallow_find_files(&libdir, |path| {
        has_prefix(path, "liballoc-") && has_extension(path, "rlib")
    });
    let core_libs = shallow_find_files(&libdir, |path| {
        has_prefix(path, "libcore-") && has_extension(path, "rlib")
    });
    let compiler_builtins_libs = shallow_find_files(libdir, |path| {
        has_prefix(path, "libcompiler_builtins") && has_extension(path, "rlib")
    });

    cc().input("foo.o")
        .out_exe("foo")
        .args(&alloc_libs)
        .args(&core_libs)
        .args(&compiler_builtins_libs)
        .run();
    run("foo");

    // Check that linking without __rust_no_alloc_shim_is_unstable defined fails
    rustc()
        .input("foo.rs")
        .crate_type("bin")
        .emit("obj")
        .panic("abort")
        .cfg("check_feature_gate")
        .run();
    cc().input("foo.o")
        .out_exe("foo")
        .args(&alloc_libs)
        .args(&core_libs)
        .args(&compiler_builtins_libs)
        .run_fail();
}