setup-ocaml
setup-ocaml copied to clipboard
v3 regression over v2: `opam exec` now fails with "Exec format error" on shell scripts on Windows
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
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
Is it related to this? https://github.com/ocaml/setup-ocaml/issues/815
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 ?
What happens if you run this with the latest v3?
Still failing at https://github.com/JasonGross/test/actions/runs/13686640123/job/38271477628
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.
Can you execute it by doing the following?
opam exec -- bash ./test.sh
Trying that out at https://github.com/JasonGross/test/actions/runs/13693808963/job/38291718192
Can you execute it by doing the following?
opam exec -- bash ./test.sh
Yes, this variant works fine
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.
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.
how are you supposed to run
opam exec -- dune buildon windows with v3? It's documented like this in the README but it fails on windows with
Exec format error. I triedopam 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.