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

bdist wheels: exclude build-time-only files #192

Closed
wants to merge 13 commits into from

Conversation

T-256
Copy link
Contributor

@T-256 T-256 commented Dec 26, 2023

Last chunk of #176

  • sdist wheel now includes all required build-from-source files.
  • bdist wheels now excludes build-time-only files.

@perklet
Copy link
Collaborator

perklet commented Dec 27, 2023

I don't think this is the direction where are heading for.

  1. The declaritive pyproject.toml is the future of python packaging, so I would like to keep setup.py as minimal as possible.
  2. For platforms which we do not support, the sdist wheel will be downloded when pip installing, it's important to keep the build files so that they can be compiled with locally installed curl-impersonate.

@T-256
Copy link
Contributor Author

T-256 commented Dec 27, 2023

  1. The declaritive pyproject.toml is the future of python packaging, so I would like to keep setup.py as minimal as possible

Then I think we should move out build.py out of curl_cffi folder. (this setup.py patch is the only way to exclude when exclude target is python file in that package)

2. For platforms which we do not support, the sdist wheel will be downloded when pip installing, it's important to keep the build files so that they can be compiled with locally installed curl-impersonate.

Makes senses. though in PR description what I said is: This PR excludes build-time-only files/folders from wheels dist But it seems it still applies on sdist.
I will try to prevent this exclusion for sdist build later today.

@T-256 T-256 marked this pull request as draft December 27, 2023 11:08
@T-256 T-256 force-pushed the no-include branch 2 times, most recently from b6712d2 to 7a48b33 Compare December 27, 2023 12:55
@T-256 T-256 changed the title exclude build.py, ffi and include bdist wheels: exclude build-time-only files Dec 27, 2023
@T-256 T-256 force-pushed the no-include branch 22 times, most recently from 384e259 to e05b868 Compare December 27, 2023 16:13
"""
#include "shim.h"
""",
libraries=["curl-impersonate-chrome"] if system != "Windows" else ["libcurl"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we may miss some steps for building windows dll, the name, if correctly configured, should be libcurl-impersonate-chrome.dll

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this miss-configuration from curl-impersonate package?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, curl-impersonate, possibly missing autoreconf on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then, IIUC it's not blocker for merge this PR.

@bjia56
Copy link
Contributor

bjia56 commented Jan 23, 2024

Testing again on 32-bit raspbian (armv7l):

pi@raspberrypi3:~ $ pip install /tmp/curl_cffi-0.6.0b8.tar.gz
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Processing /tmp/curl_cffi-0.6.0b8.tar.gz
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting cffi>=1.12.0
  Using cached https://www.piwheels.org/simple/cffi/cffi-1.16.0-cp39-cp39-linux_armv7l.whl (367 kB)
Requirement already satisfied: certifi in /usr/lib/python3/dist-packages (from curl_cffi==0.6.0b8) (2020.6.20)
Collecting pycparser
  Using cached https://www.piwheels.org/simple/pycparser/pycparser-2.21-py2.py3-none-any.whl (119 kB)
Building wheels for collected packages: curl-cffi
  Building wheel for curl-cffi (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /tmp/tmpj8kc28s0_in_process.py build_wheel /tmp/tmpas0s8c7j
       cwd: /tmp/pip-req-build-gwupegko
  Complete output (5 lines):
  running bdist_wheel
  running build
  Downloading libcurl-impersonate-chrome from https://github.com/yifeikong/curl-impersonate/releases/download/v0.6.0b8/libcurl-impersonate-v0.6.0b8.arm-linux-gnu.tar.gz...
  Unpacking downloaded files...
  error: [Errno 13] Permission denied: '/usr/local/lib/libcurl-impersonate-chrome.a'
  ----------------------------------------
  ERROR: Failed building wheel for curl-cffi
Failed to build curl-cffi
ERROR: Could not build wheels for curl-cffi which use PEP 517 and cannot be installed directly

Not sure how important it is to allow the curl libs to be installed without root, though.

@perklet
Copy link
Collaborator

perklet commented Jan 23, 2024

I think we need to use patchelf on the curl-impersonate side

@bjia56
Copy link
Contributor

bjia56 commented Jan 23, 2024

The curl libraries are already self-contained after the curl-impersonate build pipeline. Above error is because the sdist attempts to download and install the libraries into /usr/local/lib, which fails when not run as root.

$ ldd -v libcurl-impersonate-chrome.so
        linux-vdso.so.1 (0x00007ffc8f614000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f6a014db000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f6a014d6000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6a012ad000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f6a017f4000)

        Version information:
        ./libcurl-impersonate-chrome.so:
                libpthread.so.0 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libpthread.so.0
                libc.so.6 (GLIBC_2.16) => /lib/x86_64-linux-gnu/libc.so.6
                libc.so.6 (GLIBC_2.3) => /lib/x86_64-linux-gnu/libc.so.6
                libc.so.6 (GLIBC_2.7) => /lib/x86_64-linux-gnu/libc.so.6
                libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6
                libc.so.6 (GLIBC_2.17) => /lib/x86_64-linux-gnu/libc.so.6
                libc.so.6 (GLIBC_2.3.4) => /lib/x86_64-linux-gnu/libc.so.6
                libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
        /lib/x86_64-linux-gnu/libz.so.1:
                libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6
                libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6
                libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
                libc.so.6 (GLIBC_2.3.4) => /lib/x86_64-linux-gnu/libc.so.6
        /lib/x86_64-linux-gnu/libpthread.so.0:
                libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
        /lib/x86_64-linux-gnu/libc.so.6:
                ld-linux-x86-64.so.2 (GLIBC_2.2.5) => /lib64/ld-linux-x86-64.so.2
                ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
                ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2

@perklet
Copy link
Collaborator

perklet commented Jan 23, 2024

Well,they have to be there,because of their rpath,which can be fixed by patchelf

@bjia56
Copy link
Contributor

bjia56 commented Jan 23, 2024

Not sure I understand - libcurl doesn't specify any other non-glibc libraries as dependencies, so it's more or less self contained. Auditwheel, on the other hand, will use patchelf to change library references to within the wheel itself, and copy the shared objects into the wheel. When cibuildwheel runs, auditwheel/delvewheel/delocate automatically runs to copy libraries into the final wheel.

@T-256
Copy link
Contributor Author

T-256 commented Jan 23, 2024

@yifeikong any suggestion to fix that? should it use chmod +x during sdist installation?

@T-256
Copy link
Contributor Author

T-256 commented Jan 23, 2024

When cibuildwheel runs, auditwheel/delvewheel/delocate automatically runs to copy libraries into the final wheel

FWIW, delvewheel dropped by #190 (windows-only), I believe we should do same for linux too. see #173.

@T-256
Copy link
Contributor Author

T-256 commented Jan 23, 2024

Above error is because the sdist attempts to download and install the libraries into /usr/local/lib, which fails when not run as root.

@bjia56 for clarification, do you verify build works when run as root?

@bjia56
Copy link
Contributor

bjia56 commented Jan 23, 2024

Auditwheel is a standard tool for building native wheels on Linux, what's the reason for removing it?

@bjia56
Copy link
Contributor

bjia56 commented Jan 23, 2024

@bjia56 for clarification, do you verify build works when run as root?

It does not yet work since the latest pre-release in curl-impersonate does not have the correct arm shared objects built. Another curl-impersonate tag will need to be cut.

@perklet
Copy link
Collaborator

perklet commented Jan 23, 2024

When cibuildwheel runs, auditwheel/delvewheel/delocate automatically runs to copy libraries into the final wheel

FWIW, delvewheel dropped by #190 (windows-only), I believe we should do same for linux too. see #173.

No, we can not. Windows dlls do not have features like rpath, that’s why you can simply copy dlls to make them work.

@@ -0,0 +1,79 @@
import os
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should move back this file to its original location for better tracking changes. It should be relocated next time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As the purposes of this PR, it tries to exclude all unneeded files from bdist wheels. the changes applied on this file after move is not much, you can compare them easily.

setup.py Outdated Show resolved Hide resolved
@perklet
Copy link
Collaborator

perklet commented Jan 24, 2024

I tested and find out that rpath or similar attributes are not set for libcurl-impersonate-chrome.so, but for libcurl-impersonate-ff.so and libcurl-impersonte-chrome.dylib.

Which basically means that we can safely change the temporaray lib directory for all linux archs. Thus, sudo will not be needed. But for macOS, we have to download it to the buildtime directory. Luckily, we have bdist wheel on macOS, users don't need to care about it.

This PR is including two different features, I suggest that we split it into smaller chunks. First we make the sdist work, then maybe excludes useless files for bdist.

auditwheel and delocate are always needed for fixing the rpath of _wrapper.so.

@T-256
Copy link
Contributor Author

T-256 commented Jan 24, 2024

This PR is including two different features, I suggest that we split it into smaller chunks. First we make the sdist work, then maybe excludes useless files for bdist.

Ok, Go ahead with fix sdits in separated PR, I'll update this PR relatively after that. I opened #225 to track it.

@T-256 T-256 force-pushed the no-include branch 2 times, most recently from 3ee52a1 to 67d27d2 Compare January 24, 2024 15:31
This reverts commit 94d8c72.
@perklet
Copy link
Collaborator

perklet commented Jan 25, 2024

This PR is including two different features, I suggest that we split it into smaller chunks. First we make the sdist work, then maybe excludes useless files for bdist.

Ok, Go ahead with fix sdits in separated PR, I'll update this PR relatively after that. I opened #225 to track it.

Cool, thanks.

@T-256 T-256 mentioned this pull request Feb 1, 2024
@T-256
Copy link
Contributor Author

T-256 commented Feb 1, 2024

Too many files need for rebasing, created new PR instead: #236

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

Successfully merging this pull request may close these issues.

3 participants