[Rust] Trying to make a multi-crates project can't find Cargo.toml but works locally

I working on the Redis challenge (my first one on the platform :sparkles:) in Rust.

Here is my repo link: https://git.codecrafters.io/ad4e5ed8476e3d04

I’m on the ECHO command stage, and wanted to make a separate crate for handling parsing/output/serialization for the redis protocol.

I basically did:

$ mkdir myred-server
$ mv src Cargo.toml myred-server/
$ touch Cargo.toml # new top-level manifest

And put in the new top-level manifest:

[workspace]
members = [
    "myred-server",
]

BUT I’m getting a build error when trying to push on master or run tests using codecrafters test even though the mentioned command works locally:

$ codecrafters test
Initiating test run...

We're warming up test runners for your repository, please bear with us.
Subsequent builds will be snappy ⚡

[build] Starting build...
[build] If you don't see logs for 60s+, please contact us at hello@codecrafters.io
[build] Step 1 complete.
[...]
[build] Step 13 complete.
[build] > error: failed to load manifest for workspace member `/app/myred-server`
[build] >
[build] > Caused by:
[build] >   failed to read `/app/myred-server/Cargo.toml`
[build] >
[build] > Caused by:
[build] >   No such file or directory (os error 2)
[build] Error: process "/bin/sh -c cargo build --release --target-dir=/tmp/codecrafters-redis-target" did not complete successfully: exit code: 101.
[build] > error: failed to load manifest for workspace member `/app/myred-server`
[build] >
[build] > Caused by:
[build] >   failed to read `/app/myred-server/Cargo.toml`
[build] >
[build] > Caused by:
[build] >   No such file or directory (os error 2)
[build] Build failed. Check the logs above for the reason.
[build] If you think this is a CodeCrafters error, please contact us at hello@codecrafters.io.

But locally:

    Finished release [optimized] target(s) in 0.03s

I know the starter Cargo.toml has lines saying I shouldn’t edit the file (let alone move it I guess…), but I’m not sure why if we’re using cargo and cargo build/cargo run (is supposed to) work?

See commit 69990426be92b3c1c50784545bda9f0715d45f0b


Also, shouldn’t there be a language:rust tag (& same for other languages) on the forum to easily find all Rust-related topics? :thinking:

I tried to revert back to not use workspace-only crates (so back to having src at root of repo), and instead only have the protocol as a separate crate, and update the dependencies to use myred-protocol = { path = "./myred-protocol" }

But I’m getting a similar result of:

$ codecrafters test
[...]
[build] Step 12 complete.
[build] Step 13 complete.
[build] >     Updating crates.io index
[build] > error: failed to get `myred-protocol` as a dependency of package `redis-starter-rust v0.1.0 (/app)`
[build] >
[build] > Caused by:
[build] >   failed to load source for dependency `myred-protocol`
[build] >
[build] > Caused by:
[build] >   Unable to update /app/myred-protocol
[build] >
[build] > Caused by:
[build] >   failed to read `/app/myred-protocol/Cargo.toml`
[build] >
[build] > Caused by:
[build] >   No such file or directory (os error 2)
[build] Error: process "/bin/sh -c cargo build --release --target-dir=/tmp/codecrafters-redis-target" did not complete successfully: exit code: 101.
[build] >   failed to load source for dependency `myred-protocol`
[build] >
[build] > Caused by:
[build] >   Unable to update /app/myred-protocol
[build] >
[build] > Caused by:
[build] >   failed to read `/app/myred-protocol/Cargo.toml`
[build] >
[build] > Caused by:
[build] >   No such file or directory (os error 2)
[build] Build failed. Check the logs above for the reason.
[build] If you think this is a CodeCrafters error, please contact us at hello@codecrafters.io.

But a cargo build works well locally :thinking:

The only explanation I would have is that you delete or only copy some files from the repo before running your tests… Is that true? Or am I missing something?

See commit 13b79c92ef9790a6ed00155953c2f1febeda083c

This is correct :slight_smile: Earlier on we relied on stuff like this to help with caching test runners across multiple users. The experience was pretty crappy when you had to change things to do with how the program is built, precisely for the reasons you mentioned - it isn’t clear/transparent why something would build fine locally but not remotely.

Last week we figured out the infra pieces required to move away from this and just have all files available. We pushed fixes to some challenge-language combinations to observe, but Redis+Rust isn’t patched yet. I’m working on a PR for this right now, will leave a note once done!

Fixed! PR:

I was able to test this on a repository cloned from your code that triggered the failure and it seemed to work.

Will mark as closed, please do let us know if you run into this again! We’ll also push this change to other challenges over the next few weeks.

Awesome thank you!!

I actually forgot I could do module directories inside the root crate :sweat_smile:, realized this after watching https://youtu.be/5RPXgDQrjio :sparkles:

Anyway I think I’ll start with modules and later move to separate crate :+1:
Do you plan to update your Rust docs to mention the ability to make modules and multiple crates?

1 Like

Yep, we’ll update this! Going to mark this as open until that’s done just so that I remember…

We’ll mention modules in the doc, don’t think separate crates is super relevant for our challenges, could be distracting.

1 Like