Skip to content

Commit a6bdfe5

Browse files
nicholasbishopGabrielMajeri
authored andcommitted
Replace build.py with the xtask pattern
This is a rewrite of the Python build.py code in Rust. See https://github.com/matklad/cargo-xtask for details of the xtask pattern. Essentially it's a pattern for extending cargo with project-specific commands. Using Rust gives all the usual benefits of checking stuff at compile time, thorough error handling, ease of testing, etc. It is more verbose though, so the LOC goes up a bit. * Removed `build-std` settings from `.cargo/config` because we want to run `xtask` with the default compiler config. The various `cargo xtask` commands handle adding the build-std args where needed. This has the side effect of obsoleting the `uefi-macros/tests/cargo_wrapper` hack. * The build subcommand now builds the whole workspace (except for xtask, since that implicitly has already been built). So no separate CI step to test that the `tmplate` package builds is needed. * Dropped the `--verbose` option, just always print the commands being run since it's helpful info. * Looked like there was some vestigial timeout code for the VM test but no timeout was set that I could see; added a timeout to the github workflow yaml instead.
1 parent 514037f commit a6bdfe5

File tree

18 files changed

+971
-544
lines changed

18 files changed

+971
-544
lines changed

.cargo/config

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
[unstable]
2-
build-std = ["core", "compiler_builtins", "alloc"]
3-
build-std-features = ["compiler-builtins-mem"]
1+
[alias]
2+
xtask = "run --package xtask --"

.github/workflows/rust.yml

+7-17
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
# TODO: cache Rust binaries
2626

2727
- name: Build
28-
run: ./build.py build --target aarch64
28+
run: cargo xtask build --target aarch64
2929

3030
build_and_test:
3131
name: Build and run tests on x86_64
@@ -47,17 +47,12 @@ jobs:
4747
components: rust-src
4848
# TODO: cache Rust binaries
4949

50-
- name: Build template
51-
uses: actions-rs/cargo@v1
52-
with:
53-
command: build
54-
args: --target x86_64-unknown-uefi --manifest-path template/Cargo.toml
55-
5650
- name: Build
57-
run: ./build.py build
51+
run: cargo xtask build --target x86_64
5852

5953
- name: Run VM tests
60-
run: ./build.py run --headless --ci
54+
run: cargo xtask run --target x86_64 --headless --ci
55+
timeout-minutes: 2
6156

6257
test:
6358
name: Run tests and documentation tests
@@ -75,7 +70,7 @@ jobs:
7570
override: true
7671

7772
- name: Run cargo test
78-
run: ./build.py test
73+
run: cargo xtask test
7974

8075
lints:
8176
name: Lints
@@ -99,12 +94,7 @@ jobs:
9994
args: --all -- --check
10095

10196
- name: Run clippy
102-
run: ./build.py clippy
97+
run: cargo xtask clippy --warnings-as-errors
10398

10499
- name: Run cargo doc
105-
uses: actions-rs/cargo@v1
106-
env:
107-
RUSTDOCFLAGS: -Dwarnings
108-
with:
109-
command: doc
110-
args: --target x86_64-unknown-uefi --all-features
100+
run: cargo xtask doc --warnings-as-errors

BUILDING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ targets.
4242

4343
- To run this in QEMU:
4444
- You will need a recent version of QEMU as well as OVMF to provide UEFI support
45-
- Check the [`build.py`](uefi-test-runner/build.py) script for an idea of
45+
- Check the [`qemu.rs`](xtask/src/qemu.rs) module for an idea of
4646
what arguments to pass to QEMU.
4747

4848
In principle, you need to replicate the file structure described above for an USB drive,

CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Pull requests, issues and suggestions are welcome!
55
The UEFI spec is huge, so there might be some omissions or some missing features.
66
You should follow the existing project structure when adding new items.
77

8-
See the top-level [README](../README.md) for details of using `./build.py` to
8+
See the top-level [README](../README.md) for details of using `cargo xtask` to
99
build and test the project.
1010

1111
Make some changes in your favourite editor / IDE:
@@ -14,7 +14,7 @@ I use [VS Code][code] with the [RLS][rls] extension.
1414
Test your changes:
1515

1616
```shell
17-
./build.py run
17+
cargo xtask run
1818
```
1919

2020
The line above will open a QEMU window where the test harness will run some tests.
@@ -23,7 +23,7 @@ Any contributions are also expected to pass [Clippy][clippy]'s static analysis,
2323
which you can run as follows:
2424

2525
```shell
26-
./build.py clippy
26+
cargo xtask clippy
2727
```
2828

2929
[clippy]: https://github.com/rust-lang-nursery/rust-clippy

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ exclude = [
1010
"uefi-macros/**",
1111
"uefi-services/**",
1212
"uefi-test-runner/**",
13+
"xtask/**",
1314
]
1415
description = "Safe and easy-to-use wrapper for building UEFI apps"
1516
repository = "https://github.com/rust-osdev/uefi-rs"
@@ -43,6 +44,7 @@ members = [
4344
"uefi-macros",
4445
"uefi-services",
4546
"uefi-test-runner",
47+
"xtask",
4648
]
4749

4850
[patch.crates-io]

README.md

+20-14
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,34 @@ rustup toolchain install nightly
7171
rustup component add --toolchain nightly rust-src
7272
```
7373

74-
Use the `./build.py` script to build and test the crate.
74+
Use the `cargo xtask` command to build and test the crate.
7575

7676
Available commands:
77-
- `build`: build `uefi-test-runner`
78-
- `clippy`: run clippy on the whole workspace
79-
- `doc`: build the docs for the library packages
77+
- `build`: build all the UEFI packages
78+
- `--release`: build in release mode
79+
- `--target {x86_64,aarch64}`: choose target UEFI arch
80+
- `clippy`: run clippy on all the packages
81+
- `--target {x86_64,aarch64}`: choose target UEFI arch
82+
- `--warnings-as-errors`: treat warnings as errors
83+
- `doc`: build the docs for the UEFI packages
84+
- `--open`: open the docs in a browser
85+
- `--warnings-as-errors`: treat warnings as errors
8086
- `run`: build `uefi-test-runner` and run it in QEMU
87+
- `--ci`: disable some tests that don't work in the CI
88+
- `--disable-kvm`: disable hardware accelerated virtualization support in QEMU.
89+
Especially useful if you want to run the tests under
90+
[WSL](https://docs.microsoft.com/en-us/windows/wsl) on Windows.
91+
- `--headless`: run QEMU without a GUI
92+
- `--ovmf-dir <PATH>`: directory in which to look for OVMF files
93+
- `--release`: build in release mode
94+
- `--target {x86_64,aarch64}`: choose target UEFI arch
8195
- `test`: run unit tests and doctests on the host
8296

83-
Available options:
84-
- `--target {x86_64,aarch64}`: choose which architecture to build/run the tests
85-
- `--verbose`: enables verbose mode, prints commands before running them
86-
- `--headless`: enables headless mode, which runs QEMU without a GUI
87-
- `--release`: builds the code with optimizations enabled
88-
- `--disable-kvm`: disable [KVM](https://www.linux-kvm.org/page/Main_Page) hardware acceleration
89-
when running the tests in QEMU (especially useful if you want to run the tests under
90-
[WSL](https://docs.microsoft.com/en-us/windows/wsl) on Windows.
91-
9297
The `uefi-test-runner` directory contains a sample UEFI app which exercises
9398
most of the library's functionality.
9499

95-
Check out the testing project's [`README.md`](uefi-test-runner/README.md) for instructions on how to run the tests.
100+
Check out the testing project's [`README.md`](uefi-test-runner/README.md) for
101+
prerequisites for running the tests.
96102

97103
## Building UEFI programs
98104

0 commit comments

Comments
 (0)