-
Notifications
You must be signed in to change notification settings - Fork 77
run.sh: force MacOs to run the executable natively when on Apple Silicon #79
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
Open
nskobelevs
wants to merge
3
commits into
NeighTools:master
Choose a base branch
from
nskobelevs:run-sh-native-apple-silicon-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+20
−2
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,7 +123,7 @@ abs_path() { | |
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" | ||
} | ||
|
||
# Set executable path and the extension to use for the libdoorstop shared object | ||
# Set executable path and the extension to use for the libdoorstop shared object as well as check whether we're running on Apple Silicon | ||
os_type="$(uname -s)" | ||
case ${os_type} in | ||
Linux*) | ||
|
@@ -148,6 +148,14 @@ case ${os_type} in | |
;; | ||
esac | ||
lib_extension="dylib" | ||
|
||
# CPUs for Apple Silicon are in the format "Apple M.." | ||
cpu_type="$(sysctl -n machdep.cpu.brand_string)" | ||
case "${cpu_type}" in | ||
Apple*) | ||
is_apple_silicon=1 | ||
;; | ||
esac | ||
;; | ||
*) | ||
# alright whos running games on freebsd | ||
|
@@ -309,4 +317,14 @@ else | |
export DYLD_INSERT_LIBRARIES="${doorstop_name}:${DYLD_INSERT_LIBRARIES}" | ||
fi | ||
|
||
exec "$executable_path" "$@" | ||
if [ -n "${is_apple_silicon}" ]; then | ||
export ARCHPREFERENCE="arm64,x86_64" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From
This tells arch to prefer |
||
|
||
# We need to use arch for Apple Silicon to allow the executable to be run natively as otherwise if | ||
# the executable is universal, supporting both x86_64 and arm64, MacOs will still run it as x86_64 | ||
# if the parent process is running as x86. | ||
# arch also strips the DYLD_INSERT_LIBRARIES env var so we have to pass that in manually | ||
exec arch -e DYLD_INSERT_LIBRARIES="${DYLD_INSERT_LIBRARIES}" "$executable_path" "$@" | ||
else | ||
exec "$executable_path" "$@" | ||
fi |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that on Intel Macs this would be something like
Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
.I don't have an Intel Mac to test this but I've reached out to a mate with one to check the output as a sanity check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
uname -m
would work? Is there a world where this matches on Linux?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
uname
shipped with MacOS is also a universal binary so it falls into the same pitfalls where it'll just run it via Rosetta and return x86_64.Could run it via
arch
andARCHPREFERENCES
like the main executable but I'm not actually sure if thearch
command shipped on Intel Macs behaves the same without throwing a fit. Will have someone who has an Intel Mac check this.My understanding is that
machdep
is an Apple only namespace, plus this is in the*Darwin*)
branch so linux wouldn't reach here.