Skip to content

Extend generated_name_override callback to variables #2351

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

Merged
merged 9 commits into from
Nov 28, 2022

Conversation

justsmth
Copy link
Contributor

@justsmth justsmth commented Nov 16, 2022

Context

Modifying (typically "prefixing") library symbols is needed to avoid conflicts for applications linking to multiple version of the same library, or when linking to several similar-but-different libraries. For example due to their histories, OpenSSL, BoringSSL and AWS-LC share many symbols in common. To avoid problems for downstream applications that depend on more than one of these libraries, symbol prefixing is needed.

Problem

The recent addition of ParseCallbacks::generated_name_override allows for function names that were modified/prefixed during their build, to have the modifications undone so that the generated bindings expose the original/intended name of the function. This is working as intended. However, the problem is that this callback is currently limited to modifying only function names, whereas other symbols (i.e., "extern" variables) may likewise need their names modified/prefixed to avoid link conflicts.

Change

  • This change updates ParseCallbacks::generated_name_override to accept a second parameter indicating the kind of item the name applies to (currently, either Function or Var).
  • A CallbackItemKind enum was added to serve as the type for this second parameter.
  • Tests have been updated to verify that the names of both function and variable can be updated by this callback.

@pvdrz
Copy link
Contributor

pvdrz commented Nov 21, 2022

@skmcgrail thanks for your contribution! I think it might be desirable to add more arguments to generated_name_override in the future and given that this is already a breaking change we could take an approach similar to this one #2355 and introduce a non-exhaustive struct (ItemInfo might be a good name?). What do you think?

@emilio
Copy link
Contributor

emilio commented Nov 22, 2022

Yeah, while we're changing the API, let's do as @pvdrz suggests to make sure that we can extend it easily in the future. Thanks!

@justsmth
Copy link
Contributor Author

@skmcgrail thanks for your contribution! I think it might be desirable to add more arguments to generated_name_override in the future and given that this is already a breaking change we could take an approach similar to this one #2355 and introduce a non-exhaustive struct (ItemInfo might be a good name?). What do you think?

Great idea!

@pvdrz pvdrz merged commit 199dfcc into rust-lang:master Nov 28, 2022
@justsmth justsmth deleted the extern-var-name-override branch November 28, 2022 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants