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 thrown when using Workspace project #54

Closed
nabilmerk opened this issue May 3, 2020 · 6 comments · Fixed by #55
Closed

Error thrown when using Workspace project #54

nabilmerk opened this issue May 3, 2020 · 6 comments · Fixed by #55

Comments

@nabilmerk
Copy link

Hi,

First of all, I want to say big thanks because your blog that explains quite well how to start with kernel OS using Rust! This language is always compared to C language but it's very rare to find an interesting blog about how to write kernel OS in Rust.

When I'm trying to play with A Minimal Rust Kernel example, I actually got an error from cargo bootimage. I don't really know where the error comes from but I've setup a workspace project compares to your example such that my directory looks like:

  • dummy_os/
    • Cargo.toml
    • .cargo/
      • config
    • src/
      • dummy_os/
        • Cargo.toml
        • main.rs
    • x86_64-dummy_os.json

The top Cargo.toml:

[workspace]
members = [
    "src/dummy_os",
]

# the profile used for `cargo build`
[profile.dev]
panic = "abort" # disable stack unwinding on panic

# the profile used for `cargo build --release`
[profile.release]
panic = "abort" # disable stack unwinding on panic

The .cargo/config:

[build]
target = "x86_64-dummy_os.json"

[target.'cfg(target_os = "none")']
runner = "bootimage runner"

The src/dummy_os/Cargo.toml:

[package]
name = "dummy_os"
version = "0.1.0"
edition = "2018"

[[bin]]
name = "dummy_os"
path = "main.rs"

[dependencies]
bootloader = "*"

The src/dummy_os/main.rs:

#![no_std] // don't link the Rust standard library
#![no_main] // disable all Rust-level entry points

use core::panic::PanicInfo;

/// This function is called on panic.
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
    loop {}
}

static HELLO: &[u8] = b"Hello World!";

#[no_mangle] // don't mangle the name of this function
pub extern "C" fn _start() -> ! {
    let vga_buffer = 0xb8000 as *mut u8;

    for (i, &byte) in HELLO.iter().enumerate() {
	unsafe {
	    *vga_buffer.offset(i as isize * 2) = byte;
	    *vga_buffer.offset(i as isize * 2 + 1) = 0xb;
	}
    }
    
    loop {}
}

Here's the error:

Building kernel
WARNING: There is no root package to read the cargo-xbuild config from.
    Updating crates.io index
   Compiling core v0.0.0 (~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore)
   Compiling compiler_builtins v0.1.27
   Compiling rustc-std-workspace-core v1.99.0 (~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/tools/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/tmp/cargo-xbuild.B83qpoInHGhF)
    Finished release [optimized] target(s) in 39.40s
   Compiling bootloader v0.9.2
   Compiling dummy_os v0.1.0 (~/dummy_os/src/dummy_os)
    Finished dev [unoptimized + debuginfo] target(s) in 0.94s
Error: Could not find required key `packages[manifest_path = `~/dummy_os/Cargo.toml`]` in cargo metadata output
@phil-opp
Copy link
Member

phil-opp commented May 6, 2020

Thanks a lot for reporting! Unfortunately, supporting workspaces is not quite trivial. For example, it makes config parsing much more complex (e.g. should the bootimage config live in the Cargo.toml in the project root or in the kernel subdirectory?). I tried to find a simple way to fix this bug, but it appears to be quite difficult to add this in a backwards compatible way.

I'm therefore planning to release a new breaking version that cleans up the crate and removes old functionality such as the bootimage test framework. This should make it much easier to add proper handling of workspaces, but it will take some time.

@phil-opp
Copy link
Member

phil-opp commented May 6, 2020

So I invested the past hours to rewrite the crate. The result is available in the rewrite branch.

Could you try the new version to test whether it fixes your problem? To install it, execute:

cargo install bootimage --git https://github.com/rust-osdev/bootimage.git --branch rewrite --force

@nabilmerk
Copy link
Author

Good news, it worked! Many thanks for that.

I also had a look to the branch. There has been a lot of rewriting. You've been quite active in few hours.

@phil-opp
Copy link
Member

phil-opp commented May 7, 2020

Great to hear that!

@phil-opp
Copy link
Member

phil-opp commented May 7, 2020

I just released the new code as version 0.8.0, in case you want to switch back to the official release.

@nabilmerk
Copy link
Author

I just did it and it actually corrected a bug when it didn't find the test executable :). Many thanks again.

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

Successfully merging a pull request may close this issue.

2 participants