|
@@ -5,6 +5,7 @@ use std::{
|
|
fs,
|
|
fs,
|
|
path::{Path, PathBuf},
|
|
path::{Path, PathBuf},
|
|
process::Command,
|
|
process::Command,
|
|
|
|
+ sync::LazyLock,
|
|
};
|
|
};
|
|
|
|
|
|
use anyhow::Context;
|
|
use anyhow::Context;
|
|
@@ -14,6 +15,18 @@ use crate::{
|
|
BOOTFS, DEBUG_DIR, H2O_BOOT, H2O_KERNEL, H2O_SYSCALL, H2O_TINIT, OC_BIN, OC_DRV, OC_LIB,
|
|
BOOTFS, DEBUG_DIR, H2O_BOOT, H2O_KERNEL, H2O_SYSCALL, H2O_TINIT, OC_BIN, OC_DRV, OC_LIB,
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+static CARGO: LazyLock<OsString> =
|
|
|
|
+ LazyLock::new(|| env::var_os("CARGO").unwrap_or_else(|| "cargo".into()));
|
|
|
|
+
|
|
|
|
+static LLVM: LazyLock<OsString> =
|
|
|
|
+ LazyLock::new(|| env::var_os("LLVM_PATH").unwrap_or_else(|| "/usr/lib/llvm-14".into()));
|
|
|
|
+
|
|
|
|
+static LLVM_OBJCOPY: LazyLock<PathBuf> =
|
|
|
|
+ LazyLock::new(|| Path::new(&*LLVM).join("bin/llvm-objcopy"));
|
|
|
|
+static LLVM_OBJDUMP: LazyLock<PathBuf> =
|
|
|
|
+ LazyLock::new(|| Path::new(&*LLVM).join("bin/llvm-objdump"));
|
|
|
|
+static LLVM_IFS: LazyLock<PathBuf> = LazyLock::new(|| Path::new(&*LLVM).join("bin/llvm-ifs"));
|
|
|
|
+
|
|
#[derive(Debug, StructOpt)]
|
|
#[derive(Debug, StructOpt)]
|
|
pub enum Type {
|
|
pub enum Type {
|
|
Img,
|
|
Img,
|
|
@@ -37,7 +50,6 @@ impl Dist {
|
|
}
|
|
}
|
|
|
|
|
|
pub fn build(self) -> Result<(), anyhow::Error> {
|
|
pub fn build(self) -> Result<(), anyhow::Error> {
|
|
- let cargo = env::var("CARGO").unwrap_or_else(|_| "cargo".to_string());
|
|
|
|
let src_root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
|
|
let src_root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
|
|
let target_root = env::var("CARGO_TARGET_DIR")
|
|
let target_root = env::var("CARGO_TARGET_DIR")
|
|
.unwrap_or_else(|_| src_root.join("target").to_string_lossy().to_string());
|
|
.unwrap_or_else(|_| src_root.join("target").to_string_lossy().to_string());
|
|
@@ -56,7 +68,6 @@ impl Dist {
|
|
|
|
|
|
// Build h2o_boot
|
|
// Build h2o_boot
|
|
self.build_impl(
|
|
self.build_impl(
|
|
- &cargo,
|
|
|
|
"h2o_boot.efi",
|
|
"h2o_boot.efi",
|
|
"BootX64.efi",
|
|
"BootX64.efi",
|
|
src_root.join(H2O_BOOT),
|
|
src_root.join(H2O_BOOT),
|
|
@@ -66,12 +77,11 @@ impl Dist {
|
|
.context("failed to build h2o_boot")?;
|
|
.context("failed to build h2o_boot")?;
|
|
|
|
|
|
// Build the VDSO
|
|
// Build the VDSO
|
|
- self.build_vdso(src_root, &cargo, &target_root)
|
|
|
|
|
|
+ self.build_vdso(src_root, &target_root)
|
|
.context("failed to build VDSO")?;
|
|
.context("failed to build VDSO")?;
|
|
|
|
|
|
// Build h2o_kernel
|
|
// Build h2o_kernel
|
|
self.build_impl(
|
|
self.build_impl(
|
|
- &cargo,
|
|
|
|
"h2o",
|
|
"h2o",
|
|
"KERNEL",
|
|
"KERNEL",
|
|
src_root.join(H2O_KERNEL),
|
|
src_root.join(H2O_KERNEL),
|
|
@@ -82,7 +92,6 @@ impl Dist {
|
|
|
|
|
|
// Build h2o_tinit
|
|
// Build h2o_tinit
|
|
self.build_impl(
|
|
self.build_impl(
|
|
- &cargo,
|
|
|
|
"tinit",
|
|
"tinit",
|
|
"TINIT",
|
|
"TINIT",
|
|
src_root.join(H2O_TINIT),
|
|
src_root.join(H2O_TINIT),
|
|
@@ -91,9 +100,9 @@ impl Dist {
|
|
)
|
|
)
|
|
.context("failed to build h2o_tinit")?;
|
|
.context("failed to build h2o_tinit")?;
|
|
|
|
|
|
- self.build_lib(&cargo, src_root, &target_root)
|
|
|
|
|
|
+ self.build_lib(src_root, &target_root)
|
|
.context("failed to build libraries")?;
|
|
.context("failed to build libraries")?;
|
|
- self.build_bin(&cargo, src_root, &target_root)
|
|
|
|
|
|
+ self.build_bin(src_root, &target_root)
|
|
.context("failed to build binaries or drivers")?;
|
|
.context("failed to build binaries or drivers")?;
|
|
|
|
|
|
crate::gen::gen_bootfs(Path::new(BOOTFS).join("../BOOT.fs"))
|
|
crate::gen::gen_bootfs(Path::new(BOOTFS).join("../BOOT.fs"))
|
|
@@ -113,19 +122,14 @@ impl Dist {
|
|
Ok(())
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
|
|
- fn build_vdso(
|
|
|
|
- &self,
|
|
|
|
- src_root: &Path,
|
|
|
|
- cargo: &String,
|
|
|
|
- target_root: &String,
|
|
|
|
- ) -> Result<(), anyhow::Error> {
|
|
|
|
|
|
+ fn build_vdso(&self, src_root: &Path, target_root: &String) -> Result<(), anyhow::Error> {
|
|
let target_triple = src_root.join(".cargo/x86_64-pc-oceanic.json");
|
|
let target_triple = src_root.join(".cargo/x86_64-pc-oceanic.json");
|
|
let cd = src_root.join(H2O_SYSCALL);
|
|
let cd = src_root.join(H2O_SYSCALL);
|
|
let ldscript = cd.join("syscall.ld");
|
|
let ldscript = cd.join("syscall.ld");
|
|
|
|
|
|
println!("Building VDSO");
|
|
println!("Building VDSO");
|
|
|
|
|
|
- let mut cmd = Command::new(cargo);
|
|
|
|
|
|
+ let mut cmd = Command::new(&*CARGO);
|
|
|
|
|
|
let cmd = cmd.current_dir(&cd).arg("rustc").args([
|
|
let cmd = cmd.current_dir(&cd).arg("rustc").args([
|
|
"--crate-type=cdylib",
|
|
"--crate-type=cdylib",
|
|
@@ -154,7 +158,7 @@ impl Dist {
|
|
|
|
|
|
fs::copy(bin_dir.join("libsv_call.so"), &path)?;
|
|
fs::copy(bin_dir.join("libsv_call.so"), &path)?;
|
|
|
|
|
|
- Command::new("llvm-ifs")
|
|
|
|
|
|
+ Command::new(&*LLVM_IFS)
|
|
.arg("--input-format=ELF")
|
|
.arg("--input-format=ELF")
|
|
.arg(format!(
|
|
.arg(format!(
|
|
"--output-elf={}/sysroot/usr/lib/libh2o.so",
|
|
"--output-elf={}/sysroot/usr/lib/libh2o.so",
|
|
@@ -164,7 +168,7 @@ impl Dist {
|
|
.status()?
|
|
.status()?
|
|
.exit_ok()?;
|
|
.exit_ok()?;
|
|
|
|
|
|
- let out = Command::new("llvm-objdump")
|
|
|
|
|
|
+ let out = Command::new(&*LLVM_OBJDUMP)
|
|
.arg("--syms")
|
|
.arg("--syms")
|
|
.arg(&path)
|
|
.arg(&path)
|
|
.output()?
|
|
.output()?
|
|
@@ -187,18 +191,12 @@ impl Dist {
|
|
Ok(())
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
|
|
- fn build_lib(
|
|
|
|
- &self,
|
|
|
|
- cargo: &str,
|
|
|
|
- src_root: impl AsRef<Path>,
|
|
|
|
- target_root: &str,
|
|
|
|
- ) -> anyhow::Result<()> {
|
|
|
|
|
|
+ fn build_lib(&self, src_root: impl AsRef<Path>, target_root: &str) -> anyhow::Result<()> {
|
|
let src_root = src_root.as_ref().join(OC_LIB);
|
|
let src_root = src_root.as_ref().join(OC_LIB);
|
|
let bin_dir = Path::new(target_root).join("x86_64-pc-oceanic");
|
|
let bin_dir = Path::new(target_root).join("x86_64-pc-oceanic");
|
|
let dst_root = Path::new(target_root).join("bootfs/lib");
|
|
let dst_root = Path::new(target_root).join("bootfs/lib");
|
|
|
|
|
|
self.build_impl(
|
|
self.build_impl(
|
|
- cargo,
|
|
|
|
"libldso.so",
|
|
"libldso.so",
|
|
"ld-oceanic.so",
|
|
"ld-oceanic.so",
|
|
src_root.join("libc/ldso"),
|
|
src_root.join("libc/ldso"),
|
|
@@ -206,7 +204,7 @@ impl Dist {
|
|
&dst_root,
|
|
&dst_root,
|
|
)?;
|
|
)?;
|
|
|
|
|
|
- Command::new("llvm-ifs")
|
|
|
|
|
|
+ Command::new(&*LLVM_IFS)
|
|
.arg("--input-format=ELF")
|
|
.arg("--input-format=ELF")
|
|
.arg(format!(
|
|
.arg(format!(
|
|
"--output-elf={}",
|
|
"--output-elf={}",
|
|
@@ -219,7 +217,6 @@ impl Dist {
|
|
.exit_ok()?;
|
|
.exit_ok()?;
|
|
|
|
|
|
self.build_impl(
|
|
self.build_impl(
|
|
- cargo,
|
|
|
|
"libco2.so",
|
|
"libco2.so",
|
|
"libco2.so",
|
|
"libco2.so",
|
|
src_root.join("libc"),
|
|
src_root.join("libc"),
|
|
@@ -230,12 +227,7 @@ impl Dist {
|
|
Ok(())
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
|
|
- fn build_bin(
|
|
|
|
- &self,
|
|
|
|
- cargo: &str,
|
|
|
|
- src_root: impl AsRef<Path>,
|
|
|
|
- target_root: &str,
|
|
|
|
- ) -> anyhow::Result<()> {
|
|
|
|
|
|
+ fn build_bin(&self, src_root: impl AsRef<Path>, target_root: &str) -> anyhow::Result<()> {
|
|
let bin_dir = Path::new(target_root).join("x86_64-pc-oceanic");
|
|
let bin_dir = Path::new(target_root).join("x86_64-pc-oceanic");
|
|
let dep_root = Path::new(target_root).join("bootfs/lib");
|
|
let dep_root = Path::new(target_root).join("bootfs/lib");
|
|
|
|
|
|
@@ -259,7 +251,7 @@ impl Dist {
|
|
} else {
|
|
} else {
|
|
name
|
|
name
|
|
};
|
|
};
|
|
- self.build_impl(cargo, &dst_name, &dst_name, ent.path(), &bin_dir, &dst_root)?;
|
|
|
|
|
|
+ self.build_impl(&dst_name, &dst_name, ent.path(), &bin_dir, &dst_root)?;
|
|
for dep in fs::read_dir(bin_dir.join(self.profile()).join("deps"))?.flatten() {
|
|
for dep in fs::read_dir(bin_dir.join(self.profile()).join("deps"))?.flatten() {
|
|
let name = dep.file_name();
|
|
let name = dep.file_name();
|
|
match name.to_str() {
|
|
match name.to_str() {
|
|
@@ -293,7 +285,6 @@ impl Dist {
|
|
|
|
|
|
fn build_impl(
|
|
fn build_impl(
|
|
&self,
|
|
&self,
|
|
- cargo: &str,
|
|
|
|
bin_name: impl AsRef<Path>,
|
|
bin_name: impl AsRef<Path>,
|
|
dst_name: impl AsRef<Path>,
|
|
dst_name: impl AsRef<Path>,
|
|
src_dir: impl AsRef<Path>,
|
|
src_dir: impl AsRef<Path>,
|
|
@@ -302,7 +293,7 @@ impl Dist {
|
|
) -> anyhow::Result<()> {
|
|
) -> anyhow::Result<()> {
|
|
println!("Building {:?}", dst_name.as_ref());
|
|
println!("Building {:?}", dst_name.as_ref());
|
|
|
|
|
|
- let mut cmd = Command::new(cargo);
|
|
|
|
|
|
+ let mut cmd = Command::new(&*CARGO);
|
|
let cmd = cmd.current_dir(src_dir).arg("build");
|
|
let cmd = cmd.current_dir(src_dir).arg("build");
|
|
if self.release {
|
|
if self.release {
|
|
cmd.arg("--release");
|
|
cmd.arg("--release");
|
|
@@ -324,12 +315,12 @@ impl Dist {
|
|
{
|
|
{
|
|
let mut sym_name = OsString::from(target_name.as_ref().as_os_str());
|
|
let mut sym_name = OsString::from(target_name.as_ref().as_os_str());
|
|
sym_name.push(".sym");
|
|
sym_name.push(".sym");
|
|
- Command::new("llvm-objcopy")
|
|
|
|
|
|
+ Command::new(&*LLVM_OBJCOPY)
|
|
.arg("--only-keep-debug")
|
|
.arg("--only-keep-debug")
|
|
.arg(&target_path)
|
|
.arg(&target_path)
|
|
.arg(dbg_dir.as_ref().join(sym_name))
|
|
.arg(dbg_dir.as_ref().join(sym_name))
|
|
.status()?;
|
|
.status()?;
|
|
- Command::new("llvm-objcopy")
|
|
|
|
|
|
+ Command::new(&*LLVM_OBJCOPY)
|
|
.arg("--strip-debug")
|
|
.arg("--strip-debug")
|
|
.arg(&target_path)
|
|
.arg(&target_path)
|
|
.status()?;
|
|
.status()?;
|
|
@@ -351,7 +342,7 @@ impl Dist {
|
|
txt_name.push(".txt");
|
|
txt_name.push(".txt");
|
|
fs::write(
|
|
fs::write(
|
|
dbg_dir.as_ref().join(txt_name),
|
|
dbg_dir.as_ref().join(txt_name),
|
|
- Command::new("llvm-objdump")
|
|
|
|
|
|
+ Command::new(&*LLVM_OBJDUMP)
|
|
.arg("-x")
|
|
.arg("-x")
|
|
.arg(&target_path)
|
|
.arg(&target_path)
|
|
.output()?
|
|
.output()?
|