naming problem: vm_linkage, vm_runtime
vm_runtime is a label attr of ocaml_library defaulting to "@rules_ocaml//cfg/runtime:dynamic", but it's actual function is to setting a linking policy for cc deps. On linux, cc_library may produce both a .a and a .so file, in which case we need to decide which to use.
otoh vm_linkage is used when linking cc deps into bytecode executables, to decide whether to use -custom or -output-complete-exe or the default (dynamic linking). So strictly speaking vm_linkage conflates two distinct (albeit related) things: cc lib linkage (static or dynamic), and vm runtime choice. If we only had two choices for output (default and -custom, say), then this choice would correspond directly to cc lib linkage policy. But since we also have -output-complete-exe, we need to keep cclib link policy distinct from "executable output form".
Note that -custom means two distinct things: 1) "produces an output file that contains both the runtime system and the bytecode for the program", and 2) "enables static linking of OCaml code with user-defined C functions". Note: "enables", not "forces". Can we use -custom with shared libs? Chapter 22 implies that -custom means static linking only.
OTOH -output-complete-exe means "Build a self-contained executable by linking a C object file containing the bytecode program, the OCaml runtime system and any other static C code given to ocamlc." I.e. forces static linking?
Complicating things further: the documentation of the native compiler is inaccurate; it says "Arguments ending in .o, .a or .so (.obj, .lib and .dll under Windows) are assumed to be C object files and libraries. They are linked with the program." This is false in the case of .so; such files are not accepted as direct args to the link command. But we can use -cclib -lfoo with the native compiler, to link shared libs.
so:
- cc_linkage : string attr, "static" or "dynamic"; or "sys" to fall back to the system default (dynamic on macos, static on linux)
- vm_exec_out (or some such) to select from among the three options
A static cc_linkage policy forces vm_exec_out to either -custom or -output-complete-exe