Skip to content

Commit

Permalink
codgen/sys: Properly generate dox features for external libraries
Browse files Browse the repository at this point in the history
This also drops an unused option that doesn't seem to be that useful

Co-authored-by: pentamassiv <[email protected]>
  • Loading branch information
bilelmoussaoui and pentamassiv committed Oct 18, 2022
1 parent e5f2c36 commit 0a9941e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 39 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
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>,
}

impl Config {
Expand Down Expand Up @@ -345,7 +344,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)?;

Ok(Config {
work_mode,
Expand Down Expand Up @@ -374,7 +372,6 @@ impl Config {
extra_versions,
lib_version_overrides,
feature_dependencies,
dox_feature_dependencies,
})
}

Expand Down Expand Up @@ -481,24 +478,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

0 comments on commit 0a9941e

Please sign in to comment.