@import files with extensions other than .zig

when i use @import("relative_srcfile_path"), i receive a compiler error if the referenced source file does NOT have a .zig extension…

is there a way around this???

Are you looking for something like @embedFile ?

Otherwise I’m not sure why importing anything but a zig source file, would make sense. What is the use case?


The compiler has the option

 -x language               Treat subsequent input files as having type <language>

but in your case you can only add the .zig extension.

It there a reason why the file does not have the .zig extension?

1 Like

it’s a somewhat unusual use-case, but i’m effectively creating a zig-based “foo framework” in which certain .zig source files are subject to some additional constraints imposed by the framework…

this is somewhat analogous to how react/js files are marked with a .jsx extension… in my case, i’d like to have (say) a .zigfoo extension…

when i’m sitting in my favorite IDE, it’s easier on the eyeballs to have my .zigfoo sources marked with a distinct icon… long story, but extension-based icon association does NOT work with suffixes of the form .foo.zig when .zig is already defined as a file-type…

it’s not a big deal; life will go on… but perhaps someday we can at least expand .zig to .zig* to handle the “framework” use-case.

1 Like

The difference in your example is that JavaScript is an interpreter language.

Zig supports a fixed list of file extensions, documented in zig/src/main.zig at 0.12.0 · ziglang/zig · GitHub

A possible solution is to add a custom Build Step that will translate your custom file to a zig source file that can be normally built.

i’ve managed to get a distinct icon working for my .foo.zig sources – which nevertheless are still .zig files as far as the compiler is concerned…

as i suggested above, this is really the least of my problems right now :wink:

1 Like