Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ extend-exclude = ["*.svg"]
gir = "gir"
inout = "inout"
serde = "serde"
typ = "typ"
5 changes: 2 additions & 3 deletions book/src/config/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ target_path = "."
# auto_path = "src/auto"
work_mode = "normal"
# Whether the library uses https://gitlab.gnome.org/GNOME/gi-docgen for its documentation
use_gi_docgen = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's going to take a while until everything uses this so for the time being maybe change use_gi_docgen to doc_format and allow the same values there, and don't make the attribute in the XML mandatory yet?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is everything? It is GTK, GLib, Pango and libadwaita (merged already https://gitlab.gnome.org/GNOME/libadwaita/-/merge_requests/1428).

The remaining bindings don't get updated often at all.

If you just want to ignore the element for now, it could be done in a separate patch by someone else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If everything using gi-docgen is updated then that's fine with me. Just default to "unknown" if the attribute is not in the XML.

generate_safety_asserts = true
deprecate_by_min_version = true
# With this option enabled, versions for gir and gir-files saved only to one file to minimize noise,
Expand Down Expand Up @@ -123,7 +122,7 @@ visibility = "pub" # or 'crate' / 'private' / 'super'
# works for flags and enums. You have to pass the "GIR" member name.
default_value = "fill"
# Change the name of the generated trait to e.g avoid naming conflicts
trait_name = "TraitnameExt"
trait_name = "TraitnameExt"
# In case you don't want to generate the documentation for this type.
generate_doc = false
# define overrides for function
Expand Down Expand Up @@ -336,7 +335,7 @@ status = "generate"
name = "stock_list_ids"
# allows to ignore global functions
ignore = true
# allows to define if the function was moved to a trait
# allows to define if the function was moved to a trait
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could go in a separate commit.

doc_trait_name = "StockExt"
# allows to define if the function was moved to a struct
doc_struct_name = "Stock"
Expand Down
6 changes: 4 additions & 2 deletions src/codegen/doc/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use super::{gi_docgen, LocationInObject};
use crate::{
analysis::functions::Info,
library::{FunctionKind, TypeId},
nameutil, Env,
nameutil,
parser::DocFormat,
Env,
};

const LANGUAGE_SEP_BEGIN: &str = "<!-- language=\"";
Expand Down Expand Up @@ -138,7 +140,7 @@ fn replace_symbols(
env: &Env,
in_type: Option<(&TypeId, Option<LocationInObject>)>,
) -> String {
if env.config.use_gi_docgen {
if env.library.doc_format == DocFormat::GiDocgen {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps for now this could be a if library.doc_format == DocFormat::GiDocgen || config.use_gi_docgen for the moment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is an option yes, although, it will end up staying there given no one will remember to remove it. As this option only impacts docs generation, i rather have bindings manually amend the format into the gir file then gir keeping this old "hack"

Copy link
Contributor

@A6GibKm A6GibKm Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fear is that this is a bit of a chicken and egg situation. Breaking gir generation is a discouragement for setting doc_format and this MR depends on libraries using it.

I suppose an alternative is to have a prequel for this PR that just reads the doc_format and does nothing with it (instead of crashing) to unblock the situation, such a MR would not depend on gir-files.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is always been like that when it comes to new annotations so i rather fix things properly.

let out = gi_docgen::replace_c_types(input, env, in_type);
let out = gi_docgen_symbol().replace_all(&out, |caps: &Captures<'_>| match &caps[2] {
"TRUE" => "[`true`]".to_string(),
Expand Down
7 changes: 0 additions & 7 deletions src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ pub struct Config {
pub external_libraries: Vec<ExternalLibrary>,
pub objects: gobjects::GObjects,
pub min_cfg_version: Version,
pub use_gi_docgen: bool,
pub make_backup: bool,
pub generate_safety_asserts: bool,
pub deprecate_by_min_version: bool,
Expand Down Expand Up @@ -286,11 +285,6 @@ impl Config {
None => Default::default(),
};

let use_gi_docgen = match toml.lookup("options.use_gi_docgen") {
Some(v) => v.as_result_bool("options.use_gi_docgen")?,
None => false,
};

let generate_safety_asserts = match toml.lookup("options.generate_safety_asserts") {
Some(v) => v.as_result_bool("options.generate_safety_asserts")?,
None => false,
Expand Down Expand Up @@ -344,7 +338,6 @@ impl Config {
external_libraries,
objects,
min_cfg_version,
use_gi_docgen,
make_backup,
generate_safety_asserts,
deprecate_by_min_version,
Expand Down
10 changes: 4 additions & 6 deletions src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{

use crate::{
analysis::conversion_type::ConversionType, config::gobjects::GStatus, env::Env,
nameutil::split_namespace_name, traits::*, version::Version,
nameutil::split_namespace_name, parser::DocFormat, traits::*, version::Version,
};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -1056,18 +1056,16 @@ pub const INTERNAL_NAMESPACE_NAME: &str = "*";
pub const INTERNAL_NAMESPACE: u16 = 0;
pub const MAIN_NAMESPACE: u16 = 1;

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Library {
pub namespaces: Vec<Namespace>,
pub index: HashMap<String, u16>,
pub doc_format: DocFormat,
}

impl Library {
pub fn new(main_namespace_name: &str) -> Self {
let mut library = Self {
namespaces: Vec::new(),
index: HashMap::new(),
};
let mut library = Self::default();
assert_eq!(
INTERNAL_NAMESPACE,
library.add_namespace(INTERNAL_NAMESPACE_NAME)
Expand Down
30 changes: 30 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@ use crate::{
xmlparser::{Element, XmlParser},
};

#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub enum DocFormat {
GtkDocMarkdown,
GtkDocDocbook,
GiDocgen,
HotDoc,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Hotdoc if the key is not hot-doc.

#[default]
Unknown,
}

impl std::str::FromStr for DocFormat {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"gtk-doc-markdown" => Ok(Self::GtkDocMarkdown),
"gtk-doc-docbook" => Ok(Self::GtkDocDocbook),
"gi-docgen" => Ok(Self::GiDocgen),
"hotdoc" => Ok(Self::HotDoc),
"unknown" => Ok(Self::Unknown),
e => Err(format!("Invalid doc:format {e}")),
}
}
}

const EMPTY_CTYPE: &str = "/*EMPTY*/";

pub fn is_empty_c_type(c_type: &str) -> bool {
Expand Down Expand Up @@ -81,6 +106,11 @@ impl Library {
std::mem::take(&mut includes),
),
"attribute" => parser.ignore_element(),
"doc" => {
let format = DocFormat::from_str(elem.attr_required("name")?)?;
self.doc_format = format;
Ok(())
}
_ => Err(parser.unexpected_element(elem)),
})?;
Ok(())
Expand Down
Loading