-
Notifications
You must be signed in to change notification settings - Fork 122
Adding vcpkg integration #825
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
base: main
Are you sure you want to change the base?
Changes from all commits
e5eb6a5
f52e0df
c59b8b1
0970eca
5b87eb3
d90a191
6e4f8e4
3d05801
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Without static-shim: INTERFACE only — Release and Debug are identical. | ||
| # With static-shim: compiled code is produced — both variants are needed. | ||
| if(NOT "static-shim" IN_LIST FEATURES) | ||
| set(VCPKG_BUILD_TYPE release) | ||
| endif() | ||
|
|
||
| vcpkg_from_github( | ||
| OUT_SOURCE_PATH SOURCE_PATH | ||
| REPO microsoft/snmalloc | ||
| REF "v${VERSION}" | ||
| SHA512 0 # Placeholder: compute the real SHA512 from the GitHub release tarball before publishing to the vcpkg registry. | ||
| HEAD_REF main | ||
| ) | ||
|
|
||
| # NOTE: The CI overlay port (see .github/workflows/main.yml, vcpkg-integration) | ||
| # uses sed to extract from this line onwards to build a portfile that points at | ||
| # the local checkout. If you reorder code above this line, update the sed | ||
| # pattern there. | ||
| vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS | ||
| FEATURES | ||
| "static-shim" SNMALLOC_STATIC_LIBRARY | ||
| INVERTED_FEATURES | ||
| "static-shim" SNMALLOC_HEADER_ONLY_LIBRARY | ||
| ) | ||
|
|
||
| vcpkg_cmake_configure( | ||
| SOURCE_PATH "${SOURCE_PATH}" | ||
| OPTIONS | ||
| -DSNMALLOC_BUILD_TESTING=OFF | ||
| ${FEATURE_OPTIONS} | ||
| ) | ||
|
|
||
| vcpkg_cmake_install() | ||
|
|
||
| vcpkg_cmake_config_fixup( | ||
| PACKAGE_NAME snmalloc | ||
| CONFIG_PATH share/snmalloc | ||
| ) | ||
|
|
||
| file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") | ||
| file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share") | ||
|
Comment on lines
+40
to
+41
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what these lines are doing.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vcpkg only allows you to have one copy of the headers etc. under the install directory. If it didn't remove the debug copies, then the post-validation step would fail. |
||
|
|
||
| vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") | ||
|
|
||
| file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" | ||
| DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| snmalloc provides CMake integration via: | ||
|
|
||
| find_package(snmalloc CONFIG REQUIRED) | ||
| target_link_libraries(<your-target> PRIVATE snmalloc::snmalloc) | ||
|
|
||
| If installed with the "static-shim" feature, a compiled static library is also | ||
| available that replaces malloc/free with a "sn_" prefix (e.g. sn_malloc, sn_free): | ||
|
|
||
| target_link_libraries(<your-target> PRIVATE snmalloc::snmallocshim-static) | ||
|
|
||
| On non-Windows, the "static-shim" feature also installs shared library shims | ||
| (snmalloc::snmallocshim, snmalloc::snmallocshim-checks, snmalloc::snmalloc-minimal) | ||
| that can be used for LD_PRELOAD-based allocator replacement. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "name": "snmalloc", | ||
| "version-semver": "0.7.4", | ||
| "description": "A high-performance, message passing based allocator", | ||
| "homepage": "https://github.com/microsoft/snmalloc", | ||
| "license": "MIT", | ||
| "dependencies": [ | ||
| { | ||
| "name": "vcpkg-cmake", | ||
| "host": true | ||
| }, | ||
| { | ||
| "name": "vcpkg-cmake-config", | ||
| "host": true | ||
| } | ||
| ], | ||
| "features": { | ||
| "static-shim": { | ||
| "description": "Build and install snmallocshim-static, a compiled static library that exports malloc/free with a configurable symbol prefix (default: sn_)" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| cmake_minimum_required(VERSION 3.16) | ||
| project(snmalloc-vcpkg-test CXX) | ||
|
|
||
| set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
| set(CMAKE_VERBOSE_MAKEFILE ON) | ||
|
|
||
| enable_testing() | ||
|
|
||
| find_package(snmalloc CONFIG REQUIRED) | ||
|
|
||
| add_executable(test-header-only test_header_only.cpp) | ||
| target_link_libraries(test-header-only PRIVATE snmalloc::snmalloc) | ||
| add_test(NAME header-only COMMAND test-header-only) | ||
|
|
||
| if(TARGET snmalloc::snmallocshim-static) | ||
| add_executable(test-static-shim test_static_shim.cpp) | ||
| target_link_libraries(test-static-shim PRIVATE snmalloc::snmallocshim-static) | ||
| add_test(NAME static-shim COMMAND test-static-shim) | ||
| endif() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /** | ||
| * Minimal vcpkg integration test for the snmalloc header-only target. | ||
| * Verifies that find_package(snmalloc) + snmalloc::snmalloc works. | ||
| */ | ||
| #include <snmalloc/snmalloc.h> | ||
|
|
||
| int main() | ||
| { | ||
| void* p = snmalloc::libc::malloc(64); | ||
| if (p == nullptr) | ||
| return 1; | ||
| snmalloc::libc::free(p); | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * Minimal vcpkg integration test for the snmallocshim-static target. | ||
| * Verifies that find_package(snmalloc) + snmalloc::snmallocshim-static works. | ||
| * The static shim replaces malloc/free with the snmalloc implementation. | ||
| */ | ||
| #include <stdlib.h> | ||
|
|
||
| extern "C" | ||
| { | ||
| void *sn_malloc(size_t); | ||
| void sn_free(void *); | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| void* p = sn_malloc(64); | ||
| if (p == nullptr) | ||
| return 1; | ||
| sn_free(p); | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "name": "snmalloc", | ||
| "version-semver": "0.7.4", | ||
| "description": "A high-performance, message passing based allocator", | ||
| "homepage": "https://github.com/microsoft/snmalloc", | ||
| "license": "MIT", | ||
| "features": { | ||
| "static-shim": { | ||
| "description": "Build and install snmallocshim-static, a compiled static library that exports malloc/free with a configurable symbol prefix (default: sn_)" | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the bit that has been wrong as an install target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.