incremental: handle @embedFile

Uses of `@embedFile` register dependencies on the corresponding
`Zcu.EmbedFile`. At the start of every update, we iterate all embedded
files and update them if necessary, and invalidate the dependencies if
they changed.

In order to properly integrate with the lazy analysis model, failed
embed files are now reported by the `AnalUnit` which actually used
`@embedFile`; the filesystem error is stored in the `Zcu.EmbedFile`.

An incremental test is added covering incremental updates to embedded
files, and I have verified locally that dependency invalidation is
working correctly.
This commit is contained in:
mlugg
2025-01-25 04:48:16 +00:00
parent 5202c977d9
commit f47b8de2ad
7 changed files with 265 additions and 169 deletions

View File

@@ -0,0 +1,46 @@
#target=x86_64-linux-selfhosted
#target=x86_64-linux-cbe
#target=x86_64-windows-cbe
#target=wasm32-wasi-selfhosted
#update=initial version
#file=main.zig
const std = @import("std");
const string = @embedFile("string.txt");
pub fn main() !void {
try std.io.getStdOut().writeAll(string);
}
#file=string.txt
Hello, World!
#expect_stdout="Hello, World!\n"
#update=change file contents
#file=string.txt
Hello again, World!
#expect_stdout="Hello again, World!\n"
#update=delete file
#rm_file=string.txt
#expect_error=ignored
#update=remove reference to file
#file=main.zig
const std = @import("std");
const string = @embedFile("string.txt");
pub fn main() !void {
try std.io.getStdOut().writeAll("a hardcoded string\n");
}
#expect_stdout="a hardcoded string\n"
#update=re-introduce reference to file
#file=main.zig
const std = @import("std");
const string = @embedFile("string.txt");
pub fn main() !void {
try std.io.getStdOut().writeAll(string);
}
#expect_error=ignore
#update=recreate file
#file=string.txt
We're back, World!
#expect_stdout="We're back, World!\n"