forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#128352 - Oneirical:daLTOnist-vision, r=<try>
Migrate `cross-lang-lto` `run-make` test to rmake Part of rust-lang#121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). Please try: try-job: x86_64-msvc try-job: i686-mingw try-job: x86_64-mingw try-job: armhf-gnu try-job: test-various try-job: aarch64-apple try-job: x86_64-gnu-llvm-18
- Loading branch information
Showing
5 changed files
with
144 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// This test checks that the object files we generate are actually | ||
// LLVM bitcode files (as used by linker LTO plugins) when compiling with | ||
// -Clinker-plugin-lto. | ||
// See https://github.com/rust-lang/rust/pull/50000 | ||
|
||
//FIXME(Oneirical): try it on windows | ||
|
||
#![feature(path_file_prefix)] | ||
|
||
use std::path::PathBuf; | ||
|
||
use run_make_support::{ | ||
cwd, has_extension, has_prefix, llvm_ar, llvm_bcanalyzer, path, rfs, rust_lib_name, rustc, | ||
shallow_find_files, static_lib_name, | ||
}; | ||
|
||
fn main() { | ||
check_bitcode(LibBuild { | ||
source: path("lib.rs"), | ||
crate_type: Some("staticlib"), | ||
output: path(static_lib_name("liblib")), | ||
lto: None, | ||
emit_obj: false, | ||
}); | ||
check_bitcode(LibBuild { | ||
source: path("lib.rs"), | ||
crate_type: Some("staticlib"), | ||
output: path(static_lib_name("liblib-fat-lto")), | ||
lto: Some("fat"), | ||
emit_obj: false, | ||
}); | ||
check_bitcode(LibBuild { | ||
source: path("lib.rs"), | ||
crate_type: Some("staticlib"), | ||
output: path(static_lib_name("liblib-thin-lto")), | ||
lto: Some("thin"), | ||
emit_obj: false, | ||
}); | ||
check_bitcode(LibBuild { | ||
source: path("lib.rs"), | ||
crate_type: Some("rlib"), | ||
output: path(rust_lib_name("liblib")), | ||
lto: None, | ||
emit_obj: false, | ||
}); | ||
check_bitcode(LibBuild { | ||
source: path("lib.rs"), | ||
crate_type: Some("cdylib"), | ||
output: path("cdylib.o"), | ||
lto: None, | ||
emit_obj: true, | ||
}); | ||
check_bitcode(LibBuild { | ||
source: path("lib.rs"), | ||
crate_type: Some("dylib"), | ||
output: path("rdylib.o"), | ||
lto: None, | ||
emit_obj: true, | ||
}); | ||
check_bitcode(LibBuild { | ||
source: path("main.rs"), | ||
crate_type: None, | ||
output: path("exe.o"), | ||
lto: None, | ||
emit_obj: true, | ||
}); | ||
} | ||
|
||
#[track_caller] | ||
fn check_bitcode(instructions: LibBuild) { | ||
let mut rustc = rustc(); | ||
rustc | ||
.input(instructions.source) | ||
.output(instructions.output.clone()) | ||
.opt_level("2") | ||
.codegen_units(1) | ||
.arg("-Clinker-plugin-lto"); | ||
if instructions.emit_obj { | ||
rustc.emit("obj"); | ||
} | ||
if let Some(crate_type) = instructions.crate_type { | ||
rustc.crate_type(crate_type); | ||
} | ||
if let Some(lto) = instructions.lto { | ||
rustc.arg(format!("-Clto={lto}")); | ||
} | ||
rustc.run(); | ||
|
||
if instructions.output.clone().extension().unwrap().to_str().unwrap() != "o" { | ||
// Remove all potential leftover object files, then turn the output into an object file. | ||
for object in shallow_find_files(cwd(), |path| has_extension(path, "o")) { | ||
rfs::remove_file(object); | ||
} | ||
llvm_ar().arg("x").arg(instructions.output.clone()).run(); | ||
} | ||
|
||
for object in shallow_find_files(cwd(), |path| { | ||
has_prefix(path, instructions.output.file_prefix().unwrap().to_str().unwrap()) | ||
&& has_extension(path, "o") | ||
}) { | ||
// All generated object files should be LLVM bitcode files - this will fail otherwise. | ||
llvm_bcanalyzer().input(object).run(); | ||
} | ||
} | ||
|
||
struct LibBuild { | ||
source: PathBuf, | ||
crate_type: Option<&'static str>, | ||
output: PathBuf, | ||
lto: Option<&'static str>, | ||
emit_obj: bool, | ||
} |