Skip to content
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

Extension ignores CXXFLAGS #1192

Closed
matt-chan opened this issue Nov 9, 2017 · 8 comments
Closed

Extension ignores CXXFLAGS #1192

matt-chan opened this issue Nov 9, 2017 · 8 comments

Comments

@matt-chan
Copy link

(I'm not sure if I should report this here, or at the Cython project.)

When using Extension (I used it for Cython, not sure about other cases), the CXXFLAGS variable is ignored during compile. This is a problem because it is normally set as an environmental variable for OSX/clang instead of CFLAGS (which is the norm for linux/gcc). For example, conda will not build C++11 code at all without the extra options present in CXXFLAGS.

I had to write a workaround to insert the CXXFLAGS into the Extension through the extra_compile_args parameter. Example code below:

def get_cxxflags():
    """If the CXXFLAGS variable is defined (clang/osx) then get it"""
    return os.environ.get("CXXFLAGS", "").split()

....

    ext_modules=[Extension(
        "x.cext",
        sources=["x/cext.pyx"] + glob.glob("x/*.cpp"),
        depends=glob.glob("x/*.hpp"),
        extra_compile_args=get_cxxflags(),
        language="c++",
        ),

Software tested (from conda):

cython                    0.26.1           py36hd51f8eb_0
python                    3.6.3                h5ce8c04_4 
setuptools                36.5.0           py36h2134326_0
...
@jaraco
Copy link
Member

jaraco commented Nov 14, 2017

Seems like maybe a reasonable thing to support, though I'm surprised it's only now coming to light. How is it that for so long there's been no need in distutils or setuptools for CXXFLAGS?

I suspect such a feature should first be implemented in distutils and then setuptools can support the backport.

@pganssle pganssle added Needs Triage Issues that need to be evaluated for severity and status. enhancement help wanted Needs Implementation Issues that are ready to be implemented. and removed Needs Triage Issues that need to be evaluated for severity and status. labels Oct 19, 2018
@pganssle
Copy link
Member

I think given that distutils is pretty much frozen, we should just go ahead and add support for it in setuptools.

reuben added a commit to mozilla/DeepSpeech that referenced this issue Oct 30, 2018
@ryandesign
Copy link

Seems like maybe a reasonable thing to support, though I'm surprised it's only now coming to light. How is it that for so long there's been no need in distutils or setuptools for CXXFLAGS?

It came to light fifteen years ago in distutils. Various patches were carried forward there for years but nothing was ever merged and distutils is dead now. Meanwhile we continue to suffer from this problem.

@ryandesign
Copy link

See also #1732.

@ryandesign
Copy link

So what's going to happen with this? How many more decades do we need to wait for Python to properly support modules written in C++?

@McSinyx
Copy link
Contributor

McSinyx commented Jun 29, 2020

@ryandesign, could you please consider patching the feature yourself, either downstream or upstream here if it's urgent. I understand that it's frustrating to not get the responses you expected but currently as you can see setuptools don't have a lot of human power.

@ryandesign
Copy link

I'm probably not the best person to do it. Besides being very busy with many other projects, I have no knowledge of the distutils/setuptools source code and only a very basic understanding of python. I would suggest that someone already familiar with those would be a better choice. Perhaps a good starting point is to look at the patches submitted to the distutils bug report to see if any of that code is still applicable to setuptools.

vlad-penkin added a commit to intel/hdk that referenced this issue Jun 15, 2022
Conda build on CentOS fails with the `error: expected ')' before 'PRIxPTR'`. The fix is to add -D__STDC_FORMAT_MACROS flag. 

Cython Extension build ignores $CXXFLAGS environment variable (pypa/setuptools#1192), the workaround is to add -D__STDC_FORMAT_MACROS flag to the Extension extra_compile_args.
alexbaden pushed a commit to intel/hdk that referenced this issue Jun 24, 2022
Conda build on CentOS fails with the `error: expected ')' before 'PRIxPTR'`. The fix is to add -D__STDC_FORMAT_MACROS flag. 

Cython Extension build ignores $CXXFLAGS environment variable (pypa/setuptools#1192), the workaround is to add -D__STDC_FORMAT_MACROS flag to the Extension extra_compile_args.
@mhsmith
Copy link

mhsmith commented Oct 16, 2024

It looks like this was fixed in setuptools 72.2.0, which includes pypa/distutils#228.

@jaraco jaraco closed this as completed Dec 25, 2024
@jaraco jaraco removed help wanted Needs Implementation Issues that are ready to be implemented. labels Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants