view third_party/tectonic/runtime.bzl @ 247:70f2a3dafc1c

[build] Bundle offline Tectonic runtime Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Mon, 03 Aug 2026 20:20:06 -0700
parents
children
line wrap: on
line source

def _tectonic_runtime_impl(ctx):
    output = ctx.actions.declare_directory(ctx.label.name)
    commands = [
        "set -e",
        "mkdir -p {}/bin {}/cache {}/sysroot/etc/fonts {}/sysroot/usr/share/fontconfig/conf.avail".format(
            output.path,
            output.path,
            output.path,
            output.path,
        ),
        "cp {} {}/bin/tectonic".format(ctx.file.binary.path, output.path),
        "cp {} {}/sysroot/etc/fonts/fonts.conf".format(
            ctx.file.fontconfig.path,
            output.path,
        ),
        "cp {} {}/LICENSE".format(ctx.file.license.path, output.path),
        "cp {} {}/THIRD_PARTY_NOTICES.md".format(
            ctx.file.notices.path,
            output.path,
        ),
        "tar -xzf {} -C {}/cache".format(
            ctx.file.cache_archive.path,
            output.path,
        ),
        "chmod 0555 {}/bin/tectonic".format(output.path),
        "chmod 0444 {}/sysroot/etc/fonts/fonts.conf".format(output.path),
        "chmod 0444 {}/LICENSE {}/THIRD_PARTY_NOTICES.md".format(
            output.path,
            output.path,
        ),
    ]
    commands.append("chmod -R a-w {}/cache".format(output.path))

    ctx.actions.run_shell(
        inputs = [
            ctx.file.binary,
            ctx.file.cache_archive,
            ctx.file.fontconfig,
            ctx.file.license,
            ctx.file.notices,
        ],
        outputs = [output],
        command = "\n".join(commands),
        progress_message = "Assembling offline Tectonic runtime",
    )
    return [
        DefaultInfo(
            files = depset([output]),
            runfiles = ctx.runfiles(files = [output]),
        ),
    ]

tectonic_runtime = rule(
    implementation = _tectonic_runtime_impl,
    attrs = {
        "binary": attr.label(allow_single_file = True, mandatory = True),
        "cache_archive": attr.label(allow_single_file = True, mandatory = True),
        "fontconfig": attr.label(allow_single_file = True, mandatory = True),
        "license": attr.label(allow_single_file = True, mandatory = True),
        "notices": attr.label(allow_single_file = True, mandatory = True),
    },
)