From the challenge:
Notes:
We recommend using a library like readline for your implementation. Most modern shells and REPLs (like the Python REPL) use readline under the hood.
Cool, sounds good, and was a fun challenge, allowed me to learn how to interface Zig code with C functionality of that sort. And famous last words, “builds on my machine!”
Then I pushed to codecrafters, and my heart sank …
remote: [build] > install
remote: [build] > +- install main
remote: [build] > +- zig build-exe main Debug native failure
remote: [build] > error: error: unable to find dynamic system library 'readline' using strategy 'paths_first'. searched paths:
remote: [build] > /usr/local/lib/libreadline.so
remote: [build] > /usr/local/lib/libreadline.a
remote: [build] > /lib/libreadline.so
remote: [build] > /lib/libreadline.a
remote: [build] > /usr/lib/libreadline.so
remote: [build] > /usr/lib/libreadline.a
remote: [build] >
remote: [build] > error: the following command exited with error code 1:
remote: [build] > /usr/local/zig/zig build-exe -lreadline -ODebug -Mroot=/app/src/main.zig -lc --cache-dir /app/.zig-cache --global-cache-dir /root/.cache/zig --name main --zig-lib-dir /usr/local/zig/lib/ --listen=-
remote: [build] > Build Summary: 0/3 steps succeeded; 1 failed
remote: [build] > install transitive failure
remote: [build] > +- install main transitive failure
remote: [build] > +- zig build-exe main Debug native failure
remote: [build] > error: the following build command failed with exit code 1:
remote: [build] > /app/.zig-cache/o/5a1025b01098546404c87e4cf16c3fdd/build /usr/local/zig/zig /usr/local/zig/lib /app /app/.zig-cache /root/.cache/zig --seed 0xfadc1c90 -Z43d49f747b4eb4ce
remote: [build] Error: process "/bin/sh -c .codecrafters/compile.sh" did not complete successfully: exit code: 1.
remote: [build] > /usr/lib/libreadline.a
remote: [build] >
remote: [build] > error: the following command exited with error code 1:
remote: [build] > /usr/local/zig/zig build-exe -lreadline -ODebug -Mroot=/app/src/main.zig -lc --cache-dir /app/.zig-cache --global-cache-dir /root/.cache/zig --name main --zig-lib-dir /usr/local/zig/lib/ --listen=-
remote: [build] > Build Summary: 0/3 steps succeeded; 1 failed
remote: [build] > install transitive failure
remote: [build] > +- install main transitive failure
remote: [build] > +- zig build-exe main Debug native failure
remote: [build] > error: the following build command failed with exit code 1:
remote: [build] > /app/.zig-cache/o/5a1025b01098546404c87e4cf16c3fdd/build /usr/local/zig/zig /usr/local/zig/lib /app /app/.zig-cache /root/.cache/zig --seed 0xfadc1c90 -Z43d49f747b4eb4ce
remote: [build] Build failed. Check the logs above for the reason.
remote: [build] If you think this is a CodeCrafters error, please contact us at hello@codecrafters.io.
remote:
remote:
remote: Looks like your codebase failed to build.
remote: If you think this is a CodeCrafters error, please let us know at hello@codecrafters.io.
Not sure how to deal with this, or how to figure out the right thing to do. Interestingly enough, it does look like the codecrafters machine has the library headers installed, or it wouldn’t build properly, but where’s the actual library?
If it matters, this is my build.zig diff:
diff --git a/build.zig b/build.zig
index d211b57..dcc7cd1 100644
--- a/build.zig
+++ b/build.zig
@@ -8,6 +8,8 @@ pub fn build(b: *std.Build) void {
.target = b.standardTargetOptions(.{}),
.optimize = b.standardOptimizeOption(.{}),
});
+ exe.linkLibC();
+ exe.linkSystemLibrary("readline");
// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default