1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
|
(** Pure AST types for .obuild files
These types represent the parsed structure without any validation
or file system checks. Validation happens in a separate pass.
*)
open Location
(** A located value - pairs a value with its source location *)
type 'a located = 'a Location.located = {
value: 'a;
loc: loc;
}
(** Dependency with optional version constraint *)
type dependency = {
dep_name: string;
dep_constraint: string option; (* e.g., ">= 1.0" *)
}
(** Extra dependency ordering: module A must be built before module B *)
type extra_dep = {
before: string; (* module name *)
after: string; (* module name *)
}
(** Per-file settings *)
type per_settings = {
per_files: string list; (* file patterns this applies to *)
per_build_deps: dependency list;
per_oflags: string list;
per_pp: string option;
}
(** Cstubs functor description: "Bindings.Types -> Types_gen" *)
type cstubs_desc = {
cstubs_functor: string; (* e.g., "Bindings.Types" *)
cstubs_instance: string; (* e.g., "Types_gen" *)
}
(** Cstubs concurrency policy *)
type cstubs_concurrency =
| Cstubs_sequential (* Default: no special concurrency support *)
| Cstubs_unlocked (* Release runtime lock during C calls *)
| Cstubs_lwt_jobs (* Lwt jobs-based concurrency *)
| Cstubs_lwt_preemptive (* Lwt preemptive threading *)
(** Cstubs errno policy *)
type cstubs_errno =
| Cstubs_ignore_errno (* Default: errno not accessed *)
| Cstubs_return_errno (* Functions return (retval, errno) pairs *)
(** Cstubs configuration block *)
type cstubs = {
cstubs_external_lib_name: string;
cstubs_type_desc: cstubs_desc option;
cstubs_func_desc: cstubs_desc option;
cstubs_generated_types: string; (* default: "Types_generated" *)
cstubs_generated_entry: string; (* default: "C" *)
cstubs_headers: string list;
cstubs_concurrency: cstubs_concurrency; (* default: Cstubs_sequential *)
cstubs_errno: cstubs_errno; (* default: Cstubs_ignore_errno *)
}
(** Stdlib choice *)
type stdlib =
| Stdlib_None
| Stdlib_Standard
| Stdlib_Core
(** Runtime boolean - can be constant or a flag variable *)
type runtime_bool =
| Bool_const of bool
| Bool_var of string
(** C-related settings (shared by all target types) *)
type c_settings = {
c_dir: string option;
c_sources: string list;
c_flags: string list;
c_libs: string list;
c_lib_paths: string list;
c_pkgs: dependency list;
}
(** OCaml-related settings (shared by all target types) *)
type ocaml_settings = {
src_dir: string list;
build_deps: dependency list;
pp: string option;
extra_deps: extra_dep list;
oflags: string list;
stdlib: stdlib option;
}
(** Custom generator definition *)
type generator = {
gen_name: string; (** Generator name for reference *)
gen_suffix: string option; (** File extension for automatic detection (e.g., "mly") *)
gen_command: string; (** Command template with variables: ${src}, ${dest}, ${base}, ${sources} *)
gen_outputs: string list; (** Output file patterns (e.g., ["${base}.ml", "${base}.mli"]) *)
gen_module_name: string option; (** Module name pattern if different from base (e.g., "${base}_t") *)
}
(** Explicit generate block for multi-input generators or overrides *)
type generate_block = {
generate_module: string; (** Output module name *)
generate_from: string list; (** Input file(s) *)
generate_using: string; (** Generator name to use *)
generate_args: string option; (** Additional command-line arguments *)
}
(** Common target settings *)
type target_common = {
buildable: runtime_bool;
installable: runtime_bool;
ocaml: ocaml_settings;
c: c_settings;
per: per_settings list;
generates: generate_block list; (** Explicit generate blocks *)
}
(** Library-specific settings *)
type library = {
lib_name: string;
lib_description: string;
lib_modules: string list;
lib_pack: bool;
lib_syntax: bool;
lib_cstubs: cstubs option;
lib_target: target_common;
lib_subs: library list; (* sub-libraries *)
}
(** Executable-specific settings *)
type executable = {
exe_name: string;
exe_main: string; (* main-is *)
exe_target: target_common;
}
(** Test settings (similar to executable) *)
type test = {
test_name: string;
test_main: string;
test_rundir: string option;
test_run_params: string list;
test_target: target_common;
}
(** Benchmark settings *)
type benchmark = {
bench_name: string;
bench_main: string;
bench_target: target_common;
}
(** Example settings *)
type example = {
example_name: string;
example_main: string;
example_target: target_common;
}
(** Flag definition *)
type flag = {
flag_name: string;
flag_description: string;
flag_default: bool;
}
(** Top-level project AST *)
type project = {
(* Required fields *)
project_name: string located;
project_version: string located;
project_obuild_ver: int located;
(* Optional metadata *)
project_synopsis: string option;
project_description: string option;
project_license: string option;
project_license_file: string option;
project_homepage: string option;
project_authors: string list;
(* Build configuration *)
project_extra_srcs: string list;
project_extra_tools: string list;
project_configure_script: string option;
project_ocaml_ver: string option; (* version constraint expr *)
project_ocaml_extra_args: string list;
(* Flags, generators, and targets *)
project_flags: flag list;
project_generators: generator list; (* Custom code generators *)
project_libs: library list;
project_exes: executable list;
project_tests: test list;
project_benchs: benchmark list;
project_examples: example list;
}
(** Default values *)
let default_c_settings = {
c_dir = None;
c_sources = [];
c_flags = [];
c_libs = [];
c_lib_paths = [];
c_pkgs = [];
}
let default_ocaml_settings = {
src_dir = [];
build_deps = [];
pp = None;
extra_deps = [];
oflags = [];
stdlib = None;
}
let default_target_common = {
buildable = Bool_const true;
installable = Bool_const true;
ocaml = default_ocaml_settings;
c = default_c_settings;
per = [];
generates = [];
}
let default_cstubs = {
cstubs_external_lib_name = "";
cstubs_type_desc = None;
cstubs_func_desc = None;
cstubs_generated_types = "Types_generated";
cstubs_generated_entry = "C";
cstubs_headers = [];
cstubs_concurrency = Cstubs_sequential;
cstubs_errno = Cstubs_ignore_errno;
}
let default_generator = {
gen_name = "";
gen_suffix = None;
gen_command = "";
gen_outputs = [];
gen_module_name = None;
}
let default_generate_block = {
generate_module = "";
generate_from = [];
generate_using = "";
generate_args = None;
}
|