Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Core: Build wheels for the appropriate architecture on OSx devices
Browse files Browse the repository at this point in the history
  • Loading branch information
mawildoer committed Oct 28, 2024
1 parent 3fc2967 commit 1b37e26
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/faebryk/core/cpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@ def compile_and_load():
Forces C++ to compile into faebryk_core_cpp_editable module which is then loaded
into _cpp.
"""
import platform
import subprocess
import sys

def _do(*args, **kwargs):
try:
return subprocess.check_output(
*args, stderr=subprocess.PIPE, text=True, **kwargs
)
except subprocess.CalledProcessError as e:
logger.error(f"Subprocess error: {e.stderr}")
raise

cpp_dir = pathlib.Path(__file__).parent
build_dir = cpp_dir / "build"

Expand All @@ -33,15 +43,20 @@ def compile_and_load():
"cmake not found, needed for compiling c++ code in editable mode"
)

pybind11_dir = subprocess.check_output(
["python", "-m", "pybind11", "--cmakedir"],
text=True,
).strip()
pybind11_dir = _do(["python", "-m", "pybind11", "--cmakedir"]).strip()

# force recompile
# Force recompile
# subprocess.run(["rm", "-rf", str(build_dir)], check=True)

subprocess.run(
other_flags = []

# On OSx we've had some issues with building for the right architecture
if sys.platform == "darwin": # macOS
arch = platform.machine()
if arch in ["arm64", "x86_64"]:
other_flags += [f"-DCMAKE_OSX_ARCHITECTURES={arch}"]

_do(
[
"cmake",
"-S",
Expand All @@ -50,16 +65,15 @@ def compile_and_load():
str(build_dir),
"-DEDITABLE=1",
f"-DCMAKE_PREFIX_PATH={pybind11_dir}",
],
check=True,
]
+ other_flags,
)
subprocess.run(
_do(
[
"cmake",
"--build",
str(build_dir),
],
check=True,
)

if not build_dir.exists():
Expand Down

0 comments on commit 1b37e26

Please sign in to comment.