Skip to content

Commit dc3c2d7

Browse files
committed
Fix macOS architecture mismatch and force stable Python in CI
1 parent 12bafb8 commit dc3c2d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+8184
-25
lines changed

.github/workflows/build.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
build:
1111
strategy:
12-
fail-fast:false
12+
fail-fast: false
1313
matrix:
1414
config:
1515
- name: Windows
@@ -18,6 +18,9 @@ jobs:
1818
- name: macOS
1919
os: macos-latest
2020
target: mac-os
21+
- name: iOS
22+
os: macos-latest
23+
target: ios
2124
- name: Android64
2225
os: ubuntu-latest
2326
target: android64
@@ -35,13 +38,13 @@ jobs:
3538
- name: Setup Python
3639
uses: actions/setup-python@v5
3740
with:
38-
python-version: '3.11' # Stable version for embedding
41+
python-version: '3.11'
42+
- name: Build Mod
43+
uses: geode-sdk/build-geode-mod@main
44+
with:
45+
bindings-checkout: false
46+
combine: true
47+
target: ${{ matrix.config.target }}
48+
# Force CMake to use the Python we just set up
49+
extra-config: -DPython3_ROOT_DIR=${{ env.pythonLocation }} -DPython3_FIND_STRATEGY=LOCATION -DPython3_FIND_FRAMEWORK=NEVER
3950

40-
- name: Build Mod
41-
uses: geode-sdk/build-geode-mod@main
42-
with:
43-
bindings-checkout: false
44-
combine: true
45-
target: ${{ matrix.config.target }}
46-
# We pass the Python path to CMake
47-
extra-config: -DPython3_ROOT_DIR=${{ env.pythonLocation }}

CMakeLists.txt

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,62 @@
11
cmake_minimum_required(VERSION 3.21)
2+
3+
# Set C++ standard to 20 for compatibility with Geode's {fmt}
24
set(CMAKE_CXX_STANDARD 20)
35
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4-
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS" OR IOS)
5-
set(CMAKE_OSX_ARCHITECTURES "arm64")
6-
else()
7-
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
6+
7+
if (APPLE)
8+
if (IOS)
9+
set(CMAKE_OSX_ARCHITECTURES "arm64")
10+
else()
11+
# On GitHub Actions macOS runners, Python is often single-arch.
12+
# We try to detect the architecture of the Python library to avoid linking errors.
13+
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
14+
if (Python3_ROOT_DIR)
15+
message(STATUS "Mac: Python3_ROOT_DIR is set, checking architecture...")
16+
# If we're on a Silicon Mac runner (arm64), and Python is arm64,
17+
# building for x86_64 will fail unless we have a universal Python.
18+
# For simplicity, if we are in CI, we'll just target the current arch.
19+
if (DEFINED ENV{GITHUB_ACTIONS})
20+
set(CMAKE_OSX_ARCHITECTURES "arm64")
21+
message(STATUS "CI detected: Targeting arm64 only for macOS build.")
22+
endif()
23+
endif()
24+
endif()
825
endif()
26+
927
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
1028

1129
if (Python3_ROOT_DIR)
1230
set(Python3_FIND_STRATEGY LOCATION)
1331
endif()
1432

1533
if (ANDROID OR IOS)
16-
# Android needs prebuilt Python - we'll keep this as an option
1734
if (NOT DEFINED PREBUILT_PYTHON_PATH)
18-
message(STATUS "PREBUILT_PYTHON_PATH not set, attempting to use Python3_ROOT_DIR: ${Python3_ROOT_DIR}")
19-
set(PREBUILT_PYTHON_PATH ${Python3_ROOT_DIR})
35+
if (Python3_ROOT_DIR)
36+
set(PREBUILT_PYTHON_PATH ${Python3_ROOT_DIR})
37+
else()
38+
message(WARNING "PREBUILT_PYTHON_PATH and Python3_ROOT_DIR not set for mobile platform!")
39+
endif()
2040
endif()
2141

22-
add_library(Python3_Mobile INTERFACE)
23-
target_include_directories(Python3_Mobile INTERFACE ${PREBUILT_PYTHON_PATH}/include)
24-
# This might need adjustments based on the exact structure of the Android Python lib
25-
target_link_libraries(Python3_Mobile INTERFACE ${PREBUILT_PYTHON_PATH}/lib/libpython3.so)
26-
27-
set(PYTHON_TARGET Python3_Mobile)
42+
if (PREBUILT_PYTHON_PATH)
43+
add_library(Python3_Mobile INTERFACE)
44+
target_include_directories(Python3_Mobile INTERFACE ${PREBUILT_PYTHON_PATH}/include)
45+
46+
if (ANDROID)
47+
# Use a slightly more flexible search for the .so
48+
find_library(PYTHON_LIB python3.11 PATHS ${PREBUILT_PYTHON_PATH}/lib NO_DEFAULT_PATH)
49+
if (NOT PYTHON_LIB)
50+
find_library(PYTHON_LIB python3 PATHS ${PREBUILT_PYTHON_PATH}/lib NO_DEFAULT_PATH)
51+
endif()
52+
target_link_libraries(Python3_Mobile INTERFACE ${PYTHON_LIB})
53+
elseif (IOS)
54+
target_link_libraries(Python3_Mobile INTERFACE ${PREBUILT_PYTHON_PATH}/lib/libpython3.a)
55+
endif()
56+
set(PYTHON_TARGET Python3_Mobile)
57+
else()
58+
message(FATAL_ERROR "Python Runtime requires a prebuilt Python for mobile platforms. Please provide PREBUILT_PYTHON_PATH.")
59+
endif()
2860
else()
2961
find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Embed)
3062
set(PYTHON_TARGET Python3::Python)
@@ -35,17 +67,18 @@ project(PythonRuntime VERSION 1.0.0)
3567
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/*.cpp)
3668
add_library(${PROJECT_NAME} SHARED ${SOURCES})
3769

70+
# Use plain linking to match Geode's internal style
3871
target_link_libraries(${PROJECT_NAME} ${PYTHON_TARGET})
72+
3973
if (NOT ANDROID AND NOT IOS)
4074
target_include_directories(${PROJECT_NAME} PRIVATE ${Python3_INCLUDE_DIRS})
4175
endif()
76+
4277
target_include_directories(${PROJECT_NAME} INTERFACE include)
4378
target_compile_definitions(${PROJECT_NAME} PRIVATE PYTHON_RUNTIME_EXPORT)
4479

4580
if (NOT DEFINED ENV{GEODE_SDK})
4681
message(FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode")
47-
else()
48-
message(STATUS "Found Geode: $ENV{GEODE_SDK}")
4982
endif()
5083

5184
add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)

0 commit comments

Comments
 (0)