| author | |
| committer | |
| log | 7eb938c9096db54fe6e99148824252904c79c227 |
| tree | 1eaf50073504d7005ed787ac798d5f56dd20bb57 |
| parent | e535057364d33819001e55d34d104916cfab1b91 |
| signature |
6 files changed, 115 insertions(+), 68 deletions(-)
src-self-hosted/libc_installation.zig+62-39| ... | ... | @@ -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( |
src-self-hosted/stage2.zig+10-10| ... | ... | @@ -741,15 +741,15 @@ fn stage2TargetParse( |
| 741 | 741 | |
| 742 | 742 | // ABI warning |
| 743 | 743 | const Stage2LibCInstallation = extern struct { |
| 744 | include_dir: [*:0]const u8, | |
| 744 | include_dir: [*]const u8, | |
| 745 | 745 | include_dir_len: usize, |
| 746 | sys_include_dir: [*:0]const u8, | |
| 746 | sys_include_dir: [*]const u8, | |
| 747 | 747 | sys_include_dir_len: usize, |
| 748 | crt_dir: [*:0]const u8, | |
| 748 | crt_dir: [*]const u8, | |
| 749 | 749 | crt_dir_len: usize, |
| 750 | msvc_lib_dir: [*:0]const u8, | |
| 750 | msvc_lib_dir: [*]const u8, | |
| 751 | 751 | msvc_lib_dir_len: usize, |
| 752 | kernel32_lib_dir: [*:0]const u8, | |
| 752 | kernel32_lib_dir: [*]const u8, | |
| 753 | 753 | kernel32_lib_dir_len: usize, |
| 754 | 754 | |
| 755 | 755 | fn initFromStage2(self: *Stage2LibCInstallation, libc: LibCInstallation) void { |
| ... | ... | @@ -793,19 +793,19 @@ const Stage2LibCInstallation = extern struct { |
| 793 | 793 | fn toStage2(self: Stage2LibCInstallation) LibCInstallation { |
| 794 | 794 | var libc: LibCInstallation = .{}; |
| 795 | 795 | if (self.include_dir_len != 0) { |
| 796 | libc.include_dir = self.include_dir[0..self.include_dir_len :0]; | |
| 796 | libc.include_dir = self.include_dir[0..self.include_dir_len]; | |
| 797 | 797 | } |
| 798 | 798 | if (self.sys_include_dir_len != 0) { |
| 799 | libc.sys_include_dir = self.sys_include_dir[0..self.sys_include_dir_len :0]; | |
| 799 | libc.sys_include_dir = self.sys_include_dir[0..self.sys_include_dir_len]; | |
| 800 | 800 | } |
| 801 | 801 | if (self.crt_dir_len != 0) { |
| 802 | libc.crt_dir = self.crt_dir[0..self.crt_dir_len :0]; | |
| 802 | libc.crt_dir = self.crt_dir[0..self.crt_dir_len]; | |
| 803 | 803 | } |
| 804 | 804 | if (self.msvc_lib_dir_len != 0) { |
| 805 | libc.msvc_lib_dir = self.msvc_lib_dir[0..self.msvc_lib_dir_len :0]; | |
| 805 | libc.msvc_lib_dir = self.msvc_lib_dir[0..self.msvc_lib_dir_len]; | |
| 806 | 806 | } |
| 807 | 807 | if (self.kernel32_lib_dir_len != 0) { |
| 808 | libc.kernel32_lib_dir = self.kernel32_lib_dir[0..self.kernel32_lib_dir_len :0]; | |
| 808 | libc.kernel32_lib_dir = self.kernel32_lib_dir[0..self.kernel32_lib_dir_len]; | |
| 809 | 809 | } |
| 810 | 810 | return libc; |
| 811 | 811 | } |
src/cache_hash.cpp+7-1| ... | ... | @@ -27,11 +27,17 @@ void cache_init(CacheHash *ch, Buf *manifest_dir) { |
| 27 | 27 | void cache_mem(CacheHash *ch, const char *ptr, size_t len) { |
| 28 | 28 | assert(ch->manifest_file_path == nullptr); |
| 29 | 29 | assert(ptr != nullptr); |
| 30 | // + 1 to include the null byte | |
| 31 | 30 | blake2b_update(&ch->blake, ptr, len); |
| 32 | 31 | } |
| 33 | 32 | |
| 33 | void cache_slice(CacheHash *ch, Slice<const char> slice) { | |
| 34 | // mix the length into the hash so that two juxtaposed cached slices can't collide | |
| 35 | cache_usize(ch, slice.len); | |
| 36 | cache_mem(ch, slice.ptr, slice.len); | |
| 37 | } | |
| 38 | ||
| 34 | 39 | void cache_str(CacheHash *ch, const char *ptr) { |
| 40 | // + 1 to include the null byte | |
| 35 | 41 | cache_mem(ch, ptr, strlen(ptr) + 1); |
| 36 | 42 | } |
| 37 | 43 |
src/cache_hash.hpp+1| ... | ... | @@ -36,6 +36,7 @@ void cache_init(CacheHash *ch, Buf *manifest_dir); |
| 36 | 36 | |
| 37 | 37 | // Next, use the hash population functions to add the initial parameters. |
| 38 | 38 | void cache_mem(CacheHash *ch, const char *ptr, size_t len); |
| 39 | void cache_slice(CacheHash *ch, Slice<const char> slice); | |
| 39 | 40 | void cache_str(CacheHash *ch, const char *ptr); |
| 40 | 41 | void cache_int(CacheHash *ch, int x); |
| 41 | 42 | void cache_bool(CacheHash *ch, bool x); |
src/codegen.cpp+16-11| ... | ... | @@ -9123,21 +9123,26 @@ static void detect_libc(CodeGen *g) { |
| 9123 | 9123 | g->libc_include_dir_len = 0; |
| 9124 | 9124 | g->libc_include_dir_list = heap::c_allocator.allocate<const char *>(dir_count); |
| 9125 | 9125 | |
| 9126 | g->libc_include_dir_list[g->libc_include_dir_len] = g->libc->include_dir; | |
| 9126 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_create_from_mem(g->libc->include_dir, g->libc->include_dir_len)); | |
| 9127 | 9127 | g->libc_include_dir_len += 1; |
| 9128 | 9128 | |
| 9129 | 9129 | if (want_sys_dir) { |
| 9130 | g->libc_include_dir_list[g->libc_include_dir_len] = g->libc->sys_include_dir; | |
| 9130 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_create_from_mem(g->libc->sys_include_dir, g->libc->sys_include_dir_len)); | |
| 9131 | 9131 | g->libc_include_dir_len += 1; |
| 9132 | 9132 | } |
| 9133 | 9133 | |
| 9134 | 9134 | if (want_um_and_shared_dirs != 0) { |
| 9135 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_sprintf( | |
| 9136 | "%s" OS_SEP ".." OS_SEP "um", g->libc->include_dir)); | |
| 9135 | Buf *include_dir_parent = buf_alloc(); | |
| 9136 | os_path_join(buf_create_from_mem(g->libc->include_dir, g->libc->include_dir_len), buf_create_from_str(".."), include_dir_parent); | |
| 9137 | ||
| 9138 | Buf *buff1 = buf_alloc(); | |
| 9139 | os_path_join(include_dir_parent, buf_create_from_str("um"), buff1); | |
| 9140 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buff1); | |
| 9137 | 9141 | g->libc_include_dir_len += 1; |
| 9138 | 9142 | |
| 9139 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_sprintf( | |
| 9140 | "%s" OS_SEP ".." OS_SEP "shared", g->libc->include_dir)); | |
| 9143 | Buf *buff2 = buf_alloc(); | |
| 9144 | os_path_join(include_dir_parent, buf_create_from_str("shared"), buff2); | |
| 9145 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buff2); | |
| 9141 | 9146 | g->libc_include_dir_len += 1; |
| 9142 | 9147 | } |
| 9143 | 9148 | assert(g->libc_include_dir_len == dir_count); |
| ... | ... | @@ -10546,11 +10551,11 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { |
| 10546 | 10551 | cache_list_of_str(ch, g->lib_dirs.items, g->lib_dirs.length); |
| 10547 | 10552 | cache_list_of_str(ch, g->framework_dirs.items, g->framework_dirs.length); |
| 10548 | 10553 | if (g->libc) { |
| 10549 | cache_str(ch, g->libc->include_dir); | |
| 10550 | cache_str(ch, g->libc->sys_include_dir); | |
| 10551 | cache_str(ch, g->libc->crt_dir); | |
| 10552 | cache_str(ch, g->libc->msvc_lib_dir); | |
| 10553 | cache_str(ch, g->libc->kernel32_lib_dir); | |
| 10554 | cache_slice(ch, Slice<const char>{g->libc->include_dir, g->libc->include_dir_len}); | |
| 10555 | cache_slice(ch, Slice<const char>{g->libc->sys_include_dir, g->libc->sys_include_dir_len}); | |
| 10556 | cache_slice(ch, Slice<const char>{g->libc->crt_dir, g->libc->crt_dir_len}); | |
| 10557 | cache_slice(ch, Slice<const char>{g->libc->msvc_lib_dir, g->libc->msvc_lib_dir_len}); | |
| 10558 | cache_slice(ch, Slice<const char>{g->libc->kernel32_lib_dir, g->libc->kernel32_lib_dir_len}); | |
| 10554 | 10559 | } |
| 10555 | 10560 | cache_buf_opt(ch, g->version_script_path); |
| 10556 | 10561 | cache_buf_opt(ch, g->override_soname); |
src/link.cpp+19-7| ... | ... | @@ -1595,7 +1595,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr |
| 1595 | 1595 | } else { |
| 1596 | 1596 | assert(parent->libc != nullptr); |
| 1597 | 1597 | Buf *out_buf = buf_alloc(); |
| 1598 | os_path_join(buf_create_from_str(parent->libc->crt_dir), buf_create_from_str(file), out_buf); | |
| 1598 | os_path_join(buf_create_from_mem(parent->libc->crt_dir, parent->libc->crt_dir_len), buf_create_from_str(file), out_buf); | |
| 1599 | 1599 | return buf_ptr(out_buf); |
| 1600 | 1600 | } |
| 1601 | 1601 | } |
| ... | ... | @@ -1860,7 +1860,7 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 1860 | 1860 | if (g->libc_link_lib != nullptr) { |
| 1861 | 1861 | if (g->libc != nullptr) { |
| 1862 | 1862 | lj->args.append("-L"); |
| 1863 | lj->args.append(g->libc->crt_dir); | |
| 1863 | lj->args.append(buf_ptr(buf_create_from_mem(g->libc->crt_dir, g->libc->crt_dir_len))); | |
| 1864 | 1864 | } |
| 1865 | 1865 | |
| 1866 | 1866 | if (g->have_dynamic_link && (is_dyn_lib || g->out_type == OutTypeExe)) { |
| ... | ... | @@ -2381,14 +2381,26 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 2381 | 2381 | lj->args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(&g->bin_file_output_path)))); |
| 2382 | 2382 | |
| 2383 | 2383 | if (g->libc_link_lib != nullptr && g->libc != nullptr) { |
| 2384 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", g->libc->crt_dir))); | |
| 2384 | Buf *buff0 = buf_create_from_str("-LIBPATH:"); | |
| 2385 | buf_append_mem(buff0, g->libc->crt_dir, g->libc->crt_dir_len); | |
| 2386 | lj->args.append(buf_ptr(buff0)); | |
| 2385 | 2387 | |
| 2386 | 2388 | if (target_abi_is_gnu(g->zig_target->abi)) { |
| 2387 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", g->libc->sys_include_dir))); | |
| 2388 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", g->libc->include_dir))); | |
| 2389 | Buf *buff1 = buf_create_from_str("-LIBPATH:"); | |
| 2390 | buf_append_mem(buff1, g->libc->sys_include_dir, g->libc->sys_include_dir_len); | |
| 2391 | lj->args.append(buf_ptr(buff1)); | |
| 2392 | ||
| 2393 | Buf *buff2 = buf_create_from_str("-LIBPATH:"); | |
| 2394 | buf_append_mem(buff2, g->libc->include_dir, g->libc->include_dir_len); | |
| 2395 | lj->args.append(buf_ptr(buff2)); | |
| 2389 | 2396 | } else { |
| 2390 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", g->libc->msvc_lib_dir))); | |
| 2391 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", g->libc->kernel32_lib_dir))); | |
| 2397 | Buf *buff1 = buf_create_from_str("-LIBPATH:"); | |
| 2398 | buf_append_mem(buff1, g->libc->msvc_lib_dir, g->libc->msvc_lib_dir_len); | |
| 2399 | lj->args.append(buf_ptr(buff1)); | |
| 2400 | ||
| 2401 | Buf *buff2 = buf_create_from_str("-LIBPATH:"); | |
| 2402 | buf_append_mem(buff2, g->libc->kernel32_lib_dir, g->libc->kernel32_lib_dir_len); | |
| 2403 | lj->args.append(buf_ptr(buff2)); | |
| 2392 | 2404 | } |
| 2393 | 2405 | } |
| 2394 | 2406 |