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)
#export WAYLAND_DISPLAY=wayland-1
#smallvil_smallvil &
#smallvil &
#sleep 2
#wayland-session
"""

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,5 +5,7 @@ branch = "main"
[build]
template = "custom"
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 = """
DYNAMIC_INIT
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"
mkdir -p "${COOKBOOK_STAGE}/usr/lib/helix/runtime/grammars"
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
${COOKBOOK_CARGO} install \
--path "${COOKBOOK_SOURCE}/${PACKAGE_PATH}" \
--path "${COOKBOOK_SOURCE}/${COOKBOOK_CARGO_PATH}" \
--root "${COOKBOOK_STAGE}/usr" \
--no-track \
--no-default-features \

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,7 +9,7 @@ patches = [
template = "custom"
script = """
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.rev = "8bf15a0"'
cookbook_cmake "${COOKBOOK_SOURCE}"/lib

View File

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

View File

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

View File

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

View File

@ -18,5 +18,5 @@ DYNAMIC_INIT
cp -v \
"target/${TARGET}/${build_type}/libfile_explorer_plugin.dylib" \
"${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]
git = "https://github.com/alacritty/alacritty"
shallow_clone = true
[build]
template = "custom"
template = "cargo"
dependencies = [
"freetype2",
"fontconfig",
"libxcb",
]
script = """
DYNAMIC_INIT
package=alacritty
"${COOKBOOK_CARGO}" build \
--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}"
"""
cargopath = "alacritty"
cargoflags = [
"--no-default-features",
"--features x11",
]

View File

@ -4,4 +4,4 @@
git = "https://codeberg.org/AeriaVelocity/sued"
[build]
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"
[build]
template = "custom"
template = "cargo"
dependencies = [
"libffi",
"libwayland",
"libxkbcommon",
]
script = """
DYNAMIC_INIT
export RUSTFLAGS="${RUSTFLAGS} -lffi"
cookbook_cargo_packages smallvil
"""
cargopackages = [
"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
export CARGO_MAKEFLAGS="-j $COOKBOOK_MAKE_JOBS" CCACHE="sccache"
PACKAGE_PATH="ports/servoshell" cookbook_cargo
COOKBOOK_CARGO_PATH="ports/servoshell" cookbook_cargo
# resources packaging
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?
let script = match &recipe.build.kind {
BuildKind::Cargo {
package_path,
cargopath,
cargoflags,
cargopackages,
cargoexamples,
} => {
format!(
"DYNAMIC_INIT\nPACKAGE_PATH={} cookbook_cargo {cargoflags}",
package_path.as_deref().unwrap_or(".")
)
let mut script = format!(
"DYNAMIC_INIT\n{}\nCOOKBOOK_CARGO_PATH={} ",
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!(
"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 {
package_path,
cargopath,
cargoflags: _,
cargopackages: _,
cargoexamples: _,
} = &recipe.recipe.build.kind
{
// 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)?;
@ -481,12 +483,12 @@ pub(crate) fn fetch_extract_tar(
pub(crate) fn fetch_cargo(
source_dir: &PathBuf,
package_path: Option<&String>,
cargopath: Option<&String>,
logger: &PtyOut,
) -> Result<(), String> {
let mut source_dir = source_dir.clone();
if let Some(package_path) = package_path {
source_dir = source_dir.join(package_path);
if let Some(cargopath) = cargopath {
source_dir = source_dir.join(cargopath);
}
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
# (or to your environment) before calling cookbook_cargo or cookbook_cargo_packages
build_type=release
install_flags=
install_flags=--no-track
build_flags=--release
if [ ! -z "${COOKBOOK_DEBUG}" ]
then
install_flags=--debug
install_flags+=" --debug"
build_flags=
build_type=debug
export CPPFLAGS="${CPPFLAGS} -g"
@ -142,16 +142,34 @@ fi
reexport_flags
# cargo template
COOKBOOK_CARGO="${COOKBOOK_REDOXER}"
COOKBOOK_CARGO_FLAGS=(
--locked
)
# cargo template using cargo install
function cookbook_cargo {
"${COOKBOOK_CARGO}" install \
--path "${COOKBOOK_SOURCE}/${PACKAGE_PATH}" \
--path "${COOKBOOK_SOURCE}${COOKBOOK_CARGO_PATH:+/$COOKBOOK_CARGO_PATH}" \
--root "${COOKBOOK_STAGE}/usr" \
--locked \
--no-track \
${install_flags} \
-j "${COOKBOOK_MAKE_JOBS}" "$@"
-j "${COOKBOOK_MAKE_JOBS}" ${install_flags} \
${COOKBOOK_CARGO_FLAGS[@]} "$@"
}
# 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
@ -159,30 +177,17 @@ function cookbook_cargo_examples {
recipe="$(basename "${COOKBOOK_RECIPE}")"
for example in "$@"
do
"${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}"
bin_dir="examples" bin_name="${example}" bin_flags="--example ${example}" cookbook_cargo_build
done
}
# helper for installing binaries that are cargo packages
function cookbook_cargo_packages {
recipe="$(basename "${COOKBOOK_RECIPE}")"
mkdir -pv "${COOKBOOK_STAGE}/usr/bin"
for package in "$@"
do
"${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}"
bin_name="${package}" bin_flags="--package ${package}" bin_final_name="${package//_/-}" cookbook_cargo_build
done
}

View File

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