about summary refs log tree commit diff
path: root/library/stdarch
diff options
context:
space:
mode:
authorMadhav Madhusoodanan <madhavmadhusoodanan@gmail.com>2025-07-27 18:00:41 +0530
committerMadhav Madhusoodanan <madhavmadhusoodanan@gmail.com>2025-07-27 18:00:41 +0530
commitc07f8bbdc2b2febed3592f112bd004e1a9016904 (patch)
tree7102ef4ab8a6f9ec9076f237cbbbc10594a5db6a /library/stdarch
parent213fd4e2e62c8d0da22c6a1e7f4f5ea2c7ca7feb (diff)
downloadrust-c07f8bbdc2b2febed3592f112bd004e1a9016904.tar.gz
rust-c07f8bbdc2b2febed3592f112bd004e1a9016904.zip
chore: handling the case where --generate-only flag is passed
Diffstat (limited to 'library/stdarch')
-rw-r--r--library/stdarch/crates/intrinsic-test/src/arm/mod.rs49
-rw-r--r--library/stdarch/crates/intrinsic-test/src/common/gen_rust.rs12
2 files changed, 37 insertions, 24 deletions
diff --git a/library/stdarch/crates/intrinsic-test/src/arm/mod.rs b/library/stdarch/crates/intrinsic-test/src/arm/mod.rs
index 917f1293b72..63663ff5fc1 100644
--- a/library/stdarch/crates/intrinsic-test/src/arm/mod.rs
+++ b/library/stdarch/crates/intrinsic-test/src/arm/mod.rs
@@ -70,7 +70,7 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
 
         let (chunk_size, chunk_count) = chunk_info(self.intrinsics.len());
 
-        let cpp_compiler = compile::build_cpp_compilation(&self.cli_options).unwrap();
+        let cpp_compiler_wrapped = compile::build_cpp_compilation(&self.cli_options);
 
         let notice = &build_notices("// ");
         fs::create_dir_all("c_programs").unwrap();
@@ -82,10 +82,15 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
                 let mut file = File::create(&c_filename).unwrap();
                 write_mod_cpp(&mut file, notice, c_target, platform_headers, chunk).unwrap();
 
-                // compile this cpp file into a .o file
-                let output = cpp_compiler
-                    .compile_object_file(&format!("mod_{i}.cpp"), &format!("mod_{i}.o"))?;
-                assert!(output.status.success(), "{output:?}");
+                // compile this cpp file into a .o file.
+                //
+                // This is done because `cpp_compiler_wrapped` is None when
+                // the --generate-only flag is passed
+                if let Some(cpp_compiler) = cpp_compiler_wrapped.as_ref() {
+                    let output = cpp_compiler
+                        .compile_object_file(&format!("mod_{i}.cpp"), &format!("mod_{i}.o"))?;
+                    assert!(output.status.success(), "{output:?}");
+                }
 
                 Ok(())
             })
@@ -101,21 +106,25 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
         )
         .unwrap();
 
-        // compile this cpp file into a .o file
-        info!("compiling main.cpp");
-        let output = cpp_compiler
-            .compile_object_file("main.cpp", "intrinsic-test-programs.o")
-            .unwrap();
-        assert!(output.status.success(), "{output:?}");
-
-        let object_files = (0..chunk_count)
-            .map(|i| format!("mod_{i}.o"))
-            .chain(["intrinsic-test-programs.o".to_owned()]);
-
-        let output = cpp_compiler
-            .link_executable(object_files, "intrinsic-test-programs")
-            .unwrap();
-        assert!(output.status.success(), "{output:?}");
+        // This is done because `cpp_compiler_wrapped` is None when
+        // the --generate-only flag is passed
+        if let Some(cpp_compiler) = cpp_compiler_wrapped.as_ref() {
+            // compile this cpp file into a .o file
+            info!("compiling main.cpp");
+            let output = cpp_compiler
+                .compile_object_file("main.cpp", "intrinsic-test-programs.o")
+                .unwrap();
+            assert!(output.status.success(), "{output:?}");
+
+            let object_files = (0..chunk_count)
+                .map(|i| format!("mod_{i}.o"))
+                .chain(["intrinsic-test-programs.o".to_owned()]);
+
+            let output = cpp_compiler
+                .link_executable(object_files, "intrinsic-test-programs")
+                .unwrap();
+            assert!(output.status.success(), "{output:?}");
+        }
 
         true
     }
diff --git a/library/stdarch/crates/intrinsic-test/src/common/gen_rust.rs b/library/stdarch/crates/intrinsic-test/src/common/gen_rust.rs
index 60bb577a80c..acc18cfb92b 100644
--- a/library/stdarch/crates/intrinsic-test/src/common/gen_rust.rs
+++ b/library/stdarch/crates/intrinsic-test/src/common/gen_rust.rs
@@ -130,6 +130,12 @@ pub fn compile_rust_programs(toolchain: Option<&str>, target: &str, linker: Opti
     /* If there has been a linker explicitly set from the command line then
      * we want to set it via setting it in the RUSTFLAGS*/
 
+    // This is done because `toolchain` is None when
+    // the --generate-only flag is passed
+    if toolchain.is_none() {
+        return true;
+    }
+
     trace!("Building cargo command");
 
     let mut cargo_command = Command::new("cargo");
@@ -138,10 +144,8 @@ pub fn compile_rust_programs(toolchain: Option<&str>, target: &str, linker: Opti
     // Do not use the target directory of the workspace please.
     cargo_command.env("CARGO_TARGET_DIR", "target");
 
-    if let Some(toolchain) = toolchain
-        && !toolchain.is_empty()
-    {
-        cargo_command.arg(toolchain);
+    if toolchain.is_some_and(|val| !val.is_empty()) {
+        cargo_command.arg(toolchain.unwrap());
     }
     cargo_command.args(["build", "--target", target, "--release"]);