Skip to content

Commit 160e54e

Browse files
committed
fix: Platform detection
1 parent 4671f08 commit 160e54e

File tree

3 files changed

+61
-29
lines changed

3 files changed

+61
-29
lines changed

.github/workflows/build-wheel.yml

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,27 +138,39 @@ jobs:
138138
# Download native artifacts
139139
python scripts/download_artifacts.py $C2PA_VERSION
140140
141-
# Set platform name based on architecture
141+
# Detect actual CPU architecture at runtime
142+
echo "Detecting CPU architecture..."
142143
if [ "${{ inputs.architecture }}" = "universal2" ]; then
143144
PLATFORM_NAME="macosx_10_9_universal2"
144-
elif [ "${{ inputs.architecture }}" = "aarch64" ]; then
145-
PLATFORM_NAME="macosx_11_0_arm64"
146-
elif [ "${{ inputs.architecture }}" = "x86_64" ]; then
147-
PLATFORM_NAME="macosx_10_9_x86_64"
148145
else
149-
echo "Unknown architecture: ${{ inputs.architecture }}"
150-
exit 1
146+
# Detect the actual CPU architecture of the runner
147+
ACTUAL_ARCH=$(uname -m)
148+
echo "Detected CPU architecture: $ACTUAL_ARCH"
149+
150+
if [ "$ACTUAL_ARCH" = "arm64" ] || [ "$ACTUAL_ARCH" = "aarch64" ]; then
151+
PLATFORM_NAME="macosx_11_0_arm64"
152+
EXPECTED_ARTIFACT_DIR="aarch64-apple-darwin"
153+
elif [ "$ACTUAL_ARCH" = "x86_64" ]; then
154+
PLATFORM_NAME="macosx_10_9_x86_64"
155+
EXPECTED_ARTIFACT_DIR="x86_64-apple-darwin"
156+
else
157+
echo "Unknown CPU architecture: $ACTUAL_ARCH"
158+
exit 1
159+
fi
160+
161+
# Verify we have the correct artifacts for this architecture
162+
if [ ! -d "artifacts/$EXPECTED_ARTIFACT_DIR" ]; then
163+
echo "Error: $EXPECTED_ARTIFACT_DIR artifacts not found for $ACTUAL_ARCH"
164+
echo "Available artifacts:"
165+
ls -la artifacts/
166+
exit 1
167+
fi
151168
fi
152169
153-
# Build wheel
154-
python setup.py bdist_wheel --plat-name $PLATFORM_NAME
170+
echo "Building wheel with platform name: $PLATFORM_NAME"
155171
156-
# Rename wheel to ensure unique filename
157-
cd dist
158-
for wheel in *.whl; do
159-
mv "$wheel" "${wheel/$PLATFORM_NAME/$PLATFORM_NAME}"
160-
done
161-
cd ..
172+
# Build wheel with specific platform
173+
python setup.py bdist_wheel --plat-name $PLATFORM_NAME
162174
163175
# Verify wheel structure
164176
echo "Verifying wheels using twine check"

scripts/download_artifacts.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,25 @@ def detect_os():
3030

3131
def detect_arch():
3232
"""Detect the CPU architecture and return the corresponding identifier."""
33-
machine = platform.machine().lower()
3433

35-
# Handle common architecture names
36-
if machine in ["x86_64", "amd64"]:
37-
return "x86_64"
38-
elif machine in ["arm64", "aarch64"]:
39-
return "aarch64"
34+
if sys.platform == "darwin":
35+
# On macOS, we need to check if we're running under Rosetta
36+
# platform.processor() gives us the actual CPU, not the emulated one
37+
if platform.processor() == 'arm':
38+
return "aarch64"
39+
else:
40+
return "x86_64"
4041
else:
41-
raise ValueError(f"Unsupported CPU architecture: {machine}")
42+
# For other platforms, use platform.machine()
43+
machine = platform.machine().lower()
44+
45+
# Handle common architecture names
46+
if machine in ["x86_64", "amd64"]:
47+
return "x86_64"
48+
elif machine in ["arm64", "aarch64"]:
49+
return "aarch64"
50+
else:
51+
raise ValueError(f"Unsupported CPU architecture: {machine}")
4252

4353
def get_platform_identifier():
4454
"""Get the full platform identifier (arch-os) for the current system,

setup.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,25 @@ def get_version():
3737

3838
def detect_arch():
3939
"""Detect the CPU architecture and return the corresponding identifier."""
40-
machine = platform.machine().lower()
4140

42-
# Handle common architecture names
43-
if machine in ["x86_64", "amd64"]:
44-
return "x86_64"
45-
elif machine in ["arm64", "aarch64"]:
46-
return "aarch64"
41+
if sys.platform == "darwin":
42+
# On macOS, we need to check if we're running under Rosetta
43+
# platform.processor() gives us the actual CPU, not the emulated one
44+
if platform.processor() == 'arm':
45+
return "aarch64"
46+
else:
47+
return "x86_64"
4748
else:
48-
raise ValueError(f"Unsupported CPU architecture: {machine}")
49+
# For other platforms, use platform.machine()
50+
machine = platform.machine().lower()
51+
52+
# Handle common architecture names
53+
if machine in ["x86_64", "amd64"]:
54+
return "x86_64"
55+
elif machine in ["arm64", "aarch64"]:
56+
return "aarch64"
57+
else:
58+
raise ValueError(f"Unsupported CPU architecture: {machine}")
4959

5060

5161
def get_platform_identifier() -> str:

0 commit comments

Comments
 (0)