houseabsolute / actions-rust-cross

GitHub Action to compile Rust with cross
Apache License 2.0
121 stars 13 forks source link

Build fails when multiple binaries are specified #8

Closed Tomiyou closed 11 months ago

Tomiyou commented 11 months ago

I have a Cargo.toml which specifies multiple binaries:

[[bin]]
name = "tcp_client_server"
path = "src/tcp_client_server.rs"

[[bin]]
name = "udp_client"
path = "src/udp_client.rs"

For some reason, strip command fails with error No such file when building for x86_64_unknown_linux-musl, but success without issue for armv7-unknown-linux-musleabihf:

Run strip-binary.sh x86_64-unknown-linux-musl
  strip-binary.sh x86_64-unknown-linux-musl
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    CARGO_INCREMENTAL: 0
    CARGO_TERM_COLOR: always
++ TARGET=x86_64-unknown-linux-musl
++ stripped=
++ for type in debug release
++ '[' -d target/x86_64-unknown-linux-musl/debug ']'
++ '[' -d target/debug ']'
++ for type in debug release
++ '[' -d target/x86_64-unknown-linux-musl/release ']'
++ strip_binary target/x86_64-unknown-linux-musl/release
+++ uname -s
++ [[ Linux =~ Darwin ]]
+++ find target/x86_64-unknown-linux-musl/release -maxdepth 1 -type f -executable
++ EXE='target/x86_64-unknown-linux-musl/release/tcp_client_server
target/x86_64-unknown-linux-musl/release/udp_client'
++ '[' -z 'target/x86_64-unknown-linux-musl/release/tcp_client_server
target/x86_64-unknown-linux-musl/release/udp_client' ']'
++ strip 'target/x86_64-unknown-linux-musl/release/tcp_client_server
target/x86_64-unknown-linux-musl/release/udp_client'
strip: 'target/x86_64-unknown-linux-musl/release/tcp_client_server
target/x86_64-unknown-linux-musl/release/udp_client': No such file        # Says `udp_client` binary does not exist
Error: Process completed with exit code 1.

My ci.yaml file.

jobs:
  build:
    name: ${{ matrix.platform.target_device }} with rust ${{ matrix.toolchain }}
    runs-on: ${{ matrix.platform.os }}
    strategy:
      fail-fast: false
      matrix:
        platform:
          - target_device: Raspberry PI
            os: ubuntu-20.04
            target: armv7-unknown-linux-musleabihf
            suffix: armv7hf
          - target_device: Linux x64
            os: ubuntu-20.04
            target: x86_64-unknown-linux-musl
            suffix: x86_64
        toolchain:
          - stable
    steps:
      - uses: actions/checkout@v3
      - name: Build binary
        uses: houseabsolute/actions-rust-cross@v0
        with:
          command: "build"
          target: ${{ matrix.platform.target }}
          toolchain: ${{ matrix.toolchain }}
          args: "--locked --release --bins"
          strip: true

I have tried to reproduce this issue locally using the command below, but everything goes well (binary exists as it should). Only when running the build via this repo's GitHub action do I encounter any issues.

cross build --target x86_64-unknown-linux-musl --locked --release --bins

Is this a bug or am I doing something wrong?

autarch commented 11 months ago

I don't think you're doing anything wrong. The reason it doesn't error with the arm architecture is because we can only run strip on native binaries for each platform, so strip is ignored when cross-compiling.

I just haven't tested this action with a crate with multiple binaries.

Can you give me a link to the action you ran for your repo? That'll help me figure out the exact fix. A PR would also be welcome.

autarch commented 11 months ago

This should be fixed in v0.0.10.