houseabsolute / actions-rust-cross

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

Compiled files didn't work #5

Closed songday closed 1 year ago

songday commented 1 year ago

Hi, thanks to provide such a good Github Action

I googled your blog
and copied ci.yml from here: https://github.com/houseabsolute/ubi/blob/master/.github/workflows/ci.yml
then changed

name: Tests and release
on: [push, pull_request]
env:
  CRATE_NAME: mytest
  GITHUB_TOKEN: ${{ github.token }}
  RUST_BACKTRACE: 1
jobs:
  test:
    name: ${{ matrix.platform.os_name }} with rust ${{ matrix.toolchain }}
    runs-on: ${{ matrix.platform.os }}
    strategy:
      fail-fast: false
      matrix:
        platform:
          - os_name: Linux-x86_64
            os: ubuntu-20.04
            target: x86_64-unknown-linux-musl
            bin: mytest
            name: mytest-Linux-x86_64-musl.tar.gz
          - os_name: Windows-x86_64
            os: windows-latest
            target: x86_64-pc-windows-msvc
            bin: mytest.exe
            name: mytest-Windows-x86_64.zip
        toolchain:
          - stable
    steps:
      - uses: actions/checkout@v3
      - name: Cache cargo & target directories
        uses: Swatinem/rust-cache@v2
        with:
          key: "v2"
      - name: Configure Git
        run: |
          git config --global user.email "songday@yeah.net"
          git config --global user.name "Songday"
      - name: Install musl-tools on Linux
        run: sudo apt-get update --yes && sudo apt-get install --yes musl-tools
        if: contains(matrix.platform.name, 'musl')
      - name: Install build-essential on Linux
        run: sudo apt-get install --yes build-essential
        if: contains(matrix.platform.name, 'musl')
      - name: Link g++
        run: sudo ln -s /bin/g++ /bin/musl-g++
        if: contains(matrix.platform.name, 'musl')
      - name: Build binary
        uses: houseabsolute/actions-rust-cross@v0
        with:
          command: "build"
          target: ${{ matrix.platform.target }}
          toolchain: ${{ matrix.toolchain }}
          args: "--release"
          strip: false
      - name: Run tests
        uses: houseabsolute/actions-rust-cross@v0
        with:
          command: "test"
          target: ${{ matrix.platform.target }}
          toolchain: ${{ matrix.toolchain }}
          args: "--release"
        if: ${{ !matrix.platform.skip_tests }}
      - name: Package as archive
        shell: bash
        run: |
          cd target/${{ matrix.platform.target }}/release
          if [[ "${{ matrix.platform.os }}" == "windows-latest" ]]; then
            7z a ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }}
          else
            tar czvf ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }}
          fi
          cd -
        if: matrix.toolchain == 'stable'
      - name: Publish release artifacts
        uses: actions/upload-artifact@v3
        with:
          name: mytest-${{ matrix.platform.os_name }}
          path: "mytest-*"
        if: matrix.toolchain == 'stable'
      - name: Generate SHA-256
        run: shasum -a 256 ${{ matrix.platform.name }}
        if: |
          matrix.toolchain == 'stable' &&
          matrix.platform.os == 'macOS-latest' &&
          ( startsWith( github.ref, 'refs/tags/v' ) ||
            github.ref == 'refs/tags/test-release' )
      - name: Publish GitHub release
        uses: softprops/action-gh-release@v1
        with:
          draft: true
          files: "mytest*"
          body_path: Changes.md
        if: matrix.toolchain == 'stable' && startsWith( github.ref, 'refs/tags/v' )

But this action compiled Windows binary didn't work on my laptop (exited without any output)
Linux binary didn't work either, when I ran it in console, it exited immediately with a output: Illegal instruction (Core dumped) (I didn't find the dump file
then I compiled one on my own, that worked
(same ructc version and toolchain)

My laptop:

  1. OS is Windows10 HomeEdition
  2. rustc version is 1.71.0
  3. toolchain is: stable-x86_64-pc-windows-msvc

I found file size of these two was different
Github Action created file: 4,480,512 bytes
My laptop created file: 4,401,152 bytes (a bit smaller)

autarch commented 1 year ago

I'm not sure what's going on here. I'm using this for several different projects without any issues. Can you link to the project that had the issue?

songday commented 1 year ago

Sorry, that's a private project, but I can create a new simple project and try again

songday commented 1 year ago

I created a simple 'HelloWorld' project, your script worked. I guess that my code or dependencies problem

songday commented 1 year ago

Found the reason, it's my mistake, I specify target cpu, so the builded file didn't run on other computers