-
Notifications
You must be signed in to change notification settings - Fork 921
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
Define variants of WEBVIEW_API with new defaults #893
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This work provides new compile-time options intended to simplify compilation and integration of the library on the source code side. The default linkage was always extern which would cause ODR violations by default when the library's header was included in multiple C++ source files. The new linkage depends on the presence of compile-time options as well as whether the library's header file is included in C or C++ code. The following use cases were taken into consideration: * Building a shared library (C++) and integrating a shared library (C/C++). * Building a static library (C++) and integrating a static library (C/C++). * Using the library as a header-only library (C++). Options: * WEBVIEW_SHARED should be defined when using the library as a shared library (C/C++). * WEBVIEW_BUILD_SHARED should be defined when building the library as a shared library (C++). * WEBVIEW_STATIC should be defined when building or using the library as a static library (C/C++). * If none of the above are defined then defaults will be used. All of the mentioned options are mutually exclusive. Details: * When WEBVIEW_API is already defined then the linkage is as specified by WEBVIEW_API. * When webview.h is included in C++ code without any options then WEBVIEW_API is set to inline to avoid ODR violations. Existing users who rely on WEBVIEW_API to default to extern may see undefined references unless they define either WEBVIEW_STATIC or WEBVIEW_API (as extern or nothing). * When webview.h is included in C code without any options then WEBVIEW_API is set to nothing which defaults to extern as before. * When WEBVIEW_STATIC is defined then WEBVIEW_API is set to nothing (extern). * When WEBVIEW_BUILD_SHARED is defined then WEBVIEW_API is set to __declspec(dllexport) when building for Windows and otherwise __attribute__((visibility("default"))). * When WEBVIEW_SHARED is defined then WEBVIEW_API is set to __declspec(dllimport) for Windows and otherwise __attribute__((visibility("default"))).
SteffenL
added
the
enhancement
New feature, enhancement of an existing feature or a request
label
Sep 12, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR is going to need some discussion to make sure that we are doing the right thing.
Proposal
This work provides new compile-time options intended to simplify compilation and integration of the library on the source code side. The default linkage was always
extern
which would cause ODR violations by default when the library's header was included in multiple C++ source files. The new linkage depends on the presence of compile-time options as well as whether the library's header file is included in C or C++ code.The following use cases were taken into consideration:
Options
WEBVIEW_SHARED
should be defined when using the library as a shared library (C/C++).WEBVIEW_BUILD_SHARED
should be defined when building the library as a shared library (C++).WEBVIEW_STATIC
should be defined when building or using the library as a static library (C/C++).If none of the above are defined then defaults will be used.
All of the mentioned options are mutually exclusive.
Details
When
WEBVIEW_API
is already defined then the linkage is as specified byWEBVIEW_API
.When
webview.h
is included in C++ code without any options thenWEBVIEW_API
is set toinline
to avoid ODR violations. Existing users who rely onWEBVIEW_API
to default toextern
may see undefined references unless they define eitherWEBVIEW_STATIC
orWEBVIEW_API
(asextern
or nothing).When
webview.h
is included in C code without any options thenWEBVIEW_API
is set to nothing which defaults toextern
as before.When
WEBVIEW_STATIC
is defined thenWEBVIEW_API
is set to nothing (extern
).When
WEBVIEW_BUILD_SHARED
is defined thenWEBVIEW_API
is set to__declspec(dllexport)
when building for Windows and otherwise__attribute__((visibility("default")))
.When
WEBVIEW_SHARED
is defined thenWEBVIEW_API
is set to__declspec(dllimport)
for Windows and otherwise__attribute__((visibility("default")))
.Discussion Points
WEBVIEW_API
?WEBVIEW_BUILD_SHARED
,WEBVIEW_SHARED
,WEBVIEW_STATIC
) appropriate?WEBVIEW_STATIC
is defined for Go bindings so that external linkage is used, just like before. Should we discuss whether Go bindings should keep using a static library by default or change it to shared library, or make that an option somehow? We have to consider the inconvenience with MS WebView2 on Windows.