Skip to content

Commit 3448eae

Browse files
committed
build.rs api rework
1 parent cda8182 commit 3448eae

17 files changed

Lines changed: 912 additions & 1954 deletions

File tree

prebindgen-ext/src/core/inline_fn.rs

Lines changed: 0 additions & 117 deletions
This file was deleted.

prebindgen-ext/src/core/mod.rs

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
11
//! Core: language-agnostic primitives for the Registry-based pipeline.
22
//!
3-
//! Pipeline shape:
4-
//! 1. [`registry::Registry::from_source`] — scan a `prebindgen::Source`
5-
//! into a flat type table.
6-
//! 2. [`resolve::resolve`] — fixed-point loop driving the configured
7-
//! [`prebindgen_ext::PrebindgenExt`] across all rank phases and both
8-
//! directions.
9-
//! 3. [`write::write_rust`] — emit the resolved bindings file.
10-
//! 4. (Destination-language Kotlin emission lives in `crate::kotlin`.)
11-
//!
12-
//! `inline_fn`, `name_mangler`, `type_binding`, `type_registry` are kept
13-
//! transitionally; they're only referenced by the unmigrated
14-
//! [`crate::kotlin::KotlinInterfaceGenerator`] which still consumes the
15-
//! old `TypeRegistry` shape. They will be removed once that generator
16-
//! lands on the new `Registry`.
3+
//! Public entry point: [`registry::Registry::from_source`] scans a
4+
//! `prebindgen::Source` into a flat type table; [`registry::Registry::write_rust`]
5+
//! resolves every required type using the configured
6+
//! [`prebindgen_ext::PrebindgenExt`] and emits the bindings file. Kotlin
7+
//! emission for the JNI back-end lives in `crate::jni::JniExt::write_kotlin`.
178
18-
pub mod inline_fn;
19-
pub mod name_mangler;
209
pub mod niches;
2110
pub mod prebindgen_ext;
2211
pub mod registry;
23-
pub mod resolve;
24-
pub mod type_binding;
25-
pub mod type_registry;
26-
pub mod write;
12+
pub(crate) mod resolve;
13+
pub(crate) mod write;
2714

2815
pub use niches::{NicheSlot, Niches};
29-
30-
pub use type_registry::{
31-
input_option, input_result, nullable_to_option, option_to_nullable, option_wire_type,
32-
output_option, output_result, primitive_builtins, result_wire_type, TypeRegistry,
33-
};
16+
pub use registry::Registry;

prebindgen-ext/src/core/name_mangler.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.

prebindgen-ext/src/core/registry.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,36 @@ impl fmt::Display for ScanError {
202202

203203
impl std::error::Error for ScanError {}
204204

205+
/// Combined error surfaced by [`Registry::write_rust`].
206+
#[derive(Debug)]
207+
pub enum WriteRustError {
208+
Resolve(crate::core::resolve::ResolveError),
209+
Write(crate::core::write::WriteError),
210+
}
211+
212+
impl fmt::Display for WriteRustError {
213+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
214+
match self {
215+
WriteRustError::Resolve(e) => write!(f, "{}", e),
216+
WriteRustError::Write(e) => write!(f, "{}", e),
217+
}
218+
}
219+
}
220+
221+
impl std::error::Error for WriteRustError {}
222+
223+
impl From<crate::core::resolve::ResolveError> for WriteRustError {
224+
fn from(e: crate::core::resolve::ResolveError) -> Self {
225+
WriteRustError::Resolve(e)
226+
}
227+
}
228+
229+
impl From<crate::core::write::WriteError> for WriteRustError {
230+
fn from(e: crate::core::write::WriteError) -> Self {
231+
WriteRustError::Write(e)
232+
}
233+
}
234+
205235
impl Registry {
206236
/// Construct a `Registry` by scanning a `prebindgen::Source`.
207237
pub fn from_source(source: &Source) -> Result<Self, ScanError> {
@@ -467,6 +497,19 @@ impl Registry {
467497
}
468498
self.type_locations.entry(key).or_insert_with(|| loc.clone());
469499
}
500+
501+
/// One-shot: resolve every required type using `ext`, then write the
502+
/// generated Rust bindings file. The single public entry point for
503+
/// language-specific binding generation — language-agnostic because
504+
/// `ext` is any [`crate::core::prebindgen_ext::PrebindgenExt`] impl.
505+
pub fn write_rust<E: crate::core::prebindgen_ext::PrebindgenExt>(
506+
&mut self,
507+
ext: &E,
508+
out_path: impl AsRef<std::path::Path>,
509+
) -> Result<std::path::PathBuf, WriteRustError> {
510+
crate::core::resolve::resolve(self, ext)?;
511+
Ok(crate::core::write::write_rust(self, ext, out_path)?)
512+
}
470513
}
471514

472515
// ──────────────────────────────────────────────────────────────────────

prebindgen-ext/src/core/type_binding.rs

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)