Skip to content

CMake: Fix Windows shared dependency handling - #1789

Open
val-ms wants to merge 1 commit into
Cisco-Talos:mainfrom
val-ms:cmake-fixups
Open

val-ms wants to merge 1 commit into
Cisco-Talos:mainfrom
val-ms:cmake-fixups

Conversation

@val-ms

@val-ms val-ms commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • use Windows import libraries, rather than runtime DLLs, as Rust linker inputs
  • model dynamic libcheck imports with separate .lib and .dll locations
  • search dependency target directories and sibling bin directories when collecting runtime DLLs
  • keep PCRE2 in module discovery when config discovery is preferred globally
  • derive Windows package architecture names for non-Visual Studio generators
  • rerun the Rust build script when dependency-library variables change

Problem

Windows dependency packages conventionally install import libraries under lib and runtime DLLs under bin. Some of ClamAV's CMake wiring used TARGET_FILE where a linker input was required and searched only one side of that layout while collecting runtime dependencies.

With Curl's exported shared target, TARGET_FILE supplied bin/libcurl.dll to libclamav_rust/build.rs. The build script converted that filename into a request for libcurl.lib, but the actual import library is lib/libcurl_imp.lib. The resulting Rust test link failed with LNK1181.

Dynamic libcheck installations had a related issue: the existing fallback target represented checkDynamic.lib as an unknown imported target and did not model or validate the corresponding runtime DLL.

Solution

Use TARGET_LINKER_FILE for the dependency paths passed to Rust. Represent a manually discovered dynamic libcheck target as SHARED IMPORTED, with IMPORTED_IMPLIB pointing to the .lib file and IMPORTED_LOCATION pointing to the DLL. Runtime dependency collection now checks both target runtime directories and the sibling bin directories derived from linker-file locations.

The patch also keeps PCRE2 in module mode alongside LibXml2, supplies a package-architecture fallback for generators that do not define CMAKE_VS_PLATFORM_NAME, and declares the Rust build script's library environment dependencies.

Validation

  • git diff --check passes
  • clean x64 build completed all 394 targets
  • all six x64 CTest groups passed
  • x64 ZIP and MSI packages generated successfully from a dependency prefix with runtime DLLs under bin
  • dynamic Check discovery resolved lib/checkDynamic.lib and bin/checkDynamic.dll separately
  • the complete 13-recipe Mussels ARM64 dependency chain built successfully
  • current ClamAV source built and installed for ARM64; clamscan.exe reports machine type AA64
  • ARM64 ZIP and MSI packages generated successfully

ARM64 tests were compiled but not executed because validation ran on an x64 Windows host.

CLAM-3051

Windows dependency packages put import libraries in lib and runtime
DLLs in bin. Some CMake consumers treated runtime DLLs as linker
inputs or failed to search sibling bin directories when collecting
runtime dependencies. This caused Rust tests to request libcurl.lib
instead of libcurl_imp.lib and rejected otherwise valid shared
installations.

Use TARGET_LINKER_FILE for Rust linker inputs, model dynamic libcheck
with separate IMPORTED_IMPLIB and IMPORTED_LOCATION properties, and
search sibling bin directories when collecting runtime DLLs. Keep
PCRE2 in module mode, derive package architectures for non-Visual
Studio generators, and rerun Rust builds when library variables
change.

Clean x64 and ARM64 Windows builds completed successfully. The x64
build completed all 394 targets and all six CTest groups. It then
generated ZIP and MSI packages. The ARM64 build produced an AA64
clamscan.exe and generated ZIP and MSI packages.

CLAM-3051
@val-ms
val-ms marked this pull request as ready for review September 10, 2026 01:05
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-10T01:14:29.413261Z 4ac180f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@val-ms

val-ms commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 4ac180fddb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

1 participant