rust-osdev / bootimage

Tool to create bootable disk images from a Rust OS kernel.
Apache License 2.0
767 stars 67 forks source link

Where does the dependency on bootloader have to be placed? #58

Closed jschwe closed 4 years ago

jschwe commented 4 years ago

I'm currently trying to build rusty-hermit with bootimage in order to use your bootloader and custom test framework. However I can't seem to figure out where to place the dependency for bootloader. In rusty-hermit the library containing the kernel libhermit-rs is built via a build script, since the application and the kernel are built with different targets. The library is then linked with the application.

Where exactly does bootimage expect the bootloader dependency? The Top level Cargo.toml is just a workspace, which also leads to WARNING: There is no root package to read the cargo-xbuild config from. Also do I need to modify the build script to use cargo-xbuild ? I'm not sure if I'm doing something wrong in that regard but it doesn't seem to make a difference whether I use xbuild or build in the build script for the kernel. In both cases I have to pass "-Z build-std=core,alloc"

I tried:

Created bootimage for `rusty_demo` at `/home/xxx/Dev/rusty-hermit/target/x86_64-unknown-hermit/debug/bootimage-rusty_demo.bin`
Error: An error occured while trying to build the bootloader: Bootloader dependency not found

You need to add a dependency on a crate named `bootloader` in your Cargo.toml.

Caused by:
    Bootloader dependency not found

    You need to add a dependency on a crate named `bootloader` in your Cargo.toml.

Do you have any ideas / hints on what I could do or look at to get this running?

phil-opp commented 4 years ago

The bootloader dependency needs to be in the Cargo.toml of the executable, so for example in demo/Cargo.toml if you want to build the rusty_demo executable.

The problem you are seeing occurs because cargo build builds all binaries in the project by default. In this situation, bootimage tries to also create bootable disk images for all built binaries, but some of the binaries have no bootimage dependency. (In the error message you posted, you see that bootimage successfully created the bootable disk image for the rusty_demo binary but failed afterwards when it tried to created the bootable disk image for the next binary. We should definitely improve the error message to make this more clear.)

To fix this problem, either add a bootimage dependency to all your binaries in the workspace if you want to build them all with bootimage. Alternatively, try building from the subdirectory of an executable or specifying a single executable to build by passing e.g. --bin rusty_demo.

jschwe commented 4 years ago

Thanks a lot, that was very helpful!