Skip to content

Commit

Permalink
Fix universal2 build
Browse files Browse the repository at this point in the history
  • Loading branch information
laggykiller committed Feb 28, 2024
1 parent cccf996 commit a26537d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ if (WIN32)
endif()

# Add conan packages
if ("${APNGASM_COMPILE_TARGET}" STREQUAL "universal2")
# x86_64 Contians static libraries that are universal2
if ("${APNGASM_COMPILE_TARGET}" STREQUAL "universal2_x86_64")
set(CONAN_TOOLCHAIN ${CMAKE_SOURCE_DIR}/conan_output/x86_64/conan_toolchain.cmake)
elseif ("${APNGASM_COMPILE_TARGET}" STREQUAL "universal2_armv8")
set(CONAN_TOOLCHAIN ${CMAKE_SOURCE_DIR}/conan_output/armv8/conan_toolchain.cmake)
else()
set(CONAN_TOOLCHAIN ${CMAKE_SOURCE_DIR}/conan_output/${APNGASM_COMPILE_TARGET}/conan_toolchain.cmake)
endif()
Expand Down
28 changes: 18 additions & 10 deletions scripts/get_arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,26 @@
}


def get_arch():
arch = None
if os.getenv("APNGASM_COMPILE_TARGET"):
arch = os.getenv("APNGASM_COMPILE_TARGET")
def get_native_arch() -> str:
for k, v in conan_archs.items():
if platform.machine().lower() in v:
return k

# Failover
return platform.machine().lower()


def get_arch() -> str:
arch_env = os.getenv("APNGASM_COMPILE_TARGET")
if isinstance(arch_env, str):
arch = arch_env
else:
for k, v in conan_archs.items():
if platform.machine().lower() in v:
arch = k
break
arch = get_native_arch()

if arch == "universal2":
arch = "universal2_" + get_native_arch()

if arch is None:
arch = platform.machine().lower()
assert arch in ("universal2_x86_64", "universal2_armv8")

return arch

Expand Down
26 changes: 18 additions & 8 deletions scripts/get_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,36 @@ def install_deps(arch: str):
def main():
arch = get_arch()

if arch != "universal2":
if not arch.startswith("universal2"):
install_deps(arch)
else:
# Repeat to install the other architecture version of libwebp
conan_output_x64 = install_deps("x86_64")
conan_output_arm = install_deps("armv8")
conan_output_universal2 = conan_output_arm.replace("armv8", "universal2")
shutil.rmtree(conan_output_universal2, ignore_errors=True)

if arch.endswith("x86_64"):
lipo_dir_merge_src = conan_output_x64
lipo_dir_merge_dst = conan_output_arm
elif arch.endswith("armv8"):
lipo_dir_merge_src = conan_output_arm
lipo_dir_merge_dst = conan_output_x64
else:
raise RuntimeError("Invalid arch: " + arch)

lipo_dir_merge_result = lipo_dir_merge_src.replace("armv8", "universal2")
shutil.rmtree(lipo_dir_merge_result, ignore_errors=True)
subprocess.run(
[
"python3",
"lipo-dir-merge/lipo-dir-merge.py",
conan_output_x64,
conan_output_arm,
conan_output_universal2,
lipo_dir_merge_src,
lipo_dir_merge_dst,
lipo_dir_merge_result,
]
)

shutil.rmtree(conan_output_x64)
shutil.move(conan_output_universal2, conan_output_x64)
shutil.rmtree(lipo_dir_merge_src)
shutil.move(lipo_dir_merge_result, lipo_dir_merge_src)


if __name__ == "__main__":
Expand Down

0 comments on commit a26537d

Please sign in to comment.