| ... | @@ -32,6 +32,7 @@ pub const LibCInstallation = struct { | ... | @@ -32,6 +32,7 @@ pub const LibCInstallation = struct { |
| 32 | LibCKernel32LibNotFound, | 32 | LibCKernel32LibNotFound, |
| 33 | UnsupportedArchitecture, | 33 | UnsupportedArchitecture, |
| 34 | WindowsSdkNotFound, | 34 | WindowsSdkNotFound, |
| | 35 | ZigIsTheCCompiler, |
| 35 | }; | 36 | }; |
| 36 | | 37 | |
| 37 | pub fn parse( | 38 | pub fn parse( |
| ... | @@ -229,10 +230,19 @@ pub const LibCInstallation = struct { | ... | @@ -229,10 +230,19 @@ pub const LibCInstallation = struct { |
| 229 | "-xc", | 230 | "-xc", |
| 230 | dev_null, | 231 | dev_null, |
| 231 | }; | 232 | }; |
| | 233 | var env_map = try std.process.getEnvMap(allocator); |
| | 234 | defer env_map.deinit(); |
| | 235 | |
| | 236 | // Detect infinite loops. |
| | 237 | const inf_loop_env_key = "ZIG_IS_DETECTING_LIBC_PATHS"; |
| | 238 | if (env_map.get(inf_loop_env_key) != null) return error.ZigIsTheCCompiler; |
| | 239 | try env_map.set(inf_loop_env_key, "1"); |
| | 240 | |
| 232 | const exec_res = std.ChildProcess.exec(.{ | 241 | const exec_res = std.ChildProcess.exec(.{ |
| 233 | .allocator = allocator, | 242 | .allocator = allocator, |
| 234 | .argv = &argv, | 243 | .argv = &argv, |
| 235 | .max_output_bytes = 1024 * 1024, | 244 | .max_output_bytes = 1024 * 1024, |
| | 245 | .env_map = &env_map, |
| 236 | // Some C compilers, such as Clang, are known to rely on argv[0] to find the path | 246 | // Some C compilers, such as Clang, are known to rely on argv[0] to find the path |
| 237 | // to their own executable, without even bothering to resolve PATH. This results in the message: | 247 | // to their own executable, without even bothering to resolve PATH. This results in the message: |
| 238 | // error: unable to execute command: Executable "" doesn't exist! | 248 | // error: unable to execute command: Executable "" doesn't exist! |
| ... | @@ -518,10 +528,19 @@ fn ccPrintFileName(args: CCPrintFileNameOptions) ![:0]u8 { | ... | @@ -518,10 +528,19 @@ fn ccPrintFileName(args: CCPrintFileNameOptions) ![:0]u8 { |
| 518 | defer allocator.free(arg1); | 528 | defer allocator.free(arg1); |
| 519 | const argv = [_][]const u8{ cc_exe, arg1 }; | 529 | const argv = [_][]const u8{ cc_exe, arg1 }; |
| 520 | | 530 | |
| | 531 | var env_map = try std.process.getEnvMap(allocator); |
| | 532 | defer env_map.deinit(); |
| | 533 | |
| | 534 | // Detect infinite loops. |
| | 535 | const inf_loop_env_key = "ZIG_IS_DETECTING_LIBC_PATHS"; |
| | 536 | if (env_map.get(inf_loop_env_key) != null) return error.ZigIsTheCCompiler; |
| | 537 | try env_map.set(inf_loop_env_key, "1"); |
| | 538 | |
| 521 | const exec_res = std.ChildProcess.exec(.{ | 539 | const exec_res = std.ChildProcess.exec(.{ |
| 522 | .allocator = allocator, | 540 | .allocator = allocator, |
| 523 | .argv = &argv, | 541 | .argv = &argv, |
| 524 | .max_output_bytes = 1024 * 1024, | 542 | .max_output_bytes = 1024 * 1024, |
| | 543 | .env_map = &env_map, |
| 525 | // Some C compilers, such as Clang, are known to rely on argv[0] to find the path | 544 | // Some C compilers, such as Clang, are known to rely on argv[0] to find the path |
| 526 | // to their own executable, without even bothering to resolve PATH. This results in the message: | 545 | // to their own executable, without even bothering to resolve PATH. This results in the message: |
| 527 | // error: unable to execute command: Executable "" doesn't exist! | 546 | // error: unable to execute command: Executable "" doesn't exist! |