From cef068953239b1c768886e25d263b1b7f3e2b406 Mon Sep 17 00:00:00 2001 From: Peter Jin Date: Sat, 6 Feb 2016 10:19:02 -0800 Subject: [PATCH] Preliminary support for building CUDA C files with nvcc. --- src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 66a2038..bcb0494 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -397,6 +397,9 @@ impl Config { self.print(&format!("debug={} opt-level={}", debug, opt_level)); let mut cmd = self.get_base_compiler(); + let nvcc = cmd.path.to_str() + .map(|path| path.contains("nvcc")) + .unwrap_or(false); if msvc { cmd.args.push("/nologo".into()); @@ -404,6 +407,8 @@ impl Config { if opt_level != 0 { cmd.args.push("/O2".into()); } + } else if nvcc { + cmd.args.push(format!("-O{}", opt_level).into()); } else { cmd.args.push(format!("-O{}", opt_level).into()); cmd.args.push("-ffunction-sections".into()); @@ -426,8 +431,11 @@ impl Config { cmd.args.push("-m64".into()); } - if self.pic.unwrap_or(!target.contains("i686") && !target.contains("windows-gnu")) { + if !nvcc && self.pic.unwrap_or(!target.contains("i686") && !target.contains("windows-gnu")) { cmd.args.push("-fPIC".into()); + } else if nvcc && self.pic.unwrap_or(false) { + cmd.args.push("-Xcompiler".into()); + cmd.args.push("\'-fPIC\'".into()); } if target.contains("musl") { cmd.args.push("-static".into());