Closed iodapson closed 2 years ago
Hi @iodapson,
Would it be possible to provide a repo link? Its hard to find a solution without seeing the code :)
If not, here are some questions:
build.rs
mod cornucopia;
before using it?Thanks for providing the info :smile:
Right, so from looking at your build.rs
, your cornucopia module will be generated in src/cornucopia.rs
, but your main.rs
file doesn't actually include that module (there's no mod cornucopia;
). Instead, you use include!(concat!(env!("OUT_DIR"), "/cornucopia.rs"));
, which is presumably not what you want ("OUT_DIR" will typically be the target
folder, not src
).
What I would recommend is to
include!(concat!(env!("OUT_DIR"), "/cornucopia.rs"));
from main.rs
cornucopia.rs
is generated correctly (according to your build.rs
file, it should be generated in src/cornucopia.rs
, make sure its there).mod cornucopia;
to your main.rs
Otherwise, you can follow the rust-on-nails-demo project's way of doing things:
main.rs
as is.let destination = env::var_os("OUT_DIR").unwrap();
and use that destination
in generate_managed
.
The difference between the two methods is that in the first method, your generated cornucopia.rs
file is part of your project as a regular module. In the second method, it is generated as a build artifact in the target
folder (i.e. not directly part of your project).
Please let me know if you need further assistance.
I have tried both ways but the error still persists. It is as if cargo (and bare rustc) can't resolve cornucopia's existence at crates.io Maybe there could be some other way to point the code to corunucopia's source code or something. Or maybe I'm doing something just outright wrong.
The cornucopia
crate is not found in your build.rs
because you need a build-dependencies
section in your Cargo.toml
. Like so:
[build-dependencies]
cornucopia = "0.8.1"
But more importantly, the demo, as found here https://github.com/purton-tech/rust-on-nails/blob/main/examples/rust-on-nails-demo/app/Cargo.toml, is using a deprecated version of Cornucopia, while you are trying to use the latest version. This will lead to many problems down the line.
I would highly suggest you use this as a base instead https://github.com/cornucopia-rs/cornucopia/tree/main/examples/auto_build. (Read the README!). This is the official way of working with Cornucopia auto-build, and is verified to work out-of-the-box. It shouldn't be too hard to adapt this to the rust-on-nails-demo. NOTE: You'll need to change the local paths in the Cargo.toml
to version numbers instead.
In any case I'll try to open a PR on Ian Purton's repo to update the demos.
Ah incredible! That worked. For some odd reason I tried [dev-dependencies] instead of [build-dependencies]. Thank you.
@iodapson No problem! Thanks for using Cornucopia :smile: I'll close the issue for now, but don't hesitate if you need further assistance.
Alright 😁
Thanks for building Cornucopia.
The following error message occurs on VS Code: use of undeclared crate or module
cornucopia
rustcE0432The above error was traced back to a 'build.rs' file with code to auto build for a docker container