Skip to content

[net-snmp] Add new port#52688

Draft
H1vee wants to merge 15 commits into
microsoft:masterfrom
H1vee:add-net-snmp
Draft

[net-snmp] Add new port#52688
H1vee wants to merge 15 commits into
microsoft:masterfrom
H1vee:add-net-snmp

Conversation

@H1vee

@H1vee H1vee commented Jul 2, 2026

Copy link
Copy Markdown

Description

Adds a new Windows port for net-snmp (https://www.net-snmp.org/), the SNMP client/manager library and command-line tools.

Features

  • ssl (default): OpenSSL support, enabling SNMPv3 (USM authentication/privacy). Depends on openssl.
  • tools: net-snmp command-line utilities (e.g. snmpget, snmpwalk, snmpset), installed to tools/net-snmp.

Implementation

The port builds net-snmp with the upstream win32 nmake build system via vcpkg_build_nmake, using Perl (acquired through vcpkg_find_acquire_program) to run the upstream Configure script. The ssl feature passes the OpenSSL include/lib directories of the vcpkg-installed openssl to Configure for both the release and debug configurations.

Two patches are applied to the upstream sources:

  • msvc-openssl-autolink.patch — the generated net-snmp-config.h auto-links OpenSSL via #pragma comment(lib, ...), but the static-CRT branch references libcrypto_static.lib/libssl_static.lib, which don't exist in vcpkg's OpenSSL. The patch always uses libcrypto.lib/libssl.lib and adds crypt32.lib, which the static OpenSSL needs at link time. This fixes net-snmp[ssl,tools] on the static-linkage triplets.
  • no-system32-install.patch — removes upstream install steps that copy netsnmp.dll and PDB files into %SYSTEMROOT%\System32; a vcpkg install must not write outside the packages directory.

Other implementation notes:

  • INSTALL_BASE (the compile-time default root for MIB/config/persistence paths) is reset in the installed header from the absolute buildtree path to upstream's default c:/usr, since the baked-in path is not relocatable; these paths are meant to be overridden at runtime via environment variables or the registry.
  • The license expression is BSD-3-Clause AND HPND AND MIT, matching the 14 parts of upstream's COPYING (SPDX deprecated the dedicated Net-SNMP identifier in license list 3.25.0 in favor of an expression of the constituent licenses).
  • A brief usage file is installed; consumers link netsnmp plus ws2_32 (OpenSSL and crypt32 are auto-linked through the header pragmas).

Supports

windows & !mingw & !uwp & !xbox

The port targets the upstream Windows (MSVC) build system. Xbox is excluded because the perl-driven nmake build is untested there.

Testing

Verified successfully on:

  • x64-windows
  • x64-windows-static
  • x64-windows-static-md
  • x86-windows

Both Debug and Release configurations build successfully, and CI feature testing covers all feature combinations (core, ssl, tools, ssl+tools). The installed library and command-line tools were verified in a downstream MSVC/CMake project.


New port checklist

  • Changes comply with the maintainer guide.

  • The packaged project is mature and ready for broad sharing with vcpkg users.

    • Has a release at least 6 months old or 6 months of demonstrated public development.
    • Is an official component of something else meeting that criteria.
    • Some other reason (please explain).
  • The packaged project shows strong association with the chosen port name.

    • The project is in Repology.
    • The project is amongst the first web search results for the port name.
    • The port name follows the Owner-Project form.
  • Optional dependencies of the build are all controlled by the port.

  • The versioning scheme in vcpkg.json matches what upstream says.

  • The license declaration in vcpkg.json matches what upstream says.

  • The installed copyright file matches what upstream says.

  • The source code comes from an authoritative source.

  • The generated usage text is brief and accurate.

  • The version database was updated by rerunning ./vcpkg x-add-version --all.

  • Exactly one version was added in each modified versions file.

@H1vee

H1vee commented Jul 2, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Comment thread ports/net-snmp/vcpkg.json Outdated
"version": "5.9.5.2",
"description": "A SNMP application library, tools and daemon",
"homepage": "https://www.net-snmp.org/",
"license": "BSD-4-Clause",

@ricardoofnl ricardoofnl Jul 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

BSD-4-Clause doesn't look right here: none of the 14 parts in upstream's COPYING carry the BSD advertising clause. They break down as HPND (Part 1, CMU/UCD), MIT (Part 10, Lennart Poettering) and BSD-3-Clause (all the others), so something like BSD-3-Clause AND HPND AND MIT would be accurate. (SPDX used to have a dedicated Net-SNMP identifier for this stack, but it is deprecated since license list 3.25.0 in favor of an expression of the constituent licenses.)

Comment thread ports/net-snmp/vcpkg.json Outdated
"supports": "windows & !mingw & !uwp",
"dependencies": [
{
"name": "vcpkg-cmake",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This dependency is unused: the portfile only uses vcpkg_build_nmake and never calls vcpkg_cmake_configure/vcpkg_cmake_install, so vcpkg-cmake can be removed.

Comment thread ports/net-snmp/portfile.cmake Outdated
vcpkg_replace_string(
"${TARGET_DIR}/include/net-snmp/net-snmp-config.h"
"#define INSTALL_BASE \"${TARGET_DIR}\""
"#define INSTALL_BASE \"/../../\""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"/../../" is not a resolvable path, so anything reading INSTALL_BASE at runtime gets a bogus value. If the intent is just to silence the absolute-path post-build check, a short comment explaining that would help future maintainers.

Comment thread ports/net-snmp/portfile.cmake Outdated
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage"
DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")

vcpkg_fixup_pkgconfig() No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The win32 nmake build doesn't install any .pc files, so vcpkg_fixup_pkgconfig() is a no-op here and can be dropped. Also missing a trailing newline at EOF.

Comment thread ports/net-snmp/usage Outdated
@@ -0,0 +1,21 @@
net-snmp provides the SNMP client/manager library and tools, and (with the

@ricardoofnl ricardoofnl Jul 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Usage files are conventionally just a short "how to consume" snippet (see e.g. ports/libuv/usage for a port without a CMake config). The installed-layout listing and the advice about system packages on other platforms (apt/Homebrew) could be dropped.

@ricardoofnl ricardoofnl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for addressing the earlier comments, the license expression, the removed vcpkg-cmake dependency, the trimmed usage file and the INSTALL_BASE comment all look good now. One new blocker inline: the two patch files referenced by the portfile are not part of the PR, which is why every Windows job in the latest CI run fails immediately.

Comment thread ports/net-snmp/portfile.cmake Outdated

vcpkg_find_acquire_program(PERL)
get_filename_component(PERL_PATH "${PERL}" DIRECTORY)
vcpkg_add_to_path("${PERL_PATH}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

msvc-openssl-autolink.patch and no-system32-install.patch are referenced here but neither file is in the PR, so the build fails at patch time on every triplet (that is what the current CI failures are). Looks like they were not git add-ed. Remember that after adding them you also need to rerun ./vcpkg x-add-version --all since the git-tree changes.

The portfile references msvc-openssl-autolink.patch and
no-system32-install.patch, but the files were never committed, so every
build failed at source extraction with 'Could not find patch'. With them
in place the port directory tree matches the git-tree already recorded
in versions/n-/net-snmp.json.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014n2bVhar9Ab4mv1KcQdEYK
@H1vee H1vee requested a review from ricardoofnl July 2, 2026 14:35

@ricardoofnl ricardoofnl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All points from my earlier reviews are resolved now, and CI is green across all 15 checks including the three static triplets that failed originally.

Worth highlighting for triage: msvc-openssl-autolink.patch fixes the actual root cause of those static failures. Upstream's win32/net-snmp/net-snmp-config.h.in auto-links OpenSSL via #pragma comment(lib, ...) and picks libcrypto_static.lib/libssl_static.lib when the CRT is static; those names come from the official OpenSSL Windows installers and never exist in vcpkg, which always ships libcrypto.lib/libssl.lib (that was the LNK1104 on x64-windows-static). The patch also adds crypt32.lib, which static OpenSSL needs for its CAPI/winstore code (that was the LNK2019 __imp_CertOpenStore on x64-windows-static-md). And no-system32-install.patch removing the upstream copy of DLLs/PDBs into %SYSTEMROOT%\System32 is something no vcpkg build should ever do anyway.

LGTM as a non-maintainer review.

@H1vee H1vee closed this Jul 2, 2026
@H1vee H1vee reopened this Jul 2, 2026
Comment thread ports/net-snmp/portfile.cmake Outdated
Comment on lines +15 to +39
set(NET_SNMP_FEATURE_LIST "")
list(APPEND NET_SNMP_FEATURE_LIST "--with-sdk")
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
list(APPEND NET_SNMP_FEATURE_LIST "--linktype=static")
else()
list(APPEND NET_SNMP_FEATURE_LIST "--linktype=dynamic")
endif()

set(TARGET_DIR "${CURRENT_PACKAGES_DIR}")
set(TARGET_DIR_DEBUG "${CURRENT_PACKAGES_DIR}/debug")

set(NET_SNMP_SSL "")
set(NET_SNMP_SSL_DEBUG "")

if("ssl" IN_LIST FEATURES)
list(APPEND NET_SNMP_SSL
"--with-ssl"
"--with-sslincdir=${CURRENT_INSTALLED_DIR}/include"
"--with-ssllibdir=${CURRENT_INSTALLED_DIR}/lib")
list(APPEND NET_SNMP_SSL_DEBUG
"--with-ssl"
"--with-sslincdir=${CURRENT_INSTALLED_DIR}/include"
"--with-ssllibdir=${CURRENT_INSTALLED_DIR}/debug/lib")
endif()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
set(NET_SNMP_FEATURE_LIST "")
list(APPEND NET_SNMP_FEATURE_LIST "--with-sdk")
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
list(APPEND NET_SNMP_FEATURE_LIST "--linktype=static")
else()
list(APPEND NET_SNMP_FEATURE_LIST "--linktype=dynamic")
endif()
set(TARGET_DIR "${CURRENT_PACKAGES_DIR}")
set(TARGET_DIR_DEBUG "${CURRENT_PACKAGES_DIR}/debug")
set(NET_SNMP_SSL "")
set(NET_SNMP_SSL_DEBUG "")
if("ssl" IN_LIST FEATURES)
list(APPEND NET_SNMP_SSL
"--with-ssl"
"--with-sslincdir=${CURRENT_INSTALLED_DIR}/include"
"--with-ssllibdir=${CURRENT_INSTALLED_DIR}/lib")
list(APPEND NET_SNMP_SSL_DEBUG
"--with-ssl"
"--with-sslincdir=${CURRENT_INSTALLED_DIR}/include"
"--with-ssllibdir=${CURRENT_INSTALLED_DIR}/debug/lib")
endif()
set(FEATURE_OPTIONS_RELEASE "")
set(FEATURE_OPTIONS_DEBUG "")
if("ssl" IN_LIST FEATURES)
list(APPEND FEATURE_OPTIONS_RELEASE
"--with-ssl"
"--with-sslincdir=${CURRENT_INSTALLED_DIR}/include"
"--with-ssllibdir=${CURRENT_INSTALLED_DIR}/lib"
)
list(APPEND FEATURE_OPTIONS_DEBUG
"--with-ssl"
"--with-sslincdir=${CURRENT_INSTALLED_DIR}/include"
"--with-ssllibdir=${CURRENT_INSTALLED_DIR}/debug/lib"
)
endif()

and just use literal ${CURRENT_PACKAGES_DIR}[/debug].

Comment thread ports/net-snmp/portfile.cmake Outdated
Comment on lines +46 to +62
vcpkg_build_nmake(
SOURCE_PATH "${SOURCE_PATH}"
PROJECT_SUBPATH win32
PRERUN_SHELL_RELEASE "${PERL}" Configure
${NET_SNMP_FEATURE_LIST}
${NET_SNMP_SSL}
--config=release
"--prefix=${TARGET_DIR}"
PRERUN_SHELL_DEBUG "${PERL}" Configure
${NET_SNMP_FEATURE_LIST}
${NET_SNMP_SSL_DEBUG}
--config=debug
"--prefix=${TARGET_DIR_DEBUG}"
PROJECT_NAME "Makefile"
TARGET ${TARGETS} install install_devel
LOGFILE_ROOT build-net-snmp
)

@dg0yt dg0yt Jul 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
vcpkg_build_nmake(
SOURCE_PATH "${SOURCE_PATH}"
PROJECT_SUBPATH win32
PRERUN_SHELL_RELEASE "${PERL}" Configure
${NET_SNMP_FEATURE_LIST}
${NET_SNMP_SSL}
--config=release
"--prefix=${TARGET_DIR}"
PRERUN_SHELL_DEBUG "${PERL}" Configure
${NET_SNMP_FEATURE_LIST}
${NET_SNMP_SSL_DEBUG}
--config=debug
"--prefix=${TARGET_DIR_DEBUG}"
PROJECT_NAME "Makefile"
TARGET ${TARGETS} install install_devel
LOGFILE_ROOT build-net-snmp
)
vcpkg_build_nmake(
SOURCE_PATH "${SOURCE_PATH}"
PROJECT_SUBPATH win32
PRERUN_SHELL_RELEASE "${PERL}" Configure
--config=release
--linktype=${VCPKG_LIBRARY_LINKAGE}
"--prefix=${CURRENT_PACKAGES_DIR}"
--with-sdk
${FEATURE_OPTIONS_RELEASE}
PRERUN_SHELL_DEBUG "${PERL}" Configure
--config=debug
--linktype=${VCPKG_LIBRARY_LINKAGE}
"--prefix=${CURRENT_PACKAGES_DIR}/debug"
--with-sdk
${FEATURE_OPTIONS_DEBUG}
PROJECT_NAME "Makefile"
TARGET ${TARGETS} install install_devel
)

Comment thread ports/net-snmp/portfile.cmake Outdated
Comment on lines +70 to +75
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
if(TARGETS STREQUAL "libs" AND EXISTS "${TARGET_DIR}/bin")
file(REMOVE_RECURSE "${TARGET_DIR}/bin")
file(REMOVE_RECURSE "${TARGET_DIR_DEBUG}/bin")
endif()
endif()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Dealing with bin in a static-only way before dealing with scripts and tools is usually a path to inconsistent build results.

Comment thread ports/net-snmp/usage
Comment on lines +1 to +6
net-snmp provides no CMake targets. It can be used from CMake via:

find_path(NETSNMP_INCLUDE_DIR net-snmp/net-snmp-config.h)
find_library(NETSNMP_LIBRARY NAMES netsnmp)
target_include_directories(main PRIVATE ${NETSNMP_INCLUDE_DIR})
target_link_libraries(main PRIVATE ${NETSNMP_LIBRARY} ws2_32)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Aligning with tool output:

Suggested change
net-snmp provides no CMake targets. It can be used from CMake via:
find_path(NETSNMP_INCLUDE_DIR net-snmp/net-snmp-config.h)
find_library(NETSNMP_LIBRARY NAMES netsnmp)
target_include_directories(main PRIVATE ${NETSNMP_INCLUDE_DIR})
target_link_libraries(main PRIVATE ${NETSNMP_LIBRARY} ws2_32)
net-snmp can be used from CMake via:
find_path(NETSNMP_INCLUDE_DIR net-snmp/net-snmp-config.h)
find_library(NETSNMP_LIBRARY NAMES netsnmp)
target_include_directories(main PRIVATE "${NETSNMP_INCLUDE_DIR}")
target_link_libraries(main PRIVATE "${NETSNMP_LIBRARY}" ws2_32)

Comment thread ports/net-snmp/vcpkg.json
"description": "A SNMP application library, tools and daemon",
"homepage": "https://www.net-snmp.org/",
"license": "BSD-3-Clause AND HPND AND MIT",
"supports": "windows & !mingw & !uwp & !xbox",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IIUC net-snmp supports !windows, but the port is limited.

@BillyONeal BillyONeal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

GPT-5.5 observes:

  • The installed binaries are not relocatable. ports/net-snmp/portfile.cmake rewrites INSTALL_BASE only in the installed header, but installed binaries/libraries still contain absolute build/package paths for locations such as share/snmp/mibs and lib/dlmod. Running an installed tool without operands attempted to create directories under the build package path, and binary scanning found those paths in installed netsnmp.dll, debug netsnmp.dll, and netsnmpmibs.lib. Ports must not embed package-build paths into installed artifacts.

  • ports/net-snmp/portfile.cmake has CRLF line endings, causing git diff --check origin/master...HEAD to report every line as trailing whitespace. vcpkg port files should use LF line endings.

============================

It also found this, but this is probably not a blocking issue to merge this.

  • ports/net-snmp/usage is not sufficient for consumers. The installed headers add MSVC autolink pragmas for libcrypto.lib and libssl.lib via ports/net-snmp/msvc-openssl-autolink.patch, but the usage snippet only links netsnmp and ws2_32. A validation CMake consumer using the snippet fails for both x64-windows and x64-windows-static with LINK : fatal error LNK1104: cannot open file 'libcrypto.lib'.

@BillyONeal BillyONeal marked this pull request as draft July 3, 2026 00:52
claude and others added 3 commits July 3, 2026 05:22
…end usage

- Add relocatable-install-base.patch: stop win32/Configure from
  substituting the --prefix path into net-snmp-config.h. The header's
  INSTALL_BASE feeds compile-time default runtime paths (MIBDIRS,
  SNMPCONFPATH, SNMPDLMODPATH, persistent storage), so the buildtree
  path ended up as string constants inside netsnmp.dll and the static
  libraries. With the patch the header keeps upstream's default c:/usr
  everywhere while --prefix still controls the install destination; the
  post-install header rewrite is no longer needed and is removed.
- Convert portfile.cmake from CRLF to LF line endings.
- Extend usage: consumers of the default ssl feature must link OpenSSL
  because net-snmp's installed headers auto-link libcrypto.lib/libssl.lib
  via MSVC pragmas.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014n2bVhar9Ab4mv1KcQdEYK
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014n2bVhar9Ab4mv1KcQdEYK
net-snmp: Make INSTALL_BASE relocatable and improve usage docs
@H1vee H1vee closed this Jul 3, 2026
@H1vee H1vee reopened this Jul 3, 2026
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.

5 participants