Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/doc/unstable-book/src/compiler-flags/codegen-backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>`.

## Example
See also the [`hotplug_codegen_backend`](https://github.com/rust-lang/rust/tree/master/tests/run-make-fulldeps/hotplug_codegen_backend) test
for a full example.
See also the [`codegen-backend/hotplug`] test for a working example.

[`codegen-backend/hotplug`]: https://github.com/rust-lang/rust/tree/master/tests/ui-fulldeps/codegen-backend/hotplug.rs

```rust,ignore (partial-example)
use rustc_codegen_ssa::traits::CodegenBackend;
Expand Down
9 changes: 9 additions & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ pub struct TestProps {
// Similar to `aux_builds`, but a list of NAME=somelib.rs of dependencies
// to build and pass with the `--extern` flag.
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
pub rustc_env: Vec<(String, String)>,
// Environment variables to unset prior to compiling.
Expand Down Expand Up @@ -231,6 +234,7 @@ mod directives {
pub const AUX_BIN: &'static str = "aux-bin";
pub const AUX_BUILD: &'static str = "aux-build";
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 RUSTC_ENV: &'static str = "rustc-env";
pub const UNSET_EXEC_ENV: &'static str = "unset-exec-env";
Expand Down Expand Up @@ -267,6 +271,7 @@ impl TestProps {
aux_builds: vec![],
aux_bins: vec![],
aux_crates: vec![],
aux_codegen_backend: None,
revisions: vec![],
rustc_env: vec![
("RUSTC_ICE".to_string(), "0".to_string()),
Expand Down Expand Up @@ -446,6 +451,9 @@ impl TestProps {
&mut self.aux_crates,
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(
ln,
EXEC_ENV,
Expand Down Expand Up @@ -722,6 +730,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"assembly-output",
"aux-bin",
"aux-build",
"aux-codegen-backend",
"aux-crate",
"build-aux-docs",
"build-fail",
Expand Down
13 changes: 13 additions & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,16 @@ impl<'test> TestCx<'test> {
));
}
}

// 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 {
Expand Down Expand Up @@ -2254,6 +2264,9 @@ impl<'test> TestCx<'test> {
}

match output_file {
// If the test's compile flags specify an output path with `-o`,
// avoid a compiler warning about `--out-dir` being ignored.
_ if self.props.compile_flags.iter().any(|flag| flag == "-o") => {}
TargetLocation::ThisFile(path) => {
rustc.arg("-o").arg(path);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/run-make-fulldeps/README.md
Original file line number Diff line number Diff line change
@@ -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.
25 changes: 0 additions & 25 deletions tests/run-make-fulldeps/hotplug_codegen_backend/Makefile

This file was deleted.

2 changes: 0 additions & 2 deletions tests/run-make-fulldeps/hotplug_codegen_backend/some_crate.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ edition: 2021

#![feature(rustc_private)]
#![deny(warnings)]

Expand Down Expand Up @@ -78,11 +80,11 @@ impl CodegenBackend for TheBackend {
match output_name {
OutFileName::Real(ref path) => {
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 => {
let mut stdout = std::io::stdout();
write!(stdout, "This has been \"compiled\" successfully.").unwrap();
writeln!(stdout, "This has been 'compiled' successfully.").unwrap();
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/ui-fulldeps/codegen-backend/hotplug.bindep.stdout
Original file line number Diff line number Diff line change
@@ -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:
3 changes: 3 additions & 0 deletions tests/ui-fulldeps/codegen-backend/hotplug.dep.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$TEST_BUILD_DIR/codegen-backend/hotplug.dep/libhotplug.rlib: $DIR/hotplug.rs

$DIR/hotplug.rs:
1 change: 1 addition & 0 deletions tests/ui-fulldeps/codegen-backend/hotplug.normal.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This has been 'compiled' successfully.
20 changes: 20 additions & 0 deletions tests/ui-fulldeps/codegen-backend/hotplug.rs
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 1 addition & 3 deletions tests/ui/io-checks/non-ice-error-on-worker-io-fail.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
warning: ignoring --out-dir flag due to -o flag

error: io error modifying ./does-not-exist/

error: aborting due to 1 previous error; 1 warning emitted
error: aborting due to 1 previous error

Loading