Skip to content

Commit

Permalink
Replace cargo xbuild calls with cargo build -Zbuild-std=core
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-opp committed Apr 30, 2024
1 parent 90928c6 commit 318b60e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,16 @@ jobs:
- name: "Install Rustup Components"
run: rustup component add rust-src llvm-tools-preview
- name: "Install cargo-xbuild"
run: cargo install cargo-xbuild --debug

- name: "Install cargo-binutils"
run: cargo install cargo-binutils --version 0.1.7 --debug

- run: cargo xbuild
- run: cargo build -Zbuild-std=core
working-directory: test-kernel
name: 'Build Test Kernel'

- name: 'Build Bootloader'
run: cargo xbuild --bin bootloader --features binary --release
run: cargo build -Zbuild-std=core --bin bootloader --features binary --release
env:
KERNEL: "test-kernel/target/x86_64-test-kernel/debug/test-kernel"
KERNEL_MANIFEST: "test-kernel/Cargo.toml"
Expand Down Expand Up @@ -96,10 +95,8 @@ jobs:
- uses: actions/checkout@v1
- name: "Install Rustup Components"
run: rustup component add rust-src llvm-tools-preview
- name: "Install cargo-xbuild"
run: cargo install cargo-xbuild --debug
- name: 'Build Example Kernel'
run: cargo xbuild
run: cargo build -Zbuild-std=core
working-directory: example-kernel


Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,28 @@ Note that the addresses **must** be given as strings (in either hex or decimal f

## Requirements

You need a nightly [Rust](https://www.rust-lang.org) compiler and [cargo xbuild](https://github.com/rust-osdev/cargo-xbuild). You also need the `llvm-tools-preview` component, which can be installed through `rustup component add llvm-tools-preview`.
You need a nightly [Rust](https://www.rust-lang.org) compiler. You also need the `llvm-tools-preview` component, which can be installed through `rustup component add llvm-tools-preview`.

## Build

The simplest way to use the bootloader is in combination with the [bootimage](https://github.com/rust-osdev/bootimage) tool. This crate **requires at least bootimage 0.7.7**. With the tool installed, you can add a normal cargo dependency on the `bootloader` crate to your kernel and then run `bootimage build` to create a bootable disk image. You can also execute `bootimage run` to run your kernel in [QEMU](https://www.qemu.org/) (needs to be installed).

To compile the bootloader manually, you need to invoke `cargo xbuild` with two environment variables:
To compile the bootloader manually, you need to invoke `cargo build -Zbuild-std=core` with two environment variables:
* `KERNEL`: points to your kernel executable (in the ELF format)
* `KERNEL_MANIFEST`: points to the `Cargo.toml` describing your kernel

For example:
```
KERNEL=/path/to/your/kernel/target/debug/your_kernel KERNEL_MANIFEST=/path/to/your/kernel/Cargo.toml cargo xbuild
KERNEL=/path/to/your/kernel/target/debug/your_kernel KERNEL_MANIFEST=/path/to/your/kernel/Cargo.toml cargo build -Zbuild-std=core
```

As an example, you can build the bootloader with example kernel from the `example-kernel` directory with the following commands:

```
cd example-kernel
cargo xbuild
cargo build -Zbuild-std=core
cd ..
KERNEL=example-kernel/target/x86_64-example-kernel/debug/example-kernel KERNEL_MANIFEST=example-kernel/Cargo.toml cargo xbuild --release --features binary
KERNEL=example-kernel/target/x86_64-example-kernel/debug/example-kernel KERNEL_MANIFEST=example-kernel/Cargo.toml cargo build -Zbuild-std=core --release --features binary
```

The `binary` feature is required to enable the dependencies required for compiling the bootloader executable. The command results in a bootloader executable at `target/x86_64-bootloader.json/release/bootloader`. This executable is still an ELF file, which can't be run directly.
Expand Down

0 comments on commit 318b60e

Please sign in to comment.