rust-osdev / rust-osdev/bootloader

Custom target files

Open
#225 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.7k
Forks
240
PR merge metrics
No merged PRs in 30d

Description

Hi, I have started working on trying to implement a way to feed the builder a path to a target JSON file..
This went about as well as I wanted it to, until I ran into this :

     Running `/home/infrandomness/CLionProjects/Arc/target/debug/xtask image /home/infrandomness/CLionProjects/Arc/target/test`
target : /home/infrandomness/CLionProjects/Arc/xtask/../targets/x86_64-arc-uefi.json
error: failed to run custom build command for `bootloader v0.10.12 (/home/infrandomness/CLionProjects/bootloader)`

Caused by:
  process didn't exit successfully: `/home/infrandomness/CLionProjects/bootloader/../kernel/target/release/build/bootloader-84b80c089ed2fd1a/build-script-build` (exit status: 101)
  --- stderr
  thread 'main' panicked at 'The UEFI bootloader must be compiled for the `x86_64-unknown-uefi` target.', build.rs:41:13
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'assertion failed: cmd.status()?.success()', src/bin/builder.rs:111:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'Build failed', xtask/src/main.rs:67:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Here are the changes I brought to the builder binary :

Index: src/bin/builder.rs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/bin/builder.rs b/src/bin/builder.rs
--- a/src/bin/builder.rs	(revision 66637c11f5d459cfb4aa5d4f9538e70f012aa442)
+++ b/src/bin/builder.rs	(date 1645915730834)
@@ -1,14 +1,7 @@
 use anyhow::{anyhow, bail, Context};
 use argh::FromArgs;
 use bootloader::disk_image::create_disk_image;
-use std::{
-    convert::TryFrom,
-    fs::{self, File},
-    io::{self, Seek},
-    path::{Path, PathBuf},
-    process::Command,
-    str::FromStr,
-};
+use std::{convert::TryFrom, env, fs::{self, File}, io::{self, Seek}, path::{Path, PathBuf}, process::Command, str::FromStr};
 
 type ExitCode = i32;
 
@@ -46,6 +39,10 @@
     /// place the output binaries at the given path
     #[argh(option)]
     out_dir: Option<PathBuf>,
+
+    /// json target to build bootloader for
+    #[argh(option)]
+    target: Option<String>,
 }
 
 #[derive(Debug, Eq, PartialEq, Copy, Clone)]
@@ -96,7 +93,8 @@
         let mut cmd = Command::new(env!("CARGO"));
         cmd.arg(build_or_run).arg("--bin").arg("uefi");
         cmd.arg("--release");
-        cmd.arg("--target").arg("x86_64-unknown-uefi");
+        cmd.arg("--target")
+            .arg(&args.target.clone().unwrap_or(String::from("x86_64-unknown-uefi")));
         cmd.arg("--features")
             .arg(args.features.join(" ") + " uefi_bin");
         cmd.arg("-Zbuild-std=core");

I was wondering, if I were to dig more into the problem to implement this feature, would this work at all if the chose target is x86_64 UEFI or aarch64 UEFI ?
I don't know a whole lot about UEFI so I am assuming that the code from an x86_64 UEFI bootloader and an ARM64 UEFI bootloader is pretty much the same; Maybe I'm wrong.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/bin/builder.rs and the bootloader build.rs referenced in the failure, then reproduce the xtask image command with a custom target path. Determine the supported UEFI target behavior and define completion as the builder accepting the target JSON and successfully building the requested UEFI bootloader.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system, operating-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.