| ... | @@ -2825,13 +2825,28 @@ fn buildOutputType( | ... | @@ -2825,13 +2825,28 @@ fn buildOutputType( |
| 2825 | break :l global_cache_directory; | 2825 | break :l global_cache_directory; |
| 2826 | } | 2826 | } |
| 2827 | if (main_pkg) |pkg| { | 2827 | if (main_pkg) |pkg| { |
| 2828 | const cache_dir_path = try pkg.root_src_directory.join(arena, &[_][]const u8{"zig-cache"}); | 2828 | // search upwards from cwd until we find directory with build.zig |
| 2829 | const dir = try pkg.root_src_directory.handle.makeOpenPath("zig-cache", .{}); | 2829 | const cwd_path = try process.getCwdAlloc(arena); |
| 2830 | cleanup_local_cache_dir = dir; | 2830 | const build_zig = "build.zig"; |
| 2831 | break :l .{ | 2831 | const zig_cache = "zig-cache"; |
| 2832 | .handle = dir, | 2832 | var dirname: []const u8 = cwd_path; |
| 2833 | .path = cache_dir_path, | 2833 | while (true) { |
| 2834 | }; | 2834 | const joined_path = try fs.path.join(arena, &[_][]const u8{ dirname, build_zig }); |
| | 2835 | if (fs.cwd().access(joined_path, .{})) |_| { |
| | 2836 | const cache_dir_path = try fs.path.join(arena, &[_][]const u8{ dirname, zig_cache }); |
| | 2837 | const dir = try pkg.root_src_directory.handle.makeOpenPath(cache_dir_path, .{}); |
| | 2838 | cleanup_local_cache_dir = dir; |
| | 2839 | break :l .{ .handle = dir, .path = cache_dir_path }; |
| | 2840 | } else |err| switch (err) { |
| | 2841 | error.FileNotFound => { |
| | 2842 | dirname = fs.path.dirname(dirname) orelse { |
| | 2843 | break :l global_cache_directory; |
| | 2844 | }; |
| | 2845 | continue; |
| | 2846 | }, |
| | 2847 | else => break :l global_cache_directory, |
| | 2848 | } |
| | 2849 | } |
| 2835 | } | 2850 | } |
| 2836 | // Otherwise we really don't have a reasonable place to put the local cache directory, | 2851 | // Otherwise we really don't have a reasonable place to put the local cache directory, |
| 2837 | // so we utilize the global one. | 2852 | // so we utilize the global one. |