Port tests/run-make-fulldeps/hotplug_codegen_backend to ui-fulldeps

This commit is contained in:
Zalathar 2024-06-05 20:12:18 +10:00
parent 58ba77f4aa
commit 7c9b469895
11 changed files with 58 additions and 31 deletions

View File

@ -12,8 +12,9 @@ backend. The library must be of crate type `dylib` and must contain a function
named `__rustc_codegen_backend` with a signature of `fn() -> Box<dyn rustc_codegen_ssa::traits::CodegenBackend>`. named `__rustc_codegen_backend` with a signature of `fn() -> Box<dyn rustc_codegen_ssa::traits::CodegenBackend>`.
## Example ## Example
See also the [`hotplug_codegen_backend`](https://github.com/rust-lang/rust/tree/master/tests/run-make-fulldeps/hotplug_codegen_backend) test See also the [`codegen-backend/hotplug`] test for a working example.
for a full example.
[`codegen-backend/hotplug`]: https://github.com/rust-lang/rust/tree/master/tests/ui-fulldeps/codegen-backend/hotplug.rs
```rust,ignore (partial-example) ```rust,ignore (partial-example)
use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::traits::CodegenBackend;

View File

@ -107,6 +107,9 @@ pub struct TestProps {
// Similar to `aux_builds`, but a list of NAME=somelib.rs of dependencies // Similar to `aux_builds`, but a list of NAME=somelib.rs of dependencies
// to build and pass with the `--extern` flag. // to build and pass with the `--extern` flag.
pub aux_crates: Vec<(String, String)>, pub aux_crates: Vec<(String, String)>,
/// Similar to `aux_builds`, but also passes the resulting dylib path to
/// `-Zcodegen-backend`.
pub aux_codegen_backend: Option<String>,
// Environment settings to use for compiling // Environment settings to use for compiling
pub rustc_env: Vec<(String, String)>, pub rustc_env: Vec<(String, String)>,
// Environment variables to unset prior to compiling. // Environment variables to unset prior to compiling.
@ -231,6 +234,7 @@ mod directives {
pub const AUX_BIN: &'static str = "aux-bin"; pub const AUX_BIN: &'static str = "aux-bin";
pub const AUX_BUILD: &'static str = "aux-build"; pub const AUX_BUILD: &'static str = "aux-build";
pub const AUX_CRATE: &'static str = "aux-crate"; pub const AUX_CRATE: &'static str = "aux-crate";
pub const AUX_CODEGEN_BACKEND: &'static str = "aux-codegen-backend";
pub const EXEC_ENV: &'static str = "exec-env"; pub const EXEC_ENV: &'static str = "exec-env";
pub const RUSTC_ENV: &'static str = "rustc-env"; pub const RUSTC_ENV: &'static str = "rustc-env";
pub const UNSET_EXEC_ENV: &'static str = "unset-exec-env"; pub const UNSET_EXEC_ENV: &'static str = "unset-exec-env";
@ -267,6 +271,7 @@ pub fn new() -> Self {
aux_builds: vec![], aux_builds: vec![],
aux_bins: vec![], aux_bins: vec![],
aux_crates: vec![], aux_crates: vec![],
aux_codegen_backend: None,
revisions: vec![], revisions: vec![],
rustc_env: vec![ rustc_env: vec![
("RUSTC_ICE".to_string(), "0".to_string()), ("RUSTC_ICE".to_string(), "0".to_string()),
@ -446,6 +451,9 @@ fn split_flags(flags: &str) -> Vec<String> {
&mut self.aux_crates, &mut self.aux_crates,
Config::parse_aux_crate, Config::parse_aux_crate,
); );
if let Some(r) = config.parse_name_value_directive(ln, AUX_CODEGEN_BACKEND) {
self.aux_codegen_backend = Some(r.trim().to_owned());
}
config.push_name_value_directive( config.push_name_value_directive(
ln, ln,
EXEC_ENV, EXEC_ENV,
@ -722,6 +730,7 @@ pub fn line_directive<'line>(
"assembly-output", "assembly-output",
"aux-bin", "aux-bin",
"aux-build", "aux-build",
"aux-codegen-backend",
"aux-crate", "aux-crate",
"build-aux-docs", "build-aux-docs",
"build-fail", "build-fail",

View File

@ -1833,6 +1833,16 @@ fn build_all_auxiliary(&self, of: &TestPaths, aux_dir: &Path, rustc: &mut Comman
)); ));
} }
} }
// Build any `//@ aux-codegen-backend`, and pass the resulting library
// to `-Zcodegen-backend` when compiling the test file.
if let Some(aux_file) = &self.props.aux_codegen_backend {
let aux_type = self.build_auxiliary(of, aux_file, aux_dir, false);
if let Some(lib_name) = get_lib_name(aux_file.trim_end_matches(".rs"), aux_type) {
let lib_path = aux_dir.join(&lib_name);
rustc.arg(format!("-Zcodegen-backend={}", lib_path.display()));
}
}
} }
fn compose_and_run_compiler(&self, mut rustc: Command, input: Option<String>) -> ProcRes { fn compose_and_run_compiler(&self, mut rustc: Command, input: Option<String>) -> ProcRes {

View File

@ -0,0 +1,4 @@
If this directory is empty, Git won't create it, and compiletest will complain
that it can't find a nonexistent test suite directory.
FIXME(#126111): Remove `run-make-fulldeps` from bootstrap.

View File

@ -1,25 +0,0 @@
include ../../run-make/tools.mk
# ignore-stage1
# This test both exists as a check that -Zcodegen-backend is capable of loading external codegen
# backends and that this external codegen backend is only included in the dep info if
# -Zbinary-dep-depinfo is used.
all:
$(RUSTC) the_backend.rs --crate-name the_backend --crate-type dylib \
-o $(TMPDIR)/the_backend.dylib
$(RUSTC) some_crate.rs --crate-name some_crate --crate-type lib -o $(TMPDIR)/some_crate \
-Z codegen-backend=$(TMPDIR)/the_backend.dylib -Z unstable-options \
--emit link,dep-info
grep -x "This has been \"compiled\" successfully." $(TMPDIR)/libsome_crate.rlib
# don't declare a dependency on the codegen backend if -Zbinary-dep-depinfo isn't used.
grep -v "the_backend.dylib" $(TMPDIR)/some_crate.d
$(RUSTC) some_crate.rs --crate-name some_crate --crate-type lib -o $(TMPDIR)/some_crate \
-Z codegen-backend=$(TMPDIR)/the_backend.dylib -Z unstable-options \
--emit link,dep-info -Zbinary-dep-depinfo
grep -x "This has been \"compiled\" successfully." $(TMPDIR)/libsome_crate.rlib
# but declare a dependency on the codegen backend if -Zbinary-dep-depinfo it used.
grep "the_backend.dylib" $(TMPDIR)/some_crate.d

View File

@ -1,2 +0,0 @@
#![feature(no_core)]
#![no_core]

View File

@ -1,3 +1,5 @@
//@ edition: 2021
#![feature(rustc_private)] #![feature(rustc_private)]
#![deny(warnings)] #![deny(warnings)]
@ -78,11 +80,11 @@ fn link(
match output_name { match output_name {
OutFileName::Real(ref path) => { OutFileName::Real(ref path) => {
let mut out_file = ::std::fs::File::create(path).unwrap(); let mut out_file = ::std::fs::File::create(path).unwrap();
write!(out_file, "This has been \"compiled\" successfully.").unwrap(); writeln!(out_file, "This has been 'compiled' successfully.").unwrap();
} }
OutFileName::Stdout => { OutFileName::Stdout => {
let mut stdout = std::io::stdout(); let mut stdout = std::io::stdout();
write!(stdout, "This has been \"compiled\" successfully.").unwrap(); writeln!(stdout, "This has been 'compiled' successfully.").unwrap();
} }
} }
} }

View File

@ -0,0 +1,4 @@
$TEST_BUILD_DIR/codegen-backend/hotplug.bindep/libhotplug.rlib: $DIR/hotplug.rs $TEST_BUILD_DIR/codegen-backend/hotplug.bindep/auxiliary/libthe_backend.so
$DIR/hotplug.rs:
$TEST_BUILD_DIR/codegen-backend/hotplug.bindep/auxiliary/libthe_backend.so:

View File

@ -0,0 +1,3 @@
$TEST_BUILD_DIR/codegen-backend/hotplug.dep/libhotplug.rlib: $DIR/hotplug.rs
$DIR/hotplug.rs:

View File

@ -0,0 +1 @@
This has been 'compiled' successfully.

View File

@ -0,0 +1,20 @@
//@ edition: 2021
//@ build-pass
//@ ignore-stage1 (requires matching sysroot built with in-tree compiler)
//@ aux-codegen-backend: the_backend.rs
//@ normalize-stdout-test: "libthe_backend.dylib" -> "libthe_backend.so"
//@ normalize-stdout-test: "the_backend.dll" -> "libthe_backend.so"
//@ revisions: normal dep bindep
//@ compile-flags: --crate-type=lib
//@ [normal] compile-flags: --emit=link=-
//@ [dep] compile-flags: --emit=link,dep-info=-
//@ [bindep] compile-flags: --emit=link,dep-info=- -Zbinary-dep-depinfo
#![feature(no_core)]
#![no_core]
// This test both exists as a check that -Zcodegen-backend is capable of loading external codegen
// backends and that this external codegen backend is only included in the dep info if
// -Zbinary-dep-depinfo is used.