@@ -54,11 +54,20 @@ def detect_arch():
54
54
else :
55
55
raise ValueError (f"Unsupported CPU architecture: { machine } " )
56
56
57
- def get_platform_identifier ():
58
- """Get the full platform identifier (arch-os) for the current system,
59
- matching the identifiers used by the Github publisher.
57
+ def get_platform_identifier (target_arch = None ):
58
+ """Get the full platform identifier (arch-os) for the current system or target.
59
+
60
+ Args:
61
+ target_arch: Optional target architecture.
62
+ If provided, overrides auto-detection.
63
+ For macOS: 'universal2', 'arm64', or 'x86_64'
64
+ For Linux: 'aarch64' or 'x86_64'
65
+ For Windows: 'arm64' or 'x64'
66
+
60
67
Returns one of:
61
- - universal-apple-darwin (for Mac)
68
+ - universal-apple-darwin (for macOS universal)
69
+ - aarch64-apple-darwin (for macOS ARM64)
70
+ - x86_64-apple-darwin (for macOS x86_64)
62
71
- x86_64-pc-windows-msvc (for Windows 64-bit)
63
72
- x86_64-unknown-linux-gnu (for Linux x86_64)
64
73
- aarch64-unknown-linux-gnu (for Linux ARM64)
@@ -67,11 +76,27 @@ def get_platform_identifier():
67
76
machine = platform .machine ().lower ()
68
77
69
78
if system == "darwin" :
70
- return "universal-apple-darwin"
79
+ if target_arch == "arm64" :
80
+ return "aarch64-apple-darwin"
81
+ elif target_arch == "x86_64" :
82
+ return "x86_64-apple-darwin"
83
+ elif target_arch == "universal2" :
84
+ return "universal-apple-darwin"
85
+ else :
86
+ # Auto-detect: prefer specific architecture over universal
87
+ if machine == "arm64" :
88
+ return "aarch64-apple-darwin"
89
+ elif machine == "x86_64" :
90
+ return "x86_64-apple-darwin"
91
+ else :
92
+ return "universal-apple-darwin"
71
93
elif system == "windows" :
72
- return "x86_64-pc-windows-msvc"
94
+ if target_arch == "arm64" :
95
+ return "aarch64-pc-windows-msvc"
96
+ else :
97
+ return "x86_64-pc-windows-msvc"
73
98
elif system == "linux" :
74
- if machine in ["arm64" , "aarch64" ]:
99
+ if target_arch == "aarch64" or machine in ["arm64" , "aarch64" ]:
75
100
return "aarch64-unknown-linux-gnu"
76
101
else :
77
102
return "x86_64-unknown-linux-gnu"
@@ -101,19 +126,20 @@ def download_and_extract_libs(url, platform_name):
101
126
response = requests .get (url , headers = headers )
102
127
response .raise_for_status ()
103
128
129
+ print (f"Downloaded zip file, extracting lib files..." )
104
130
with zipfile .ZipFile (io .BytesIO (response .content )) as zip_ref :
105
131
# Extract only files inside the libs/ directory
132
+ extracted_count = 0
106
133
for member in zip_ref .namelist ():
107
- print (f" Processing zip member: { member } " )
108
134
if member .startswith ("lib/" ) and not member .endswith ("/" ):
109
- print (f" Processing lib file from downloadedzip: { member } " )
110
135
target_path = platform_dir / os .path .relpath (member , "lib" )
111
- print (f" Moving file to target path: { target_path } " )
112
136
target_path .parent .mkdir (parents = True , exist_ok = True )
113
137
with zip_ref .open (member ) as source , open (target_path , "wb" ) as target :
114
138
target .write (source .read ())
139
+ extracted_count += 1
140
+ print (f" Extracted: { member } -> { target_path } " )
115
141
116
- print (f"Done downloading and extracting libraries for { platform_name } " )
142
+ print (f"Done downloading and extracting { extracted_count } library files for { platform_name } " )
117
143
118
144
def copy_artifacts_to_root ():
119
145
"""Copy the artifacts folder from scripts/artifacts to the root of the repository."""
@@ -122,56 +148,77 @@ def copy_artifacts_to_root():
122
148
return
123
149
124
150
print ("Copying artifacts from scripts/artifacts to root..." )
151
+ print ("Contents of scripts/artifacts before copying:" )
152
+ for item in sorted (SCRIPTS_ARTIFACTS_DIR .iterdir ()):
153
+ print (f" { item .name } " )
154
+
125
155
if ROOT_ARTIFACTS_DIR .exists ():
126
156
shutil .rmtree (ROOT_ARTIFACTS_DIR )
127
157
print (f"Copying from { SCRIPTS_ARTIFACTS_DIR } to { ROOT_ARTIFACTS_DIR } " )
128
158
shutil .copytree (SCRIPTS_ARTIFACTS_DIR , ROOT_ARTIFACTS_DIR )
129
159
print ("Done copying artifacts" )
130
- print ("\n Folder content of artifacts directory:" )
160
+ print ("\n Folder content of root artifacts directory:" )
131
161
for item in sorted (ROOT_ARTIFACTS_DIR .iterdir ()):
132
162
print (f" { item .name } " )
133
163
134
164
def main ():
135
165
if len (sys .argv ) < 2 :
136
- print ("Usage: python download_artifacts.py <release_tag>" )
166
+ print ("Usage: python download_artifacts.py <release_tag> [target_architecture] " )
137
167
print ("Example: python download_artifacts.py c2pa-v0.49.5" )
168
+ print ("Example: python download_artifacts.py c2pa-v0.49.5 arm64" )
138
169
sys .exit (1 )
139
170
140
171
release_tag = sys .argv [1 ]
172
+ target_arch = sys .argv [2 ] if len (sys .argv ) > 2 else None
173
+
141
174
try :
175
+ # Clean up any existing artifacts before starting
176
+ print ("Cleaning up existing artifacts..." )
177
+ if SCRIPTS_ARTIFACTS_DIR .exists ():
178
+ shutil .rmtree (SCRIPTS_ARTIFACTS_DIR )
142
179
SCRIPTS_ARTIFACTS_DIR .mkdir (exist_ok = True )
143
180
print (f"Fetching release information for tag { release_tag } ..." )
144
181
release = get_release_by_tag (release_tag )
145
182
print (f"Found release: { release ['tag_name' ]} \n " )
146
183
147
- # Get the platform identifier for the current system
184
+ # Get the platform identifier for the target architecture
148
185
env_platform = os .environ .get ("C2PA_LIBS_PLATFORM" )
149
186
if env_platform :
150
187
print (f"Using platform from environment variable C2PA_LIBS_PLATFORM: { env_platform } " )
151
- platform_id = env_platform or get_platform_identifier ()
188
+ platform_id = env_platform
189
+ else :
190
+ platform_id = get_platform_identifier (target_arch )
191
+ print (f"Using target architecture: { target_arch or 'auto-detected' } " )
192
+ print (f"Detected machine architecture: { platform .machine ()} " )
193
+ print (f"Detected system: { platform .system ()} " )
194
+
152
195
print ("Looking up releases for platform id: " , platform_id )
153
- print ("Environment variable set for lookup: " , env_platform )
154
- platform_source = "environment variable" if env_platform else "auto-detection"
155
- print (f"Target platform: { platform_id } (set through{ platform_source } )" )
196
+ platform_source = "environment variable" if env_platform else "target architecture" if target_arch else "auto-detection"
197
+ print (f"Target platform: { platform_id } (set through { platform_source } )" )
156
198
157
199
# Construct the expected asset name
158
200
expected_asset_name = f"{ release_tag } -{ platform_id } .zip"
159
201
print (f"Looking for asset: { expected_asset_name } " )
160
202
161
203
# Find the matching asset in the release
162
204
matching_asset = None
205
+ print (f"Looking for asset: { expected_asset_name } " )
206
+ print ("Available assets in release:" )
163
207
for asset in release ['assets' ]:
208
+ print (f" - { asset ['name' ]} " )
164
209
if asset ['name' ] == expected_asset_name :
165
210
matching_asset = asset
166
- break
211
+ print ( f"Using native library: { matching_asset [ 'name' ] } " )
167
212
168
213
if matching_asset :
169
- print (f"Found matching asset: { matching_asset ['name' ]} " )
214
+ print (f"\n Downloading asset: { matching_asset ['name' ]} " )
170
215
download_and_extract_libs (matching_asset ['browser_download_url' ], platform_id )
171
216
print ("\n Artifacts have been downloaded and extracted successfully!" )
172
217
copy_artifacts_to_root ()
173
218
else :
174
- print (f"\n No matching asset found: { expected_asset_name } " )
219
+ print (f"\n No matching asset found for platform: { platform_id } " )
220
+ print (f"Expected asset name: { expected_asset_name } " )
221
+ print ("Please check if the asset exists in the release or if the platform identifier is correct." )
175
222
176
223
except requests .exceptions .RequestException as e :
177
224
print (f"Error: { e } " )
0 commit comments