Skip to content

Commit ee9bf20

Browse files
committed
Replace artifact dependency with build script
Artifact dependencies and `-Zbuild-std` don't work together yet.
1 parent 8fb5eff commit ee9bf20

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ json = "0.12.4"
3232
fatfs = "0.3.4"
3333
gpt = "3.0.0"
3434

35+
# [dependencies.bootloader-x86_64-uefi]
36+
# version = "0.1.0"
37+
# path = "uefi"
38+
# artifact = ["bin"]
39+
# target = "x86_64-unknown-uefi"
40+
3541
[build-dependencies]
3642
llvm-tools-build = { version = "0.1", optional = true, package = "llvm-tools" }
3743
toml = { version = "0.5.1", optional = true }

build.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use std::{
2+
path::{Path, PathBuf},
3+
process::Command,
4+
};
5+
6+
fn main() {
7+
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
8+
9+
let uefi_path = build_uefi_bootloader(&out_dir);
10+
11+
println!(
12+
"cargo:rustc-env=UEFI_BOOTLOADER_PATH={}",
13+
uefi_path.display()
14+
);
15+
}
16+
17+
fn build_uefi_bootloader(out_dir: &Path) -> PathBuf {
18+
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".into());
19+
let mut cmd = Command::new(cargo);
20+
cmd.arg("install").arg("bootloader-x86_64-uefi");
21+
// TODO: remove, only for testing, replace by `--version`
22+
cmd.arg("--path").arg("uefi");
23+
cmd.arg("--locked");
24+
cmd.arg("--target").arg("x86_64-unknown-uefi");
25+
cmd.arg("-Zbuild-std=core")
26+
.arg("-Zbuild-std-features=compiler-builtins-mem");
27+
cmd.arg("--root").arg(out_dir);
28+
cmd.env_remove("RUSTFLAGS");
29+
let status = cmd
30+
.status()
31+
.expect("failed to run cargo install for uefi bootloader");
32+
if status.success() {
33+
let path = out_dir.join("bin").join("bootloader-x86_64-uefi.efi");
34+
assert!(
35+
path.exists(),
36+
"uefi bootloader executable does not exist after building"
37+
);
38+
path
39+
} else {
40+
panic!("failed to build uefi bootloader");
41+
}
42+
}

0 commit comments

Comments
 (0)