Skip to content

Commit

Permalink
v0.2.0 (with doc attributes)
Browse files Browse the repository at this point in the history
  • Loading branch information
GodotRust committed Nov 15, 2024
1 parent 4c7db48 commit 1d3ffcb
Show file tree
Hide file tree
Showing 93 changed files with 296 additions and 285 deletions.
1 change: 1 addition & 0 deletions examples/dodge-the-creeps/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(published_docs, feature(doc_cfg))]
/*
* Copyright (c) godot-rust; Bromeon and contributors.
* This Source Code Form is subject to the terms of the Mozilla Public
Expand Down
1 change: 1 addition & 0 deletions examples/hot-reload/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(published_docs, feature(doc_cfg))]
/*
* Copyright (c) godot-rust; Bromeon and contributors.
* This Source Code Form is subject to the terms of the Mozilla Public
Expand Down
2 changes: 1 addition & 1 deletion godot-bindings/src/header_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(crate) fn generate_rust_binding(in_h_path: &Path, out_rs_path: &Path) {
});
}

//#[cfg(target_os = "macos")]
//#[cfg(target_os = "macos")] #[cfg_attr(published_docs, doc(cfg(target_os = "macos")))]
fn configure_platform_specific(builder: bindgen::Builder) -> bindgen::Builder {
// On macOS arm64 architecture, we currently get the following error. Tried using different LLVM versions.
// Not clear if bindgen can be configured in a better way.
Expand Down
18 changes: 9 additions & 9 deletions godot-bindings/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@ pub const ALL_VERSIONS: &[(u8, u8, u8)] = &[

// [version-sync] [[
// [line] #[cfg(feature = "api-$kebabVersion")]\npub use gdextension_api::version_$snakeVersion as prebuilt;\n
#[cfg(feature = "api-4-1")]
#[cfg(feature = "api-4-1")] #[cfg_attr(published_docs, doc(cfg(feature = "api-4-1")))]
pub use gdextension_api::version_4_1 as prebuilt;

#[cfg(feature = "api-4-1-1")]
#[cfg(feature = "api-4-1-1")] #[cfg_attr(published_docs, doc(cfg(feature = "api-4-1-1")))]
pub use gdextension_api::version_4_1_1 as prebuilt;

#[cfg(feature = "api-4-1-2")]
#[cfg(feature = "api-4-1-2")] #[cfg_attr(published_docs, doc(cfg(feature = "api-4-1-2")))]
pub use gdextension_api::version_4_1_2 as prebuilt;

#[cfg(feature = "api-4-1-3")]
#[cfg(feature = "api-4-1-3")] #[cfg_attr(published_docs, doc(cfg(feature = "api-4-1-3")))]
pub use gdextension_api::version_4_1_3 as prebuilt;

#[cfg(feature = "api-4-1-4")]
#[cfg(feature = "api-4-1-4")] #[cfg_attr(published_docs, doc(cfg(feature = "api-4-1-4")))]
pub use gdextension_api::version_4_1_4 as prebuilt;

#[cfg(feature = "api-4-2")]
#[cfg(feature = "api-4-2")] #[cfg_attr(published_docs, doc(cfg(feature = "api-4-2")))]
pub use gdextension_api::version_4_2 as prebuilt;

#[cfg(feature = "api-4-2-1")]
#[cfg(feature = "api-4-2-1")] #[cfg_attr(published_docs, doc(cfg(feature = "api-4-2-1")))]
pub use gdextension_api::version_4_2_1 as prebuilt;

#[cfg(feature = "api-4-2-2")]
#[cfg(feature = "api-4-2-2")] #[cfg_attr(published_docs, doc(cfg(feature = "api-4-2-2")))]
pub use gdextension_api::version_4_2_2 as prebuilt;

#[cfg(feature = "api-4-3")]
#[cfg(feature = "api-4-3")] #[cfg_attr(published_docs, doc(cfg(feature = "api-4-3")))]
pub use gdextension_api::version_4_3 as prebuilt;

// ]]
Expand Down
15 changes: 8 additions & 7 deletions godot-bindings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(published_docs, feature(doc_cfg))]
/*
* Copyright (c) godot-rust; Bromeon and contributors.
* This Source Code Form is subject to the terms of the Mozilla Public
Expand Down Expand Up @@ -42,10 +43,10 @@ pub struct GodotVersion {
// Custom mode: Regenerate all files

// This file is explicitly included in unit tests. Needs regex dependency.
#[cfg(test)]
#[cfg(test)] #[cfg_attr(published_docs, doc(cfg(test)))]
mod godot_version;

#[cfg(feature = "api-custom")]
#[cfg(feature = "api-custom")] #[cfg_attr(published_docs, doc(cfg(feature = "api-custom")))]
#[path = ""]
mod depend_on_custom {
use super::*;
Expand All @@ -63,7 +64,7 @@ mod depend_on_custom {
godot_exe::write_gdextension_headers(h_path, rs_path, false, watch);
}

#[cfg(feature = "api-custom-extheader")]
#[cfg(feature = "api-custom-extheader")] #[cfg_attr(published_docs, doc(cfg(feature = "api-custom-extheader")))]
pub fn write_gdextension_headers_from_c(h_path: &Path, rs_path: &Path, watch: &mut StopWatch) {
godot_exe::write_gdextension_headers(h_path, rs_path, true, watch);
}
Expand All @@ -73,13 +74,13 @@ mod depend_on_custom {
}
}

#[cfg(feature = "api-custom")]
#[cfg(feature = "api-custom")] #[cfg_attr(published_docs, doc(cfg(feature = "api-custom")))]
pub use depend_on_custom::*;

// ----------------------------------------------------------------------------------------------------------------------------------------------
// Prebuilt mode: Reuse existing files

#[cfg(not(feature = "api-custom"))]
#[cfg(not(feature = "api-custom"))] #[cfg_attr(published_docs, doc(cfg(not(feature = "api-custom"))))]
#[path = ""]
mod depend_on_prebuilt {
use super::*;
Expand Down Expand Up @@ -121,7 +122,7 @@ mod depend_on_prebuilt {
}
}

#[cfg(not(feature = "api-custom"))]
#[cfg(not(feature = "api-custom"))] #[cfg_attr(published_docs, doc(cfg(not(feature = "api-custom"))))]
pub use depend_on_prebuilt::*;

// ----------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -185,7 +186,7 @@ pub fn emit_wasm_nothreads_cfg() {

// The environment variable for target family has a list of applicable families separated by commas.
// For Emscripten in particular, this can be "unix,wasm". Therefore, to check for the Wasm target, we must check each item in the list.
#[cfg(feature = "experimental-wasm-nothreads")]
#[cfg(feature = "experimental-wasm-nothreads")] #[cfg_attr(published_docs, doc(cfg(feature = "experimental-wasm-nothreads")))]
if std::env::var("CARGO_CFG_TARGET_FAMILY")
.expect("target family environment variable")
.split(',')
Expand Down
4 changes: 2 additions & 2 deletions godot-cell/src/borrow_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl From<String> for BorrowStateErr {
}
}

#[cfg(all(test, feature = "proptest"))]
#[cfg(all(test, feature = "proptest"))] #[cfg_attr(published_docs, doc(cfg(all(test, feature = "proptest"))))]
mod proptests {
use super::*;
use proptest::{arbitrary::Arbitrary, collection::vec, prelude::*};
Expand Down Expand Up @@ -632,7 +632,7 @@ mod proptests {
}
}

#[cfg(test)]
#[cfg(test)] #[cfg_attr(published_docs, doc(cfg(test)))]
mod test {
use super::*;

Expand Down
2 changes: 1 addition & 1 deletion godot-cell/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl<T> CellState<T> {
}
}

#[cfg(test)]
#[cfg(test)] #[cfg_attr(published_docs, doc(cfg(test)))]
mod test {
use super::*;

Expand Down
1 change: 1 addition & 0 deletions godot-cell/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(published_docs, feature(doc_cfg))]
/*
* Copyright (c) godot-rust; Bromeon and contributors.
* This Source Code Form is subject to the terms of the Mozilla Public
Expand Down
4 changes: 2 additions & 2 deletions godot-codegen/src/generator/central_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ pub fn make_sys_central_code(api: &ExtensionApi) -> TokenStream {
let [opaque_32bit, opaque_64bit] = make_opaque_types(api);

quote! {
#[cfg(target_pointer_width = "32")]
#[cfg(target_pointer_width = "32")] #[cfg_attr(published_docs, doc(cfg(target_pointer_width = "32")))]
pub mod types {
#(#opaque_32bit)*
}
#[cfg(target_pointer_width = "64")]
#[cfg(target_pointer_width = "64")] #[cfg_attr(published_docs, doc(cfg(target_pointer_width = "64")))]
pub mod types {
#(#opaque_64bit)*
}
Expand Down
2 changes: 1 addition & 1 deletion godot-codegen/src/generator/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn make_class(class: &Class, ctx: &mut Context, view: &ApiView) -> GeneratedClas
let (cfg_attributes, cfg_inner_attributes);
if class.is_experimental {
cfg_attributes = quote! {
// #[cfg(feature = "experimental-godot-api")]
// #[cfg(feature = "experimental-godot-api")] #[cfg_attr(published_docs, doc(cfg(feature = "experimental-godot-api")))]
#[cfg_attr(published_docs, doc(cfg(feature = "experimental-godot-api")))]
};
cfg_inner_attributes = quote! {
Expand Down
6 changes: 3 additions & 3 deletions godot-codegen/src/generator/method_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl MethodInitGroup {
}
}

#[cfg(not(feature = "codegen-lazy-fptrs"))]
#[cfg(not(feature = "codegen-lazy-fptrs"))] #[cfg_attr(published_docs, doc(cfg(not(feature = "codegen-lazy-fptrs"))))]
fn function_name(&self) -> Ident {
format_ident!("load_{}_methods", self.class_name)
}
Expand Down Expand Up @@ -302,7 +302,7 @@ fn make_named_method_table(info: NamedMethodTable) -> TokenStream {
}
}

#[cfg(not(feature = "codegen-lazy-fptrs"))]
#[cfg(not(feature = "codegen-lazy-fptrs"))] #[cfg_attr(published_docs, doc(cfg(not(feature = "codegen-lazy-fptrs"))))]
fn make_method_table(info: IndexedMethodTable) -> TokenStream {
let IndexedMethodTable {
table_name,
Expand Down Expand Up @@ -416,7 +416,7 @@ fn make_method_table(info: IndexedMethodTable) -> TokenStream {
}
}

#[cfg(feature = "codegen-lazy-fptrs")]
#[cfg(feature = "codegen-lazy-fptrs")] #[cfg_attr(published_docs, doc(cfg(feature = "codegen-lazy-fptrs")))]
fn make_method_table(info: IndexedMethodTable) -> TokenStream {
let IndexedMethodTable {
table_name,
Expand Down
2 changes: 1 addition & 1 deletion godot-codegen/src/generator/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub fn try_to_notification(constant: &JsonClassConstant) -> Option<Ident> {
/// This cannot be represented in a Rust enum, so we merge the two constants into a single enumerator.
fn workaround_constant_collision(all_constants: &mut Vec<(Ident, i32)>) {
// This constant has never been used by the engine.
#[cfg(before_api = "4.2")]
#[cfg(before_api = "4.2")] #[cfg_attr(published_docs, doc(cfg(before_api = "4.2")))]
all_constants.retain(|(constant_name, _)| constant_name != "NODE_RECACHE_REQUESTED");

let _ = &all_constants; // unused warning
Expand Down
2 changes: 1 addition & 1 deletion godot-codegen/src/generator/virtual_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn make_special_virtual_methods(notification_enum_name: &Ident) -> TokenStream {
///
/// See also in Godot docs:
/// * [`Object::_get_property_list`](https://docs.godotengine.org/en/latest/classes/class_object.html#class-object-private-method-get-property-list)
#[cfg(since_api = "4.3")]
#[cfg(since_api = "4.3")] #[cfg_attr(published_docs, doc(cfg(since_api = "4.3")))]
fn get_property_list(&mut self) -> Vec<crate::meta::PropertyInfo> {
unimplemented!()
}
Expand Down
9 changes: 5 additions & 4 deletions godot-codegen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(published_docs, feature(doc_cfg))]
/*
* Copyright (c) godot-rust; Bromeon and contributors.
* This Source Code Form is subject to the terms of the Mozilla Public
Expand All @@ -21,7 +22,7 @@ mod models;
mod special_cases;
mod util;

#[cfg(test)]
#[cfg(test)] #[cfg_attr(published_docs, doc(cfg(test)))]
mod tests;

use crate::context::Context;
Expand Down Expand Up @@ -51,12 +52,12 @@ fn write_file(path: &Path, contents: String) {
.unwrap_or_else(|e| panic!("failed to write code file to {};\n\t{}", path.display(), e));
}

#[cfg(not(feature = "codegen-rustfmt"))]
#[cfg(not(feature = "codegen-rustfmt"))] #[cfg_attr(published_docs, doc(cfg(not(feature = "codegen-rustfmt"))))]
fn submit_fn(path: PathBuf, tokens: TokenStream) {
write_file(&path, formatter::format_tokens(tokens));
}

#[cfg(feature = "codegen-rustfmt")]
#[cfg(feature = "codegen-rustfmt")] #[cfg_attr(published_docs, doc(cfg(feature = "codegen-rustfmt")))]
mod rustfmt {
use super::*;
use std::process::Command;
Expand Down Expand Up @@ -92,7 +93,7 @@ mod rustfmt {
static FILES_TO_RUSTFMT: Mutex<Vec<PathBuf>> = Mutex::new(Vec::new());
}

#[cfg(feature = "codegen-rustfmt")]
#[cfg(feature = "codegen-rustfmt")] #[cfg_attr(published_docs, doc(cfg(feature = "codegen-rustfmt")))]
pub(crate) use rustfmt::*;

pub fn generate_sys_files(
Expand Down
8 changes: 4 additions & 4 deletions godot-codegen/src/models/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,23 @@ pub enum BuildConfiguration {
}

impl BuildConfiguration {
#[cfg(feature = "double-precision")]
#[cfg(feature = "double-precision")] #[cfg_attr(published_docs, doc(cfg(feature = "double-precision")))]
pub fn is_applicable(self) -> bool {
matches!(self, Self::Double32 | Self::Double64)
}

#[cfg(not(feature = "double-precision"))]
#[cfg(not(feature = "double-precision"))] #[cfg_attr(published_docs, doc(cfg(not(feature = "double-precision"))))]
pub fn is_applicable(self) -> bool {
matches!(self, Self::Float32 | Self::Float64)
}

// Rewrite the above using #[cfg].
#[cfg(feature = "double-precision")]
#[cfg(feature = "double-precision")] #[cfg_attr(published_docs, doc(cfg(feature = "double-precision")))]
pub fn all_applicable() -> [BuildConfiguration; 2] {
[BuildConfiguration::Double32, BuildConfiguration::Double64]
}

#[cfg(not(feature = "double-precision"))]
#[cfg(not(feature = "double-precision"))] #[cfg_attr(published_docs, doc(cfg(not(feature = "double-precision"))))]
pub fn all_applicable() -> [BuildConfiguration; 2] {
[BuildConfiguration::Float32, BuildConfiguration::Float64]
}
Expand Down
4 changes: 2 additions & 2 deletions godot-codegen/src/models/domain_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,13 +457,13 @@ impl ClassMethod {
};

// Since Godot 4.4, GDExtension advertises whether virtual methods have a default implementation or are required to be overridden.
#[cfg(before_api = "4.4")]
#[cfg(before_api = "4.4")] #[cfg_attr(published_docs, doc(cfg(before_api = "4.4")))]
let is_virtual_required = special_cases::is_virtual_method_required(
&class_name.rust_ty.to_string(),
rust_method_name,
);

#[cfg(since_api = "4.4")]
#[cfg(since_api = "4.4")] #[cfg_attr(published_docs, doc(cfg(since_api = "4.4")))]
let is_virtual_required = method.is_virtual
&& method.is_required.unwrap_or_else(|| {
panic!(
Expand Down
2 changes: 1 addition & 1 deletion godot-codegen/src/models/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub struct JsonClassMethod {
pub is_vararg: bool,
pub is_static: bool,
pub is_virtual: bool,
#[cfg(since_api = "4.4")]
#[cfg(since_api = "4.4")] #[cfg_attr(published_docs, doc(cfg(since_api = "4.4")))]
pub is_required: Option<bool>, // Only virtual functions have this field.
pub hash: Option<i64>,
pub return_value: Option<JsonMethodReturn>,
Expand Down
14 changes: 7 additions & 7 deletions godot-codegen/src/special_cases/codegen_special_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ pub(crate) fn is_builtin_method_excluded(method: &JsonBuiltinMethod) -> bool {
method.is_vararg
}

#[cfg(not(feature = "codegen-full"))]
#[cfg(not(feature = "codegen-full"))] #[cfg_attr(published_docs, doc(cfg(not(feature = "codegen-full"))))]
pub(crate) fn is_class_excluded(godot_class_name: &str) -> bool {
!SELECTED_CLASSES.contains(&godot_class_name)
}

#[cfg(feature = "codegen-full")]
#[cfg(feature = "codegen-full")] #[cfg_attr(published_docs, doc(cfg(feature = "codegen-full")))]
pub(crate) fn is_class_excluded(_godot_class_name: &str) -> bool {
false
}

#[cfg(not(feature = "codegen-full"))]
#[cfg(not(feature = "codegen-full"))] #[cfg_attr(published_docs, doc(cfg(not(feature = "codegen-full"))))]
fn is_type_excluded(ty: &str, ctx: &mut Context) -> bool {
use crate::conv;
use crate::models::domain::RustTy;
Expand All @@ -53,7 +53,7 @@ fn is_type_excluded(ty: &str, ctx: &mut Context) -> bool {
is_rust_type_excluded(&conv::to_rust_type(ty, None, ctx))
}

#[cfg(feature = "codegen-full")]
#[cfg(feature = "codegen-full")] #[cfg_attr(published_docs, doc(cfg(feature = "codegen-full")))]
fn is_type_excluded(_ty: &str, _ctx: &mut Context) -> bool {
false
}
Expand Down Expand Up @@ -86,15 +86,15 @@ pub(crate) fn is_class_method_excluded(method: &JsonClassMethod, ctx: &mut Conte
false
}

#[cfg(feature = "codegen-full")]
#[cfg(feature = "codegen-full")] #[cfg_attr(published_docs, doc(cfg(feature = "codegen-full")))]
pub(crate) fn is_utility_function_excluded(
_function: &JsonUtilityFunction,
_ctx: &mut Context,
) -> bool {
false
}

#[cfg(not(feature = "codegen-full"))]
#[cfg(not(feature = "codegen-full"))] #[cfg_attr(published_docs, doc(cfg(not(feature = "codegen-full"))))]
pub(crate) fn is_utility_function_excluded(
function: &JsonUtilityFunction,
ctx: &mut Context,
Expand All @@ -113,7 +113,7 @@ pub(crate) fn is_utility_function_excluded(
// Allowed-classes

// Classes for minimal config
#[cfg(not(feature = "codegen-full"))]
#[cfg(not(feature = "codegen-full"))] #[cfg_attr(published_docs, doc(cfg(not(feature = "codegen-full"))))]
const SELECTED_CLASSES: &[&str] = &[
"AnimatedSprite2D",
"Area2D",
Expand Down
4 changes: 2 additions & 2 deletions godot-codegen/src/special_cases/special_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn is_godot_type_deleted(godot_ty: &str) -> bool {
match target_os.as_deref() {
Ok("ios") | Ok("emscripten") => return true,
Ok("macos") => {
#[cfg(before_api = "4.2")]
#[cfg(before_api = "4.2")] #[cfg_attr(published_docs, doc(cfg(before_api = "4.2")))]
return true;
}
_ => {}
Expand Down Expand Up @@ -392,7 +392,7 @@ pub fn get_interface_extra_docs(trait_name: &str) -> Option<&'static str> {
}
}

#[cfg(before_api = "4.4")]
#[cfg(before_api = "4.4")] #[cfg_attr(published_docs, doc(cfg(before_api = "4.4")))]
pub fn is_virtual_method_required(class_name: &str, method: &str) -> bool {
match (class_name, method) {
("ScriptLanguageExtension", _) => method != "get_doc_comment_delimiters",
Expand Down
Loading

0 comments on commit 1d3ffcb

Please sign in to comment.