Skip to content

Commit

Permalink
Create separate x86_64 and ARM64 macOS targets. (#3760)
Browse files Browse the repository at this point in the history
Create explicit x86_64 and ARM64 macOS build targets, so it's clear that
the CI is building x86_64 binaries (on both Intel and ARM64 build
machines). Also, use the `CMAKE_APPLE_SILICON_PROCESSOR` CMake variable
(which sets `CMAKE_SYSTEM_PROCESSOR`) so `BUILD_X86_ON_MACOS` is not
necessary.

And update the README.
  • Loading branch information
mrpippy authored Nov 17, 2024
1 parent 24ad551 commit 8f445bd
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-matrix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ jobs:
name: "🍎 MacOS"
uses: ./.github/workflows/macos-build.yaml
with:
cmakePreset: "Release-macos-clang"
cmakePreset: "Release-macos-x86_64-clang"
cachePrefix: ""

build_macos_arm:
name: "🍎 MacOS"
uses: ./.github/workflows/macos-build-arm.yaml
with:
cmakePreset: "Release-macos-rosetta-clang"
cmakePreset: "Release-macos-x86_64-clang"
cachePrefix: ""
4 changes: 2 additions & 2 deletions .github/workflows/release-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
name: "🍎 MacOS"
uses: ./.github/workflows/macos-build.yaml
with:
cmakePreset: "Release-macos-clang-static"
cmakePreset: "Release-macos-x86_64-clang-static"
cachePrefix: "static"
uploadArtifacts: true
secrets: inherit
Expand All @@ -85,7 +85,7 @@ jobs:
name: "🍎 MacOS"
uses: ./.github/workflows/macos-build.yaml
with:
cmakePreset: "Release-macos-rosetta-clang-static"
cmakePreset: "Release-macos-x86_64-clang-static"
cachePrefix: "static"
uploadArtifacts: true
secrets: inherit
Expand Down
9 changes: 1 addition & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(jak)
include(CTest)

# Options
option(BUILD_X86_ON_MACOS "Builds the project for macOS for Rosetta 2" OFF)

# Include third-party modules
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/third-party/cmake/modules/)

Expand Down Expand Up @@ -127,11 +124,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")

# pin to AVX for macOS, hopefully all macOS runners have atleast this architecture
# technically speaking, SSE4 is the cutoff for Apple Silicon so...only a matter of time!
if (BUILD_X86_ON_MACOS)
message("Targetting x86 on macOS via Rosetta 2 (requires Sequoia)")
set(CMAKE_OSX_ARCHITECTURES "x86_64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
elseif(NOT CMAKE_CXX_COMPILER_TARGET STREQUAL "arm64-apple-darwin")
if(NOT CMAKE_CXX_COMPILER_TARGET STREQUAL "arm64-apple-darwin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
endif()

Expand Down
52 changes: 32 additions & 20 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@
"CMAKE_INSTALL_PREFIX": "${sourceDir}/build/install/${presetName}"
}
},
{
"name": "base-macos-arm64",
"hidden": true,
"cacheVariables": {
"CMAKE_APPLE_SILICON_PROCESSOR": "arm64",
"CMAKE_OSX_ARCHITECTURES": "arm64"
}
},
{
"name": "base-macos-x86_64",
"hidden": true,
"cacheVariables": {
"CMAKE_APPLE_SILICON_PROCESSOR": "x86_64",
"CMAKE_OSX_ARCHITECTURES": "x86_64"
}
},
{
"name": "base-clang",
"hidden": true,
Expand Down Expand Up @@ -159,37 +175,33 @@
"inherits": ["base-linux-release", "base-clang"]
},
{
"name": "Release-macos-clang",
"displayName": "MacOS Release (clang)",
"description": "Build with Clang as Release without Debug Symbols",
"inherits": ["base-macos-release", "base-clang"]
"name": "Release-macos-arm64-clang",
"displayName": "MacOS ARM64 Release (clang)",
"description": "Build for ARM64 with Clang as Release without Debug Symbols",
"inherits": ["base-macos-release", "base-macos-arm64", "base-clang"]
},
{
"name": "Release-macos-rosetta-clang",
"displayName": "MacOS Release Rosetta (clang)",
"description": "Build with Clang as Release without Debug Symbols",
"inherits": ["base-macos-release", "base-clang"],
"cacheVariables": {
"BUILD_X86_ON_MACOS": "ON"
}
"name": "Release-macos-x86_64-clang",
"displayName": "MacOS x86_64 Release (clang)",
"description": "Build for x86_64 with Clang as Release without Debug Symbols",
"inherits": ["base-macos-release", "base-macos-x86_64", "base-clang"]
},
{
"name": "Release-macos-clang-static",
"displayName": "MacOS Static Release (clang)",
"description": "Build with Clang as Release without Debug Symbols but statically linked",
"inherits": ["base-macos-release", "base-clang"],
"name": "Release-macos-arm64-clang-static",
"displayName": "MacOS ARM64 Static Release (clang)",
"description": "Build for ARM64 with Clang as Release without Debug Symbols but statically linked",
"inherits": ["base-macos-release", "base-macos-arm64", "base-clang"],
"cacheVariables": {
"STATICALLY_LINK": "true",
"ZYDIS_BUILD_SHARED_LIB": "OFF"
}
},
{
"name": "Release-macos-rosetta-clang-static",
"displayName": "MacOS Rosetta Static Release (clang)",
"description": "Build with Clang as Release without Debug Symbols but statically linked, requires MacOS Sequoia",
"inherits": ["base-macos-release", "base-clang"],
"name": "Release-macos-x86_64-clang-static",
"displayName": "MacOS x86_64 Static Release (clang)",
"description": "Build for x86_64 with Clang as Release without Debug Symbols but statically linked, requires MacOS Sequoia",
"inherits": ["base-macos-release", "base-macos-x86_64", "base-clang"],
"cacheVariables": {
"BUILD_X86_ON_MACOS": "ON",
"STATICALLY_LINK": "true",
"ZYDIS_BUILD_SHARED_LIB": "OFF"
}
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Our objectives are:

We support both Linux and Windows on x86-64.

> We do not support, or plan to support the ARM architecture. This means that this will not run on devices such as an M1 Mac or a mobile device.
> We do not support, or plan to support the ARM architecture. This means that this will not run on devices such as a mobile device.
### Current Status

Expand Down Expand Up @@ -235,29 +235,33 @@ Then build the entire project as `Windows Release (clang)`. You can also press C

### MacOS

> NOTE: At this time you can only run the game on macOS if you have an Intel processor.
> NOTE: Running the game requires an Apple Silicon Mac running macOS Sequoia, or an Intel Mac.
Ensure that you have Xcode command line tools installed (this installs things like Apple Clang). If you don't, you can run the following command:

```bash
xcode-select --install
```

#### Intel Based
On Apple Silicon, Rosetta 2 also must be installed:

```bash
softwareupdate --install-rosetta
```

#### Building for x86_64

```bash
brew install cmake nasm ninja go-task clang-format
cmake -B build --preset=Release-macos-clang
cmake -B build --preset=Release-macos-x86_64-clang
cmake --build build --parallel $((`sysctl -n hw.logicalcpu`))
```

#### Apple Silicon

**Not Supported at This Time**
#### Building for ARM64 (experimental, unsupported)

```bash
brew install cmake ninja go-task clang-format
cmake -B build --preset=Release-macos-clang
cmake -B build --preset=Release-macos-arm64-clang
cmake --build build --parallel $((`sysctl -n hw.logicalcpu`))
```

Expand Down
5 changes: 1 addition & 4 deletions game/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Set a more convenient ARM flag
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64" AND (NOT BUILD_X86_ON_MACOS))
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
set(ARM64_ARCH TRUE)
message(STATUS "ARM64 architecture detected")
elseif()
set(ARM64_ARCH FALSE)
message(STATUS "Forcefully targetting x86 via Rosetta 2")
else()
set(ARM64_ARCH FALSE)
message(STATUS "Non-ARM64 architecture detected")
Expand Down

0 comments on commit 8f445bd

Please sign in to comment.