Disclaimer, I don’t know any zig, I just want this thing to work and I hope someone can help.
There is the following library that sadly doesn’t come with compiled binaries:
They do however have a build.zig
file which seems to be for cross platform compilation. It’s dated 16 June 2022.
If I use zig build on this with zig 0.15.1 (correct me if my usage is wrong), then I get:
build.zig:6:21: error: root source file struct ‘std’ has no member named ‘build’
pub fn build(b: *std.build.Builder) !void {
~^~~~
/opt/homebrew/Cellar/zig/0.15.1/lib/zig/std/std.zig:1:1: note: struct declared here
pub const ArrayHashMap = array_hash_map.ArrayHashMap;
^~~
referenced by:
runBuild__anon_21150: /opt/homebrew/Cellar/zig/0.15.1/lib/zig/std/Build.zig:2213:50
main: /opt/homebrew/Cellar/zig/0.15.1/lib/zig/compiler/build_runner.zig:366:29
4 reference(s) hidden; use ‘-freference-trace=6’ to see all references
I also tried zig 0.9.1 cause it’s a tagged version and it’s a few months from before 16 June 2022.
This however gives me:
thread 12279453 panic: Darwin is handled separately via std.zig.system.darwin module
Unable to dump stack trace: debug info stripped
zsh: abort /Users/doeke/Downloads/zig-macos-aarch64-0.9.1/./zig build
The build.zig file is only 71 lines long. Can someone be so friendly to fix it?
There’s been a ton of changes in the Zig build system API since 2022, but oth the build.zig file looks quite simple, just building a bunch a static libraries from C code.
Here’s an example from one of my projects what building a C static library looks like now:
Direct port, with the removal of the different targets, you can specify them with -Dtarget=[target triple] instead. Also for optimisations -Doptimize=[Debug|ReleaseSafe|ReleaseFast|ReleaseSmall]Debug is the default.
@tensorush s’ is more idiomatic, though it doesnt matter much for such a simple build script.
Zig has a different (much stricter) default set of compilation options for C code than Clang, one thing it does for instance is automatically activating UBSAN in debug mode which then requires to link with the ubsan runtime library (when using Zig as linker this happens automatically).
To disable this behaviour it should be enough to build just with "-fno-sanitize=undefined" (that’s what I do when building C code to WASM via Zig but then use Emscripten as linker, and that seems to remove all dependencies on the ubsan runtime).
One more thing, I would like two export 2 files instead of one.
So one with name “mqtt” and with source, “src/mqtt.c”.
And one time with name “mqtt_pal” and with source, “src/mqtt_pal.c”.
Although this sounds simple, not knowing zig makes me really struggle with it.
Could someone help?