Skip to content

Commit

Permalink
CompilerNode interface (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
pretty-wise authored Jan 14, 2022
1 parent d7bca79 commit fa68895
Show file tree
Hide file tree
Showing 41 changed files with 957 additions and 515 deletions.
18 changes: 9 additions & 9 deletions client/data-build-cli/src/data-build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use clap::{AppSettings, Parser, Subcommand};
use lgn_content_store::ContentStoreAddr;
use lgn_data_build::DataBuildOptions;
use lgn_data_compiler::{
compiler_api::CompilationEnv, compiler_reg::CompilerRegistryOptions, Locale, Platform, Target,
compiler_api::CompilationEnv, compiler_node::CompilerRegistryOptions, Locale, Platform, Target,
};
use lgn_data_offline::ResourcePathId;
use lgn_data_runtime::ResourceTypeAndId;
Expand Down Expand Up @@ -151,17 +151,17 @@ fn main() -> Result<(), String> {
let locale = Locale::new(&locale);
let content_store_path = ContentStoreAddr::from(cas.as_str());

let compilers = {
if let Some(mut exe_dir) = std::env::args().next().map(|s| PathBuf::from(&s)) {
let compilers = std::env::args()
.next()
.and_then(|s| {
let mut exe_dir = PathBuf::from(&s);
if exe_dir.pop() && exe_dir.is_dir() {
CompilerRegistryOptions::from_dir(&exe_dir)
Some(CompilerRegistryOptions::from_dir(&exe_dir))
} else {
CompilerRegistryOptions::default()
None
}
} else {
CompilerRegistryOptions::default()
}
};
})
.unwrap_or_default();

let mut build = DataBuildOptions::new(build_index, compilers)
.content_store(&content_store_path)
Expand Down
2 changes: 1 addition & 1 deletion client/data-build-cli/src/scrape/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{

use lgn_content_store::ContentStoreAddr;
use lgn_data_build::{DataBuild, DataBuildOptions};
use lgn_data_compiler::compiler_reg::CompilerRegistryOptions;
use lgn_data_compiler::compiler_node::CompilerRegistryOptions;
use lgn_data_offline::resource::Project;
use lgn_data_runtime::ResourceType;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion client/data-build-cli/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fs;
use lgn_content_store::{ContentStoreAddr, HddContentStore};
use lgn_data_build::DataBuildOptions;
use lgn_data_compiler::{
compiler_api::CompilationEnv, compiler_reg::CompilerRegistryOptions, Locale, Platform, Target,
compiler_api::CompilationEnv, compiler_node::CompilerRegistryOptions, Locale, Platform, Target,
};
use lgn_data_offline::{
resource::{Project, ResourcePathName, ResourceRegistryOptions},
Expand Down
12 changes: 7 additions & 5 deletions compiler/material/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use lgn_data_compiler::{
compiler_utils::{hash_code_and_data, path_id_to_binary},
};
use lgn_data_offline::{ResourcePathId, Transform};
use lgn_data_runtime::Resource;
use lgn_data_runtime::{AssetRegistryOptions, Resource};

pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
name: env!("CARGO_CRATE_NAME"),
Expand All @@ -73,15 +73,17 @@ pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
lgn_graphics_offline::Material::TYPE,
lgn_graphics_runtime::Material::TYPE,
),
init_func: init,
compiler_hash_func: hash_code_and_data,
compile_func: compile,
};

fn init(registry: AssetRegistryOptions) -> AssetRegistryOptions {
registry.add_loader::<lgn_graphics_offline::Material>()
}

fn compile(mut context: CompilerContext<'_>) -> Result<CompilationOutput, CompilerError> {
let resources = context
.take_registry()
.add_loader::<lgn_graphics_offline::Material>()
.create();
let resources = context.registry();

let resource =
resources.load_sync::<lgn_graphics_offline::Material>(context.source.resource_id());
Expand Down
12 changes: 7 additions & 5 deletions compiler/psd2tex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use lgn_data_compiler::{
compiler_utils::hash_code_and_data,
};
use lgn_data_offline::Transform;
use lgn_data_runtime::Resource;
use lgn_data_runtime::{AssetRegistryOptions, Resource};
use lgn_graphics_offline::PsdFile;

pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
Expand All @@ -74,15 +74,17 @@ pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
lgn_graphics_offline::PsdFile::TYPE,
lgn_graphics_offline::Texture::TYPE,
),
init_func: init,
compiler_hash_func: hash_code_and_data,
compile_func: compile,
};

fn init(options: AssetRegistryOptions) -> AssetRegistryOptions {
options.add_loader::<lgn_graphics_offline::PsdFile>()
}

fn compile(mut context: CompilerContext<'_>) -> Result<CompilationOutput, CompilerError> {
let resources = context
.take_registry()
.add_loader::<lgn_graphics_offline::PsdFile>()
.create();
let resources = context.registry();

let resource =
resources.load_sync::<lgn_graphics_offline::PsdFile>(context.source.resource_id());
Expand Down
12 changes: 7 additions & 5 deletions compiler/runtime-entity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use lgn_data_compiler::{
compiler_utils::hash_code_and_data,
};
use lgn_data_offline::{ResourcePathId, Transform};
use lgn_data_runtime::Resource;
use lgn_data_runtime::{AssetRegistryOptions, Resource};
use sample_data_compiler::offline_to_runtime::FromOffline;
use sample_data_offline as offline_data;
use sample_data_runtime as runtime_data;
Expand All @@ -75,15 +75,17 @@ pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
code_version: "1",
data_version: "1",
transform: &Transform::new(offline_data::Entity::TYPE, runtime_data::Entity::TYPE),
init_func: init,
compiler_hash_func: hash_code_and_data,
compile_func: compile,
};

fn init(options: AssetRegistryOptions) -> AssetRegistryOptions {
options.add_loader::<offline_data::Entity>()
}

fn compile(mut context: CompilerContext<'_>) -> Result<CompilationOutput, CompilerError> {
let resources = context
.take_registry()
.add_loader::<offline_data::Entity>()
.create();
let resources = context.registry();

let entity = resources.load_sync::<offline_data::Entity>(context.source.resource_id());
let entity = entity.get(&resources).unwrap();
Expand Down
12 changes: 7 additions & 5 deletions compiler/runtime-instance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use lgn_data_compiler::{
compiler_utils::hash_code_and_data,
};
use lgn_data_offline::{ResourcePathId, Transform};
use lgn_data_runtime::Resource;
use lgn_data_runtime::{AssetRegistryOptions, Resource};
use sample_data_compiler::offline_to_runtime::FromOffline;
use sample_data_offline as offline_data;
use sample_data_runtime as runtime_data;
Expand All @@ -75,15 +75,17 @@ pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
code_version: "1",
data_version: "1",
transform: &Transform::new(offline_data::Instance::TYPE, runtime_data::Instance::TYPE),
init_func: init,
compiler_hash_func: hash_code_and_data,
compile_func: compile,
};

fn init(options: AssetRegistryOptions) -> AssetRegistryOptions {
options.add_loader::<offline_data::Instance>()
}

fn compile(mut context: CompilerContext<'_>) -> Result<CompilationOutput, CompilerError> {
let resources = context
.take_registry()
.add_loader::<offline_data::Instance>()
.create();
let resources = context.registry();

let instance = resources.load_sync::<offline_data::Instance>(context.source.resource_id());
let instance = instance.get(&resources).unwrap();
Expand Down
12 changes: 7 additions & 5 deletions compiler/runtime-mesh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use lgn_data_compiler::{
compiler_utils::hash_code_and_data,
};
use lgn_data_offline::{ResourcePathId, Transform};
use lgn_data_runtime::Resource;
use lgn_data_runtime::{AssetRegistryOptions, Resource};
use sample_data_compiler::offline_to_runtime::FromOffline;
use sample_data_offline as offline_data;
use sample_data_runtime as runtime_data;
Expand All @@ -75,15 +75,17 @@ pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
code_version: "1",
data_version: "1",
transform: &Transform::new(offline_data::Mesh::TYPE, runtime_data::Mesh::TYPE),
init_func: init,
compiler_hash_func: hash_code_and_data,
compile_func: compile,
};

fn init(registry: AssetRegistryOptions) -> AssetRegistryOptions {
registry.add_loader::<offline_data::Mesh>()
}

fn compile(mut context: CompilerContext<'_>) -> Result<CompilationOutput, CompilerError> {
let resources = context
.take_registry()
.add_loader::<offline_data::Mesh>()
.create();
let resources = context.registry();

let mesh = resources.load_sync::<offline_data::Mesh>(context.source.resource_id());
let mesh = mesh.get(&resources).unwrap();
Expand Down
12 changes: 7 additions & 5 deletions compiler/test-atoi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use lgn_data_compiler::{
compiler_utils::hash_code_and_data,
};
use lgn_data_offline::Transform;
use lgn_data_runtime::Resource;
use lgn_data_runtime::{AssetRegistryOptions, Resource};

pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
name: env!("CARGO_CRATE_NAME"),
Expand All @@ -75,15 +75,17 @@ pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
text_resource::TextResource::TYPE,
integer_asset::IntegerAsset::TYPE,
),
init_func: init,
compiler_hash_func: hash_code_and_data,
compile_func: compile,
};

fn init(registry: AssetRegistryOptions) -> AssetRegistryOptions {
registry.add_loader::<text_resource::TextResource>()
}

fn compile(mut context: CompilerContext<'_>) -> Result<CompilationOutput, CompilerError> {
let resources = context
.take_registry()
.add_loader::<text_resource::TextResource>()
.create();
let resources = context.registry();

let resource = resources.load_sync::<text_resource::TextResource>(context.source.resource_id());
let resource = resource.get(&resources).unwrap();
Expand Down
12 changes: 7 additions & 5 deletions compiler/test-base64/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use lgn_data_compiler::{
compiler_utils::hash_code_and_data,
};
use lgn_data_offline::Transform;
use lgn_data_runtime::Resource;
use lgn_data_runtime::{AssetRegistryOptions, Resource};

pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
name: env!("CARGO_CRATE_NAME"),
Expand All @@ -76,15 +76,17 @@ pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
binary_resource::BinaryResource::TYPE,
text_resource::TextResource::TYPE,
),
init_func: init,
compiler_hash_func: hash_code_and_data,
compile_func: compile,
};

fn init(registry: AssetRegistryOptions) -> AssetRegistryOptions {
registry.add_loader::<binary_resource::BinaryResource>()
}

fn compile(mut context: CompilerContext<'_>) -> Result<CompilationOutput, CompilerError> {
let resources = context
.take_registry()
.add_loader::<binary_resource::BinaryResource>()
.create();
let resources = context.registry();

let resource =
resources.load_sync::<binary_resource::BinaryResource>(context.source.resource_id());
Expand Down
12 changes: 7 additions & 5 deletions compiler/test-refs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use lgn_data_compiler::{
compiler_utils::hash_code_and_data,
};
use lgn_data_offline::Transform;
use lgn_data_runtime::Resource;
use lgn_data_runtime::{AssetRegistryOptions, Resource};

pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
name: env!("CARGO_CRATE_NAME"),
Expand All @@ -75,15 +75,17 @@ pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
refs_resource::TestResource::TYPE,
refs_asset::RefsAsset::TYPE,
),
init_func: init,
compiler_hash_func: hash_code_and_data,
compile_func: compile,
};

fn init(registry: AssetRegistryOptions) -> AssetRegistryOptions {
registry.add_loader::<refs_resource::TestResource>()
}

fn compile(mut context: CompilerContext<'_>) -> Result<CompilationOutput, CompilerError> {
let resources = context
.take_registry()
.add_loader::<refs_resource::TestResource>()
.create();
let resources = context.registry();

let resource = resources.load_sync::<refs_resource::TestResource>(context.source.resource_id());
assert!(!resource.is_err(&resources));
Expand Down
12 changes: 7 additions & 5 deletions compiler/test-reverse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use lgn_data_compiler::{
compiler_utils::hash_code_and_data,
};
use lgn_data_offline::{resource::ResourceProcessor, Transform};
use lgn_data_runtime::Resource;
use lgn_data_runtime::{AssetRegistryOptions, Resource};

pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
name: env!("CARGO_CRATE_NAME"),
Expand All @@ -75,15 +75,17 @@ pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
text_resource::TextResource::TYPE,
text_resource::TextResource::TYPE,
),
init_func: init,
compiler_hash_func: hash_code_and_data,
compile_func: compile,
};

fn init(registry: AssetRegistryOptions) -> AssetRegistryOptions {
registry.add_loader::<text_resource::TextResource>()
}

fn compile(mut context: CompilerContext<'_>) -> Result<CompilationOutput, CompilerError> {
let resources = context
.take_registry()
.add_loader::<text_resource::TextResource>()
.create();
let resources = context.registry();

let resource = resources.load_sync::<text_resource::TextResource>(context.source.resource_id());
let resource = resource.get(&resources).unwrap();
Expand Down
13 changes: 8 additions & 5 deletions compiler/test-split/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use lgn_data_compiler::{
compiler_utils::hash_code_and_data,
};
use lgn_data_offline::{resource::ResourceProcessor, Transform};
use lgn_data_runtime::Resource;
use lgn_data_runtime::{AssetRegistryOptions, Resource};

pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
name: env!("CARGO_CRATE_NAME"),
Expand All @@ -75,16 +75,19 @@ pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
multitext_resource::MultiTextResource::TYPE,
text_resource::TextResource::TYPE,
),
init_func: init,
compiler_hash_func: hash_code_and_data,
compile_func: compile,
};

fn compile(mut context: CompilerContext<'_>) -> Result<CompilationOutput, CompilerError> {
let resources = context
.take_registry()
fn init(registry: AssetRegistryOptions) -> AssetRegistryOptions {
registry
.add_loader::<multitext_resource::MultiTextResource>()
.add_loader::<text_resource::TextResource>()
.create();
}

fn compile(mut context: CompilerContext<'_>) -> Result<CompilationOutput, CompilerError> {
let resources = context.registry();

let resource =
resources.load_sync::<multitext_resource::MultiTextResource>(context.source.resource_id());
Expand Down
12 changes: 7 additions & 5 deletions compiler/tex2bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use lgn_data_compiler::{
compiler_utils::hash_code_and_data,
};
use lgn_data_offline::Transform;
use lgn_data_runtime::Resource;
use lgn_data_runtime::{AssetRegistryOptions, Resource};

pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
name: env!("CARGO_CRATE_NAME"),
Expand All @@ -75,15 +75,17 @@ pub static COMPILER_INFO: CompilerDescriptor = CompilerDescriptor {
lgn_graphics_offline::Texture::TYPE,
lgn_graphics_runtime::Texture::TYPE,
),
init_func: init,
compiler_hash_func: hash_code_and_data,
compile_func: compile,
};

fn init(registry: AssetRegistryOptions) -> AssetRegistryOptions {
registry.add_loader::<lgn_graphics_offline::Texture>()
}

fn compile(mut context: CompilerContext<'_>) -> Result<CompilationOutput, CompilerError> {
let resources = context
.take_registry()
.add_loader::<lgn_graphics_offline::Texture>()
.create();
let resources = context.registry();

let resource =
resources.load_sync::<lgn_graphics_offline::Texture>(context.source.resource_id());
Expand Down
Loading

0 comments on commit fa68895

Please sign in to comment.