Error when trying to add assembly file to small Zig OS project

Hi all -
I’m working on a small OS mostly written in Zig but with a small amount of assembly. I’m using Zig 0.14.0-dev .

Here is the error I’m getting -

andy@obsidian:~/Zig-DOS$ zig build
/home/andy/Zig-DOS/build.zig:47:28: error: expected type ‘Build.LazyPath’, found ‘*const [36:0]u8’
kernel.addAssemblyFile(“./src/kernel/kernel_asm/interrupts.s”);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/andy/zig/lib/std/Build.zig:2171:22: note: union declared here
pub const LazyPath = union(enum) {
^~~~~
/home/andy/zig/lib/std/Build/Step/Compile.zig:873:51: note: parameter type declared here
pub fn addAssemblyFile(compile: *Compile, source: LazyPath) void {
^~~~~~~~
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$

The statement creating the error is this -

kernel.addAssemblyFile(“./src/kernel/kernel_asm/interrupts.s”);

This is the addAssemblyFile function in the Zig source code -

pub fn addAssemblyFile(self: *LibExeObjStep, path: const u8) void {
self.link_objects.append(.{
.assembly_file = .{ .path = self.builder.dupe(path) },
}) catch unreachable;
}

I tried to make sense of that function as it relates to the statement but I’m having problems understanding how my statement is wrong.
Hoping someone may be able to help - many thanks in advance.

  • mooseman

Your “addAssemblyFile” function looks wrong. Its path parameter is a LazyType, as we can see in the std docs.

So you should do kernel.addAssemblyFile(b.path("src/kernel/kernel_asm/interrupts.s"));.
And, by the way, you can just embed the assembly using asm volatile. I did that a lot in my kernel and as of now, I have not a single raw assembly file.

2 Likes

Hi samuel-fiedler - thanks very much for your reply!
I’ll try that corrected snippet and see how I go.

Many thanks - bye for now -

( Update : It worked! Awesome! Thanks again… :slightly_smiling_face: )

  • mooseman