Skip to content

Commit

Permalink
Re-execute natively if started under Rosetta 2
Browse files Browse the repository at this point in the history
But not if building for x86_64 or if a selfupdate or migrate is already
underway. This should help prevent issues caused by build systems
auto-detecting that they are on x86_64 even though we're using compiler
flags that build for arm64.
  • Loading branch information
jmroot committed Oct 15, 2024
1 parent 425b158 commit eee437c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/port/port.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -5607,6 +5607,20 @@ if {[catch {mportinit ui_options global_options global_variations} result]} {
fatal "Failed to initialize MacPorts, $result"
}

# Re-execute if running under Rosetta 2 and not building for x86_64.
# We know we are a universal binary if this is needed since mportinit
# would have errored if not.
if {${macports::os_major} >= 20 && ${macports::os_platform} eq "darwin" &&
${macports::build_arch} ne "x86_64" &&
![info exists global_options(ports_no_migration_check)] &&
![catch {sysctl sysctl.proc_translated} translated] && $translated
} then {
ui_warn "MacPorts started under Rosetta 2, re-executing natively"
execl /usr/bin/arch [list -arm64 $::argv0 {*}$::argv]
ui_debug "Would have executed $::argv0 $::argv"
ui_warn "Failed to re-execute MacPorts... just continuing"
}

# Change to port directory if requested
if {[info exists global_options(ports_dir)]} {
set dir $global_options(ports_dir)
Expand Down

0 comments on commit eee437c

Please sign in to comment.