reference-docs: build again with 40 workspace crates
The crate README rewrite was unrolled at eval time: one sed block per crate, each carrying one -e expression per other crate. The installPhase string grew with the square of the crate count, and at 40 crates (d5de1e494added swarm-claude-login) it reached 131708 bytes. Linux caps a single environment variable at 128 KiB, so exec of the builder failed with "Argument list too long" and every consumer of reference-docs failed with it, the website repo included. The rewrite is now a shell loop over $members at build time, building the same sed expressions per crate. The phase text no longer depends on the crate count. Output is byte-identical to the old form at6aab2ebb6(39 crates, the last commit where it built). Closes #5321
This commit is contained in:
parent
3b4f5d60ff
commit
fcda1f4a04
1 changed files with 23 additions and 36 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
{
|
{
|
||||||
stdenv,
|
stdenv,
|
||||||
lib,
|
|
||||||
self,
|
self,
|
||||||
optionsMd,
|
optionsMd,
|
||||||
}:
|
}:
|
||||||
|
|
@ -34,22 +33,6 @@
|
||||||
let
|
let
|
||||||
cargoToml = builtins.fromTOML (builtins.readFile ../../Cargo.toml);
|
cargoToml = builtins.fromTOML (builtins.readFile ../../Cargo.toml);
|
||||||
members = cargoToml.workspace.members;
|
members = cargoToml.workspace.members;
|
||||||
|
|
||||||
# A member-name relative link (`../<other-crate>`, no specific file —
|
|
||||||
# forge's browser renders that as a directory listing today) becomes a
|
|
||||||
# sibling crates/<other-crate>.md link once every crate README
|
|
||||||
# lives flat in the same directory. Built once, applied per file below,
|
|
||||||
# rather than a fresh `lib.concatMapStrings` per crate's own transform —
|
|
||||||
# every crate needs the exact same substitution list (every *other*
|
|
||||||
# member), so this only differs on the `member != other` filter.
|
|
||||||
siblingLinkFixups =
|
|
||||||
member:
|
|
||||||
lib.concatMapStrings (
|
|
||||||
other:
|
|
||||||
lib.optionalString (other != member) ''
|
|
||||||
-e 's,\]\(\.\./${other}(/)?\),](./${other}.md),g' \
|
|
||||||
''
|
|
||||||
) members;
|
|
||||||
in
|
in
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
pname = "hyperhive-docs";
|
pname = "hyperhive-docs";
|
||||||
|
|
@ -63,11 +46,15 @@ stdenv.mkDerivation {
|
||||||
# the alternative is hand-copying READMEs into docs/ and letting them
|
# the alternative is hand-copying READMEs into docs/ and letting them
|
||||||
# drift, which is the exact duplication this issue exists to avoid.
|
# drift, which is the exact duplication this issue exists to avoid.
|
||||||
src = ../../docs;
|
src = ../../docs;
|
||||||
inherit self optionsMd;
|
inherit self optionsMd members;
|
||||||
|
|
||||||
dontBuild = true;
|
dontBuild = true;
|
||||||
dontConfigure = true;
|
dontConfigure = true;
|
||||||
|
|
||||||
|
# The per-crate rewrite is a loop at build time, so this phase's text
|
||||||
|
# stays the same size as crates are added: each attribute reaches the
|
||||||
|
# builder as one environment variable, and Linux refuses to exec with
|
||||||
|
# a single one over 128 KiB.
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
runHook preInstall
|
runHook preInstall
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
|
|
@ -75,24 +62,24 @@ stdenv.mkDerivation {
|
||||||
mkdir -p "$out/crates"
|
mkdir -p "$out/crates"
|
||||||
cp -r "$optionsMd" "$out/options"
|
cp -r "$optionsMd" "$out/options"
|
||||||
|
|
||||||
${lib.concatMapStrings (member: ''
|
for member in $members; do
|
||||||
if [ -f "$self/${member}/README.md" ]; then
|
[ -f "$self/$member/README.md" ] || continue
|
||||||
# Rewrite relative links that were correct from the crate's own
|
# Rewrite relative links that were correct from the crate's own
|
||||||
# position in the repo tree but aren't once the file is
|
# position in the repo tree but aren't once the file is
|
||||||
# virtually one level under docs/ instead:
|
# virtually one level under docs/ instead:
|
||||||
# ../docs/x.md (crate root -> repo docs/) -> ../x.md lint:allow (stand-in name)
|
# ../docs/x.md (crate root -> repo docs/) -> ../x.md lint:allow (stand-in name)
|
||||||
# (crates/ -> docs/ is one directory shallower than
|
# (crates/ -> docs/ is one directory shallower than
|
||||||
# <crate>/ -> docs/ was, so the leading docs/ segment drops)
|
# <crate>/ -> docs/ was, so the leading docs/ segment drops)
|
||||||
# ../<sibling-crate> (that crate's own directory, no file)
|
# ../<sibling-crate> (that crate's own directory, no file; forge
|
||||||
# -> ./<sibling-crate>.md, once that sibling also has a
|
# renders it as a directory listing) -> ./<sibling-crate>.md,
|
||||||
# crates page every crate README lives flat beside it.
|
# since every crate README lives flat beside it under crates/.
|
||||||
sed -E \
|
fixups=(-e 's,\]\(\.\./docs/,](../,g')
|
||||||
-e 's,\]\(\.\./docs/,](../,g' \
|
for other in $members; do
|
||||||
${siblingLinkFixups member} \
|
[ "$other" != "$member" ] || continue
|
||||||
"$self/${member}/README.md" \
|
fixups+=(-e "s,\]\(\.\./$other(/)?\),](./$other.md),g")
|
||||||
> "$out/crates/${member}.md"
|
done
|
||||||
fi
|
sed -E "''${fixups[@]}" "$self/$member/README.md" >"$out/crates/$member.md"
|
||||||
'') members}
|
done
|
||||||
|
|
||||||
runHook postInstall
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue