Skip to main content

Builder

Struct Builder 

Source
pub struct Builder { /* private fields */ }
Expand description

What to generate, and where.

Every method takes and returns the builder, so a build.rs reads as one expression.

Implementations§

Source§

impl Builder

Source

pub fn out_dir(self, dir: impl Into<PathBuf>) -> Self

Writes generated files to dir instead of OUT_DIR.

A build script needs this only when it writes somewhere it also reads from, such as a checked-in copy; OUT_DIR is the ordinary destination, and where openusd::include_schema! looks.

Source

pub fn plug_info(self, path: impl Into<PathBuf>) -> Self

Reads what a plugInfo.json declares beside its schemas, the way C++ registers it: the metadata fields of each plugin’s SdfMetadata block and the kinds of its Kinds block.

Each plugin’s declarations belong to the library whose libraryName is the plugin’s Name. They are registered with that library’s schemas; a field is also named in its tokens, and read and written through extension traits on the handles it applies to (AttributeMetadata and its siblings). A plugin with no schema library is named with declaration_family, and one file may hold plugins of both sorts. A plugin that is neither is an error when generate runs.

Source

pub fn declaration_family(self, name: impl Into<String>) -> Self

Generates the plugin called name as a family of its own, for a plugin that declares kinds or metadata fields and has no schema library. Repeatable.

The plugin is read from a file plug_info names. Its file is written as <name>.rs and included with openusd::include_schema! like a schema library’s, and its SCHEMAS registers the declarations and no schema. A name no configured plugInfo.json declares is an error when generate runs.

Source

pub fn shader_defs( self, library: impl Into<String>, path: impl Into<PathBuf>, ) -> Self

Generates a view of each shader node the layer at path defines, as usdShaders’s shaderDefs.usda defines UsdPreviewSurface and its companions.

Each def Shader prim authoring an info:id is a node, and its view wraps the usdShade library’s Shader view, so that library must be placed with extern_library. The file is written as <library>.rs and included with openusd::include_schema! like a schema library’s.

Source

pub fn search_path(self, dir: impl Into<PathBuf>) -> Self

Adds a directory that a schema.usda’s sublayers resolve through, the way ar::DefaultResolver::with_search_paths takes them.

Upstream schemas sublayer each other by bare path (subLayers = [@usd/schema.usda@]), which is what a search path resolves. Repeatable, and searched in the order given.

Source

pub fn extern_library( self, library: impl Into<String>, rust_path: impl Into<String>, ) -> Self

Declares where a library this run does not generate already lives, so the generated code can name types from it.

library is the libraryName that library’s schema.usda declares and rust_path the module path its views are reachable at, as in ("usdGeom", "openusd_schemas::geom"). A class inheriting from, or reflecting, a schema of a library this run does not generate needs it declared here; a class of a declared library that a schema’s prose names is linked to where it lives, and one of an undeclared library is left as prose. The path is to the library’s views, so a library generated for its schema data alone has nothing to declare. Keyed by library name, so declaring one twice keeps the last.

Source

pub fn schema(self, path: impl Into<PathBuf>) -> Self

Adds a schema.usda to generate a library from. Repeatable.

Source

pub fn schema_data(self, path: impl Into<PathBuf>) -> Self

Adds a schema.usda to generate schema data from, without its views.

The generated file still carries the tokens and the declaration table a registry is built from; what it leaves out is the trait and view per schema. That is what a crate whose API for these schemas is written by hand wants: the declarations a registry needs, without a generated set of views beside its own to collide with.

A schema that declares skipCodeGeneration is treated this way whether or not it is named here.

Source

pub fn token_enum(self, declared: TokenEnum) -> Self

Adds a Rust enum over a token property’s allowedTokens. Repeatable.

See TokenEnum for what it takes and why it is named rather than derived. The enum joins the generated file of the library its source property belongs to, beside that library’s token constants; a library no configured enum names generates exactly what it did before.

An enum whose library this run does not build generates nothing, so one list of enums describes families that are each behind their own feature. Naming a library this build neither generates nor declares with extern_library is an error.

Source

pub fn generate(self) -> Result<(), Error>

Generates every configured library.

Configuring no schemas, shader definitions or declaration families is not an error and writes nothing: a consumer whose families are feature-gated generates none of them when its features are off, and its build.rs should not have to know that.

Otherwise the output directory must be known, from out_dir or from the OUT_DIR a build script runs with, and is created if it does not exist.

Each library writes one file, <library>.rs, named after the libraryName its /GLOBAL declares and included by openusd::include_schema!. It carries both the views and the schema data, the latter as the declaration table usd::SchemaRegistryBuilder::register takes. A library that asked for skipCodeGeneration writes that file too, carrying its tokens and its schema data without the views — the data is what a registry is built from, so a library declining an API still has to ship it.

Two schemas declaring the same libraryName would write one file, and are refused before anything is written. A file already holding what this run generates is left untouched, its modification time with it.

Source

pub fn build_library( &self, schema: impl AsRef<Path>, views: Views, ) -> Result<Output, Error>

Generates one schema library, writing nothing.

The whole pipeline, for a caller that wants the result rather than the files: generate runs this over every schema schema named and writes what comes back. The schema is named here instead, so that list has no bearing on this call. A schema asking for skipCodeGeneration gets no views whatever views says.

Source

pub fn build_declarations(&self, family: &str) -> Result<Output, Error>

Generates the declaration-only family of the plugin called family, writing nothing: the file generate writes for a name declaration_family gave.

Source

pub fn build_shader_defs( &self, library: &str, path: impl AsRef<Path>, ) -> Result<NodeOutput, Error>

Generates the views of the shader nodes the layer at path defines, writing nothing: the file generate writes for a library shader_defs named.

Trait Implementations§

Source§

impl Debug for Builder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.