janestreet / base

Standard library for OCaml
MIT License
860 stars 125 forks source link

support for mirageOS #89

Closed anuragsoni closed 4 years ago

anuragsoni commented 4 years ago

I noticed this while working on a project which is using ppx_compare. I wanted to use Base to provide the comparison functions that can be used by ppx_compare. The library needs to be usable under mirage, but when using the comparison functions from base, i get a build error when targetting any mirage backend that is not unix. (hvt, spt etc)

ld: _build/main.native.o: in function `camlBase__Import0__Pmakeblock_2212':
(.data+0x8b70): undefined reference to `Base_am_testing'
ld: _build/main.native.o: in function `camlBase__Hash__const_immstring_521':
(.data+0xa630): undefined reference to `Base_hash_double'
ld: _build/main.native.o: in function `camlBase__Exn__const_immstring_66':
(.data+0xcab8): undefined reference to `Base_clear_caml_backtrace_pos'
ld: _build/main.native.o: in function `camlBase__String__const_immstring_456':
(.data+0x237f0): undefined reference to `Base_hash_string'
ld: _build/main.native.o: in function `camlBase_internalhash_types':
(.data+0x2dba8): undefined reference to `Base_internalhash_get_hash_value'
ld: (.data+0x2dbb0): undefined reference to `Base_internalhash_fold_string'
ld: (.data+0x2dbb8): undefined reference to `Base_internalhash_fold_float'
ld: (.data+0x2dbc0): undefined reference to `Base_internalhash_fold_int'
ld: (.data+0x2dbc8): undefined reference to `Base_internalhash_fold_int64'
run ['ld' '-nostdlib' '-z' 'max-page-size=0x1000' '-static' '-T'
     '/home/asoni/.opam/4.10.0+flambda/lib/pkgconfig/../../lib/solo5-bindings-hvt/solo5_hvt.lds'

Is mirage support something that is desirable for base? Its not a blocker since I can define my own comparison functions and/or alternatives like Containers. But it'd be great if I could use Base as i use it everywhere else and it simplifies using other ppxes like ppx_sexp_conv.

yminsky commented 4 years ago

Hmm. This isn't something I understand especially. Base is meant to be highly portable. The missing symbols are just C functions, right? Why aren't such things compatible with Mirage? It's not like JavaScript compilation, where you need to stub C-functions out, right?

Anyway, being compatible with Mirage seems desirable. Is there a guide somewhere as to what one needs to do to be compatible?

yminsky commented 4 years ago

From @avsm, I learn that this will be broken until Mirage merges this:

https://github.com/mirage/mirage/pull/1153

It's being actively worked on now. Closing this issue, since there's nothing to do in Base, it seems.

avsm commented 4 years ago

Nothing needs to happen on the Base side. This is unsupported in Mirage3 until https://github.com/mirage/mirage/pull/1153 is merged (due for Mirage4), and #88 is fixed in Base (which was done in a point release recently).

The background is that Mirage4 will support transparently building C stubs in an isolated dune workspace, thus ensuring that all external dependencies are systematically compiled for the same execution environment. This will not only let Base stubs work, but unlock any library that builds with dune and includes reasonably portable C stubs (or indeed, WASI or other interesting targets).

anuragsoni commented 4 years ago

Thanks for the reference to the work in progress. I had initially thought there were some changes needed in base because of something i saw in the bigstringaf project about linking against ocaml-freestanding.

The proposed mirage 4 updates look really nice and I'll look forward to using it.