Skip to content

Commit d10a7fd

Browse files
author
Christophe Delord
committed
install Zig from mirrors with minisig signatures
1 parent e1006ba commit d10a7fd

File tree

8 files changed

+90
-56
lines changed

8 files changed

+90
-56
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ distributions (Debian, Fedora and Arch Linux) or on MacOS.
5555
### Quick compilation
5656

5757
The script `bootstrap.sh` installs `ninja`, `zig` (if required) and
58-
compiles LuaX. Once done, LuaX can be installed with `ninja install`.
59-
`git` must be installed to clone the LuaX repository but it can also be
60-
compiled from a source archive without git.
58+
compiles LuaX. `curl`, `minisign` and `tar` are needed to compile LuaX
59+
with `zig`.
60+
61+
Once done, LuaX can be installed with `ninja install`. `git` must be
62+
installed to clone the LuaX repository but it can also be compiled from
63+
a source archive without git.
6164

6265
The installation path of Zig is defined in the `build.lua` file. On
6366
Linux or MacOS, the installation path is defined by the variable

bootstrap.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ fi
9999
# C compiler
100100
######################################################################
101101

102-
ZIG_URL=$(grep "ZIG_URL *=" build.lua | cut -d= -f2 | tr -d " \",")
103102
ZIG_VERSION=$(grep "ZIG_VERSION *=" build.lua | cut -d= -f2 | tr -d " \",")
103+
ZIG_KEY=$(grep "ZIG_KEY *=" build.lua | cut -d= -f2 | tr -d " \",")
104104
ZIG_PATH=$(grep "ZIG_PATH *=" build.lua | cut -d= -f2 | tr -d " \",")
105105
eval "ZIG=$ZIG_PATH/$ZIG_VERSION/zig" # use eval to expand "~"
106106

@@ -109,7 +109,7 @@ case "$COMPILER" in
109109
COMPILER="$ZIG cc"
110110
if ! [ -x "$ZIG" ]
111111
then
112-
tools/install_zig.sh "$ZIG_URL" "$ZIG_VERSION" "$ZIG"
112+
tools/install_zig.sh "$ZIG_VERSION" "$ZIG" "$ZIG_KEY"
113113
[ -x "$ZIG" ] || error "zig can not be installed"
114114
fi
115115
;;

build.lua

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ For further information about luax you can visit
1818
https://codeberg.org/cdsoft/luax
1919
]]
2020

21-
version "9.5" "2025-08-26"
21+
version "9.5.1" "2025-08-27"
2222

2323
local F = require "F"
2424
local fs = require "fs"
@@ -35,7 +35,7 @@ LUAX.COPYRIGHT = I"LuaX $(VERSION) Copyright (C) 2021-$(DATE:split'%-':head()
3535

3636
local BUILD_CONFIG = {
3737
ZIG_VERSION = "0.14.1",
38-
ZIG_URL = "https://ziglang.org/download/VERSION/zig-ARCH-OS-VERSION",
38+
ZIG_KEY = "RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U",
3939
ZIG_PATH = "~/.local/opt/zig",
4040
ZIG_PATH_WIN = "~\\zig",
4141
}
@@ -413,21 +413,17 @@ local compiler_deps = {}
413413
case(compiler) {
414414

415415
zig = function()
416-
var "zig_url" (BUILD_CONFIG.ZIG_URL
417-
: gsub("OS", sys.os)
418-
: gsub("ARCH", sys.arch)
419-
: gsub("VERSION", BUILD_CONFIG.ZIG_VERSION)
420-
)
421416
var "zig_version" (BUILD_CONFIG.ZIG_VERSION)
422417
local zig_path = case(sys.os) {
423418
windows = BUILD_CONFIG.ZIG_PATH_WIN:gsub("^~", os.getenv"LOCALAPPDATA" or "~"),
424419
[Nil] = BUILD_CONFIG.ZIG_PATH:gsub("^~", os.getenv"HOME" or "~"),
425420
}
426421
var "zig" { zig_path/"$zig_version"/"zig" }
422+
var "zig_key" { BUILD_CONFIG.ZIG_KEY }
427423

428424
build "$zig" {
429425
description = "install zig $zig_version",
430-
command = "tools/install_zig.sh $zig_url $zig_version $out",
426+
command = "tools/install_zig.sh $zig_version $out $zig_key",
431427
pool = "console",
432428
}
433429

doc/luax.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ distributions (Debian, Fedora and Arch Linux) or on MacOS.
5555
### Quick compilation
5656

5757
The script `bootstrap.sh` installs `ninja`, `zig` (if required) and
58-
compiles LuaX. Once done, LuaX can be installed with `ninja install`.
59-
`git` must be installed to clone the LuaX repository but it can also be
60-
compiled from a source archive without git.
58+
compiles LuaX. `curl`, `minisign` and `tar` are needed to compile LuaX
59+
with `zig`.
60+
61+
Once done, LuaX can be installed with `ninja install`. `git` must be
62+
installed to clone the LuaX repository but it can also be compiled from
63+
a source archive without git.
6164

6265
The installation path of Zig is defined in the `build.lua` file. On
6366
Linux or MacOS, the installation path is defined by the variable

doc/src/luax.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ distributions (Debian, Fedora and Arch Linux) or on MacOS.
6868
### Quick compilation
6969

7070
The script `bootstrap.sh` installs `ninja`, `zig` (if required) and compiles LuaX.
71+
`curl`, `minisign` and `tar` are needed to compile LuaX with `zig`.
72+
7173
Once done, LuaX can be installed with `ninja install`.
7274
`git` must be installed to clone the LuaX repository but it can also be compiled from a source archive without git.
7375

luax/luax_build_config.lua.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ return {
2828
version = @q(COMPILER_VERSION),
2929
full_version = @q(COMPILER_FULL_VERSION),
3030
},
31-
zig = @(COMPILER_NAME=="zig" and ("{ path=%q, path_win=%q, url=%q }"):format(ZIG_PATH, ZIG_PATH_WIN, ZIG_URL) or nil),
31+
zig = @(COMPILER_NAME=="zig" and ("{ key=%q, path=%q, path_win=%q }"):format(ZIG_KEY, ZIG_PATH, ZIG_PATH_WIN) or nil),
3232
mode = @q(MODE),
3333
lto = @LTO,
3434
socket = @SOCKET,

luax/luax_cmd_compile.lua

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

tools/install_zig.sh

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,9 @@
2020

2121
set -e
2222

23-
ZIG_URL="$1"
24-
ZIG_VERSION="$2"
25-
ZIG="$3"
26-
27-
found()
28-
{
29-
hash "$@" 2>/dev/null
30-
}
31-
32-
download()
33-
{
34-
local URL="$1"
35-
local OUTPUT="$2"
36-
echo "Downloading $URL"
37-
if ! found curl
38-
then
39-
echo "ERROR: curl not found"
40-
exit 1
41-
fi
42-
curl -L "$URL" -o "$OUTPUT" --progress-bar --fail
43-
}
23+
ZIG_VERSION="$1"
24+
ZIG="$2"
25+
ZIG_KEY="$3"
4426

4527
ARCH="$(uname -m)"
4628
case "$ARCH" in
@@ -58,19 +40,50 @@ case "$(uname -s)" in
5840
(*) OS=unknown ;;
5941
esac
6042

61-
ZIG_URL=${ZIG_URL//OS/$OS}
62-
ZIG_URL=${ZIG_URL//ARCH/$ARCH}
63-
ZIG_URL=${ZIG_URL//VERSION/$ZIG_VERSION}
64-
ZIG_URL="$ZIG_URL$EXT"
65-
ZIG_ARCHIVE=$(basename "$ZIG_URL")
43+
ZIG_ARCHIVE=zig-$ARCH-$OS-$ZIG_VERSION$EXT
44+
45+
found()
46+
{
47+
hash "$@" 2>/dev/null
48+
}
49+
50+
download()
51+
{
52+
local OUTPUT="$1"
53+
echo "Downloading $ZIG_ARCHIVE"
54+
if ! found curl
55+
then
56+
echo "ERROR: curl not found"
57+
exit 1
58+
fi
59+
if ! found minisign
60+
then
61+
echo "ERROR: minisign not found"
62+
exit 1
63+
fi
64+
local MIRRORS
65+
MIRRORS=$(curl -s https://ziglang.org/download/community-mirrors.txt)
66+
mapfile -t MIRRORS < <(shuf -e "${MIRRORS[@]}")
67+
for mirror in "${MIRRORS[@]}"
68+
do
69+
echo "Try mirror: $mirror/$ZIG_ARCHIVE"
70+
if curl -L "$mirror/$ZIG_ARCHIVE?source=luax-zig-setup" -o "$OUTPUT" --progress-bar --fail
71+
then
72+
curl -L "$mirror/$ZIG_ARCHIVE.minisig?source=luax-zig-setup" -o "$OUTPUT.minisig" --progress-bar --fail
73+
minisign -Vm "$OUTPUT" -x "$OUTPUT.minisig" -P "$ZIG_KEY"
74+
break
75+
fi
76+
done
77+
}
6678

6779
if ! [ -x "$ZIG" ]
6880
then
6981
mkdir -p "$(dirname "$ZIG")"
70-
download "$ZIG_URL" "$(dirname "$ZIG")/$ZIG_ARCHIVE"
82+
download "$(dirname "$ZIG")/$ZIG_ARCHIVE"
7183

7284
tar xJf "$(dirname "$ZIG")/$ZIG_ARCHIVE" -C "$(dirname "$ZIG")" --strip-components 1
7385
rm "$(dirname "$ZIG")/$ZIG_ARCHIVE"
86+
rm "$(dirname "$ZIG")/$ZIG_ARCHIVE.minisig"
7487
fi
7588

7689
touch "$ZIG"

0 commit comments

Comments
 (0)