Skip to content
  • Matthew Clarkson's avatar
    feat: add `debian_launcher`/`patchelf_unpack` rules · b07e4e17
    Matthew Clarkson authored and Matthew Clarkson's avatar Matthew Clarkson committed
    Use `patchelf_unpack` to unpack the downloaded packages and patch the ELF interpreter path:
    
    ```py
    patchelf_unpack(
        name = "patched",
        # `rules_distroless#apt` extension is *highly* recommended
        srcs = ["@debian-bookworm-qemu//:packages"],
        filters = [
            "usr/share/doc/**",       # No need to unpack documentation
            "lib64/ld-linux-*.so.?",  # Remove dangling symlink
        ],
    )
    ```
    
    Use `patchelf_launcher` to launch a binary from the unpacked directory:
    
    ```py
    patchelf_launcher(
        name = "qemu-system-x86_64",
        srcs = [
            ":patched",
            "@rules_patchelf//patchelf/launcher/elf/interpreter/debian",
            "@rules_patchelf//patchelf/launcher/library/path/debian",
        ],
        env = {
            "TMPDIR": "./tmp",
        },
    )
    ```
    
    Run the binary:
    
    ```console
    $ bazelisk run -- :qemu-system-x86_64 --version
    QEMU emulator version 7.2.13 (Debian 1:7.2+dfsg-7+deb12u7)
    Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers
    ```
    
    Closes rfc#1
    b07e4e17