File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,12 @@ json = "0.12.4"
32
32
fatfs = " 0.3.4"
33
33
gpt = " 3.0.0"
34
34
35
+ # [dependencies.bootloader-x86_64-uefi]
36
+ # version = "0.1.0"
37
+ # path = "uefi"
38
+ # artifact = ["bin"]
39
+ # target = "x86_64-unknown-uefi"
40
+
35
41
[build-dependencies ]
36
42
llvm-tools-build = { version = " 0.1" , optional = true , package = " llvm-tools" }
37
43
toml = { version = " 0.5.1" , optional = true }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments