diff --git a/src/lib.rs b/src/lib.rs index f46fade8e..9a1c4886b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1139,6 +1139,21 @@ impl Build { for obj in objs { self.compile_object(obj)?; } + + if self.cuda { + let compiler = self.try_get_compiler()?; + let mut cmd = compiler.to_command(); + cmd.arg("-dlink"); + for obj in objs { + cmd.arg(obj.dst.clone()); + } + cmd.arg("-o"); + let out_dir = self.get_out_dir()?; + let out_dir = out_dir.join("__cc_internal_link.o"); + cmd.arg(out_dir); + run(&mut cmd, "nvcc")?; + } + Ok(()) } @@ -1165,6 +1180,11 @@ impl Build { .into_owned(), ) }; + + if self.cuda { + cmd.arg("-dc"); + } + let is_arm = target.contains("aarch64") || target.contains("arm"); command_add_output_file(&mut cmd, &obj.dst, self.cuda, msvc, clang, is_asm, is_arm); // armasm and armasm64 don't requrie -c option @@ -1713,7 +1733,15 @@ impl Build { // appends to it, which we don't want. let _ = fs::remove_file(&dst); - let objects: Vec<_> = objs.iter().map(|obj| obj.dst.clone()).collect(); + let mut objects: Vec<_> = objs.iter().map(|obj| obj.dst.clone()).collect(); + + if self.cuda { + let out_dir = self.get_out_dir()?; + let out_dir = out_dir.join("__cc_internal_link.o"); + objects.push(out_dir); + } + + let objects = objects; let target = self.get_target()?; if target.contains("msvc") { let (mut cmd, program) = self.get_ar()?;