Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error[E0463]: can't find crate for core when cargo bootimage #1033

Closed
BackMountainDevil opened this issue Jul 7, 2021 · 4 comments
Closed

Comments

@BackMountainDevil
Copy link

What happened?

It got error when I run cargo bootimage to get an image.

  • error[E0463]: can't find crate for core

env

  • OS: Linux arch 5.10.47-1-lts x86_64 GNU/Linux
  • rustc 1.55.0-nightly (e8cb1a4a5 2021-06-27)
  • cargo 1.55.0-nightly (9233aa06c 2021-06-22)
  • target = "x86_64-blog_os.json"

How that happen

I follow your blog in Chinese version.

fine

$  cargo build --target x86_64-blog_os.json
   Compiling os v0.1.0 (/home/kearney/Documents/code/rust/os-rust/os)
error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-blog_os-9626546152685556648` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-blog_os-9626546152685556648`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error: aborting due to previous error

This error is the same as the blog. So it is fine

$ cargo install cargo-xbuild
    Updating `https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git` index
     Ignored package `cargo-xbuild v0.6.5` is already installed, use --force to override

$ rustup component add rust-src
info: component 'rust-src' is up to date

$ cargo xbuild
   Compiling compiler_builtins v0.1.46
   Compiling core v0.0.0 (/home/kearney/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling rustc-std-workspace-core v1.99.0 (/home/kearney/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/tmp/cargo-xbuildczo8s8)
    Finished release [optimized] target(s) in 11.29s
   Compiling os v0.1.0 (/home/kearney/Documents/code/rust/os-rust/os)
    Finished dev [unoptimized + debuginfo] target(s) in 0.27s

$ cargo install bootimage
    Updating `https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git` index
   Installed package `bootimage v0.10.3` (executables `bootimage`, `cargo-bootimage`)

$ rustup component add llvm-tools-preview
info: component 'llvm-tools-preview' for target 'x86_64-unknown-linux-gnu' is up to date

Now everyhing is ok until next step.

wrong situation

If below step work. it should not get error. So I can continue toqemu-system-x86_64 -drive format=raw,file=bootimage-blog_os.bin ..

$  cargo bootimage
WARNING: `CARGO_MANIFEST_DIR` env variable not set
Building kernel
   Compiling bootloader v0.9.18
error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-blog_os-9626546152685556648` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-blog_os-9626546152685556648`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `bootloader`

To learn more, run the command again with --verbose.
Error: Kernel build failed.
Stderr: 

$ > cargo bootimage
Error: Please invoke bootimage with a subcommand. See `bootimage --help` for more information.

Some solution

reinstall bootimage from your home directory

#853

Try running cargo install bootimage from your home directory instead of the project directory.

cd ~
cargo install bootimage --force

turn to project dir. Not work..

$ cargo clean
$ cargo xbuild
   Compiling core v0.0.0 (/home/kearney/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling compiler_builtins v0.1.46
   Compiling rustc-std-workspace-core v1.99.0 (/home/kearney/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/tmp/cargo-xbuild8HbCtr)
   Compiling bootloader v0.9.18
   Compiling os v0.1.0 (/home/kearney/Documents/code/rust/os-rust/os)
    Finished dev [unoptimized + debuginfo] target(s) in 0.44s

$ cargo bootimage
WARNING: `CARGO_MANIFEST_DIR` env variable not set
Building kernel
   Compiling bootloader v0.9.18
error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-blog_os-9626546152685556648` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-blog_os-9626546152685556648`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `bootloader`

To learn more, run the command again with --verbose.
Error: Kernel build failed.
Stderr: 

emm confused

#837
#835

I just updated the blog to use standard cargo build instead of cargo-xbuild in #835.

Does that mean use build? but belows tells it not. So I turn to the English version web. The steps is same as the Chinese version...

$ cargo clean
$ cargo build
   Compiling bootloader v0.9.18
error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-blog_os-9626546152685556648` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-blog_os-9626546152685556648`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`
@bjorn3
Copy link
Contributor

bjorn3 commented Jul 7, 2021

Have you enabled build-std in .cargo/config.toml?

[unstable]
build-std-features = ["compiler-builtins-mem"]
build-std = ["core", "compiler_builtins"]

@BackMountainDevil
Copy link
Author

oh, my dear friend. Thank you for you advics. I follow your advics so

# enabled build-std in .cargo/config.toml
$ cargo clean
$ cargo build --target x86_64-blog_os.json
warning: unused manifest key: unstable
   Compiling bootloader v0.9.18
error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-blog_os-9626546152685556648` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-blog_os-9626546152685556648`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error: aborting due to previous error

error: could not compile `bootloader`

$ cargo install cargo-xbuild
    Updating `https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git` index
     Ignored package `cargo-xbuild v0.6.5` is already installed, use --force to override

$ cargo xbuild --target x86_64-blog_os.json
   Compiling core v0.0.0 (/home/kearney/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling compiler_builtins v0.1.46
   Compiling rustc-std-workspace-core v1.99.0 (/home/kearney/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/tmp/cargo-xbuildz13f2t)
    Finished release [optimized] target(s) in 11.13s
warning: unused manifest key: unstable
   Compiling bootloader v0.9.18
   Compiling os v0.1.0 (/home/kearney/Documents/code/rust/os-rust/os)
    Finished dev [unoptimized + debuginfo] target(s) in 0.52s

$ cargo bootimage
WARNING: `CARGO_MANIFEST_DIR` env variable not set
Building kernel
warning: unused manifest key: unstable
   Compiling bootloader v0.9.18
error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-blog_os-9626546152685556648` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-blog_os-9626546152685556648`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `bootloader`

To learn more, run the command again with --verbose.
Error: Kernel build failed.
Stderr: 

try build -Zbuild-std but failed

$ cargo build -Zbuild-std
$ cargo clean
$ cargo xbuild
    Finished release [optimized] target(s) in 11.39s
warning: unused manifest key: unstable
   Compiling bootloader v0.9.18
    Finished dev [unoptimized + debuginfo] target(s) in 0.95s

$ cargo bootimage
WARNING: `CARGO_MANIFEST_DIR` env variable not set
Building kernel
warning: unused manifest key: unstable
   Compiling bootloader v0.9.18
error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-blog_os-9626546152685556648` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-blog_os-9626546152685556648`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `bootloader`

Then I try reinstall bootimage from home directory but got the same error.

@BackMountainDevil
Copy link
Author

I will fix this someday in the future. But not now

@s0ubhik
Copy link

s0ubhik commented Apr 5, 2023

You have to build it with nightly channel

# blog_os/rust-tootlchain.toml
[toolchain]
channel = "nightly"

and then run

cargo build
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
cargo build

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants