Skip to content

Add rust-toolchain.toml and pin to a working nightly #502

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 9 additions & 101 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,26 +106,15 @@ 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:
command: fmt
args: --all -- --check
run: |
rustup component add rustfmt
cargo fmt --all -- --check

- name: Run clippy
run: cargo xtask clippy --warnings-as-errors
run: |
rustup component add clippy
cargo xtask clippy --warnings-as-errors

- name: Run cargo doc
run: cargo xtask doc --warnings-as-errors
Expand All @@ -185,20 +126,10 @@ 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
run: |
rustup component add miri
cargo xtask miri

# This job tests that the template app builds successfully with the
# released versions of the libraries on crates.io.
Expand All @@ -214,17 +145,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 +155,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
10 changes: 10 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[toolchain]
# Pinned due to https://github.com/rust-osdev/uefi-rs/issues/500.
#
# Compilation started failing 2022-09-02. The previous several builds
# don't have miri available though, so pin to a slightly older version.
channel = "nightly-2022-08-26"

# Install the `rust-src` component so that `-Zbuild-std` works. This in
# addition to the components included in the default profile.
components = ["rust-src"]
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
4 changes: 4 additions & 0 deletions template/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
# Pinned due to https://github.com/rust-osdev/uefi-rs/issues/500.
channel = "nightly-2022-09-01"
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