diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/bindings/lang/clang/Generate.toml | 11 | ||||
| -rw-r--r-- | core/bindings/lang/clang/build.rs | 67 | ||||
| -rw-r--r-- | core/bindings/lang/clang/configures/nogamepads_data.toml | 17 | ||||
| -rw-r--r-- | core/bindings/lang/clang/headers/nogamepads_data.h (renamed from core/bindings/lang/clang/headers/nogamepads.h) | 34 |
4 files changed, 81 insertions, 48 deletions
diff --git a/core/bindings/lang/clang/Generate.toml b/core/bindings/lang/clang/Generate.toml deleted file mode 100644 index 08d8b00..0000000 --- a/core/bindings/lang/clang/Generate.toml +++ /dev/null @@ -1,11 +0,0 @@ -language = "C" -include_guard = "NOGAMEPADS_H" -header = "// Auto generated by cbindgen 0.29.0" -cpp_compat = true - -[parse] -parse_deps = true -include = ["*"] - -[fn] -prefix = "ngp_"
\ No newline at end of file diff --git a/core/bindings/lang/clang/build.rs b/core/bindings/lang/clang/build.rs index c43ee7f..190501e 100644 --- a/core/bindings/lang/clang/build.rs +++ b/core/bindings/lang/clang/build.rs @@ -1,34 +1,61 @@ fn main() { - // Get the project root directory let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); let root_path = std::path::Path::new(&manifest_dir); - // Input configuration file path - let config_path = root_path.join("Generate.toml"); + // Input configuration directory path + let config_dir = root_path.join("configures"); // Output directory path (headers folder in the crate directory) let headers_dir = root_path.join("headers"); - // Create the headers directory (if it does not exist) - std::fs::create_dir_all(&headers_dir).expect("Failed to create headers directory"); - - // Output file path - let output_file = headers_dir.join("nogamepads.h"); + // Clear existing headers directory (if it exists) + if headers_dir.exists() { + std::fs::remove_dir_all(&headers_dir).expect("Failed to remove headers directory"); + } - // Load configuration from Generate.toml - let config = cbindgen::Config::from_file(&config_path) - .expect("Failed to parse Generate.toml configuration"); - - // Generate header file - cbindgen::Builder::new() - .with_crate(manifest_dir) - .with_config(config) - .generate() - .expect("Failed to generate C header file") - .write_to_file(&output_file); + // Create a new headers directory + std::fs::create_dir_all(&headers_dir).expect("Failed to create headers directory"); - println!("cargo:rerun-if-changed={}", config_path.display()); + // Find all TOML files in configures directory + let config_files = std::fs::read_dir(&config_dir) + .expect("Failed to read configures directory") + .filter_map(|entry| { + let entry = entry.expect("Failed to read directory entry"); + let path = entry.path(); + if path.is_file() && path.extension().map_or(false, |ext| ext == "toml") { + Some(path) + } else { + None + } + }); + + // Process each configuration file + for config_path in config_files { + // Extract filename without extension + let file_stem = config_path.file_stem() + .and_then(|s| s.to_str()) + .expect("Invalid filename") + .to_string(); + + // Set output file path + let output_file = headers_dir.join(format!("{}.h", file_stem)); + + // Load configuration from current TOML file + let config = cbindgen::Config::from_file(&config_path) + .expect(&format!("Failed to parse configuration: {}", config_path.display())); + + // Generate header file + cbindgen::Builder::new() + .with_crate(&manifest_dir) + .with_config(config) + .generate() + .expect(&format!("Failed to generate header for: {}", config_path.display())) + .write_to_file(&output_file); + } + + // Print rerun instructions + println!("cargo:rerun-if-changed={}", config_dir.display()); println!("cargo:rerun-if-changed=src/mycode.rs"); println!("cargo:rerun-if-changed=build.rs"); }
\ No newline at end of file diff --git a/core/bindings/lang/clang/configures/nogamepads_data.toml b/core/bindings/lang/clang/configures/nogamepads_data.toml new file mode 100644 index 0000000..56d645d --- /dev/null +++ b/core/bindings/lang/clang/configures/nogamepads_data.toml @@ -0,0 +1,17 @@ +language = "C" +include_guard = "NOGAMEPADS_DATA_H" +header = "// Auto generated by cbindgen 0.29.0" +cpp_compat = true + +[parse] +parse_deps = true +include = [ + "string_converter", + + "ngpd_game_info", + "ngpd_message", + "ngpd_player" +] + +[fn] +prefix = "ngpd_data_"
\ No newline at end of file diff --git a/core/bindings/lang/clang/headers/nogamepads.h b/core/bindings/lang/clang/headers/nogamepads_data.h index 3242a44..6d9f1ad 100644 --- a/core/bindings/lang/clang/headers/nogamepads.h +++ b/core/bindings/lang/clang/headers/nogamepads_data.h @@ -1,7 +1,7 @@ // Auto generated by cbindgen 0.29.0 -#ifndef NOGAMEPADS_H -#define NOGAMEPADS_H +#ifndef NOGAMEPADS_DATA_H +#define NOGAMEPADS_DATA_H #include <stdarg.h> #include <stdbool.h> @@ -146,36 +146,36 @@ typedef struct FfiConnectionResponseMessage { extern "C" { #endif // __cplusplus -ngp_ void free_c_string(char *ptr); +ngpd_data_ void free_c_string(char *ptr); -ngp_ struct FfiPlayer *player_register(const char *id, const char *password); +ngpd_data_ struct FfiPlayer *player_register(const char *id, const char *password); -ngp_ bool player_check(const struct FfiPlayer *player, const char *password); +ngpd_data_ bool player_check(const struct FfiPlayer *player, const char *password); -ngp_ void player_set_nickname(struct FfiPlayer *player, const char *nickname); +ngpd_data_ void player_set_nickname(struct FfiPlayer *player, const char *nickname); -ngp_ void player_set_hue(struct FfiPlayer *player, int hue); +ngpd_data_ void player_set_hue(struct FfiPlayer *player, int hue); -ngp_ void player_set_hsv(struct FfiPlayer *player, int hue, double saturation, double value); +ngpd_data_ void player_set_hsv(struct FfiPlayer *player, int hue, double saturation, double value); -ngp_ void player_free(struct FfiPlayer *player); +ngpd_data_ void player_free(struct FfiPlayer *player); -ngp_ void free_control_message(struct FfiControlMessage msg); +ngpd_data_ void free_control_message(struct FfiControlMessage msg); -ngp_ void free_game_message(struct FfiGameMessage msg); +ngpd_data_ void free_game_message(struct FfiGameMessage msg); -ngp_ void free_exit_reason(enum FfiExitReason msg); +ngpd_data_ void free_exit_reason(enum FfiExitReason msg); -ngp_ void free_connection_message(struct FfiConnectionMessage msg); +ngpd_data_ void free_connection_message(struct FfiConnectionMessage msg); -ngp_ void free_connection_response_message(struct FfiConnectionResponseMessage msg); +ngpd_data_ void free_connection_response_message(struct FfiConnectionResponseMessage msg); -ngp_ void free_join_failed_message(enum FfiJoinFailedMessage msg); +ngpd_data_ void free_join_failed_message(enum FfiJoinFailedMessage msg); -ngp_ void free_game_info(struct FfiGameInfo map); +ngpd_data_ void free_game_info(struct FfiGameInfo map); #ifdef __cplusplus } // extern "C" #endif // __cplusplus -#endif /* NOGAMEPADS_H */ +#endif /* NOGAMEPADS_DATA_H */ |
