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

Core: Build wheels for the appropriate architecture on OSx devices #107

Merged
merged 1 commit into from
Oct 28, 2024
Merged
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
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