diff --git a/cmdstanpy/model.py b/cmdstanpy/model.py index 873bff09..1f40a624 100644 --- a/cmdstanpy/model.py +++ b/cmdstanpy/model.py @@ -43,6 +43,7 @@ do_command, get_logger, returncode_msg, + macos_make_arch, ) from . import progress as progbar @@ -413,7 +414,10 @@ def compile( 'MAKE', 'make' if platform.system() != 'Windows' else 'mingw32-make', ) + cmd = [make] + if sys.platform == 'darwin': + cmd = macos_make_arch() + cmd if self._compiler_options is not None: cmd.extend(self._compiler_options.compose()) cmd.append(Path(exe_file).as_posix()) diff --git a/cmdstanpy/utils.py b/cmdstanpy/utils.py index 03b7357b..5a1403b5 100644 --- a/cmdstanpy/utils.py +++ b/cmdstanpy/utils.py @@ -1478,3 +1478,16 @@ def __enter__(self) -> Tuple[str, bool]: def __exit__(self, exc_type, exc_val, exc_tb) -> None: # type: ignore if self._tmpdir: shutil.rmtree(self._tmpdir, ignore_errors=True) + + +def macos_make_arch() -> List[str]: + """Determine what `arch -arm64` prefix required for `make` invocations.""" + if sys.platform != 'darwin': + return [] + cmd = ['file', cmdstan_path() + '/bin/stansummary'] + out = subprocess.check_output(cmd).decode('ascii').strip() + match = re.search(r"Mach-O 64-bit executable (.*?)$", out) + if match: + arch, = match.groups() + return ['arch', '-' + arch] + return []