Skip to content

Commit

Permalink
Merge branch 'master' into external-docs-url
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronErhardt committed Oct 19, 2022
2 parents 81f04a5 + 952ff41 commit 9579827
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 53 deletions.
4 changes: 0 additions & 4 deletions book/src/config_ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ version = "3.16"
dependencies = [
"glib-sys/v3_16"
]
# Add features to the "dox" feature declaration in `Cargo.toml`. So with the following
# config, it'll generate:
# dox = ["whatever"]
dox_feature_dependencies = ["whatever"]
```

You can mark some functions that has suffix `_utf8` on Windows:
Expand Down
11 changes: 10 additions & 1 deletion src/analysis/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl Bounds {
&bound_type,
*par.nullable,
par.instance_parameter,
par.move_,
));
if r#async && (par.name == "callback" || par.name.ends_with("_callback")) {
let func_name = func.c_identifier.as_ref().unwrap();
Expand Down Expand Up @@ -182,7 +183,12 @@ impl Bounds {
}
} else if par.instance_parameter {
if let Some(bound_type) = Bounds::type_for(env, par.typ) {
ret = Some(Bounds::get_to_glib_extra(&bound_type, *par.nullable, true));
ret = Some(Bounds::get_to_glib_extra(
&bound_type,
*par.nullable,
true,
par.move_,
));
}
}

Expand Down Expand Up @@ -214,12 +220,15 @@ impl Bounds {
bound_type: &BoundType,
nullable: bool,
instance_parameter: bool,
move_: bool,
) -> String {
use self::BoundType::*;
match bound_type {
AsRef(_) if nullable => ".as_ref().map(|p| p.as_ref())".to_owned(),
AsRef(_) if move_ => ".upcast()".to_owned(),
AsRef(_) => ".as_ref()".to_owned(),
IsA(_) if nullable && !instance_parameter => ".map(|p| p.as_ref())".to_owned(),
IsA(_) if move_ => ".upcast()".to_owned(),
IsA(_) => ".as_ref()".to_owned(),
_ => String::new(),
}
Expand Down
7 changes: 3 additions & 4 deletions src/analysis/function_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub struct RustParameter {
pub ind_c: usize, //index in `Vec<CParameter>`
pub name: String,
pub typ: TypeId,
pub allow_none: bool,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -226,7 +225,7 @@ pub fn analyze(
if async_func && async_param_to_remove(&par.name) {
add_rust_parameter = false;
}

let move_ = configured_parameters.iter().any(|p| p.move_);
let mut array_par = configured_parameters.iter().find_map(|cp| {
cp.length_of
.as_ref()
Expand All @@ -246,6 +245,7 @@ pub fn analyze(
&bound_type,
*array_par.nullable,
array_par.instance_parameter,
move_,
))
.into();
}
Expand Down Expand Up @@ -297,7 +297,7 @@ pub fn analyze(
user_data_index: par.closure,
destroy_index: par.destroy,
try_from_glib: try_from_glib.clone(),
move_: configured_parameters.iter().any(|p| p.move_),
move_,
};
parameters.c_parameters.push(c_par);

Expand All @@ -309,7 +309,6 @@ pub fn analyze(
name: name.clone(),
typ,
ind_c,
allow_none: par.allow_none,
};
parameters.rust_parameters.push(rust_par);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ fn analyze_function(
}

imports.add_used_types(&used_types);
if ret.base_tid.is_some() {
if ret.base_tid.is_some() || parameters.c_parameters.iter().any(|p| p.move_) {
imports.add("glib::object::Cast");
}

Expand Down
1 change: 0 additions & 1 deletion src/analysis/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ fn analyze_property(
transfer: library::Transfer::None,
caller_allocates: false,
nullable: library::Nullable(false),
allow_none: false,
array_length: None,
is_error: false,
doc: None,
Expand Down
19 changes: 9 additions & 10 deletions src/codegen/sys/cargo_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,6 @@ fn fill_in(root: &mut Table, env: &Env) {
features.insert(version.to_feature(), Value::Array(prev_array));
Some(version)
});
features.insert(
"dox".to_string(),
Value::Array(
env.config
.dox_feature_dependencies
.iter()
.map(|s| Value::String(s.clone()))
.collect(),
),
);
}

{
Expand Down Expand Up @@ -191,6 +181,15 @@ fn fill_in(root: &mut Table, env: &Env) {
),
);
}

{
let features = upsert_table(root, "features");
let mut dox_features = Vec::new();
for ext_lib in &env.config.external_libraries {
dox_features.push(Value::String(format!("{}/dox", ext_lib.lib_name)));
}
features.insert("dox".to_string(), Value::Array(dox_features));
}
}

fn get_feature_dependencies(
Expand Down
21 changes: 0 additions & 21 deletions src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ pub struct Config {
pub extra_versions: Vec<Version>,
pub lib_version_overrides: HashMap<Version, Version>,
pub feature_dependencies: HashMap<Version, Vec<String>>,
pub dox_feature_dependencies: Vec<String>,
/// An url that will be inserted into the docs as link that links
/// to another doc source, for example when builds on docs.rs
/// are limited due to license issues.
Expand Down Expand Up @@ -349,7 +348,6 @@ impl Config {
let extra_versions = read_extra_versions(&toml)?;
let lib_version_overrides = read_lib_version_overrides(&toml)?;
let feature_dependencies = read_feature_dependencies(&toml)?;
let dox_feature_dependencies = read_dox_feature_dependencies(&toml)?;
let external_docs_url = read_external_docs_url(&toml)?;

Ok(Config {
Expand Down Expand Up @@ -379,7 +377,6 @@ impl Config {
extra_versions,
lib_version_overrides,
feature_dependencies,
dox_feature_dependencies,
external_docs_url,
})
}
Expand Down Expand Up @@ -487,24 +484,6 @@ fn read_extra_versions(toml: &toml::Value) -> Result<Vec<Version>, String> {
}
}

fn read_dox_feature_dependencies(toml: &toml::Value) -> Result<Vec<String>, String> {
match toml.lookup("options.dox_feature_dependencies") {
Some(a) => a
.as_result_vec("options.dox_feature_dependencies")?
.iter()
.map(|v| {
v.as_str()
.ok_or_else(|| {
"options.dox_feature_dependencies expected to be array of string"
.to_string()
})
.map(str::to_owned)
})
.collect(),
None => Ok(Vec::new()),
}
}

fn read_lib_version_overrides(toml: &toml::Value) -> Result<HashMap<Version, Version>, String> {
let v = match toml.lookup("lib_version_overrides") {
Some(a) => a.as_result_vec("lib_version_overrides")?,
Expand Down
22 changes: 18 additions & 4 deletions src/config/external_libraries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::str::FromStr;
pub struct ExternalLibrary {
pub namespace: String,
pub crate_name: String,
pub lib_name: String,
pub min_version: Option<Version>,
}

Expand All @@ -16,10 +17,14 @@ pub fn read_external_libraries(toml: &toml::Value) -> Result<Vec<ExternalLibrary
.as_result_vec("options.external_libraries")?
.iter()
.filter_map(|v| v.as_str().map(String::from))
.map(|namespace| ExternalLibrary {
crate_name: crate_name(&namespace),
min_version: None,
namespace,
.map(|namespace| {
let crate_name_ = crate_name(&namespace);
ExternalLibrary {
crate_name: crate_name_.clone(),
lib_name: crate_name_,
min_version: None,
namespace,
}
})
.collect(),
None => Vec::new(),
Expand All @@ -42,6 +47,7 @@ pub fn read_external_libraries(toml: &toml::Value) -> Result<Vec<ExternalLibrary
let lib = ExternalLibrary {
namespace: namespace.to_owned(),
crate_name: crate_name_,
lib_name: crate_name(namespace),
min_version,
};
external_libraries.push(lib);
Expand All @@ -50,6 +56,7 @@ pub fn read_external_libraries(toml: &toml::Value) -> Result<Vec<ExternalLibrary
let lib = ExternalLibrary {
namespace: namespace.to_owned(),
crate_name: crate_name_.clone(),
lib_name: crate_name(custom_lib.1.as_str().expect("No custom lib name set")),
min_version: None,
};
external_libraries.push(lib);
Expand Down Expand Up @@ -98,6 +105,7 @@ other-lib="OtherLib"
ExternalLibrary {
namespace: "GLib".to_owned(),
crate_name: "glib".to_owned(),
lib_name: "glib".to_owned(),
min_version: None,
}
);
Expand All @@ -106,6 +114,7 @@ other-lib="OtherLib"
ExternalLibrary {
namespace: "Gdk".to_owned(),
crate_name: "gdk".to_owned(),
lib_name: "gdk".to_owned(),
min_version: None,
}
);
Expand All @@ -114,6 +123,7 @@ other-lib="OtherLib"
ExternalLibrary {
namespace: "GdkPixbuf".to_owned(),
crate_name: "gdk_pixbuf".to_owned(),
lib_name: "gdk_pixbuf".to_owned(),
min_version: None,
}
);
Expand All @@ -123,6 +133,7 @@ other-lib="OtherLib"
ExternalLibrary {
namespace: "CoolLib".to_owned(),
crate_name: "coollib".to_owned(),
lib_name: "cool_lib".to_owned(),
min_version: None,
}
);
Expand All @@ -131,6 +142,7 @@ other-lib="OtherLib"
ExternalLibrary {
namespace: "OtherLib".to_owned(),
crate_name: "other-lib".to_owned(),
lib_name: "other_lib".to_owned(),
min_version: None,
}
);
Expand All @@ -153,6 +165,7 @@ OtherLib={min_version = "0.4.0"}
ExternalLibrary {
namespace: "CoolLib".to_owned(),
crate_name: "coollib".to_owned(),
lib_name: "cool_lib".to_owned(),
min_version: Some(Version::from_str("0.3.0").unwrap()),
}
);
Expand All @@ -161,6 +174,7 @@ OtherLib={min_version = "0.4.0"}
ExternalLibrary {
namespace: "OtherLib".to_owned(),
crate_name: "other_lib".to_owned(),
lib_name: "other_lib".to_owned(),
min_version: Some(Version::from_str("0.4.0").unwrap()),
}
);
Expand Down
1 change: 0 additions & 1 deletion src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ pub struct Parameter {
pub transfer: Transfer,
pub caller_allocates: bool,
pub nullable: Nullable,
pub allow_none: bool,
pub array_length: Option<u32>,
pub is_error: bool,
pub doc: Option<String>,
Expand Down
4 changes: 0 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,6 @@ impl Library {
caller_allocates: false,
nullable: Nullable(true),
array_length: None,
allow_none: true,
is_error: true,
doc: None,
scope: ParameterScope::None,
Expand Down Expand Up @@ -1106,7 +1105,6 @@ impl Library {
.attr_from_str("transfer-ownership")?
.unwrap_or(Transfer::None);
let nullable = elem.attr_bool("nullable", false);
let allow_none = elem.attr_bool("allow-none", false);
let scope = elem.attr_from_str("scope")?.unwrap_or(ParameterScope::None);
let closure = elem.attr_from_str("closure")?;
let destroy = elem.attr_from_str("destroy")?;
Expand Down Expand Up @@ -1165,7 +1163,6 @@ impl Library {
transfer,
caller_allocates,
nullable: Nullable(nullable),
allow_none,
array_length,
is_error: false,
doc,
Expand All @@ -1183,7 +1180,6 @@ impl Library {
transfer: Transfer::None,
caller_allocates: false,
nullable: Nullable(false),
allow_none,
array_length: None,
is_error: false,
doc,
Expand Down
2 changes: 1 addition & 1 deletion tests/sys/gdk-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ libc = "0.2"
package = "cairo-sys-rs"
git = "https://github.com/gtk-rs/cairo"

[dependencies.gdk-pixbuf]
[dependencies.gdk_pixbuf]
package = "gdk-pixbuf-sys"
path = "../gdk-pixbuf-sys"

Expand Down
2 changes: 1 addition & 1 deletion tests/sys/gtk-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ path = "../atk-sys"
package = "cairo-sys-rs"
git = "https://github.com/gtk-rs/cairo"

[dependencies.gdk-pixbuf]
[dependencies.gdk_pixbuf]
package = "gdk-pixbuf-sys"
path = "../gdk-pixbuf-sys"

Expand Down

0 comments on commit 9579827

Please sign in to comment.