I’m curious how self-contained @cImport
blocks really are.
If I have a file:
const c = @cImport({
@cInclude("some_header.h");
});
pub const FancyType = c.fancy_type;
const PrivateType = opaque{};
I know that when I import this file into another, FancyType
will be visible but PrivateType
won’t be. It only exists within this one file, so the Zig compiler won’t even process it while dealing with other files (right?).
Likewise, the cImport
is not public. However, I’m not sure if it gets the same treatment as Zig variables. At what point do the C headers get converted to Zig?
Whenever I get build errors regarding the imported C headers, the compiler is always referencing a cimport.zig
file in the cache. This makes it seem that the cImport
statements are actually separate from the file that contains them. Which makes me wonder if the compiler treats them special, or if after conversion they are treated like any other zig source file.
In other words, if I were to manually convert some C headers into Zig code and write them into a file (i.e. “some_headers.zig”), and then import them normally, would the end result be identical to what cImport
does?
I guess I’m trying to understand the limits of how they can get used, and why external code sometimes complains about missing C headers when they shouldn’t have even known they existed.