--- In email@example.com
, Gerd Stolpmann <gerd@...> wrote:
> Am Dienstag, den 09.07.2013, 20:41 +0000 schrieb talex5:
> > --- In firstname.lastname@example.org, Gerd Stolpmann <gerd@>
> > wrote:
> > >
> > > Am Montag, den 08.07.2013, 19:23 +0000 schrieb talex5:
> > >
> > > > In particular, it seems that bytecode that uses the Unix module is
> > not
> > > > portable between Unix and Windows (the source code is, just not
> > the
> > > > bytecode):
> > > >
> > > >
> > http://stackoverflow.com/questions/17315402/how-to-make-ocaml-bytecode-that-works-on-windows-and-linux
> > > A relatively easy workaround is not to link the bytecode files to an
> > > executable, but leave them as cma's, and just load them into a
> > script.
> > > That means compile all your stuff so you get mylib.cma, and then
> > create
> > > (or generate) a script like
> > >
> > > #!/usr/bin/env ocaml
> > > #directory "/where/my/stuff/is/installed";;
> > > #load "unix.cma";;
> > > #load "mylib.cma";;
> > >
> > > (For Windows, provide a .bat driver side-by-side.)
> > (no need for a .bat script; 0install provides a cross-platform
> > replacement for #! lines)
> > But I don't see how this would help. Either unix.cma is shipped with
> > my program (in which case it's the unix.cma for the build system, not
> > for the platform running the program), or it's the unix.cma shipped
> > with the platform, in which case the hashes won't match.
> Right. But on the other hand, there is absolutely no guarantee that
> bytecode produced with one version of ocaml can be run on other versions
> of ocaml. E.g. the representation of lazy values changed several times.
> Recently the hash algorithm was changed. You would have to go through
> all changes to ensure that your bytecode is still compatible.
OK, I've done some tests and your solution seems to work well:
I was able to compile 0install to bytecode on Linux, and then run that bytecode on both Windows and Linux.
> I don't think it is possible to produce universally runnable bytecode
> executables without shipping the version of ocamlrun together with the
> bytecode. It is just not made for this use case - don't mix this up with
> strictly controlled environments like jvm.
OK, this is what I'll do to start with. OCaml changes slowly enough that we can probably stick with a single version for a few years.
Hopefully some kind of dynamic linker can be added later to allow a bit more flexibility. I guess changes to e.g the hash algorithm wouldn't affect other code, since the interface hasn't changed. Unless ocamlc saves pre-built hash-tables in the binaries or something? But isn't it designed to allow implementation changes, just as long as the interface stays the same?