@@ -33,6 +33,25 @@ impl fmt::Display for CudaBuilderError {
33
33
}
34
34
}
35
35
36
+ #[ derive( Debug , Clone , Copy , PartialEq ) ]
37
+ pub enum DebugInfo {
38
+ None ,
39
+ LineTables ,
40
+ // NOTE(RDambrosio016): currently unimplemented because it causes a segfault somewhere in LLVM
41
+ // or libnvvm. Probably the latter.
42
+ // Full,
43
+ }
44
+
45
+ impl DebugInfo {
46
+ fn into_nvvm_and_rustc_options ( self ) -> ( String , String ) {
47
+ match self {
48
+ DebugInfo :: None => unreachable ! ( ) ,
49
+ DebugInfo :: LineTables => ( "-generate-line-info" . into ( ) , "-Cdebuginfo=1" . into ( ) ) ,
50
+ // DebugInfo::Full => ("-g".into(), "-Cdebuginfo=2".into()),
51
+ }
52
+ }
53
+ }
54
+
36
55
pub enum EmitOption {
37
56
LlvmIr ,
38
57
Bitcode ,
@@ -117,7 +136,8 @@ pub struct CudaBuilder {
117
136
///
118
137
/// `true` by default.
119
138
pub override_libm : bool ,
120
- pub debug : bool ,
139
+ /// Whether to generate any debug info and what level of info to generate.
140
+ pub debug : DebugInfo ,
121
141
}
122
142
123
143
impl CudaBuilder {
@@ -137,11 +157,12 @@ impl CudaBuilder {
137
157
emit : None ,
138
158
optix : false ,
139
159
override_libm : true ,
140
- debug : false ,
160
+ debug : DebugInfo :: None ,
141
161
}
142
162
}
143
163
144
- pub fn debug ( mut self , debug : bool ) -> Self {
164
+ /// Whether to generate any debug info and what level of info to generate.
165
+ pub fn debug ( mut self , debug : DebugInfo ) -> Self {
145
166
self . debug = debug;
146
167
self
147
168
}
@@ -385,9 +406,10 @@ fn invoke_rustc(builder: &CudaBuilder) -> Result<PathBuf, CudaBuilderError> {
385
406
llvm_args. push ( "--override-libm" . to_string ( ) ) ;
386
407
}
387
408
388
- if builder. debug {
389
- rustflags. push ( "-Cdebuginfo=1" . to_string ( ) ) ;
390
- llvm_args. push ( "-generate-line-info" . to_string ( ) ) ;
409
+ if builder. debug != DebugInfo :: None {
410
+ let ( nvvm_flag, rustc_flag) = builder. debug . into_nvvm_and_rustc_options ( ) ;
411
+ llvm_args. push ( nvvm_flag) ;
412
+ rustflags. push ( rustc_flag) ;
391
413
}
392
414
393
415
let llvm_args = llvm_args. join ( " " ) ;
0 commit comments