Build unison with OCaml+Opam Images for Docker for Windows

Container: ocaml/opam:windows-msvc-ocaml-4.12 latest

Tried build unison 2.51.5 with the following results:
C:\cygwin64\home\unison\unison-master

make OSTYPE=cygwin OSARCH=win32
Cannot find file ./configure.ml.
Cannot find file ./configure.ml.
Cannot find file ./configure.ml.
Cannot find file ./configure.ml.
Cannot find file ./configure.ml.
make -C src UISTYLE=text
make[1]: Entering directory ‘/home/unison/unison-master/src’
windres win32rc/unison.rc win32rc/unison.res
make[1]: windres: No such file or directory
make[1]: *** [Makefile.OCaml:421: win32rc/unison.res] Error 127
make[1]: Leaving directory ‘/home/unison/unison-master/src’
make: *** [Makefile:6: text] Error 2

windres seems not available or any modification to Makefile.OCaml is required?

dir
Directory of C:\cygwin64\bin

02/04/2017 03:41 AM 40,979 wc.exe
02/17/2021 01:39 AM 41,491 whatis.exe
03/31/2020 05:20 PM 23,059 whereis.exe
03/13/2013 05:43 PM 25,619 which.exe
02/04/2017 03:41 AM 61,459 who.exe
02/04/2017 03:41 AM 27,667 whoami.exe
6 File(s) 220,274 bytes
0 Dir(s) 20,586,315,776 bytes free

Anyone manage to build unison successfully? Your advices are much appreciated!

I think you want something like ocaml-env exec --ms -- make … which then puts the VS tools into path. Does cl work as a command as things stand?

cl work as a command:
C:\cygwin64\home\opam>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30133 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

usage: cl [ option… ] filename… [ /link linkoption… ]

link also availabe:
C:\cygwin64\home\opam>link
Microsoft (R) Incremental Linker Version 14.29.30133.0
Copyright (C) Microsoft Corporation. All rights reserved.

usage: LINK [options] [files] [@commandfile]

options:

Tools seems in the PATH:
C:\cygwin64\home\opam>path
PATH=C:\opam.opam\4.12\bin;C:\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64;C:\BuildTools\MSBuild\Current\bin\Ro
slyn;C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Build
Tools\MSBuild\Current\Bin;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\BuildTools\Common7\IDE;C:\BuildTools\Comm
on7\Tools;C:\cygwin64\bin;C:\Program Files\winget-cli;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Window
s\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\ContainerAdministrator
AppData\Local\Microsoft\WindowsApps

For MSVC it use “ocaml-env exec --64 --ms=vs2019 --” as suggested in the annuncement message.

Just figure out windres is actually available as x86_64-w64-mingw32-windres in this container, try manually generated both unison.res and unison.res.lib:

>x86_64-w64-mingw32-windres src/win32rc/unison.rc -O coff src/win32rc/unison.res.li
b
>x86_64-w64-mingw32-windres src/win32rc/unison.rc -O res src/win32rc/unison.res

C:\unison-master>ls -l src/win32rc
total 109
-rwx------ 1 ContainerAdministrator ContainerAdministrator 35840 Jan  2 16:55 U.ico
-rwx------ 1 ContainerAdministrator ContainerAdministrator    49 Jan  2 16:55 unison.rc
-rw-r--r-- 1 ContainerAdministrator ContainerAdministrator 36136 Jan  3 13:05 unison.res
-rw-r--r-- 1 ContainerAdministrator ContainerAdministrator 36466 Jan  3 13:04 unison.res.lib

then

>make OSTYPE=cygwin
Cannot find file ./configure.ml.
Cannot find file ./configure.ml.
Cannot find file ./configure.ml.
Cannot find file ./configure.ml.
Cannot find file ./configure.ml.
make -C src UISTYLE=text
make[1]: Entering directory '/home/unison/unison-master/src'
windres win32rc/unison.res win32rc/unison.res.lib
UISTYLE = text
Building for Windows
NATIVE = true
STATIC = false
OSTYPE = cygwin
OSARCH = win32
ocamlopt: ubase/rx.mli ---> ubase/rx.cmi
ocamlopt -g -I lwt -I ubase -I system -I fsmonitor -I fsmonitor/windows -I system/win -I lwt/win   -c ./ubase/rx.mli
ocamlopt: ubase/rx.ml ---> ubase/rx.cmx
ocamlopt -g -I lwt -I ubase -I system -I fsmonitor -I fsmonitor/windows -I system/win -I lwt/win   -c ./ubase/rx.ml
ocamlopt: unicode_tables.ml ---> unicode_tables.cmx
ocamlopt -g -I lwt -I ubase -I system -I fsmonitor -I fsmonitor/windows -I system/win -I lwt/win   -c ./unicode_tables.m
l
ocamlopt: unicode.mli ---> unicode.cmi

at the end

ocamlopt -g -I lwt -I ubase -I system -I fsmonitor -I fsmonitor/windows -I system/win -I lwt/win -ccopt -o./hash_compat.
o -c ./hash_compat.c
cl : Command line warning D9035 : option 'o' has been deprecated and will be removed in a future release
Linking unison.exe
ocamlopt -verbose -g -I lwt -I ubase -I system -I fsmonitor -I fsmonitor/windows -I system/win -I lwt/win  -o unison.exe
   unix.cmxa str.cmxa bigarray.cmxa ubase/rx.cmx unicode_tables.cmx unicode.cmx bytearray.cmx system/system_win.cmx syst
em/system_generic.cmx system/win/system_impl.cmx system.cmx ubase/projectInfo.cmx ubase/myMap.cmx ubase/safelist.cmx uba
se/util.cmx ubase/uarg.cmx ubase/prefs.cmx ubase/trace.cmx ubase/proplist.cmx lwt/pqueue.cmx lwt/lwt.cmx lwt/lwt_util.cm
x lwt/win/lwt_unix_impl.cmx lwt/lwt_unix.cmx uutil.cmx case.cmx pred.cmx fileutil.cmx name.cmx path.cmx fspath.cmx fs.cm
x fingerprint.cmx abort.cmx osx.cmx external.cmx fswatch.cmx props.cmx fileinfo.cmx os.cmx lock.cmx clroot.cmx common.cm
x tree.cmx checksum.cmx terminal.cmx transfer.cmx xferhint.cmx remote.cmx globals.cmx fswatchold.cmx fpcache.cmx update.
cmx copy.cmx stasher.cmx files.cmx sortri.cmx recon.cmx transport.cmx strings.cmx uicommon.cmx uitext.cmx test.cmx main.
cmx linktext.cmx system/system_win_stubs.o lwt/lwt_unix_stubs.o osxsupport.o pty.o bytearray_stubs.o hash_compat.o -ccli
b "-link win32rc/unison.res.lib"
don't know what to do with system/system_win_stubs.o
Usage: ocamlopt <options> <files>
Options are:
  -fPIC  Generate position-independent machine code (default)
  -fno-PIC  Generate position-dependent machine code
  -a  Build a library
  ...
  ...
  ...
make[1]: *** [Makefile.OCaml:458: unison.exe] Error 2
make[1]: Leaving directory '/home/unison/unison-master/src'
make: *** [Makefile:6: text] Error 2

Failed at the final linking stage.

Have you tried using dune build? Unison is now ported to dune, it should work (in theory).

Or better yet, unison also has an opam package. Simply calling

opam install unison

should work in theory

1 Like

I need a fix in NTFS symbolic link which is in the current Master, so I must compile from source…

I just figure out the above error due to cl doesn’t support -o option, the output file actually left as an .obj file in the source root rather than it’s original sub-folder. All .c files are end up with .obj files in the source root.

I didn’t read the thread correctly the other day - windres is a binutils command; for MSVC you want rc (docs on MSDN). A long time ago (relevant, given Unison’s age), windres was an unprefixed tool but, as you’ve found, it’s now x86_64-w64-mingw32-windres. FlexDLL has a demonstration of using both windres and rc in the same Makefile at
flexdll/Makefile at 02a5d3eb365f6778ac847a0cd57854d08489babb · alainfrisch/flexdll · GitHub and flexdll/Makefile at 02a5d3eb365f6778ac847a0cd57854d08489babb · alainfrisch/flexdll · GitHub

FYI, build issues fixed with the help of owner of this PR