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 `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 cb50b77
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 154 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
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
9 changes: 9 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[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"
]
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
33 changes: 1 addition & 32 deletions xtask/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@ impl Deref for TargetOpt {
}
}

#[derive(Debug, Parser)]
pub struct ToolchainOpt {
/// Rust toolchain to use, e.g. "nightly-2022-02-24".
#[clap(long, action)]
toolchain: Option<String>,
}

impl ToolchainOpt {
/// Get the toolchain arg if set, otherwise use `default_toolchain`.
pub fn or(&self, default_toolchain: &str) -> Option<String> {
self.toolchain
.clone()
.or_else(|| Some(default_toolchain.to_string()))
}
}

#[derive(Debug, Parser)]
pub struct BuildModeOpt {
/// Build in release mode.
Expand Down Expand Up @@ -75,9 +59,6 @@ pub struct BuildOpt {
#[clap(flatten)]
pub target: TargetOpt,

#[clap(flatten)]
pub toolchain: ToolchainOpt,

#[clap(flatten)]
pub build_mode: BuildModeOpt,
}
Expand All @@ -88,19 +69,13 @@ pub struct ClippyOpt {
#[clap(flatten)]
pub target: TargetOpt,

#[clap(flatten)]
pub toolchain: ToolchainOpt,

#[clap(flatten)]
pub warning: WarningOpt,
}

/// Build the docs for the uefi packages.
#[derive(Debug, Parser)]
pub struct DocOpt {
#[clap(flatten)]
pub toolchain: ToolchainOpt,

/// Open the docs in a browser.
#[clap(long, action)]
pub open: bool,
Expand All @@ -111,20 +86,14 @@ pub struct DocOpt {

/// Run unit tests and doctests under Miri.
#[derive(Debug, Parser)]
pub struct MiriOpt {
#[clap(flatten)]
pub toolchain: ToolchainOpt,
}
pub struct MiriOpt {}

/// Build uefi-test-runner and run it in QEMU.
#[derive(Debug, Parser)]
pub struct QemuOpt {
#[clap(flatten)]
pub target: TargetOpt,

#[clap(flatten)]
pub toolchain: ToolchainOpt,

#[clap(flatten)]
pub build_mode: BuildModeOpt,

Expand Down

0 comments on commit cb50b77

Please sign in to comment.