I have a OS specific binary in a zip file that I w...
# general
p
I have a OS specific binary in a zip file that I want to download for the OS that I'm running pants on. Then unzip it and run the binary with the adhoc_tool.. is that possible? In bazel I can do this with multiple http_archives and switching on the platform. Is environments something I can use here? 🤔
It looks like http_source might have a per_platform https://www.pantsbuild.org/docs/reference-resource#codesourcecode
w
Is this inside a plugin? Or just using adhoc tool? Could you download it using the adhoc tool workflow and use it within the same pipeline?
p
I was going to start with adhoc tooling
👍 1
w
So, I’m not sure off the top of my head if any of Pants’s download tooling gets exposed to adhoc tool, but what about using system_binaries to do it manually?
curl
zip
etc?
Admittedly a bit dirty, as I don’t know if Platform.current is exposed anywhere, which could make the cross-platform bit cleaner
p
Oh I was thinking.. resource (http source (per platform?)) unzip with adhoc tool adhoc tool on unzipped file 🤔
w
Oh, maybe
I’ve never used the http_source. Was that a @bitter-ability-32190 ism?
1
p
I'm trying to make sense of this
Copy code
If a per_platform is provided, represents a mapping from platform to http_source, where the platform is one of (linux_arm64, linux_x86_64, macos_arm64, macos_x86_64) and is resolved in the execution target. Each http_source value MUST have the same filename provided.
I think it is
Copy code
resource(
  name="blah",
  per_platform(
    linux_arm64: blah?
  )
)
w
I can’t help out much as I haven’t used that functionality - but this discussion has opened my eyes to cleaning up a couple of other workflows, if what you’re doing works without a plugin. I’m just so far on the plugin train myself, just make little ones to make my life mildly easier
p
OOOh I was close https://github.com/pantsbuild/pants/blob/f14cdebb57669bdeb789dcc7f12e655e455ea8f3/build-support/bin/act/BUILD#L8-L36 here is almost what I was doing
Copy code
file(
    name="downloaded-act",
    source=per_platform(
        macos_x86_64=http_source(
            url="<https://github.com/nektos/act/releases/download/v0.2.46/act_Darwin_x86_64.tar.gz>",
            len=6289585,
            sha256="503bd4560afa3394fac87c404d4b34d1b422b8bb136b7f4ddaab27d08367700a",
            filename="act.tar.gz",
        ),
        macos_arm64=http_source(
            url="<https://github.com/nektos/act/releases/download/v0.2.46/act_Darwin_arm64.tar.gz>",
            len=6015670,
            sha256="6e5aae98192747d9430625cf0ac42e9fbcdbd9bc5e2558eb0297d0e2f9f2b2a8",
            filename="act.tar.gz",
        ),
        linux_x86_64=http_source(
            url="<https://github.com/nektos/act/releases/download/v0.2.46/act_Linux_x86_64.tar.gz>",
            len=6079499,
            sha256="19d5cdf534f892c1b62c32765c3982e2eb1334d66de4cc7e4a0e568cc0256f44",
            filename="act.tar.gz",
        ),
        linux_arm64=http_source(
            url="<https://github.com/nektos/act/releases/download/v0.2.46/act_Linux_arm64.tar.gz>",
            len=5544514,
            sha256="06418ca7430df409940812afe343c00118d7df889b11422232ff31a32a32b737",
            filename="act.tar.gz",
        ),
    ),
)

shell_command(
    name="extracted-act",
    command="tar -xf act.tar.gz",
    tools=["tar", "gzip"],
    execution_dependencies=[":downloaded-act"],
    output_directories=["act"],
)

file(
    name=".actrc",
    source=".actrc",
)
@wide-midnight-78598 This worked for my tool
Copy code
file(
    name="downloaded-balena-cli",
    source=per_platform(
        macos_x86_64=http_source(
            url="<https://github.com/balena-io/balena-cli/releases/download/v16.6.4/balena-cli-v16.6.4-macOS-x64-standalone.zip>",
            len=75226655,
            sha256="cd698271a65b4337da14b4b4f883df19a7abe9f6feeb64365a3f22c58beaf4aa",
            filename="balena-cli.zip",
        ),
        linux_x86_64=http_source(
            url="<https://github.com/balena-io/balena-cli/releases/download/v16.6.4/balena-cli-v16.6.4-linux-x64-standalone.zip>",
            len=73597750,
            sha256="ddd65f922bbedd37d4be81c809f4b1bd0731ea88c5ec1031b77d90e2f3dd3d78",
            filename="balena-cli.zip",
        ),
    ),
)

shell_command(
    name="extracted-balena-cli",
    command="unzip -o balena-cli.zip",
    tools=["unzip"],
    execution_dependencies=[":downloaded-balena-cli"],
    output_directories=["balena-cli"],
)

relocated_files(
    name="balena-at-root",
    files_targets=[":extracted-balena-cli"],
    src=f"{build_file_dir()}",
    dest="",
)

run_shell_command(
    name="balena",
    command="XDG_CONFIG_DIRS=${CHROOT}:$XDG_CONFIG_DIRS {chroot}/balena-cli/balena $@",
    workdir="/",
    execution_dependencies=[":balena-at-root"],
)
🎉 1
b
LGTM 😊