@@ -54,11 +54,20 @@ def detect_arch():
5454 else :
5555 raise ValueError (f"Unsupported CPU architecture: { machine } " )
5656
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+
6067 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)
6271 - x86_64-pc-windows-msvc (for Windows 64-bit)
6372 - x86_64-unknown-linux-gnu (for Linux x86_64)
6473 - aarch64-unknown-linux-gnu (for Linux ARM64)
@@ -67,11 +76,27 @@ def get_platform_identifier():
6776 machine = platform .machine ().lower ()
6877
6978 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"
7193 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"
7398 elif system == "linux" :
74- if machine in ["arm64" , "aarch64" ]:
99+ if target_arch == "aarch64" or machine in ["arm64" , "aarch64" ]:
75100 return "aarch64-unknown-linux-gnu"
76101 else :
77102 return "x86_64-unknown-linux-gnu"
@@ -101,19 +126,20 @@ def download_and_extract_libs(url, platform_name):
101126 response = requests .get (url , headers = headers )
102127 response .raise_for_status ()
103128
129+ print (f"Downloaded zip file, extracting lib files..." )
104130 with zipfile .ZipFile (io .BytesIO (response .content )) as zip_ref :
105131 # Extract only files inside the libs/ directory
132+ extracted_count = 0
106133 for member in zip_ref .namelist ():
107- print (f" Processing zip member: { member } " )
108134 if member .startswith ("lib/" ) and not member .endswith ("/" ):
109- print (f" Processing lib file from downloadedzip: { member } " )
110135 target_path = platform_dir / os .path .relpath (member , "lib" )
111- print (f" Moving file to target path: { target_path } " )
112136 target_path .parent .mkdir (parents = True , exist_ok = True )
113137 with zip_ref .open (member ) as source , open (target_path , "wb" ) as target :
114138 target .write (source .read ())
139+ extracted_count += 1
140+ print (f" Extracted: { member } -> { target_path } " )
115141
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 } " )
117143
118144def copy_artifacts_to_root ():
119145 """Copy the artifacts folder from scripts/artifacts to the root of the repository."""
@@ -122,56 +148,77 @@ def copy_artifacts_to_root():
122148 return
123149
124150 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+
125155 if ROOT_ARTIFACTS_DIR .exists ():
126156 shutil .rmtree (ROOT_ARTIFACTS_DIR )
127157 print (f"Copying from { SCRIPTS_ARTIFACTS_DIR } to { ROOT_ARTIFACTS_DIR } " )
128158 shutil .copytree (SCRIPTS_ARTIFACTS_DIR , ROOT_ARTIFACTS_DIR )
129159 print ("Done copying artifacts" )
130- print ("\n Folder content of artifacts directory:" )
160+ print ("\n Folder content of root artifacts directory:" )
131161 for item in sorted (ROOT_ARTIFACTS_DIR .iterdir ()):
132162 print (f" { item .name } " )
133163
134164def main ():
135165 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] " )
137167 print ("Example: python download_artifacts.py c2pa-v0.49.5" )
168+ print ("Example: python download_artifacts.py c2pa-v0.49.5 arm64" )
138169 sys .exit (1 )
139170
140171 release_tag = sys .argv [1 ]
172+ target_arch = sys .argv [2 ] if len (sys .argv ) > 2 else None
173+
141174 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 )
142179 SCRIPTS_ARTIFACTS_DIR .mkdir (exist_ok = True )
143180 print (f"Fetching release information for tag { release_tag } ..." )
144181 release = get_release_by_tag (release_tag )
145182 print (f"Found release: { release ['tag_name' ]} \n " )
146183
147- # Get the platform identifier for the current system
184+ # Get the platform identifier for the target architecture
148185 env_platform = os .environ .get ("C2PA_LIBS_PLATFORM" )
149186 if env_platform :
150187 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+
152195 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 } )" )
156198
157199 # Construct the expected asset name
158200 expected_asset_name = f"{ release_tag } -{ platform_id } .zip"
159201 print (f"Looking for asset: { expected_asset_name } " )
160202
161203 # Find the matching asset in the release
162204 matching_asset = None
205+ print (f"Looking for asset: { expected_asset_name } " )
206+ print ("Available assets in release:" )
163207 for asset in release ['assets' ]:
208+ print (f" - { asset ['name' ]} " )
164209 if asset ['name' ] == expected_asset_name :
165210 matching_asset = asset
166- break
211+ print ( f"Using native library: { matching_asset [ 'name' ] } " )
167212
168213 if matching_asset :
169- print (f"Found matching asset: { matching_asset ['name' ]} " )
214+ print (f"\n Downloading asset: { matching_asset ['name' ]} " )
170215 download_and_extract_libs (matching_asset ['browser_download_url' ], platform_id )
171216 print ("\n Artifacts have been downloaded and extracted successfully!" )
172217 copy_artifacts_to_root ()
173218 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." )
175222
176223 except requests .exceptions .RequestException as e :
177224 print (f"Error: { e } " )
0 commit comments