Skip to content

Commit 0b45a56

Browse files
committed
Added enviroment setup tool.
1 parent 9576ede commit 0b45a56

File tree

7 files changed

+58
-37
lines changed

7 files changed

+58
-37
lines changed

cargo_tests/build_std/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn main() {
110110
//let mut f = std::fs::File::create("foo.txt").unwrap();
111111

112112
//std::hint::black_box(f);
113-
std::io::stdout().write_all(b"hello world\n").unwrap();
113+
//std::io::stdout().write_all(b"hello world\n").unwrap();
114114
let s = format!("Hello {}\0",8);
115115
unsafe{puts(s.as_ptr())};
116116

src/assembly.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{
1010
r#type::TypeDef,
1111
IString,
1212
};
13+
use crate::rustc_middle::dep_graph::DepContext;
1314
use rustc_middle::mir::{
1415
interpret::{AllocId, GlobalAlloc},
1516
mono::MonoItem,
@@ -233,6 +234,7 @@ impl Assembly {
233234
name: &str,
234235
cache: &mut TyCache,
235236
) -> Result<(), MethodCodegenError> {
237+
236238
if crate::utilis::is_function_magic(name) {
237239
return Ok(());
238240
}
@@ -469,20 +471,22 @@ impl Assembly {
469471
MonoItem::Fn(instance) => {
470472
//let instance = crate::utilis::monomorphize(&instance,tcx);
471473
let symbol_name = crate::utilis::function_name(item.symbol_name(tcx));
472-
474+
let function_compile_timer = tcx.profiler().generic_activity_with_arg("compile function",item.symbol_name(tcx).to_string());
473475
self.checked_add_fn(instance, tcx, &symbol_name, cache)
474476
.expect("Could not add function!");
475-
477+
drop(function_compile_timer);
476478
Ok(())
477479
}
478480
MonoItem::GlobalAsm(asm) => {
479481
eprintln!("Unsuported item - Global ASM:{asm:?}");
480482
Ok(())
481483
}
482484
MonoItem::Static(stotic) => {
485+
let static_compile_timer = tcx.profiler().generic_activity_with_arg("compile static initializer",item.symbol_name(tcx).to_string());
483486
let alloc = tcx.eval_static_initializer(stotic).unwrap();
484487
let alloc_id = tcx.reserve_and_set_memory_alloc(alloc);
485488
self.add_allocation(crate::utilis::alloc_id_to_u64(alloc_id), tcx);
489+
drop(static_compile_timer);
486490
//eprintln!("Unsuported item - Static:{stotic:?}");
487491
Ok(())
488492
}

src/bin/rustflags.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
fn main(){
2+
let build_env = rustc_codegen_clr::compile_test::cargo_build_env();
3+
println!("In order to compile cargo crates with `rustc_codegen_clr`, please set the RUSTFLAGS enviorment variable to:");
4+
println!();
5+
println!("\"{build_env}\"");
6+
println!();
7+
println!("On linux, you may use the following commmand to quickly set the required enviroment variables:");
8+
println!();
9+
println!("export RUSTFLAGS=\"{build_env}\"");
10+
println!();
11+
println!("On windows(powershell), you may use the following commmand to quickly set the required enviroment variables:");
12+
println!();
13+
println!("$Env:RUSTFLAGS = '{build_env}'");
14+
println!();
15+
println!("After you are done working with `rustc_codegen_clr` either unset the enviroment variable OR restart your shell(close the command prompt window).");
16+
println!("On linux, you may use the following commmand to quickly unset the required enviroment variables:");
17+
println!();
18+
println!("unset RUSTFLAGS");
19+
println!();
20+
println!("Please note that those varaibles may change when the codegen is updated/rebuilt.");
21+
println!("After each time the codegen is rebuilt, please use this tool again to get updated build enviroment variables.");
22+
println!();
23+
println!("If you are using the project, please remember to:");
24+
println!("1. Update BOTH rustc and the project on a regular basis.");
25+
println!("2. Report compiler bugs to the maintainers of `rustc_codegen_clr` not the maintainers of the compiler as a whole.");
26+
println!(" In 99.999% of the cases, the bug is wihin this project and not the compiler.");
27+
}

src/cil/call_site.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl CallSite {
7272
if self.class().is_some() {
7373
return false;
7474
};
75-
if self.name.as_ref() != "black_box" && self.name.as_ref() != "assert_inhabited"{
75+
if self.name.as_ref() != "black_box" && self.name.as_ref() != "assert_inhabited" {
7676
return false;
7777
};
7878
if self.signature.inputs().len() != 1 {

src/compile_test.rs

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,7 @@ macro_rules! cargo_test {
301301
// Ensures the test directory is present
302302
std::fs::create_dir_all(test_dir).expect("Could not setup the test env");
303303
// Builds the backend if neceasry
304-
super::RUSTC_BUILD_STATUS
305-
.as_ref()
306-
.expect("Could not build rustc!");
307-
let backend = super::absolute_backend_path();
308-
let backend = backend.display();
309-
let linker = super::RUSTC_CODEGEN_CLR_LINKER.display();
310-
let rustflags = format!("-Z codegen-backend={backend} -C linker={linker}");
304+
let rustflags = super::cargo_build_env();
311305
// Compiles the test project
312306
let out = std::process::Command::new("cargo")
313307
.env("RUSTFLAGS", &rustflags)
@@ -342,13 +336,7 @@ macro_rules! cargo_test {
342336
// Ensures the test directory is present
343337
std::fs::create_dir_all(test_dir).expect("Could not setup the test env");
344338
// Builds the backend if neceasry
345-
super::RUSTC_BUILD_STATUS
346-
.as_ref()
347-
.expect("Could not build rustc!");
348-
let backend = super::absolute_backend_path();
349-
let backend = backend.display();
350-
let linker = super::RUSTC_CODEGEN_CLR_LINKER.display();
351-
let rustflags = format!("-Z codegen-backend={backend} -C linker={linker}");
339+
let rustflags = super::cargo_build_env();
352340
// Compiles the test project
353341
let mut command = std::process::Command::new("cargo");
354342
command
@@ -395,14 +383,8 @@ macro_rules! cargo_test_ignored {
395383
let test_dir = concat!("./cargo_tests/", stringify!($test_name), "/");
396384
// Ensures the test directory is present
397385
std::fs::create_dir_all(test_dir).expect("Could not setup the test env");
398-
// Builds the backend if neceasry
399-
super::RUSTC_BUILD_STATUS
400-
.as_ref()
401-
.expect("Could not build rustc!");
402-
let backend = super::absolute_backend_path();
403-
let backend = backend.display();
404-
let linker = super::RUSTC_CODEGEN_CLR_LINKER.display();
405-
let rustflags = format!("-Z codegen-backend={backend} -C linker={linker}");
386+
387+
let rustflags = super::cargo_build_env();
406388
// Compiles the test project
407389
let out = std::process::Command::new("cargo")
408390
.env("RUSTFLAGS", &rustflags)
@@ -437,14 +419,8 @@ macro_rules! cargo_test_ignored {
437419
let test_dir = concat!("./cargo_tests/", stringify!($test_name), "/");
438420
// Ensures the test directory is present
439421
std::fs::create_dir_all(test_dir).expect("Could not setup the test env");
440-
// Builds the backend if neceasry
441-
super::RUSTC_BUILD_STATUS
442-
.as_ref()
443-
.expect("Could not build rustc!");
444-
let backend = super::absolute_backend_path();
445-
let backend = backend.display();
446-
let linker = super::RUSTC_CODEGEN_CLR_LINKER.display();
447-
let rustflags = format!("-Z codegen-backend={backend} -C linker={linker}");
422+
423+
let rustflags = super::cargo_build_env();
448424
// Compiles the test project
449425
let mut command = std::process::Command::new("cargo");
450426
command
@@ -505,7 +481,6 @@ fn build_backend() -> Result<(), String> {
505481
.expect("could not build the backend");
506482
Ok(())
507483
}
508-
#[cfg(test)]
509484
fn absolute_backend_path() -> PathBuf {
510485
if cfg!(debug_assertions) {
511486
if cfg!(target_os = "linux") {
@@ -664,3 +639,12 @@ lazy_static! {
664639

665640
};
666641
}
642+
pub fn cargo_build_env()->String{
643+
RUSTC_BUILD_STATUS
644+
.as_ref()
645+
.expect("Could not build rustc!");
646+
let backend = absolute_backend_path();
647+
let backend = backend.display();
648+
let linker = RUSTC_CODEGEN_CLR_LINKER.display();
649+
format!("-Z codegen-backend={backend} -C linker={linker}")
650+
}

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub mod cil;
110110
/// Runtime errors and utlity functions/macros related to them
111111
mod codegen_error;
112112
/// Test harnesses.
113-
mod compile_test;
113+
pub mod compile_test;
114114
/// Code handling loading constant values in CIL.
115115
mod constant;
116116
/// Code detecting and inserting wrappers around entrypoints.
@@ -165,7 +165,7 @@ use rustc_session::{
165165
Session,
166166
};
167167
use rustc_span::ErrorGuaranteed;
168-
168+
use crate::rustc_middle::dep_graph::DepContext;
169169
use std::{
170170
any::Any,
171171
path::{Path, PathBuf},
@@ -223,7 +223,9 @@ impl CodegenBackend for MyBackend {
223223
codegen.opt();
224224
// Done twice for inlining!
225225
codegen.opt();
226+
let ffi_compile_timer = tcx.profiler(). generic_activity("insert .NET FFI functions/types");
226227
ffi::insert_ffi_functions(&mut codegen, tcx);
228+
drop(ffi_compile_timer);
227229
let name: IString = cgus.iter().next().unwrap().name().to_string().into();
228230

229231
Box::new((

src/type/tycache.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ pub fn ty_generic_arg(ty: Ty) -> GenericArg {
424424
// but it might not be.
425425

426426
fn try_find_ptr_components(ctx: TyCtxt) -> DefId {
427+
use crate::rustc_middle::dep_graph::DepContext;
428+
let find_ptr_components_timer = ctx.profiler(). generic_activity("ptr::metadata::PtrComponents");
427429
use rustc_middle::middle::exported_symbols::ExportedSymbol;
428430
let mut core = None;
429431
for krate in ctx.crates(()) {
@@ -464,10 +466,12 @@ fn try_find_ptr_components(ctx: TyCtxt) -> DefId {
464466
"Found more than one defintin of PtrComponents"
465467
);
466468
ptr_components = Some(did);
469+
break;
467470
}
468471

469472
//44548
470473
}
471474
//todo!("core:{core:?} max_index:{max_index:?} ptr_components:{ptr_components:?}");
475+
drop(find_ptr_components_timer);
472476
ptr_components.expect("Could not find core::ptr::metadata::PtrComponents")
473477
}

0 commit comments

Comments
 (0)