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

How to cross-compile dylib on macos? #1731

Open
louisabraham opened this issue Jan 24, 2024 · 4 comments
Open

How to cross-compile dylib on macos? #1731

louisabraham opened this issue Jan 24, 2024 · 4 comments

Comments

@louisabraham
Copy link

Description

On https://github.com/louisabraham/pydivsufsort/, my setup.py calls a bash file that builds a dylib file.

https://github.com/louisabraham/pydivsufsort/blob/33802969cbe1bcc3a29ea5c10bc281205794c3e4/setup.py#L39-L52

class build(_build):
    def run(self):
        if platform.system() == "Windows":
            witness = Path(__file__).parent / "pydivsufsort/divsufsort.dll"
            assert witness.exists(), "Launch ./build.sh first"
        elif platform.system() == "Darwin":
            script = Path(__file__).parent / "build.sh"
            path = script.absolute().as_posix()
            Popen(["arch", "-" + platform.machine(), path], shell=False).wait()
        else:
            script = Path(__file__).parent / "build.sh"
            path = script.absolute().as_posix()
            Popen([path], shell=True, executable="/bin/bash").wait()
        super().run()

Calling arch works only if platform.machine() returns the correct value. However I think that cibuildwheel uses a x86_64 interpreter even for cross-compilation builds.

Is there a way for me to detect from setup.py that cibuildwheel is trying to cross-compile?

Build log

No response

CI config

https://github.com/louisabraham/pydivsufsort/blob/33802969cbe1bcc3a29ea5c10bc281205794c3e4/.github/workflows/build-and-upload.yml

@louisabraham
Copy link
Author

Related issue: #1537

It's weird because I'm already using platform.machine().

@joerick
Copy link
Contributor

joerick commented Jan 26, 2024

sysconfig.get_platform() will pick up the cross-compilation flags that cibuildwheel sets. Have you tried that?

@louisabraham
Copy link
Author

The problem is that I get machine macosx-10.9-universal2. Can I get either arm64 or x86_64 ?

@joerick
Copy link
Contributor

joerick commented Jan 26, 2024

If you're running cibuildwheel with CIBW_ARCHS_MACOS=x86_64 arm64, then you won't get universal2. If you're running setup.py outside of cibuildwheel, then I guess it matches the arch that the interpreter was built with, which is universal2.

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

2 participants