@@ -323,26 +323,43 @@ local function compile_native(tmp, current_output, target_definition)
323323 windows = build_config .zig .path_win :gsub (" ^~" , os.getenv " LOCALAPPDATA" or " ~" ),
324324 [F .Nil ] = build_config .zig .path :gsub (" ^~" , os.getenv " HOME" or " ~" ),
325325 }/ zig_version
326+ local zig_key = build_config .zig .key ;
326327
327328 local zig = zig_path / " zig" .. sys .exe
328329
329330 -- Install Zig (to cross compile and link C sources)
330331 if not zig :is_file () then
331332 log (" Zig" , " download and install Zig to %s" , zig_path )
332- local url = build_config .zig .url
333- : gsub (" OS" , sys .os )
334- : gsub (" ARCH" , sys .arch )
335- : gsub (" VERSION" , zig_version )
336- .. F .case (sys .os ) { windows = " .zip" , [F .Nil ]= " .tar.xz" }
337- local archive = url :basename ()
338333 local curl = require " curl"
339334 local term = require " term"
340- assert (curl .request {
341- " -fSL" ,
342- (quiet or not term .isatty (io.stdout )) and " -s" or " -#" ,
343- url ,
344- " -o" , tmp / archive ,
345- })
335+ local ext = F .case (sys .os ) { windows = " .zip" , [F .Nil ]= " .tar.xz" }
336+ local archive , ok , err
337+ local mirrors = curl " https://ziglang.org/download/community-mirrors.txt" : lines () : shuffle ()
338+ for _ , mirror in ipairs (mirrors ) do
339+ local url = string.format (" %s/zig-%s-%s-%s%s" , mirror , sys .arch , sys .os , zig_version , ext )
340+ local source = " ?source=luax-zig-setup"
341+ log (" Zig" , " try mirror %s" , mirror )
342+ archive = url :basename ()
343+ ok , err = curl .request {
344+ " -fSL" ,
345+ (quiet or not term .isatty (io.stdout )) and " -s" or " -#" ,
346+ url .. source ,
347+ " -o" , tmp / archive ,
348+ }
349+ if ok then
350+ assert (curl .request {
351+ " -fSL" ,
352+ (quiet or not term .isatty (io.stdout )) and " -s" or " -#" ,
353+ url .. " .minisig" .. source ,
354+ " -o" , tmp / archive .. " .minisig" ,
355+ })
356+ if not ok then break end
357+ ok = sh .run { " minisign" , " -Vm" , tmp / archive , " -x" , tmp / archive .. " .minisig" , " -P" , zig_key }
358+ if not ok then err = " minisig error" end
359+ break
360+ end
361+ end
362+ assert (ok , err )
346363 fs .mkdirs (zig_path )
347364 assert (sh .run (" tar -xJf" , tmp / archive , " -C" , zig_path , " --strip-components" , 1 ))
348365 if not zig :is_file () then
0 commit comments