kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

lib_resolve.h (2955B)


      1 #ifndef KIT_DRIVER_LIB_RESOLVE_H
      2 #define KIT_DRIVER_LIB_RESOLVE_H
      3 
      4 #include "driver.h"
      5 
      6 /* Whether driver_lib_resolve should look for shared libraries (.so),
      7  * archives (.a), or both. `LIB_RESOLVE_AUTO` follows the GNU-ld
      8  * positional rule: under -Bdynamic try `lib<name>.so` first then
      9  * `lib<name>.a`; under -Bstatic try `lib<name>.a` only.
     10  *
     11  * `out_kind` (when non-NULL) reports which suffix actually matched so
     12  * the caller can route the result into the right input slot
     13  * (dso_bytes vs. archives). */
     14 typedef enum LibResolveMode {
     15   LIB_RESOLVE_STATIC_ONLY,
     16   LIB_RESOLVE_DYNAMIC_PREFER, /* .so first, then .a (default for dynamic
     17                                  link mode) */
     18   LIB_RESOLVE_DYNAMIC_ONLY,
     19 } LibResolveMode;
     20 
     21 typedef enum LibResolveKind {
     22   LIB_RESOLVE_KIND_ARCHIVE = 0,
     23   LIB_RESOLVE_KIND_SHARED = 1,
     24   /* Apple .tbd text-based stub: same downstream routing as SHARED
     25    * (feeds the linker as a DSO input), distinct so the cc driver can
     26    * tell what suffix matched. */
     27   LIB_RESOLVE_KIND_TBD = 2,
     28 } LibResolveKind;
     29 
     30 /* Target-OS hint for the suffix list. Windows uses the mingw / MSVC
     31  * naming variants (`lib<name>.dll.a`, `lib<name>.a`, `<name>.lib`,
     32  * `<name>.dll.a`); everything else uses the POSIX `lib<name>.*` set. */
     33 typedef enum LibResolveOS {
     34   LIB_RESOLVE_OS_POSIX = 0,
     35   LIB_RESOLVE_OS_WINDOWS = 1,
     36 } LibResolveOS;
     37 
     38 /* Resolve `-l<name>` against a list of `-L`-style search directories.
     39  *
     40  * On success, returns 0 and writes a heap-allocated, NUL-terminated
     41  * path into `*out_path`, with its allocation size in `*out_size`. The
     42  * caller frees the path via driver_free(env, *out_path, *out_size).
     43  * If `out_kind` is non-NULL, *out_kind tells the caller whether the
     44  * matched file is a `.so` (LIB_RESOLVE_KIND_SHARED) or a `.a`
     45  * (LIB_RESOLVE_KIND_ARCHIVE).
     46  *
     47  * The legacy entry point `driver_lib_resolve` defaults to POSIX
     48  * naming. `driver_lib_resolve_for_os` is the same function with an
     49  * explicit target-OS hint so the caller can switch the suffix list
     50  * for cross-compilation (Windows targets need .lib / .dll.a in
     51  * addition to .a). The OS hint is independent of the host OS.
     52  *
     53  * On failure, returns nonzero with `*out_path` unchanged. Failure
     54  * cases:
     55  *   - no candidate exists in any of the search directories
     56  *   - allocation failure while constructing a candidate path */
     57 int driver_lib_resolve(DriverEnv* env, const char* name, LibResolveMode mode,
     58                        const char* const* search_dirs, uint32_t nsearch_dirs,
     59                        char** out_path, size_t* out_size,
     60                        LibResolveKind* out_kind);
     61 
     62 int driver_lib_resolve_for_os(DriverEnv* env, const char* name,
     63                               LibResolveMode mode, LibResolveOS os,
     64                               const char* const* search_dirs,
     65                               uint32_t nsearch_dirs, char** out_path,
     66                               size_t* out_size, LibResolveKind* out_kind);
     67 
     68 #endif