4 ms·
@cImport works without build.zig and even with build.zig requires no special configuration (ignoring linking). As it is currently described, @import of C will
by kbolino 2y ago
@cImport works without build.zig and even with build.zig requires no special configuration (ignoring linking).
As it is currently described, @import of C will require build.zig and specific configuration therein.
- jeltz 2y agoAnd form my experience from Rust that is much less ergonomic. Maybe Zig will do it better than Rust but who knows?
- samatman 2y agobuild.zig is on its way to being essential. I consider that an appropriate development. Binaries need to be built, this should be integrated with the rest of the system in any modern language. It's not incompatible with using something like CMake or Ninja either, it just puts certain responsibilities inside of build.zig. Where they belong.
- throwawaymaths 2y agoI don't think that's the case. In general you can set up @import modules from the command line, and I'm not 100% sure but I think build.zig generally just templates a command line call anyways.
- kbolino 2y agoI don't think this DSL is finalized yet, but you can see on a linked issue what the build.zig to support @import of C looks like on nightly: const translate_c = b.addTranslateC(.{ .root_source_file = b.path("src/c.h"), .target = target, .optimize = optimize, }); exe.root_module.addImport("c", translate_c.createModule()); https://github.com/ziglang/zig/issues/20648 https://github.com/ziglang/zig/issues/20648
- mk12 2y agoIt won't require build.zig, you'll just have to run zig translate-c on the C file. Andrew's comment here[1] says that @cImport is basically @import + the compiler implicitly running translate-c for you. There was some discussion of removing the translate-c subcommand as well (which would force you to use build.zig), but I don't think it's been decided to do that. [1] https://github.com/ziglang/zig/issues/20630#issuecomment-2259213229 https://github.com/ziglang/zig/issues/20630#issuecomment-225...