Caching fails when bootstrapping a compiler, but only on MacOS

I’m trying to cache build artifacts, placed in a directory named build. This is the step in my workflow:

    - name: Cache Build
      uses: actions/cache@v2
      env:
        cache-name: cache-build
      with:
        path: ./build
        key: ${{ matrix.os }}-${{ github.ref }}-${{ env.cache-name }}-${{ hashFiles('**/build.config') }}
        restore-keys: |
          ${{ matrix.os }}-${{ github.ref }}-${{ env.cache-name }}-${{ hashFiles('**/build.config') }}
          ${{ matrix.os }}-${{ github.ref }}-${{ env.cache-name }}-
          ${{ matrix.os }}-${{ github.ref }}-
          ${{ matrix.os }}-

Part of the build process is bootstrapping a compiler. On a clean rebuild I download an different version of the compiler from an external link and use it to perform the initial bootstrap. On subsequent rebuilds, I use the compiler in the build directory.

On the first CI run when the cache is empty, everything builds as I expect - including running the compiled compiler in the build directory

On the second (or any further runs), the MacOS runner pulls the bootstrapped compiler from the cache. If I run ls -l on the runner I can see that the compiler executable is there with executable permissions

# after running ls -l build/my_compiler in the GA Ubuntu runner
-rwxr-xr-x  1 runner docker 32818656 Oct 28 21:32 my_compiler

# after running ls -l buil/my_compiler in the GA MacOS runner
-rwxr-xr-x    1 runner  staff  25371840 Oct 28 21:36 my_compiler

And if I run file build/my_compiler on MacOS I see:

build/my_compiler: data

But on ubuntu:

build/my_compiler: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=db1ec79c2103093cbb0953dc3a2e36c39882688b, not stripped

When trying to invoke the bootstrapped compiler through a bash script later on I get:

scripts/make.bash: line 21: build/my_compiler: cannot execute binary file

On ubuntu everything functions normally.

TL:D:

I’m bootstrapping a compiler and caching it for subsequent workflow runs. The bootstrapped compiler only works on MacOS after it’s compiled the first time, but isn’t recognized as a Mach-O binary after being loaded from the cache.

How should I go about debugging and resolving this? I know this isn’t a typical use case.

@m-hilgendorf,

There is an recent reported issue ticket about the similar problems:

You can follow this issue ticket and add your comments to it.