Skip to content

Commit

Permalink
Add rust-toolchain.toml
Browse files Browse the repository at this point in the history
Add a `rust-toolchain.toml` file that specifies the channel and
components needed to build uefi-rs. See
https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file for
documentation of the `rust-toolchain.toml` format.

Remove the `--toolchain` option from `xtask`, as using this file is a
simpler alternative. Also remove the instructions for installing the
nightly toolchain from the readme, as `rustup` will do this
automatically now.

The template application has been updated to add a
`rust-toolchain.toml`, and `BUILDING.md` has been updated to mention it
as well.

The `toolchain` action previously used in the CI is unmaintained and
doesn't understand `rust-toolchain.toml` (it does understand the older
`rust-toolchain` file, but that doesn't allow for including required
components). Since the runners come with rustup already installed, we
don't actually need a complex action here anyway, so just remove those
sections entirely.

Note that this change will also cause `xtask` itself to be built with
nightly. That should generally be fine, we only had it using stable
because of rust-osdev#397, and in the
future we can easily temporarily pin to a non-current nightly if a bug
occurs with an `xtask` dependency again.

Fixes rust-osdev#498
  • Loading branch information
nicholasbishop committed Sep 4, 2022
1 parent 55e6896 commit d414f52
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 167 deletions.
95 changes: 0 additions & 95 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ jobs:
sudo apt-get update
sudo apt-get install qemu-system-arm qemu-efi-aarch64 -y
- name: Install stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rust-src
# TODO: cache Rust binaries

- name: Build
run: cargo xtask build --target aarch64

Expand All @@ -59,18 +47,6 @@ jobs:
sudo apt-get update
sudo apt-get install qemu-system-x86 ovmf -y
- name: Install stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rust-src
# TODO: cache Rust binaries

- name: Build
run: cargo xtask build --target x86_64

Expand Down Expand Up @@ -106,18 +82,6 @@ jobs:
curl -o OVMF32_CODE.fd https://raw.githubusercontent.com/retrage/edk2-nightly/${EDK2_NIGHTLY_COMMIT}/bin/RELEASEIa32_OVMF_CODE.fd
curl -o OVMF32_VARS.fd https://raw.githubusercontent.com/retrage/edk2-nightly/${EDK2_NIGHTLY_COMMIT}/bin/RELEASEIa32_OVMF_VARS.fd
- name: Install stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rust-src
# TODO: cache Rust binaries

- name: Build
run: cargo xtask build --target ia32

Expand All @@ -132,18 +96,6 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rust-src

- name: Run cargo test
run: cargo xtask test

Expand All @@ -154,18 +106,6 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rustfmt, clippy, rust-src

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
Expand All @@ -185,18 +125,6 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Install latest nightly toolchain that includes Miri
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: miri

- name: Run miri
run: cargo xtask miri

Expand All @@ -214,17 +142,6 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rust-src

- name: Build
run: cargo xtask test-latest-release

Expand All @@ -235,17 +152,5 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rust-src

- name: Build
run: cargo xtask build
30 changes: 18 additions & 12 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,31 @@ targets.
[`i686-unknown-uefi`]: https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_target/src/spec/i686_unknown_uefi.rs
[`x86_64-unknown-uefi`]: https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_target/src/spec/x86_64_unknown_uefi.rs

## Building
## Building for a UEFI target

- Install a `nightly` version of the Rust [toolchain](https://rust-lang.github.io/rustup/concepts/toolchains.html):
For instructions on building the `uefi-rs` crates, see the
[README](README.md). This section is for building your own crates,
outside of the `uefi-rs` repo.

`rustup toolchain install nightly`
- Install a `nightly` version of the Rust [toolchain] and include the
`rust-src` [component]. The easiest way to do this is with a
`rust-toolchain.toml` file, for example:

```toml
[toolchain]
channel = "nightly"
components = ["rust-src"]
```

It is not currently possible to build the core crate with a stable version of the Rust compiler.
- Build the crate:

- You need to add the `rust-src` toolchain [component](https://rust-lang.github.io/rustup/concepts/components.html)
(if it's not already installed), which Cargo will use to build the core crates for the UEFI target:

`rustup component add --toolchain nightly rust-src`

- Build this crate using the `nightly` toolchain:

`cargo +nightly build --target x86_64-unknown-uefi`.
`cargo build --target x86_64-unknown-uefi`.

- The `target` directory will contain a `x86_64-unknown-uefi` subdirectory,
where you will find a `<crate name>.efi` file - a normal UEFI executable.

[toolchain]: https://rust-lang.github.io/rustup/concepts/toolchains.html
[component]: https://rust-lang.github.io/rustup/concepts/components.html

## Running

Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ the [UEFI specification][spec] for detailed information.

## Building and testing uefi-rs

Install the `nightly` version of Rust and the `rust-src` component:
```
rustup toolchain install nightly
rustup component add --toolchain nightly rust-src
```

Use the `cargo xtask` command to build and test the crate.

Available commands:
Expand Down
13 changes: 13 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[toolchain]
# Nightly is required due to use of unstable features.
channel = "nightly"
components = [
# Needed for `cargo xtask miri`.
"miri",
# Needed for `-Zbuild-std`.
"rust-src",

# Standard components.
"clippy",
"rustfmt",
]
3 changes: 2 additions & 1 deletion template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ how to build and run a UEFI application developed using `uefi-rs`.

## File structure

- [`.cargo/config`](./.cargo/config) file sets some `build-std` options.
- [`.cargo/config`](./.cargo/config) sets some `build-std` options.
- [`rust-toolchain.toml`](rust-toolchain.toml) sets the nightly channel.
- [`Cargo.toml`](./Cargo.toml) shows the necessary dependencies.
- [`src/main.rs`](./src/main.rs) has a minimal entry point that
initializes the `uefi-services` crate and exits successfully.
Expand Down
3 changes: 3 additions & 0 deletions template/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "nightly"
components = ["rust-src"]
8 changes: 1 addition & 7 deletions xtask/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ pub fn fix_nested_cargo_env(cmd: &mut Command) {
pub struct Cargo {
pub action: CargoAction,
pub features: Vec<Feature>,
pub toolchain: Option<String>,
pub packages: Vec<Package>,
pub release: bool,
pub target: Option<UefiArch>,
Expand All @@ -131,10 +130,6 @@ impl Cargo {

fix_nested_cargo_env(&mut cmd);

if let Some(toolchain) = &self.toolchain {
cmd.arg(&format!("+{}", toolchain));
}

let action;
let mut sub_action = None;
let mut extra_args: Vec<&str> = Vec::new();
Expand Down Expand Up @@ -239,15 +234,14 @@ mod tests {
let cargo = Cargo {
action: CargoAction::Doc { open: true },
features: vec![Feature::Alloc],
toolchain: Some("nightly".into()),
packages: vec![Package::Uefi, Package::Xtask],
release: false,
target: None,
warnings_as_errors: true,
};
assert_eq!(
command_to_string(&cargo.command().unwrap()),
"RUSTDOCFLAGS=-Dwarnings cargo +nightly doc --package uefi --package xtask --features alloc --open"
"RUSTDOCFLAGS=-Dwarnings cargo doc --package uefi --package xtask --features alloc --open"
);
}
}
18 changes: 4 additions & 14 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ mod util;
use anyhow::Result;
use cargo::{fix_nested_cargo_env, Cargo, CargoAction, Feature, Package};
use clap::Parser;
use opt::{Action, BuildOpt, ClippyOpt, DocOpt, MiriOpt, Opt, QemuOpt};
use opt::{Action, BuildOpt, ClippyOpt, DocOpt, Opt, QemuOpt};
use std::process::Command;
use tempfile::TempDir;
use util::{command_to_string, run_cmd};

const NIGHTLY: &str = "nightly";

fn build(opt: &BuildOpt) -> Result<()> {
let cargo = Cargo {
action: CargoAction::Build,
features: Feature::more_code(),
toolchain: opt.toolchain.or(NIGHTLY),
packages: Package::all_except_xtask(),
release: opt.build_mode.release,
target: Some(*opt.target),
Expand All @@ -36,7 +33,6 @@ fn clippy(opt: &ClippyOpt) -> Result<()> {
let cargo = Cargo {
action: CargoAction::Clippy,
features: Feature::more_code(),
toolchain: opt.toolchain.or(NIGHTLY),
packages: Package::all_except_xtask(),
release: false,
target: Some(*opt.target),
Expand All @@ -48,7 +44,6 @@ fn clippy(opt: &ClippyOpt) -> Result<()> {
let cargo = Cargo {
action: CargoAction::Clippy,
features: Vec::new(),
toolchain: None,
packages: vec![Package::Xtask],
release: false,
target: None,
Expand All @@ -62,7 +57,6 @@ fn doc(opt: &DocOpt) -> Result<()> {
let cargo = Cargo {
action: CargoAction::Doc { open: opt.open },
features: Feature::more_code(),
toolchain: opt.toolchain.or(NIGHTLY),
packages: Package::published(),
release: false,
target: None,
Expand All @@ -72,11 +66,10 @@ fn doc(opt: &DocOpt) -> Result<()> {
}

/// Run unit tests and doctests under Miri.
fn run_miri(opt: &MiriOpt) -> Result<()> {
fn run_miri() -> Result<()> {
let cargo = Cargo {
action: CargoAction::Miri,
features: [Feature::Exts].into(),
toolchain: opt.toolchain.or(NIGHTLY),
packages: [Package::Uefi].into(),
release: false,
target: None,
Expand All @@ -100,7 +93,6 @@ fn run_vm_tests(opt: &QemuOpt) -> Result<()> {
let cargo = Cargo {
action: CargoAction::Build,
features,
toolchain: opt.toolchain.or(NIGHTLY),
packages: vec![Package::UefiTestRunner],
release: opt.build_mode.release,
target: Some(*opt.target),
Expand All @@ -119,7 +111,6 @@ fn run_host_tests() -> Result<()> {
let cargo = Cargo {
action: CargoAction::Test,
features: Vec::new(),
toolchain: None,
packages: vec![Package::Xtask],
release: false,
target: None,
Expand All @@ -131,7 +122,6 @@ fn run_host_tests() -> Result<()> {
let cargo = Cargo {
action: CargoAction::Test,
features: vec![Feature::Exts],
toolchain: Some(NIGHTLY.into()),
// Don't test uefi-services (or the packages that depend on it)
// as it has lang items that conflict with `std`.
packages: vec![Package::Uefi, Package::UefiMacros],
Expand Down Expand Up @@ -173,7 +163,7 @@ fn test_latest_release() -> Result<()> {
let mut build_cmd = Command::new("cargo");
fix_nested_cargo_env(&mut build_cmd);
build_cmd
.args(&["+nightly", "build", "--target", "x86_64-unknown-uefi"])
.args(&["build", "--target", "x86_64-unknown-uefi"])
.current_dir(tmp_dir.join("template"));

// Check that the command is indeed in BUILDING.md, then verify the
Expand All @@ -190,7 +180,7 @@ fn main() -> Result<()> {
Action::Build(build_opt) => build(build_opt),
Action::Clippy(clippy_opt) => clippy(clippy_opt),
Action::Doc(doc_opt) => doc(doc_opt),
Action::Miri(miri_opt) => run_miri(miri_opt),
Action::Miri(_) => run_miri(),
Action::Run(qemu_opt) => run_vm_tests(qemu_opt),
Action::Test(_) => run_host_tests(),
Action::TestLatestRelease(_) => test_latest_release(),
Expand Down
Loading

0 comments on commit d414f52

Please sign in to comment.