hosted.h (2734B)
1 #ifndef KIT_DRIVER_HOSTED_H 2 #define KIT_DRIVER_HOSTED_H 3 4 #include <kit/compile.h> 5 #include <stdint.h> 6 7 #include "driver.h" 8 9 typedef enum DriverHostedInputKind { 10 DRIVER_HOSTED_INPUT_OBJECT, 11 DRIVER_HOSTED_INPUT_ARCHIVE, 12 DRIVER_HOSTED_INPUT_DSO, 13 } DriverHostedInputKind; 14 15 typedef struct DriverHostedInput { 16 uint8_t kind; /* DriverHostedInputKind */ 17 uint8_t pad[3]; 18 const char* path; 19 char* owned_path; 20 size_t owned_size; 21 } DriverHostedInput; 22 23 #define DRIVER_HOSTED_MAX_BEFORE 4 24 #define DRIVER_HOSTED_MAX_AFTER 16 25 #define DRIVER_HOSTED_MAX_FINAL 2 26 #define DRIVER_HOSTED_MAX_INCLUDES 4 27 #define DRIVER_HOSTED_MAX_DEFINES 20 28 #define DRIVER_HOSTED_MAX_LIB_SEARCH_DIRS 8 29 30 typedef struct DriverHostedPlan { 31 const char* profile_name; 32 const char* interp_path; 33 DriverHostedInput before[DRIVER_HOSTED_MAX_BEFORE]; 34 uint32_t nbefore; 35 DriverHostedInput after[DRIVER_HOSTED_MAX_AFTER]; 36 uint32_t nafter; 37 DriverHostedInput final[DRIVER_HOSTED_MAX_FINAL]; 38 uint32_t nfinal; 39 const char* system_includes[DRIVER_HOSTED_MAX_INCLUDES]; 40 char* owned_system_includes[DRIVER_HOSTED_MAX_INCLUDES]; 41 size_t owned_system_include_sizes[DRIVER_HOSTED_MAX_INCLUDES]; 42 uint32_t nsystem_includes; 43 KitDefine defines[DRIVER_HOSTED_MAX_DEFINES]; 44 uint32_t ndefines; 45 /* Library search directories from the hosted dirs resolution; added to the 46 * driver's lib search path so user-specified -l flags (e.g. -lm, -lpthread) 47 * can be found. Ownership is transferred from DriverHostedDirs. */ 48 char* lib_search_dirs[DRIVER_HOSTED_MAX_LIB_SEARCH_DIRS]; 49 size_t lib_search_dir_sizes[DRIVER_HOSTED_MAX_LIB_SEARCH_DIRS]; 50 uint32_t nlib_search_dirs; 51 } DriverHostedPlan; 52 53 typedef struct DriverHostedRequest { 54 DriverEnv* env; 55 const char* tool; 56 KitTargetSpec target; 57 const char* sysroot; 58 int static_link; 59 int link_inputs; 60 } DriverHostedRequest; 61 62 int driver_hosted_resolve(const DriverHostedRequest* req, 63 DriverHostedPlan* out); 64 void driver_hosted_plan_fini(DriverEnv* env, DriverHostedPlan* plan); 65 66 /* Resolve just the hosted include + library search directories for the 67 * request's target/sysroot -- KIT_SYSROOT or an explicit --sysroot (expanded 68 * per target-OS layout), else the native host probe (target OS+arch == host). 69 * No crt/libc files are bound. Fills `out` (zeroed internally; release with 70 * driver_hosted_dirs_fini). Returns 0 on success -- `out` may legitimately be 71 * empty when no sysroot applies and the target is not the native host; nonzero 72 * only on allocation failure. Shared by driver_hosted_resolve and by the cc 73 * driver's -print-search-dirs. */ 74 int driver_hosted_dirs_resolve(const DriverHostedRequest* req, 75 DriverHostedDirs* out); 76 77 #endif