From ac076234de75b70137d6fbb2e008b4449b775774 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?T=C3=BAlio=20Toffolo?= <tulio@toffolo.com.br>
Date: Tue, 16 Jan 2024 19:50:50 -0800
Subject: [PATCH 1/2] Add support to Mac M1/M2/M3

Update following suggestion by @suzhenyu22
---
 mip/cbc.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mip/cbc.py b/mip/cbc.py
index 13824650..9723493f 100644
--- a/mip/cbc.py
+++ b/mip/cbc.py
@@ -4,6 +4,7 @@
 from typing import Dict, List, Tuple, Optional, Union
 from sys import platform, maxsize
 from os.path import dirname, isfile, exists
+from platform import machine as platform_machine
 import os
 import multiprocessing as multip
 import numbers
@@ -97,7 +98,9 @@
         elif platform.lower().startswith("darwin") or platform.lower().startswith(
             "macos"
         ):
-            if os_is_64_bit:
+            if platform_machine().lower().startswith("arm64"):
+                libfile = os.path.join(pathlib, "cbc-c-darwin-arm64.dylib")
+            elif os_is_64_bit:
                 libfile = os.path.join(pathlib, "cbc-c-darwin-x86-64.dylib")
         if not libfile:
             raise NotImplementedError("You operating system/platform is not supported")

From 759068775676cad3faca7450530b29452fb111fc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?T=C3=BAlio=20Toffolo?= <tulio@toffolo.com.br>
Date: Tue, 16 Jan 2024 21:59:54 -0800
Subject: [PATCH 2/2] Add MacOS ARM binary for CBC and script used to compile
 it

---
 mip/libraries/cbc-c-darwin-arm64.dylib | Bin 0 -> 6052168 bytes
 scripts/buildCBCMacARM.sh              |  85 +++++++++++++++++++++++++
 2 files changed, 85 insertions(+)
 create mode 100755 mip/libraries/cbc-c-darwin-arm64.dylib
 create mode 100644 scripts/buildCBCMacARM.sh

diff --git a/mip/libraries/cbc-c-darwin-arm64.dylib b/mip/libraries/cbc-c-darwin-arm64.dylib
new file mode 100755
index 0000000000000000000000000000000000000000..5f0c191fd55d0158917b2bc0039b4708e99778a7
GIT binary patch
diff --git a/scripts/buildCBCMacARM.sh b/scripts/buildCBCMacARM.sh
new file mode 100644
index 00000000..a24aa17c
--- /dev/null
+++ b/scripts/buildCBCMacARM.sh
@@ -0,0 +1,85 @@
+export MACOSX_DEPLOYMENT_TARGET="10.9"
+export CFLAGS="-fPIC -Ofast -DNDEBUG -ffast-math -mmacosx-version-min=10.9"
+export CXXFLAGS="-fPIC -Og -DNDEBUG -ffast-math -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.9"
+export F77FLAGS="-fPIC -Ofast -DNDEBUG -ffast-math"
+export LDFLAGS="-fPIC -Ofast -DNDEBUG -ffast-math"
+
+DIR=`pwd`
+OUTDIR="/opt/cbc/bin"
+export PKG_CONFIG_PATH="${OUTDIR}/lib/pkgconfig/:${PKG_CONFIG_PATH}"
+
+echo
+echo "Making and installing Glpk"
+cd ${DIR}/ThirdParty-Glpk
+./configure --prefix=${OUTDIR}/ --enable-static --disable-shared
+git pull
+make
+make install
+
+echo
+echo "Making and installing Lapack"
+cd ${DIR}/ThirdParty-Lapack
+./configure --prefix=${OUTDIR}/ --enable-static --disable-shared
+git pull
+make
+make install
+
+echo
+echo "Making and installing Blas"
+cd ${DIR}/ThirdParty-Blas
+./configure --prefix=${OUTDIR}/ --enable-static --disable-shared
+git pull
+make
+make install
+
+echo
+echo "Making and installing CoinUtils"
+cd ${DIR}/CoinUtils
+./configure --prefix=${OUTDIR}/ --enable-static --disable-shared
+git pull
+make
+make install
+
+echo
+echo "Making and installing Osi"
+cd ${DIR}/Osi
+./configure --prefix=${OUTDIR}/ --enable-static --disable-shared
+git pull
+make
+make install
+
+echo
+echo "Making and installing Clp"
+cd ${DIR}/Clp
+./configure --prefix=${OUTDIR}/ --enable-static --disable-shared
+git pull
+make
+make install
+
+echo
+echo "Making and installing Cgl"
+cd ${DIR}/Cgl
+./configure --prefix=${OUTDIR}/ --enable-static --disable-shared
+git pull
+make
+make install
+
+echo
+echo "Making and installing Cbc"
+cd ${DIR}/Cbc
+./configure --prefix=${OUTDIR}/ --enable-cbc-parallel --enable-static --disable-shared
+git pull
+make
+make install
+
+echo
+echo "Compiling dynamic library"
+cd ${DIR}
+clang++ -shared -Ofast -fPIC -o cbc-c-darwin-arm64.dylib \
+        -I${OUTDIR}/include/coin-or/ -I${OUTDIR}/include/coin-or/glpk -I${OUTDIR}/include/coin \
+        -L${OUTDIR}/lib \
+        ./Cbc/src/Cbc_C_Interface.cpp \
+        -lCbc -lCgl -lClp -lCoinUtils -lOsi -lOsiCbc -lOsiClp -lOsiGlpk \
+        -lcoinblas -lcoinglpk -lcoinlapack \
+        -lbz2 -lz -llapack ${CXXFLAGS} -stdlib=libc++ -lreadline
+echo "Done!"
