Skip to content

Support for Cuda Separate Compilation #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand All @@ -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
Expand Down Expand Up @@ -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()?;
Expand Down