| ... | @@ -4831,10 +4831,8 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi | ... | @@ -4831,10 +4831,8 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 4831 | .root = .{ .root_dir = build_root }, | 4831 | .root = .{ .root_dir = build_root }, |
| 4832 | .root_src_path = build_zig_basename, | 4832 | .root_src_path = build_zig_basename, |
| 4833 | }; | 4833 | }; |
| 4834 | var dependencies_zig_src = std.ArrayList(u8).init(gpa); | | |
| 4835 | defer dependencies_zig_src.deinit(); | | |
| 4836 | if (build_options.only_core_functionality) { | 4834 | if (build_options.only_core_functionality) { |
| 4837 | try Package.Fetch.createEmptyDependenciesModule(&dependencies_zig_src); | 4835 | try createEmptyDependenciesModule(arena, &main_mod, local_cache_directory); |
| 4838 | } else { | 4836 | } else { |
| 4839 | var http_client: std.http.Client = .{ .allocator = gpa }; | 4837 | var http_client: std.http.Client = .{ .allocator = gpa }; |
| 4840 | defer http_client.deinit(); | 4838 | defer http_client.deinit(); |
| ... | @@ -4890,40 +4888,16 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi | ... | @@ -4890,40 +4888,16 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 4890 | | 4888 | |
| 4891 | if (fetch_only) return cleanExit(); | 4889 | if (fetch_only) return cleanExit(); |
| 4892 | | 4890 | |
| 4893 | try job_queue.createDependenciesModule(&dependencies_zig_src); | 4891 | var source_buf = std.ArrayList(u8).init(gpa); |
| 4894 | | 4892 | defer source_buf.deinit(); |
| 4895 | const deps_mod = m: { | 4893 | try job_queue.createDependenciesSource(&source_buf); |
| 4896 | // Atomically create the file in a directory named after the hash of its contents. | 4894 | const deps_mod = try createDependenciesModule( |
| 4897 | const basename = "dependencies.zig"; | 4895 | arena, |
| 4898 | const rand_int = std.crypto.random.int(u64); | 4896 | source_buf.items, |
| 4899 | const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ | 4897 | &main_mod, |
| 4900 | Package.Manifest.hex64(rand_int); | 4898 | local_cache_directory, |
| 4901 | { | 4899 | ); |
| 4902 | var tmp_dir = try local_cache_directory.handle.makeOpenPath(tmp_dir_sub_path, .{}); | | |
| 4903 | defer tmp_dir.close(); | | |
| 4904 | try tmp_dir.writeFile(basename, dependencies_zig_src.items); | | |
| 4905 | } | | |
| 4906 | | 4900 | |
| 4907 | var hh: Cache.HashHelper = .{}; | | |
| 4908 | hh.addBytes(build_options.version); | | |
| 4909 | hh.addBytes(dependencies_zig_src.items); | | |
| 4910 | const hex_digest = hh.final(); | | |
| 4911 | | | |
| 4912 | const o_dir_sub_path = try arena.dupe(u8, "o" ++ fs.path.sep_str ++ hex_digest); | | |
| 4913 | try Package.Fetch.renameTmpIntoCache( | | |
| 4914 | local_cache_directory.handle, | | |
| 4915 | tmp_dir_sub_path, | | |
| 4916 | o_dir_sub_path, | | |
| 4917 | ); | | |
| 4918 | | | |
| 4919 | break :m try Package.Module.create(arena, .{ | | |
| 4920 | .root = .{ | | |
| 4921 | .root_dir = local_cache_directory, | | |
| 4922 | .sub_path = o_dir_sub_path, | | |
| 4923 | }, | | |
| 4924 | .root_src_path = basename, | | |
| 4925 | }); | | |
| 4926 | }; | | |
| 4927 | { | 4901 | { |
| 4928 | // We need a Module for each package's build.zig. | 4902 | // We need a Module for each package's build.zig. |
| 4929 | const hashes = job_queue.table.keys(); | 4903 | const hashes = job_queue.table.keys(); |
| ... | @@ -4944,7 +4918,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi | ... | @@ -4944,7 +4918,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 4944 | deps_mod.deps.putAssumeCapacityNoClobber(hash_cloned, m); | 4918 | deps_mod.deps.putAssumeCapacityNoClobber(hash_cloned, m); |
| 4945 | } | 4919 | } |
| 4946 | } | 4920 | } |
| 4947 | try main_mod.deps.put(arena, "@dependencies", deps_mod); | | |
| 4948 | } | 4921 | } |
| 4949 | | 4922 | |
| 4950 | try main_mod.deps.put(arena, "@build", &build_mod); | 4923 | try main_mod.deps.put(arena, "@build", &build_mod); |
| ... | @@ -6795,3 +6768,55 @@ fn cmdFetch( | ... | @@ -6795,3 +6768,55 @@ fn cmdFetch( |
| 6795 | | 6768 | |
| 6796 | return cleanExit(); | 6769 | return cleanExit(); |
| 6797 | } | 6770 | } |
| | 6771 | |
| | 6772 | fn createEmptyDependenciesModule( |
| | 6773 | arena: Allocator, |
| | 6774 | main_mod: *Package.Module, |
| | 6775 | local_cache_directory: Cache.Directory, |
| | 6776 | ) !void { |
| | 6777 | var source = std.ArrayList(u8).init(arena); |
| | 6778 | try Package.Fetch.JobQueue.createEmptyDependenciesSource(&source); |
| | 6779 | _ = try createDependenciesModule(arena, source.items, main_mod, local_cache_directory); |
| | 6780 | } |
| | 6781 | |
| | 6782 | /// Creates the dependencies.zig file and corresponding `Package.Module` for the |
| | 6783 | /// build runner to obtain via `@import("@dependencies")`. |
| | 6784 | fn createDependenciesModule( |
| | 6785 | arena: Allocator, |
| | 6786 | source: []const u8, |
| | 6787 | main_mod: *Package.Module, |
| | 6788 | local_cache_directory: Cache.Directory, |
| | 6789 | ) !*Package.Module { |
| | 6790 | // Atomically create the file in a directory named after the hash of its contents. |
| | 6791 | const basename = "dependencies.zig"; |
| | 6792 | const rand_int = std.crypto.random.int(u64); |
| | 6793 | const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ |
| | 6794 | Package.Manifest.hex64(rand_int); |
| | 6795 | { |
| | 6796 | var tmp_dir = try local_cache_directory.handle.makeOpenPath(tmp_dir_sub_path, .{}); |
| | 6797 | defer tmp_dir.close(); |
| | 6798 | try tmp_dir.writeFile(basename, source); |
| | 6799 | } |
| | 6800 | |
| | 6801 | var hh: Cache.HashHelper = .{}; |
| | 6802 | hh.addBytes(build_options.version); |
| | 6803 | hh.addBytes(source); |
| | 6804 | const hex_digest = hh.final(); |
| | 6805 | |
| | 6806 | const o_dir_sub_path = try arena.dupe(u8, "o" ++ fs.path.sep_str ++ hex_digest); |
| | 6807 | try Package.Fetch.renameTmpIntoCache( |
| | 6808 | local_cache_directory.handle, |
| | 6809 | tmp_dir_sub_path, |
| | 6810 | o_dir_sub_path, |
| | 6811 | ); |
| | 6812 | |
| | 6813 | const deps_mod = try Package.Module.create(arena, .{ |
| | 6814 | .root = .{ |
| | 6815 | .root_dir = local_cache_directory, |
| | 6816 | .sub_path = o_dir_sub_path, |
| | 6817 | }, |
| | 6818 | .root_src_path = basename, |
| | 6819 | }); |
| | 6820 | try main_mod.deps.put(arena, "@dependencies", deps_mod); |
| | 6821 | return deps_mod; |
| | 6822 | } |