Make cargo build script more useful

This commit is contained in:
Wildan M 2026-03-06 00:44:35 +07:00
parent cf717dc830
commit 2d899ca1a7
No known key found for this signature in database
GPG Key ID: 01AC53185C679C79
28 changed files with 140 additions and 117 deletions

View File

@ -69,7 +69,7 @@ cosmic-comp wayland-session
# For smallvil (easier to debug) # For smallvil (easier to debug)
#export WAYLAND_DISPLAY=wayland-1 #export WAYLAND_DISPLAY=wayland-1
#smallvil_smallvil & #smallvil &
#sleep 2 #sleep 2
#wayland-session #wayland-session
""" """

View File

@ -2,8 +2,7 @@
git = "https://gitlab.redox-os.org/redox-os/findutils.git" git = "https://gitlab.redox-os.org/redox-os/findutils.git"
[build] [build]
template = "custom" template = "cargo"
script = """ cargoflags = [
DYNAMIC_INIT "--bin find"
cookbook_cargo --bin find ]
"""

View File

@ -2,8 +2,11 @@
git = "https://gitlab.redox-os.org/redox-os/pkgar.git" git = "https://gitlab.redox-os.org/redox-os/pkgar.git"
[build] [build]
template = "custom" template = "cargo"
script = """ cargopackages = [
DYNAMIC_INIT "pkgar",
PACKAGE_PATH="pkgar" cookbook_cargo --features "cli" "pkgar-keys",
""" ]
cargoflags = [
"--features cli"
]

View File

@ -5,6 +5,6 @@ git = "https://gitlab.redox-os.org/redox-os/pkgutils.git"
template = "custom" template = "custom"
script = """ script = """
# Must be statically linked # Must be statically linked
PACKAGE_PATH=pkg-cli COOKBOOK_CARGO_PATH=pkg-cli
cookbook_cargo cookbook_cargo
""" """

View File

@ -2,7 +2,7 @@
git = "https://gitlab.redox-os.org/redox-os/orbclient.git" git = "https://gitlab.redox-os.org/redox-os/orbclient.git"
[build] [build]
template = "custom" template = "cargo"
script = """ cargoexamples = [
cookbook_cargo_examples simple "simple"
""" ]

View File

@ -3,4 +3,4 @@ git = "https://github.com/lukas-kirschner/procedural-wallpapers-rs.git"
[build] [build]
template = "cargo" template = "cargo"
package_path = "procedural_wallpapers" cargopath = "procedural_wallpapers"

View File

@ -3,8 +3,10 @@ same_as = "../orbutils"
[build] [build]
template = "cargo" template = "cargo"
package_path = "orbutils" cargopath = "orbutils"
cargoflags = "--bin background" cargoflags = [
"--bin background"
]
[package] [package]
dependencies = [ dependencies = [

View File

@ -5,5 +5,7 @@ branch = "main"
[build] [build]
template = "custom" template = "custom"
script = """ script = """
cookbook_cargo_packages editor DYNAMIC_INIT
COOKBOOK_CARGO_FLAGS=() # remove --locked
COOKBOOK_CARGO_PATH=examples/editor cookbook_cargo_build
""" """

View File

@ -10,7 +10,7 @@ template = "custom"
script = """ script = """
DYNAMIC_INIT DYNAMIC_INIT
export CFLAGS="$CFLAGS -D__redox__" export CFLAGS="$CFLAGS -D__redox__"
PACKAGE_PATH="helix-term" cookbook_cargo COOKBOOK_CARGO_PATH="helix-term" cookbook_cargo
mv "${COOKBOOK_STAGE}/usr/bin/hx" "${COOKBOOK_STAGE}/usr/bin/helix" mv "${COOKBOOK_STAGE}/usr/bin/hx" "${COOKBOOK_STAGE}/usr/bin/helix"
mkdir -p "${COOKBOOK_STAGE}/usr/lib/helix/runtime/grammars" mkdir -p "${COOKBOOK_STAGE}/usr/lib/helix/runtime/grammars"
mkdir -p "${COOKBOOK_STAGE}/usr/lib/helix/runtime/queries" mkdir -p "${COOKBOOK_STAGE}/usr/lib/helix/runtime/queries"

View File

@ -8,7 +8,7 @@ export CARGOFLAGS="--no-default-features --features chrono"
# --locked uses a reallyyyy old redox_syscall and libc which fails # --locked uses a reallyyyy old redox_syscall and libc which fails
${COOKBOOK_CARGO} install \ ${COOKBOOK_CARGO} install \
--path "${COOKBOOK_SOURCE}/${PACKAGE_PATH}" \ --path "${COOKBOOK_SOURCE}/${COOKBOOK_CARGO_PATH}" \
--root "${COOKBOOK_STAGE}/usr" \ --root "${COOKBOOK_STAGE}/usr" \
--no-track \ --no-track \
--no-default-features \ --no-default-features \

View File

@ -11,7 +11,7 @@ examples="main directions image raster"
for example in "${examples}" for example in "${examples}"
do do
"${COOKBOOK_CARGO}" build \ "${COOKBOOK_CARGO}" build \
--manifest-path "${COOKBOOK_SOURCE}/${PACKAGE_PATH}/Cargo.toml" \ --manifest-path "${COOKBOOK_SOURCE}/${COOKBOOK_CARGO_PATH}/Cargo.toml" \
--example "${example}" \ --example "${example}" \
--release \ --release \
--features "monospace-font" --features "monospace-font"

View File

@ -14,7 +14,7 @@ recipe="$(basename "${COOKBOOK_RECIPE}")"
for example in simulator for example in simulator
do do
"${COOKBOOK_CARGO}" build \ "${COOKBOOK_CARGO}" build \
--manifest-path "${COOKBOOK_SOURCE}/${PACKAGE_PATH}/Cargo.toml" \ --manifest-path "${COOKBOOK_SOURCE}/${COOKBOOK_CARGO_PATH}/Cargo.toml" \
--example "${example}" \ --example "${example}" \
--release \ --release \
--features=simulator --features=simulator

View File

@ -6,28 +6,17 @@ shallow_clone = true
template = "custom" template = "custom"
script = """ script = """
DYNAMIC_INIT DYNAMIC_INIT
recipe="$(basename "${COOKBOOK_RECIPE}")" COOKBOOK_CARGO_FLAGS=() # remove --locked
function build_from_dir { COOKBOOK_CARGO_PATH="examples/animations" cookbook_cargo_build
prog_name=$1 COOKBOOK_CARGO_PATH="examples/canvas_stress_test" bin_name="canvas-stress-test" cookbook_cargo_build
dir_name=$2 COOKBOOK_CARGO_PATH="examples/canvas_waves" bin_name="canvas-waves" cookbook_cargo_build
"${COOKBOOK_CARGO}" build \ COOKBOOK_CARGO_PATH="examples/colors_rgb" bin_name="color-rgb" cookbook_cargo_build
--manifest-path "${COOKBOOK_SOURCE}/examples/${dir_name}/Cargo.toml" \ COOKBOOK_CARGO_PATH="examples/demo" cookbook_cargo_build
${build_flags} COOKBOOK_CARGO_PATH="examples/demo2" cookbook_cargo_build
mkdir -pv "${COOKBOOK_STAGE}/usr/bin" COOKBOOK_CARGO_PATH="examples/minimal" cookbook_cargo_build
cp -v \ COOKBOOK_CARGO_PATH="examples/pong" cookbook_cargo_build
"target/${TARGET}/${build_type}/${prog_name}" \ COOKBOOK_CARGO_PATH="examples/text_area" cookbook_cargo_build
"${COOKBOOK_STAGE}/usr/bin/${recipe}_${prog_name}" COOKBOOK_CARGO_PATH="examples/user_input" bin_name="user-input" cookbook_cargo_build
} COOKBOOK_CARGO_PATH="examples/website" cookbook_cargo_build
build_from_dir animations animations COOKBOOK_CARGO_PATH="examples/world_map" bin_name="world-map" cookbook_cargo_build
build_from_dir canvas-stress-test canvas_stress_test
build_from_dir canvas-waves canvas_waves
build_from_dir color-rgb colors_rgb
build_from_dir demo demo
build_from_dir demo2 demo2
build_from_dir minimal minimal
build_from_dir pong pong
build_from_dir text_area text_area
build_from_dir user-input user_input
build_from_dir website website
build_from_dir world-map world_map
""" """

View File

@ -11,7 +11,7 @@ recipe="$(basename "${COOKBOOK_RECIPE}")"
for example in imgille for example in imgille
do do
"${COOKBOOK_CARGO}" build \ "${COOKBOOK_CARGO}" build \
--manifest-path "${COOKBOOK_SOURCE}/${PACKAGE_PATH}/Cargo.toml" \ --manifest-path "${COOKBOOK_SOURCE}/${COOKBOOK_CARGO_PATH}/Cargo.toml" \
--example "${example}" \ --example "${example}" \
--release \ --release \
--features=img --features=img

View File

@ -11,7 +11,7 @@ git = "https://github.com/dcampbell24/hnefatafl"
template = "custom" template = "custom"
script = """ script = """
"${COOKBOOK_CARGO}" build \ "${COOKBOOK_CARGO}" build \
--manifest-path "${COOKBOOK_SOURCE}/${PACKAGE_PATH}/Cargo.toml" \ --manifest-path "${COOKBOOK_SOURCE}/${COOKBOOK_CARGO_PATH}/Cargo.toml" \
--features client \ --features client \
--release \ --release \
--no-default-features --no-default-features

View File

@ -9,7 +9,7 @@ patches = [
template = "custom" template = "custom"
script = """ script = """
DYNAMIC_INIT DYNAMIC_INIT
PACKAGE_PATH=cli cookbook_cargo \ COOKBOOK_CARGO_PATH=cli cookbook_cargo \
--config 'patch.crates-io.rustix.git = "https://github.com/bytecodealliance/rustix"' \ --config 'patch.crates-io.rustix.git = "https://github.com/bytecodealliance/rustix"' \
--config 'patch.crates-io.rustix.rev = "8bf15a0"' --config 'patch.crates-io.rustix.rev = "8bf15a0"'
cookbook_cmake "${COOKBOOK_SOURCE}"/lib cookbook_cmake "${COOKBOOK_SOURCE}"/lib

View File

@ -4,4 +4,4 @@ git = "https://github.com/lemunozm/termchat"
shallow_clone = true shallow_clone = true
[build] [build]
template = "cargo" template = "cargo"
cargoflags = "--all-features" cargoflags = ["--all-features"]

View File

@ -4,7 +4,7 @@ git = "https://github.com/RainbowCookie32/rusty-psn"
shallow_clone = true shallow_clone = true
[build] [build]
template = "cargo" template = "cargo"
cargoflags = "--features cli" cargoflags = ["--features cli"]
dependencies = [ dependencies = [
"openssl3", "openssl3",
] ]

View File

@ -4,7 +4,7 @@ git = "https://github.com/Siriusmart/youtube-tui"
shallow_clone = true shallow_clone = true
[build] [build]
template = "cargo" template = "cargo"
cargoflags = "--no-default-features" cargoflags = ["--no-default-features"]
dependencies = [ dependencies = [
"openssl3", "openssl3",
] ]

View File

@ -18,5 +18,5 @@ DYNAMIC_INIT
cp -v \ cp -v \
"target/${TARGET}/${build_type}/libfile_explorer_plugin.dylib" \ "target/${TARGET}/${build_type}/libfile_explorer_plugin.dylib" \
"${COOKBOOK_SOURCE}"/lib/http-server/inline/file_explorer.plugin.httprs "${COOKBOOK_SOURCE}"/lib/http-server/inline/file_explorer.plugin.httprs
PACKAGE_PATH=crates/http-server cookbook_cargo --bin http-server COOKBOOK_CARGO_PATH=crates/http-server cookbook_cargo --bin http-server
""" """

View File

@ -1,24 +1,16 @@
#TODO not compiled or tested #TODO need to patch glutin
[source] [source]
git = "https://github.com/alacritty/alacritty" git = "https://github.com/alacritty/alacritty"
shallow_clone = true
[build] [build]
template = "custom" template = "cargo"
dependencies = [ dependencies = [
"freetype2", "freetype2",
"fontconfig", "fontconfig",
"libxcb", "libxcb",
] ]
script = """ cargopath = "alacritty"
DYNAMIC_INIT cargoflags = [
package=alacritty "--no-default-features",
"${COOKBOOK_CARGO}" build \ "--features x11",
--manifest-path "${COOKBOOK_SOURCE}/Cargo.toml" \ ]
--package "${package}" \
--release \
--no-default-features \
--features=x11
mkdir -pv "${COOKBOOK_STAGE}/usr/bin"
cp -v \
"target/${TARGET}/release/${package}" \
"${COOKBOOK_STAGE}/usr/bin/${package}"
"""

View File

@ -4,4 +4,4 @@
git = "https://codeberg.org/AeriaVelocity/sued" git = "https://codeberg.org/AeriaVelocity/sued"
[build] [build]
template = "cargo" template = "cargo"
cargoflags = "--features=repl,startup,history" cargoflags = ["--features=repl,startup,history"]

View File

@ -4,14 +4,12 @@ git = "https://github.com/jackpot51/smithay"
branch = "redox" branch = "redox"
[build] [build]
template = "custom" template = "cargo"
dependencies = [ dependencies = [
"libffi", "libffi",
"libwayland", "libwayland",
"libxkbcommon", "libxkbcommon",
] ]
script = """ cargopackages = [
DYNAMIC_INIT "smallvil"
export RUSTFLAGS="${RUSTFLAGS} -lffi" ]
cookbook_cargo_packages smallvil
"""

View File

@ -40,7 +40,7 @@ export CLANGFLAGS="-I $PREFIX_INCLUDE/c++/13.2.0 -I $PREFIX_INCLUDE/c++/13.2.0/$
unset CC_WRAPPER unset CC_WRAPPER
export CARGO_MAKEFLAGS="-j $COOKBOOK_MAKE_JOBS" CCACHE="sccache" export CARGO_MAKEFLAGS="-j $COOKBOOK_MAKE_JOBS" CCACHE="sccache"
PACKAGE_PATH="ports/servoshell" cookbook_cargo COOKBOOK_CARGO_PATH="ports/servoshell" cookbook_cargo
# resources packaging # resources packaging
mkdir -p ${COOKBOOK_STAGE}/usr/lib/servo/bin mkdir -p ${COOKBOOK_STAGE}/usr/lib/servo/bin

View File

@ -345,13 +345,38 @@ pub fn build(
//TODO: Add more configurability, convert scripts to Rust? //TODO: Add more configurability, convert scripts to Rust?
let script = match &recipe.build.kind { let script = match &recipe.build.kind {
BuildKind::Cargo { BuildKind::Cargo {
package_path, cargopath,
cargoflags, cargoflags,
cargopackages,
cargoexamples,
} => { } => {
format!( let mut script = format!(
"DYNAMIC_INIT\nPACKAGE_PATH={} cookbook_cargo {cargoflags}", "DYNAMIC_INIT\n{}\nCOOKBOOK_CARGO_PATH={} ",
package_path.as_deref().unwrap_or(".") flags_fn("COOKBOOK_CARGO_FLAGS", cargoflags),
) cargopath.as_deref().unwrap_or(".")
);
if cargopackages.len() == 0 && cargoexamples.len() == 0 {
script += "cookbook_cargo\n"
} else {
if cargopackages.len() > 0 {
script += "cookbook_cargo_packages";
for package in cargopackages {
script += " ";
script += package;
}
script += "\n";
}
if cargoexamples.len() > 0 {
script += "cookbook_cargo_examples";
for example in cargoexamples {
script += " ";
script += example;
}
script += "\n";
}
}
script
} }
BuildKind::Configure { configureflags } => format!( BuildKind::Configure { configureflags } => format!(
"DYNAMIC_INIT\n{}cookbook_configure", "DYNAMIC_INIT\n{}cookbook_configure",

View File

@ -396,12 +396,14 @@ pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result
}; };
if let BuildKind::Cargo { if let BuildKind::Cargo {
package_path, cargopath,
cargoflags: _, cargoflags: _,
cargopackages: _,
cargoexamples: _,
} = &recipe.recipe.build.kind } = &recipe.recipe.build.kind
{ {
// TODO: No need to fetch if !check_source and already fetched? // TODO: No need to fetch if !check_source and already fetched?
fetch_cargo(&source_dir, package_path.as_ref(), logger)?; fetch_cargo(&source_dir, cargopath.as_ref(), logger)?;
} }
fetch_apply_source_info(recipe, ident)?; fetch_apply_source_info(recipe, ident)?;
@ -481,12 +483,12 @@ pub(crate) fn fetch_extract_tar(
pub(crate) fn fetch_cargo( pub(crate) fn fetch_cargo(
source_dir: &PathBuf, source_dir: &PathBuf,
package_path: Option<&String>, cargopath: Option<&String>,
logger: &PtyOut, logger: &PtyOut,
) -> Result<(), String> { ) -> Result<(), String> {
let mut source_dir = source_dir.clone(); let mut source_dir = source_dir.clone();
if let Some(package_path) = package_path { if let Some(cargopath) = cargopath {
source_dir = source_dir.join(package_path); source_dir = source_dir.join(cargopath);
} }
let local_redoxer = Path::new("target/release/cookbook_redoxer"); let local_redoxer = Path::new("target/release/cookbook_redoxer");

View File

@ -124,11 +124,11 @@ fi
# to not strip symbols from the final package, add COOKBOOK_NOSTRIP=true to the recipe # to not strip symbols from the final package, add COOKBOOK_NOSTRIP=true to the recipe
# (or to your environment) before calling cookbook_cargo or cookbook_cargo_packages # (or to your environment) before calling cookbook_cargo or cookbook_cargo_packages
build_type=release build_type=release
install_flags= install_flags=--no-track
build_flags=--release build_flags=--release
if [ ! -z "${COOKBOOK_DEBUG}" ] if [ ! -z "${COOKBOOK_DEBUG}" ]
then then
install_flags=--debug install_flags+=" --debug"
build_flags= build_flags=
build_type=debug build_type=debug
export CPPFLAGS="${CPPFLAGS} -g" export CPPFLAGS="${CPPFLAGS} -g"
@ -142,16 +142,34 @@ fi
reexport_flags reexport_flags
# cargo template
COOKBOOK_CARGO="${COOKBOOK_REDOXER}" COOKBOOK_CARGO="${COOKBOOK_REDOXER}"
COOKBOOK_CARGO_FLAGS=(
--locked
)
# cargo template using cargo install
function cookbook_cargo { function cookbook_cargo {
"${COOKBOOK_CARGO}" install \ "${COOKBOOK_CARGO}" install \
--path "${COOKBOOK_SOURCE}/${PACKAGE_PATH}" \ --path "${COOKBOOK_SOURCE}${COOKBOOK_CARGO_PATH:+/$COOKBOOK_CARGO_PATH}" \
--root "${COOKBOOK_STAGE}/usr" \ --root "${COOKBOOK_STAGE}/usr" \
--locked \ -j "${COOKBOOK_MAKE_JOBS}" ${install_flags} \
--no-track \ ${COOKBOOK_CARGO_FLAGS[@]} "$@"
${install_flags} \ }
-j "${COOKBOOK_MAKE_JOBS}" "$@"
# cargo template using cargo build (prefixed name)
function cookbook_cargo_build {
recipe="${recipe:-$(basename "${COOKBOOK_RECIPE}")}"
bin_dir="${bin_dir:-.}"
bin_flags="${bin_flags:-}"
bin_name="${bin_name:-$(basename "${COOKBOOK_CARGO_PATH}")}"
bin_final_name="${bin_final_name:-${recipe}_${bin_name//_/-}}"
mkdir -pv "${COOKBOOK_STAGE}/usr/bin"
"${COOKBOOK_CARGO}" build \
--manifest-path "${COOKBOOK_SOURCE}${COOKBOOK_CARGO_PATH:+/$COOKBOOK_CARGO_PATH}/Cargo.toml" \
${bin_flags} ${build_flags} -j "${COOKBOOK_MAKE_JOBS}" ${COOKBOOK_CARGO_FLAGS[@]}
cp -v \
"target/${TARGET}/${build_type}/${bin_dir}/${bin_name}" \
"${COOKBOOK_STAGE}/usr/bin/${bin_final_name}"
unset bin_name bin_flags bin_dir bin_final_name
} }
# helper for installing binaries that are cargo examples # helper for installing binaries that are cargo examples
@ -159,30 +177,17 @@ function cookbook_cargo_examples {
recipe="$(basename "${COOKBOOK_RECIPE}")" recipe="$(basename "${COOKBOOK_RECIPE}")"
for example in "$@" for example in "$@"
do do
"${COOKBOOK_CARGO}" build \ bin_dir="examples" bin_name="${example}" bin_flags="--example ${example}" cookbook_cargo_build
--manifest-path "${COOKBOOK_SOURCE}/${PACKAGE_PATH}/Cargo.toml" \
--example "${example}" \
${build_flags} -j "${COOKBOOK_MAKE_JOBS}"
mkdir -pv "${COOKBOOK_STAGE}/usr/bin"
cp -v \
"target/${TARGET}/${build_type}/examples/${example}" \
"${COOKBOOK_STAGE}/usr/bin/${recipe}_${example}"
done done
} }
# helper for installing binaries that are cargo packages # helper for installing binaries that are cargo packages
function cookbook_cargo_packages { function cookbook_cargo_packages {
recipe="$(basename "${COOKBOOK_RECIPE}")" recipe="$(basename "${COOKBOOK_RECIPE}")"
mkdir -pv "${COOKBOOK_STAGE}/usr/bin"
for package in "$@" for package in "$@"
do do
"${COOKBOOK_CARGO}" build \ bin_name="${package}" bin_flags="--package ${package}" bin_final_name="${package//_/-}" cookbook_cargo_build
--manifest-path "${COOKBOOK_SOURCE}/${PACKAGE_PATH}/Cargo.toml" \
--package "${package}" \
${build_flags} -j "${COOKBOOK_MAKE_JOBS}"
mkdir -pv "${COOKBOOK_STAGE}/usr/bin"
cp -v \
"target/${TARGET}/${build_type}/${package}" \
"${COOKBOOK_STAGE}/usr/bin/${recipe}_${package}"
done done
} }

View File

@ -100,9 +100,13 @@ pub enum BuildKind {
#[serde(rename = "cargo")] #[serde(rename = "cargo")]
Cargo { Cargo {
#[serde(default)] #[serde(default)]
package_path: Option<String>, cargopath: Option<String>,
#[serde(default)] #[serde(default)]
cargoflags: String, cargoflags: Vec<String>,
#[serde(default)]
cargopackages: Vec<String>,
#[serde(default)]
cargoexamples: Vec<String>,
}, },
/// Will build and install using configure and make /// Will build and install using configure and make
#[serde(rename = "configure")] #[serde(rename = "configure")]
@ -559,8 +563,10 @@ mod tests {
shallow_clone: None, shallow_clone: None,
}), }),
build: BuildRecipe::new(BuildKind::Cargo { build: BuildRecipe::new(BuildKind::Cargo {
package_path: None, cargopath: None,
cargoflags: String::new(), cargoflags: Vec::new(),
cargopackages: Vec::new(),
cargoexamples: Vec::new(),
}), }),
..Default::default() ..Default::default()
} }