From 5d27a6cb4b8c8c1688dc5f7defeb6fe3c4006fae Mon Sep 17 00:00:00 2001 From: SamJakob Date: Wed, 8 Nov 2023 15:04:19 +0000 Subject: [PATCH 1/5] Add Apple Silicon support --- gui/Scyther/Scyther.py | 10 +++++++++- src/BuildMacArm.cmake | 10 ++++++++++ src/BuildMacIntel.cmake | 4 ++-- src/CMakeLists.txt | 5 ++--- src/GetOS.cmake | 10 +++++++--- src/build.sh | 18 ++++++++++++------ src/subbuild-mac-arm.sh | 20 ++++++++++++++++++++ 7 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 src/BuildMacArm.cmake create mode 100644 src/subbuild-mac-arm.sh diff --git a/gui/Scyther/Scyther.py b/gui/Scyther/Scyther.py index 1232f23..4b2f31c 100755 --- a/gui/Scyther/Scyther.py +++ b/gui/Scyther/Scyther.py @@ -30,6 +30,8 @@ import os.path import sys import io import tempfile +import platform + try: import hashlib HASHLIB = True @@ -170,7 +172,13 @@ def getScytherBackend(): elif "darwin" in sys.platform: """ OS X """ - scythername = "scyther-mac" + # Check if there is an ARM version available at scyther-mac-arm + # Otherwise, just fallback to the default scyther-mac which is the + # Intel version for backwards-compatibility reasons. + if platform.processor().startswith("arm"): + scythername = "scyther-mac-arm" + else: + scythername = "scyther-mac" elif sys.platform.startswith('win'): diff --git a/src/BuildMacArm.cmake b/src/BuildMacArm.cmake new file mode 100644 index 0000000..8183577 --- /dev/null +++ b/src/BuildMacArm.cmake @@ -0,0 +1,10 @@ +################################################################ +# Name: BuildMacArm.cmake +# Purpose: Build MacArm binary +# Author: Sam Jakob M. +################################################################ + +message (STATUS "Building Apple Mac ARM (Apple Silicon) version") +set (scythername "scyther-mac") +add_executable (${scythername} ${Scyther_sources}) +set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.15") diff --git a/src/BuildMacIntel.cmake b/src/BuildMacIntel.cmake index 6ad6e16..0272a1e 100644 --- a/src/BuildMacIntel.cmake +++ b/src/BuildMacIntel.cmake @@ -7,5 +7,5 @@ message (STATUS "Building Apple Mac Intel version") set (scythername "scyther-mac") add_executable (${scythername} ${Scyther_sources}) -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.6") - +set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.6 -arch x86_64") +set (CMAKE_OSX_ARCHITECTURES "x86_64") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 72a1df5..0f413db 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,8 +6,7 @@ # Scyther project project (Scyther) -# I need 2.4 for flex/etc although it does not run yet -CMAKE_MINIMUM_REQUIRED(VERSION 2.4) +CMAKE_MINIMUM_REQUIRED(VERSION 2.18) # Try clang #set (CMAKE_C_COMPILER "clang") @@ -17,7 +16,7 @@ set (Scyther_sources arachne.c binding.c claim.c color.c compiler.c cost.c debug.c depend.c dotout.c error.c heuristic.c hidelevel.c intruderknowledge.c knowledge.c label.c list.c main.c mgu.c - prune_bounds.c prune_theorems.c role.c + prune_bounds.c prune_theorems.c role.c specialterm.c states.c switches.c symbol.c system.c tac.c tempfile.c termlist.c termmap.c term.c timer.c type.c warshall.c xmlout.c diff --git a/src/GetOS.cmake b/src/GetOS.cmake index 981ed7a..aabe6f9 100644 --- a/src/GetOS.cmake +++ b/src/GetOS.cmake @@ -18,9 +18,13 @@ if (WIN32) else (WIN32) # Not windows, is it a mac? if (APPLE) - # TODO: A mac, but what architecture? - # For now we assume intel - set (Source_OS "MacIntel") + if(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "arm64" AND NOT DEFINED ENV{ARCH}) + # If Apple and Arm64, set Source_OS to MacArm + set(Source_OS "MacArm") + else(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "arm64" AND NOT DEFINED ENV{ARCH}) + # If not arm64, assume Intel for legacy reasons. + set(Source_OS "MacIntel") + endif(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "arm64" AND NOT DEFINED ENV{ARCH}) else (APPLE) # Not a mac, not windows if (UNIX) diff --git a/src/build.sh b/src/build.sh index 30b8316..dfbabd0 100755 --- a/src/build.sh +++ b/src/build.sh @@ -5,13 +5,19 @@ # Different choice if on Darwin PLATFORM=`uname` -echo $PLATFORM -if [ "$PLATFORM" = "Darwin" ] -then - ./subbuild-mac-intel.sh +echo "Platform: $PLATFORM" + +if [ "$PLATFORM" = "Darwin" ]; then + ARCH=`arch` + echo "Architecture: $ARCH" + + if [ "$ARCH" = "arm64" ]; then + ./subbuild-mac-arm.sh + else + ./subbuild-mac-intel.sh + fi else - if [ "$PLATFORM" = "Linux" ] - then + if [ "$PLATFORM" = "Linux" ]; then # Build linux version ./subbuild-unix-unix.sh else diff --git a/src/subbuild-mac-arm.sh b/src/subbuild-mac-arm.sh new file mode 100644 index 0000000..ceaca01 --- /dev/null +++ b/src/subbuild-mac-arm.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +set -e + +# Default flags +CMFLAGS="-D CMAKE_BUILD_TYPE:STRING=Release" + +# Make for intel +cmake $CMFLAGS -D TARGETOS=MacArm . && make scyther-mac + +echo +echo +echo "---------------------------------------------------------" +echo "Built the Mac ARM binary" + +# Copy to the correct locations +cp scyther-mac ../gui/Scyther/scyther-mac-arm + +echo Copied the files to their respective locations +echo "---------------------------------------------------------" From 8073fed85e951c50f4f13f41b37b7df6e17d726d Mon Sep 17 00:00:00 2001 From: SamJakob Date: Wed, 8 Nov 2023 15:17:34 +0000 Subject: [PATCH 2/5] Check if ARM build exists before using --- gui/Scyther/Scyther.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/Scyther/Scyther.py b/gui/Scyther/Scyther.py index 4b2f31c..56e8cc7 100755 --- a/gui/Scyther/Scyther.py +++ b/gui/Scyther/Scyther.py @@ -175,7 +175,7 @@ def getScytherBackend(): # Check if there is an ARM version available at scyther-mac-arm # Otherwise, just fallback to the default scyther-mac which is the # Intel version for backwards-compatibility reasons. - if platform.processor().startswith("arm"): + if platform.processor().startswith("arm") and os.path.exists(getBinDir(),"scyther-mac-arm"): scythername = "scyther-mac-arm" else: scythername = "scyther-mac" From 149c9d737e913ce9f52fc2389721736302aa28fb Mon Sep 17 00:00:00 2001 From: SamJakob Date: Wed, 8 Nov 2023 15:18:31 +0000 Subject: [PATCH 3/5] Make subbuild-mac-arm executable --- src/subbuild-mac-arm.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 src/subbuild-mac-arm.sh diff --git a/src/subbuild-mac-arm.sh b/src/subbuild-mac-arm.sh old mode 100644 new mode 100755 From cb054f92b83d9189599618d82f0ce48448a251b7 Mon Sep 17 00:00:00 2001 From: SamJakob Date: Wed, 8 Nov 2023 15:28:11 +0000 Subject: [PATCH 4/5] Add Intel-from-ARM cross-compile configuration --- src/BuildMacArm-MacIntel.cmake | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/BuildMacArm-MacIntel.cmake diff --git a/src/BuildMacArm-MacIntel.cmake b/src/BuildMacArm-MacIntel.cmake new file mode 100644 index 0000000..e35725e --- /dev/null +++ b/src/BuildMacArm-MacIntel.cmake @@ -0,0 +1,11 @@ +################################################################ +# Name: BuildMacIntel.cmake +# Purpose: Build MacIntel binary +# Author: Cas Cremers +################################################################ + +message (STATUS "Building Apple Mac Intel version (cross-compiling)") +set (scythername "scyther-mac") +add_executable (${scythername} ${Scyther_sources}) +set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.6 -arch x86_64") +set (CMAKE_OSX_ARCHITECTURES "x86_64") From 5ea557e0a335a5d0d39b1ec171ed34d50e5ca95d Mon Sep 17 00:00:00 2001 From: SamJakob Date: Wed, 8 Nov 2023 17:27:46 +0000 Subject: [PATCH 5/5] Clean up check for ARM build --- gui/Scyther/Scyther.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gui/Scyther/Scyther.py b/gui/Scyther/Scyther.py index 56e8cc7..6203ca7 100755 --- a/gui/Scyther/Scyther.py +++ b/gui/Scyther/Scyther.py @@ -175,7 +175,9 @@ def getScytherBackend(): # Check if there is an ARM version available at scyther-mac-arm # Otherwise, just fallback to the default scyther-mac which is the # Intel version for backwards-compatibility reasons. - if platform.processor().startswith("arm") and os.path.exists(getBinDir(),"scyther-mac-arm"): + has_arm_build = os.path.exists(os.path.join(getBinDir(),"scyther-mac-arm")) + + if platform.processor().startswith("arm") and has_arm_build: scythername = "scyther-mac-arm" else: scythername = "scyther-mac"