-
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 6 commits
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,121 @@ | |
| <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)' == '' AND Exists('$(ProgramW6432)\WSL\wslc.exe')">$(ProgramW6432)\WSL\wslc.exe</WslcCliPath> | ||
| <WslcCliPath Condition="'$(WslcCliPath)' == ''">wslc</WslcCliPath> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- Default metadata for WslcImage items --> | ||
| <ItemDefinitionGroup> | ||
| <WslcImage> | ||
| <Tag>latest</Tag> | ||
| <OutputDir>$(WslcImageOutputDir)</OutputDir> | ||
| </WslcImage> | ||
| </ItemDefinitionGroup> | ||
|
|
||
| <!-- Auto-detection fallback: if no WslcImage declared, detect container/Dockerfile --> | ||
|
Contributor
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 think we should do that. The developer is not required to build their container images here.
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. Sure, this is just fallback, will remove it later. |
||
| <ItemGroup Condition="'@(WslcImage)' == '' AND Exists('$(ProjectDir)container\Dockerfile')"> | ||
| <WslcImage Include="$(MSBuildProjectName)" | ||
| Dockerfile="$(ProjectDir)container\Dockerfile" | ||
| Context="$(ProjectDir)container" | ||
| Sources="$(ProjectDir)container" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup Condition="'@(WslcImage)' == '' AND Exists('$(ProjectDir)docker\Dockerfile')"> | ||
| <WslcImage Include="$(MSBuildProjectName)" | ||
| Dockerfile="$(ProjectDir)docker\Dockerfile" | ||
| Context="$(ProjectDir)docker" | ||
| Sources="$(ProjectDir)docker" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- 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);_WslcSourceDir=%(WslcImage.Sources);_WslcOutput=%(WslcImage.OutputDir)" /> | ||
shuaiyuanxx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </Target> | ||
|
Comment on lines
+69
to
+72
|
||
|
|
||
| <!-- | ||
| Collect source files for incremental check. | ||
| Wildcards are expanded here in ItemGroup Include (not in Inputs attribute or MSBuild task Properties, | ||
| where they get escaped). Sources can be semicolon separated directory paths; | ||
| each is expanded with **\* to collect all files recursively. | ||
| --> | ||
| <Target Name="_WslcCollectSources" BeforeTargets="_WslcBuildSingleImage"> | ||
| <ItemGroup> | ||
| <_WslcSourceDirs Include="$(_WslcSourceDir.Split(';'))" /> | ||
| <_WslcSourceFiles Include="$(_WslcDockerfile)" /> | ||
| <_WslcSourceFiles Include="%(_WslcSourceDirs.Identity)\**\*" Condition="'%(_WslcSourceDirs.Identity)' != ''" /> | ||
| </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)" /> | ||
|
|
||
| <Message Importance="high" | ||
| Text="WSLC: Building image '$(_WslcName):$(_WslcTag)'..." /> | ||
|
|
||
| <Exec Command=""$(WslcCliPath)" image build -t "$(_WslcName):$(_WslcTag)" -f "$(_WslcDockerfile)" "$(_WslcContext)"" | ||
| ConsoleToMSBuild="true" /> | ||
|
|
||
| <!-- | ||
| Uncomment when wslc image save is available: | ||
| <MakeDir Directories="$(_WslcOutput)" /> | ||
| <Exec Command=""$(WslcCliPath)" image save -o "$(_WslcOutput)\$(_WslcName).tar" "$(_WslcName):$(_WslcTag)"" | ||
| ConsoleToMSBuild="true" /> | ||
| --> | ||
|
|
||
| <Touch Files="$(IntDir)wslc_$(_WslcName).marker" AlwaysCreate="true" /> | ||
|
|
||
| <Message Importance="high" | ||
| Text="WSLC: [$(_WslcName)] Image '$(_WslcName):$(_WslcTag)' built successfully." /> | ||
| </Target> | ||
|
|
||
| <!-- Clean container artifacts --> | ||
| <Target Name="WslcClean" | ||
| AfterTargets="Clean" | ||
| Condition="'@(WslcImage)' != ''"> | ||
|
|
||
| <Delete Files="$(IntDir)wslc_%(WslcImage.Identity).marker" /> | ||
| <!-- | ||
| Uncomment when wslc image save is available: | ||
| <Delete Files="%(WslcImage.OutputDir)\%(WslcImage.Identity).tar" /> | ||
| --> | ||
| </Target> | ||
|
|
||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # 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 | ||
| # ) | ||
| # | ||
| # # With explicit image registry/name (IMAGE defaults to NAME if omitted): | ||
| # wslc_add_image( | ||
| # NAME my-server | ||
| # IMAGE ghcr.io/myorg/my-server | ||
| # TAG v1.2.3 | ||
| # DOCKERFILE container/Dockerfile | ||
| # CONTEXT container/ | ||
| # ) | ||
|
|
||
| function(wslc_add_image) | ||
| cmake_parse_arguments( | ||
| PARSE_ARGV 0 ARG | ||
| "" # options (none) | ||
| "NAME;IMAGE;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_IMAGE) | ||
| set(ARG_IMAGE "${ARG_NAME}") | ||
| endif() | ||
| if(NOT ARG_TAG) | ||
| set(ARG_TAG "latest") | ||
| endif() | ||
| if(NOT ARG_OUTPUT) | ||
| set(ARG_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}") | ||
| endif() | ||
|
|
||
| # Find wslc CLI | ||
| if(NOT WSLC_CLI_PATH) | ||
| find_program(WSLC_CLI_PATH wslc PATHS "$ENV{ProgramW6432}/WSL" "$ENV{ProgramFiles}/WSL") | ||
| if(NOT WSLC_CLI_PATH) | ||
| message(FATAL_ERROR "wslc CLI not found. Install WSL by running: wsl --install --no-distribution") | ||
| endif() | ||
| endif() | ||
|
|
||
| set(_image_ref "${ARG_IMAGE}:${ARG_TAG}") | ||
| set(_marker "${CMAKE_CURRENT_BINARY_DIR}/wslc_${ARG_NAME}.marker") | ||
| # Uncomment when wslc image save is available: | ||
| # set(_tar_output "${ARG_OUTPUT}/${ARG_NAME}.tar") | ||
|
|
||
| # Resolve source globs to file lists | ||
| file(GLOB_RECURSE _resolved_sources CONFIGURE_DEPENDS ${ARG_SOURCES}) | ||
|
|
||
| add_custom_command( | ||
| OUTPUT "${_marker}" | ||
| COMMAND "${WSLC_CLI_PATH}" image build -t "${_image_ref}" -f "${ARG_DOCKERFILE}" "${ARG_CONTEXT}" | ||
| # Uncomment when wslc image save is available: | ||
| # COMMAND ${CMAKE_COMMAND} -E make_directory "${ARG_OUTPUT}" | ||
| # COMMAND "${WSLC_CLI_PATH}" image save -o "${_tar_output}" "${_image_ref}" | ||
| COMMAND ${CMAKE_COMMAND} -E touch "${_marker}" | ||
| DEPENDS ${_resolved_sources} "${ARG_DOCKERFILE}" | ||
| COMMENT "WSLC: Building image '${_image_ref}'..." | ||
| VERBATIM | ||
| ) | ||
|
|
||
| add_custom_target(wslc_image_${ARG_NAME} ALL | ||
| DEPENDS "${_marker}" | ||
| ) | ||
| endfunction() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <Import Project="$(MSBuildThisFileDirectory)..\build\Microsoft.WSL.Containers.common.targets" /> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <Import Project="$(MSBuildThisFileDirectory)..\..\build\native\Microsoft.WSL.Containers.targets" /> | ||
| </Project> |
Uh oh!
There was an error while loading. Please reload this page.