-
Notifications
You must be signed in to change notification settings - Fork 1.7k
draft pr for build UX #14551
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: feature/wsl-for-apps
Are you sure you want to change the base?
draft pr for build UX #14551
Changes from 1 commit
635f324
208e9ec
af041e4
e5f990d
e00d4ed
16dbf44
f5c1c75
14e0dbf
9554539
d3dc0e6
1c29367
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 |
|---|---|---|
|
|
@@ -7,4 +7,99 @@ | |
| <ItemGroup> | ||
| <ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)..\runtimes\win-$(WSLCSDK_Platform)\wslcsdk.dll" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- ================================================================== --> | ||
| <!-- Container Image Build Targets --> | ||
| <!-- ================================================================== --> | ||
|
|
||
| <!-- Default properties --> | ||
| <PropertyGroup> | ||
| <WslcImageOutputDir Condition="'$(WslcImageOutputDir)' == ''">$(OutDir)</WslcImageOutputDir> | ||
| <WslcCliPath Condition="'$(WslcCliPath)' == ''">wslc</WslcCliPath> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- Default metadata for WslcImage items --> | ||
| <ItemDefinitionGroup> | ||
| <WslcImage> | ||
| <Tag>latest</Tag> | ||
| <Output>$(WslcImageOutputDir)</Output> | ||
| </WslcImage> | ||
| </ItemDefinitionGroup> | ||
|
|
||
| <!-- Check that wslc CLI is installed --> | ||
| <Target Name="WslcCheckDependencies" | ||
| BeforeTargets="WslcBuildAllImages" | ||
| Condition="'@(WslcImage)' != ''"> | ||
|
|
||
| <Exec Command="$(WslcCliPath) --version" | ||
| IgnoreExitCode="true" | ||
| ConsoleToMSBuild="true" | ||
| StandardOutputImportance="low" | ||
| StandardErrorImportance="low"> | ||
| <Output TaskParameter="ExitCode" PropertyName="_WslcExitCode" /> | ||
| </Exec> | ||
|
|
||
| <Error Condition="'$(_WslcExitCode)' != '0'" | ||
| Code="WSLC0001" | ||
| Text="The WSLC runtime was not found. Install WSL by running: wsl --install --no-distribution" /> | ||
shuaiyuanxx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </Target> | ||
|
|
||
| <!-- Outer target: dispatch each WslcImage to inner target via MSBuild task --> | ||
| <Target Name="WslcBuildAllImages" | ||
| AfterTargets="Build" | ||
| DependsOnTargets="WslcCheckDependencies" | ||
| Condition="'@(WslcImage)' != ''"> | ||
|
Comment on lines
+64
to
+67
|
||
|
|
||
| <MSBuild Projects="$(MSBuildProjectFullPath)" | ||
| Targets="_WslcBuildSingleImage" | ||
| Properties="Configuration=$(Configuration);Platform=$(Platform);_WslcName=%(WslcImage.Identity);_WslcTag=%(WslcImage.Tag);_WslcDockerfile=%(WslcImage.Dockerfile);_WslcContext=%(WslcImage.Context);_WslcSources=%(WslcImage.Sources);_WslcOutput=%(WslcImage.Output)" /> | ||
| </Target> | ||
|
Comment on lines
+69
to
+72
|
||
|
|
||
| <!-- Collect source files for incremental check (wildcards only expand in ItemGroup Include) --> | ||
| <Target Name="_WslcCollectSources" BeforeTargets="_WslcBuildSingleImage"> | ||
| <ItemGroup> | ||
| <_WslcSourceFiles Include="$(_WslcDockerfile);$(_WslcSources)" /> | ||
shuaiyuanxx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </ItemGroup> | ||
| </Target> | ||
|
|
||
| <!-- Inner target: build a single image with incremental check --> | ||
| <Target Name="_WslcBuildSingleImage" | ||
| DependsOnTargets="_WslcCollectSources" | ||
| Inputs="@(_WslcSourceFiles)" | ||
| Outputs="$(IntDir)wslc_$(_WslcName).marker"> | ||
|
|
||
|
Comment on lines
+91
to
+93
|
||
| <MakeDir Directories="$(IntDir);$(_WslcOutput)" /> | ||
|
|
||
| <Message Importance="high" | ||
| Text="WSLC: Building image '$(_WslcName):$(_WslcTag)'..." /> | ||
|
|
||
| <Exec Command="$(WslcCliPath) image build -t "$(_WslcName):$(_WslcTag)" -f "$(_WslcDockerfile)" "$(_WslcContext)"" | ||
| ConsoleToMSBuild="true" /> | ||
|
|
||
| <Message Importance="high" | ||
| Text="WSLC: Saving image '$(_WslcName):$(_WslcTag)' to $(_WslcOutput)\$(_WslcName).tar..." /> | ||
|
|
||
| <Exec Command="$(WslcCliPath) image save "$(_WslcName):$(_WslcTag)" -o "$(_WslcOutput)\$(_WslcName).tar"" | ||
| ConsoleToMSBuild="true" /> | ||
|
|
||
| <!-- Save image ID for efficient check-then-load at runtime --> | ||
| <Exec Command="$(WslcCliPath) image inspect "$(_WslcName):$(_WslcTag)" --format {{.Id}} > "$(_WslcOutput)\$(_WslcName).id"" | ||
| IgnoreStandardErrorWarningFormat="true" /> | ||
|
|
||
| <Touch Files="$(IntDir)wslc_$(_WslcName).marker" AlwaysCreate="true" /> | ||
|
|
||
| <Message Importance="high" | ||
| Text="WSLC: [$(_WslcName)] Image built and saved successfully." /> | ||
| </Target> | ||
|
|
||
| <!-- Clean container artifacts --> | ||
| <Target Name="WslcClean" | ||
| AfterTargets="Clean" | ||
| Condition="'@(WslcImage)' != ''"> | ||
|
|
||
| <Delete Files="%(WslcImage.Output)\%(WslcImage.Identity).tar" /> | ||
| <Delete Files="%(WslcImage.Output)\%(WslcImage.Identity).id" /> | ||
| <Delete Files="$(IntDir)wslc_%(WslcImage.Identity).marker" /> | ||
| </Target> | ||
|
|
||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # wslcConfig.cmake - Container image build support for CMake | ||
| # | ||
| # Provides the wslc_add_image() function for declaring container image | ||
| # build targets with incremental rebuild support. | ||
| # | ||
| # Usage: | ||
| # list(APPEND CMAKE_MODULE_PATH "<nuget>/build/cmake") | ||
| # find_package(wslc REQUIRED) | ||
| # | ||
| # wslc_add_image( | ||
| # NAME my-server | ||
| # DOCKERFILE container/Dockerfile | ||
| # CONTEXT container/ | ||
| # SOURCES container/src/*.cpp container/src/*.h | ||
| # TAG latest | ||
| # OUTPUT ${CMAKE_BINARY_DIR}/images | ||
| # ) | ||
|
|
||
| function(wslc_add_image) | ||
| cmake_parse_arguments( | ||
| PARSE_ARGV 0 ARG | ||
| "" # options (none) | ||
| "NAME;TAG;DOCKERFILE;CONTEXT;OUTPUT" # one-value keywords | ||
| "SOURCES" # multi-value keywords | ||
| ) | ||
|
|
||
| # Validate required arguments | ||
| if(NOT ARG_NAME) | ||
| message(FATAL_ERROR "wslc_add_image: NAME is required") | ||
| endif() | ||
| if(NOT ARG_DOCKERFILE) | ||
| message(FATAL_ERROR "wslc_add_image: DOCKERFILE is required") | ||
| endif() | ||
| if(NOT ARG_CONTEXT) | ||
| message(FATAL_ERROR "wslc_add_image: CONTEXT is required") | ||
| endif() | ||
|
|
||
| # Defaults | ||
| if(NOT ARG_TAG) | ||
| set(ARG_TAG "latest") | ||
| endif() | ||
| if(NOT ARG_OUTPUT) | ||
| set(ARG_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}") | ||
| endif() | ||
|
|
||
| set(_image_ref "${ARG_NAME}:${ARG_TAG}") | ||
| set(_tar_output "${ARG_OUTPUT}/${ARG_NAME}.tar") | ||
| set(_id_output "${ARG_OUTPUT}/${ARG_NAME}.id") | ||
| set(_marker "${CMAKE_CURRENT_BINARY_DIR}/wslc_${ARG_NAME}.marker") | ||
|
|
||
| # Resolve source globs to file lists | ||
| file(GLOB_RECURSE _resolved_sources ${ARG_SOURCES}) | ||
shuaiyuanxx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| add_custom_command( | ||
| OUTPUT "${_marker}" | ||
| COMMAND wslc image build -t "${_image_ref}" -f "${ARG_DOCKERFILE}" "${ARG_CONTEXT}" | ||
| COMMAND wslc image save "${_image_ref}" -o "${_tar_output}" | ||
| COMMAND ${CMAKE_COMMAND} -E touch "${_marker}" | ||
shuaiyuanxx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| DEPENDS ${_resolved_sources} "${ARG_DOCKERFILE}" | ||
shuaiyuanxx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| COMMENT "WSLC: Building image '${_image_ref}'..." | ||
| VERBATIM | ||
| ) | ||
|
|
||
| add_custom_target(wslc_image_${ARG_NAME} ALL | ||
| DEPENDS "${_marker}" | ||
| ) | ||
| endfunction() | ||
Uh oh!
There was an error while loading. Please reload this page.