Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/scripts/package-binary.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,31 @@ cmp "$binary" "$bare"
cmp "$binary" "$tmp/extracted/$name/bin/moq-relay"

echo "release assets package together without path collisions"

# Without --binary the script builds the flake package named after the binary:
# `.#moq` for the moq-cli crate, since `.#moq-cli` is a stub refusing the old name.
cat >"$tmp/bin/nix" <<'NIX'
#!/usr/bin/env bash
set -euo pipefail
[[ "$1 $3" == "build --out-link" && "$2" == *"#moq" ]] || {
echo "unexpected: nix $*" >&2
exit 1
}
mkdir -p "$4/bin"
printf '#!/usr/bin/env sh\necho moq\n' >"$4/bin/moq"
chmod 0755 "$4/bin/moq"
NIX
chmod 0755 "$tmp/bin/nix"

PATH="$tmp/bin:$PATH" "$WORKSPACE_DIR/rs/scripts/package-binary.sh" \
--crate moq-cli \
--bin moq \
--version 0.12.2 \
--target "$target" \
--output "$tmp/dist"

name="moq-cli-v0.12.2-$target"
tar -xzf "$tmp/dist/$name.tar.gz" -C "$tmp/extracted"
[[ "$("$tmp/extracted/$name/bin/moq")" == moq ]]

echo "a nix build packages the flake output named after the binary"
11 changes: 6 additions & 5 deletions rs/scripts/package-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -euo pipefail
# --bin overrides the binary/command name when it differs from the crate (e.g.
# the `moq-cli` crate ships its binary as `moq`); it defaults to the crate name.
#
# Builds via `nix build .#<crate>` against the flake-pinned toolchain unless
# Builds via `nix build .#<bin>` against the flake-pinned toolchain unless
# --binary supplies an existing build. Produces
# <output>/<crate>-v<version>-<target>.tar.gz, named after the release tag so
# a URL rewritten from one tag to the next still resolves; the layout matches
Expand Down Expand Up @@ -97,12 +97,13 @@ if [[ -n "$BINARY" ]]; then
BIN_FILE="$BINARY"
echo "Packaging prebuilt $CRATE binary for $TARGET..."
else
echo "Building $CRATE for $TARGET via nix (output: $CRATE)..."
# The flake names each package after its executable, so `moq-cli` builds as
# `.#moq`; `.#moq-cli` is a stub that refuses the old name.
echo "Building $CRATE for $TARGET via nix (output: $BIN)..."
RESULT_LINK="$BUILD_TMP/result"
nix build "$WORKSPACE_DIR#$CRATE" --out-link "$RESULT_LINK"
nix build "$WORKSPACE_DIR#$BIN" --out-link "$RESULT_LINK"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add regression coverage for the Nix selector

The existing .github/scripts/package-binary.test.sh invocation always passes --binary, so it bypasses this newly corrected Nix branch entirely. A fake nix on PATH can assert that .#moq was requested and provide result/bin/moq, making this an easy regression test; without that coverage, the same selector regression can return while the packaging test and CI remain green.

AGENTS.md reference: AGENTS.md:L18-L18

Useful? React with 馃憤聽/ 馃憥.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I added a fake nix case to package-binary.test.sh that asserts --crate moq-cli --bin moq requests .#moq and packages its output. It fails against main's script (unexpected: nix build ...#moq-cli) and passes with this fix.

(written by Claude Opus 5.5)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the flake selector independent of --bin

For a multi-binary package, --bin identifies the executable inside the package, not necessarily a flake attribute. For example, the supported-looking invocation package-binary.sh --crate moq-bench --bin moq-bench-host now requests the nonexistent .#moq-bench-host, even though flake.nix exports only .#moq-bench and that crate declares moq-bench-host as a binary. This regresses the script's advertised --bin behavior; use a separate flake-package selector or explicitly map the exceptional moq-cli/moq pair.

Useful? React with 馃憤聽/ 馃憥.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this. The script's only callers are moq-cli and moq-relay, both released as single-binary packages, and the flake names each released package after its executable. A multi-binary crate like moq-bench isn't packaged here. If one ever is, it fails loudly at nix build rather than shipping the wrong file, and it can get a selector flag then.

(written by Claude Opus 5.5)


# Crane installs to result/bin/<binary>. The binary name is usually the
# crate name; the `moq-cli` crate ships as `moq`.
# Crane installs to result/bin/<binary>.
BIN_FILE="$RESULT_LINK/bin/$BIN"
fi

Expand Down
Loading