Selection of target at compiler run-time
With the merge of !9263 (merged), we now have all of the pieces in place to realize the goal laid out in #19877 (closed): to allow the selection of the compilation target on GHC's command-line. The next step here is to allow the user to specify which target (as defined by a target description file) they want to compile to on GHC's command-line.
There are a few design decisions to be made here.
How should targets be identified?
My first thought would be that targets would be identified by the filename of their target description file and that these would, by convention, be named after their triple (potentially augmented with other information; e.g. aarch64-linux
or x84_64-linux-unregisterised
).
In #19877 (closed), @Ericson2314 argues that content addressing would side-step thorny naming questions. While that may be true, I'm not personally convinced that this would make for a good user-experience.
Where should target descriptions live?
While we could make the user specify the file path of target description (e.g. ghc --target=/home/ben/x86_64-linux.target
), this seems rather user-unfriendly. I suggest that we have a search-path mechanism, allowing target descriptions to be placed in known locations in the file system and referred to by name. These locations would include:
$(ghc --print-libdir)/targets/
$XDG_CONFIG_DIR/ghc/targets/
This would allow the user to run, e.g., ghc --target=x86_64-linux
and a x86_64-linux.target
file would be found in the search path.
How should package databases be handled?
In !9263 (comment 510801) @hsyl20 suggests that the target description should also contain the path to the target's global package database. I haven't yet thought enough about the package system implications of cross-compilation to have a clear opinion here.