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

fix: add Apple Silicon support #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Jiacheng787
Copy link

On Apple Silicon platforms (such as M1 and M2), the mini_racer library is compiled as armlibmini_racer.dylib instead of libmini_racer.dylib. Using the incorrect library path may cause a runtime exception.

To address this issue, we introduce a runtime check to determine if the current system is running on Apple Silicon. We utilize the sys module to inspect the system's characteristics.

Here's how the check works:

  1. We use sys.platform to check the identifier of the current operating system. For macOS systems, the value of sys.platform is 'darwin'.

  2. We use sys.maxsize to check the maximum integer value supported by the current Python interpreter. On Apple Silicon devices, due to the 64-bit architecture, the value of sys.maxsize is greater than 2^32.

  3. If sys.platform is equal to 'darwin' and sys.maxsize is greater than 2^32, it indicates that the current system is Apple Silicon, and the function returns True. Otherwise, the function returns False.

Here's the code snippet that implements this check:

import sys

def is_apple_silicon():
    return sys.platform == 'darwin' and sys.maxsize > 2**32

By incorporating this check into the library's initialization process, we can dynamically determine the appropriate library path based on the underlying system architecture.

If the is_apple_silicon() function returns True, we use the armlibmini_racer.dylib library path. Otherwise, we fallback to the default libmini_racer.dylib path.

This runtime detection ensures that the mini_racer library is correctly loaded on Apple Silicon systems, preventing potential runtime exceptions caused by using the incorrect library path.

Please note that this workaround assumes that the operating system running on Apple Silicon devices is macOS and that a 64-bit Python interpreter is being used. If these assumptions change in the future, the detection logic may need to be updated accordingly.

@kelvindecosta
Copy link

+1

@kelvindecosta
Copy link

Hey @nizox , I'm really sorry for bothering you, I hope you're doing well.
I would really appreciate an update on this particular PR.

Thank you for maintaining this amazing project!

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.

2 participants