about summary refs log tree commit diff
path: root/tests/ui-fulldeps/codegen-backend
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-06-05 20:12:18 +1000
committerZalathar <Zalathar@users.noreply.github.com>2024-06-07 22:28:00 +1000
commit7c9b469895692f25475e387d2cbe33cecbdb43a9 (patch)
treee0a1de6c70086c53838759ae1fe3e14312401441 /tests/ui-fulldeps/codegen-backend
parent58ba77f4aa46ca94f643eebe8f61a44f56c8abd5 (diff)
downloadrust-7c9b469895692f25475e387d2cbe33cecbdb43a9.tar.gz
rust-7c9b469895692f25475e387d2cbe33cecbdb43a9.zip
Port `tests/run-make-fulldeps/hotplug_codegen_backend` to ui-fulldeps
Diffstat (limited to 'tests/ui-fulldeps/codegen-backend')
-rw-r--r--tests/ui-fulldeps/codegen-backend/auxiliary/the_backend.rs99
-rw-r--r--tests/ui-fulldeps/codegen-backend/hotplug.bindep.stdout4
-rw-r--r--tests/ui-fulldeps/codegen-backend/hotplug.dep.stdout3
-rw-r--r--tests/ui-fulldeps/codegen-backend/hotplug.normal.stdout1
-rw-r--r--tests/ui-fulldeps/codegen-backend/hotplug.rs20
5 files changed, 127 insertions, 0 deletions
diff --git a/tests/ui-fulldeps/codegen-backend/auxiliary/the_backend.rs b/tests/ui-fulldeps/codegen-backend/auxiliary/the_backend.rs
new file mode 100644
index 00000000000..f273bbc99a8
--- /dev/null
+++ b/tests/ui-fulldeps/codegen-backend/auxiliary/the_backend.rs
@@ -0,0 +1,99 @@
+//@ edition: 2021
+
+#![feature(rustc_private)]
+#![deny(warnings)]
+
+extern crate rustc_codegen_ssa;
+extern crate rustc_data_structures;
+extern crate rustc_driver;
+extern crate rustc_errors;
+extern crate rustc_hir;
+extern crate rustc_metadata;
+extern crate rustc_middle;
+extern crate rustc_session;
+extern crate rustc_span;
+extern crate rustc_symbol_mangling;
+extern crate rustc_target;
+
+use rustc_codegen_ssa::traits::CodegenBackend;
+use rustc_codegen_ssa::{CodegenResults, CrateInfo};
+use rustc_data_structures::fx::FxIndexMap;
+use rustc_errors::ErrorGuaranteed;
+use rustc_metadata::EncodedMetadata;
+use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
+use rustc_middle::ty::TyCtxt;
+use rustc_session::config::OutputFilenames;
+use rustc_session::Session;
+use std::any::Any;
+
+struct TheBackend;
+
+impl CodegenBackend for TheBackend {
+    fn locale_resource(&self) -> &'static str {
+        ""
+    }
+
+    fn codegen_crate<'a, 'tcx>(
+        &self,
+        tcx: TyCtxt<'tcx>,
+        metadata: EncodedMetadata,
+        _need_metadata_module: bool,
+    ) -> Box<dyn Any> {
+        Box::new(CodegenResults {
+            modules: vec![],
+            allocator_module: None,
+            metadata_module: None,
+            metadata,
+            crate_info: CrateInfo::new(tcx, "fake_target_cpu".to_string()),
+        })
+    }
+
+    fn join_codegen(
+        &self,
+        ongoing_codegen: Box<dyn Any>,
+        _sess: &Session,
+        _outputs: &OutputFilenames,
+    ) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
+        let codegen_results = ongoing_codegen
+            .downcast::<CodegenResults>()
+            .expect("in join_codegen: ongoing_codegen is not a CodegenResults");
+        (*codegen_results, FxIndexMap::default())
+    }
+
+    fn link(
+        &self,
+        sess: &Session,
+        codegen_results: CodegenResults,
+        outputs: &OutputFilenames,
+    ) -> Result<(), ErrorGuaranteed> {
+        use rustc_session::{
+            config::{CrateType, OutFileName},
+            output::out_filename,
+        };
+        use std::io::Write;
+        let crate_name = codegen_results.crate_info.local_crate_name;
+        for &crate_type in sess.opts.crate_types.iter() {
+            if crate_type != CrateType::Rlib {
+                sess.dcx().fatal(format!("Crate type is {:?}", crate_type));
+            }
+            let output_name = out_filename(sess, crate_type, &outputs, crate_name);
+            match output_name {
+                OutFileName::Real(ref path) => {
+                    let mut out_file = ::std::fs::File::create(path).unwrap();
+                    writeln!(out_file, "This has been 'compiled' successfully.").unwrap();
+                }
+                OutFileName::Stdout => {
+                    let mut stdout = std::io::stdout();
+                    writeln!(stdout, "This has been 'compiled' successfully.").unwrap();
+                }
+            }
+        }
+        Ok(())
+    }
+}
+
+/// This is the entrypoint for a hot plugged rustc_codegen_llvm
+#[no_mangle]
+pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
+    Box::new(TheBackend)
+}
diff --git a/tests/ui-fulldeps/codegen-backend/hotplug.bindep.stdout b/tests/ui-fulldeps/codegen-backend/hotplug.bindep.stdout
new file mode 100644
index 00000000000..4d58fd503d0
--- /dev/null
+++ b/tests/ui-fulldeps/codegen-backend/hotplug.bindep.stdout
@@ -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:
diff --git a/tests/ui-fulldeps/codegen-backend/hotplug.dep.stdout b/tests/ui-fulldeps/codegen-backend/hotplug.dep.stdout
new file mode 100644
index 00000000000..48b7534d8fa
--- /dev/null
+++ b/tests/ui-fulldeps/codegen-backend/hotplug.dep.stdout
@@ -0,0 +1,3 @@
+$TEST_BUILD_DIR/codegen-backend/hotplug.dep/libhotplug.rlib: $DIR/hotplug.rs
+
+$DIR/hotplug.rs:
diff --git a/tests/ui-fulldeps/codegen-backend/hotplug.normal.stdout b/tests/ui-fulldeps/codegen-backend/hotplug.normal.stdout
new file mode 100644
index 00000000000..1aa032de9e4
--- /dev/null
+++ b/tests/ui-fulldeps/codegen-backend/hotplug.normal.stdout
@@ -0,0 +1 @@
+This has been 'compiled' successfully.
diff --git a/tests/ui-fulldeps/codegen-backend/hotplug.rs b/tests/ui-fulldeps/codegen-backend/hotplug.rs
new file mode 100644
index 00000000000..dc0fb3f9efd
--- /dev/null
+++ b/tests/ui-fulldeps/codegen-backend/hotplug.rs
@@ -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.