Skip to content

Commit 26be890

Browse files
Add rust-toolchain.toml
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. A few jobs need extra components installed, do that with `rustup component add`. 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 #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 #498
1 parent 55e6896 commit 26be890

File tree

9 files changed

+45
-173
lines changed

9 files changed

+45
-173
lines changed

.github/workflows/rust.yml

+9-101
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@ jobs:
2828
sudo apt-get update
2929
sudo apt-get install qemu-system-arm qemu-efi-aarch64 -y
3030
31-
- name: Install stable
32-
uses: actions-rs/toolchain@v1
33-
with:
34-
toolchain: stable
35-
36-
- name: Install latest nightly
37-
uses: actions-rs/toolchain@v1
38-
with:
39-
toolchain: nightly
40-
components: rust-src
41-
# TODO: cache Rust binaries
42-
4331
- name: Build
4432
run: cargo xtask build --target aarch64
4533

@@ -59,18 +47,6 @@ jobs:
5947
sudo apt-get update
6048
sudo apt-get install qemu-system-x86 ovmf -y
6149
62-
- name: Install stable
63-
uses: actions-rs/toolchain@v1
64-
with:
65-
toolchain: stable
66-
67-
- name: Install latest nightly
68-
uses: actions-rs/toolchain@v1
69-
with:
70-
toolchain: nightly
71-
components: rust-src
72-
# TODO: cache Rust binaries
73-
7450
- name: Build
7551
run: cargo xtask build --target x86_64
7652

@@ -106,18 +82,6 @@ jobs:
10682
curl -o OVMF32_CODE.fd https://raw.githubusercontent.com/retrage/edk2-nightly/${EDK2_NIGHTLY_COMMIT}/bin/RELEASEIa32_OVMF_CODE.fd
10783
curl -o OVMF32_VARS.fd https://raw.githubusercontent.com/retrage/edk2-nightly/${EDK2_NIGHTLY_COMMIT}/bin/RELEASEIa32_OVMF_VARS.fd
10884
109-
- name: Install stable
110-
uses: actions-rs/toolchain@v1
111-
with:
112-
toolchain: stable
113-
114-
- name: Install latest nightly
115-
uses: actions-rs/toolchain@v1
116-
with:
117-
toolchain: nightly
118-
components: rust-src
119-
# TODO: cache Rust binaries
120-
12185
- name: Build
12286
run: cargo xtask build --target ia32
12387

@@ -132,18 +96,6 @@ jobs:
13296
- name: Checkout sources
13397
uses: actions/checkout@v2
13498

135-
- name: Install stable
136-
uses: actions-rs/toolchain@v1
137-
with:
138-
toolchain: stable
139-
140-
- name: Install latest nightly
141-
uses: actions-rs/toolchain@v1
142-
with:
143-
profile: minimal
144-
toolchain: nightly
145-
components: rust-src
146-
14799
- name: Run cargo test
148100
run: cargo xtask test
149101

@@ -154,26 +106,15 @@ jobs:
154106
- name: Checkout sources
155107
uses: actions/checkout@v2
156108

157-
- name: Install stable
158-
uses: actions-rs/toolchain@v1
159-
with:
160-
toolchain: stable
161-
162-
- name: Install latest nightly
163-
uses: actions-rs/toolchain@v1
164-
with:
165-
profile: minimal
166-
toolchain: nightly
167-
components: rustfmt, clippy, rust-src
168-
169109
- name: Run cargo fmt
170-
uses: actions-rs/cargo@v1
171-
with:
172-
command: fmt
173-
args: --all -- --check
110+
run: |
111+
rustup component add rustfmt
112+
cargo fmt --all -- --check
174113
175114
- name: Run clippy
176-
run: cargo xtask clippy --warnings-as-errors
115+
run: |
116+
rustup component add clippy
117+
cargo xtask clippy --warnings-as-errors
177118
178119
- name: Run cargo doc
179120
run: cargo xtask doc --warnings-as-errors
@@ -185,20 +126,10 @@ jobs:
185126
- name: Checkout sources
186127
uses: actions/checkout@v2
187128

188-
- name: Install stable
189-
uses: actions-rs/toolchain@v1
190-
with:
191-
toolchain: stable
192-
193-
- name: Install latest nightly toolchain that includes Miri
194-
uses: actions-rs/toolchain@v1
195-
with:
196-
profile: minimal
197-
toolchain: nightly
198-
components: miri
199-
200129
- name: Run miri
201-
run: cargo xtask miri
130+
run: |
131+
rustup component add miri
132+
cargo xtask miri
202133
203134
# This job tests that the template app builds successfully with the
204135
# released versions of the libraries on crates.io.
@@ -214,17 +145,6 @@ jobs:
214145
- name: Checkout sources
215146
uses: actions/checkout@v2
216147

217-
- name: Install stable
218-
uses: actions-rs/toolchain@v1
219-
with:
220-
toolchain: stable
221-
222-
- name: Install latest nightly
223-
uses: actions-rs/toolchain@v1
224-
with:
225-
toolchain: nightly
226-
components: rust-src
227-
228148
- name: Build
229149
run: cargo xtask test-latest-release
230150

@@ -235,17 +155,5 @@ jobs:
235155
- name: Checkout sources
236156
uses: actions/checkout@v2
237157

238-
- name: Install stable
239-
uses: actions-rs/toolchain@v1
240-
with:
241-
toolchain: stable
242-
243-
- name: Install latest nightly
244-
uses: actions-rs/toolchain@v1
245-
with:
246-
profile: minimal
247-
toolchain: nightly
248-
components: rust-src
249-
250158
- name: Build
251159
run: cargo xtask build

BUILDING.md

+18-12
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,31 @@ targets.
1313
[`i686-unknown-uefi`]: https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_target/src/spec/i686_unknown_uefi.rs
1414
[`x86_64-unknown-uefi`]: https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc_target/src/spec/x86_64_unknown_uefi.rs
1515

16-
## Building
16+
## Building for a UEFI target
1717

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

20-
`rustup toolchain install nightly`
22+
- Install a `nightly` version of the Rust [toolchain] and include the
23+
`rust-src` [component]. The easiest way to do this is with a
24+
`rust-toolchain.toml` file, for example:
25+
26+
```toml
27+
[toolchain]
28+
channel = "nightly"
29+
components = ["rust-src"]
30+
```
2131

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

24-
- You need to add the `rust-src` toolchain [component](https://rust-lang.github.io/rustup/concepts/components.html)
25-
(if it's not already installed), which Cargo will use to build the core crates for the UEFI target:
26-
27-
`rustup component add --toolchain nightly rust-src`
28-
29-
- Build this crate using the `nightly` toolchain:
30-
31-
`cargo +nightly build --target x86_64-unknown-uefi`.
34+
`cargo build --target x86_64-unknown-uefi`.
3235

3336
- The `target` directory will contain a `x86_64-unknown-uefi` subdirectory,
3437
where you will find a `<crate name>.efi` file - a normal UEFI executable.
38+
39+
[toolchain]: https://rust-lang.github.io/rustup/concepts/toolchains.html
40+
[component]: https://rust-lang.github.io/rustup/concepts/components.html
3541

3642
## Running
3743

README.md

-6
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ the [UEFI specification][spec] for detailed information.
6363

6464
## Building and testing uefi-rs
6565

66-
Install the `nightly` version of Rust and the `rust-src` component:
67-
```
68-
rustup toolchain install nightly
69-
rustup component add --toolchain nightly rust-src
70-
```
71-
7266
Use the `cargo xtask` command to build and test the crate.
7367

7468
Available commands:

rust-toolchain.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[toolchain]
2+
# Nightly is required due to use of unstable features.
3+
channel = "nightly"
4+
5+
# Install the `rust-src` component so that `-Zbuild-std` works. This in
6+
# addition to the components included in the default profile.
7+
components = ["rust-src"]

template/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ how to build and run a UEFI application developed using `uefi-rs`.
88

99
## File structure
1010

11-
- [`.cargo/config`](./.cargo/config) file sets some `build-std` options.
11+
- [`.cargo/config`](./.cargo/config) sets some `build-std` options.
12+
- [`rust-toolchain.toml`](rust-toolchain.toml) sets the nightly channel.
1213
- [`Cargo.toml`](./Cargo.toml) shows the necessary dependencies.
1314
- [`src/main.rs`](./src/main.rs) has a minimal entry point that
1415
initializes the `uefi-services` crate and exits successfully.

template/rust-toolchain.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "nightly"
3+
components = ["rust-src"]

xtask/src/cargo.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ pub fn fix_nested_cargo_env(cmd: &mut Command) {
118118
pub struct Cargo {
119119
pub action: CargoAction,
120120
pub features: Vec<Feature>,
121-
pub toolchain: Option<String>,
122121
pub packages: Vec<Package>,
123122
pub release: bool,
124123
pub target: Option<UefiArch>,
@@ -131,10 +130,6 @@ impl Cargo {
131130

132131
fix_nested_cargo_env(&mut cmd);
133132

134-
if let Some(toolchain) = &self.toolchain {
135-
cmd.arg(&format!("+{}", toolchain));
136-
}
137-
138133
let action;
139134
let mut sub_action = None;
140135
let mut extra_args: Vec<&str> = Vec::new();
@@ -239,15 +234,14 @@ mod tests {
239234
let cargo = Cargo {
240235
action: CargoAction::Doc { open: true },
241236
features: vec![Feature::Alloc],
242-
toolchain: Some("nightly".into()),
243237
packages: vec![Package::Uefi, Package::Xtask],
244238
release: false,
245239
target: None,
246240
warnings_as_errors: true,
247241
};
248242
assert_eq!(
249243
command_to_string(&cargo.command().unwrap()),
250-
"RUSTDOCFLAGS=-Dwarnings cargo +nightly doc --package uefi --package xtask --features alloc --open"
244+
"RUSTDOCFLAGS=-Dwarnings cargo doc --package uefi --package xtask --features alloc --open"
251245
);
252246
}
253247
}

xtask/src/main.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,15 @@ mod util;
1111
use anyhow::Result;
1212
use cargo::{fix_nested_cargo_env, Cargo, CargoAction, Feature, Package};
1313
use clap::Parser;
14-
use opt::{Action, BuildOpt, ClippyOpt, DocOpt, MiriOpt, Opt, QemuOpt};
14+
use opt::{Action, BuildOpt, ClippyOpt, DocOpt, Opt, QemuOpt};
1515
use std::process::Command;
1616
use tempfile::TempDir;
1717
use util::{command_to_string, run_cmd};
1818

19-
const NIGHTLY: &str = "nightly";
20-
2119
fn build(opt: &BuildOpt) -> Result<()> {
2220
let cargo = Cargo {
2321
action: CargoAction::Build,
2422
features: Feature::more_code(),
25-
toolchain: opt.toolchain.or(NIGHTLY),
2623
packages: Package::all_except_xtask(),
2724
release: opt.build_mode.release,
2825
target: Some(*opt.target),
@@ -36,7 +33,6 @@ fn clippy(opt: &ClippyOpt) -> Result<()> {
3633
let cargo = Cargo {
3734
action: CargoAction::Clippy,
3835
features: Feature::more_code(),
39-
toolchain: opt.toolchain.or(NIGHTLY),
4036
packages: Package::all_except_xtask(),
4137
release: false,
4238
target: Some(*opt.target),
@@ -48,7 +44,6 @@ fn clippy(opt: &ClippyOpt) -> Result<()> {
4844
let cargo = Cargo {
4945
action: CargoAction::Clippy,
5046
features: Vec::new(),
51-
toolchain: None,
5247
packages: vec![Package::Xtask],
5348
release: false,
5449
target: None,
@@ -62,7 +57,6 @@ fn doc(opt: &DocOpt) -> Result<()> {
6257
let cargo = Cargo {
6358
action: CargoAction::Doc { open: opt.open },
6459
features: Feature::more_code(),
65-
toolchain: opt.toolchain.or(NIGHTLY),
6660
packages: Package::published(),
6761
release: false,
6862
target: None,
@@ -72,11 +66,10 @@ fn doc(opt: &DocOpt) -> Result<()> {
7266
}
7367

7468
/// Run unit tests and doctests under Miri.
75-
fn run_miri(opt: &MiriOpt) -> Result<()> {
69+
fn run_miri() -> Result<()> {
7670
let cargo = Cargo {
7771
action: CargoAction::Miri,
7872
features: [Feature::Exts].into(),
79-
toolchain: opt.toolchain.or(NIGHTLY),
8073
packages: [Package::Uefi].into(),
8174
release: false,
8275
target: None,
@@ -100,7 +93,6 @@ fn run_vm_tests(opt: &QemuOpt) -> Result<()> {
10093
let cargo = Cargo {
10194
action: CargoAction::Build,
10295
features,
103-
toolchain: opt.toolchain.or(NIGHTLY),
10496
packages: vec![Package::UefiTestRunner],
10597
release: opt.build_mode.release,
10698
target: Some(*opt.target),
@@ -119,7 +111,6 @@ fn run_host_tests() -> Result<()> {
119111
let cargo = Cargo {
120112
action: CargoAction::Test,
121113
features: Vec::new(),
122-
toolchain: None,
123114
packages: vec![Package::Xtask],
124115
release: false,
125116
target: None,
@@ -131,7 +122,6 @@ fn run_host_tests() -> Result<()> {
131122
let cargo = Cargo {
132123
action: CargoAction::Test,
133124
features: vec![Feature::Exts],
134-
toolchain: Some(NIGHTLY.into()),
135125
// Don't test uefi-services (or the packages that depend on it)
136126
// as it has lang items that conflict with `std`.
137127
packages: vec![Package::Uefi, Package::UefiMacros],
@@ -173,7 +163,7 @@ fn test_latest_release() -> Result<()> {
173163
let mut build_cmd = Command::new("cargo");
174164
fix_nested_cargo_env(&mut build_cmd);
175165
build_cmd
176-
.args(&["+nightly", "build", "--target", "x86_64-unknown-uefi"])
166+
.args(&["build", "--target", "x86_64-unknown-uefi"])
177167
.current_dir(tmp_dir.join("template"));
178168

179169
// Check that the command is indeed in BUILDING.md, then verify the
@@ -190,7 +180,7 @@ fn main() -> Result<()> {
190180
Action::Build(build_opt) => build(build_opt),
191181
Action::Clippy(clippy_opt) => clippy(clippy_opt),
192182
Action::Doc(doc_opt) => doc(doc_opt),
193-
Action::Miri(miri_opt) => run_miri(miri_opt),
183+
Action::Miri(_) => run_miri(),
194184
Action::Run(qemu_opt) => run_vm_tests(qemu_opt),
195185
Action::Test(_) => run_host_tests(),
196186
Action::TestLatestRelease(_) => test_latest_release(),

0 commit comments

Comments
 (0)