Error: environment variable `OUT_DIR` not defined

I'm building a library and a crate together, with the binary depending on the library. My directory structure looks like this:

├── Cargo.lock
├── Cargo.toml
├── disk-nvme.img
├── disk-sata.img
├── docs
│   ├── book
│   ├── book.toml
│   └── src
│       ├──
│       └──
├── libk
│   ├── Cargo.lock
│   ├── Cargo.toml
│   └── src
│       ├──
│       ├──
│       ├──
│       ├──
│       ├──
│       ├──
│       ├──
│       ├──
│       ├── task
│       │   ├── cooperative
│       │   │   ├──
│       │   │   └──
│       │   └──
│       └──
├── Makefile.toml
├── OVMF.fd
├── qemu2.log
├── qemu.log
├── src
│   ├──
│   └──
└── x86_64-kernel-none.json

I'm using cargo make to build the project. Part of my build process is to run cargo check and cargo clippy. However, when running cargo check, Rust complains that the OUT_DIR environment variable is not defined, which is needed for this source code:

include!(concat!(env!("OUT_DIR"), "/"));

This makes absolutely no sense to me, since the build script runs without any issues. Can somebody enlighten me as to why this is happening?

Okay, so I've solved the first problem but I'm now getting "can't find crate for std". This is despite the fact that any use of std is in my build script, only, and not anywhere else. I think Cargo is building my build script with no_std... I can't remember how to solve this but I know I've suffered this before. It only happens with my library target though, not my main binary target, at least from what I can see. I'm surprised this bug is still even a thing. Its choking on the log target, but in both Cargo.toml files, I have:

default-features =false
version = "0.4.14"

Edit: I'm also building using a custom target profile, but Cargo still shouldn't be building any build scripts with that target profile but should be building them using the native one.

The OUT_DIR can be defined in the makefile.toml

OUT_DIR = "somedir"

and for the missing std, i see many other threads about it.
for example:

Regarding the OUT_DIR, know that —outside of cargo make-specific stuff— the env var is only present if you have a script. In your case, the libk/ crate does not seem to have one.

Regarding the std stuff, are you using resolver = "2"? There are bugs regarding the default "feature resolver" which make the features for scripts & procedural macros (and other target-specific deps and whatnot) to be unified all together, which the resolver = "2" solves.


Thanks, I had forgotten about that key. Adding that to both crates is now producing this weird compiler error with extprim that I didn't encounter before:

   Compiling extprim v1.7.1
error[E0557]: feature has been removed
  --> /home/ethin/.cargo/registry/src/
58 | #![cfg_attr(extprim_channel="unstable", feature(llvm_asm, test, specialization, const_fn))]
   |                                                                                  8 caret characters feature has been removed
   = note: split into finer-grained feature gates

Apparently, the syntex_syntax crate requires it. That crate, in turn, is needed by rustfmt. Is the "rustfmt" crate on the one that the rustfmt tool uses, or do I have to use another registry?

I don't believe rustfmt is published to any more because it uses rustc's internal APIs directly. So rustup distributes it alongside the version of rustc it is built for.

The page you've linked to tells to use, is this what you want?

i see the nightly at:
Also their github readme points to it (via badge).
I agree it's a bit confusing.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.