Skip to content

Commit 5dd6574

Browse files
authored
Add script to build ocamlformat with mingw64 (#1702)
1 parent e78506b commit 5dd6574

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

.github/workflows/build-mingw64.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build mingw64 binary
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ref:
7+
required: true
8+
default: 'master'
9+
10+
env:
11+
CYGWINSETUP: setup-x86_64.exe
12+
PACKAGES: git,m4,patchutils,make,curl,unzip,mingw64-x86_64-binutils,mingw64-x86_64-gcc-core,mingw64-x86_64-headers,mingw64-x86_64-runtime
13+
SITE: https://mirrors.kernel.org/sourceware/cygwin
14+
15+
jobs:
16+
build:
17+
runs-on: windows-latest
18+
env:
19+
SHELLOPTS: igncr
20+
steps:
21+
- name: Checkout Repository
22+
uses: actions/checkout@v1
23+
with:
24+
ref: ${{ github.event.inputs.ref }}
25+
- name: Download Cygwin Installer
26+
run: |
27+
curl.exe -o C:\${{ env.CYGWINSETUP }} https://www.cygwin.com/${{ env.CYGWINSETUP }}
28+
shell: cmd
29+
- name: Setup Cygwin
30+
run: |
31+
C:\${{ env.CYGWINSETUP }} -A -q -D -L -g -o -s ${{ env.SITE }} -l C:\cygwin64-cache -R C:\cygwin64 -C Base -P ${{ env.PACKAGES }}
32+
shell: cmd
33+
- name: Run Build Script
34+
run: |
35+
cd '${{ github.workspace }}'
36+
bash tools/build-mingw64.sh
37+
shell: C:\cygwin64\bin\bash.exe --login --norc '{0}'
38+
- name: Upload Artifact
39+
uses: actions/upload-artifact@v2
40+
with:
41+
name: ocamlformat-${{ github.event.inputs.ref }}.exe
42+
path: ${{ github.workspace }}\_build\install\default\bin\ocamlformat.exe
43+
if-no-files-found: error

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/test-extra/code
55
/_opam
66
/_coverage
7+
/_build-mingw64

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
- Break the line and reindent the cursor when pressing <ENTER>
6666
(#1639, #1685, @gpetiot) (#1687, @bcc32)
6767

68+
#### Internal
69+
70+
+ A script `tools/build-mingw64.sh` is provided to build a native Windows
71+
binary of `ocamlformat` using `mingw64` toolchain under Cygwin.
72+
6873
### 0.18.0 (2021-03-30)
6974

7075
#### Bug fixes

HACKING.org

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,23 @@ End state:
222222

223223
...
224224
#+END_SRC
225+
226+
* Building on Windows
227+
228+
`ocamlformat` can be built as a native Windows binary using the `mingw64`
229+
toolchain under Cygwin. The following Cygwin packages are required:
230+
231+
- `git`, `curl`, `unzip`
232+
- `m4`, `patchutils`, `make`
233+
- `mingw64-x86_64-binutils`, `mingw64-x86_64-gcc-core`, `mingw64-x86_64-headers`, `mingw64-x86_64-runtime`
234+
235+
The binary is built by executing `bash tools/build-mingw64.sh` from the root of
236+
the repository. The first time the script is launched, it will install `opam` in
237+
the subdirectory `_build-mingw64` and use it to install all the dependencies of
238+
`ocamlformat` and then build the binary. Subsequent launches of the script will
239+
only rebuild `ocamlformat`. If you need to start from scratch again, simply
240+
remove the `_build-mingw64` directory.
241+
242+
This script can also be triggered as a GitHub Action named `build-mingw64` which
243+
will build the binary in a GitHub worker and upload it back to GitHub. To
244+
retrieve it, select the Action run in question and scroll down to "Artifacts".

tools/build-mingw64.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# Script to build `ocamlformat' under Windows, using the `mingw64' toolchain.
4+
# All it requires is a standard Cygwin installation with the `mingw64'
5+
# toolchain.
6+
7+
set -euo pipefail
8+
9+
opam_url=https://github.com/fdopen/opam-repository-mingw/releases/download/0.0.0.2/opam64.tar.xz
10+
opam_archive=$(basename ${opam_url})
11+
12+
build_dir=_build-mingw64
13+
14+
mkdir -p ${build_dir}
15+
16+
cd ${build_dir}
17+
18+
[ -f ${opam_archive} ] || curl -O -L ${opam_url}
19+
20+
[ -d opam64 ] || tar xf ${opam_archive}
21+
22+
[ -f bin/opam.exe ] || bash opam64/install.sh --prefix $(pwd)
23+
24+
export PATH=$(pwd)/bin:${PATH}
25+
26+
export OPAMROOT="$(cygpath -aml _opam)"
27+
28+
opam init default "https://github.com/fdopen/opam-repository-mingw.git#opam2" -c "ocaml-variants.4.12.0+mingw64c" --disable-sandboxing --no-setup
29+
30+
eval $(opam env)
31+
32+
cd ..
33+
34+
set +eu
35+
opam install -y --deps-only ./ocamlformat.opam
36+
set -eu
37+
38+
dune subst
39+
40+
dune build -p ocamlformat

0 commit comments

Comments
 (0)