Skip to content

Commit 28f28ee

Browse files
authored
Apple ARM support (#651)
## Changes * Compiles the Mac library for both arm64 and x86_64 to enable Apple Silicon support. ## Comments - [x] Works on x86_64 - [x] Works on ARM ## Tests To check an architecture and mark the checkbox, evaluate: ```wl PacletUninstall["SetReplace"]; Quit; PacletInstall["path_to_built_paclet_in_CI"]; << SetReplace`; WolframModel[{{1, 2}} -> {{1, 3}, {1, 3}, {3, 2}}, {{1, 1}}, 4, "FinalStatePlot", Method -> "LowLevel"] ```
1 parent b3b6d33 commit 28f28ee

3 files changed

Lines changed: 47 additions & 26 deletions

File tree

.circleci/config.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,18 @@ jobs:
171171
cp -r $cmakeDir/CMake.app/Contents/share/* /usr/local/share/
172172
173173
- run:
174-
name: Build
175-
command: scripts/buildLibraryResources.sh
174+
name: Build arm64
175+
command: scripts/buildLibraryResources.sh arm64
176+
177+
- run:
178+
name: Build x86_64
179+
command: scripts/buildLibraryResources.sh x86_64
176180

177181
- persist_to_workspace:
178182
root: LibraryResources
179183
paths:
180184
- MacOSX-x86-64
185+
- MacOSX-ARM64
181186

182187
- store_artifacts:
183188
path: ./LibraryResources/

PacletInfo.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Description -> "SetReplace implements WolframModel and other functions used in the Wolfram Physics Project.",
88
Creator -> "Wolfram Research",
99
URL -> "https://github.com/maxitg/SetReplace",
10-
SystemID -> {"MacOSX-x86-64", "Linux-x86-64", "Windows-x86-64"},
10+
SystemID -> {"MacOSX-x86-64", "Linux-x86-64", "Windows-x86-64", "MacOSX-ARM64"},
1111
Extensions -> {
1212
{"Kernel", Context -> "SetReplace`"},
1313
{"LibraryLink"}

scripts/buildLibraryResources.sh

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,39 @@ set -eo pipefail
44
setReplaceRoot=$(dirname "$(cd "$(dirname "$0")" && pwd)")
55
cd "$setReplaceRoot"
66

7+
# Obtain requested architectures
8+
9+
if [[ -n "$1" ]]; then
10+
arch="$1"
11+
else
12+
arch="$(uname -m)"
13+
fi
14+
15+
# Set the platform-specific names
16+
17+
if [[ "$(uname -s)" == "Darwin" && "$arch" == "arm64" ]]; then
18+
cmakeArchitectureArg="-DCMAKE_OSX_ARCHITECTURES=arm64"
19+
libraryResourcesDirName=MacOSX-ARM64
20+
libraryExtension=dylib
21+
elif [[ "$(uname -s)" == "Darwin" && "$arch" == "x86_64" ]]; then
22+
cmakeArchitectureArg="-DCMAKE_OSX_ARCHITECTURES=x86_64"
23+
libraryResourcesDirName=MacOSX-x86-64
24+
libraryExtension=dylib
25+
elif [[ "$(uname -s)" == "Linux" && "$arch" == "x86_64" ]]; then
26+
libraryResourcesDirName=Linux-x86-64
27+
libraryExtension=so
28+
elif [[ "$OSTYPE" == "msys" && "$(uname -m)" == "x86_64" ]]; then # Windows
29+
libraryResourcesDirName=Windows-x86-64
30+
libraryExtension=dll
31+
else
32+
echo "Operating system unsupported"
33+
exit 1
34+
fi
35+
36+
libraryDir=LibraryResources/$libraryResourcesDirName
37+
echo "LibraryResources directory: $setReplaceRoot/$libraryDir"
38+
echo "Library extension: $libraryExtension"
39+
740
# Compute the source hash
841

942
sourceFiles="$(ls libSetReplace/*pp CMakeLists.txt cmake/* scripts/buildLibraryResources.sh)"
@@ -15,7 +48,8 @@ if command -v shasum &>/dev/null; then
1548
for fileToHash in $sourceFiles; do
1649
shasum -a 256 "$fileToHash"
1750
done
18-
uname -sm
51+
uname -s
52+
echo "$arch"
1953
)" | shasum -a 256 | cut -d\ -f1
2054
)"
2155
elif [[ "$OSTYPE" == "msys" && $(command -v certutil) ]]; then # there is another certutil in macOS
@@ -24,7 +58,8 @@ elif [[ "$OSTYPE" == "msys" && $(command -v certutil) ]]; then # there is anothe
2458
for fileToHash in $sourceFiles; do
2559
echo "$(certutil -hashfile "$fileToHash" SHA256 | findstr -v "hash")" "$fileToHash"
2660
done
27-
uname -sm
61+
uname -s
62+
echo "$arch"
2863
)" >"$TEMP"/libSetReplaceFilesToHash
2964
sha=$(certutil -hashfile "$TEMP"/libSetReplaceFilesToHash SHA256 | findstr -v "hash")
3065
else
@@ -39,30 +74,11 @@ echo "libSetReplace sources hash: $shortSHA"
3974

4075
mkdir -p build
4176
cd build
42-
cmake .. -DSET_REPLACE_ENABLE_ALLWARNINGS=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release
77+
cmake .. -DSET_REPLACE_ENABLE_ALLWARNINGS=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release \
78+
${cmakeArchitectureArg:+"$cmakeArchitectureArg"}
4379
cmake --build . --config Release # Needed for multi-config generators
4480
cd ..
4581

46-
# Set the platform-specific names
47-
48-
if [ "$(uname -sm)" = "Darwin x86_64" ]; then
49-
libraryResourcesDirName=MacOSX-x86-64
50-
libraryExtension=dylib
51-
elif [ "$(uname -sm)" = "Linux x86_64" ]; then
52-
libraryResourcesDirName=Linux-x86-64
53-
libraryExtension=so
54-
elif [[ "$OSTYPE" == "msys" && "$(uname -m)" == "x86_64" ]]; then # Windows
55-
libraryResourcesDirName=Windows-x86-64
56-
libraryExtension=dll
57-
else
58-
echo "Operating system unsupported"
59-
exit 1
60-
fi
61-
62-
libraryDir=LibraryResources/$libraryResourcesDirName
63-
echo "LibraryResources directory: $setReplaceRoot/$libraryDir"
64-
echo "Library extension: $libraryExtension"
65-
6682
# Find the compiled library
6783

6884
compiledLibrary=build/libSetReplace.$libraryExtension

0 commit comments

Comments
 (0)