Skip to content

Commit c75d8da

Browse files
authored
Merge pull request #1888 from madhav-madhusoodanan/intrinsic-test-generate-only-support
`intrinsic-test`: bringing back support for --generate-only flag
2 parents 6f71cdf + 57197b6 commit c75d8da

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

crates/intrinsic-test/src/arm/mod.rs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
7070

7171
let (chunk_size, chunk_count) = chunk_info(self.intrinsics.len());
7272

73-
let cpp_compiler = compile::build_cpp_compilation(&self.cli_options).unwrap();
73+
let cpp_compiler_wrapped = compile::build_cpp_compilation(&self.cli_options);
7474

7575
let notice = &build_notices("// ");
7676
fs::create_dir_all("c_programs").unwrap();
@@ -82,10 +82,15 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
8282
let mut file = File::create(&c_filename).unwrap();
8383
write_mod_cpp(&mut file, notice, c_target, platform_headers, chunk).unwrap();
8484

85-
// compile this cpp file into a .o file
86-
let output = cpp_compiler
87-
.compile_object_file(&format!("mod_{i}.cpp"), &format!("mod_{i}.o"))?;
88-
assert!(output.status.success(), "{output:?}");
85+
// compile this cpp file into a .o file.
86+
//
87+
// This is done because `cpp_compiler_wrapped` is None when
88+
// the --generate-only flag is passed
89+
if let Some(cpp_compiler) = cpp_compiler_wrapped.as_ref() {
90+
let output = cpp_compiler
91+
.compile_object_file(&format!("mod_{i}.cpp"), &format!("mod_{i}.o"))?;
92+
assert!(output.status.success(), "{output:?}");
93+
}
8994

9095
Ok(())
9196
})
@@ -101,21 +106,25 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
101106
)
102107
.unwrap();
103108

104-
// compile this cpp file into a .o file
105-
info!("compiling main.cpp");
106-
let output = cpp_compiler
107-
.compile_object_file("main.cpp", "intrinsic-test-programs.o")
108-
.unwrap();
109-
assert!(output.status.success(), "{output:?}");
110-
111-
let object_files = (0..chunk_count)
112-
.map(|i| format!("mod_{i}.o"))
113-
.chain(["intrinsic-test-programs.o".to_owned()]);
114-
115-
let output = cpp_compiler
116-
.link_executable(object_files, "intrinsic-test-programs")
117-
.unwrap();
118-
assert!(output.status.success(), "{output:?}");
109+
// This is done because `cpp_compiler_wrapped` is None when
110+
// the --generate-only flag is passed
111+
if let Some(cpp_compiler) = cpp_compiler_wrapped.as_ref() {
112+
// compile this cpp file into a .o file
113+
info!("compiling main.cpp");
114+
let output = cpp_compiler
115+
.compile_object_file("main.cpp", "intrinsic-test-programs.o")
116+
.unwrap();
117+
assert!(output.status.success(), "{output:?}");
118+
119+
let object_files = (0..chunk_count)
120+
.map(|i| format!("mod_{i}.o"))
121+
.chain(["intrinsic-test-programs.o".to_owned()]);
122+
123+
let output = cpp_compiler
124+
.link_executable(object_files, "intrinsic-test-programs")
125+
.unwrap();
126+
assert!(output.status.success(), "{output:?}");
127+
}
119128

120129
true
121130
}

crates/intrinsic-test/src/common/gen_rust.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ pub fn compile_rust_programs(toolchain: Option<&str>, target: &str, linker: Opti
130130
/* If there has been a linker explicitly set from the command line then
131131
* we want to set it via setting it in the RUSTFLAGS*/
132132

133+
// This is done because `toolchain` is None when
134+
// the --generate-only flag is passed
135+
if toolchain.is_none() {
136+
return true;
137+
}
138+
133139
trace!("Building cargo command");
134140

135141
let mut cargo_command = Command::new("cargo");
@@ -138,10 +144,8 @@ pub fn compile_rust_programs(toolchain: Option<&str>, target: &str, linker: Opti
138144
// Do not use the target directory of the workspace please.
139145
cargo_command.env("CARGO_TARGET_DIR", "target");
140146

141-
if let Some(toolchain) = toolchain
142-
&& !toolchain.is_empty()
143-
{
144-
cargo_command.arg(toolchain);
147+
if toolchain.is_some_and(|val| !val.is_empty()) {
148+
cargo_command.arg(toolchain.unwrap());
145149
}
146150
cargo_command.args(["build", "--target", target, "--release"]);
147151

0 commit comments

Comments
 (0)