Skip to content

gh-134273: Allow setting JIT compiler flags with CFLAGS_JIT #134276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

zanieb
Copy link
Contributor

@zanieb zanieb commented May 19, 2025

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! These should also be part of the hash in _Target._compute_digest.

@bedevere-app
Copy link

bedevere-app bot commented May 19, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@brandtbucher
Copy link
Member

BTW, JIT CI is broken on macOS and Windows currently, so if those fail (build failure on Windows and 2 failing tests on macOS), it's not your fault.

@zanieb
Copy link
Contributor Author

zanieb commented May 19, 2025

Technically, this should probably also support CFLAGS_NODIST? I'm not sure.

@zanieb zanieb marked this pull request as ready for review May 20, 2025 14:00
@brandtbucher
Copy link
Member

It's up to you. If you want to add CFLAGS_NODIST, just use the same --with-cflags option to pass them though (the build script doesn't care which is which).

@brandtbucher
Copy link
Member

brandtbucher commented May 20, 2025

So, this breaks on universal builds, since that sets CONFIGURE_CFLAGS= -arch arm64 -arch x86_64. See the AArch64 macOS failures in CI (it's different from the expected test failures).

I think part of the problem is that we don't want to use an option for the JIT just because it's being used for the interpreter itself. We want very tight control over the code we're generating, especially since the parse step is sort of fragile.

What flags are you needing to pass, exactly? Is it only include paths?

@zanieb
Copy link
Contributor Author

zanieb commented May 20, 2025

I only need the include flag for my build to pass. But I only caught #134291 because all of my flags were passed through. It's possible there are other subtle differences. I'm totally fine with a CFLAGS_JIT, personally. I feel like people are opposed to new CFLAGS variants, but here it makes a lot of sense.

@zanieb zanieb changed the title gh-134273: Propagate CFLAGS to the JIT gh-134273: Allow setting JIT compiler flags with CFLAGS_JIT May 27, 2025
@zanieb
Copy link
Contributor Author

zanieb commented May 29, 2025

I've updated to use CFLAGS_JIT

@zanieb
Copy link
Contributor Author

zanieb commented Jun 4, 2025

@brandtbucher gentle nudge, so I don't need to maintain patches in perpetuity :)

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this! Just a couple of suggestions, then I'll land:

@@ -120,6 +123,7 @@ async def _compile(
) -> _stencils.StencilGroup:
o = tempdir / f"{opname}.o"
args = [
*shlex.split(self.cflags),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know what? I changed my mind.

Let's move these to the end, so people can override our options if they really need to. Anyone using this option should know what they're doing.

Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
zanieb and others added 2 commits June 6, 2025 08:27
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
@brandtbucher
Copy link
Member

Thanks! I just pushed the last change myself.

@brandtbucher
Copy link
Member

Sorry, I just pulled this down to play with it locally, and I have one question. It seems suboptimal to have to set the environment variable when actually running make. It think the way we prefer to do things like this is to "lock-in" configuration like this at configure time instead. For example, this won't currently work:

$ CFLAGS_JIT="-Icustom/include/dir" ./configure --enable-experimental-jit
$ # ...some time later...
$ make

What do you think about this patch, which will capture the variable at configure time and hardcode it in the Makefile? I think this is closer to what we do for similar things like CFLAGS_NODIST. I'm not an Autoconf or build system expert though, so I could be missing something:

diff --git a/configure.ac b/configure.ac
index 9ab4b370f1c..f6091c21b2a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2752,7 +2752,6 @@ AS_VAR_IF([ac_cv_gcc_compat], [yes], [
 ])
 
 # Check for --enable-experimental-jit:
-AC_SUBST([CFLAGS_JIT])
 AC_MSG_CHECKING([for --enable-experimental-jit])
 AC_ARG_ENABLE([experimental-jit],
               [AS_HELP_STRING([--enable-experimental-jit@<:@=no|yes|yes-off|interpreter@:>@],
@@ -2777,7 +2776,7 @@ AS_VAR_IF([jit_flags],
           [],
           [AS_VAR_APPEND([CFLAGS_NODIST], [" $jit_flags"])
            AS_VAR_SET([REGEN_JIT_COMMAND],
-                      ["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir . --cflags=\"\$(CFL
AGS_JIT)\""])
+                      ["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir . --cflags=\"$CFLAG
S_JIT\""])
            AS_VAR_SET([JIT_STENCILS_H], ["jit_stencils.h"])
            AS_VAR_IF([Py_DEBUG],
                      [true],
diff --git a/configure b/configure
index 68213817679..6170e67e6e2 100755
--- a/configure
+++ b/configure
@@ -906,7 +906,6 @@ DSYMUTIL_PATH
 DSYMUTIL
 JIT_STENCILS_H
 REGEN_JIT_COMMAND
-CFLAGS_JIT
 UNIVERSAL_ARCH_FLAGS
 WASM_STDLIB
 WASM_ASSETS_DIR
@@ -10833,7 +10832,6 @@ esac
 fi
 
 # Check for --enable-experimental-jit:
-
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --enable-experimental-jit" >&5
 printf %s "checking for --enable-experimental-jit... " >&6; }
 # Check whether --enable-experimental-jit was given.
@@ -10865,7 +10863,7 @@ then :
 
 else case e in #(
   e) as_fn_append CFLAGS_NODIST " $jit_flags"
-           REGEN_JIT_COMMAND="\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir . --cflags=\"
\$(CFLAGS_JIT)\""
+           REGEN_JIT_COMMAND="\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir . --cflags=\"
$CFLAGS_JIT\""
            JIT_STENCILS_H="jit_stencils.h"
            if test "x$Py_DEBUG" = xtrue
 then :

@zanieb
Copy link
Contributor Author

zanieb commented Jun 7, 2025

t seems suboptimal to have to set the environment variable when actually running make. It think the way we prefer to do things like this is to "lock-in" configuration like this at configure time instead.

Oh, that's how I thought it was working originally and definitely my intent. I guess I broke that when I changed it to CFLAGS_JIT, thanks for checking!

What do you think about this patch, which will capture the variable at configure time and hardcode it in the Makefile?

If the patch works, that's great.

@zanieb
Copy link
Contributor Author

zanieb commented Jun 7, 2025

(I can also actually use this patch in python-build-standalone to confirm it's working as intended, right now I'm using something hackier)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy