Implement shallow clone and migrate rust recipe

This commit is contained in:
Wildan Mubarok 2025-07-13 12:47:11 +00:00 committed by Jeremy Soller
parent c9f1240cf8
commit 8d10768c19
5 changed files with 70 additions and 47 deletions

View File

@ -1,6 +1,9 @@
[llvm]
download-ci-llvm = false
static-libstdcpp = false
static-libstdcpp = false
# TODO: This currently must need to be set manually.
# If you like to build llvm with sccache, uncomment:
# ccache = "sccache"
[build]
host = ["x86_64-unknown-redox"]

View File

@ -1,30 +0,0 @@
GIT=https://gitlab.redox-os.org/redox-os/rust.git
BRANCH=redox-2024-05-11
BUILD_DEPENDS=(llvm18 zlib)
DEPENDS="gcc13 cargo"
PREPARE_COPY=0
function recipe_version {
printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
skip=1
}
function recipe_build {
unset AR AS CC CXX LD NM OBJCOPY OBJDUMP RANLIB READELF STRIP
export MAGIC_EXTRA_RUSTFLAGS="-C link-args=-lz"
python3 "${COOKBOOK_SOURCE}/x.py" install --config "${COOKBOOK_RECIPE}/config.toml" --jobs $(nproc) --incremental
skip=1
}
function recipe_clean {
"$REDOX_MAKE" clean
skip=1
}
function recipe_stage {
rsync -av --delete "install/" "$1/"
# Cannot use STRIP because it is unset in recipe_build
#TODO: rustdoc
"${HOST}-strip" -v "$1/bin/rustc"
skip=1
}

View File

@ -0,0 +1,38 @@
[source]
git = "https://gitlab.redox-os.org/redox-os/rust.git"
branch = "redox-2024-05-11"
# due to heavy git operation, this will only clone once and will not refetch
# if you want to refetch or changing the branch, please do ucr.rust
shallow_clone = true
[build]
template = "custom"
dependencies = [
"llvm18",
"zlib"
]
script = """
DYNAMIC_INIT
HOST_STRIP=$STRIP
# Linker flags for stage2 compiler (host -> target)
export MAGIC_EXTRA_RUSTFLAGS="${LDFLAGS} -C link-args=-lz"
# Don't poison the stage1 compiler (host -> host)
unset AR AS CC CXX LD LDFLAGS NM OBJCOPY OBJDUMP RANLIB READELF STRIP
python3 "${COOKBOOK_SOURCE}/x.py" install \
--config "${COOKBOOK_RECIPE}/config.toml" \
--jobs $(nproc)
rsync -av --delete "${COOKBOOK_BUILD}"/install/* "${COOKBOOK_STAGE}/"
"${HOST_STRIP}" -v "${COOKBOOK_STAGE}/bin/rustc"
# TODO: rustdoc
"""
[package]
dependencies = [
"gcc13",
"cargo"
]
# TODO: Not implemented
# version_script = """
# printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
# """

View File

@ -226,6 +226,7 @@ fn fetch_offline(recipe_dir: &Path, source: &Option<SourceRecipe>) -> Result<Pat
rev: _,
patches: _,
script: _,
shallow_clone: _,
})
| Some(SourceRecipe::Tar {
tar: _,
@ -289,8 +290,10 @@ fn fetch(recipe_dir: &Path, source: &Option<SourceRecipe>) -> Result<PathBuf, St
rev,
patches,
script,
shallow_clone,
}) => {
//TODO: use libgit?
let shallow_clone = *shallow_clone == Some(true);
if !source_dir.is_dir() {
// Create source.tmp
let source_dir_tmp = recipe_dir.join("source.tmp");
@ -302,12 +305,15 @@ fn fetch(recipe_dir: &Path, source: &Option<SourceRecipe>) -> Result<PathBuf, St
if let Some(branch) = branch {
command.arg("--branch").arg(branch);
}
if shallow_clone {
command.arg("--depth").arg("1").arg("--shallow-submodules");
}
command.arg(&source_dir_tmp);
run_command(command)?;
// Move source.tmp to source atomically
rename(&source_dir_tmp, &source_dir)?;
} else {
} else if !shallow_clone {
// Don't let this code reset the origin for the cookbook repo
let source_git_dir = source_dir.join(".git");
if !source_git_dir.is_dir() {
@ -343,7 +349,7 @@ fn fetch(recipe_dir: &Path, source: &Option<SourceRecipe>) -> Result<PathBuf, St
command.arg("-C").arg(&source_dir);
command.arg("checkout").arg(rev);
run_command(command)?;
} else {
} else if !shallow_clone {
//TODO: complicated stuff to check and reset branch to origin
let mut command = Command::new("bash");
command.arg("-c").arg(
@ -374,21 +380,23 @@ fi"#,
run_command(command)?;
}
// Sync submodules URL
let mut command = Command::new("git");
command.arg("-C").arg(&source_dir);
command.arg("submodule").arg("sync").arg("--recursive");
run_command(command)?;
if !shallow_clone {
// Sync submodules URL
let mut command = Command::new("git");
command.arg("-C").arg(&source_dir);
command.arg("submodule").arg("sync").arg("--recursive");
run_command(command)?;
// Update submodules
let mut command = Command::new("git");
command.arg("-C").arg(&source_dir);
command
.arg("submodule")
.arg("update")
.arg("--init")
.arg("--recursive");
run_command(command)?;
// Update submodules
let mut command = Command::new("git");
command.arg("-C").arg(&source_dir);
command
.arg("submodule")
.arg("update")
.arg("--init")
.arg("--recursive");
run_command(command)?;
}
// Apply patches
for patch_name in patches {

View File

@ -35,6 +35,9 @@ pub enum SourceRecipe {
/// The optional revision of the git repository to use for builds. Please specify for
/// reproducible builds
rev: Option<String>,
/// The optional config to run as shallow fetch. Only use this for heavy git like "rust"
/// This will disable recipe autofetching because of its cost on git server
shallow_clone: Option<bool>,
/// A list of patch files to apply to the source
#[serde(default)]
patches: Vec<String>,
@ -231,6 +234,7 @@ mod tests {
rev: Some("06344744d3d55a5ac9a62a6059cb363d40699bbc".to_string()),
patches: Vec::new(),
script: None,
shallow_clone: None,
}),
build: BuildRecipe {
kind: BuildKind::Cargo {