Skip to content

Commit

Permalink
codegen/sys: Don't expect the crates are renamed
Browse files Browse the repository at this point in the history
In the past, this seemed like a decent idea but the switch to using
cargo workspace proves it wasn't as we now have conflicting crates
with the same names
  • Loading branch information
bilelmoussaoui committed Feb 1, 2024
1 parent 68044d0 commit 9ebc443
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/codegen/sys/cargo_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ fn fill_empty(root: &mut Table, env: &Env, crate_name: &str) {

let deps = upsert_table(root, "dependencies");
for ext_lib in &env.config.external_libraries {
let dep = upsert_table(deps, &ext_lib.crate_name);
let ext_package = if ext_lib.crate_name == "cairo" {
format!("{}-sys-rs", ext_lib.crate_name)
} else if ext_lib.crate_name == "gdk_pixbuf" {
Expand Down Expand Up @@ -92,7 +91,7 @@ fn fill_empty(root: &mut Table, env: &Env, crate_name: &str) {
| "gstreamer-allocators-sys" => "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs",
&_ => "ADD GIT REPOSITORY URL HERE",
};
set_string(dep, "package", ext_package);
let dep = upsert_table(deps, ext_package);
set_string(dep, "git", repo_url);
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/codegen/sys/lib_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn generate_lib(w: &mut dyn Write, env: &Env) -> Result<()> {
general::start_comments(w, &env.config)?;
statics::begin(w)?;

generate_extern_crates(w, env)?;
include_custom_modules(w, env)?;
statics::after_extern_crates(w)?;

Expand Down Expand Up @@ -104,6 +105,21 @@ fn generate_lib(w: &mut dyn Write, env: &Env) -> Result<()> {
Ok(())
}

fn generate_extern_crates(w: &mut dyn Write, env: &Env) -> Result<()> {
for library in &env.config.external_libraries {
w.write_all(
format!(
"use {}_sys as {};\n",
library.crate_name.replace('-', "_"),
crate_name(&library.namespace)
)
.as_bytes(),
)?;
}

Ok(())
}

fn include_custom_modules(w: &mut dyn Write, env: &Env) -> Result<()> {
let modules = find_modules(env)?;
if !modules.is_empty() {
Expand Down

0 comments on commit 9ebc443

Please sign in to comment.