Make it easier to make a local WSLC SDK NuGet (#40623)

Flor Chacón committed May 22, 2026 at 11:08 UTC 07c7dbd9b53c1e7e3382e55851636133f193276d
5 files changed +51 -12
UserConfig.cmake.sample
+3
@@ -39,6 +39,9 @@ endif()
39 # # Uncomment to build the C# WSLC sdk
40 # set(WSL_BUILD_SDKCS true)
41
42 +# # Uncomment to configure the WSLC SDK NuGet to only target the current platform
43 +# set(WSL_NUGET_SINGLE_PLATFORM true)
44 +
45 # # Uncomment to generate a "thin" MSI package which builds and installs faster
46 # set(WSL_BUILD_THIN_PACKAGE true)
47
nuget/CMakeLists.txt
+40 -1
@@ -1,10 +1,49 @@
1 set(NUGET_PACKAGES Microsoft.WSL.PluginApi.nuspec Microsoft.WSL.Containers.nuspec)
2 set(WSL_NUGET_TARGET_FRAMEWORK "net8.0-windows10.0.19041.0")
3
4 -# generate vars with native paths since nuget won't accept unix path separators
4 +# Generate vars with native paths since nuget won't accept unix path separators.
5 cmake_path(NATIVE_PATH CMAKE_SOURCE_DIR CMAKE_SOURCE_DIR_NATIVE)
6 cmake_path(NATIVE_PATH CMAKE_BINARY_DIR CMAKE_BINARY_DIR_NATIVE)
7
8 +# For the WSLC SDK, we allow packaging only one platform or not including the C# projection
9 +# to make it easier to build a local package for development.
10 +# The list files needed in each case are included conditionally from a nuspec fragment.
11 +
12 +# Read a nuspec fragment .in file and expand its CMake variables into the named variable.
13 +# Pass PLATFORM <arch> to bind the ${PLATFORM} placeholder in the fragment.
14 +function(read_nuspec_fragment var path)
15 + cmake_parse_arguments(ARG "" "PLATFORM" "" ${ARGN})
16 + if(DEFINED ARG_PLATFORM)
17 + set(PLATFORM "${ARG_PLATFORM}")
18 + endif()
19 + file(READ "${path}" content)
20 + string(CONFIGURE "${content}" content)
21 + set(${var} "${content}" PARENT_SCOPE)
22 +endfunction()
23 +
24 +# C# SDK wrapper DLL — AnyCPU, produced for any TARGET_PLATFORM.
25 +# Only include it when the C# SDK was actually built (WSL_BUILD_SDKCS).
26 +if(WSL_BUILD_SDKCS)
27 + read_nuspec_fragment(NUGET_SDKCS_FILE "${CMAKE_CURRENT_LIST_DIR}/fragments/wslc-cs.nuspec.in")
28 +else()
29 + set(NUGET_SDKCS_FILE "")
30 +endif()
31 +
32 +# x64 native runtime — include when this is an x64 build, or for a multi-arch package.
33 +if(TARGET_PLATFORM STREQUAL "x64" OR NOT WSL_NUGET_SINGLE_PLATFORM)
34 + read_nuspec_fragment(NUGET_X64_RUNTIMES "${CMAKE_CURRENT_LIST_DIR}/fragments/wslc-runtime.nuspec.in" PLATFORM x64)
35 +else()
36 + set(NUGET_X64_RUNTIMES "")
37 +endif()
38 +
39 +# arm64 native runtime — include when this is an arm64 build, or for a multi-arch package.
40 +if(TARGET_PLATFORM STREQUAL "arm64" OR NOT WSL_NUGET_SINGLE_PLATFORM)
41 + read_nuspec_fragment(NUGET_ARM64_RUNTIMES "${CMAKE_CURRENT_LIST_DIR}/fragments/wslc-runtime.nuspec.in" PLATFORM arm64)
42 +else()
43 + set(NUGET_ARM64_RUNTIMES "")
44 +endif()
45 +
46 +# Generate the .nuspec files
47 foreach(PACKAGE ${NUGET_PACKAGES})
48 configure_file("${CMAKE_CURRENT_LIST_DIR}/${PACKAGE}.in" "${CMAKE_BINARY_DIR}/${PACKAGE}")
49 endforeach()
\ No newline at end of file
nuget/Microsoft.WSL.Containers.nuspec.in
+4 -11
@@ -17,17 +17,10 @@
17 </metadata>
18 <files>
19 <file src="${CMAKE_SOURCE_DIR_NATIVE}\src\windows\WslcSDK\wslcsdk.h" target="include"/>
20 -
21 - <file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\x64\${CMAKE_BUILD_TYPE}\wslcsdkcs.dll" target="lib\${WSL_NUGET_TARGET_FRAMEWORK}\"/>
22 - <file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\x64\${CMAKE_BUILD_TYPE}\Microsoft.WSL.Containers.winmd" target="winmd\Microsoft.WSL.Containers.winmd"/>
23 -
24 - <file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\x64\${CMAKE_BUILD_TYPE}\wslcsdk.lib" target="runtimes\win-x64\"/>
25 - <file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\x64\${CMAKE_BUILD_TYPE}\wslcsdk.dll" target="runtimes\win-x64\native\"/>
26 -
27 - <file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\arm64\${CMAKE_BUILD_TYPE}\wslcsdk.lib" target="runtimes\win-arm64\"/>
28 - <file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\arm64\${CMAKE_BUILD_TYPE}\wslcsdk.dll" target="runtimes\win-arm64\native\"/>
29 -
20 + <file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\${TARGET_PLATFORM}\${CMAKE_BUILD_TYPE}\Microsoft.WSL.Containers.winmd" target="winmd\Microsoft.WSL.Containers.winmd"/>
21 <file src="${CMAKE_SOURCE_DIR_NATIVE}\nuget\Microsoft.WSL.Containers\**" exclude="**\net\**"/>
31 - <file src="${CMAKE_SOURCE_DIR_NATIVE}\nuget\Microsoft.WSL.Containers\build\net\**" target="build\${WSL_NUGET_TARGET_FRAMEWORK}"/>
22 +${NUGET_SDKCS_FILE}
23 +${NUGET_X64_RUNTIMES}
24 +${NUGET_ARM64_RUNTIMES}
25 </files>
26 </package>
nuget/fragments/wslc-cs.nuspec.in new
+2
@@ -0,0 +1,2 @@
1 + <file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\${TARGET_PLATFORM}\${CMAKE_BUILD_TYPE}\wslcsdkcs.dll" target="lib\${WSL_NUGET_TARGET_FRAMEWORK}\"/>
2 + <file src="${CMAKE_SOURCE_DIR_NATIVE}\nuget\Microsoft.WSL.Containers\build\net\**" target="build\${WSL_NUGET_TARGET_FRAMEWORK}"/>
nuget/fragments/wslc-runtime.nuspec.in new
+2
@@ -0,0 +1,2 @@
1 + <file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\${PLATFORM}\${CMAKE_BUILD_TYPE}\wslcsdk.lib" target="runtimes\win-${PLATFORM}\"/>
2 + <file src="${CMAKE_SOURCE_DIR_NATIVE}\bin\${PLATFORM}\${CMAKE_BUILD_TYPE}\wslcsdk.dll" target="runtimes\win-${PLATFORM}\native\"/>