-
-
Notifications
You must be signed in to change notification settings - Fork 25
Description
I can do a PR myself (if it is small-ish like the proposal below) once this design question is answered.
Context
The way I do cross-compilation is using Dune workspace targets, which is just a wrapper around ocamlfind toolchains. I believe others who use opam-monorepo do the same thing.
Problem
I'm running into problems with luv because luv uses a custom build in src/c/dune. One example blocker is
Line 75 in 0ed668e
| "sh configure --host `ocamlc -config | awk '/host/ {print $NF}'` \ |
(bash
"sh configure --host `ocamlc -config | awk '/host/ {print $NF}'` \
'CC=%{cc}' CFLAGS=-DNDEBUG --silent --enable-silent-rules")For cross-compiling, you would want a build for ocamlc -config like above, but you would also want a ocamlfind -toolchain <toolchain> ocamlc -config build. Dune does this automatically by building a "native" context=default target (which uses no toolchain) and then building separately (ex. context="android") for any targets listed in dune-workspace.
Proposal
A couple points:
- I think plumbing the toolchain logic into the embedded libuv parts of src/c/dune is too complicated (ie. hard to maintain).
- I think using embedded libuv is undesirable in many common cross-compiling situations. For example, when cross-compiling Android ... it is better to have a prebuilt, well-tested, properly configured Android libuv library than to cross-compile and embed libuv internally with
ocamlc -configflags.
So my idea would be to:
- Extend the simple logic that is already present for LUV_USE_SYSTEM_LIBUV. Dune has a variable called
context_name; it is also available asJbuild_plugin.V1.context. Ifdune-workspacehas two targets "native" and "android", then src/c/dune will be called withcontext_name="default"in the _build/default directory and then called again withcontext_name="default.android"in the _build/default.android directory. - If and only if LUV_USE_SYSTEM_LIBUV is set, have
LUV_SYSTEM_LIBUV_${uppercase(sanitize(context_name))}be an environment variable that setsuv_library_flag. If it isn't defined just fallback to-luv. For example:LUV_USE_SYSTEM_LIBUV=yes LUV_SYSTEM_LIBUV_DEFAULT='-luv' LUV_SYSTEM_LIBUV_DEFAULT_ANDROID_AARCH64='-L/Android/prebuilt/llvm-aarch64/lib;-luv' LUV_SYSTEM_LIBUV_DEFAULT_ANDROID_ARM32='/Android/prebuilt/llvm-arm32v7a/lib/libuv.so' LUV_SYSTEM_LIBUV_DEFAULT_WINDOWS64='-LC:/Program Files/vcpkg/windows-x64/lib;-llibuv'
I used semicolons as a separator as one way to allow spaces in paths which is essential for Windows. Could also have escaped the space or passed in OCaml escaped strings.
What do you think? Suggestions?
Thanks.