libc: clone openlibm when needed

This commit is contained in:
2024-11-13 16:31:26 +02:00
parent 9e187a4e94
commit 8160f2ab1a
4 changed files with 49 additions and 22 deletions
+2
View File
@@ -1,3 +1,5 @@
/llvm-project
/prefix
/sysroot
/libs
/programs
+24 -3
View File
@@ -4,10 +4,16 @@ use std::{
process::Command,
};
use crate::{env::BuildEnv, error::Error, util};
use crate::{
env::BuildEnv,
error::Error,
util::{self, git_clone},
};
use super::cargo::CargoBuilder;
pub const OPENLIBM_URL: &str = "https://git.alnyan.me/yggdrasil/openlibm.git";
pub struct Llvm {
root: PathBuf,
}
@@ -138,9 +144,13 @@ fn build_openlibm(env: &BuildEnv, llvm: &Llvm) -> Result<Openlibm, Error> {
command
}
log::info!("Building openlibm");
let libm_path = env
.workspace_root
.join(format!("toolchain-c/libs/openlibm-{}", env.arch.name()));
let libm_path = env.workspace_root.join("toolchain-c/libs/openlibm");
git_clone(&libm_path, OPENLIBM_URL, "alnyan/yggdrasil")?;
log::info!("Building openlibm");
let mut command = make(env, llvm, &libm_path);
if !command.status()?.success() {
@@ -164,6 +174,17 @@ fn install_openlibm(env: &BuildEnv, libm: &Openlibm) -> Result<(), Error> {
}
fn build_llvm(env: &BuildEnv) -> Result<Llvm, Error> {
// Configuration:
/*
cmake -DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt" -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_SYSTEM_NAME=yggdrasil -DLLVM_USE_LINKER=lld -DBUILD_SHARED_LIBS=false -DLLVM_BUILD_TOOLS=false -DLLVM_CCACHE_BUILD=true -DCMAKE_BUILD_TYPE=Release -DCMAKE_HOST_TRIPLE=x86_64-unknown-linux-gnu -DUNIX=1 -GNinja -DCMAKE_INSTALL_PREFIX=/home/alnyan/build/ygg/toolchain-c/prefix/host ../llvm
Build:
cmake --build . -j 16
Install:
cmake --build . -t install
*/
// TODO actually build and install LLVM
Ok(Llvm {
root: env.workspace_root.join("toolchain-c/prefix/host"),
+6 -19
View File
@@ -5,7 +5,11 @@ use std::{
process::Command,
};
use crate::{env::BuildEnv, error::Error, util};
use crate::{
env::BuildEnv,
error::Error,
util::{self, git_clone},
};
const TOOLCHAIN_URL: &str = "https://git.alnyan.me/yggdrasil/yggdrasil-rust";
@@ -139,24 +143,7 @@ fn install_shims<P: AsRef<Path>>(env: &BuildEnv, toolchain_root: P) -> Result<()
pub fn fetch(env: &BuildEnv, branch: &str) -> Result<(), Error> {
let path = env.workspace_root.join("toolchain");
match git2::Repository::open(&path) {
Ok(_) => {}
Err(err) if err.code() == git2::ErrorCode::NotFound => {
log::info!(
"Fetching toolchain: src={}, branch={}",
TOOLCHAIN_URL,
branch
);
git2::build::RepoBuilder::new()
.branch(branch)
.clone(TOOLCHAIN_URL, &path)?;
}
Err(err) => return Err(err.into()),
}
Ok(())
git_clone(path, TOOLCHAIN_URL, branch)
}
pub fn build(env: &BuildEnv) -> Result<(), Error> {
+17
View File
@@ -58,3 +58,20 @@ pub fn copy_dir_recursive<S: AsRef<Path>, D: AsRef<Path>>(src: S, dst: D) -> Res
Ok(())
}
pub fn git_clone(dst: impl AsRef<Path>, url: &str, branch: &str) -> Result<(), Error> {
let path = dst.as_ref();
match git2::Repository::open(path) {
Ok(_) => {}
Err(err) if err.code() == git2::ErrorCode::NotFound => {
log::info!("Fetching: src={}, branch={}", url, branch);
git2::build::RepoBuilder::new()
.branch(branch)
.clone(url, &path)?;
}
Err(err) => return Err(err.into()),
}
Ok(())
}