@@ -35,6 +35,10 @@ fn main() {
35
35
let outdir = path:: PathBuf :: from (
36
36
env:: var ( "OUT_DIR" ) . expect ( "OUT_DIR environment variable should be set by cargo." ) ,
37
37
) ;
38
+ let manifest_dir = path:: PathBuf :: from (
39
+ env:: var ( "CARGO_MANIFEST_DIR" )
40
+ . expect ( "CARGO_MANIFEST_DIR environment variable should be set by cargo." ) ,
41
+ ) ;
38
42
39
43
let sdk = cuda_sdk:: CudaSdk :: new ( ) . expect ( "Cannot create CUDA SDK instance." ) ;
40
44
// Emit metadata for the build script.
@@ -63,11 +67,11 @@ fn main() {
63
67
println ! ( "cargo::rerun-if-env-changed={}" , e) ;
64
68
}
65
69
66
- create_cuda_driver_bindings ( & sdk, outdir. as_path ( ) ) ;
67
- create_cuda_runtime_bindings ( & sdk, outdir. as_path ( ) ) ;
68
- create_cublas_bindings ( & sdk, outdir. as_path ( ) ) ;
69
- create_nptx_compiler_bindings ( & sdk, outdir. as_path ( ) ) ;
70
- create_nvvm_bindings ( & sdk, outdir. as_path ( ) ) ;
70
+ create_cuda_driver_bindings ( & sdk, & outdir, & manifest_dir ) ;
71
+ create_cuda_runtime_bindings ( & sdk, & outdir, & manifest_dir ) ;
72
+ create_cublas_bindings ( & sdk, & outdir, & manifest_dir ) ;
73
+ create_nptx_compiler_bindings ( & sdk, & outdir, & manifest_dir ) ;
74
+ create_nvvm_bindings ( & sdk, & outdir, & manifest_dir ) ;
71
75
72
76
if cfg ! ( any(
73
77
feature = "driver" ,
@@ -101,14 +105,19 @@ fn main() {
101
105
}
102
106
}
103
107
104
- fn create_cuda_driver_bindings ( sdk : & cuda_sdk:: CudaSdk , outdir : & path:: Path ) {
108
+ fn create_cuda_driver_bindings (
109
+ sdk : & cuda_sdk:: CudaSdk ,
110
+ outdir : & path:: Path ,
111
+ manifest_dir : & path:: Path ,
112
+ ) {
105
113
if !cfg ! ( feature = "driver" ) {
106
114
return ;
107
115
}
108
116
let bindgen_path = path:: PathBuf :: from ( format ! ( "{}/driver_sys.rs" , outdir. display( ) ) ) ;
109
- let header = "build/driver_wrapper.h" ;
117
+ let header = manifest_dir. join ( "build/driver_wrapper.h" ) ;
118
+ println ! ( "cargo::rerun-if-changed={}" , header. display( ) ) ;
110
119
let bindings = bindgen:: Builder :: default ( )
111
- . header ( header)
120
+ . header ( header. to_str ( ) . expect ( "header should be valid UTF-8" ) )
112
121
. parse_callbacks ( Box :: new ( callbacks:: FunctionRenames :: new (
113
122
"cu" ,
114
123
outdir,
@@ -145,14 +154,19 @@ fn create_cuda_driver_bindings(sdk: &cuda_sdk::CudaSdk, outdir: &path::Path) {
145
154
. expect ( "Cannot write CUDA driver bindgen output to file." ) ;
146
155
}
147
156
148
- fn create_cuda_runtime_bindings ( sdk : & cuda_sdk:: CudaSdk , outdir : & path:: Path ) {
157
+ fn create_cuda_runtime_bindings (
158
+ sdk : & cuda_sdk:: CudaSdk ,
159
+ outdir : & path:: Path ,
160
+ manifest_dir : & path:: Path ,
161
+ ) {
149
162
if !cfg ! ( feature = "runtime" ) {
150
163
return ;
151
164
}
152
165
let bindgen_path = path:: PathBuf :: from ( format ! ( "{}/runtime_sys.rs" , outdir. display( ) ) ) ;
153
- let header = "build/runtime_wrapper.h" ;
166
+ let header = manifest_dir. join ( "build/runtime_wrapper.h" ) ;
167
+ println ! ( "cargo::rerun-if-changed={}" , header. display( ) ) ;
154
168
let bindings = bindgen:: Builder :: default ( )
155
- . header ( header)
169
+ . header ( header. to_str ( ) . expect ( "header should be valid UTF-8" ) )
156
170
. parse_callbacks ( Box :: new ( callbacks:: FunctionRenames :: new (
157
171
"cuda" ,
158
172
outdir,
@@ -187,7 +201,7 @@ fn create_cuda_runtime_bindings(sdk: &cuda_sdk::CudaSdk, outdir: &path::Path) {
187
201
. expect ( "Cannot write CUDA runtime bindgen output to file." ) ;
188
202
}
189
203
190
- fn create_cublas_bindings ( sdk : & cuda_sdk:: CudaSdk , outdir : & path:: Path ) {
204
+ fn create_cublas_bindings ( sdk : & cuda_sdk:: CudaSdk , outdir : & path:: Path , manifest_dir : & path :: Path ) {
191
205
#[ rustfmt:: skip]
192
206
let params = & [
193
207
( cfg ! ( feature = "cublas" ) , "cublas" , "^cublas.*" , "^CUBLAS.*" ) ,
@@ -199,9 +213,10 @@ fn create_cublas_bindings(sdk: &cuda_sdk::CudaSdk, outdir: &path::Path) {
199
213
continue ;
200
214
}
201
215
let bindgen_path = path:: PathBuf :: from ( format ! ( "{}/{pkg}_sys.rs" , outdir. display( ) ) ) ;
202
- let header = format ! ( "build/{pkg}_wrapper.h" ) ;
216
+ let header = manifest_dir. join ( format ! ( "build/{pkg}_wrapper.h" ) ) ;
217
+ println ! ( "cargo::rerun-if-changed={}" , header. display( ) ) ;
203
218
let bindings = bindgen:: Builder :: default ( )
204
- . header ( & header)
219
+ . header ( header. to_str ( ) . expect ( "header should be valid UTF-8" ) )
205
220
. parse_callbacks ( Box :: new ( callbacks:: FunctionRenames :: new (
206
221
pkg,
207
222
outdir,
@@ -235,13 +250,19 @@ fn create_cublas_bindings(sdk: &cuda_sdk::CudaSdk, outdir: &path::Path) {
235
250
}
236
251
}
237
252
238
- fn create_nptx_compiler_bindings ( sdk : & cuda_sdk:: CudaSdk , outdir : & path:: Path ) {
253
+ fn create_nptx_compiler_bindings (
254
+ sdk : & cuda_sdk:: CudaSdk ,
255
+ outdir : & path:: Path ,
256
+ manifest_dir : & path:: Path ,
257
+ ) {
239
258
if !cfg ! ( feature = "nvptx-compiler" ) {
240
259
return ;
241
260
}
242
261
let bindgen_path = path:: PathBuf :: from ( format ! ( "{}/nvptx_compiler_sys.rs" , outdir. display( ) ) ) ;
262
+ let header = manifest_dir. join ( "build/nvptx_compiler_wrapper.h" ) ;
263
+ println ! ( "cargo::rerun-if-changed={}" , header. display( ) ) ;
243
264
let bindings = bindgen:: Builder :: default ( )
244
- . header ( "build/nvptx_compiler_wrapper.h" )
265
+ . header ( header . to_str ( ) . expect ( "header should be valid UTF-8" ) )
245
266
. parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks :: new ( ) ) )
246
267
. clang_args (
247
268
sdk. cuda_include_paths ( )
@@ -268,13 +289,15 @@ fn create_nptx_compiler_bindings(sdk: &cuda_sdk::CudaSdk, outdir: &path::Path) {
268
289
. expect ( "Cannot write nvptx-compiler bindgen output to file." ) ;
269
290
}
270
291
271
- fn create_nvvm_bindings ( sdk : & cuda_sdk:: CudaSdk , outdir : & path:: Path ) {
292
+ fn create_nvvm_bindings ( sdk : & cuda_sdk:: CudaSdk , outdir : & path:: Path , manifest_dir : & path :: Path ) {
272
293
if !cfg ! ( feature = "nvvm" ) {
273
294
return ;
274
295
}
275
296
let bindgen_path = path:: PathBuf :: from ( format ! ( "{}/nvvm_sys.rs" , outdir. display( ) ) ) ;
297
+ let header = manifest_dir. join ( "build/nvvm_wrapper.h" ) ;
298
+ println ! ( "cargo::rerun-if-changed={}" , header. display( ) ) ;
276
299
let bindings = bindgen:: Builder :: default ( )
277
- . header ( "build/nvvm_wrapper.h" )
300
+ . header ( header . to_str ( ) . expect ( "header should be valid UTF-8" ) )
278
301
. parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks :: new ( ) ) )
279
302
. clang_args (
280
303
sdk. nvvm_include_paths ( )
0 commit comments