Skip to content

Commit d8fde50

Browse files
committed
Auto merge of #126111 - Zalathar:fulldeps-hotplug, r=jieyouxu
Port `tests/run-make-fulldeps/hotplug_codegen_backend` to ui-fulldeps This is the last remaining run-make-fulldeps test, which means I actually had to leave behind a dummy README file to prevent compiletest from complaining about a missing directory. (Removing the run-make-fulldeps suite entirely is non-trivial, so I intend to do so in a separate PR after this one.) --- I wasn't sure about adding a new kind of aux build just for this one test, so I also tried to just port this test from Makefile to [rmake](#121876) instead. But I found that I couldn't get rmake to fully work for a run-make-fulldeps test, which convinced me that getting rid of run-make-fulldeps is worthwhile. r? `@jieyouxu`
2 parents 16e8803 + 7c9b469 commit d8fde50

File tree

12 files changed

+62
-34
lines changed

12 files changed

+62
-34
lines changed

src/doc/unstable-book/src/compiler-flags/codegen-backend.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ backend. The library must be of crate type `dylib` and must contain a function
1212
named `__rustc_codegen_backend` with a signature of `fn() -> Box<dyn rustc_codegen_ssa::traits::CodegenBackend>`.
1313

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

1819
```rust,ignore (partial-example)
1920
use rustc_codegen_ssa::traits::CodegenBackend;

src/tools/compiletest/src/header.rs

+9
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ pub struct TestProps {
107107
// Similar to `aux_builds`, but a list of NAME=somelib.rs of dependencies
108108
// to build and pass with the `--extern` flag.
109109
pub aux_crates: Vec<(String, String)>,
110+
/// Similar to `aux_builds`, but also passes the resulting dylib path to
111+
/// `-Zcodegen-backend`.
112+
pub aux_codegen_backend: Option<String>,
110113
// Environment settings to use for compiling
111114
pub rustc_env: Vec<(String, String)>,
112115
// Environment variables to unset prior to compiling.
@@ -231,6 +234,7 @@ mod directives {
231234
pub const AUX_BIN: &'static str = "aux-bin";
232235
pub const AUX_BUILD: &'static str = "aux-build";
233236
pub const AUX_CRATE: &'static str = "aux-crate";
237+
pub const AUX_CODEGEN_BACKEND: &'static str = "aux-codegen-backend";
234238
pub const EXEC_ENV: &'static str = "exec-env";
235239
pub const RUSTC_ENV: &'static str = "rustc-env";
236240
pub const UNSET_EXEC_ENV: &'static str = "unset-exec-env";
@@ -267,6 +271,7 @@ impl TestProps {
267271
aux_builds: vec![],
268272
aux_bins: vec![],
269273
aux_crates: vec![],
274+
aux_codegen_backend: None,
270275
revisions: vec![],
271276
rustc_env: vec![
272277
("RUSTC_ICE".to_string(), "0".to_string()),
@@ -446,6 +451,9 @@ impl TestProps {
446451
&mut self.aux_crates,
447452
Config::parse_aux_crate,
448453
);
454+
if let Some(r) = config.parse_name_value_directive(ln, AUX_CODEGEN_BACKEND) {
455+
self.aux_codegen_backend = Some(r.trim().to_owned());
456+
}
449457
config.push_name_value_directive(
450458
ln,
451459
EXEC_ENV,
@@ -722,6 +730,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
722730
"assembly-output",
723731
"aux-bin",
724732
"aux-build",
733+
"aux-codegen-backend",
725734
"aux-crate",
726735
"build-aux-docs",
727736
"build-fail",

src/tools/compiletest/src/runtest.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,16 @@ impl<'test> TestCx<'test> {
18331833
));
18341834
}
18351835
}
1836+
1837+
// Build any `//@ aux-codegen-backend`, and pass the resulting library
1838+
// to `-Zcodegen-backend` when compiling the test file.
1839+
if let Some(aux_file) = &self.props.aux_codegen_backend {
1840+
let aux_type = self.build_auxiliary(of, aux_file, aux_dir, false);
1841+
if let Some(lib_name) = get_lib_name(aux_file.trim_end_matches(".rs"), aux_type) {
1842+
let lib_path = aux_dir.join(&lib_name);
1843+
rustc.arg(format!("-Zcodegen-backend={}", lib_path.display()));
1844+
}
1845+
}
18361846
}
18371847

18381848
fn compose_and_run_compiler(&self, mut rustc: Command, input: Option<String>) -> ProcRes {
@@ -2254,6 +2264,9 @@ impl<'test> TestCx<'test> {
22542264
}
22552265

22562266
match output_file {
2267+
// If the test's compile flags specify an output path with `-o`,
2268+
// avoid a compiler warning about `--out-dir` being ignored.
2269+
_ if self.props.compile_flags.iter().any(|flag| flag == "-o") => {}
22572270
TargetLocation::ThisFile(path) => {
22582271
rustc.arg("-o").arg(path);
22592272
}

tests/run-make-fulldeps/README.md

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

tests/run-make-fulldeps/hotplug_codegen_backend/Makefile

-25
This file was deleted.

tests/run-make-fulldeps/hotplug_codegen_backend/some_crate.rs

-2
This file was deleted.

tests/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs tests/ui-fulldeps/codegen-backend/auxiliary/the_backend.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//@ edition: 2021
2+
13
#![feature(rustc_private)]
24
#![deny(warnings)]
35

@@ -78,11 +80,11 @@ impl CodegenBackend for TheBackend {
7880
match output_name {
7981
OutFileName::Real(ref path) => {
8082
let mut out_file = ::std::fs::File::create(path).unwrap();
81-
write!(out_file, "This has been \"compiled\" successfully.").unwrap();
83+
writeln!(out_file, "This has been 'compiled' successfully.").unwrap();
8284
}
8385
OutFileName::Stdout => {
8486
let mut stdout = std::io::stdout();
85-
write!(stdout, "This has been \"compiled\" successfully.").unwrap();
87+
writeln!(stdout, "This has been 'compiled' successfully.").unwrap();
8688
}
8789
}
8890
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$TEST_BUILD_DIR/codegen-backend/hotplug.bindep/libhotplug.rlib: $DIR/hotplug.rs $TEST_BUILD_DIR/codegen-backend/hotplug.bindep/auxiliary/libthe_backend.so
2+
3+
$DIR/hotplug.rs:
4+
$TEST_BUILD_DIR/codegen-backend/hotplug.bindep/auxiliary/libthe_backend.so:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$TEST_BUILD_DIR/codegen-backend/hotplug.dep/libhotplug.rlib: $DIR/hotplug.rs
2+
3+
$DIR/hotplug.rs:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This has been 'compiled' successfully.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ edition: 2021
2+
//@ build-pass
3+
//@ ignore-stage1 (requires matching sysroot built with in-tree compiler)
4+
5+
//@ aux-codegen-backend: the_backend.rs
6+
//@ normalize-stdout-test: "libthe_backend.dylib" -> "libthe_backend.so"
7+
//@ normalize-stdout-test: "the_backend.dll" -> "libthe_backend.so"
8+
9+
//@ revisions: normal dep bindep
10+
//@ compile-flags: --crate-type=lib
11+
//@ [normal] compile-flags: --emit=link=-
12+
//@ [dep] compile-flags: --emit=link,dep-info=-
13+
//@ [bindep] compile-flags: --emit=link,dep-info=- -Zbinary-dep-depinfo
14+
15+
#![feature(no_core)]
16+
#![no_core]
17+
18+
// This test both exists as a check that -Zcodegen-backend is capable of loading external codegen
19+
// backends and that this external codegen backend is only included in the dep info if
20+
// -Zbinary-dep-depinfo is used.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
warning: ignoring --out-dir flag due to -o flag
2-
31
error: io error modifying ./does-not-exist/
42

5-
error: aborting due to 1 previous error; 1 warning emitted
3+
error: aborting due to 1 previous error
64

0 commit comments

Comments
 (0)