codecrafters-io / build-your-own-redis

Definition for the redis challenge.
https://app.codecrafters.io/courses/redis/overview
MIT License
101 stars 29 forks source link

Zig: fix issues with using c_allocator #213

Open ippsav opened 1 month ago

ippsav commented 1 month ago

This is a refactor for the Zig Dockerfile, as of now c_allocator is unusable in zig when using alpine and would require too much hassle to make it work, that is why I've switched to debian-slim with some other changes.

TODO:

rohitpaulk commented 1 month ago

@ippsav thanks for this! Will need to figure out the build failures before we can merge this though. I'll point people here if they ask about this.

@ippsav what kind of error do you see emitted when trying to use c_allocator? I'd like to setup an alert on our end to see how often people run into this.

ippsav commented 1 month ago

@ippsav what kind of error do you see emitted when trying to use c_allocator? I'd like to setup an alert on our end to see how often people run into this.

It says that it can't use c_allocator because libc is not linked (alpine doesn't use libc, it uses musl instead)


remote: [compile] Running zig build
remote: [compile] install
remote: [compile] +- install zig
remote: [compile]    +- zig build-exe zig Debug native 4 errors
remote: [compile] /usr/lib/zig/std/heap.zig:38:13: error: C allocator is only available when linking against libc
remote: [compile] /usr/lib/zig/std/c/linux.zig:295:12: error: dependency on libc must be explicitly specified in the build command
remote: [compile] /usr/lib/zig/std/c/linux.zig:294:12: error: dependency on libc must be explicitly specified in the build command
remote: [compile] /usr/lib/zig/std/c.zig:1732:12: error: dependency on libc must be explicitly specified in the build command
remote: [compile] error: the following command failed with 4 compilation errors:
remote: [compile] /usr/bin/zig build-exe -ODebug -Mroot=/app/src/main.zig --cache-dir /app/zig-cache --global-cache-dir /root/.cache/zig --name zig --listen=-
remote: [compile] Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
remote: [compile] install transitive failure
remote: [compile] +- install zig transitive failure
remote: [compile]    +- zig build-exe zig Debug native 4 errors
remote: [compile] error: the following build command failed with exit code 1:
remote: [compile] /app/zig-cache/o/3575a756c377e78b682c7f0661a9d0f7/build /usr/bin/zig /app /app/zig-cache /root/.cache/zig --seed 0xe5f6a33c -Z4a80c61905ef91fb
remote: [compile] Looks like your code failed to compile.
remote: [compile] If you think this is a CodeCrafters error, please let us know at hello@codecrafters.io.```
rohitpaulk commented 1 month ago

@ippsav awesome, thanks - alert set!

ippsav commented 1 month ago

@rohitpaulk this is not urgent as gpa allocator is good for 99% of the cases, but if someone try and use a dependency that in itself it uses c_allocator there will be issues.