I’m getting an error with the installArtifact function in build.zig .
The relevant part of the build script is here:
// Create an executable for the kernel
const kernel = b.addExecutable(.{
.name = "Zig-DOS-Kernel",
.root_source_file = b.path("./src/kernel/main.zig"),
.target = target,
});
kernel.addIncludePath(b.path("./lib/"));
// Install the kernel artifact.
b.installArtifact(kernel); // Problem is on this line
const std = @import("std");
pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{
.name = "hello",
.root_source_file = b.path("hello.zig"),
.target = b.host,
});
b.installArtifact(exe); // Seems to be the same syntax as my code
const run_exe = b.addRunArtifact(exe);
const run_step = b.step("run", "Run the application");
run_step.dependOn(&run_exe.step);
}
My code seems to use the identical syntax to the code in the docs so I’m assuming that the syntax for installArtifact may have changed.
Is that correct?
installArtifact copies the executable (to the path set using --prefix or to the default prefix ./zig-out/bin) when the install step is run.
You can run the install step using:
zig build install
Most times zig build run the install step, because it is the default step.
Run zig build -l to list all steps. In the listing the default step–that zig build runs–is marked as (default).
I’ve just tried doing that - running “zig build install” - but I got the same error as when I ran just “zig build” - here it is -
andy@obsidian:~/Zig-DOS$ zig build install
/home/andy/Zig-DOS/build.zig:53:6: error: no field or member function named 'installArtifact' in '@TypeOf(.enum_literal)'
b.installArtifact(kernel);
^~~~~~~~~~~~~~~~
referenced by:
runBuild__anon_8818: /home/andy/zig/lib/std/Build.zig:2116:27
main: /home/andy/zig/lib/compiler/build_runner.zig:301:29
remaining reference traces hidden; use '-freference-trace' to see all reference traces
andy@obsidian:~/Zig-DOS$
So, this has got me a bit puzzled…
Hoping you can help
Many thanks -
Yes, my build.zig starts like that, but I have an apology to make.
I found the problem. There was a period (.) at the end of a line.
I removed that and the command worked!
So - my bad - apologies for all of this!
Many thanks for your help though - this help-forum is excellent!
Thanks again, bye for now -
Update: I’m making good progress now. A few errors to do with incorrect paths but those kind of errors are easy to fix - I know what the problem is - an incorrect path earlier on in the build.zig file.
So - happy days!