@@ -40,11 +40,17 @@ def detect_arch():
4040 else :
4141 raise ValueError (f"Unsupported CPU architecture: { machine } " )
4242
43- def get_platform_identifier ():
44- """Get the full platform identifier (arch-os) for the current system,
45- matching the identifiers used by the Github publisher.
43+ def get_platform_identifier (target_arch = None ):
44+ """Get the full platform identifier (arch-os) for the current system or target.
45+
46+ Args:
47+ target_arch: Optional target architecture. If provided, overrides auto-detection.
48+ For macOS: 'universal2', 'arm64', or 'x86_64'
49+
4650 Returns one of:
47- - universal-apple-darwin (for Mac)
51+ - universal-apple-darwin (for macOS universal)
52+ - aarch64-apple-darwin (for macOS ARM64)
53+ - x86_64-apple-darwin (for macOS x86_64)
4854 - x86_64-pc-windows-msvc (for Windows 64-bit)
4955 - x86_64-unknown-linux-gnu (for Linux x86_64)
5056 - aarch64-unknown-linux-gnu (for Linux ARM64)
@@ -53,11 +59,27 @@ def get_platform_identifier():
5359 machine = platform .machine ().lower ()
5460
5561 if system == "darwin" :
56- return "universal-apple-darwin"
62+ if target_arch == "arm64" :
63+ return "aarch64-apple-darwin"
64+ elif target_arch == "x86_64" :
65+ return "x86_64-apple-darwin"
66+ elif target_arch == "universal2" :
67+ return "universal-apple-darwin"
68+ else :
69+ # Auto-detect: prefer specific architecture over universal
70+ if machine == "arm64" :
71+ return "aarch64-apple-darwin"
72+ elif machine == "x86_64" :
73+ return "x86_64-apple-darwin"
74+ else :
75+ return "universal-apple-darwin"
5776 elif system == "windows" :
58- return "x86_64-pc-windows-msvc"
77+ if target_arch == "arm64" :
78+ return "aarch64-pc-windows-msvc"
79+ else :
80+ return "x86_64-pc-windows-msvc"
5981 elif system == "linux" :
60- if machine in ["arm64" , "aarch64" ]:
82+ if target_arch == "aarch64" or machine in ["arm64" , "aarch64" ]:
6183 return "aarch64-unknown-linux-gnu"
6284 else :
6385 return "x86_64-unknown-linux-gnu"
@@ -87,19 +109,20 @@ def download_and_extract_libs(url, platform_name):
87109 response = requests .get (url , headers = headers )
88110 response .raise_for_status ()
89111
112+ print (f"Downloaded zip file, extracting lib files..." )
90113 with zipfile .ZipFile (io .BytesIO (response .content )) as zip_ref :
91114 # Extract only files inside the libs/ directory
115+ extracted_count = 0
92116 for member in zip_ref .namelist ():
93- print (f" Processing zip member: { member } " )
94117 if member .startswith ("lib/" ) and not member .endswith ("/" ):
95- print (f" Processing lib file from downloadedzip: { member } " )
96118 target_path = platform_dir / os .path .relpath (member , "lib" )
97- print (f" Moving file to target path: { target_path } " )
98119 target_path .parent .mkdir (parents = True , exist_ok = True )
99120 with zip_ref .open (member ) as source , open (target_path , "wb" ) as target :
100121 target .write (source .read ())
122+ extracted_count += 1
123+ print (f" Extracted: { member } -> { target_path } " )
101124
102- print (f"Done downloading and extracting libraries for { platform_name } " )
125+ print (f"Done downloading and extracting { extracted_count } library files for { platform_name } " )
103126
104127def copy_artifacts_to_root ():
105128 """Copy the artifacts folder from scripts/artifacts to the root of the repository."""
@@ -108,56 +131,77 @@ def copy_artifacts_to_root():
108131 return
109132
110133 print ("Copying artifacts from scripts/artifacts to root..." )
134+ print ("Contents of scripts/artifacts before copying:" )
135+ for item in sorted (SCRIPTS_ARTIFACTS_DIR .iterdir ()):
136+ print (f" { item .name } " )
137+
111138 if ROOT_ARTIFACTS_DIR .exists ():
112139 shutil .rmtree (ROOT_ARTIFACTS_DIR )
113140 print (f"Copying from { SCRIPTS_ARTIFACTS_DIR } to { ROOT_ARTIFACTS_DIR } " )
114141 shutil .copytree (SCRIPTS_ARTIFACTS_DIR , ROOT_ARTIFACTS_DIR )
115142 print ("Done copying artifacts" )
116- print ("\n Folder content of artifacts directory:" )
143+ print ("\n Folder content of root artifacts directory:" )
117144 for item in sorted (ROOT_ARTIFACTS_DIR .iterdir ()):
118145 print (f" { item .name } " )
119146
120147def main ():
121148 if len (sys .argv ) < 2 :
122- print ("Usage: python download_artifacts.py <release_tag>" )
149+ print ("Usage: python download_artifacts.py <release_tag> [target_architecture] " )
123150 print ("Example: python download_artifacts.py c2pa-v0.49.5" )
151+ print ("Example: python download_artifacts.py c2pa-v0.49.5 arm64" )
124152 sys .exit (1 )
125153
126154 release_tag = sys .argv [1 ]
155+ target_arch = sys .argv [2 ] if len (sys .argv ) > 2 else None
156+
127157 try :
158+ # Clean up any existing artifacts before starting
159+ print ("Cleaning up existing artifacts..." )
160+ if SCRIPTS_ARTIFACTS_DIR .exists ():
161+ shutil .rmtree (SCRIPTS_ARTIFACTS_DIR )
128162 SCRIPTS_ARTIFACTS_DIR .mkdir (exist_ok = True )
129163 print (f"Fetching release information for tag { release_tag } ..." )
130164 release = get_release_by_tag (release_tag )
131165 print (f"Found release: { release ['tag_name' ]} \n " )
132166
133- # Get the platform identifier for the current system
167+ # Get the platform identifier for the target architecture
134168 env_platform = os .environ .get ("C2PA_LIBS_PLATFORM" )
135169 if env_platform :
136170 print (f"Using platform from environment variable C2PA_LIBS_PLATFORM: { env_platform } " )
137- platform_id = env_platform or get_platform_identifier ()
171+ platform_id = env_platform
172+ else :
173+ platform_id = get_platform_identifier (target_arch )
174+ print (f"Using target architecture: { target_arch or 'auto-detected' } " )
175+ print (f"Detected machine architecture: { platform .machine ()} " )
176+ print (f"Detected system: { platform .system ()} " )
177+
138178 print ("Looking up releases for platform id: " , platform_id )
139- print ("Environment variable set for lookup: " , env_platform )
140- platform_source = "environment variable" if env_platform else "auto-detection"
141- print (f"Target platform: { platform_id } (set through{ platform_source } )" )
179+ platform_source = "environment variable" if env_platform else "target architecture" if target_arch else "auto-detection"
180+ print (f"Target platform: { platform_id } (set through { platform_source } )" )
142181
143182 # Construct the expected asset name
144183 expected_asset_name = f"{ release_tag } -{ platform_id } .zip"
145184 print (f"Looking for asset: { expected_asset_name } " )
146185
147186 # Find the matching asset in the release
148187 matching_asset = None
188+ print (f"Looking for asset: { expected_asset_name } " )
189+ print ("Available assets in release:" )
149190 for asset in release ['assets' ]:
191+ print (f" - { asset ['name' ]} " )
150192 if asset ['name' ] == expected_asset_name :
151193 matching_asset = asset
152- break
194+ print ( f"Matching asset: { matching_asset [ 'name' ] } " )
153195
154196 if matching_asset :
155- print (f"Found matching asset: { matching_asset ['name' ]} " )
197+ print (f"\n Downloading asset: { matching_asset ['name' ]} " )
156198 download_and_extract_libs (matching_asset ['browser_download_url' ], platform_id )
157199 print ("\n Artifacts have been downloaded and extracted successfully!" )
158200 copy_artifacts_to_root ()
159201 else :
160- print (f"\n No matching asset found: { expected_asset_name } " )
202+ print (f"\n No matching asset found for platform: { platform_id } " )
203+ print (f"Expected asset name: { expected_asset_name } " )
204+ print ("Please check if the asset exists in the release or if the platform identifier is correct." )
161205
162206 except requests .exceptions .RequestException as e :
163207 print (f"Error: { e } " )
0 commit comments