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

Adding DLL export/import tags to generated public upb API (redux) (#17079) #17105

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

copybara-service[bot]
Copy link

Adding DLL export/import tags to generated public upb API (redux) (#17079)

Picking up #14981 from @dawidcha after several months of radio silence.

Quoting the OP of that PR:

I have been collaborating with the grpc developers to make it possible to build that library as a Windows DLL - a couple of PRs were already merged, more like grpc/grpc#34345 are pending.

The grpc library incorporates some upb-generated, and upbdefs-generated code into grpc.dll, which is referenced by other code that consumes the library. Since this is now a DLL, that code doesn't know how to link to these generated symbols because they are not annotated with __declspec(dllimport).

This PR aims to fix that by introducing a parameter 'dllexport_tag' to the upb and upbdefs plugins. That parameter should be a string e.g. MYAPP_DLL and when set, the extern symbols are annotated with a macro with that name. This can either be set externally to __declspec(dllimport) or, as is usual practice, when compiling code into a DLL, the macro <dllexport_tag>_EXPORT (i.e. MYAPP_DLL_EXPORT) is defined, and when consuming the DLL <dllexport_tag>_IMPORT is defined if neither are defined then the MYAPP_DLL macro becomes empty string which is what you want for building a static library.

This is a continuation of #14230

Fixes: #14255

Towards #13726
Closes #14981

Closes #17079

COPYBARA_INTEGRATE_REVIEW=#17079 from h-vetinari:add_dll_tags 34927b1
FUTURE_COPYBARA_INTEGRATE_REVIEW=#17079 from h-vetinari:add_dll_tags 34927b1

…7079)

Picking up #14981 from @dawidcha after several months of radio silence.

Quoting the OP of that PR:
> I have been collaborating with the grpc developers to make it possible to build that library as a Windows DLL - a couple of PRs were already merged, more like [grpc/grpc#34345](grpc/grpc#34345) are pending.
>
> The grpc library incorporates some upb-generated, and upbdefs-generated code into grpc.dll, which is referenced by other code that consumes the library. Since this is now a DLL, that code doesn't know how to link to these generated symbols because they are not annotated with __declspec(dllimport).
>
> This PR aims to fix that by introducing a parameter 'dllexport_tag' to the upb and upbdefs plugins. That parameter should be a string e.g. MYAPP_DLL and when set, the extern symbols are annotated with a macro with that name. This can either be set externally to __declspec(dllimport) or, as is usual practice, when compiling code into a DLL, the macro <dllexport_tag>_EXPORT (i.e. MYAPP_DLL_EXPORT) is defined, and when consuming the DLL <dllexport_tag>_IMPORT is defined if neither are defined then the MYAPP_DLL macro becomes empty string which is what you want for building a static library.
>
> This is a continuation of #14230
>
> Fixes: #14255

Towards #13726
Closes #14981

Closes #17079

COPYBARA_INTEGRATE_REVIEW=#17079 from h-vetinari:add_dll_tags 34927b1
PiperOrigin-RevId: 642622258
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.

upb-generator to emit code that can be used in a Windows shared library (DLL)
1 participant