| ... | @@ -906,6 +906,9 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -906,6 +906,9 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 906 | artifact_sub_dir, | 906 | artifact_sub_dir, |
| 907 | }; | 907 | }; |
| 908 | | 908 | |
| | 909 | const builtin_pkg = try Package.create(gpa, zig_cache_artifact_directory.path.?, "builtin2.zig"); |
| | 910 | try root_pkg.add(gpa, "builtin", builtin_pkg); |
| | 911 | |
| 909 | // TODO when we implement serialization and deserialization of incremental compilation metadata, | 912 | // TODO when we implement serialization and deserialization of incremental compilation metadata, |
| 910 | // this is where we would load it. We have open a handle to the directory where | 913 | // this is where we would load it. We have open a handle to the directory where |
| 911 | // the output either already is, or will be. | 914 | // the output either already is, or will be. |
| ... | @@ -2822,6 +2825,11 @@ fn updateBuiltinZigFile(comp: *Compilation, mod: *Module) !void { | ... | @@ -2822,6 +2825,11 @@ fn updateBuiltinZigFile(comp: *Compilation, mod: *Module) !void { |
| 2822 | const source = try comp.generateBuiltinZigSource(comp.gpa); | 2825 | const source = try comp.generateBuiltinZigSource(comp.gpa); |
| 2823 | defer comp.gpa.free(source); | 2826 | defer comp.gpa.free(source); |
| 2824 | try mod.zig_cache_artifact_directory.handle.writeFile("builtin.zig", source); | 2827 | try mod.zig_cache_artifact_directory.handle.writeFile("builtin.zig", source); |
| | 2828 | |
| | 2829 | // FIXME: Remove builtin2.zig when stage2 can correctly generate code for builtin.zig! |
| | 2830 | const source2 = try comp.generateBuiltin2ZigSource(comp.gpa); |
| | 2831 | defer comp.gpa.free(source2); |
| | 2832 | try mod.zig_cache_artifact_directory.handle.writeFile("builtin2.zig", source2); |
| 2825 | } | 2833 | } |
| 2826 | | 2834 | |
| 2827 | pub fn dump_argv(argv: []const []const u8) void { | 2835 | pub fn dump_argv(argv: []const []const u8) void { |
| ... | @@ -2831,6 +2839,26 @@ pub fn dump_argv(argv: []const []const u8) void { | ... | @@ -2831,6 +2839,26 @@ pub fn dump_argv(argv: []const []const u8) void { |
| 2831 | std.debug.print("{s}\n", .{argv[argv.len - 1]}); | 2839 | std.debug.print("{s}\n", .{argv[argv.len - 1]}); |
| 2832 | } | 2840 | } |
| 2833 | | 2841 | |
| | 2842 | fn generateBuiltin2ZigSource(comp: *Compilation, allocator: *Allocator) ![]u8 { |
| | 2843 | var buffer = std.ArrayList(u8).init(allocator); |
| | 2844 | defer buffer.deinit(); |
| | 2845 | |
| | 2846 | const target = comp.getTarget(); |
| | 2847 | |
| | 2848 | try buffer.writer().print( |
| | 2849 | \\pub const link_libc = {}; |
| | 2850 | \\pub const arch = {}; |
| | 2851 | \\pub const os = {}; |
| | 2852 | \\ |
| | 2853 | , .{ |
| | 2854 | comp.bin_file.options.link_libc, |
| | 2855 | @enumToInt(target.cpu.arch), |
| | 2856 | @enumToInt(target.os.tag), |
| | 2857 | }); |
| | 2858 | |
| | 2859 | return buffer.toOwnedSlice(); |
| | 2860 | } |
| | 2861 | |
| 2834 | pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8 { | 2862 | pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) ![]u8 { |
| 2835 | const tracy = trace(@src()); | 2863 | const tracy = trace(@src()); |
| 2836 | defer tracy.end(); | 2864 | defer tracy.end(); |