From fc0e27c24bb6e3853e9b7da8f1ff59025edf1e70 Mon Sep 17 00:00:00 2001 From: native-api Date: Fri, 13 Dec 2024 23:06:03 +0300 Subject: [PATCH] Support PACKAGE_CPPFLAGS and PACKAGE_LDFLAGS (#3130) add test to test all the flag types --- plugins/python-build/README.md | 8 +- plugins/python-build/bin/python-build | 12 ++- plugins/python-build/test/build.bats | 133 ++++++++++++++------------ 3 files changed, 87 insertions(+), 66 deletions(-) diff --git a/plugins/python-build/README.md b/plugins/python-build/README.md index b717512f..e6b7b4f8 100644 --- a/plugins/python-build/README.md +++ b/plugins/python-build/README.md @@ -169,16 +169,14 @@ You can set certain environment variables to control the build process. * `PYTHON_BUILD_DEFINITIONS` can be a list of colon-separated paths that get additionally searched when looking up build definitions. * `CC` sets the path to the C compiler. -* `PYTHON_CFLAGS` lets you pass additional options to the default `CFLAGS`. Use - this to override, for instance, the `-O3` option. * `CONFIGURE_OPTS` lets you pass additional options to `./configure`. * `MAKE` lets you override the command to use for `make`. Useful for specifying GNU make (`gmake`) on some systems. * `MAKE_OPTS` (or `MAKEOPTS`) lets you pass additional options to `make`. * `MAKE_INSTALL_OPTS` lets you pass additional options to `make install`. -* `PYTHON_CONFIGURE_OPTS` and `PYTHON_MAKE_OPTS` and `PYTHON_MAKE_INSTALL_OPTS` allow - you to specify configure and make options for building CPython. These variables - will be passed to Python only, not any dependent packages (e.g. libyaml). +* `_CFLAGS`, `_CPPFLAGS`, `_LDFLAGS` let you pass additional options to `CFLAGS`/`CPPFLAGS`/`LDFLAGS` specifically for building `` (Python itself or a dependency library) from source as part of the build script. `` should be a capitalized name of the package without version (technically, capitalized first argument to `install_package` without version). E.g. for CPython, it's "`PYTHON`", for Readline, "`READLINE`", for PyPy (only applies when building it from source), "`PYPY`". Check the source of the build script you're using if unsure. +* `_CONFIGURE_OPTS`, `_MAKE_OPTS`, `_MAKE_INSTALL_OPTS`, `_MAKE_INSTALL_TARGET` allow + you to specify configure and make options for building `` (same as above). "Make install target" would replace "`install`" in the `make install` invocation. ### Applying patches to Python before compiling diff --git a/plugins/python-build/bin/python-build b/plugins/python-build/bin/python-build index 16fe6285..34fd0d27 100755 --- a/plugins/python-build/bin/python-build +++ b/plugins/python-build/bin/python-build @@ -811,6 +811,8 @@ build_package_standard_build() { local PACKAGE_MAKE_OPTS="${package_var_name}_MAKE_OPTS" local PACKAGE_MAKE_OPTS_ARRAY="${package_var_name}_MAKE_OPTS_ARRAY[@]" local PACKAGE_CFLAGS="${package_var_name}_CFLAGS" + local PACKAGE_CPPFLAGS="${package_var_name}_CPPFLAGS" + local PACKAGE_LDFLAGS="${package_var_name}_LDFLAGS" if [ "$package_var_name" = "PYTHON" ]; then use_homebrew || true @@ -826,8 +828,14 @@ build_package_standard_build() { use_free_threading || true fi - ( if [ "${CFLAGS+defined}" ] || [ "${!PACKAGE_CFLAGS+defined}" ]; then - export CFLAGS="$CFLAGS ${!PACKAGE_CFLAGS}" + ( if [[ -n "${!PACKAGE_CFLAGS}" ]]; then + export CFLAGS="${CFLAGS:+$CFLAGS }${!PACKAGE_CFLAGS}" + fi + if [[ -n "${!PACKAGE_CPPFLAGS}" ]]; then + export CPPFLAGS="${CPPFLAGS:+$CPPFLAGS }${!PACKAGE_CPPFLAGS}" + fi + if [[ -n "${!PACKAGE_LDFLAGS}" ]]; then + export LDFLAGS="${LDFLAGS:+$LDFLAGS }${!PACKAGE_LDFLAGS}" fi if [ -z "$CC" ] && is_mac -ge 1010; then export CC=clang diff --git a/plugins/python-build/test/build.bats b/plugins/python-build/test/build.bats index c6984898..8e3ce566 100644 --- a/plugins/python-build/test/build.bats +++ b/plugins/python-build/test/build.bats @@ -30,12 +30,12 @@ cached_tarball() { tarball() { local name="$1" local path="$PWD/$name" - local configure="$path/configure" + local configure="$path/${2:-configure}" shift 1 executable "$configure" <> build.log +echo "$name: CFLAGS=\\"\$CFLAGS\\" CPPFLAGS=\\"\$CPPFLAGS\\" LDFLAGS=\\"\$LDFLAGS\\" PKG_CONFIG_PATH=\\"\$PKG_CONFIG_PATH\\"" >> build.log echo "$name: \$@" \${PYTHONOPT:+PYTHONOPT=\$PYTHONOPT} >> build.log OUT @@ -50,7 +50,7 @@ OUT stub_make_install() { stub "$MAKE" \ " : echo \"$MAKE \$@\" >> build.log" \ - "install : echo \"$MAKE \$@\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'" + "${1:-install} : echo \"$MAKE \$@\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'" } assert_build_log() { @@ -74,17 +74,60 @@ assert_build_log() { unstub make assert_build_log <