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

macOS force arch #556

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmdstanpy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
do_command,
get_logger,
returncode_msg,
macos_make_arch,
)

from . import progress as progbar
Expand Down Expand Up @@ -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())
Expand Down
13 changes: 13 additions & 0 deletions cmdstanpy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []