Skip to main content

unity_solution_generator/
lib.rs

1//! Unity Solution Generator core library.
2//!
3//! Ported from the Swift `SolutionGeneratorCore` target.
4
5/// Version of the user-visible `csproj.lock` format. Bump only on intentional
6/// schema changes; `csproj.lock` may be checked in, so a bump means consumers
7/// re-lock against possibly different Unity installs. See [[architecture.md]].
8pub const LOCKFILE_VERSION: u32 = 1;
9
10/// Version of the dev-local cache files (`scan-cache`, `lock-fingerprint`,
11/// `.fingerprints/<hash>`). Bumping invalidates ALL three caches wholesale —
12/// no migrations. These files are gitignored under `Library/`, so cold-rebuild
13/// on bump is harmless. Cargo / Bazel idiom.
14pub const CACHE_VERSION: u32 = 1;
15
16pub mod defines;
17pub mod error;
18pub(crate) mod generate_cache;
19pub mod io;
20pub(crate) mod lock_cache;
21pub mod lockfile;
22pub mod lockfile_scanner;
23pub(crate) mod package_cache;
24pub mod paths;
25pub mod profile;
26pub mod project_scanner;
27pub mod solution_generator;
28pub mod typecheck;
29pub(crate) mod walk;
30pub mod xml;
31
32pub use defines::{generate_version_defines, parse_scripting_defines};
33pub use error::{GeneratorError, LockfileError, Result};
34pub use lockfile::{DllRef, Lockfile, LockfileIO, RefCategory};
35pub use lockfile_scanner::LockfileScanner;
36pub use paths::{
37    DEFAULT_GENERATOR_ROOT, lockfile_path, parent_directory, resolve_project_root, resolve_real_path,
38};
39pub use project_scanner::{AsmDefRecord, ProjectCategory, ProjectScanner, ScanResult, VersionDefine};
40pub use solution_generator::{
41    BuildConfig, BuildPlatform, GenerateOptions, GenerateResult, SolutionGenerator,
42};
43pub use typecheck::{TypecheckOptions, TypecheckResult};
44/// Test-only re-exports of internal helpers. Not part of the stable public API.
45#[doc(hidden)]
46pub mod __test_only {
47    pub use crate::lock_cache::{build_entries, is_valid};
48    pub use crate::typecheck::__test_only_build_rsp as build_rsp;
49}
50
51/// High-level convenience: parse string args + run the full generate pipeline.
52///
53/// Used by the CLI and by external FFI hosts (see meow-tower's BoxcatBridge).
54/// `platform` accepts `ios|android|osx`; `config` accepts `prod|dev|editor`.
55/// `extra_refs` is a comma-separated list of DLL paths (see `DllRef::parse_list`).
56/// Loads or scans the lockfile as needed.
57pub fn generate(
58    project_root: &str,
59    platform: &str,
60    config: &str,
61    output_dir: Option<&str>,
62    extra_refs: Option<&str>,
63) -> Result<()> {
64    let build_platform = BuildPlatform::parse(platform).ok_or_else(|| {
65        GeneratorError::Other(format!(
66            "Unknown platform '{platform}'. Use 'ios', 'android', or 'osx'."
67        ))
68    })?;
69    let build_config = BuildConfig::parse(config).ok_or_else(|| {
70        GeneratorError::Other(format!(
71            "Unknown config '{config}'. Use 'prod', 'dev', or 'editor'."
72        ))
73    })?;
74    let resolved = resolve_project_root(project_root);
75    let extra_refs_vec: Vec<DllRef> = extra_refs.map(DllRef::parse_list).unwrap_or_default();
76    let options = GenerateOptions::new(resolved.clone(), build_platform)
77        .with_build_config(build_config)
78        .with_output_dir(output_dir)
79        .with_extra_refs(extra_refs_vec);
80    let lockfile = LockfileIO::load_or_scan(&resolved, DEFAULT_GENERATOR_ROOT)?;
81    SolutionGenerator::new().generate_from_lockfile(&options, &lockfile)?;
82    Ok(())
83}