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

cmake: add support for single libcurl compilation pass #11546

Closed
wants to merge 3 commits into from

Conversation

vszakats
Copy link
Member

@vszakats vszakats commented Jul 30, 2023

Before this patch CMake builds used two separate compilation passes to
build the shared and static libcurl respectively. This patch allows to
reduce that to a single pass if the target platform and build settings
allow it.

This reduces CMake build times when building both static and shared
libcurl at the same time, making these dual builds an almost zero-cost
option.

Enable this feature for Windows builds, where the difference between the
two passes was the use of __declspec(dllexport) attribute for exported
API functions for the shared builds. This patch replaces this method
with the use of libcurl.def at DLL link time.

Also update Makefile.mk to use libcurl.def to export libcurl API
symbols on Windows. This simplifies (or fixes) this build method (e.g.
in curl-for-win, which generated a libcurl.def from .h files using
an elaborate set of transformations).

libcurl.def has the maintenance cost of keeping the list of public
libcurl API symbols up-to-date. This list seldom changes, so the cost
is low.

Closes #11546


  • curl previously had a libcurl.def placed in the lib directory. I opted for the root directory, because in lib it may be overwritten by .def files generated by the DLL linker command when using certain build methods/options.

  • single-pass libcurl builds can be freely extended to other platforms, if both shared/static libs have position-independent code enable and symbol exports can be fixed up via a linker option.

  • it might be an option to make libcurl.def an OS-agnostic raw list of public API symbols (= without the top EXPORTS line) for re-use for other purposes. CMake could handle that with some extra lines. In Makefile.mk less trivially, but also seems doable.

@vszakats vszakats added build cmake Windows Windows-specific labels Jul 30, 2023
@vszakats vszakats marked this pull request as draft July 30, 2023 13:08
@dfandrich
Copy link
Contributor

dfandrich commented Jul 30, 2023 via email

@dfandrich
Copy link
Contributor

dfandrich commented Jul 30, 2023 via email

@vszakats
Copy link
Member Author

vszakats commented Jul 30, 2023

We do use declspec(), yes, and this is what forces separate compile passes for shared and static libs. The goal of this PR is to avoid that double work. Another positive side effect is that Makefile.mk builds can also use this libcurl.def, without having to generate it manually. Makefile.mk always used a single compile pass, so a .def file was always necessary for correct results (on Windows).

The file was deleted because it wasn't used. This time it will be used by two build systems.

@vszakats vszakats marked this pull request as ready for review July 30, 2023 22:20
@vszakats vszakats changed the title cmake: add support for single libcurl compilation pass on Windows cmake: add support for single libcurl compilation pass Jul 31, 2023
@vszakats vszakats closed this in 2ebc74c Aug 1, 2023
@vszakats vszakats deleted the build-add-libcurl-def branch August 1, 2023 08:15
vszakats added a commit to curl/curl-for-win that referenced this pull request Aug 1, 2023
Stop dynamically generating `libcurl.def` with the next curl release,
which provides it and uses it automatically in GNU Make builds.

curl/curl@2ebc74c
curl/curl#11546
vszakats added a commit to vszakats/curl that referenced this pull request Aug 8, 2023
2ebc74c curl#11546 introduced sharing
libcurl objects for shared and static targets.

The above automatically enabled for Windows builds, with an option to
disable with `SHARE_LIB_OBJECT=OFF`.

This patch extend this feature for all platforms as a manual option.
You can enable it by setting `SHARE_LIB_OBJECT=ON`. Shared objects will
be built in PIC mode, meaning the static lib will also have PIC code.

EXPERIMENTAL.

Closes #xxxxx
vszakats added a commit that referenced this pull request Aug 9, 2023
2ebc74c #11546 introduced sharing
libcurl objects for shared and static targets.

The above automatically enabled for Windows builds, with an option to
disable with `SHARE_LIB_OBJECT=OFF`.

This patch extend this feature to all platforms as a manual option.
You can enable it by setting `SHARE_LIB_OBJECT=ON`. Then shared objects
are built in PIC mode, meaning the static lib will also have PIC code.

[EXPERIMENTAL]

Closes #11627
ptitSeb pushed a commit to wasix-org/curl that referenced this pull request Sep 25, 2023
Before this patch CMake builds used two separate compilation passes to
build the shared and static libcurl respectively. This patch allows to
reduce that to a single pass if the target platform and build settings
allow it.

This reduces CMake build times when building both static and shared
libcurl at the same time, making these dual builds an almost zero-cost
option.

Enable this feature for Windows builds, where the difference between the
two passes was the use of `__declspec(dllexport)` attribute for exported
API functions for the shared builds. This patch replaces this method
with the use of `libcurl.def` at DLL link time.

Also update `Makefile.mk` to use `libcurl.def` to export libcurl API
symbols on Windows. This simplifies (or fixes) this build method (e.g.
in curl-for-win, which generated a `libcurl.def` from `.h` files using
an elaborate set of transformations).

`libcurl.def` has the maintenance cost of keeping the list of public
libcurl API symbols up-to-date. This list seldom changes, so the cost
is low.

Closes curl#11546
ptitSeb pushed a commit to wasix-org/curl that referenced this pull request Sep 25, 2023
2ebc74c curl#11546 introduced sharing
libcurl objects for shared and static targets.

The above automatically enabled for Windows builds, with an option to
disable with `SHARE_LIB_OBJECT=OFF`.

This patch extend this feature to all platforms as a manual option.
You can enable it by setting `SHARE_LIB_OBJECT=ON`. Then shared objects
are built in PIC mode, meaning the static lib will also have PIC code.

[EXPERIMENTAL]

Closes curl#11627
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants