curl/.github/workflows
Viktor Szakats 66ad54e46b
cmake: add CURL_DROP_UNUSED option to reduce binary sizes
To enable known linker options dropping unused, dead, code and data from
the executables built.

Useful to reduce binary sizes for curl, libcurl shared lib and apps
linking static libcurl. It's effective on both "unity" and non-unity
builds. Aligning "unity" build sizes with default, non-unity ones.

Supported platforms: Apple, MSVC, llvm/clang and GCC on all tested
platforms: Linux, BSDs, Windows, MSYS2/Cygwin, Android, MS-DOS.

Notes:
- Static libraries grow 20-30% with non-Apple toolchains.
  This effect is controlled by separate, optional compiler flags on
  non-Apple. This patch enables them automatically for public binaries
  (libcurl and curl tool), and leaves them off for internal/test ones.
- MSVC enables this option by default for 'Release' configurations.
  The curl build option has no effect on it.
- Observed effect on VS2010 is negligible. VS2012+ is recommended.
- Works with LTO, Fil-C.
- No observed/conclusive effect on build speed.
- On Windows with clang/gcc (mingw-w64/MSYS2/Cygwin) it also enables
  `-fno-asynchronous-unwind-tables` as a workaround to make
  the toolchain options actually work.
  Ref: https://sourceware.org/bugzilla/show_bug.cgi?id=11539
  Thanks-to: Andarwinux

Also:
- GHA: enable in Linux and MinGW jobs to test it. Size changes:

  - linux aws-lc H3:
    curl: 2000000 -> 1937152, libcurl.a: 2065724 -> 2716532 bytes
  - macos clang HTTP-only:
    curl: 1364376 -> 128799 bytes, libcurl.a: unchanged
  - macos llvm MultiSSL:
    curl: 410056 -> 405720, libcurl.dylib: 1350336 -> 1348480 bytes
  - mingw schannel c-ares U:
    curl: 1588736 -> 1507328, libcurl-d.a: 3322040 -> 3884746 bytes
    bld: 34 -> 35MB

- GHA: enable in MSVC and Apple jobs to reduce disk footprint, with no
  obvious downside. Size changes:

  - AppVeyor CI VS2019:
    curl: 2339840 -> 1295872, libcurl-d.dll: 3155968 -> 1900544 bytes
    bld: 161 -> 97MB
  - AppVeyor CI VS2022 clang-cl:
    curl: 2933248 -> 2332160, libcurl-d.lib: 4762688 -> 5511330 bytes
    bld: 133 -> 121MB
  - AppVeyor CI VS2022 HTTP-only:
    curl: 3514368 -> 2177024, libcurl-d.lib: 2538420 -> 3151740 bytes
    bld: 137 -> 83MB
  - GHA intel:
    curl: 2629120 -> 2023424, libcurl-d.lib: 4366652 -> 5350670 bytes
    bld: 86 -> 69MB
  - GHA arm64:
    curl: 2832896 -> 2063872, libcurl-d.lib: 4690616 -> 5597250 bytes
    bld: 82 -> 66MB

Refs:
https://maskray.me/blog/2021-02-28-linker-garbage-collection
https://web.archive.org/web/20110811230637/msdn.microsoft.com/en-us/library/bxwfs976.aspx (VS2010)
https://learn.microsoft.com/cpp/build/reference/opt-optimizations
https://learn.microsoft.com/cpp/build/reference/gy-enable-function-level-linking

Closes #20357
2026-01-22 17:08:20 +01:00
..
appveyor-status.yml GHA: switch 12 Linux jobs to arm64 2026-01-09 19:35:16 +01:00
checkdocs.yml tidy-up: merge root packages directory into projects 2026-01-12 23:49:35 +01:00
checksrc.yml build: add curl-lint/lint targets, CURL_LINT cmake option 2026-01-12 16:45:24 +01:00
checkurls.yml GHA: switch 12 Linux jobs to arm64 2026-01-09 19:35:16 +01:00
codeql.yml tidy-up: merge root packages directory into projects 2026-01-12 23:49:35 +01:00
configure-vs-cmake.yml GHA: delete disable-man-db hack, runners doing it by default now 2026-01-11 15:40:21 +01:00
curl-for-win.yml GHA/curl-for-win: add CPU to Linux minimal job name 2026-01-20 03:38:18 +01:00
distcheck.yml GHA: delete disable-man-db hack, runners doing it by default now 2026-01-11 15:40:21 +01:00
fuzz.yml GHA: silence fresh zizmor 1.21.0 warnings 2026-01-16 13:48:28 +01:00
http3-linux.yml cmake: add CURL_DROP_UNUSED option to reduce binary sizes 2026-01-22 17:08:20 +01:00
label.yml GHA: set concurrency: where missing 2025-10-24 13:38:11 +02:00
linux-old.yml tidy-up: miscellaneous 2026-01-15 13:06:13 +01:00
linux.yml cmake: add CURL_DROP_UNUSED option to reduce binary sizes 2026-01-22 17:08:20 +01:00
macos.yml cmake: add CURL_DROP_UNUSED option to reduce binary sizes 2026-01-22 17:08:20 +01:00
non-native.yml GHA: strip Windows/MS-DOS/Android binaries to see their real size 2026-01-21 16:05:17 +01:00
windows.yml cmake: add CURL_DROP_UNUSED option to reduce binary sizes 2026-01-22 17:08:20 +01:00