From 3ee1f4da0052802fc0cdd7162428708639db61a0 Mon Sep 17 00:00:00 2001 From: Anhad Singh Date: Mon, 20 Jan 2025 19:12:15 +1100 Subject: [PATCH] feat(cookbook): add the option to prefer static By default all libraries and applications that can be dynamically linked will be dynamically linked. You can override this behaviour by setting the `COOKBOOK_PREFER_STATIC` environment variable. Note that if you perviously did not use this flag, it might (most likely will) require a complete userland sysroot recompilation. It will look like this: ```bash $ make clean $ COOKBOOK_PREFER_STATIC=yes make image ``` For testing, the following will also work: ```bash $ COOKBOOK_PREFER_STATIC=yes make cr.{PACKAGE_NAME} # obviously replace # PACKAGE_NAME with # the name of a package :) ``` Signed-off-by: Anhad Singh --- recipes/dev/gcc13/recipe.toml | 12 ++++++++++++ recipes/libs/libiconv/recipe.toml | 13 +++++++++++-- src/bin/cook.rs | 20 ++++++++++++-------- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/recipes/dev/gcc13/recipe.toml b/recipes/dev/gcc13/recipe.toml index 72405a87f..106e8e748 100644 --- a/recipes/dev/gcc13/recipe.toml +++ b/recipes/dev/gcc13/recipe.toml @@ -37,6 +37,18 @@ COOKBOOK_CONFIGURE_FLAGS=( --with-bugurl="https://gitlab.redox-os.org/redox-os/gcc/-/issues" ) +if [[ -n "$COOKBOOK_PREFER_STATIC" ]]; then + COOKBOOK_CONFIGURE_FLAGS+=( + --enable-static + --disable-shared + ) +else + COOKBOOK_CONFIGURE_FLAGS+=( + --enable-shared + --disable-static + ) +fi + "${COOKBOOK_CONFIGURE}" "${COOKBOOK_CONFIGURE_FLAGS[@]}" "${COOKBOOK_MAKE}" -j "${COOKBOOK_MAKE_JOBS}" all-gcc "${COOKBOOK_MAKE}" install-gcc DESTDIR="${COOKBOOK_STAGE}" diff --git a/recipes/libs/libiconv/recipe.toml b/recipes/libs/libiconv/recipe.toml index 1ef97dc58..38e46cce2 100644 --- a/recipes/libs/libiconv/recipe.toml +++ b/recipes/libs/libiconv/recipe.toml @@ -23,9 +23,18 @@ DYNAMIC_INIT COOKBOOK_CONFIGURE_FLAGS=( --host="${GNU_TARGET}" --prefix="" - --enable-shared - --enable-static ac_cv_have_decl_program_invocation_name=no ) +if [[ -n "$COOKBOOK_PREFER_STATIC" ]]; then + COOKBOOK_CONFIGURE_FLAGS+=( + --enable-static + --disable-shared + ) +else + COOKBOOK_CONFIGURE_FLAGS+=( + --enable-shared + --enable-static + ) +fi cookbook_configure """ diff --git a/src/bin/cook.rs b/src/bin/cook.rs index 305d849f4..fcfab14a9 100644 --- a/src/bin/cook.rs +++ b/src/bin/cook.rs @@ -170,6 +170,18 @@ fn run_command_stdin(mut command: process::Command, stdin_data: &[u8]) -> Result static SHARED_PRESCRIPT: &str = r#" function DYNAMIC_INIT { + COOKBOOK_AUTORECONF="autoreconf" + autotools_recursive_regenerate() { + for f in $(find . -name configure.ac -o -name configure.in -type f | sort); do + echo "* autotools regen in '$(dirname $f)'..." + ( cd "$(dirname "$f")" && "${COOKBOOK_AUTORECONF}" -fvi "$@" -I${COOKBOOK_HOST_SYSROOT}/share/aclocal ) + done + } + + if [[ -n "$COOKBOOK_PREFER_STATIC" ]]; then + return + fi + echo "WARN: Program is being compiled dynamically." COOKBOOK_CONFIGURE_FLAGS=( @@ -182,14 +194,6 @@ function DYNAMIC_INIT { # TODO: check paths for spaces export LDFLAGS="-L${COOKBOOK_SYSROOT}/lib" export RUSTFLAGS="-C target-feature=-crt-static" - - COOKBOOK_AUTORECONF="autoreconf" - autotools_recursive_regenerate() { - for f in $(find . -name configure.ac -o -name configure.in -type f | sort); do - echo "* autotools regen in '$(dirname $f)'..." - ( cd "$(dirname "$f")" && "${COOKBOOK_AUTORECONF}" -fvi "$@" -I${COOKBOOK_HOST_SYSROOT}/share/aclocal ) - done - } } "#;