Skip to content

Commit

Permalink
use build.zig.zon instead of build.zig.ini for the manifest file
Browse files Browse the repository at this point in the history
 * improve error message when build manifest file is missing
 * update std.zig.Ast to support ZON
 * Compilation.AllErrors.Message: make the notes field a const slice
 * move build manifest parsing logic into src/Manifest.zig and add more
   checks, and make the checks integrate into the standard error
   reporting code so that reported errors look sexy

closes #14290
  • Loading branch information
andrewrk committed Feb 3, 2023
1 parent 873bb29 commit 81c27c7
Show file tree
Hide file tree
Showing 8 changed files with 665 additions and 224 deletions.
4 changes: 2 additions & 2 deletions lib/std/Build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1496,8 +1496,8 @@ pub fn dependency(b: *Build, name: []const u8, args: anytype) *Dependency {
}
}

const full_path = b.pathFromRoot("build.zig.ini");
std.debug.print("no dependency named '{s}' in '{s}'\n", .{ name, full_path });
const full_path = b.pathFromRoot("build.zig.zon");
std.debug.print("no dependency named '{s}' in '{s}'. All packages used in build.zig must be declared in this file.\n", .{ name, full_path });
std.process.exit(1);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/std/array_hash_map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,8 @@ pub fn ArrayHashMapUnmanaged(
}

/// Create a copy of the hash map which can be modified separately.
/// The copy uses the same context and allocator as this instance.
/// The copy uses the same context as this instance, but is allocated
/// with the provided allocator.
pub fn clone(self: Self, allocator: Allocator) !Self {
if (@sizeOf(ByIndexContext) != 0)
@compileError("Cannot infer context " ++ @typeName(Context) ++ ", call cloneContext instead.");
Expand Down
4 changes: 4 additions & 0 deletions lib/std/zig/Ast.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
//! Abstract Syntax Tree for Zig source code.
//! For Zig syntax, the root node is at nodes[0] and contains the list of
//! sub-nodes.
//! For Zon syntax, the root node is at nodes[0] and contains lhs as the node
//! index of the main expression.

/// Reference to externally-owned data.
source: [:0]const u8,
Expand Down
13 changes: 11 additions & 2 deletions lib/std/zig/Parse.zig
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,26 @@ pub fn parseRoot(p: *Parse) !void {
/// TODO: set a flag in Parse struct, and honor that flag
/// by emitting compilation errors when non-zon nodes are encountered.
pub fn parseZon(p: *Parse) !void {
const node_index = p.parseExpr() catch |err| switch (err) {
// We must use index 0 so that 0 can be used as null elsewhere.
p.nodes.appendAssumeCapacity(.{
.tag = .root,
.main_token = 0,
.data = undefined,
});
const node_index = p.expectExpr() catch |err| switch (err) {
error.ParseError => {
assert(p.errors.items.len > 0);
return;
},
else => |e| return e,
};
assert(node_index == 0);
if (p.token_tags[p.tok_i] != .eof) {
try p.warnExpected(.eof);
}
p.nodes.items(.data)[0] = .{
.lhs = node_index,
.rhs = undefined,
};
}

/// ContainerMembers <- ContainerDeclarations (ContainerField COMMA)* (ContainerField / ContainerDeclarations)
Expand Down
2 changes: 1 addition & 1 deletion src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ pub const AllErrors = struct {
count: u32 = 1,
/// Does not include the trailing newline.
source_line: ?[]const u8,
notes: []Message = &.{},
notes: []const Message = &.{},
reference_trace: []Message = &.{},

/// Splits the error message up into lines to properly indent them
Expand Down
Loading

0 comments on commit 81c27c7

Please sign in to comment.