Skip to content

Commit 81c27c7

Browse files
committed
use build.zig.zon instead of build.zig.ini for the manifest file
* 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
1 parent 873bb29 commit 81c27c7

File tree

8 files changed

+665
-224
lines changed

8 files changed

+665
-224
lines changed

lib/std/Build.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -1496,8 +1496,8 @@ pub fn dependency(b: *Build, name: []const u8, args: anytype) *Dependency {
14961496
}
14971497
}
14981498

1499-
const full_path = b.pathFromRoot("build.zig.ini");
1500-
std.debug.print("no dependency named '{s}' in '{s}'\n", .{ name, full_path });
1499+
const full_path = b.pathFromRoot("build.zig.zon");
1500+
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 });
15011501
std.process.exit(1);
15021502
}
15031503

lib/std/array_hash_map.zig

+2-1
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,8 @@ pub fn ArrayHashMapUnmanaged(
11451145
}
11461146

11471147
/// Create a copy of the hash map which can be modified separately.
1148-
/// The copy uses the same context and allocator as this instance.
1148+
/// The copy uses the same context as this instance, but is allocated
1149+
/// with the provided allocator.
11491150
pub fn clone(self: Self, allocator: Allocator) !Self {
11501151
if (@sizeOf(ByIndexContext) != 0)
11511152
@compileError("Cannot infer context " ++ @typeName(Context) ++ ", call cloneContext instead.");

lib/std/zig/Ast.zig

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
//! Abstract Syntax Tree for Zig source code.
2+
//! For Zig syntax, the root node is at nodes[0] and contains the list of
3+
//! sub-nodes.
4+
//! For Zon syntax, the root node is at nodes[0] and contains lhs as the node
5+
//! index of the main expression.
26

37
/// Reference to externally-owned data.
48
source: [:0]const u8,

lib/std/zig/Parse.zig

+11-2
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,26 @@ pub fn parseRoot(p: *Parse) !void {
181181
/// TODO: set a flag in Parse struct, and honor that flag
182182
/// by emitting compilation errors when non-zon nodes are encountered.
183183
pub fn parseZon(p: *Parse) !void {
184-
const node_index = p.parseExpr() catch |err| switch (err) {
184+
// We must use index 0 so that 0 can be used as null elsewhere.
185+
p.nodes.appendAssumeCapacity(.{
186+
.tag = .root,
187+
.main_token = 0,
188+
.data = undefined,
189+
});
190+
const node_index = p.expectExpr() catch |err| switch (err) {
185191
error.ParseError => {
186192
assert(p.errors.items.len > 0);
187193
return;
188194
},
189195
else => |e| return e,
190196
};
191-
assert(node_index == 0);
192197
if (p.token_tags[p.tok_i] != .eof) {
193198
try p.warnExpected(.eof);
194199
}
200+
p.nodes.items(.data)[0] = .{
201+
.lhs = node_index,
202+
.rhs = undefined,
203+
};
195204
}
196205

197206
/// ContainerMembers <- ContainerDeclarations (ContainerField COMMA)* (ContainerField / ContainerDeclarations)

src/Compilation.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ pub const AllErrors = struct {
385385
count: u32 = 1,
386386
/// Does not include the trailing newline.
387387
source_line: ?[]const u8,
388-
notes: []Message = &.{},
388+
notes: []const Message = &.{},
389389
reference_trace: []Message = &.{},
390390

391391
/// Splits the error message up into lines to properly indent them

0 commit comments

Comments
 (0)