Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codegen/sys: Don't expect the crates are renamed #1542

Merged
merged 1 commit into from
Feb 1, 2024
Merged
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
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",
Copy link
Member

Choose a reason for hiding this comment

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

Why not just use foo_sys everywhere directly instead of going via the rename?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to do that, but the whole code is a mess. So for now, I just want a single file to update whenever I do a release

Copy link
Member

Choose a reason for hiding this comment

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

Ok, so this is just a hack for now to make things work and at a later time the whole renaming should be removed?

Maybe something @GuillaumeGomez wants to look at?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, so this is just a hack for now to make things work and at a later time the whole renaming should be removed?

Yeah, just going back to the original thing we had

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
Loading