aboutsummaryrefslogtreecommitdiff
path: root/std/build.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-03-31 05:48:15 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-03-31 05:55:41 -0400
commit3ca027ca8219dbdbb6467645944c4daada037f51 (patch)
tree786a6c4ecac9f11d3a60f3c14c1b4276a3adc8d6 /std/build.zig
parent536c35136ab98f2f56d07937727b3c99c0e35c5c (diff)
downloadzig-3ca027ca8219dbdbb6467645944c4daada037f51.tar.gz
zig-3ca027ca8219dbdbb6467645944c4daada037f51.zip
first pass at zig build system
* `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
Diffstat (limited to 'std/build.zig')
-rw-r--r--std/build.zig59
1 files changed, 59 insertions, 0 deletions
diff --git a/std/build.zig b/std/build.zig
new file mode 100644
index 0000000000..746800668a
--- /dev/null
+++ b/std/build.zig
@@ -0,0 +1,59 @@
+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));
+}