Hi all - first-timer here and very much enjoying using Zig!
I’m creating a small OS and I’ve got an error with my build script while trying to build the code -
"error: no field or member function named ‘setTarget’ in ‘Build.Step.Compile’ "
My Zig version is 0.12.0-dev.2811+3cafb9655 and I’m developing on Linux.
The block of code causing the problem is here -
kernel.linkLibC();
kernel.setTarget(b.standardTargetOptions(.{})); // <------ error is here
kernel.install();
However, if you want to work with the target after creating the compile step, you can use kernel.root_module.resolved_target (and set that field directly).
Finally, if you’re interested in learning more about the build system, there’s an official guide here: Zig Build System ⚡ Zig Programming Language You might find some of the more advanced topics helpful as you get further along in your project.
Not quite, the target is expected to be a ResolvedTarget, which provides the build system with quite a few bits of information about the build target, including the CPU architecture and operating system.
You can get a ResolvedTarget for a target of your choice by using b.resolveTargetQuery. For example, since you’re making your own OS for x86-64, you’ll need a freestanding target (no OS), which will look like this:
Update: I tried that and it seemed to work! (Well, Zig didn’t complain about it anyway… )
Sorry for the many questions. I’m very used to Makefiles and am comfortable with them - it just takes a while to get used to the new build system in Zig…
I’m off to bed soon, so I’ll see you all again tomorrow - thanks to all for your help!
Cheers -
Thanks for mentioning my article. This is my record when I tried to write a toy kernel in the past. If it is wrong or outdated, please call me directly.
Hi dimdin and yingyi - thanks for that, that’s awesome!
Looks like a great tutorial there too, yingyi - many thanks for doing that!
I am absolutely hooked on Zig! It is sooooo much faster developing inj Zig rather than C as you don’t have to mess around with header files!
The whole language (from the syntax to the build build process) seems to have been really well thought-out. Beautifully designed!