Compare commits
3
Commits
159f7bfe83
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b3ebd0f7a | ||
|
|
4c701854f9 | ||
|
|
551ba34cab |
@@ -31,13 +31,28 @@ return {
|
||||
summary = "Short description",
|
||||
url = "https://.../src.tar.gz",
|
||||
deps = { "libfoo", "libbar>=2.0" },
|
||||
build_system = "autotools", -- autotools | cmake | meson | make | cargo | custom
|
||||
build_system = "autotools", -- autotools | cmake | meson | make | cargo | zig | build.sh | custom
|
||||
configure_args = { "--enable-x" },
|
||||
test = "${DESTDIR}/usr/bin/mypkg --version",
|
||||
}
|
||||
```
|
||||
|
||||
**Build systems**: `autotools`, `cmake`, `meson`, `make`, `cargo`, `custom`
|
||||
**Build systems**: `autotools`, `cmake`, `meson`, `make`, `cargo`, `zig`, `build.sh`, `custom`
|
||||
|
||||
## Post-transaction hooks
|
||||
|
||||
Packages may ship post-transaction hooks — pure-data Lua files under
|
||||
`usr/share/zeta/hooks/*.hook` in the stage tree. A hook declares an `order`,
|
||||
a `trigger` (e.g. `{ op = "install", type = "package", target = { "mypkg" } }`),
|
||||
and an `action` (e.g. `{ when = "post", exec = "..." }`).
|
||||
|
||||
At build time `zeta-makepkg` scans the stage for `*.hook` files, validates each
|
||||
one (they must load as a table carrying `trigger` and `action`), and merges
|
||||
their paths into the generated `files` whitelist so hooks are committed
|
||||
alongside the declared files. A malformed hook fails the build.
|
||||
|
||||
See [`toolchain/examples/hooks-demo/`](toolchain/examples/hooks-demo/hooks-demo.recipe)
|
||||
for a working example.
|
||||
|
||||
## Structure
|
||||
|
||||
|
||||
@@ -227,6 +227,8 @@ local function wizard()
|
||||
"meson (meson setup build && ninja && ninja install)",
|
||||
"make (make && make install)",
|
||||
"cargo (cargo build --release)",
|
||||
"zig (zig build && zig build install --prefix /usr)",
|
||||
"build.sh (sh build.sh with DESTDIR staging)",
|
||||
"custom (run build_script)",
|
||||
})
|
||||
|
||||
@@ -235,7 +237,7 @@ local function wizard()
|
||||
|
||||
-- 8. Configure args (skip for cargo)
|
||||
rcp.configure_args = {}
|
||||
if rcp.build_system ~= "cargo" then
|
||||
if rcp.build_system ~= "cargo" and rcp.build_system ~= "build.sh" then
|
||||
io.write("Configure args" .. dim(" [comma-separated, e.g. --enable-feature, --without-x]") .. ": ")
|
||||
io.flush()
|
||||
local args_line = io.read("*l")
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
# build.sh — example build.sh-style build script for zeta-makepkg.
|
||||
#
|
||||
# Invoked from the extracted source directory. The tool sets:
|
||||
# $DESTDIR → staging tree root (e.g. /tmp/zeta-makepkg/buildsh-tool-.../stage)
|
||||
#
|
||||
# This script must compile/assemble the software and install every output
|
||||
# file under $DESTDIR with standard FHS paths (usr/bin/, usr/lib/, etc.).
|
||||
#
|
||||
# For a real project you would replace the example below with the project's
|
||||
# own build.sh — e.g. one that runs configure && make && make install with
|
||||
# DESTDIR set, or any autotools-like shell build sequence.
|
||||
|
||||
set -eu
|
||||
|
||||
echo "==> Building buildsh-tool (build.sh)"
|
||||
|
||||
# Example: install a shell script into the staging tree
|
||||
mkdir -p "$DESTDIR/usr/bin"
|
||||
cat > "$DESTDIR/usr/bin/buildsh-tool" <<'EOF'
|
||||
#!/bin/sh
|
||||
echo "buildsh-tool 1.0"
|
||||
EOF
|
||||
chmod 755 "$DESTDIR/usr/bin/buildsh-tool"
|
||||
|
||||
echo "==> Install complete"
|
||||
@@ -0,0 +1,23 @@
|
||||
-- buildsh-demo.recipe — demonstrates build_system = "build.sh".
|
||||
--
|
||||
-- The build.sh build system runs the source tree's build.sh script from the
|
||||
-- extracted source directory. The script receives $DESTDIR pointing at the
|
||||
-- staging tree where installed files must be placed, exactly like the
|
||||
-- 'custom' build system — but the script name is fixed to build.sh.
|
||||
--
|
||||
-- To try this:
|
||||
-- 1. Unpack the source tarball: tar -xzf buildsh-tool-1.0.tar.gz
|
||||
-- 2. Run the script manually: cd buildsh-tool-1.0 && DESTDIR=/tmp/stage sh build.sh
|
||||
-- 3. Inspect the staged output: find /tmp/stage
|
||||
-- 4. Build with makepkg: zeta-makepkg buildsh-demo.recipe
|
||||
|
||||
return {
|
||||
name = "buildsh-tool",
|
||||
version = "1.0",
|
||||
summary = "Example build.sh-style package (shell-installed binary)",
|
||||
url = "buildsh-tool-1.0.tar.gz",
|
||||
sha256 = nil,
|
||||
deps = {},
|
||||
build_system = "build.sh",
|
||||
test = "test -x ${DESTDIR}/usr/bin/buildsh-tool",
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#!/bin/sh
|
||||
# build.sh — example custom build script for zeta-makepkg.
|
||||
#
|
||||
# Invoked from the extracted source directory. The tool sets:
|
||||
# $DESTDIR → staging tree root (e.g. /tmp/zeta-makepkg/hooks-demo-.../stage)
|
||||
#
|
||||
# This script installs a small command under usr/bin/ and a post-transaction
|
||||
# hook under usr/share/zeta/hooks/. A hook is a pure-data Lua file:
|
||||
#
|
||||
# return {
|
||||
# order = 50,
|
||||
# trigger = { op = "install", type = "package", target = { "hooks-demo" } },
|
||||
# action = { when = "post", exec = "true", description = "example hook" },
|
||||
# }
|
||||
#
|
||||
# zeta-makepkg scans the stage for usr/share/zeta/hooks/*.hook, validates the
|
||||
# format, and merges the paths into the generated `files` whitelist.
|
||||
|
||||
set -eu
|
||||
|
||||
echo "==> Building hooks-demo (custom)"
|
||||
|
||||
# Install a tiny command
|
||||
mkdir -p "$DESTDIR/usr/bin"
|
||||
cat > "$DESTDIR/usr/bin/hooks-demo" <<'EOF'
|
||||
#!/bin/sh
|
||||
echo "hooks-demo: post-transaction hooks are working"
|
||||
EOF
|
||||
chmod 755 "$DESTDIR/usr/bin/hooks-demo"
|
||||
|
||||
# Install a post-transaction hook (pure data, no side effects)
|
||||
mkdir -p "$DESTDIR/usr/share/zeta/hooks"
|
||||
cat > "$DESTDIR/usr/share/zeta/hooks/hooks-demo.hook" <<'EOF'
|
||||
return {
|
||||
order = 50,
|
||||
trigger = { op = "install", type = "package", target = { "hooks-demo" } },
|
||||
action = { when = "post", exec = "true", description = "example hook" },
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "==> Install complete"
|
||||
@@ -0,0 +1,26 @@
|
||||
-- hooks-demo.recipe — demonstrates shipping a post-transaction hook.
|
||||
--
|
||||
-- The custom build script installs a small command and a hook file under
|
||||
-- usr/share/zeta/hooks/. zeta-makepkg scans the stage for *.hook files,
|
||||
-- validates each one (a hook is a pure-data Lua table carrying `trigger`
|
||||
-- and `action`), and merges the found paths into the generated `files`
|
||||
-- whitelist so the hook is committed alongside the declared files.
|
||||
--
|
||||
-- To try this:
|
||||
-- 1. Unpack the source tarball: tar -xzf hooks-demo-1.0.tar.gz
|
||||
-- 2. Run the script manually: cd hooks-demo-1.0 && DESTDIR=/tmp/stage sh build.sh
|
||||
-- 3. Inspect the staged output: find /tmp/stage
|
||||
-- 4. Build with makepkg: zeta-makepkg hooks-demo.recipe
|
||||
|
||||
return {
|
||||
name = "hooks-demo",
|
||||
version = "1.0",
|
||||
summary = "Example package shipping a post-transaction hook",
|
||||
url = "hooks-demo-1.0.tar.gz",
|
||||
sha256 = nil,
|
||||
deps = {},
|
||||
build_system = "custom",
|
||||
build_script = "build.sh",
|
||||
files = { "usr/bin/hooks-demo", "usr/share/zeta/hooks/hooks-demo.hook" },
|
||||
test = "test -x ${DESTDIR}/usr/bin/hooks-demo",
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
-- zig.recipe — zig build system example.
|
||||
--
|
||||
-- Demonstrates: zig, configure_args (-D flags), source sha256.
|
||||
|
||||
return {
|
||||
name = "my-zig-app",
|
||||
version = "1.0.0",
|
||||
summary = "An example application built with Zig",
|
||||
url = "https://example.com/my-zig-app-1.0.0.tar.gz",
|
||||
sha256 = nil,
|
||||
deps = {},
|
||||
build_system = "zig",
|
||||
configure_args = { "-Doptimize=ReleaseFast" },
|
||||
test = "test -x ${DESTDIR}/usr/bin/my-zig-app",
|
||||
files = { "usr/bin/my-zig-app" },
|
||||
}
|
||||
@@ -11,6 +11,7 @@ local recipe = require("recipe")
|
||||
local builder = require("builder")
|
||||
local packager = require("packager")
|
||||
local indexer = require("indexer")
|
||||
local hooks = require("hooks")
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- Dependency resolution (--follow)
|
||||
@@ -118,6 +119,8 @@ function build.single(recipe_path, opts)
|
||||
|
||||
builder.run_build(r, source_dir, stage_dir, { jobs = opts.jobs })
|
||||
|
||||
local hook_paths = hooks.scan_hooks(stage_dir)
|
||||
|
||||
if r.test then
|
||||
builder.run_test(r.test, stage_dir)
|
||||
else
|
||||
@@ -126,7 +129,7 @@ function build.single(recipe_path, opts)
|
||||
|
||||
local tarball_path = path.join(pkg_dir, r.name .. "-" .. r.version .. ".tar.gz")
|
||||
local sha256 = packager.create_tarball(stage_dir, tarball_path)
|
||||
packager.write_manifest(r, sha256, pkg_dir, opts.repo)
|
||||
packager.write_manifest(r, sha256, pkg_dir, opts.repo, hook_paths)
|
||||
|
||||
if not opts.no_index then
|
||||
indexer.generate(packages_dir)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
-- Handles the full build pipeline for a recipe:
|
||||
-- 1. fetch_source — download to cache (or detect git)
|
||||
-- 2. extract_source — unpack tarball or clone git repo
|
||||
-- 3. run_build — dispatch autotools/cmake/meson/make/cargo/custom
|
||||
-- 3. run_build — dispatch autotools/cmake/meson/make/cargo/zig/build.sh/custom
|
||||
-- 4. run_test — execute post-build verification command
|
||||
--
|
||||
-- All subprocesses run in a minimal environment. Build tools (meson, cmake,
|
||||
@@ -243,7 +243,16 @@ function builder.run_build(recipe, source_dir, stage_dir, opts)
|
||||
end
|
||||
|
||||
if bs == "autotools" then
|
||||
run("./configure --prefix=/usr" .. args_str)
|
||||
-- Some projects ship a capitalized Configure instead of autoconf's configure.
|
||||
local config_script = "configure"
|
||||
if not path.exists(path.join(source_dir, "configure")) then
|
||||
if path.exists(path.join(source_dir, "Configure")) then
|
||||
config_script = "Configure"
|
||||
else
|
||||
error(("no configure script found in %s (looked for ./configure and ./Configure)"):format(source_dir), 0)
|
||||
end
|
||||
end
|
||||
run("./" .. config_script .. " --prefix=/usr" .. args_str)
|
||||
run("make -j" .. njobs)
|
||||
run("make install DESTDIR=" .. path.quote(stage_dir))
|
||||
|
||||
@@ -289,6 +298,16 @@ function builder.run_build(recipe, source_dir, stage_dir, opts)
|
||||
end
|
||||
run("install -D " .. path.quote(target) .. " " .. path.quote(path.join(bin_dir, path.basename(target))))
|
||||
|
||||
elseif bs == "zig" then
|
||||
run("zig build -Doptimize=ReleaseSafe" .. args_str)
|
||||
run("zig build install --prefix /usr -Ddestdir=" .. path.quote(stage_dir))
|
||||
|
||||
elseif bs == "build.sh" then
|
||||
if not path.exists(path.join(source_dir, "build.sh")) then
|
||||
error(("no build.sh script found in %s (build_system is 'build.sh')"):format(source_dir), 0)
|
||||
end
|
||||
run("DESTDIR=" .. path.quote(stage_dir) .. " sh build.sh")
|
||||
|
||||
elseif bs == "custom" then
|
||||
local script = recipe.build_script
|
||||
run("DESTDIR=" .. path.quote(stage_dir) .. " sh " .. path.quote(script))
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
-- hooks.lua -- scan and validate post-transactional hook files in the stage.
|
||||
--
|
||||
-- Zeta packages may ship hooks under usr/share/zeta/hooks/*.hook. A hook is
|
||||
-- a Lua file returning a table of the form:
|
||||
--
|
||||
-- return {
|
||||
-- order = 100,
|
||||
-- trigger = { ... },
|
||||
-- action = { ... },
|
||||
-- }
|
||||
--
|
||||
-- scan_hooks(stage_dir) finds every *.hook file under the stage's
|
||||
-- usr/share/zeta/hooks/ directory, loads each one in an empty environment
|
||||
-- (the same lockdown as recipe.load), verifies it returns a table carrying
|
||||
-- `trigger` and `action` tables, and returns the stage-relative paths
|
||||
-- (e.g. "usr/share/zeta/hooks/demo.hook"). A malformed hook — bad syntax,
|
||||
-- runtime error, non-table result, or missing trigger/action — raises.
|
||||
|
||||
local hooks = {}
|
||||
|
||||
local path = require("path")
|
||||
local log = require("log")
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- Private helpers
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
-- Load a single hook file under an empty environment and perform minimal
|
||||
-- validation. Returns the hook table or raises on any failure.
|
||||
local function load_hook(filepath)
|
||||
local f, err = io.open(filepath, "rb")
|
||||
if not f then
|
||||
error(("hook %q: cannot open: %s"):format(filepath, tostring(err)), 0)
|
||||
end
|
||||
local src = f:read("*a")
|
||||
f:close()
|
||||
|
||||
-- Hooks run in a minimal environment — they're pure data, but we still
|
||||
-- lock down globals to prevent accidental side effects (same as recipes).
|
||||
local env = {}
|
||||
local chunk
|
||||
if setfenv then
|
||||
chunk, err = loadstring(src, "@" .. filepath)
|
||||
if chunk then setfenv(chunk, env) end
|
||||
else
|
||||
chunk, err = load(src, "@" .. filepath, "t", env)
|
||||
end
|
||||
if not chunk then
|
||||
error(("hook %q: syntax error: %s"):format(filepath, tostring(err)), 0)
|
||||
end
|
||||
|
||||
local ok, raw = pcall(chunk)
|
||||
if not ok then
|
||||
error(("hook %q: runtime error: %s"):format(filepath, tostring(raw)), 0)
|
||||
end
|
||||
|
||||
if type(raw) ~= "table" then
|
||||
error(("hook %q: must return a table"):format(filepath), 0)
|
||||
end
|
||||
if type(raw.trigger) ~= "table" then
|
||||
error(("hook %q: missing or invalid `trigger` table"):format(filepath), 0)
|
||||
end
|
||||
if type(raw.action) ~= "table" then
|
||||
error(("hook %q: missing or invalid `action` table"):format(filepath), 0)
|
||||
end
|
||||
|
||||
return raw
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- Public API
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
-- Scan the stage for usr/share/zeta/hooks/*.hook, validate each one, and
|
||||
-- return their stage-relative paths (sorted for deterministic manifests).
|
||||
-- Returns an empty list when no hooks directory exists. Raises on the first
|
||||
-- malformed hook.
|
||||
function hooks.scan_hooks(stage_dir)
|
||||
local hooks_dir = path.join(stage_dir, "usr/share/zeta/hooks")
|
||||
if not path.exists(hooks_dir) then
|
||||
return {}
|
||||
end
|
||||
|
||||
log.step("scanning hooks in " .. hooks_dir)
|
||||
|
||||
local found = {}
|
||||
local f = io.popen("find " .. path.quote(hooks_dir)
|
||||
.. " -type f -name '*.hook' 2>/dev/null | sort")
|
||||
if f then
|
||||
for line in f:lines() do
|
||||
if line ~= "" then found[#found + 1] = line end
|
||||
end
|
||||
f:close()
|
||||
end
|
||||
|
||||
local base = stage_dir:gsub("/+$", "")
|
||||
local rels = {}
|
||||
for _, abs in ipairs(found) do
|
||||
load_hook(abs) -- raises on malformed hooks
|
||||
local rel = abs:sub(#base + 2) -- strip "<stage_dir>/" prefix
|
||||
rels[#rels + 1] = rel
|
||||
log.ok(("hook %s"):format(rel))
|
||||
end
|
||||
|
||||
return rels
|
||||
end
|
||||
|
||||
return hooks
|
||||
@@ -97,7 +97,13 @@ end
|
||||
-- The generated manifest uses archive mode (strip=1) and includes the
|
||||
-- computed sha256 of the binary tarball. Optional fields (deps, files,
|
||||
-- test) are included when present in the recipe.
|
||||
function packager.write_manifest(recipe, tarball_sha256, pkg_dir, repo)
|
||||
--
|
||||
-- `hooks` (optional) is a list of stage-relative paths of packaged hook
|
||||
-- files (usr/share/zeta/hooks/*.hook). When `recipe.files` is set, the
|
||||
-- hook paths are merged into the emitted files whitelist so the hooks are
|
||||
-- committed alongside the whitelisted files. When `recipe.files` is nil,
|
||||
-- hooks are ignored (all staged files commit anyway).
|
||||
function packager.write_manifest(recipe, tarball_sha256, pkg_dir, repo, hooks)
|
||||
local repo = repo or "https://raw.githubusercontent.com/gretagen/zeta-packages/refs/heads/main"
|
||||
local lines = {}
|
||||
local function emit(fmt, ...)
|
||||
@@ -129,6 +135,9 @@ function packager.write_manifest(recipe, tarball_sha256, pkg_dir, repo)
|
||||
for _, f in ipairs(recipe.files) do
|
||||
file_strs[#file_strs + 1] = string.format('"%s"', escape(f))
|
||||
end
|
||||
for _, h in ipairs(hooks or {}) do
|
||||
file_strs[#file_strs + 1] = string.format('"%s"', escape(h))
|
||||
end
|
||||
emit(' files = { %s },', table.concat(file_strs, ", "))
|
||||
end
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
-- url = "https://.../mypkg-1.2.3.tar.gz",
|
||||
-- sha256 = nil, -- optional source checksum
|
||||
-- deps = { "libfoo" },
|
||||
-- build_system = "meson", -- autotools | cmake | meson | make | cargo | custom
|
||||
-- build_system = "meson", -- autotools | cmake | meson | make | cargo | zig | build.sh | custom
|
||||
-- configure_args = { ... }, -- optional extra args
|
||||
-- build_script = "build.sh", -- required for custom
|
||||
-- test = "test -f ${DESTDIR}/usr/bin/mypkg",
|
||||
@@ -31,7 +31,8 @@ local KNOWN_KEYS = {
|
||||
|
||||
local BUILD_SYSTEMS = {
|
||||
autotools = true, cmake = true, meson = true,
|
||||
make = true, cargo = true, custom = true,
|
||||
make = true, cargo = true, zig = true,
|
||||
["build.sh"] = true, custom = true,
|
||||
}
|
||||
|
||||
local HEX64 = "^" .. string.rep("%x", 64) .. "$"
|
||||
|
||||
Reference in New Issue
Block a user