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

Mention that ctypesgen requires gcc #165

Open
mara004 opened this issue Feb 4, 2023 · 11 comments
Open

Mention that ctypesgen requires gcc #165

mara004 opened this issue Feb 4, 2023 · 11 comments

Comments

@mara004
Copy link
Contributor

mara004 commented Feb 4, 2023

It should be mentioned somewhere in the readme/description that ctypesgen needs gcc, ideally with installation instructions for the various platforms. I also find the term pure-python kind of misleading if gcc is involved. 1

Footnotes

  1. Although it's correct in the sense that ctypesgen itself is written entirely in Python, I feel like pure-python somewhat feigns "standalone" (i. e. independent of compiled binaries other than Python itself) in the current context.

@mara004
Copy link
Contributor Author

mara004 commented Feb 4, 2023

Also, ctypesgen should fail if gcc is missing, instead of producing a file that only contains the library loader template but no actual bindings.

@nilason
Copy link
Collaborator

nilason commented Feb 4, 2023

You are right, it should be mentioned also early on in the Readme file.

It is, however, mentioned that a C (pre-)compiler (clang is also working just fine) is needed in https://github.com/ctypesgen/ctypesgen/wiki/Getting-Started.

@mara004
Copy link
Contributor Author

mara004 commented Feb 4, 2023

Ah, you're right, I completely forgot about the Wiki, although it's mentioned (but the projects I commonly work with don't have one). Sorry for overlooking this!

@demberto
Copy link

demberto commented Apr 12, 2023

MSVC works for me by specifying --cpp="cl -E", although I cannot verify if the output is correct.

EDIT: Yes, the output is incomplete with MSVC

@mara004
Copy link
Contributor Author

mara004 commented Dec 16, 2023

clang is also working just fine

However, ctypesgen always wants gcc by default, even if clang is present but gcc is not.
Anyway, I have now implemented auto-detection using shutil.which(...) in pypdfium2-team@7559e81 ff.

I've also done some search for pure-python pre-processors, but AFAICS they're not currently near enough an emulation of gcc/clang to be usable in ctypesgen. See also ned14/pcpp#85 (comment) f.

@mara004
Copy link
Contributor Author

mara004 commented Dec 16, 2023

Yes, the output is incomplete with MSVC

@demberto Could you elaborate on why it fails or what is missing in the preprocessed header? (you may use --save-preprocessed-headers $FILENAME for inspection)
Unless MSVC's output is actually wrong, perhaps ctypesgen's parser could be made compatible with what MSVC does differently?

@demberto
Copy link

demberto commented Dec 16, 2023

I am no longer looking into this nor have the time to do it. (I'm out)

@mara004
Copy link
Contributor Author

mara004 commented Dec 16, 2023

I am no longer looking into this nor have the time to do it. (I'm out)

OK, sorry for directing the question at you then.

I rather meant, if someone has access to MSVC and time/interest to investigate, it would be nice to get some information on why it fails. But that doesn't necessarily mean I'll have time to look into it, either.
Actually I'm under time pressure too and not sure how long I can continue to actively commit to pypdfium2/ctypesgen.

@nilason
Copy link
Collaborator

nilason commented Dec 17, 2023

clang is also working just fine

However, ctypesgen always wants gcc by default, even if clang is present but gcc is not. Anyway, I have now implemented auto-detection using shutil.which(...) in pypdfium2-team@7559e81 ff.

There's no way to know which compiler would be the default compiler, there may be several installed in a machine, the gcc is the default option defined in:

default_values = {
"other_headers": [],
"modules": [],
"include_search_paths": [],
"compile_libdirs": [],
"runtime_libdirs": [],
"cpp": "gcc -E",
"allow_gnu_c": False,

but may be changed to whichever you like (with the cpp option).

@mara004
Copy link
Contributor Author

mara004 commented Dec 17, 2023

The point is this: there may be only clang available but not gcc. In that case, it is good to dynamically select as default the one that is available. This is ctypesgen's task, not the caller's.
To be clear, I am not talking about removing the cpp option or something, just a smarter default. See the referenced commit for implementation.

@mara004
Copy link
Contributor Author

mara004 commented Dec 17, 2023

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

No branches or pull requests

3 participants