summaryrefslogtreecommitdiffstats
path: root/src/test/run-make-fulldeps/hotplug_codegen_backend
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/run-make-fulldeps/hotplug_codegen_backend
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/run-make-fulldeps/hotplug_codegen_backend')
-rw-r--r--src/test/run-make-fulldeps/hotplug_codegen_backend/Makefile26
-rw-r--r--src/test/run-make-fulldeps/hotplug_codegen_backend/some_crate.rs2
-rw-r--r--src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs82
3 files changed, 110 insertions, 0 deletions
diff --git a/src/test/run-make-fulldeps/hotplug_codegen_backend/Makefile b/src/test/run-make-fulldeps/hotplug_codegen_backend/Makefile
new file mode 100644
index 000000000..4cda243ff
--- /dev/null
+++ b/src/test/run-make-fulldeps/hotplug_codegen_backend/Makefile
@@ -0,0 +1,26 @@
+include ../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:
+ /bin/echo || exit 0 # This test requires /bin/echo to exist
+ $(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
diff --git a/src/test/run-make-fulldeps/hotplug_codegen_backend/some_crate.rs b/src/test/run-make-fulldeps/hotplug_codegen_backend/some_crate.rs
new file mode 100644
index 000000000..da27b7f34
--- /dev/null
+++ b/src/test/run-make-fulldeps/hotplug_codegen_backend/some_crate.rs
@@ -0,0 +1,2 @@
+#![feature(no_core)]
+#![no_core]
diff --git a/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs b/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs
new file mode 100644
index 000000000..2c4309fbe
--- /dev/null
+++ b/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs
@@ -0,0 +1,82 @@
+#![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::FxHashMap;
+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 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,
+ ) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorGuaranteed> {
+ let codegen_results = ongoing_codegen
+ .downcast::<CodegenResults>()
+ .expect("in join_codegen: ongoing_codegen is not a CodegenResults");
+ Ok((*codegen_results, FxHashMap::default()))
+ }
+
+ fn link(
+ &self,
+ sess: &Session,
+ codegen_results: CodegenResults,
+ outputs: &OutputFilenames,
+ ) -> Result<(), ErrorGuaranteed> {
+ use rustc_session::{config::CrateType, 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.fatal(&format!("Crate type is {:?}", crate_type));
+ }
+ let output_name = out_filename(sess, crate_type, &outputs, &*crate_name.as_str());
+ let mut out_file = ::std::fs::File::create(output_name).unwrap();
+ write!(out_file, "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)
+}