@@ -14,11 +14,11 @@ usingnamespace @import("windows_sdk.zig");
14
14
15
15
/// See the render function implementation for documentation of the fields.
16
16
pub const LibCInstallation = struct {
17
- include_dir : ? [: 0 ]const u8 = null ,
18
- sys_include_dir : ? [: 0 ]const u8 = null ,
19
- crt_dir : ? [: 0 ]const u8 = null ,
20
- msvc_lib_dir : ? [: 0 ]const u8 = null ,
21
- kernel32_lib_dir : ? [: 0 ]const u8 = null ,
17
+ include_dir : ? []const u8 = null ,
18
+ sys_include_dir : ? []const u8 = null ,
19
+ crt_dir : ? []const u8 = null ,
20
+ msvc_lib_dir : ? []const u8 = null ,
21
+ kernel32_lib_dir : ? []const u8 = null ,
22
22
23
23
pub const FindError = error {
24
24
OutOfMemory ,
@@ -327,15 +327,20 @@ pub const LibCInstallation = struct {
327
327
var search_buf : [2 ]Search = undefined ;
328
328
const searches = fillSearch (& search_buf , sdk );
329
329
330
- var result_buf = try std .Buffer .initSize (allocator , 0 );
331
- defer result_buf .deinit ();
332
-
333
330
for (searches ) | search | {
334
- result_buf .shrink (0 );
335
- const stream = result_buf .outStream ();
336
- try stream .print ("{}\\ Include\\ {}\\ ucrt" , .{ search .path , search .version });
337
-
338
- var dir = fs .cwd ().openDir (result_buf .span (), .{}) catch | err | switch (err ) {
331
+ const dir_path = try fs .path .join (
332
+ allocator ,
333
+ &[_ ][]const u8 {
334
+ search .path ,
335
+ "Include" ,
336
+ search .version ,
337
+ "ucrt" ,
338
+ },
339
+ );
340
+ var found = false ;
341
+ defer if (! found ) allocator .free (dir_path );
342
+
343
+ var dir = fs .cwd ().openDir (dir_path , .{}) catch | err | switch (err ) {
339
344
error .FileNotFound ,
340
345
error .NotDir ,
341
346
error .NoDevice ,
@@ -350,7 +355,8 @@ pub const LibCInstallation = struct {
350
355
else = > return error .FileSystem ,
351
356
};
352
357
353
- self .include_dir = result_buf .toOwnedSlice ();
358
+ found = true ;
359
+ self .include_dir = dir_path ;
354
360
return ;
355
361
}
356
362
@@ -367,9 +373,6 @@ pub const LibCInstallation = struct {
367
373
var search_buf : [2 ]Search = undefined ;
368
374
const searches = fillSearch (& search_buf , sdk );
369
375
370
- var result_buf = try std .Buffer .initSize (allocator , 0 );
371
- defer result_buf .deinit ();
372
-
373
376
const arch_sub_dir = switch (builtin .arch ) {
374
377
.i386 = > "x86" ,
375
378
.x86_64 = > "x64" ,
@@ -378,11 +381,20 @@ pub const LibCInstallation = struct {
378
381
};
379
382
380
383
for (searches ) | search | {
381
- result_buf .shrink (0 );
382
- const stream = result_buf .outStream ();
383
- try stream .print ("{}\\ Lib\\ {}\\ ucrt\\ {}" , .{ search .path , search .version , arch_sub_dir });
384
-
385
- var dir = fs .cwd ().openDir (result_buf .span (), .{}) catch | err | switch (err ) {
384
+ const dir_path = try fs .path .join (
385
+ allocator ,
386
+ &[_ ][]const u8 {
387
+ search .path ,
388
+ "Lib" ,
389
+ search .version ,
390
+ "ucrt" ,
391
+ arch_sub_dir ,
392
+ },
393
+ );
394
+ var found = false ;
395
+ defer if (! found ) allocator .free (dir_path );
396
+
397
+ var dir = fs .cwd ().openDir (dir_path , .{}) catch | err | switch (err ) {
386
398
error .FileNotFound ,
387
399
error .NotDir ,
388
400
error .NoDevice ,
@@ -397,7 +409,8 @@ pub const LibCInstallation = struct {
397
409
else = > return error .FileSystem ,
398
410
};
399
411
400
- self .crt_dir = result_buf .toOwnedSlice ();
412
+ found = true ;
413
+ self .crt_dir = dir_path ;
401
414
return ;
402
415
}
403
416
return error .LibCRuntimeNotFound ;
@@ -421,10 +434,6 @@ pub const LibCInstallation = struct {
421
434
422
435
var search_buf : [2 ]Search = undefined ;
423
436
const searches = fillSearch (& search_buf , sdk );
424
-
425
- var result_buf = try std .Buffer .initSize (allocator , 0 );
426
- defer result_buf .deinit ();
427
-
428
437
const arch_sub_dir = switch (builtin .arch ) {
429
438
.i386 = > "x86" ,
430
439
.x86_64 = > "x64" ,
@@ -433,11 +442,20 @@ pub const LibCInstallation = struct {
433
442
};
434
443
435
444
for (searches ) | search | {
436
- result_buf .shrink (0 );
437
- const stream = result_buf .outStream ();
438
- try stream .print ("{}\\ Lib\\ {}\\ um\\ {}" , .{ search .path , search .version , arch_sub_dir });
439
-
440
- var dir = fs .cwd ().openDir (result_buf .span (), .{}) catch | err | switch (err ) {
445
+ const dir_path = try fs .path .join (
446
+ allocator ,
447
+ &[_ ][]const u8 {
448
+ search .path ,
449
+ "Lib" ,
450
+ search .version ,
451
+ "um" ,
452
+ arch_sub_dir ,
453
+ },
454
+ );
455
+ var found = false ;
456
+ defer if (! found ) allocator .free (dir_path );
457
+
458
+ var dir = fs .cwd ().openDir (dir_path , .{}) catch | err | switch (err ) {
441
459
error .FileNotFound ,
442
460
error .NotDir ,
443
461
error .NoDevice ,
@@ -452,7 +470,8 @@ pub const LibCInstallation = struct {
452
470
else = > return error .FileSystem ,
453
471
};
454
472
455
- self .kernel32_lib_dir = result_buf .toOwnedSlice ();
473
+ found = true ;
474
+ self .kernel32_lib_dir = dir_path ;
456
475
return ;
457
476
}
458
477
return error .LibCKernel32LibNotFound ;
@@ -470,12 +489,16 @@ pub const LibCInstallation = struct {
470
489
const up1 = fs .path .dirname (msvc_lib_dir ) orelse return error .LibCStdLibHeaderNotFound ;
471
490
const up2 = fs .path .dirname (up1 ) orelse return error .LibCStdLibHeaderNotFound ;
472
491
473
- var result_buf = try std .Buffer .init (allocator , up2 );
474
- defer result_buf .deinit ();
475
-
476
- try result_buf .append ("\\ include" );
492
+ const dir_path = try fs .path .join (
493
+ allocator ,
494
+ &[_ ][]const u8 {
495
+ up2 ,
496
+ "include" ,
497
+ },
498
+ );
499
+ errdefer allocator .free (dir_path );
477
500
478
- var dir = fs .cwd ().openDir (result_buf . span () , .{}) catch | err | switch (err ) {
501
+ var dir = fs .cwd ().openDir (dir_path , .{}) catch | err | switch (err ) {
479
502
error .FileNotFound ,
480
503
error .NotDir ,
481
504
error .NoDevice ,
@@ -490,7 +513,7 @@ pub const LibCInstallation = struct {
490
513
else = > return error .FileSystem ,
491
514
};
492
515
493
- self .sys_include_dir = result_buf . toOwnedSlice () ;
516
+ self .sys_include_dir = dir_path ;
494
517
}
495
518
496
519
fn findNativeMsvcLibDir (
0 commit comments