Builded by Github actions, but generated files didn't work at all

Hi Everyone.

I found an article Cross Compiling Rust Projects in GitHub Actions

I copied that script and created a new one

name: 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 "abc@google.net"
          git config --global user.name "Abc"
      - 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 immediately 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 builded one on my own (target=x86_64-pc-windows-msvc), that worked
(same ructc version and toolchain)

My laptop:

  1. OS is Windows10 Home Edition
  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)

Do you have any toughts

Can you try building a hello-world-like simple crate and see if it works?

Yes, it worked :frowning:

I'm not sure wether was my code or dependencies cause this

my dependencies were

axum = {version = "0.6", features = ["query"]}
colored = "2.0"
enum_dispatch = "0.3"
erased-serde = "0.3"
once_cell = "1.18"
redb = "1.0"
regex = "1.9"
rkyv = {version = "0.7", features = ["validation"]}
scru128 = "2.8.1"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0"
time = { version = "0.3", features = ["formatting"] }
tower-http = { version = "0.4.0", features = ["cors"] }
tokio = { version = "1", features = ["fs", "io-util", "macros", "net", "rt", "rt-multi-thread", "signal", "time"] }

maybe it's compiled with certain cpu feature that is not available on your local machine, similar to this thread:

if you can configure the build pipeline to log the full compiler command line flags, maybe you can find some clue.

it would helpful too if you can find where the crash happens. you can simply run the binary through a debugger, it should catch the exception and show the exact offending instruction.

You're totally right. it's my mistake

I tried snmalloc-rs and added

[build]
rustflags = ["-C", "target-cpu=native"]
rustdocflags = ["-C", "target-cpu=native"]

in .cargo/config.toml and I forgot to comment it out
stupid
Thanks a lot


By the way, I ran Actions generated file, Windows gave me a warning
win

(It's in Chinese)
it said Microsoft Defender SmartScreen stopped an unknown application starting
and asked me if I started it or not

Was it signature missing?

I builded one on my own didn't popup this alert

Windows knows when an exe was built locally or downloaded. It expects downloaded exes to be signed.

it's just a safety measure of Windows. if you download a file that might potentially contain executable code (mainly .exe file, but may include other file types like word documents with VBA macros etc) from the internet, unless it's digitally signed using a valid certificate, windows will flag the file as untrusted and requires explicit user approval to run. locally generated executable files as built by compilers are not flagged, but windows defender still scans executable files when it's created or changed on the filesystem.

for example, here's some detailed explanation:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.