1111import platform
1212import stat
1313import sys
14- import tempfile
1514import urllib .request
1615
1716from dataclasses import dataclass
@@ -85,6 +84,12 @@ class BuckInfo:
8584 archive_name = "buck2-x86_64-apple-darwin.zst" ,
8685 target_versions = ["3eb1ae97ea963086866b4d2d9ffa966d" ],
8786 ),
87+ ("windows" , "x86_64" ): BuckInfo (
88+ archive_name = "buck2-x86_64-pc-windows-msvc.exe.zst" ,
89+ target_versions = [
90+ "bf1685c4c4ddd9de4592b5a955cb7326fd01e6c4d5f561643422bed961a17401"
91+ ],
92+ ),
8893}
8994
9095
@@ -135,6 +140,8 @@ def resolve_buck2(args: argparse.Namespace) -> Union[str, int]:
135140 os_family = "linux"
136141 elif sys .platform .startswith ("darwin" ):
137142 os_family = "darwin"
143+ elif sys .platform .startswith ("win" ):
144+ os_family = "windows"
138145
139146 platform_key = (os_family , arch )
140147 if platform_key not in BUCK_PLATFORM_MAP :
@@ -193,12 +200,12 @@ def resolve_buck2(args: argparse.Namespace) -> Union[str, int]:
193200
194201 buck2_archive_url = f"https://github.com/facebook/buck2/releases/download/{ target_buck_version } /{ buck_info .archive_name } "
195202
196- with tempfile . NamedTemporaryFile () as archive_file :
203+ try :
197204 print (f"Downloading buck2 from { buck2_archive_url } ..." , file = sys .stderr )
198- urllib .request .urlretrieve (buck2_archive_url , archive_file . name )
205+ archive_file , _ = urllib .request .urlretrieve (buck2_archive_url )
199206
200207 # Extract and chmod.
201- with open (archive_file . name , "rb" ) as f :
208+ with open (archive_file , "rb" ) as f :
202209 data = f .read ()
203210 decompressed_bytes = zstd .decompress (data )
204211
@@ -207,6 +214,8 @@ def resolve_buck2(args: argparse.Namespace) -> Union[str, int]:
207214
208215 file_stat = os .stat (buck2_local_path )
209216 os .chmod (buck2_local_path , file_stat .st_mode | stat .S_IEXEC )
217+ finally :
218+ os .remove (archive_file )
210219
211220 return buck2_local_path
212221
0 commit comments