gd_project ========== .. rust:crate:: gd_project :synopsis: The Guidedog project builder: a handful of verbs over a loaded project. The Guidedog project builder: a handful of verbs over a loaded project. .. code-block:: rust use gd_project::{BuildOptions, BuilderKind, LoadOptions}; let project = gd_project::load("docs".as_ref(), &LoadOptions::default())?; let result = gd_project::build(&project, BuilderKind::Html, &BuildOptions::default()); for report in &result.reports { /* gd_report::Report */ } if let Some(problem) = &result.problem { eprintln!("{problem}"); } gd_project::clean(&project)?; A build discovers the documents (and the generated API pages), loads the translations, reads what changed since the last build (gd-read), resolves the project (gd-resolve), writes the output with the builder (gd-site, gd-book or gd-intl) into a gd-outputs generation, and publishes it whole. .. rubric:: Re-exports .. rust:use:: pub use gd_env::BuildOptions .. rust:use:: pub use gd_env::BuildResult .. rust:use:: pub use gd_env::BuildStage .. rust:use:: pub use gd_env::BuilderKind .. rust:use:: pub use gd_env::Confinement .. rust:use:: pub use gd_env::ContentRule .. rust:use:: pub use gd_env::ContentRules .. rust:use:: pub use gd_env::Jobs .. rust:use:: pub use gd_env::PluginAccess .. rust:use:: pub use gd_env::ReadScope .. rubric:: Structs .. rust:struct:: pub struct LoadOptions Where a project is and what it is built with. Fill it with struct-update syntax: ``LoadOptions { plugins: linked, ..Default::default() }``. .. rubric:: Fields .. rust:field:: pub config: gd_conf::LoadOptions The command line's say: ``-c``, ``-C``, ``-D``, the sphinx-build form's folders. .. rust:field:: pub plugins: gd_plugins::Registry The build plugins linked into this program, looked up before the machine registry (``plugins = [...]`` in conf.toml selects them). .. rust:field:: pub registry: Option The readers and renderers; ``None``: ``guidedoc_defaults::registry()``. .. rust:struct:: pub struct Project A loaded documentation project. Builds borrow it and never change it (each works on its own copy of the configuration), so one project may be built any number of times. .. rubric:: Fields .. rust:field:: pub config: Config The checked settings. .. rust:field:: pub warnings: Vec What loading warned about; every build reports them again. .. rust:field:: pub settings: Digest The digest of conf.toml's text and the ``-D`` overrides: what every output uses. .. rust:field:: pub registry: Registry The readers and renderers. .. rust:field:: pub plugins: gd_plugins::Registry The linked build plugins. .. rubric:: Implementations .. rust:impl:: impl Project :noindex: :for: Project .. rust:method:: pub fn watch_skip(&self) -> Vec The paths a watch skips: the build folder, whose changes are the build's own. .. rubric:: Functions .. rust:function:: pub fn build(project: &Project, kind: BuilderKind, options: &BuildOptions) -> BuildResult Builds ``project`` with the builder ``kind``: reads the documents whose sources changed (all of them with ``fresh``), resolves the project, writes the outputs whose inputs changed (all of them with ``all``), and publishes them whole. The build applies ``options.effective_confinement()`` to its own copy of the configuration and ``options.content_rules(&project.config)`` to every document. The project is never changed: a confined build confines only itself and any number of builds may follow. It never fails outright: the result carries the problem that stopped it (exit != 0), every report, and the counters. Only a build that did all its work, and that ``-W`` does not fail, publishes; any other leaves the previous output, manifest and environment as they were. .. rust:function:: pub fn writes_dependencies(kind: BuilderKind) -> bool Tells whether ``kind`` writes a dependency manifest: every builder whose output a person reads. .. rust:function:: pub fn build_limits(options: &BuildOptions) -> Result The limits every session of a build reads and renders with: the engine's defaults with ``--max-depth``, ``--max-nodes`` and ``--stack-kib``. Documents are read and pages rendered on threads of ``gd_host::WORKER_STACK_BYTES`` (the command line runs its own work on one too), so the stack budget may be at most what such a thread holds. Fails with ``build.stack`` (exit 2) when ``--stack-kib`` asks for more; a caller may call it before building to refuse the options early. .. rust:function:: pub fn content_policy(rules: ContentRules) -> Policy The policy of a build with the content ``rules`` (``gd_env::BuildOptions::content_rules``): raw content and unsafe URLs allowed or omitted as they say (an unstated rule allows), untranslatable math allowed, and a document with an unknown directive or role reported and still built. .. rust:function:: pub fn trusted_policy() -> Policy The policy of a build of the user's own project: raw HTML and Typst, any URL and untranslatable math are used as Sphinx uses them, and, as in Sphinx, a document with an unknown directive or role is reported and still built. .. rust:function:: pub fn untrusted_policy() -> Policy The policy of an ``--untrusted`` build of a project from elsewhere: raw content and unsafe URLs (``javascript:`` and the like) are left out with a warning. What such a build reads is its confinement (``gd_env::Confinement::STRICT``), not its policy. .. rust:function:: pub fn clean(project: &Project) -> Result<(), Problem> Removes everything in the project's build folder, as ``make clean`` does for Sphinx, and leaves the folder itself; a missing one is nothing to clean. Fails with ``project.clean-root`` when the build path is not a folder and ``host.io`` when an entry cannot be removed. .. rust:function:: pub fn load(dir: &Path, options: &LoadOptions) -> Result Loads the project found from ``dir`` (conf.toml there, in ``dir/source``, or in the nearest parent folder that has one) or the folders ``options`` names. Fails with ``core.registry.invalid`` (exit 2) when the engine registry has an adapter without an ID or version, or one ID twice, and with gd-conf's problems (``config.invalid``, ``project.missing``, ...) when the configuration cannot be read. Whether the registry has the readers the documents need is known when a build finds them (``build.reader``). .. rust:function:: pub fn watch_roots(config: &Config) -> Vec The paths ``guidedog serve`` watches for changes: the source folder, the Odin package folders and Rust crates the API pages are made from, and the static, extra, template, include, autodoc and locale folders outside the source folder (those inside it are watched with it). The build folder is never one of them; skip it while watching (see :rust:fn:`Project::watch_skip `). .. rubric:: Constants .. rust:const:: pub const DEPENDENCIES_FILE: &str = "gd-dependencies.json" The manifest's file name in the output folder. .. rust:const:: pub const DEPENDENCIES_SCHEMA: u32 = 1 The version of the manifest's form; it changes when a field changes meaning. .. rust:const:: pub const RECORDS_LOCK: &str = "build.lock" The lock file's name in the records folder.