Skip to content

Commit

Permalink
Merge pull request #29 from Indra-db/replace-C-defines-with-cargo-fea…
Browse files Browse the repository at this point in the history
…tures

replace C defines with Rust features + feature lock rust code
  • Loading branch information
Indra-db authored Mar 26, 2024
2 parents a64ef7a + d0cefc2 commit 5855fc5
Show file tree
Hide file tree
Showing 8 changed files with 413 additions and 103 deletions.
156 changes: 139 additions & 17 deletions flecs_ecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,45 @@ flecs_ecs_sys = { path = "../flecs_ecs_sys" }
[dev-dependencies]
criterion = "0.5.1"
seq-macro = "0.3.5"
rand = "0.8.5"
rand = "0.8.5"
ctor = "0.2.7"

[[bench]]
name = "query"
harness = false

[features]
flecs_app = []
flecs_pipeline = []
flecs_system = []
flecs_rules = []
flecs_timer = []
flecs_doc = []
flecs_rest = []
flecs_meta = []
flecs_metrics = []
flecs_ecs_asserts = []
flecs_enable_all_asserts = ["flecs_ecs_asserts"]
flecs_enable_all_asserts = ["flecs_ecs_asserts"] # TODO: add C assert feature and make it a disable? feature instead
sys_regenerate_binding = ["flecs_ecs_sys/regenerate_binding"]
sys_build_debug = ["flecs_ecs_sys/build_debug"]

# Flecs C defines / features
flecs_module = ["flecs_ecs_sys/flecs_module"] # Module support
flecs_parser = ["flecs_ecs_sys/flecs_parser"] # String parser for queries
flecs_plecs = ["flecs_ecs_sys/flecs_plecs", "flecs_module", "flecs_parser", "flecs_expr"] # ECS data definition format
flecs_rules = ["flecs_ecs_sys/flecs_rules"] # Constraint solver for advanced queries
flecs_snapshot = ["flecs_ecs_sys/flecs_snapshot"] # Snapshot & restore ECS data
flecs_stats = ["flecs_ecs_sys/flecs_stats"] # Access runtime statistics
flecs_monitor = ["flecs_ecs_sys/flecs_monitor","flecs_stats", "flecs_system", "flecs_timer"] # Track runtime statistics periodically
flecs_metrics = ["flecs_ecs_sys/flecs_metrics", "flecs_meta", "flecs_units", "flecs_pipeline"] # Expose component data as statistics
flecs_alerts = ["flecs_ecs_sys/flecs_alerts", "flecs_rules", "flecs_pipeline"] # Monitor conditions for errors
flecs_system = ["flecs_ecs_sys/flecs_system", "flecs_module"] # System support
flecs_pipeline = ["flecs_ecs_sys/flecs_pipeline", "flecs_module", "flecs_system"] # Pipeline support
flecs_timer = ["flecs_ecs_sys/flecs_timer", "flecs_module", "flecs_pipeline"] # Timer support
flecs_meta = ["flecs_ecs_sys/flecs_meta", "flecs_module"] # Reflection support
flecs_units = ["flecs_ecs_sys/flecs_units", "flecs_module", "flecs_meta"] # Builtin standard units
flecs_expr = ["flecs_ecs_sys/flecs_expr", "flecs_meta", "flecs_parser"] # Parsing strings to/from component values
flecs_json = ["flecs_ecs_sys/flecs_json", "flecs_expr"] # Parsing JSON to/from component values
flecs_doc = ["flecs_ecs_sys/flecs_doc", "flecs_module"] # Document entities & components
flecs_coredoc = ["flecs_ecs_sys/flecs_coredoc","flecs_doc", "flecs_meta"] # Documentation for core entities & components
flecs_log = ["flecs_ecs_sys/flecs_log"] # When enabled ECS provides more detailed logs
flecs_app = ["flecs_ecs_sys/flecs_app", "flecs_pipeline"] # Application addon
flecs_os_api_impl = ["flecs_ecs_sys/flecs_os_api_impl"] # Default implementation for OS API
flecs_http = ["flecs_ecs_sys/flecs_http"] # Tiny HTTP server for connecting to remote UI
flecs_rest = ["flecs_ecs_sys/flecs_rest", "flecs_http", "flecs_json", "flecs_rules", "flecs_pipeline"] # REST API for querying application data
flecs_journal = ["flecs_ecs_sys/flecs_journal","flecs_log"] # Journaling addon (disabled by default)

# Enabling this will not build a copy of flecs into this library.
# Instead, the executable that this is linked with will need to
# provide the symbols required. This is useful when using both
Expand All @@ -50,19 +67,124 @@ sys_build_debug = ["flecs_ecs_sys/build_debug"]
sys_disable_build_c_library = ["flecs_ecs_sys/disable_build_c_library"]

default = [

"flecs_enable_all_asserts",
"flecs_module",
"flecs_parser",
"flecs_plecs",
"flecs_rules",
"flecs_snapshot",
"flecs_stats",
"flecs_monitor",
"flecs_metrics",
"flecs_alerts",
"flecs_system",
"flecs_pipeline",
"flecs_timer",
"flecs_doc",
"flecs_rest",
"flecs_meta",
"flecs_metrics",
"flecs_rules",
"flecs_units",
"flecs_expr",
"flecs_json",
"flecs_doc",
"flecs_coredoc",
"flecs_log",
"flecs_app",
"flecs_pipeline",
"flecs_os_api_impl",
"flecs_http",
"flecs_rest",
]

[target.'cfg(any())'.dependencies]
flecs_ecs_derive = { version = "=0.1.0", path = "../flecs_ecs_derive" }
flecs_ecs_sys = { version = "=0.1.0", path = "../flecs_ecs_sys" }


# These examples are only the examples that rely on a certain feature to compile successfully.
[[example]]
name = "system_ctx"
path = "examples/system_ctx.rs"
required-features = ["flecs_system"]

[[example]]
name = "system_custom_phases_no_builtin"
path = "examples/system_custom_phases_no_builtin.rs"
required-features = ["flecs_system"]

[[example]]
name = "system_custom_phases"
path = "examples/system_custom_phases.rs"
required-features = ["flecs_system"]

[[example]]
name = "system_custom_runner"
path = "examples/system_custom_runner.rs"
required-features = ["flecs_system"]

[[example]]
name = "system_custom_pipeline"
path = "examples/system_custom_pipeline.rs"
required-features = ["flecs_system"]

[[example]]
name = "system_delta_time"
path = "examples/system_delta_time.rs"
required-features = ["flecs_system"]

[[example]]
name = "system_mutate_entity_handle"
path = "examples/system_mutate_entity_handle.rs"
required-features = ["flecs_system"]

[[example]]
name = "system_mutate_entity"
path = "examples/system_mutate_entity.rs"
required-features = ["flecs_system"]

[[example]]
name = "system_no_readonly"
path = "examples/system_no_readonly.rs"
required-features = ["flecs_system"]

[[example]]
name = "system_pipeline"
path = "examples/system_pipeline.rs"
required-features = ["flecs_system"]

[[example]]
name = "system_startup_system"
path = "examples/system_startup_system.rs"
required-features = ["flecs_system"]

[[example]]
name = "system_sync_point_delete"
path = "examples/system_sync_point_delete.rs"
required-features = ["flecs_system"]

[[example]]
name = "system_sync_point"
path = "examples/system_sync_point.rs"
required-features = ["flecs_system"]

[[example]]
name = "system_target_fps"
path = "examples/system_target_fps.rs"
required-features = ["flecs_system"]

[[example]]
name = "system_time_interval"
path = "examples/system_time_interval.rs"
required-features = ["flecs_system"]

[[example]]
name = "a_hello_world"
path = "examples/a_hello_world.rs"
required-features = ["flecs_system"]

[[example]]
name = "system_basics"
path = "examples/system_basics.rs"
required-features = ["flecs_system"]

[[example]]
name = "query_sorting"
path = "examples/query_sorting.rs"
required-features = ["flecs_system"]
17 changes: 12 additions & 5 deletions flecs_ecs/src/core/c_types.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#![allow(non_upper_case_globals)]

use crate::{
core::component_registration::{
try_register_struct_component, try_register_struct_component_named, CachedComponentData,
ComponentData, ComponentType, Struct,
},
core::component_registration::{CachedComponentData, ComponentData, ComponentType, Struct},
sys::{
ecs_entity_t, ecs_filter_t, ecs_flags32_t, ecs_id_t, ecs_inout_kind_t,
ecs_inout_kind_t_EcsIn, ecs_inout_kind_t_EcsInOut, ecs_inout_kind_t_EcsInOutDefault,
Expand All @@ -15,8 +12,16 @@ use crate::{
ecs_query_group_info_t, ecs_query_t, ecs_ref_t, ecs_rule_t, ecs_table_t, ecs_term_id_t,
ecs_term_t, ecs_type_hooks_t, ecs_type_info_t, ecs_type_kind_t, ecs_type_t,
ecs_world_info_t, ecs_world_t, EcsComponent, EcsIdentifier, EcsPoly, EcsTarget,
EcsTickSource, FLECS_IDEcsComponentID_,
FLECS_IDEcsComponentID_,
},
};

#[cfg(feature = "flecs_system")]
use crate::{
core::component_registration::{
try_register_struct_component, try_register_struct_component_named,
},
sys::EcsTickSource,
};

use std::{ffi::CStr, sync::OnceLock};
Expand Down Expand Up @@ -45,6 +50,7 @@ pub type TermIdT = ecs_term_id_t;
pub type TermT = ecs_term_t;
pub type PrimitiveKindT = ecs_primitive_kind_t;
pub type FTimeT = f32;
#[cfg(feature = "flecs_system")]
pub type TickSource = EcsTickSource;

pub static SEPARATOR: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"::\0") };
Expand Down Expand Up @@ -513,6 +519,7 @@ impl CachedComponentData for Poly {
}
}

#[cfg(feature = "flecs_system")]
impl CachedComponentData for TickSource {
type UnderlyingType = TickSource;
fn register_explicit(world: *mut WorldT) {
Expand Down
51 changes: 14 additions & 37 deletions flecs_ecs_sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,54 +31,31 @@ build_debug = []
# Flecs C defines / features
flecs_module = [] # Module support
flecs_parser = [] # String parser for queries
flecs_plecs = ["flecs_expr"] # ECS data definition format
flecs_plecs = ["flecs_module", "flecs_parser", "flecs_expr"] # ECS data definition format
flecs_rules = [] # Constraint solver for advanced queries
flecs_snapshot = [] # Snapshot & restore ECS data
flecs_stats = [] # Access runtime statistics
flecs_monitor = ["flecs_stats", "flecs_system", "flecs_timer"] # Track runtime statistics periodically
flecs_metrics = [] # Expose component data as statistics
flecs_alerts = [] # Monitor conditions for errors
flecs_system = [] # System support
flecs_pipeline = [] # Pipeline support
flecs_timer = [] # Timer support
flecs_meta = [] # Reflection support
flecs_metrics = ["flecs_meta", "flecs_units", "flecs_pipeline"] # Expose component data as statistics
flecs_alerts = ["flecs_rules", "flecs_pipeline"] # Monitor conditions for errors
flecs_system = ["flecs_module"] # System support
flecs_pipeline = ["flecs_module", "flecs_system"] # Pipeline support
flecs_timer = ["flecs_module", "flecs_pipeline"] # Timer support
flecs_meta = ["flecs_meta_c", "flecs_module"] # Reflection support
flecs_meta_c = [] # Utilities for populating reflection data
flecs_units = [] # Builtin standard units
flecs_expr = [] # Parsing strings to/from component values
flecs_json = [] # Parsing JSON to/from component values
flecs_doc = [] # Document entities & components
flecs_coredoc = [] # Documentation for core entities & components
flecs_units = ["flecs_module", "flecs_meta"] # Builtin standard units
flecs_expr = ["flecs_meta", "flecs_parser"] # Parsing strings to/from component values
flecs_json = ["flecs_expr"] # Parsing JSON to/from component values
flecs_doc = ["flecs_module"] # Document entities & components
flecs_coredoc = ["flecs_doc", "flecs_meta"] # Documentation for core entities & components
flecs_log = [] # When enabled ECS provides more detailed logs
flecs_app = ["flecs_pipeline"] # Application addon
flecs_os_api_impl = [] # Default implementation for OS API
flecs_http = [] # Tiny HTTP server for connecting to remote UI
flecs_rest = ["flecs_http"] # REST API for querying application data
flecs_journal = [] # Journaling addon (disabled by default)
flecs_rest = ["flecs_http", "flecs_json", "flecs_rules", "flecs_pipeline"] # REST API for querying application data
flecs_journal = ["flecs_log"] # Journaling addon (disabled by default)
default = [
"flecs_module",
"flecs_parser",
"flecs_plecs",
"flecs_rules",
"flecs_snapshot",
"flecs_stats",
"flecs_monitor",
"flecs_metrics",
"flecs_alerts",
"flecs_system",
"flecs_pipeline",
"flecs_timer",
"flecs_meta",
"flecs_meta_c",
"flecs_units",
"flecs_expr",
"flecs_json",
"flecs_doc",
"flecs_coredoc",
"flecs_log",
"flecs_app",
"flecs_os_api_impl",
"flecs_http",
"flecs_rest",
]


Loading

0 comments on commit 5855fc5

Please sign in to comment.