4 ms·
> - Compiled languages shouldn't be using text file imports as modules Zig doesn't use C-style textual includes, if that's what you mean.
by defen 5y ago
> - Compiled languages shouldn't be using text file imports as modules
Zig doesn't use C-style textual includes, if that's what you mean.
- pjmlp 5y agoSure it does, @import expects a text file that is then parsed into a struct like data structure. I expect a proper binary module, with native code and symbol table.
- flohofwoe 5y agoThe important part is that (unlike C/C++ headers) included modules can't be polluted with code that's coming before the @import(). Everything else is just an implementation detail. @import also has a second mode where the string isn't a Zig source file path, but a package name. AFAIK currently this also just resolves to a package-root zig file, but it could just as well be extended to some sort of binary format, the question is just: why?
- pjmlp 5y agoBecause many business situations we only want to distribute binary libraries. If I want to distribute source code I would be using scripting languages. It is also a nagging point for me when I play around with cargo, which contrary to conan and vcpkg, doesn't do binary libraries. By the way, C++ modules might get a binary format definition by C++26 (too little time to sort it out by C++23), based on BMI/IFC formats already being deployed in GCC and VC++ respectively.
- ayende 5y agoIn which case, you can simply use the binary. Zig make is easier to consume external code, why have a separate process for consuming binaries from Zig vs. everything else?
- pjmlp 5y agoWhere does it say @import works with binary modules?
- defen 5y agoTo do this in Zig you would ship a binary + a "header" file that looks like: `pub extern fn foo(c_int) c_int;` etc. then import with `usingnamespace @import("./my_header.zig");` and now you have a function `foo` that you can call; then you just need to link with the object file that defines it. Is your complaint that you still need the "header" file? What language / tools do you use that let you skip that part?