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

If a custom header file is used it isn't included in the source distribution #831

Closed
2 tasks done
stusmall opened this issue Mar 5, 2022 · 3 comments
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@stusmall
Copy link

stusmall commented Mar 5, 2022

Bug Description

I'm building a crate following the example in the cffi-mixed test crate. One of the unique things about this crate is that python is only one of several different languages I'm creating bindings for. Because I've this I am using safer_ffi to define the FFI layer. cbindgen isn't able to produce headers using safer-ffi so I'm using the safer-ffi produced header and dropping it in target/header.h. This works great for the produced wheel but the header is left out of the source distro and thus fails to work.

Your Python version (python -V)

3.8.12

Your pip version (pip -V)

22.0.3

What bindings you're using

cffi

Does cargo build work?

  • Yes, it works

If on windows, have you checked that you aren't accidentally using unix path (those with the forward slash /)?

  • Yes

Steps to Reproduce

I wrote a minimal reproduction case for this here: https://github.com/stusmall/maturin-safer-ffi

Just pull it and follow the instructions in the readme. Some of the things the crate does might seem strange, but it is there to support many different language bindings to one rust crate.

@messense
Copy link
Member

messense commented Mar 6, 2022

I think currently maturin will look at target/header.h but it won't package any file from target directory.

Alternatively you can use a build script that writes a header file to $PROJECT_ROOT/target/header.h.

Thus this design is broken for source distribution if you are not generating the header.h in build scripts.

cc @konstin

@konstin
Copy link
Member

konstin commented Mar 6, 2022

The idea is that the build script generates the header and writes it to target directory, but i don't know safe_ffi so i don't know if that assumption still makes sense for it

@stusmall
Copy link
Author

stusmall commented Mar 6, 2022

I'm moderately new to safer_ffi, I know there is a reason why they opted for the pattern with the test thing rather than using build.rs but I'm not 100% on what it is. I'm pretty sure it's because build.rs doesn't allow post build actions which is what they need for the header generation.

Either way I just found out that setting sdist-include = ["target/header.h"] under [tool.maturin] will include it and everything works great.

If I haven't thanked y'all already I'd like to now. This project is absolutely fantastic!

@stusmall stusmall closed this as completed Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants