setup-ocaml icon indicating copy to clipboard operation
setup-ocaml copied to clipboard

v3 regression over v2: `opam exec` now fails with "Exec format error" on shell scripts on Windows

Open JasonGross opened this issue 1 year ago • 2 comments

opam exec -- ./test.sh
Fatal error: exception C:\hostedtoolcache\windows\opam\2.2.1\x86_64\opam.exe: "create_process" failed on ./test.sh: Exec format error

https://github.com/JasonGross/test/actions/runs/10953316111/job/30413386004

logs_28625164728.zip

Full yml file
name: Example Workflow

on: [push, pull_request]

jobs:
  build:

    runs-on: windows-latest
    name: build
    steps:
    - uses: actions/checkout@v4
      with:
        submodules: recursive
    - uses: ocaml/setup-ocaml@v3
      with:
        ocaml-compiler: 4.13.1
    - run: opam exec -- chmod +x test.sh
    - run: opam exec -- cat test.sh
    - run: opam exec -- ./test.sh


  buildv2:

    runs-on: windows-latest
    name: buildv2
    steps:
    - uses: actions/checkout@v2
      with:
        submodules: recursive
    - uses: ocaml/setup-ocaml@v2
      with:
        ocaml-compiler: 4.13.1
    - run: opam exec -- chmod +x test.sh
    - run: opam exec -- cat test.sh
    - run: opam exec -- ./test.sh

JasonGross avatar Sep 20 '24 04:09 JasonGross

Is it related to this? https://github.com/ocaml/setup-ocaml/issues/815

smorimoto avatar Oct 04 '24 12:10 smorimoto

You are suggesting that it might be related to https://github.com/ocaml/setup-ocaml/issues/815#issuecomment-2204843777 in particular, where perhaps indirecting through ocaml-env exec -- opam.exe exec instead of jumping straight to opam exec might change something? Or that opam exec might sometimes recognize bash scripts depending on what shell its run from? (The problem is that opam is trying to run the bash script as a binary executable, but I don't know what's causing that issue.) Is there a way to disentangle opam version issues from setup-ocaml version issues by changing something at https://github.com/JasonGross/test/blob/d70236be3e6d76e9bcac5a65b68298784b33f44d/.github/workflows/main.yml ?

JasonGross avatar Oct 04 '24 16:10 JasonGross

What happens if you run this with the latest v3?

smorimoto avatar Mar 05 '25 21:03 smorimoto

Still failing at https://github.com/JasonGross/test/actions/runs/13686640123/job/38271477628

JasonGross avatar Mar 06 '25 00:03 JasonGross

If I understand correctly, even when using Cygwin, you still need to invoke the shell explicitly. This is because opam is compiled as a native Windows binary (opam.exe) and utilises the Windows CreateProcess API to launch processes. This API does not recognise shell scripts as directly executable files, regardless of whether you’re operating within a Cygwin environment. So, to run your shell script, you must explicitly call an interpreter like bash.

smorimoto avatar Mar 06 '25 01:03 smorimoto

Can you execute it by doing the following?

opam exec -- bash ./test.sh

smorimoto avatar Mar 06 '25 01:03 smorimoto

Trying that out at https://github.com/JasonGross/test/actions/runs/13693808963/job/38291718192

JasonGross avatar Mar 06 '25 07:03 JasonGross

Can you execute it by doing the following?

opam exec -- bash ./test.sh

Yes, this variant works fine

JasonGross avatar Mar 06 '25 09:03 JasonGross

Nice. This is not strictly an issue with this action, as I believe it comes from opam now native rather than regression. I'm going to close this issue.

smorimoto avatar Mar 08 '25 03:03 smorimoto

how are you supposed to run

opam exec -- dune build

on windows with v3? It's documented like this in the README but it fails on windows with Exec format error. I tried

opam exec -- bash -c "dune build"

And it fails the same.

tsnobip avatar Jul 31 '25 08:07 tsnobip

how are you supposed to run

opam exec -- dune build

on windows with v3? It's documented like this in the README but it fails on windows with Exec format error. I tried

opam exec -- bash -c "dune build"

And it fails the same.

For future readers, I think it was related to using dune workflow for my local development (since it's not compatible with windows yet), it worked once I removed the pkg lock folder.

tsnobip avatar Aug 05 '25 08:08 tsnobip