Skip to content

Commit

Permalink
fix: universal2 build (#90)
Browse files Browse the repository at this point in the history
ExternalProject_add does not forward CMAKE_OSX_ARCHITECTURES to the external project. This leads to a broken universal2 build which only has the x86_64 binary.
Let's forward a few variables to the external project to fix this.
  • Loading branch information
mayeut authored Nov 21, 2021
1 parent 89ef2b5 commit 450d8bb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,30 @@ if(UNIX AND NOT APPLE)
)
else()
set(Ninja_BINARY_DIR ${CMAKE_BINARY_DIR}/Ninja-build)
# cache arguments
set(_cache_args )
foreach(var_name IN ITEMS
CMAKE_BUILD_TYPE
CMAKE_TOOLCHAIN_FILE
CMAKE_BUILD_PARALLEL_LEVEL
CMAKE_JOB_POOLS
CMAKE_JOB_POOL_COMPILE
CMAKE_JOB_POOL_LINK
CMAKE_OSX_DEPLOYMENT_TARGET
CMAKE_OSX_ARCHITECTURES
CMAKE_OSX_SYSROOT
)
if(DEFINED ${var_name})
list(APPEND _cache_args
-D${var_name}:STRING=${${var_name}}
)
message(STATUS "SuperBuild - ${var_name}: ${${var_name}}")
endif()
endforeach()
# _cache_args should not be empty
list(APPEND _cache_args
-DNINJA_SUPERBUILD:BOOL=true
)
ExternalProject_add(build_ninja
SOURCE_DIR ${Ninja_SOURCE_DIR}
BINARY_DIR ${Ninja_BINARY_DIR}
Expand All @@ -111,6 +135,7 @@ else()
USES_TERMINAL_CONFIGURE 1
USES_TERMINAL_BUILD 1
INSTALL_COMMAND ""
CMAKE_CACHE_ARGS ${_cache_args}
DEPENDS
download_ninja_source
)
Expand Down
10 changes: 10 additions & 0 deletions scripts/repair_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import subprocess
import sys
import tempfile
import zipfile
from pathlib import Path

from convert_to_generic_platform_wheel import convert_to_generic_platform_wheel
Expand Down Expand Up @@ -58,6 +59,15 @@ def main():
# we need to handle macOS x86_64 & arm64 here for now, let's use additional_platforms for this.
additional_platforms = []
if os_ == "macos":
# delocate-wheel --require-archs does not seem to check executables...
with tempfile.TemporaryDirectory() as tmpdir2_:
tmpdir2 = Path(tmpdir2_)
with zipfile.ZipFile(file, 'r') as zip_ref:
zip_ref.extractall(tmpdir2)
exe = list(tmpdir2.glob("**/bin/ninja"))
assert len(exe) == 1, exe
subprocess.run(["lipo", str(exe[0]), "-verify_arch", "x86_64", "arm64"], check=True, stdout=subprocess.PIPE)

# first, get the target macOS deployment target from the wheel
match = re.match(r"^.*-macosx_(\d+)_(\d+)_.*\.whl$", file.name)
assert match is not None, f"Couldn't match on {file.name}"
Expand Down

0 comments on commit 450d8bb

Please sign in to comment.