Skip to content

Commit

Permalink
windows/msvc: Improve some build aspects.
Browse files Browse the repository at this point in the history
Introduce a PyLibSource variable, akin to PyExtModSource, for specifying
source files from the lib/ directory: these do not have to be included
in qstr generation.

Fix the command used for preprocessing (for qstr scanning) so that it
properly supports preprocessor definitions like /Dval="quotedvalue"
by turning that into /Dval=\"quotedvalue\".

For consistency with the Makefile/CMake-based builds add the ability
to update git submodules.

Signed-off-by: stijn <stijn@ignitron.net>
  • Loading branch information
stinos committed Mar 25, 2024
1 parent bf329c6 commit de47800
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ports_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Build mpy-cross.exe
run: msbuild mpy-cross\mpy-cross.vcxproj -maxcpucount -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.platform }}
- name: Update submodules
run: git submodule update --init lib/micropython-lib
run: msbuild ports\windows\micropython.vcxproj -target:UpdateSubmodules -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.platform }} -property:PyVariant=${{ matrix.variant }}
- name: Build micropython.exe
run: msbuild ports\windows\micropython.vcxproj -maxcpucount -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.platform }} -property:PyVariant=${{ matrix.variant }}
- name: Get micropython.exe path
Expand Down
1 change: 1 addition & 0 deletions ports/windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ In the IDE, open `micropython-cross.vcxproj` and `micropython.vcxproj` and build
To build from the command line:

msbuild ../../mpy-cross/mpy-cross.vcxproj
msbuild micropython.vcxproj /t:UpdateSubmodules
msbuild micropython.vcxproj

__Variants__
Expand Down
3 changes: 2 additions & 1 deletion ports/windows/micropython.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<ItemGroup>
<ClCompile Include="@(PyCoreSource)" />
<ClCompile Include="@(PyExtModSource)" />
<ClCompile Include="@(PyLibSource)" />
<ClCompile Include="$(PyBaseDir)shared\readline\*.c" />
<ClCompile Include="$(PyBaseDir)shared\runtime\gchelper_generic.c" />
<ClCompile Include="$(PyBaseDir)ports\windows\*.c" />
Expand All @@ -108,7 +109,7 @@
</ItemGroup>
<Import Project="msvc/genhdr.targets" />
<Import Project="$(CustomPropsFile)" Condition="exists('$(CustomPropsFile)')" />
<Target Name="GenerateMicroPythonSources" BeforeTargets="BuildGenerateSources" DependsOnTargets="GenerateHeaders;FreezeModules">
<Target Name="GenerateMicroPythonSources" BeforeTargets="BuildGenerateSources" DependsOnTargets="UpdateSubmodulesIfInIDE;GenerateHeaders;FreezeModules">
</Target>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
12 changes: 12 additions & 0 deletions ports/windows/msvc/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,16 @@
<Copy SourceFiles="%(PyOutputFiles.Identity)" DestinationFiles="%(PyOutputFiles.Destination)"/>
<WriteLinesToFile File="$(TLogLocation)$(ProjectName).write.u.tlog" Lines="$(PyFileCopyCookie);@(PyOutputFiles->'%(Destination)')" Overwrite="True"/>
</Target>

<Target Name="UpdateSubmodules" Condition="@(PySubmodules) != ''">
<Message Text="Updating submodules: @(PySubmodules)"/>
<Exec Command="git submodule sync $(PyBaseDir)%(PySubmodules.Identity)"/>
<Exec Command="git submodule update --init $(PyBaseDir)%(PySubmodules.Identity)"/>
</Target>

<!-- Within an IDE it's usually not simple to manually select Targets to build so allow doing
this automatically to be able to build from scratch. Still make this optional though because it isn't exactly fast. -->
<Target Name="UpdateSubmodulesIfInIDE" DependsOnTargets="UpdateSubmodules"
Condition="'$(BuildingInsideVisualStudio)' == 'True' And '$(PySkipModuleUpdate)' != 'True'">
</Target>
</Project>
6 changes: 4 additions & 2 deletions ports/windows/msvc/genhdr.targets
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ using(var outFile = System.IO.File.CreateText(OutputFile)) {
<ItemGroup>
<PyIncDirs Include="$(PyIncDirs)"/>
<PreProcDefs Include="%(ClCompile.PreProcessorDefinitions);NO_QSTR"/>
<PyQstrSourceFiles Include="@(ClCompile)" Exclude="$(PyBuildDir)\frozen_content.c">
<PyQstrSourceFiles Include="@(ClCompile)" Exclude="$(PyBuildDir)\frozen_content.c;@(PyLibSource)">
<Changed>False</Changed>
<OutFile>$([System.String]::new('%(FullPath)').Replace('$(PyBaseDir)', '$(DestDir)qstr\'))</OutFile>
</PyQstrSourceFiles>
Expand All @@ -82,7 +82,9 @@ using(var outFile = System.IO.File.CreateText(OutputFile)) {
</QstrDependencies>
</ItemGroup>
<PropertyGroup>
<PyPreProcCommand>$(PyClTool) /nologo /I@(PyIncDirs, ' /I') /D@(PreProcDefs, ' /D')</PyPreProcCommand>
<!--Command is going to run via shell so need to escape quotes. -->
<UnescapedPreProcDefs>/D@(PreProcDefs, ' /D')</UnescapedPreProcDefs>
<PyPreProcCommand>$(PyClTool) /nologo /I@(PyIncDirs, ' /I') $([System.String]::Copy('$(UnescapedPreProcDefs)').Replace('"','\"'))</PyPreProcCommand>
<ForceQstrRebuild>@(QstrDependencies->AnyHaveMetadataValue('Changed', 'True'))</ForceQstrRebuild>
<RunPreProcConcat>@(PyQstrSourceFiles->AnyHaveMetadataValue('Changed', 'True'))</RunPreProcConcat>
</PropertyGroup>
Expand Down

0 comments on commit de47800

Please sign in to comment.