mirage / mirage-crypto

Cryptographic primitives for OCaml, in OCaml (also used in MirageOS)
ISC License
77 stars 43 forks source link

Config flags are not correct when used in cross-architecture-compilation with Dune 3 #153

Closed TheLortex closed 2 years ago

TheLortex commented 2 years ago

With Dune 2, cross-compiling mirage-crypto from x86 to aarch64 was working fine.

With Dune 3, it fails with the following error:

File "duniverse/mirage-crypto/src/dune", line 9, characters 47-51:
9 |   (names detect_cpu_features misc misc_sse md5 sha1 sha256 sha512 hash_stubs
                                                   ^^^^
aarch64-linux-gnu-gcc: error: unrecognized command-line option ‘-mrdrnd’
aarch64-linux-gnu-gcc: error: unrecognized command-line option ‘-mrdseed’
aarch64-linux-gnu-gcc: error: unrecognized command-line option ‘-mssse3’
aarch64-linux-gnu-gcc: error: unrecognized command-line option ‘-maes’
aarch64-linux-gnu-gcc: error: unrecognized command-line option ‘-mpclmul’

It looks like x86 CPU-specific optimisations are enabled even if we are cross-compiling for arm64. So what happens is that the configurator is configuring for the host instead of the target.

hannesm commented 2 years ago

Thanks for the report. Do you have knowledge on how to fix it? I lack any dune insight, as well as cross-compilation setup insights.

tmcgilchrist commented 2 years ago

I ran into this issue from the linked mirage cross compilation post. It seems like the duniverse that now gets created when you follow those instructions expects dune 3.0 or newer, using features like (using ctypes 0.1). So cross compilation is no longer working from Linux x86 -> ARM64.

Is anyone able to point to how I could get started fixing the cross compilation issue with this library?

hannesm commented 2 years ago

@tmcgilchrist I have no clue how to fix this, and can't find anything in the dune changes that point to fixes in that area. Maybe @TheLortex has some idea? Maybe @dinosaure encountered such issues with digestif as well?

TheLortex commented 2 years ago

So I have re-tested the tutorial with dune 3.2.0 it worked fine. @tmcgilchrist if you can confirm that it works fine with the latest version of dune, I suggest closing the issue for now and updating the blog post.

hannesm commented 2 years ago

Thanks for your investigation @TheLortex. AFAICT there's not much to do from the mirage-crypto side.