diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 82eb467c6..390267b33 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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. @@ -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 @@ -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 diff --git a/BUILDING.md b/BUILDING.md index 38e7ec01e..6819adba9 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -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 `.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 diff --git a/README.md b/README.md index 750f8fa0c..f6bb1ea27 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 000000000..4894e55a9 --- /dev/null +++ b/rust-toolchain.toml @@ -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"] diff --git a/template/README.md b/template/README.md index 424b15973..4a3b1c417 100644 --- a/template/README.md +++ b/template/README.md @@ -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. diff --git a/template/rust-toolchain.toml b/template/rust-toolchain.toml new file mode 100644 index 000000000..404eda326 --- /dev/null +++ b/template/rust-toolchain.toml @@ -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"] diff --git a/xtask/src/cargo.rs b/xtask/src/cargo.rs index 58f751459..e9f03ab2e 100644 --- a/xtask/src/cargo.rs +++ b/xtask/src/cargo.rs @@ -118,7 +118,6 @@ pub fn fix_nested_cargo_env(cmd: &mut Command) { pub struct Cargo { pub action: CargoAction, pub features: Vec, - pub toolchain: Option, pub packages: Vec, pub release: bool, pub target: Option, @@ -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(); @@ -239,7 +234,6 @@ 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, @@ -247,7 +241,7 @@ mod tests { }; 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" ); } } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 4d39611d5..ae8327d6d 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -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), @@ -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), @@ -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, @@ -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, @@ -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, @@ -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), @@ -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, @@ -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], @@ -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 @@ -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(), diff --git a/xtask/src/opt.rs b/xtask/src/opt.rs index 1f5fcc0cf..751e17b81 100644 --- a/xtask/src/opt.rs +++ b/xtask/src/opt.rs @@ -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, -} - -impl ToolchainOpt { - /// Get the toolchain arg if set, otherwise use `default_toolchain`. - pub fn or(&self, default_toolchain: &str) -> Option { - self.toolchain - .clone() - .or_else(|| Some(default_toolchain.to_string())) - } -} - #[derive(Debug, Parser)] pub struct BuildModeOpt { /// Build in release mode. @@ -75,9 +59,6 @@ pub struct BuildOpt { #[clap(flatten)] pub target: TargetOpt, - #[clap(flatten)] - pub toolchain: ToolchainOpt, - #[clap(flatten)] pub build_mode: BuildModeOpt, } @@ -88,9 +69,6 @@ pub struct ClippyOpt { #[clap(flatten)] pub target: TargetOpt, - #[clap(flatten)] - pub toolchain: ToolchainOpt, - #[clap(flatten)] pub warning: WarningOpt, } @@ -98,9 +76,6 @@ pub struct ClippyOpt { /// 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, @@ -111,10 +86,7 @@ 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)] @@ -122,9 +94,6 @@ pub struct QemuOpt { #[clap(flatten)] pub target: TargetOpt, - #[clap(flatten)] - pub toolchain: ToolchainOpt, - #[clap(flatten)] pub build_mode: BuildModeOpt,