| author | |
| committer | |
| log | 2c882b2e651386399fd48c24302fd2d4ba430ef3 |
| tree | b8d3299504b4dd3dceae45a912f720e1d5461831 |
| parent | dff1ac1089dd8a7cae5c167bdb4e6269c9b84bb6 |
| signature |
5 files changed, 14 insertions(+), 11 deletions(-)
lib/std/target.zig+1| ... | ... | @@ -435,6 +435,7 @@ pub const Target = struct { |
| 435 | 435 | elf, |
| 436 | 436 | macho, |
| 437 | 437 | wasm, |
| 438 | c, | |
| 438 | 439 | }; |
| 439 | 440 | |
| 440 | 441 | pub const SubSystem = enum { |
src-self-hosted/Module.zig-2| ... | ... | @@ -723,7 +723,6 @@ pub const InitOptions = struct { |
| 723 | 723 | object_format: ?std.builtin.ObjectFormat = null, |
| 724 | 724 | optimize_mode: std.builtin.Mode = .Debug, |
| 725 | 725 | keep_source_files_loaded: bool = false, |
| 726 | cbe: bool = false, | |
| 727 | 726 | }; |
| 728 | 727 | |
| 729 | 728 | pub fn init(gpa: *Allocator, options: InitOptions) !Module { |
| ... | ... | @@ -733,7 +732,6 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module { |
| 733 | 732 | .output_mode = options.output_mode, |
| 734 | 733 | .link_mode = options.link_mode orelse .Static, |
| 735 | 734 | .object_format = options.object_format orelse options.target.getObjectFormat(), |
| 736 | .cbe = options.cbe, | |
| 737 | 735 | }); |
| 738 | 736 | errdefer bin_file.destroy(); |
| 739 | 737 |
src-self-hosted/link.zig+5-3| ... | ... | @@ -22,7 +22,6 @@ pub const Options = struct { |
| 22 | 22 | /// Used for calculating how much space to reserve for executable program code in case |
| 23 | 23 | /// the binary file deos not already have such a section. |
| 24 | 24 | program_code_size_hint: u64 = 256 * 1024, |
| 25 | cbe: bool = false, | |
| 26 | 25 | }; |
| 27 | 26 | |
| 28 | 27 | /// Attempts incremental linking, if the file already exists. |
| ... | ... | @@ -35,10 +34,11 @@ pub fn openBinFilePath( |
| 35 | 34 | sub_path: []const u8, |
| 36 | 35 | options: Options, |
| 37 | 36 | ) !*File { |
| 38 | const file = try dir.createFile(sub_path, .{ .truncate = options.cbe, .read = true, .mode = determineMode(options) }); | |
| 37 | const cbe = options.object_format == .c; | |
| 38 | const file = try dir.createFile(sub_path, .{ .truncate = cbe, .read = true, .mode = determineMode(options) }); | |
| 39 | 39 | errdefer file.close(); |
| 40 | 40 | |
| 41 | if (options.cbe) { | |
| 41 | if (cbe) { | |
| 42 | 42 | var bin_file = try allocator.create(File.C); |
| 43 | 43 | errdefer allocator.destroy(bin_file); |
| 44 | 44 | bin_file.* = try openCFile(allocator, file, options); |
| ... | ... | @@ -1573,6 +1573,7 @@ pub fn createElfFile(allocator: *Allocator, file: fs.File, options: Options) !Fi |
| 1573 | 1573 | .Lib => return error.TODOImplementWritingLibFiles, |
| 1574 | 1574 | } |
| 1575 | 1575 | switch (options.object_format) { |
| 1576 | .c => unreachable, | |
| 1576 | 1577 | .unknown => unreachable, // TODO remove this tag from the enum |
| 1577 | 1578 | .coff => return error.TODOImplementWritingCOFF, |
| 1578 | 1579 | .elf => {}, |
| ... | ... | @@ -1632,6 +1633,7 @@ fn openBinFileInner(allocator: *Allocator, file: fs.File, options: Options) !Fil |
| 1632 | 1633 | } |
| 1633 | 1634 | switch (options.object_format) { |
| 1634 | 1635 | .unknown => unreachable, // TODO remove this tag from the enum |
| 1636 | .c => unreachable, | |
| 1635 | 1637 | .coff => return error.IncrFailed, |
| 1636 | 1638 | .elf => {}, |
| 1637 | 1639 | .macho => return error.IncrFailed, |
src-self-hosted/main.zig+7-5| ... | ... | @@ -194,8 +194,8 @@ fn buildOutputType( |
| 194 | 194 | var emit_zir: Emit = .no; |
| 195 | 195 | var target_arch_os_abi: []const u8 = "native"; |
| 196 | 196 | var target_mcpu: ?[]const u8 = null; |
| 197 | var cbe: bool = false; | |
| 198 | 197 | var target_dynamic_linker: ?[]const u8 = null; |
| 198 | var object_format: ?std.builtin.ObjectFormat = null; | |
| 199 | 199 | |
| 200 | 200 | var system_libs = std.ArrayList([]const u8).init(gpa); |
| 201 | 201 | defer system_libs.deinit(); |
| ... | ... | @@ -283,7 +283,11 @@ fn buildOutputType( |
| 283 | 283 | i += 1; |
| 284 | 284 | target_mcpu = args[i]; |
| 285 | 285 | } else if (mem.eql(u8, arg, "--c")) { |
| 286 | cbe = true; | |
| 286 | if (object_format) |old| { | |
| 287 | std.debug.print("attempted to override object format {} with C\n", .{old}); | |
| 288 | process.exit(1); | |
| 289 | } | |
| 290 | object_format = .c; | |
| 287 | 291 | } else if (mem.startsWith(u8, arg, "-mcpu=")) { |
| 288 | 292 | target_mcpu = arg["-mcpu=".len..]; |
| 289 | 293 | } else if (mem.eql(u8, arg, "--dynamic-linker")) { |
| ... | ... | @@ -417,7 +421,6 @@ fn buildOutputType( |
| 417 | 421 | else => |e| return e, |
| 418 | 422 | }; |
| 419 | 423 | |
| 420 | const object_format: ?std.builtin.ObjectFormat = null; | |
| 421 | 424 | var target_info = try std.zig.system.NativeTargetInfo.detect(gpa, cross_target); |
| 422 | 425 | if (target_info.cpu_detection_unimplemented) { |
| 423 | 426 | // TODO We want to just use detected_info.target but implementing |
| ... | ... | @@ -436,7 +439,7 @@ fn buildOutputType( |
| 436 | 439 | std.debug.print("-fno-emit-bin not supported yet", .{}); |
| 437 | 440 | process.exit(1); |
| 438 | 441 | }, |
| 439 | .yes_default_path => if (cbe) | |
| 442 | .yes_default_path => if (object_format != null and object_format.? == .c) | |
| 440 | 443 | try std.fmt.allocPrint(arena, "{}.c", .{root_name}) |
| 441 | 444 | else |
| 442 | 445 | try std.zig.binNameAlloc(arena, root_name, target_info.target, output_mode, link_mode), |
| ... | ... | @@ -470,7 +473,6 @@ fn buildOutputType( |
| 470 | 473 | .object_format = object_format, |
| 471 | 474 | .optimize_mode = build_mode, |
| 472 | 475 | .keep_source_files_loaded = zir_out_path != null, |
| 473 | .cbe = cbe, | |
| 474 | 476 | }); |
| 475 | 477 | defer module.deinit(); |
| 476 | 478 |
src-self-hosted/test.zig+1-1| ... | ... | @@ -444,7 +444,7 @@ pub const TestContext = struct { |
| 444 | 444 | .bin_file_path = bin_name, |
| 445 | 445 | .root_pkg = root_pkg, |
| 446 | 446 | .keep_source_files_loaded = true, |
| 447 | .cbe = case.cbe, | |
| 447 | .object_format = if (case.cbe) .c else null, | |
| 448 | 448 | }); |
| 449 | 449 | defer module.deinit(); |
| 450 | 450 |