mirror of
https://github.com/ziglang/zig.git
synced 2025-12-25 07:33:08 +00:00
* `zig build --export [obj|lib|exe]` changed to `zig build_obj`, `zig build_lib` and `zig build_exe` respectively. * `--name` parameter is optional when it can be inferred from the root source filename. closes #207 * `zig build` now looks for `build.zig` which interacts with `std.build.Builder` to describe the targets, and then the zig build system prints TODO: build these targets. See #204 * add `@bitcast` which is mainly used for pointer reinterpret casting and make explicit casting not do pointer reinterpretation. Closes #290 * fix debug info for byval parameters * sort command line help options * `std.debug.panic` supports format string printing * add `std.mem.IncrementingAllocator` * fix const ptr to a variable with data changing at runtime. closes #289
60 lines
1.7 KiB
Zig
60 lines
1.7 KiB
Zig
const io = @import("io.zig");
|
|
const mem = @import("mem.zig");
|
|
const debug = @import("debug.zig");
|
|
const List = @import("list.zig").List;
|
|
const Allocator = @import("mem.zig").Allocator;
|
|
|
|
error ExtraArg;
|
|
|
|
pub const Builder = struct {
|
|
zig_exe: []const u8,
|
|
allocator: &Allocator,
|
|
exe_list: List(&Exe),
|
|
|
|
pub fn init(zig_exe: []const u8, allocator: &Allocator) -> Builder {
|
|
Builder {
|
|
.zig_exe = zig_exe,
|
|
.allocator = allocator,
|
|
.exe_list = List(&Exe).init(allocator),
|
|
}
|
|
}
|
|
|
|
pub fn addExe(self: &Builder, root_src: []const u8, name: []const u8) -> &Exe {
|
|
return self.addExeErr(root_src, name) %% |err| handleErr(err);
|
|
}
|
|
|
|
pub fn addExeErr(self: &Builder, root_src: []const u8, name: []const u8) -> %&Exe {
|
|
const exe = %return self.allocator.create(Exe);
|
|
*exe = Exe {
|
|
.root_src = root_src,
|
|
.name = name,
|
|
};
|
|
%return self.exe_list.append(exe);
|
|
return exe;
|
|
}
|
|
|
|
pub fn make(self: &Builder, args: []const []const u8) -> %void {
|
|
var verbose = false;
|
|
for (args) |arg| {
|
|
if (mem.eql(u8, arg, "--verbose")) {
|
|
verbose = true;
|
|
} else {
|
|
%%io.stderr.printf("Unrecognized argument: '{}'\n", arg);
|
|
return error.ExtraArg;
|
|
}
|
|
}
|
|
for (self.exe_list.toSlice()) |exe| {
|
|
%%io.stderr.printf("TODO: invoke this command:\nzig build_exe {} --name {}\n", exe.root_src, exe.name);
|
|
}
|
|
}
|
|
};
|
|
|
|
const Exe = struct {
|
|
root_src: []const u8,
|
|
name: []const u8,
|
|
};
|
|
|
|
fn handleErr(err: error) -> noreturn {
|
|
debug.panic("error: {}\n", @errorName(err));
|
|
}
|