Skip to content

Commit

Permalink
Codegen: remove build_config from domain model
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Jan 21, 2024
1 parent 0eb3c4d commit e9c2b72
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 35 deletions.
3 changes: 0 additions & 3 deletions godot-codegen/src/class_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ impl FnDefinitions {
pub(crate) fn generate_class_files(
api: &ExtensionApi,
ctx: &mut Context,
_build_config: [&str; 2],
gen_path: &Path,
submit_fn: &mut SubmitFn,
) {
Expand Down Expand Up @@ -141,7 +140,6 @@ pub(crate) fn generate_class_files(
pub(crate) fn generate_builtin_class_files(
api: &ExtensionApi,
ctx: &mut Context,
_build_config: [&str; 2],
gen_path: &Path,
submit_fn: &mut SubmitFn,
) {
Expand Down Expand Up @@ -179,7 +177,6 @@ pub(crate) fn generate_builtin_class_files(
pub(crate) fn generate_native_structures_files(
api: &ExtensionApi,
ctx: &mut Context,
_build_config: [&str; 2],
gen_path: &Path,
submit_fn: &mut SubmitFn,
) {
Expand Down
11 changes: 4 additions & 7 deletions godot-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ pub fn generate_sys_files(
h_path: &Path,
watch: &mut godot_bindings::StopWatch,
) {
let (json_api, build_config) = load_extension_api(watch);
let json_api = load_extension_api(watch);

let mut ctx = Context::build_from_api(&json_api);
watch.record("build_context");

let api = ExtensionApi::from_json(&json_api, build_config, &mut ctx);
let api = ExtensionApi::from_json(&json_api, &mut ctx);
watch.record("map_domain_models");

// TODO if ctx is no longer needed for below functions:
Expand Down Expand Up @@ -99,11 +99,11 @@ pub fn generate_core_files(core_gen_path: &Path) {

generate_core_mod_file(core_gen_path, &mut submit_fn);

let (json_api, build_config) = load_extension_api(&mut watch);
let json_api = load_extension_api(&mut watch);
let mut ctx = Context::build_from_api(&json_api);
watch.record("build_context");

let api = ExtensionApi::from_json(&json_api, build_config, &mut ctx);
let api = ExtensionApi::from_json(&json_api, &mut ctx);
watch.record("map_domain_models");

// TODO if ctx is no longer needed for below functions:
Expand All @@ -121,7 +121,6 @@ pub fn generate_core_files(core_gen_path: &Path) {
generate_class_files(
&api,
&mut ctx,
build_config,
&core_gen_path.join("classes"),
&mut submit_fn,
);
Expand All @@ -130,7 +129,6 @@ pub fn generate_core_files(core_gen_path: &Path) {
generate_builtin_class_files(
&api,
&mut ctx,
build_config,
&core_gen_path.join("builtin_classes"),
&mut submit_fn,
);
Expand All @@ -139,7 +137,6 @@ pub fn generate_core_files(core_gen_path: &Path) {
generate_native_structures_files(
&api,
&mut ctx,
build_config,
&core_gen_path.join("native"),
&mut submit_fn,
);
Expand Down
1 change: 0 additions & 1 deletion godot-codegen/src/models/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub struct ExtensionApi {
pub native_structures: Vec<NativeStructure>,
pub utility_functions: Vec<UtilityFunction>,
pub global_enums: Vec<Enum>,
pub build_config: [&'static str; 2],
pub godot_version: GodotApiVersion,

/// Map `(original Godot name, build config) -> builtin size` in bytes.
Expand Down
7 changes: 1 addition & 6 deletions godot-codegen/src/models/domain_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ use std::collections::HashMap;
// Top-level

impl ExtensionApi {
pub fn from_json(
json: &JsonExtensionApi,
build_config: [&'static str; 2],
ctx: &mut Context,
) -> Self {
pub fn from_json(json: &JsonExtensionApi, ctx: &mut Context) -> Self {
Self {
builtins: BuiltinVariant::all_from_json(&json.global_enums, &json.builtin_classes, ctx),
classes: json
Expand All @@ -54,7 +50,6 @@ impl ExtensionApi {
.iter()
.map(|json| Enum::from_json(json, None))
.collect(),
build_config,
godot_version: GodotApiVersion::from_json(&json.header),
builtin_sizes: Self::builtin_size_from_json(&json.builtin_class_sizes),
}
Expand Down
20 changes: 2 additions & 18 deletions godot-codegen/src/models/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,22 +251,7 @@ impl JsonMethodReturn {
// ----------------------------------------------------------------------------------------------------------------------------------------------
// Implementation

pub fn load_extension_api(
watch: &mut godot_bindings::StopWatch,
) -> (JsonExtensionApi, [&'static str; 2]) {
// For float/double inference, see:
// * https://github.com/godotengine/godot-proposals/issues/892
// * https://github.com/godotengine/godot-cpp/pull/728
// Have to do target_pointer_width check after code generation
// So pass a [32bit, 64bit] around of appropriate precision
// For why see: https://github.com/rust-lang/rust/issues/42587
let build_config: [&'static str; 2] = {
if cfg!(feature = "double-precision") {
["double_32", "double_64"]
} else {
["float_32", "float_64"]
}
};
pub fn load_extension_api(watch: &mut godot_bindings::StopWatch) -> JsonExtensionApi {
// Use type inference, so we can accept both String (dynamically resolved) and &str (prebuilt).
// #[allow]: as_ref() acts as impl AsRef<str>, but with conditional compilation

Expand All @@ -279,6 +264,5 @@ pub fn load_extension_api(
watch.record("deserialize_json");

println!("Parsed extension_api.json for version {:?}", model.header);

(model, build_config)
model
}
7 changes: 7 additions & 0 deletions godot-ffi/src/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
///
/// Note: due to `align(4)` / `align(8)` and not `packed` repr, this type may be bigger than `N` bytes
/// (which should be OK since C++ just needs to read/write those `N` bytes reliably).
///
///
/// For float/double inference, see:
/// * https://github.com/godotengine/godot-proposals/issues/892
/// * https://github.com/godotengine/godot-cpp/pull/728
///
/// We have to do a `target_pointer_width` check *after* code generation, see https://github.com/rust-lang/rust/issues/42587.
#[cfg_attr(target_pointer_width = "32", repr(C, align(4)))]
#[cfg_attr(target_pointer_width = "64", repr(C, align(8)))]
#[derive(Copy, Clone)]
Expand Down

0 comments on commit e9c2b72

Please sign in to comment.