Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Distribute compiled binary files via GitHub release #89

Merged
merged 2 commits into from
Nov 8, 2020
Merged

Conversation

taiki-e
Copy link
Owner

@taiki-e taiki-e commented Nov 8, 2020

If you install locally, I basically recommend using cargo install, but given that one of cargo-hack's main purposes is to use it in CI, it makes sense to distribute the compiled binary files.

@taiki-e taiki-e added the C-enhancement Category: A new feature or an improvement for an existing one label Nov 8, 2020
@taiki-e
Copy link
Owner Author

taiki-e commented Nov 8, 2020

UPDATE: See #91 for the currently recommended install script.

To install latest release:

# get latest release and host toolchain
version=$(curl -LsSf https://api.github.com/repos/taiki-e/cargo-hack/releases/latest | jq -r '.name')
host=$(rustc -Vv | grep host | sed 's/host: //')

# linux/macos
curl -LsSf https://github.com/taiki-e/cargo-hack/releases/download/v${version}/cargo-hack-v${version}-${host}.tar.gz | tar xzf -

# windows
curl -LsSf https://github.com/taiki-e/cargo-hack/releases/download/v${version}/cargo-hack-v${version}-${host}.zip -o cargo-hack.zip
7z x cargo-hack.zip

@taiki-e taiki-e force-pushed the release branch 6 times, most recently from fdb8cb2 to 59b085b Compare November 8, 2020 21:59
@taiki-e
Copy link
Owner Author

taiki-e commented Nov 8, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Nov 8, 2020

Build succeeded:

@bors bors bot merged commit 78022ab into master Nov 8, 2020
@bors bors bot deleted the release branch November 8, 2020 22:20
@jhpratt
Copy link
Contributor

jhpratt commented Nov 8, 2020

I will say, we think alike. I've been contemplating whether to file a PR for a couple days for this exact thing 😁

@jhpratt
Copy link
Contributor

jhpratt commented Nov 9, 2020

For those (like myself) looking for a single script to download it, I just added some conditionals to the above.

version=$(curl -LsSf https://api.github.com/repos/taiki-e/cargo-hack/releases/latest | jq -r '.name')
host=$(rustc -Vv | grep host | sed 's/host: //')

if [ $host = 'x86_64-pc-windows-msvc' ]; then
    curl -LsSf https://github.com/taiki-e/cargo-hack/releases/download/v${version}/cargo-hack-v${version}-${host}.zip -o cargo-hack.zip
    7z x cargo-hack.zip
elif [ $host = 'x86_64-apple-darwin' ] || [ $host = 'x86_64-unknown-linux-gnu' ]; then
    curl -LsSf https://github.com/taiki-e/cargo-hack/releases/download/v${version}/cargo-hack-v${version}-${host}.tar.gz | tar xzf -
else
    echo "unsupported operating system"
    exit 1
fi

Use freely, of course.

@taiki-e
Copy link
Owner Author

taiki-e commented Nov 9, 2020

@jhpratt Thanks, that script is really useful:)

@taiki-e
Copy link
Owner Author

taiki-e commented Nov 9, 2020

FWIW, if don't care about the exact name of the toolchain (usually there is no problem), using [[ ... ]] instead of [ ... ] makes it a bit simpler:

- if [ $host = 'x86_64-pc-windows-msvc' ]; then
+ if [[ $host =~ windows ]]; then
      curl -LsSf https://github.com/taiki-e/cargo-hack/releases/download/v${version}/cargo-hack-v${version}-${host}.zip -o cargo-hack.zip
      7z x cargo-hack.zip
- elif [ $host = 'x86_64-apple-darwin' ] || [ $host = 'x86_64-unknown-linux-gnu' ]; then
+ elif [[ $host =~ darwin|linux ]]; then

@jhpratt
Copy link
Contributor

jhpratt commented Nov 9, 2020

That would definitely make things simpler.

I'm currently looking into how I can still add cargo-hack to $PATH for GitHub Actions. For obvious reasons I'd prefer to avoid adding the current directory to the path. I'm honestly not too familiar with what the idiomatic thing to do is if you have any suggestions?

@jhpratt
Copy link
Contributor

jhpratt commented Nov 9, 2020

And completely unrelated to my previous comment, it might be worth stripping the binary before bundling it up. In my experience this typically reduces binary size by about two thirds.

@taiki-e
Copy link
Owner Author

taiki-e commented Nov 9, 2020

I'm currently looking into how I can still add cargo-hack to $PATH for GitHub Actions. For obvious reasons I'd prefer to avoid adding the current directory to the path. I'm honestly not too familiar with what the idiomatic thing to do is if you have any suggestions?

I don't know if that's the idiomatic way, but I think creating a new directory and adding that directory to $PATH is an easy way. Something like the following:

mkdir ci-bin
mv cargo-hack ci-bin/
echo "$(pwd)/ci-bin" >> "${GITHUB_PATH}"

it might be worth stripping the binary before bundling it up. In my experience this typically reduces binary size by about two thirds.

I think that's definitely a good idea, I'll try that.

EDIT: filed #90

@taiki-e taiki-e mentioned this pull request Nov 9, 2020
bors bot added a commit that referenced this pull request Nov 9, 2020
90: ci: Strip release binary r=taiki-e a=taiki-e

#89 (comment)


Co-authored-by: Taiki Endo <[email protected]>
@jhpratt
Copy link
Contributor

jhpratt commented Nov 9, 2020

I've no idea if you're familiar with the way the PATH env var works in Windows, but I certainly don't. Just reporting that doing the following fails on CI (I use Linux personally, and my household doesn't have any Windows machines).

- name: Install cargo-hack
  shell: bash
  run: |
    version=$(curl -LsSf https://api.github.com/repos/taiki-e/cargo-hack/releases/latest | jq -r '.name')
    host=$(rustc -Vv | grep host | sed 's/host: //')

    if [[ $host =~ windows ]]; then
        curl -LsSf https://github.com/taiki-e/cargo-hack/releases/download/v${version}/cargo-hack-v${version}-${host}.zip -o cargo-hack.zip
        7z x cargo-hack.zip
    elif [[ $host =~ darwin|linux ]]; then
        curl -LsSf https://github.com/taiki-e/cargo-hack/releases/download/v${version}/cargo-hack-v${version}-${host}.tar.gz | tar xzf -
    else
        echo "unsupported operating system"
        exit 1
    fi

    mkdir __cargo_hack_bin
    mv cargo-hack __cargo_hack_bin
    echo "$(pwd)/__cargo_hack_bin" >> $GITHUB_PATH

And I see that you've already implemented stripping, but given that the download is <1 second on CI in the previous link, it turns out that minor optimization will probably have an extremely small effect.

@taiki-e
Copy link
Owner Author

taiki-e commented Nov 9, 2020

I've no idea if you're familiar with the way the PATH env var works in Windows, but I certainly don't. Just reporting that doing the following fails on CI (I use Linux personally, and my household doesn't have any Windows machines).

Hmm, it's odd that $GITHUB_PATH doesn't work on windows. (I thought it is the formal way to add path...)
I think the way of moving a binary to a directory that is already in $PATH should probably work:

mv cargo-hack $HOME/.cargo/bin/

@taiki-e
Copy link
Owner Author

taiki-e commented Nov 9, 2020

Hmm, it's odd that $GITHUB_PATH doesn't work on windows. (I thought it is the formal way to add path...)

Oh, this seems to be because the Unix style absolute path (\c\...) returned by bash's pwd is not considered a valid path of Windows. So the following patches work.

          7z x cargo-hack.zip
+         echo "$(pwd)/__cargo_hack_bin" | sed 's/^\///' | sed 's/\//:\\/' >> $GITHUB_PATH
      elif [[ $host =~ darwin|linux ]]; then
          curl -LsSf https://github.com/taiki-e/cargo-hack/releases/download/v${version}/cargo-hack-v${version}-${host}.tar.gz | tar xzf -
+         echo "$(pwd)/__cargo_hack_bin" >> $GITHUB_PATH
      else
      mkdir __cargo_hack_bin
      mv cargo-hack __cargo_hack_bin
-     echo "$(pwd)/__cargo_hack_bin" >> $GITHUB_PATH

However, the way mentioned in my comments above is simpler.

version=$(curl -LsSf https://api.github.com/repos/taiki-e/cargo-hack/releases/latest | jq -r '.name')
host=$(rustc -Vv | grep host | sed 's/host: //')

if [[ $host =~ windows ]]; then
  curl -LsSf https://github.com/taiki-e/cargo-hack/releases/download/v${version}/cargo-hack-v${version}-${host}.zip -o cargo-hack.zip
  7z x cargo-hack.zip
elif [[ $host =~ darwin|linux ]]; then
  curl -LsSf https://github.com/taiki-e/cargo-hack/releases/download/v${version}/cargo-hack-v${version}-${host}.tar.gz | tar xzf -
else
  echo "unsupported operating system"
  exit 1
fi

mv cargo-hack $HOME/.cargo/bin/

@jhpratt
Copy link
Contributor

jhpratt commented Nov 9, 2020

That's some odd behavior. I pulled the mv behavior into the extraction, but that's just personal preference. I can confirm that this works as expected on CI.

version=$(curl -LsSf https://api.github.com/repos/taiki-e/cargo-hack/releases/latest | jq -r '.name')
host=$(rustc -Vv | grep host | sed 's/host: //')

if [[ $host =~ windows ]]; then
    curl -LsSf https://github.com/taiki-e/cargo-hack/releases/download/v${version}/cargo-hack-v${version}-${host}.zip -o cargo-hack.zip
    7z x cargo-hack.zip -o~/.cargo/bin
elif [[ $host =~ darwin|linux ]]; then
    curl -LsSf https://github.com/taiki-e/cargo-hack/releases/download/v${version}/cargo-hack-v${version}-${host}.tar.gz | tar xzf - -C ~/.cargo/bin
else
    echo "unsupported operating system"
    exit 1
fi

@taiki-e
Copy link
Owner Author

taiki-e commented Nov 12, 2020

Hmm, maybe it is better not to include the version number in the release binary. cross-rs/cross#457
That allows installing cargo-hack with one command if you know the host os.
before(current):

version=$(curl -LsSf https://api.github.com/repos/taiki-e/cargo-hack/releases/latest | jq -r '.name')
curl -LsSf https://github.com/taiki-e/cargo-hack/releases/download/v${version}/cargo-hack-v${version}-x86_64-unknown-linux-gnu.tar.gz | tar xzf - -C ~/.cargo/bin

after:

curl -LsSf https://github.com/taiki-e/cargo-hack/releases/latest/download/cargo-hack-x86_64-unknown-linux-gnu.tar.gz | tar xzf - -C ~/.cargo/bin

That said, this will break the CI that depends on the current URL. However, this issue can be avoided by distributing under both names until the next major version (0.5).

UPDATE: filed #91 and released in 0.4.4

bors bot added a commit that referenced this pull request Nov 13, 2020
91: ci: Remove version number from release binaries r=taiki-e a=taiki-e

See also #89 (comment)

This allows installing cargo-hack with one command if you know the host os.
before(current):

```sh
version=$(curl -LsSf https://api.github.com/repos/taiki-e/cargo-hack/releases/latest | jq -r '.name')
curl -LsSf https://github.com/taiki-e/cargo-hack/releases/download/v${version}/cargo-hack-v${version}-x86_64-unknown-linux-gnu.tar.gz | tar xzf - -C ~/.cargo/bin
```

after:

```sh
curl -LsSf https://github.com/taiki-e/cargo-hack/releases/latest/download/cargo-hack-x86_64-unknown-linux-gnu.tar.gz | tar xzf - -C ~/.cargo/bin
```

Script for cross-platform installing to be also a bit simpler.
before(current): #89 (comment)
after:

```sh
host=$(rustc -Vv | grep host | sed 's/host: //')
if [[ $host =~ windows ]]; then
    curl -LsSf https://github.com/taiki-e/cargo-hack/releases/latest/download/cargo-hack-${host}.zip -o cargo-hack.zip
    7z x cargo-hack.zip -o~/.cargo/bin
elif [[ $host =~ darwin|linux ]]; then
    curl -LsSf https://github.com/taiki-e/cargo-hack/releases/latest/download/cargo-hack-${host}.tar.gz | tar xzf - -C ~/.cargo/bin
else
    echo "unsupported operating system"
    exit 1
fi
```

To prevent breaking the CI that depends on the current URL, we will distribute under both names until the next major version (0.5).


Co-authored-by: Taiki Endo <[email protected]>
hawkw pushed a commit to tokio-rs/tracing that referenced this pull request Nov 13, 2020
)

## Motivation

Closes #648

## Solution

Install cargo-hack from GitHub release instead of using cache.
See also taiki-e/cargo-hack#89 and 
taiki-e/cargo-hack#91.
hawkw added a commit to tower-rs/tower that referenced this pull request Nov 23, 2020
CI is currently busted due to [issues with caching `cargo-hack`][1].
Currently, we cache the `cargo-hack` executable to speed up builds by
avoiding the overhead of compiling it from source in every build.

Recently, `cargo-hack` has started publishing binaries on GitHub
Releases. Rather than compiling it on CI and caching it, we can just
download the binary instead. This ought to fix the build.

See also taiki-e/cargo-hack#89 and taiki-e/cargo-hack#91.

[1]: https://github.com/tower-rs/tower/runs/1425940763
hawkw added a commit to tower-rs/tower that referenced this pull request Nov 23, 2020
CI is currently busted due to [issues with caching `cargo-hack`][1].
Currently, we cache the `cargo-hack` executable to speed up builds by
avoiding the overhead of compiling it from source in every build.

Recently, `cargo-hack` has started publishing binaries on GitHub
Releases. Rather than compiling it on CI and caching it, we can just
download the binary instead. This ought to fix the build.

See also taiki-e/cargo-hack#89 and taiki-e/cargo-hack#91.

[1]: https://github.com/tower-rs/tower/runs/1425940763
hawkw pushed a commit to tokio-rs/tracing that referenced this pull request Nov 23, 2020
)

Closes #648

Install cargo-hack from GitHub release instead of using cache.
See also taiki-e/cargo-hack#89 and
taiki-e/cargo-hack#91.
hawkw pushed a commit to tokio-rs/tracing that referenced this pull request Nov 23, 2020
)

Closes #648

Install cargo-hack from GitHub release instead of using cache.
See also taiki-e/cargo-hack#89 and
taiki-e/cargo-hack#91.
hawkw added a commit to tower-rs/tower that referenced this pull request Dec 23, 2020
CI is currently busted due to [issues with caching `cargo-hack`][1].
Currently, we cache the `cargo-hack` executable to speed up builds by
avoiding the overhead of compiling it from source in every build.

Recently, `cargo-hack` has started publishing binaries on GitHub
Releases. Rather than compiling it on CI and caching it, we can just
download the binary instead. This ought to fix the build.

See also taiki-e/cargo-hack#89 and taiki-e/cargo-hack#91.

[1]: https://github.com/tower-rs/tower/runs/1425940763
@taiki-e taiki-e removed the C-enhancement Category: A new feature or an improvement for an existing one label Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants