zigzap / zap

blazingly fast backends in zig
MIT License
2.23k stars 75 forks source link

Build error using TLS #61

Closed Vemahk closed 9 months ago

Vemahk commented 9 months ago

Versions: Zig: 0.11.0 Zap: 0.2.5

I have a pet-project I'm working on using zap, and I thought I'd try out the TLS stuff when I saw 0.2.5 come out. I tried plugging it in real quickly and immediately ran into a build issue. Thought it was just me, so I cloned the zap repo and ran the zig build run-https, only to have the same build issue pop up.

vemahk:~/zap$ zig build run-https
zig build-exe https Debug native: error: the following command failed with 1 compilation errors:
/home/vemahk/.apps/zig/zig build-exe /home/vemahk/zap/examples/https/https.zig /home/vemahk/zap/zig-cache/o/6ec5768283debabdd042d8fe36799e77/libfacil.io.a -lc --cache-dir /home/vemahk/zap/zig-cache --global-cache-dir /home/vemahk/.cache/zig --name https --mod zap::/home/vemahk/zap/src/zap.zig --deps zap --listen=-
Build Summary: 1/4 steps succeeded; 1 failed (disable with --summary none)
run-https transitive failure
mq run https transitive failure
   mq zig build-exe https Debug native 1 errors
error: ld.lld: undefined symbol: fio_tls_new
    note: referenced by tls.zig:27 (/home/vemahk/zap/src/tls.zig:27)
    note:               /home/vemahk/zap/zig-cache/o/b7e39a688312582a3599d8d94587fe9f/https.o:(tls.init)

Relevant machine specs: OS: Ubuntu 22.04.3 LTS aarch64 Host: Raspberry Pi 4 Model B Rev 1.2 Kernel: 5.15.0-1044-raspi CPU: BCM2835 (4) @ 1.500GHz

I figured it might have something to do with running on an ARM raspberry pi... but honestly I'm kinda green to all this, so I've got no idea.

Anyway, would appreciate any help. Thanks for your good work on this stuff, zap's been great.

Vemahk commented 9 months ago

Well, just noticed "make sure to build with -Dopenssl=true" in the readme. Might be right about my ARM situation, cause that gives some more interesting errors trying to build facil.io... It can't seem to find libssl in any of several places. Gonna keep pokin' around.

Vemahk commented 9 months ago

Yeah ok was just missing libssl. Sorry for the trouble. (just apt install libssl-dev, and all is well.)

renerocksai commented 9 months ago

No worries. Please note that, in order to use zap as a dependency in your own project, the -Dopenssl=true approach does not work. Hence, I released a fix in 0.2.6 "just now" where the whole thing changed to using an env var: ZAP_USE_OPENSSL=true. Updated the README as well.

Vemahk commented 9 months ago

@renerocksai I did wonder about that. I happened upon a stroke of luck that adding .openssl = true to the build options for adding zap in my build.zig seemed to work alright. Might have another issue to submit about using TLS here in a little bit- was noticing some weird stalling going on, but I couldn't track down what was causing it.

(what I mean about my build.zig, exactly)

const zap = b.dependency("zap", .{
    .target = target,
    .optimize = optimize,
    .openssl = true
});

Not sure if that's actually doing what I expect it to, but I couldn't argue with the build errors going away.

renerocksai commented 9 months ago

Thanks for the update. I was sure I tried that. But, then again, I might actually have used .use_openssl = true. 🤦‍♂️

I shall try again tomorrow and maybe re-add the build option if I succeed.

Re other issues with openssl support.... I am not an expert since I don't use it; I usually put my stuff (I have many zap projects on 1 server) behind nginx.

But pls report any issues; maybe someone will be able to help. Also, if you're not already and don't mind, feel free to hop on the discord server and ask there.