From 61d80d212f139ff55986cc211369b975173d2f7a Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 28 Nov 2026 11:56:30 -0800 Subject: [PATCH 1/3] release: ship debug-symbol sidecars per REL-009 (#296) Split the release binary's line tables into fastled-v--symbols.tar.zst per target (Linux post-link objcopy split, macOS packed .dSYM + strip -x, Windows .pdb), gate the release preflight and create-release on one sidecar per target, and list every asset in SHA256SUMS. --- .github/workflows/_build.yml | 34 ++++- .github/workflows/auto-release.yml | 27 +++- Cargo.toml | 6 +- ci/stage_symbols.py | 222 +++++++++++++++++++++++++++++ tests/unit/test_stage_symbols.py | 187 ++++++++++++++++++++++++ 5 files changed, 472 insertions(+), 4 deletions(-) create mode 100644 ci/stage_symbols.py create mode 100644 tests/unit/test_stage_symbols.py diff --git a/.github/workflows/_build.yml b/.github/workflows/_build.yml index fcaada0a..78896142 100644 --- a/.github/workflows/_build.yml +++ b/.github/workflows/_build.yml @@ -119,6 +119,11 @@ jobs: env: CARGO_TARGET_TRIPLE: ${{ inputs.rust-target != 'x86_64-unknown-linux-gnu' && inputs.rust-target || '' }} run: | + # REL-009: darwin keeps a packed .dSYM for the symbols sidecar; + # Linux stays split-debuginfo "off" and is split post-link. + case "${{ inputs.rust-target }}" in + *apple-darwin) export CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO=packed ;; + esac if [ -n "$CARGO_TARGET_TRIPLE" ]; then soldr cargo build --release --bin fastled --target "$CARGO_TARGET_TRIPLE" case "$CARGO_TARGET_TRIPLE" in @@ -144,9 +149,27 @@ jobs: BIN_SRC="target/release/${EXE_NAME}" fi fi + echo "FASTLED_BIN_SRC=$BIN_SRC" >> "$GITHUB_ENV" + echo "FASTLED_EXE_NAME=$EXE_NAME" >> "$GITHUB_ENV" + ls -lh "$BIN_SRC" + + # REL-009 (#296): move the line tables into + # fastled-v--symbols.tar.zst and slim the cargo output + # in place (setup.py re-copies it into the wheel), before Authenticode + # signing so the signed bytes are the shipped bytes. A missing sidecar + # fails the build. + - name: Split debug symbols into the release sidecar + env: + RUST_TARGET: ${{ inputs.rust-target }} + run: | + if [ -z "$RUST_TARGET" ]; then + echo "::error::REL-009 sidecars need an explicit rust-target" >&2 + exit 1 + fi + python ci/stage_symbols.py stage --binary "$FASTLED_BIN_SRC" --triple "$RUST_TARGET" --out symbols mkdir -p src/fastled/bin - cp -f "$BIN_SRC" "src/fastled/bin/${EXE_NAME}" - ls -lh src/fastled/bin/ + cp -f "$FASTLED_BIN_SRC" "src/fastled/bin/${FASTLED_EXE_NAME}" + ls -lh src/fastled/bin/ symbols/ # Azure Artifact Signing (Authenticode), OIDC only. Signs the cargo # output in place (setup.py re-copies it into the wheel) and the bundled @@ -253,6 +276,13 @@ jobs: path: src/fastled/bin/fastled* if-no-files-found: error + - name: Upload debug-symbol sidecar + uses: actions/upload-artifact@v4 + with: + name: symbols-${{ inputs.runs-on }}-${{ inputs.rust-target || 'native' }} + path: symbols/*-symbols.tar.zst + if-no-files-found: error + - name: Upload failure logs if: failure() uses: actions/upload-artifact@v4 diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml index 8e03b895..0bfe67c4 100644 --- a/.github/workflows/auto-release.yml +++ b/.github/workflows/auto-release.yml @@ -197,6 +197,14 @@ jobs: with: pattern: binary-* path: binaries + - uses: actions/download-artifact@v4 + with: + pattern: symbols-* + path: symbols + - name: Check debug-symbol sidecars before tagging (REL-009) + env: + VERSION: ${{ needs.detect-version.outputs.version }} + run: python ci/stage_symbols.py check --symbols symbols --version "$VERSION" - name: Check wheel and binary artifacts before tagging env: VERSION: ${{ needs.detect-version.outputs.version }} @@ -310,6 +318,17 @@ jobs: pattern: binary-* path: binaries + - uses: actions/checkout@v5 + with: + ref: ${{ inputs.candidate_sha }} + path: src + + - name: Download debug-symbol sidecars + uses: actions/download-artifact@v4 + with: + pattern: symbols-* + path: symbols + - name: Prepare release files shell: bash run: | @@ -326,12 +345,16 @@ jobs: esac done cd .. + # REL-009: one sidecar per target; a missing one fails the release. + python src/ci/stage_symbols.py check --symbols symbols --version "${{ needs.detect-version.outputs.version }}" + find symbols -name '*-symbols.tar.zst' -exec cp {} release/ \; + python src/ci/stage_symbols.py sums --dir release ls -la release/ - name: Sign release artifacts with sigstore uses: sigstore/gh-action-sigstore-python@v3.3.0 with: - inputs: ./release/*.zip + inputs: ./release/*.zip ./release/*-symbols.tar.zst ./release/SHA256SUMS release-signing-artifacts: true - name: Create GitHub Release @@ -340,6 +363,8 @@ jobs: tag_name: v${{ needs.detect-version.outputs.version }} files: | release/*.zip + release/*-symbols.tar.zst + release/SHA256SUMS release/*.sigstore draft: false prerelease: false diff --git a/Cargo.toml b/Cargo.toml index e88b1592..eda6efcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,11 @@ kernal-api = { version = "=0.1.19", features = ["fs", "fs-watch", "hash-sha256", [profile.release] debug = "line-tables-only" -split-debuginfo = "packed" +# REL-009 (#296): ci/stage_symbols.py carves the line tables into a +# per-target -symbols.tar.zst sidecar after linking. Linux stays "off" +# (post-link objcopy split); darwin release builds override to "packed" via +# CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO in _build.yml for the .dSYM. +split-debuginfo = "off" strip = "none" [profile.dev.package.kernal-api] diff --git a/ci/stage_symbols.py b/ci/stage_symbols.py new file mode 100644 index 00000000..00cc8173 --- /dev/null +++ b/ci/stage_symbols.py @@ -0,0 +1,222 @@ +"""Stage REL-009 debug-symbol sidecars for the released fastled binary (#296). + +The release profile builds with ``debug = "line-tables-only"`` and no +build-time strip, so the linked binary carries its line tables. This script +then moves them into a per-target sidecar, +``fastled-v--symbols.tar.zst``, and slims the shipped binary: + +* Linux: post-link carve-out -- ``objcopy --only-keep-debug`` -> + ``strip --strip-debug`` -> ``objcopy --add-gnu-debuglink``. rustc's own + ``split-debuginfo = "packed"`` misses std and cc-built objects and + duplicates DWARF instead (forge-ci/soldr docs/DEBUG_SIDECARS.md). +* macOS: the ``fastled.dSYM`` bundle (cargo's packed output when present, + otherwise ``dsymutil``), then ``strip -x``. +* Windows MSVC: the linker's ``fastled.pdb``; the PE is left untouched. + +A missing sidecar is an error, never a skip. + +Usage: + stage_symbols.py stage --binary --triple [--version V] --out + stage_symbols.py check --symbols [--version V] + stage_symbols.py sums --dir +""" + +from __future__ import annotations + +import argparse +import hashlib +import io +import platform +import shutil +import subprocess +import sys +import tarfile +import tempfile +import tomllib +from collections.abc import Callable +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +NAME = "fastled" +TARGETS = ( + "x86_64-unknown-linux-gnu", + "aarch64-unknown-linux-gnu", + "x86_64-pc-windows-msvc", + "aarch64-pc-windows-msvc", + "x86_64-apple-darwin", + "aarch64-apple-darwin", +) + +Runner = Callable[[list[str]], None] + + +class SidecarError(RuntimeError): + """A sidecar could not be produced or is missing.""" + + +def run_tool(argv: list[str]) -> None: + print("+ " + " ".join(argv), flush=True) + subprocess.run(argv, check=True) + + +def workspace_version(root: Path = ROOT) -> str: + data = tomllib.loads((root / "Cargo.toml").read_text(encoding="utf-8")) + return str(data["workspace"]["package"]["version"]) + + +def sidecar_name(version: str, triple: str) -> str: + return f"{NAME}-v{version}-{triple}-symbols.tar.zst" + + +def compress(data: bytes) -> bytes: + return _zstd(["-q", "-19", "-c"], data) + + +def decompress(data: bytes) -> bytes: + return _zstd(["-q", "-d", "-c"], data) + + +def _zstd(args: list[str], data: bytes) -> bytes: + exe = shutil.which("zstd") + if exe is None: + raise SidecarError("zstd CLI not found; it is required to pack sidecars") + with tempfile.TemporaryDirectory() as tmp: + src = Path(tmp) / "in" + dst = Path(tmp) / "out" + src.write_bytes(data) + with dst.open("wb") as out: + subprocess.run([exe, *args, str(src)], check=True, stdout=out) + return dst.read_bytes() + + +def _binutil(tool: str, triple: str, host_machine: str) -> str: + arch = triple.split("-", 1)[0] + host = {"amd64": "x86_64", "arm64": "aarch64"}.get( + host_machine.lower(), host_machine.lower() + ) + return tool if arch == host else f"{arch}-linux-gnu-{tool}" + + +def _split_linux( + binary: Path, triple: str, work: Path, run: Runner, host_machine: str +) -> Path: + debug = work / f"{NAME}.debug" + objcopy = _binutil("objcopy", triple, host_machine) + run([objcopy, "--only-keep-debug", str(binary), str(debug)]) + run([_binutil("strip", triple, host_machine), "--strip-debug", str(binary)]) + run([objcopy, f"--add-gnu-debuglink={debug}", str(binary)]) + return debug + + +def _split_macos(binary: Path, work: Path, run: Runner) -> Path: + packed = binary.with_name(f"{binary.name}.dSYM") + dsym = work / f"{NAME}.dSYM" + if packed.is_dir(): + shutil.copytree(packed, dsym) + else: + run(["dsymutil", str(binary), "-o", str(dsym)]) + run(["strip", "-x", str(binary)]) + return dsym + + +def _windows_pdb(binary: Path, work: Path) -> Path: + pdb = binary.with_suffix(".pdb") + if not pdb.is_file(): + raise SidecarError(f"expected the linker's pdb next to {binary}: {pdb}") + staged = work / f"{NAME}.pdb" + shutil.copy2(pdb, staged) + return staged + + +def stage( + binary: Path, + triple: str, + version: str, + out: Path, + run: Runner = run_tool, + host_machine: str | None = None, +) -> Path: + """Split ``binary`` in place and write its sidecar archive into ``out``.""" + if not binary.is_file(): + raise SidecarError(f"release binary not found: {binary}") + out.mkdir(parents=True, exist_ok=True) + if "linux" in triple: + symbols = _split_linux( + binary, triple, out, run, host_machine or platform.machine() + ) + elif "apple-darwin" in triple: + symbols = _split_macos(binary, out, run) + elif "windows-msvc" in triple: + symbols = _windows_pdb(binary, out) + else: + raise SidecarError(f"no sidecar policy for target {triple}") + if not symbols.exists() or (symbols.is_file() and symbols.stat().st_size == 0): + raise SidecarError(f"sidecar was not produced for {triple}: {symbols}") + buffer = io.BytesIO() + with tarfile.open(fileobj=buffer, mode="w") as tar: + tar.add(symbols, arcname=symbols.name) + archive = out / sidecar_name(version, triple) + archive.write_bytes(compress(buffer.getvalue())) + print( + f"{triple}: binary {binary.stat().st_size} bytes, " + f"sidecar {archive.name} {archive.stat().st_size} bytes" + ) + return archive + + +def check(symbols_root: Path, version: str) -> list[Path]: + """Return one sidecar per release target, or fail naming the missing ones.""" + found = {path.name: path for path in symbols_root.rglob("*-symbols.tar.zst")} + missing = [t for t in TARGETS if sidecar_name(version, t) not in found] + if missing: + raise SidecarError(f"missing debug-symbol sidecars for: {', '.join(missing)}") + sidecars = [found[sidecar_name(version, t)] for t in TARGETS] + empty = [p for p in sidecars if p.stat().st_size == 0] + if empty: + raise SidecarError(f"empty debug-symbol sidecars: {empty}") + return sidecars + + +def write_sha256sums(release_dir: Path) -> Path: + lines = [] + for path in sorted(release_dir.iterdir()): + if path.is_file() and path.name != "SHA256SUMS": + digest = hashlib.sha256(path.read_bytes()).hexdigest() + lines.append(f"{digest} {path.name}\n") + sums = release_dir / "SHA256SUMS" + sums.write_text("".join(lines), encoding="utf-8") + return sums + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__) + sub = parser.add_subparsers(dest="command", required=True) + p_stage = sub.add_parser("stage") + p_stage.add_argument("--binary", type=Path, required=True) + p_stage.add_argument("--triple", required=True) + p_stage.add_argument("--version") + p_stage.add_argument("--out", type=Path, required=True) + p_check = sub.add_parser("check") + p_check.add_argument("--symbols", type=Path, required=True) + p_check.add_argument("--version") + p_sums = sub.add_parser("sums") + p_sums.add_argument("--dir", type=Path, required=True) + args = parser.parse_args(argv) + try: + if args.command == "stage": + stage( + args.binary, args.triple, args.version or workspace_version(), args.out + ) + elif args.command == "check": + for path in check(args.symbols, args.version or workspace_version()): + print(f"{path.name} {path.stat().st_size} bytes") + else: + print(write_sha256sums(args.dir).read_text(encoding="utf-8"), end="") + except SidecarError as error: + print(f"error: {error}", file=sys.stderr) + return 1 + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/unit/test_stage_symbols.py b/tests/unit/test_stage_symbols.py new file mode 100644 index 00000000..f1797806 --- /dev/null +++ b/tests/unit/test_stage_symbols.py @@ -0,0 +1,187 @@ +"""Tests for ci/stage_symbols.py (REL-009 debug-symbol sidecars, #296).""" + +import importlib.util +import io +import sys +import tarfile +from pathlib import Path + +import pytest + +ROOT = Path(__file__).resolve().parents[2] +WORKFLOWS = ROOT / ".github" / "workflows" +SPEC = importlib.util.spec_from_file_location( + "stage_symbols", ROOT / "ci" / "stage_symbols.py" +) +assert SPEC and SPEC.loader +stage = importlib.util.module_from_spec(SPEC) +sys.modules[SPEC.name] = stage +SPEC.loader.exec_module(stage) + +VERSION = "2.0.23" + + +class Recorder: + def __init__(self) -> None: + self.calls: list[list[str]] = [] + + def __call__(self, argv: list[str]) -> None: + self.calls.append(argv) + # Emulate the tools' file effects so staging can archive them. + if argv[0].endswith("objcopy") and argv[1] == "--only-keep-debug": + Path(argv[3]).write_bytes(b"DWARF") + if argv[0] == "dsymutil": + out = Path(argv[argv.index("-o") + 1]) + (out / "Contents" / "Resources" / "DWARF").mkdir(parents=True) + (out / "Contents" / "Resources" / "DWARF" / "fastled").write_bytes(b"D") + + +def _members(archive: Path) -> list[str]: + data = stage.decompress(archive.read_bytes()) + with tarfile.open(fileobj=io.BytesIO(data)) as tar: + return sorted(tar.getnames()) + + +def test_sidecar_name() -> None: + assert ( + stage.sidecar_name(VERSION, "x86_64-unknown-linux-gnu") + == "fastled-v2.0.23-x86_64-unknown-linux-gnu-symbols.tar.zst" + ) + + +def test_linux_post_link_split_order(tmp_path: Path) -> None: + binary = tmp_path / "fastled" + binary.write_bytes(b"ELF") + run = Recorder() + out = stage.stage( + binary, + "aarch64-unknown-linux-gnu", + VERSION, + tmp_path / "s", + run, + host_machine="aarch64", + ) + debug = str(tmp_path / "s" / "fastled.debug") + assert run.calls == [ + ["objcopy", "--only-keep-debug", str(binary), debug], + ["strip", "--strip-debug", str(binary)], + ["objcopy", f"--add-gnu-debuglink={debug}", str(binary)], + ] + assert out.name == stage.sidecar_name(VERSION, "aarch64-unknown-linux-gnu") + assert _members(out) == ["fastled.debug"] + + +def test_linux_cross_target_uses_prefixed_binutils(tmp_path: Path) -> None: + binary = tmp_path / "fastled" + binary.write_bytes(b"ELF") + run = Recorder() + stage.stage( + binary, + "aarch64-unknown-linux-gnu", + VERSION, + tmp_path / "s", + run, + host_machine="x86_64", + ) + assert [c[0] for c in run.calls] == [ + "aarch64-linux-gnu-objcopy", + "aarch64-linux-gnu-strip", + "aarch64-linux-gnu-objcopy", + ] + + +def test_macos_dsym_then_strip(tmp_path: Path) -> None: + binary = tmp_path / "fastled" + binary.write_bytes(b"MACHO") + run = Recorder() + out = stage.stage(binary, "aarch64-apple-darwin", VERSION, tmp_path / "s", run) + assert run.calls[0][0] == "dsymutil" + assert run.calls[1] == ["strip", "-x", str(binary)] + assert "fastled.dSYM/Contents/Resources/DWARF/fastled" in _members(out) + + +def test_macos_reuses_packed_dsym(tmp_path: Path) -> None: + binary = tmp_path / "fastled" + binary.write_bytes(b"MACHO") + packed = tmp_path / "fastled.dSYM" / "Contents" + packed.mkdir(parents=True) + (packed / "Info.plist").write_bytes(b"p") + run = Recorder() + out = stage.stage(binary, "x86_64-apple-darwin", VERSION, tmp_path / "s", run) + assert run.calls == [["strip", "-x", str(binary)]] + assert "fastled.dSYM/Contents/Info.plist" in _members(out) + + +def test_windows_ships_pdb(tmp_path: Path) -> None: + binary = tmp_path / "fastled.exe" + binary.write_bytes(b"MZ") + (tmp_path / "fastled.pdb").write_bytes(b"PDB") + run = Recorder() + out = stage.stage(binary, "x86_64-pc-windows-msvc", VERSION, tmp_path / "s", run) + assert run.calls == [] + assert _members(out) == ["fastled.pdb"] + + +def test_windows_missing_pdb_fails(tmp_path: Path) -> None: + binary = tmp_path / "fastled.exe" + binary.write_bytes(b"MZ") + with pytest.raises(stage.SidecarError, match="pdb"): + stage.stage( + binary, "aarch64-pc-windows-msvc", VERSION, tmp_path / "s", Recorder() + ) + + +def test_linux_missing_debug_fails(tmp_path: Path) -> None: + binary = tmp_path / "fastled" + binary.write_bytes(b"ELF") + with pytest.raises(stage.SidecarError): + stage.stage( + binary, "x86_64-unknown-linux-gnu", VERSION, tmp_path / "s", lambda a: None + ) + + +def test_check_requires_every_target(tmp_path: Path) -> None: + for triple in stage.TARGETS: + (tmp_path / f"symbols-x-{triple}").mkdir() + ( + tmp_path / f"symbols-x-{triple}" / stage.sidecar_name(VERSION, triple) + ).write_bytes(b"z") + assert len(stage.check(tmp_path, VERSION)) == len(stage.TARGETS) + ( + tmp_path + / "symbols-x-aarch64-apple-darwin" + / stage.sidecar_name(VERSION, "aarch64-apple-darwin") + ).unlink() + with pytest.raises(stage.SidecarError, match="aarch64-apple-darwin"): + stage.check(tmp_path, VERSION) + + +def test_sha256sums_lists_sidecars(tmp_path: Path) -> None: + (tmp_path / "fastled-linux-x86_64.zip").write_bytes(b"a") + sidecar = stage.sidecar_name(VERSION, "x86_64-unknown-linux-gnu") + (tmp_path / sidecar).write_bytes(b"b") + text = stage.write_sha256sums(tmp_path).read_text() + assert f" {sidecar}\n" in text + assert " fastled-linux-x86_64.zip\n" in text + + +def test_release_profile_keeps_line_tables() -> None: + cargo = (ROOT / "Cargo.toml").read_text() + section = cargo.split("[profile.release]", 1)[1].split("\n[", 1)[0] + assert 'debug = "line-tables-only"' in section + assert 'split-debuginfo = "off"' in section + assert 'strip = "none"' in section + + +def test_workflows_stage_upload_and_gate_sidecars() -> None: + build = (WORKFLOWS / "_build.yml").read_text() + release = (WORKFLOWS / "auto-release.yml").read_text() + assert "ci/stage_symbols.py stage" in build + assert "name: symbols-${{ inputs.runs-on }}" in build + assert build.index("ci/stage_symbols.py stage") < build.index( + "- name: Authenticode-sign" + ) + assert "ci/stage_symbols.py check" in release + assert "ci/stage_symbols.py sums" in release + assert "release/SHA256SUMS" in release + assert "release/*-symbols.tar.zst" in release From 436e42be2d253d8c99078cefdec03071c13bed96 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Sat, 28 Nov 2026 12:43:41 -0800 Subject: [PATCH 2/3] release: fail the preflight when a wheel carries debug symbols (#296) Ci-Attestation: {"at":1795958414,"gate":"general/linux-x64/lint","host":"linux-x86_64","key":"3a29f3041963797ed27a70233639fdc4201fa7c2722b4ec05836014c1c8c48b7","lane":"lint","parents":["61d80d212f139ff55986cc211369b975173d2f7a"],"secs":218,"stamp":"b49c40e604b50f97a2aa78b066a6d270","tree":"204755de7ed0afad14c245e345dc8b3cb3d8bb7f","v":1,"via":"run"} Ci-Attestation: {"at":1795958414,"gate":"rust/all/fmt","host":"linux-x86_64","key":"3a29f3041963797ed27a70233639fdc4201fa7c2722b4ec05836014c1c8c48b7","lane":"lint","parents":["61d80d212f139ff55986cc211369b975173d2f7a"],"secs":218,"stamp":"cb450d8c7c49270fc17889c62543955f","tree":"204755de7ed0afad14c245e345dc8b3cb3d8bb7f","v":1,"via":"run"} Ci-Attestation: {"at":1795958414,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"3a29f3041963797ed27a70233639fdc4201fa7c2722b4ec05836014c1c8c48b7","lane":"lint","parents":["61d80d212f139ff55986cc211369b975173d2f7a"],"secs":218,"stamp":"fe0db44f2a0e163b6186abdfea90e7c4","tree":"204755de7ed0afad14c245e345dc8b3cb3d8bb7f","v":1,"via":"run"} Ci-Attestation: {"at":1795958414,"gate":"rust/x86_64-unknown-linux-gnu/dylint","host":"linux-x86_64","key":"3a29f3041963797ed27a70233639fdc4201fa7c2722b4ec05836014c1c8c48b7","lane":"lint","parents":["61d80d212f139ff55986cc211369b975173d2f7a"],"secs":218,"stamp":"3c71a64ae4466d4ae6ecfcee826e66a9","tree":"204755de7ed0afad14c245e345dc8b3cb3d8bb7f","v":1,"via":"run"} --- ci/release_artifact_lint.py | 50 +++++++++++++++++++++++++++++++++++++ tests/unit/test_ci_modes.py | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/ci/release_artifact_lint.py b/ci/release_artifact_lint.py index 14074edd..ddd998e9 100644 --- a/ci/release_artifact_lint.py +++ b/ci/release_artifact_lint.py @@ -17,6 +17,48 @@ "aarch64-apple-darwin": "macosx_11_0_arm64", } MAX_WHEEL_BYTES = 100_000_000 # Conservative PyPI per-file limit. +# REL-009 owner rule (#296): debug symbols ship only as GitHub release +# sidecars, never inside a wheel. +SYMBOL_SUFFIXES = (".pdb", ".debug", ".dwp", ".dwo", "-symbols.tar.zst") + + +def _elf_debug_sections(data: bytes) -> list[str]: + """Names of .debug_*/.zdebug_* sections in a little-endian ELF64 image.""" + if len(data) < 64 or data[:4] != b"\x7fELF" or data[4:6] != b"\x02\x01": + return [] + shoff = int.from_bytes(data[0x28:0x30], "little") + shentsize = int.from_bytes(data[0x3A:0x3C], "little") + shnum = int.from_bytes(data[0x3C:0x3E], "little") + shstrndx = int.from_bytes(data[0x3E:0x40], "little") + if shentsize < 64 or shstrndx >= shnum or shoff + shnum * shentsize > len(data): + return [] + + def header(index: int) -> bytes: + start = shoff + index * shentsize + return data[start : start + 64] + + strtab = header(shstrndx) + str_off = int.from_bytes(strtab[0x18:0x20], "little") + str_size = int.from_bytes(strtab[0x20:0x28], "little") + names = data[str_off : str_off + str_size] + found = [] + for index in range(shnum): + name_off = int.from_bytes(header(index)[0:4], "little") + name = names[name_off:].split(b"\0", 1)[0].decode("latin-1") + if name.startswith((".debug_", ".zdebug_")): + found.append(name) + return found + + +def wheel_symbol_problems(members: dict[str, bytes]) -> list[str]: + """Symbol files or unstripped ELF binaries among a wheel's members.""" + problems = [] + for name, data in members.items(): + if ".dSYM/" in name or name.endswith((".dSYM", *SYMBOL_SUFFIXES)): + problems.append(f"{name}: debug-symbol file in wheel") + elif sections := _elf_debug_sections(data): + problems.append(f"{name}: unstripped debug sections {sections}") + return problems def check(wheel_root: Path, binary_root: Path, version: str) -> dict: @@ -57,6 +99,14 @@ def check(wheel_root: Path, binary_root: Path, version: str) -> dict: raise ValueError( f"invalid wheel archive: {path} (bad member: {bad_member})" ) + problems = wheel_symbol_problems( + { + name: archive.read(name) if name.startswith("fastled/bin/") else b"" + for name in archive.namelist() + } + ) + if problems: + raise ValueError(f"symbols in wheel {path.name}: {problems}") wheels.append({"name": path.name, "bytes": size}) binary_dirs = ( diff --git a/tests/unit/test_ci_modes.py b/tests/unit/test_ci_modes.py index 92a32be3..a2557ea9 100644 --- a/tests/unit/test_ci_modes.py +++ b/tests/unit/test_ci_modes.py @@ -420,6 +420,51 @@ def test_release_artifact_lint_checks_exact_six_wheels_and_binaries(tmp_path): artifacts.check(wheels, binaries, "2.0.23") +def _elf64(section_names): + """A minimal little-endian ELF64 image whose section headers name `section_names`.""" + import struct + + names = ["", *section_names, ".shstrtab"] + strtab = b"" + offsets = [] + for name in names: + offsets.append(len(strtab)) + strtab += name.encode() + b"\0" + shoff = 64 + len(strtab) + header = b"\x7fELF\x02\x01\x01" + b"\0" * 9 + header += struct.pack( + " Date: Sun, 29 Nov 2026 05:31:49 -0800 Subject: [PATCH 3/3] fix(release): ship the staged stripped binary in the wheel; stub zstd in unit tests (#296) Ci-Attestation: {"at":1795959131,"gate":"general/linux-x64/lint","host":"linux-x86_64","key":"3f53ea2951a202b8a2a1ffeeff207d0b90159efb90b8705b53ca7175598e6711","lane":"lint","parents":["436e42be2d253d8c99078cefdec03071c13bed96"],"secs":5,"stamp":"9943367a5a527e775f2318bcf6074760","tree":"fc81c8fc09ab8398b61312d1c2757e56c0c0bd0c","v":1,"via":"run"} Ci-Attestation: {"at":1795959217,"gate":"python/linux-x64/test","host":"linux-x86_64","key":"3d56f235b0322560de6a96700b308becd98051af10f0ed881a197a8d532d8cef","lane":"test","parents":["436e42be2d253d8c99078cefdec03071c13bed96"],"secs":85,"stamp":"81e0b86744f76c4c26a72cf64550b07d","tree":"fc81c8fc09ab8398b61312d1c2757e56c0c0bd0c","v":1,"via":"run"} Ci-Attestation: {"at":1795959131,"gate":"rust/all/fmt","host":"linux-x86_64","key":"3f53ea2951a202b8a2a1ffeeff207d0b90159efb90b8705b53ca7175598e6711","lane":"lint","parents":["436e42be2d253d8c99078cefdec03071c13bed96"],"secs":5,"stamp":"14f36feb3bd998050aece90d5e0da300","tree":"fc81c8fc09ab8398b61312d1c2757e56c0c0bd0c","v":1,"via":"run"} Ci-Attestation: {"at":1795959131,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"3f53ea2951a202b8a2a1ffeeff207d0b90159efb90b8705b53ca7175598e6711","lane":"lint","parents":["436e42be2d253d8c99078cefdec03071c13bed96"],"secs":5,"stamp":"8e38cd95006d4ccf8ce04ab0d9bacb6d","tree":"fc81c8fc09ab8398b61312d1c2757e56c0c0bd0c","v":1,"via":"run"} Ci-Attestation: {"at":1795959131,"gate":"rust/x86_64-unknown-linux-gnu/dylint","host":"linux-x86_64","key":"3f53ea2951a202b8a2a1ffeeff207d0b90159efb90b8705b53ca7175598e6711","lane":"lint","parents":["436e42be2d253d8c99078cefdec03071c13bed96"],"secs":5,"stamp":"478d63843a725811ef775116862a20a8","tree":"fc81c8fc09ab8398b61312d1c2757e56c0c0bd0c","v":1,"via":"run"} Ci-Attestation: {"at":1795959217,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"3d56f235b0322560de6a96700b308becd98051af10f0ed881a197a8d532d8cef","lane":"test","parents":["436e42be2d253d8c99078cefdec03071c13bed96"],"secs":85,"stamp":"083236e246336da2ca4c38b08875161c","tree":"fc81c8fc09ab8398b61312d1c2757e56c0c0bd0c","v":1,"via":"run"} --- .github/workflows/_build.yml | 9 +++++++- setup.py | 15 +++++++++++++ tests/unit/test_setup_packaging.py | 35 ++++++++++++++++++++++++++++++ tests/unit/test_stage_symbols.py | 20 +++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) diff --git a/.github/workflows/_build.yml b/.github/workflows/_build.yml index 78896142..f7565e61 100644 --- a/.github/workflows/_build.yml +++ b/.github/workflows/_build.yml @@ -122,7 +122,11 @@ jobs: # REL-009: darwin keeps a packed .dSYM for the symbols sidecar; # Linux stays split-debuginfo "off" and is split post-link. case "${{ inputs.rust-target }}" in - *apple-darwin) export CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO=packed ;; + *apple-darwin) + export CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO=packed + # Persist for every later Cargo invocation in this job. + echo "CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO=packed" >> "$GITHUB_ENV" + ;; esac if [ -n "$CARGO_TARGET_TRIPLE" ]; then soldr cargo build --release --bin fastled --target "$CARGO_TARGET_TRIPLE" @@ -207,6 +211,9 @@ jobs: # Native for x86_64 Linux, for the same reason as the build step. FASTLED_RUST_TARGET: ${{ inputs.rust-target != 'x86_64-unknown-linux-gnu' && inputs.rust-target || '' }} run: | + # REL-009 (#296): ship the stripped (and signed) binary staged above; + # setup.py must not rebuild it, or the sidecar would not match. + export FASTLED_STAGED_BINARY="$FASTLED_BIN_SRC" PLAT_NAME="" case "${{ inputs.rust-target }}" in aarch64-pc-windows-msvc) PLAT_NAME="win_arm64" ;; diff --git a/setup.py b/setup.py index a0147eb4..18e86b81 100644 --- a/setup.py +++ b/setup.py @@ -89,6 +89,21 @@ def _copy_first_available_binary(root: Path) -> bool: def ensure_bundled_fastled_binary(root: Path = ROOT) -> None: dest = root / "src" / "fastled" / "bin" / EXE_NAME + staged = os.environ.get("FASTLED_STAGED_BINARY") + if staged: + # REL-009 (#296): CI already built, symbol-split and signed this + # binary; rebuilding would replace it and orphan its sidecar. + src = Path(staged) + if not src.is_absolute(): + src = root / src + if not src.is_file(): + raise RuntimeError(f"FASTLED_STAGED_BINARY not found: {src}") + _remove_stale_bundled_binaries(root) + dest.parent.mkdir(parents=True, exist_ok=True) + shutil.copy2(src, dest) + os.utime(dest) + return + if (root / "Cargo.toml").is_file(): # Source build: a pre-existing binary may predate the current source # (issue #165 shipped a broken viewer for days this way), so always diff --git a/tests/unit/test_setup_packaging.py b/tests/unit/test_setup_packaging.py index d7e592c0..5cb20efe 100644 --- a/tests/unit/test_setup_packaging.py +++ b/tests/unit/test_setup_packaging.py @@ -140,3 +140,38 @@ def test_copy_prefers_arch_target_and_refreshes_mtime( dest = root / "src" / "fastled" / "bin" / mod.EXE_NAME assert dest.read_bytes() == b"FRESH" assert dest.stat().st_mtime > old, "dest mtime must be refreshed, not copied" + + +def test_staged_binary_skips_rebuild(setup_module, tmp_path, monkeypatch): + """REL-009 (#296): a staged (stripped, signed) binary ships as-is. + + Rebuilding after staging would replace the stripped executable (on Darwin + with a different split-debuginfo profile) while the sidecar still matches + the earlier build. + """ + mod = setup_module + root = tmp_path + (root / "Cargo.toml").write_text("[workspace]\n", encoding="utf-8") + staged = root / "target" / "release" / mod.EXE_NAME + staged.parent.mkdir(parents=True) + staged.write_bytes(b"STRIPPED") + + def no_cargo(cmd, cwd=None): + raise AssertionError(f"cargo must not run for a staged binary: {cmd}") + + monkeypatch.setattr(mod.subprocess, "check_call", no_cargo) + monkeypatch.setenv("FASTLED_STAGED_BINARY", str(staged)) + + mod.ensure_bundled_fastled_binary(root) + + assert (root / "src" / "fastled" / "bin" / mod.EXE_NAME).read_bytes() == ( + b"STRIPPED" + ) + + +def test_missing_staged_binary_fails(setup_module, tmp_path, monkeypatch): + mod = setup_module + (tmp_path / "Cargo.toml").write_text("[workspace]\n", encoding="utf-8") + monkeypatch.setenv("FASTLED_STAGED_BINARY", str(tmp_path / "nope")) + with pytest.raises(RuntimeError, match="FASTLED_STAGED_BINARY"): + mod.ensure_bundled_fastled_binary(tmp_path) diff --git a/tests/unit/test_stage_symbols.py b/tests/unit/test_stage_symbols.py index f1797806..5ccecbd8 100644 --- a/tests/unit/test_stage_symbols.py +++ b/tests/unit/test_stage_symbols.py @@ -2,6 +2,7 @@ import importlib.util import io +import shutil import sys import tarfile from pathlib import Path @@ -20,6 +21,25 @@ VERSION = "2.0.23" +# The real zstd codec, kept for the one test that exercises it. +REAL_COMPRESS = stage.compress +REAL_DECOMPRESS = stage.decompress + + +@pytest.fixture(autouse=True) +def _no_zstd(monkeypatch: pytest.MonkeyPatch) -> None: + """Orchestration tests must not need the zstd CLI (./install omits it).""" + monkeypatch.setattr(stage, "compress", lambda data: data) + monkeypatch.setattr(stage, "decompress", lambda data: data) + + +@pytest.mark.skipif(shutil.which("zstd") is None, reason="zstd CLI not installed") +def test_real_zstd_round_trip() -> None: + payload = b"DWARF" * 1000 + packed = REAL_COMPRESS(payload) + assert packed != payload + assert REAL_DECOMPRESS(packed) == payload + class Recorder: def __init__(self) -> None: