From 8d10768c196f1803fc93efe6295cbd670181e8d3 Mon Sep 17 00:00:00 2001 From: Wildan Mubarok Date: Sun, 13 Jul 2025 12:47:11 +0000 Subject: [PATCH] Implement shallow clone and migrate rust recipe --- recipes/dev/rust/config.toml | 5 ++++- recipes/dev/rust/recipe.sh | 30 --------------------------- recipes/dev/rust/recipe.toml | 38 ++++++++++++++++++++++++++++++++++ src/bin/cook.rs | 40 +++++++++++++++++++++--------------- src/recipe.rs | 4 ++++ 5 files changed, 70 insertions(+), 47 deletions(-) delete mode 100644 recipes/dev/rust/recipe.sh create mode 100644 recipes/dev/rust/recipe.toml diff --git a/recipes/dev/rust/config.toml b/recipes/dev/rust/config.toml index 0a05f38c2..d2760f2e7 100644 --- a/recipes/dev/rust/config.toml +++ b/recipes/dev/rust/config.toml @@ -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"] diff --git a/recipes/dev/rust/recipe.sh b/recipes/dev/rust/recipe.sh deleted file mode 100644 index 71cbe2500..000000000 --- a/recipes/dev/rust/recipe.sh +++ /dev/null @@ -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 -} diff --git a/recipes/dev/rust/recipe.toml b/recipes/dev/rust/recipe.toml new file mode 100644 index 000000000..e71a4c6e6 --- /dev/null +++ b/recipes/dev/rust/recipe.toml @@ -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)" +# """ diff --git a/src/bin/cook.rs b/src/bin/cook.rs index cb13d2f05..84bb99e5d 100644 --- a/src/bin/cook.rs +++ b/src/bin/cook.rs @@ -226,6 +226,7 @@ fn fetch_offline(recipe_dir: &Path, source: &Option) -> Result) -> Result { //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) -> Result) -> Result, + /// 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, /// A list of patch files to apply to the source #[serde(default)] patches: Vec, @@ -231,6 +234,7 @@ mod tests { rev: Some("06344744d3d55a5ac9a62a6059cb363d40699bbc".to_string()), patches: Vec::new(), script: None, + shallow_clone: None, }), build: BuildRecipe { kind: BuildKind::Cargo {