Makefile to build.zig for a C project (uSockets)

Hi, I’m learning Zig (coming from JavaScript) and I’ve been exploring building a web server with Zig. I’ve settled on using uSockets as the underlying networking library because it’s simpler to use compared to my struggles with libuv :slight_smile:.

uSockets is a C project which means I need a way to build and integrate with Zig. I currently have a working sample with it, and was able to convert some of the content in the projects Makefile to Zig build system (thanks to LLM for the huge help).
However, I need help adding more options which are in the Makefile but I’m unsure how to go about it. So here’s my ask:

  • Could you pls review the build script to see if what I currently have is a good start?
  • How can I add some of the other options from the Makefile, e.g BoringSSL support.
  • Do I have the c_flags correct? I’m unsure what -fno-sanitize=undefined does, and if I should just remove that.

My repo is public on GitHub (others can use it), and the Makefile here.

Thanks for the help and contribution :folded_hands:

It’s a good build script.
-fno-sanitize=undefined tells the compiler not to insert checks for undefined behaviour, you should report this to upstream so they can fix them.

regarding BoringSSL there are two options:

  • implement boringssl build script as part of this one, this needs zig to fetch git submodules which i am not sure if it does.
  • find a zig build script for for boringssl i found this its 2 years old
  • (recomended) make a seperate build script repo for boringssl and depend on it (could yoink a good amount from the linked project)

Thank you.
For the -fno-sanitiser=undefined this was suggested by LLM. I researched about it and found this question in this forum, so I decided to put a comment and see what others suggest.

The Makefile contains

# WITH_ASAN builds with sanitizers
ifeq ($(WITH_ASAN),1)
	override CFLAGS += -fsanitize=address -g
	override LDFLAGS += -fsanitize=address
endif

Which I believe is for that flag. Using address instead of undefined compiles successfully. Since I’m not sure what I’m doing, I just left a comment to revisit later.

does it compile without -fno-sanitize=undefined if so than remove it, if no, report the errors upstream.

zig enable sanitisation by default in safe build modes (releaseSafe and debug) so you shouldn’t need to pass any -fsanitize flags

1 Like

I tried it and it compiles with both -fno-sanitize=undefined and -fno-sanitize=address.

Thank you