Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
move zig objcopy command to be lazily built
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk authored and RossComputerGuy committed Mar 20, 2024
1 parent 26a28de commit 7c90e44
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
23 changes: 17 additions & 6 deletions src/objcopy.zig → lib/compiler/objcopy.zig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const builtin = @import("builtin");
const std = @import("std");
const mem = std.mem;
const fs = std.fs;
Expand All @@ -6,12 +7,22 @@ const Allocator = std.mem.Allocator;
const File = std.fs.File;
const assert = std.debug.assert;

const main = @import("main.zig");
const fatal = main.fatal;
const fatal = std.zig.fatal;
const Server = std.zig.Server;
const build_options = @import("build_options");

pub fn cmdObjCopy(
pub fn main() !void {
var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena_instance.deinit();
const arena = arena_instance.allocator();

var general_purpose_allocator: std.heap.GeneralPurposeAllocator(.{}) = .{};
const gpa = general_purpose_allocator.allocator();

const args = try std.process.argsAlloc(arena);
return cmdObjCopy(gpa, arena, args[1..]);
}

fn cmdObjCopy(
gpa: Allocator,
arena: Allocator,
args: []const []const u8,
Expand Down Expand Up @@ -148,7 +159,7 @@ pub fn cmdObjCopy(
});
},
.elf => {
if (elf_hdr.endian != @import("builtin").target.cpu.arch.endian())
if (elf_hdr.endian != builtin.target.cpu.arch.endian())
fatal("zig objcopy: ELF to ELF copying only supports native endian", .{});
if (elf_hdr.phoff == 0) // no program header
fatal("zig objcopy: ELF to ELF copying only supports programs", .{});
Expand All @@ -175,7 +186,7 @@ pub fn cmdObjCopy(
.gpa = gpa,
.in = std.io.getStdIn(),
.out = std.io.getStdOut(),
.zig_version = build_options.version,
.zig_version = builtin.zig_version_string,
});
defer server.deinit();

Expand Down
5 changes: 4 additions & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
.root_src_path = "fmt.zig",
});
} else if (mem.eql(u8, cmd, "objcopy")) {
return @import("objcopy.zig").cmdObjCopy(gpa, arena, cmd_args);
return jitCmd(gpa, arena, cmd_args, .{
.cmd_name = "objcopy",
.root_src_path = "objcopy.zig",
});
} else if (mem.eql(u8, cmd, "fetch")) {
return cmdFetch(gpa, arena, cmd_args);
} else if (mem.eql(u8, cmd, "libc")) {
Expand Down

0 comments on commit 7c90e44

Please sign in to comment.