Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Follow up to #1475. Motivated by work at
gtk-rs-core
andgstreamer-rs
to override library linking.At the moment a
#[link]
attribute is being generated for everyextern "C"
code block. This is not generally needed sincesystem-deps
already handles linking libraries, and it makes overriding dependencies difficult from higher up crates.The only exception is one edge case when using Windows and static constants, but that is a limitation of the compiler. To handle this case, allow to use custom
build.rs
scripts by not overriding the package field.All of the context for this change and all of the alternatives we considered are explained in gtk-rs/gtk-rs-core#1508.
Changes
#[link]
attribute generation.package.build
key doesn't exist inCargo.toml
, generate it to bebuild.rs
. Otherwise keep the existing value.Caveats
Something to consider is whether removing the
#[link]
generation could affect other crates. From an overview of other crates relying ongir
, it seems that they are not linking static constants, just functions, which do not explicitly need dllimport. If this is expected to be a problem, maybe a command line flag like--link
could be added to the generator script that allows customizing this behaviour.