" can't find crate for 'wasmtime-component-macro' " Error while trying to build a crate with wasmtime

I'm not sure what's causing this, and I have noticed that this happens with other unrelated crates as well where it will not be able to find a macro-related crate even though that crate does show up in the build log. I've also tried adding said crate as a dependency in my Cargo.toml, but still no dice.

Is there something I don't know about cargo that is causing this? I'm also using NixOS, could the non-standard filesystem hierarchy be causing some issues? I'd love to solve this problem on my own but I really don't know where to begin. Any and all guidance would be appreciated

EDIT: Below is the output of cargo build -p wasmtime on my machine:

   Compiling wasmtime v30.0.2
error[E0463]: can't find crate for `wasmtime_component_macro`
   --> /home/bailor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-30.0.2/src/runtime/component/mod.rs:408:9
    |
408 | pub use wasmtime_component_macro::bindgen;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error[E0463]: can't find crate for `wasmtime_component_macro`
   --> /home/bailor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-30.0.2/src/runtime/component/mod.rs:550:9
    |
550 | pub use wasmtime_component_macro::ComponentType;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error[E0463]: can't find crate for `wasmtime_component_macro`
   --> /home/bailor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-30.0.2/src/runtime/component/mod.rs:578:9
    |
578 | pub use wasmtime_component_macro::Lift;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error[E0463]: can't find crate for `wasmtime_component_macro`
   --> /home/bailor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-30.0.2/src/runtime/component/mod.rs:606:9
    |
606 | pub use wasmtime_component_macro::Lower;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error[E0463]: can't find crate for `wasmtime_component_macro`
   --> /home/bailor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-30.0.2/src/runtime/component/mod.rs:665:9
    |
665 | pub use wasmtime_component_macro::flags;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error[E0432]: unresolved imports `crate::component::ComponentType`, `crate::component::Lift`, `crate::component::Lower`, `crate::component::Lift`, `crate::component::Lower`, `crate::component::Lift`, `crate::component::Lower`, `crate::component::ComponentType`, `crate::component::Lift`, `crate::component::Lower`
 --> /home/bailor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-30.0.2/src/runtime/component/func/host.rs:4:44
  |
4 | use crate::component::{ComponentNamedList, ComponentType, Lift, Lower, Val};
  |                                            ^^^^^^^^^^^^^  ^^^^  ^^^^^
  |
 ::: /home/bailor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-30.0.2/src/runtime/component/instance.rs:4:64
  |
4 |     Component, ComponentExportIndex, ComponentNamedList, Func, Lift, Lower, ResourceType, TypedFunc,
  |                                                                ^^^^  ^^^^^
  |
 ::: /home/bailor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-30.0.2/src/runtime/component/linker.rs:6:59
  |
6 |     Component, ComponentNamedList, Instance, InstancePre, Lift, Lower, ResourceType, Val,
  |                                                           ^^^^  ^^^^^
  |
 ::: /home/bailor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmtime-30.0.2/src/runtime/component/resources.rs:3:24
  |
3 | use crate::component::{ComponentType, Lift, Lower};
  |                        ^^^^^^^^^^^^^  ^^^^  ^^^^^

Some errors have detailed explanations: E0432, E0463.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `wasmtime` (lib) due to 6 previous errors

What are the exact steps you took that lead to the error message you posted?

Here is a minimal reproducible example. Firstly, I am using NixOS 23.11 but my flake for the project uses nixpkgs-unstable. I elected to use a flake because the project I'm building has some C-library dependencies and since I'm on NixOS that's the preferred way of managing C dependencies. Below is a minimal flake I used to reproduce the issue.

{
	description = "Minimal Reproducible Example Flake";
	inputs = {
		nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
	};
	outputs = { self, nixpkgs }:  
    let 
        pkgs = nixpkgs.legacyPackages.x86_64-linux;
    in
    {
        devShell.x86_64-linux = pkgs.mkShell {
            shellHook = "$SHELL; exit"; # I use zsh, nix-shell won't use zsh by default
            nativeBuildInputs = with pkgs; [
                rustup
            ];
        };
	};
}

In the directory where that flake was created I run nix develop to add rustup to my path, then cargo init . to create a new crate. cargo add wasmtime and then cargo build. The output of the build is the same as the output in my original post. Changing toolchains doesn't make a difference.

I'm sorry I can't help you much. I can only say that wasmtime 30.0.2 and 31 both compile linux, so I think it's related to the nix config.

I've fixed the issue, and it was related to nix. The way nix patches binaries doesn't jive well with rustup. For what reason I'm not sure, and sadly I don't really have time to track down that reason. However the simple way I fixed this while still using nix to manage everything is to just use a different version of rustup than the one provided by nixpkgs. I've tried and succeeded in compiling wasmtime with both a version from devenv and one from a rust overlay created a nix user. (https://github.com/oxalica/rust-overlay)