1
0
Fork 0
forked from koniifer/ableos

Repbuild now can build kernel on non-POSIX systems and run on non-Linux systems.

This commit is contained in:
Erin 2023-01-07 22:11:21 +01:00 committed by ondra05
parent b802732acf
commit 7d21956b0a
3 changed files with 20 additions and 54 deletions

19
Cargo.lock generated
View file

@ -388,18 +388,6 @@ version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "nix"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46a58d1d356c6597d08cde02c2f09d785b09e28711837b1ed667dc652c08a694"
dependencies = [
"bitflags",
"cfg-if",
"libc",
"static_assertions",
]
[[package]]
name = "num-integer"
version = "0.1.45"
@ -492,7 +480,6 @@ dependencies = [
"error-stack",
"fatfs",
"log",
"nix",
]
[[package]]
@ -580,12 +567,6 @@ dependencies = [
"lock_api",
]
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "supports-color"
version = "1.3.1"

View file

@ -8,8 +8,3 @@ env_logger = "0.10"
error-stack = "0.2"
fatfs = "0.3"
log = "0.4"
[dependencies.nix]
version = "0.26"
default-features = false
features = ["fs"]

View file

@ -24,8 +24,7 @@ fn main() -> Result<(), Error> {
run()
}
Some("help" | "h") => {
println!(
concat!(
println!(concat!(
"AbleOS RepBuild\n",
"Subcommands:\n",
" build (b): Build a bootable disk image\n",
@ -33,8 +32,7 @@ fn main() -> Result<(), Error> {
" run (r): Build and run AbleOS in QEMU\n\n",
"Options for build and run:\n",
" -r: build in release mode",
),
);
),);
Ok(())
}
_ => Err(report!(Error::InvalidSubCom)),
@ -62,19 +60,7 @@ fn get_fs() -> Result<FileSystem<impl ReadWriteSeek>, io::Error> {
.create(true)
.open(path)?;
{
#[cfg(unix)]
nix::fcntl::fallocate(
img.as_raw_fd(),
FallocateFlags::from_bits(0).unwrap(),
0,
1024 * 1024 * 64,
)
.map_err(|e| std::io::Error::from_raw_os_error(e as i32))?;
#[cfg(not(any(unix)))]
compile_error!("unsupported platform");
}
img.set_len(1024 * 1024 * 64)?;
fatfs::format_volume(&mut img, FormatVolumeOptions::new())?;
@ -122,19 +108,23 @@ fn build(release: bool) -> Result<(), Error> {
}
fn run() -> Result<(), Error> {
let mut com = Command::new("qemu-system-x86_64");
#[rustfmt::skip]
let args = [
com.args([
"-bios", "/usr/share/OVMF/OVMF_CODE.fd",
"-enable-kvm",
"-cpu", "host",
"-drive", "file=target/disk.img,format=raw",
"-m", "4G",
"-serial", "stdio",
"-smp", "cores=2",
];
]);
match Command::new("qemu-system-x86_64")
.args(args)
#[cfg(target_os = "linux")]
{
com.args(["-enable-kvm", "-cpu", "host"]);
}
match com
.status()
.into_report()
.change_context(Error::ProcessSpawn)?