Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On Apple Silicon platforms (such as M1 and M2), the
mini_racer
library is compiled asarmlibmini_racer.dylib
instead oflibmini_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:
We use
sys.platform
to check the identifier of the current operating system. For macOS systems, the value ofsys.platform
is 'darwin'.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 ofsys.maxsize
is greater than 2^32.If
sys.platform
is equal to 'darwin' andsys.maxsize
is greater than 2^32, it indicates that the current system is Apple Silicon, and the function returnsTrue
. Otherwise, the function returnsFalse
.Here's the code snippet that implements this check:
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 returnsTrue
, we use thearmlibmini_racer.dylib
library path. Otherwise, we fallback to the defaultlibmini_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.