authorJynn Nelson <github@jyn.dev> 2023-04-02 21:25:20 UTC
committerJynn Nelson <github@jyn.dev> 2023-04-02 21:54:24 UTC
logc45037b95641f22ec53a39bd13e2535d4d1605bd
tree589650a4bc0387541bc257305da283453d2f861c
parent4851d5663cf74fafc1d753d68394ea0011cfde36

try to fix test-various


7 files changed, 115 insertions(+), 112 deletions(-)

tests/run-make-fulldeps/hotplug_codegen_backend/Makefile created+26
......@@ -0,0 +1,26 @@
1include ../../run-make/tools.mk
2
3# ignore-stage1
4
5# This test both exists as a check that -Zcodegen-backend is capable of loading external codegen
6# backends and that this external codegen backend is only included in the dep info if
7# -Zbinary-dep-depinfo is used.
8
9all:
10 /bin/echo || exit 0 # This test requires /bin/echo to exist
11 $(RUSTC) the_backend.rs --crate-name the_backend --crate-type dylib \
12 -o $(TMPDIR)/the_backend.dylib
13
14 $(RUSTC) some_crate.rs --crate-name some_crate --crate-type lib -o $(TMPDIR)/some_crate \
15 -Z codegen-backend=$(TMPDIR)/the_backend.dylib -Z unstable-options \
16 --emit link,dep-info
17 grep -x "This has been \"compiled\" successfully." $(TMPDIR)/libsome_crate.rlib
18 # don't declare a dependency on the codegen backend if -Zbinary-dep-depinfo isn't used.
19 grep -v "the_backend.dylib" $(TMPDIR)/some_crate.d
20
21 $(RUSTC) some_crate.rs --crate-name some_crate --crate-type lib -o $(TMPDIR)/some_crate \
22 -Z codegen-backend=$(TMPDIR)/the_backend.dylib -Z unstable-options \
23 --emit link,dep-info -Zbinary-dep-depinfo
24 grep -x "This has been \"compiled\" successfully." $(TMPDIR)/libsome_crate.rlib
25 # but declare a dependency on the codegen backend if -Zbinary-dep-depinfo it used.
26 grep "the_backend.dylib" $(TMPDIR)/some_crate.d
tests/run-make-fulldeps/hotplug_codegen_backend/some_crate.rs created+2
......@@ -0,0 +1,2 @@
1#![feature(no_core)]
2#![no_core]
tests/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs created+84
......@@ -0,0 +1,84 @@
1#![feature(rustc_private)]
2#![deny(warnings)]
3
4extern crate rustc_codegen_ssa;
5extern crate rustc_data_structures;
6extern crate rustc_driver;
7extern crate rustc_errors;
8extern crate rustc_hir;
9extern crate rustc_metadata;
10extern crate rustc_middle;
11extern crate rustc_session;
12extern crate rustc_span;
13extern crate rustc_symbol_mangling;
14extern crate rustc_target;
15
16use rustc_codegen_ssa::traits::CodegenBackend;
17use rustc_codegen_ssa::{CodegenResults, CrateInfo};
18use rustc_data_structures::fx::FxHashMap;
19use rustc_errors::ErrorGuaranteed;
20use rustc_metadata::EncodedMetadata;
21use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
22use rustc_middle::ty::TyCtxt;
23use rustc_session::config::OutputFilenames;
24use rustc_session::Session;
25use std::any::Any;
26
27struct TheBackend;
28
29impl CodegenBackend for TheBackend {
30 fn locale_resource(&self) -> &'static str { "" }
31
32 fn codegen_crate<'a, 'tcx>(
33 &self,
34 tcx: TyCtxt<'tcx>,
35 metadata: EncodedMetadata,
36 _need_metadata_module: bool,
37 ) -> Box<dyn Any> {
38 Box::new(CodegenResults {
39 modules: vec![],
40 allocator_module: None,
41 metadata_module: None,
42 metadata,
43 crate_info: CrateInfo::new(tcx, "fake_target_cpu".to_string()),
44 })
45 }
46
47 fn join_codegen(
48 &self,
49 ongoing_codegen: Box<dyn Any>,
50 _sess: &Session,
51 _outputs: &OutputFilenames,
52 ) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorGuaranteed> {
53 let codegen_results = ongoing_codegen
54 .downcast::<CodegenResults>()
55 .expect("in join_codegen: ongoing_codegen is not a CodegenResults");
56 Ok((*codegen_results, FxHashMap::default()))
57 }
58
59 fn link(
60 &self,
61 sess: &Session,
62 codegen_results: CodegenResults,
63 outputs: &OutputFilenames,
64 ) -> Result<(), ErrorGuaranteed> {
65 use rustc_session::{config::CrateType, output::out_filename};
66 use std::io::Write;
67 let crate_name = codegen_results.crate_info.local_crate_name;
68 for &crate_type in sess.opts.crate_types.iter() {
69 if crate_type != CrateType::Rlib {
70 sess.fatal(&format!("Crate type is {:?}", crate_type));
71 }
72 let output_name = out_filename(sess, crate_type, &outputs, crate_name);
73 let mut out_file = ::std::fs::File::create(output_name).unwrap();
74 write!(out_file, "This has been \"compiled\" successfully.").unwrap();
75 }
76 Ok(())
77 }
78}
79
80/// This is the entrypoint for a hot plugged rustc_codegen_llvm
81#[no_mangle]
82pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
83 Box::new(TheBackend)
84}
tests/run-make/compiler-lookup-paths/Makefile+3
......@@ -1,5 +1,8 @@
11include ../tools.mk
22
3# ignore-wasm32 (need a C compiler)
4# ignore-wasm64 (need a C compiler)
5
36all: $(TMPDIR)/libnative.a
47 mkdir -p $(TMPDIR)/crate
58 mkdir -p $(TMPDIR)/native
tests/run-make/hotplug_codegen_backend/Makefile deleted-26
......@@ -1,26 +0,0 @@
1include ../tools.mk
2
3# ignore-stage1
4
5# This test both exists as a check that -Zcodegen-backend is capable of loading external codegen
6# backends and that this external codegen backend is only included in the dep info if
7# -Zbinary-dep-depinfo is used.
8
9all:
10 /bin/echo || exit 0 # This test requires /bin/echo to exist
11 $(RUSTC) the_backend.rs --crate-name the_backend --crate-type dylib \
12 -o $(TMPDIR)/the_backend.dylib
13
14 $(RUSTC) some_crate.rs --crate-name some_crate --crate-type lib -o $(TMPDIR)/some_crate \
15 -Z codegen-backend=$(TMPDIR)/the_backend.dylib -Z unstable-options \
16 --emit link,dep-info
17 grep -x "This has been \"compiled\" successfully." $(TMPDIR)/libsome_crate.rlib
18 # don't declare a dependency on the codegen backend if -Zbinary-dep-depinfo isn't used.
19 grep -v "the_backend.dylib" $(TMPDIR)/some_crate.d
20
21 $(RUSTC) some_crate.rs --crate-name some_crate --crate-type lib -o $(TMPDIR)/some_crate \
22 -Z codegen-backend=$(TMPDIR)/the_backend.dylib -Z unstable-options \
23 --emit link,dep-info -Zbinary-dep-depinfo
24 grep -x "This has been \"compiled\" successfully." $(TMPDIR)/libsome_crate.rlib
25 # but declare a dependency on the codegen backend if -Zbinary-dep-depinfo it used.
26 grep "the_backend.dylib" $(TMPDIR)/some_crate.d
tests/run-make/hotplug_codegen_backend/some_crate.rs deleted-2
......@@ -1,2 +0,0 @@
1#![feature(no_core)]
2#![no_core]
tests/run-make/hotplug_codegen_backend/the_backend.rs deleted-84
......@@ -1,84 +0,0 @@
1#![feature(rustc_private)]
2#![deny(warnings)]
3
4extern crate rustc_codegen_ssa;
5extern crate rustc_data_structures;
6extern crate rustc_driver;
7extern crate rustc_errors;
8extern crate rustc_hir;
9extern crate rustc_metadata;
10extern crate rustc_middle;
11extern crate rustc_session;
12extern crate rustc_span;
13extern crate rustc_symbol_mangling;
14extern crate rustc_target;
15
16use rustc_codegen_ssa::traits::CodegenBackend;
17use rustc_codegen_ssa::{CodegenResults, CrateInfo};
18use rustc_data_structures::fx::FxHashMap;
19use rustc_errors::ErrorGuaranteed;
20use rustc_metadata::EncodedMetadata;
21use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
22use rustc_middle::ty::TyCtxt;
23use rustc_session::config::OutputFilenames;
24use rustc_session::Session;
25use std::any::Any;
26
27struct TheBackend;
28
29impl CodegenBackend for TheBackend {
30 fn locale_resource(&self) -> &'static str { "" }
31
32 fn codegen_crate<'a, 'tcx>(
33 &self,
34 tcx: TyCtxt<'tcx>,
35 metadata: EncodedMetadata,
36 _need_metadata_module: bool,
37 ) -> Box<dyn Any> {
38 Box::new(CodegenResults {
39 modules: vec![],
40 allocator_module: None,
41 metadata_module: None,
42 metadata,
43 crate_info: CrateInfo::new(tcx, "fake_target_cpu".to_string()),
44 })
45 }
46
47 fn join_codegen(
48 &self,
49 ongoing_codegen: Box<dyn Any>,
50 _sess: &Session,
51 _outputs: &OutputFilenames,
52 ) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorGuaranteed> {
53 let codegen_results = ongoing_codegen
54 .downcast::<CodegenResults>()
55 .expect("in join_codegen: ongoing_codegen is not a CodegenResults");
56 Ok((*codegen_results, FxHashMap::default()))
57 }
58
59 fn link(
60 &self,
61 sess: &Session,
62 codegen_results: CodegenResults,
63 outputs: &OutputFilenames,
64 ) -> Result<(), ErrorGuaranteed> {
65 use rustc_session::{config::CrateType, output::out_filename};
66 use std::io::Write;
67 let crate_name = codegen_results.crate_info.local_crate_name;
68 for &crate_type in sess.opts.crate_types.iter() {
69 if crate_type != CrateType::Rlib {
70 sess.fatal(&format!("Crate type is {:?}", crate_type));
71 }
72 let output_name = out_filename(sess, crate_type, &outputs, crate_name);
73 let mut out_file = ::std::fs::File::create(output_name).unwrap();
74 write!(out_file, "This has been \"compiled\" successfully.").unwrap();
75 }
76 Ok(())
77 }
78}
79
80/// This is the entrypoint for a hot plugged rustc_codegen_llvm
81#[no_mangle]
82pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
83 Box::new(TheBackend)
84}