Skip to content

Enhance pkg-config generation for interface libraries and Windows compatibility#3488

Merged
levlam merged 5 commits into
tdlib:masterfrom
luadebug:fix-pc
May 15, 2026
Merged

Enhance pkg-config generation for interface libraries and Windows compatibility#3488
levlam merged 5 commits into
tdlib:masterfrom
luadebug:fix-pc

Conversation

@luadebug

@luadebug luadebug commented Oct 20, 2025

Copy link
Copy Markdown
Contributor

Back in 2024s problem of PE size exceeding was resolved #2888, but actually the issue is still present and as workaround we need to split tdcore.lib into two part in case we build for Windows OS host, LTO enable flag comes here as helper to enforce splitting into two parts.

Unfortunately .pc generation handler for tdcore_part1.lib & tdcore_part2.lib was not implemented yet. This is attempt to make that splitting work. As microsoft/vcpkg#47690 validates generated .pc would work against vcpkg ci. https://github.com/microsoft/vcpkg/pull/47690/files#diff-bab39c8782e3538fd5a1a88f8c113153002bff5f4410bc4329729a7e9a59e99dR1

FAILED: tdcore.lib 
C:\Windows\system32\cmd.exe /C "cd . && C:\PROGRA~1\MICROS~1\2022\ENTERP~1\VC\Tools\MSVC\1444~1.352\bin\Hostx64\x64\lib.exe  /machine:x64 /nologo /out:tdcore.lib @CMakeFiles\tdcore.rsp && cd ."
tdcore.lib : fatal error LNK1248: image size (1022142D3) exceeds maximum allowable size (FFFFFFFF)

ninja: build stopped: subcommand failed.

@levlam

levlam commented Oct 21, 2025

Copy link
Copy Markdown
Contributor

Is it possible to avoid special handling of td_core with
if ("${TARGET}" STREQUAL "tdcore" AND "${LIBRARY_TYPE}" STREQUAL "INTERFACE_LIBRARY")
and always propagate interface libraries to the final target?
The generator cmake/GeneratePkgConfig.cmake is supposed to be project-agnostic and shouldn't depend on specific names of target or project structure.

@mateodelgado313-hash mateodelgado313-hash left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@59tyrg94qn-svg 59tyrg94qn-svg left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ciao

@mdnajmulhasanrafa-lab mdnajmulhasanrafa-lab mentioned this pull request Jan 29, 2026
@tdlib tdlib deleted a comment from 168ranew-cmd Feb 20, 2026
@tdlib tdlib deleted a comment from 168ranew-cmd Feb 20, 2026
@luadebug luadebug marked this pull request as draft April 11, 2026 23:14
@luadebug luadebug marked this pull request as ready for review April 12, 2026 02:25
Add interface compile definitions to pkg-config generation.
@luadebug

Copy link
Copy Markdown
Contributor Author

Maybe we should wait microsoft/vcpkg#51103 first.

@luadebug

Copy link
Copy Markdown
Contributor Author

@levlam review.

@levlam

levlam commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

@luadebug I'm currently busy with the next release. I'll review and test the changes after it.

@levlam

levlam commented May 14, 2026

Copy link
Copy Markdown
Contributor

Hi, @luadebug.

I reviewed the changes, partly tested them, and think that they are good to be merged now.

Duriing the testing I noticed a difference between the old and the new generated files. Previously, on Windows full absolute path to the library has always been used instead of combination of -L and -l:

    if (WIN32)
      set(${OUTPUT} "-l\"${DIRECTORY_NAME}/${NAME}\"" PARENT_SCOPE)
    else()
      get_filename_component(FULL_NAME "${PATH}" NAME)
      set(${OUTPUT} "-L\"${DIRECTORY_NAME}\" -l:${FULL_NAME}" PARENT_SCOPE)
    endif()

Does it still work correctly without full paths thanks to extraction of the correct library name from the path?

@luadebug

luadebug commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

Hi, @luadebug.

I reviewed the changes, partly tested them, and think that they are good to be merged now.

Duriing the testing I noticed a difference between the old and the new generated files. Previously, on Windows full absolute path to the library has always been used instead of combination of -L and -l:

    if (WIN32)
      set(${OUTPUT} "-l\"${DIRECTORY_NAME}/${NAME}\"" PARENT_SCOPE)
    else()
      get_filename_component(FULL_NAME "${PATH}" NAME)
      set(${OUTPUT} "-L\"${DIRECTORY_NAME}\" -l:${FULL_NAME}" PARENT_SCOPE)
    endif()

Does it still work correctly without full paths thanks to extraction of the correct library name from the path?

This is fine for MSVC and clang-cl because -L"DIR" -lNAME is the canonical pkg-config form and the MSVC translation is handled by pkg-config itself, not by the compiler. From the pkg-config man page, the --msvc-syntax option "causes pkg-config to output -l and -L flags in the form recognized by the Microsoft Visual C++ command-line compiler, cl. Specifically, instead of -Lx:/some/path it prints /libpath:x/some/path, and instead of -lfoo it prints foo.lib." So as long as the .pc file uses the standard -L/-l form, MSVC consumers get the right output automatically.

References:

--msvc-syntax
This option is available only on Windows. It causes pkg-config to output -l and -L flags in the form recognized by the Microsoft Visual C++ command-line compiler, cl. Specifically, instead of -Lx:/some/path it prints /libpath:x/some/path, and instead of -lfoo it prints foo.lib. Note that the --libs output consists of flags for the linker, and should be placed on the cl command line after a /link switch.

clang-cl is covered by the same mechanism: it shares cl.exe's command-line syntax (https://clang.llvm.org/docs/MSVCCompatibility.html), so anything that wraps pkg-config for MSVC works identically for clang-cl. The old absolute-path-inside--l form was actually the non-standard part — the new output is what pkg-config consumers expect.

p.s. the vcpkg azuri ci pipeline actually validates that all works in microsoft/vcpkg#51103 PR

@levlam levlam merged commit 51780ad into tdlib:master May 15, 2026
@levlam

levlam commented May 15, 2026

Copy link
Copy Markdown
Contributor

Merged. Thank you, @luadebug!

@albertoblue87-netizen albertoblue87-netizen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@albertoblue87-netizen albertoblue87-netizen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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.

Build of tdcore fails with linker error on windows

9 participants