Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zig: fix issues with using c_allocator #213

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ippsav
Copy link
Contributor

@ippsav ippsav commented Jun 5, 2024

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:

  • Make the second test after the diff merge pass

@rohitpaulk
Copy link
Member

@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
Copy link
Contributor Author

ippsav commented Jun 7, 2024

@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
Copy link
Member

@ippsav awesome, thanks - alert set!

@ippsav
Copy link
Contributor Author

ippsav commented Jun 7, 2024

@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.

@rohitpaulk rohitpaulk changed the title Swap alpine to debian for missing deps (libc c_allocator) Zig: fix issues with using c_allocator Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants