Skip to content

windows: msbuild variant support #8032

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions ports/windows/.appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ skip_tags: true
environment:
# Python version used
MICROPY_CPYTHON3: c:/python38/python.exe
# The variants.
matrix:
- PyVariant: dev
- PyVariant: standard

init:
# Set build version number to commit to be travis-like
Expand All @@ -18,6 +22,12 @@ platform:
- x86
- x64

matrix:
# One debug build is enough.
exclude:
- configuration: Debug
PyVariant: dev

before_build:
- ps: |
@"
Expand All @@ -36,6 +46,7 @@ build:

test_script:
- ps: |
$env:MICROPY_MICROPYTHON=(msbuild ports\windows\micropython.vcxproj /nologo /v:m /t:ShowTargetPath).Trim()
cd (Join-Path $env:APPVEYOR_BUILD_FOLDER 'tests')
& $env:MICROPY_CPYTHON3 run-tests.py
if ($LASTEXITCODE -ne 0) {
Expand All @@ -58,7 +69,7 @@ after_test:
$env:MSYSTEM = if ($platform -eq 'x86') {'MINGW32'} else {'MINGW64'}
$env:CHERE_INVOKING = 'enabled_from_arguments'
cd (Join-Path $env:APPVEYOR_BUILD_FOLDER 'ports/windows')
C:\msys64\usr\bin\bash.exe -l -c "make -B -j4 V=1"
C:\msys64\usr\bin\bash.exe -l -c "make -B -j4 V=1 VARIANT=$($env:PyVariant)"
if ($LASTEXITCODE -ne 0) {
throw "$env:MSYSTEM build exited with code $LASTEXITCODE"
}
Expand All @@ -67,17 +78,8 @@ after_test:
if ($LASTEXITCODE -ne 0) {
throw "$env:MSYSTEM mpy_cross build exited with code $LASTEXITCODE"
}
cd (Join-Path $env:APPVEYOR_BUILD_FOLDER 'tests')
$testArgs = @('run-tests.py')
foreach ($skipTest in @('math_fun', 'float2int_double', 'float_parse', 'math_domain_special')) {
$testArgs = $testArgs + '-e' + $skipTest
}
& $env:MICROPY_CPYTHON3 $testArgs
if ($LASTEXITCODE -ne 0) {
& $env:MICROPY_CPYTHON3 run-tests.py --print-failures
throw "Test failure"
}
& $env:MICROPY_CPYTHON3 ($testArgs + @('--via-mpy', '-d', 'basics', 'float', 'micropython'))
cd (Join-Path $env:APPVEYOR_BUILD_FOLDER 'ports/windows')
C:\msys64\usr\bin\bash.exe -l -c "make V=1 test_full VARIANT=$($env:PyVariant)"
if ($LASTEXITCODE -ne 0) {
& $env:MICROPY_CPYTHON3 run-tests.py --print-failures
throw "Test failure"
Expand Down
36 changes: 33 additions & 3 deletions ports/windows/Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
# Select the variant to build for.
VARIANT ?= standard

# If the build directory is not given, make it reflect the variant name.
BUILD ?= build-$(VARIANT)

VARIANT_DIR ?= variants/$(VARIANT)
ifeq ($(wildcard $(VARIANT_DIR)/.),)
$(error Invalid VARIANT specified: $(VARIANT_DIR))
endif

include ../../py/mkenv.mk
-include mpconfigport.mk
include $(VARIANT_DIR)/mpconfigvariant.mk

FROZEN_MANIFEST ?= variants/manifest.py

# define main target
PROG = micropython
# Define main target
# This should be configured by the mpconfigvariant.mk
PROG ?= micropython

# qstr definitions (must come before including py.mk)
QSTR_DEFS = ../unix/qstrdefsport.h
QSTR_GLOBAL_DEPENDENCIES = $(VARIANT_DIR)/mpconfigvariant.h

# include py core make definitions
include $(TOP)/py/py.mk

INC += -I.
INC += -I$(TOP)
INC += -I$(BUILD)
INC += -I$(VARIANT_DIR)

# compiler settings
CFLAGS = $(INC) -Wall -Wpointer-arith -Wdouble-promotion -Werror -std=gnu99 -DUNIX -D__USE_MINGW_ANSI_STDIO=1 $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
Expand Down Expand Up @@ -41,7 +58,8 @@ SRC_C = \
init.c \
sleep.c \
fmode.c \
$(SRC_MOD)
$(SRC_MOD) \
$(wildcard $(VARIANT_DIR)/*.c)

OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))

Expand All @@ -63,3 +81,15 @@ CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool -DMICROPY_MODULE_F
endif

include $(TOP)/py/mkrules.mk

.PHONY: test test_full

RUN_TESTS_SKIP += -e math_fun -e float2int_double -e float_parse -e math_domain_special

test: $(PROG) $(TOP)/tests/run-tests.py
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) $(PYTHON) ./run-tests.py $(RUN_TESTS_SKIP)

test_full: test
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) $(PYTHON) ./run-tests.py --via-mpy $(RUN_TESTS_MPY_CROSS_FLAGS) $(RUN_TESTS_SKIP) -d basics float micropython
20 changes: 20 additions & 0 deletions ports/windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ To build from the command line:
msbuild ../../mpy-cross/mpy-cross.vcxproj
msbuild micropython.vcxproj

__Variants__

The msvc port supports variants (like the unix and windows mingw ports) and the one which gets built is
controlled by the `PyVariant` msbuild property. It defaults to `standard`.
The other variants can be built like:

msbuild micropython.vcxproj /p:PyVariant=dev

Or by adding a file [Directory.build.props](https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build#directorybuildprops-and-directorybuildtargets) in this directory or a parent directory:

```xml
<Project>
<PropertyGroup>
<PyVariant>dev</PyVariant>
</PropertyGroup>
</Project>
```

See [paths.props](msvc/paths.props) for other related variables like build and variant directories.

__Stack usage__

The msvc compiler is quite stack-hungry which might result in a "maximum recursion depth exceeded"
Expand Down
2 changes: 2 additions & 0 deletions ports/windows/micropython.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
</ImportGroup>
<PropertyGroup Label="UserMacros">
<CustomPropsFile Condition="'$(CustomPropsFile)'==''">msvc/user.props</CustomPropsFile>
<TargetName>$(PyProg)</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile />
Expand Down Expand Up @@ -95,6 +96,7 @@
<ClCompile Include="$(PyBaseDir)ports\unix\modos.c"/>
<ClCompile Include="$(PyBaseDir)ports\unix\modtime.c"/>
<ClCompile Include="$(PyBaseDir)ports\unix\modmachine.c" />
<ClCompile Include="$(PyVariantDir)*.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="@(PyCoreInclude)" />
Expand Down
19 changes: 16 additions & 3 deletions ports/windows/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

// options to control how MicroPython is built

// Variant-specific definitions.
#include "mpconfigvariant.h"

// By default use MicroPython version of readline
#ifndef MICROPY_USE_READLINE
#define MICROPY_USE_READLINE (1)
Expand Down Expand Up @@ -54,9 +57,13 @@
#define MICROPY_REPL_AUTO_INDENT (1)
#define MICROPY_HELPER_LEXER_UNIX (1)
#define MICROPY_ENABLE_SOURCE_LINE (1)
#ifndef MICROPY_FLOAT_IMPL
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
#endif
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#ifndef MICROPY_STREAMS_NON_BLOCK
#define MICROPY_STREAMS_NON_BLOCK (1)
#endif
#define MICROPY_STREAMS_POSIX_API (1)
#define MICROPY_OPT_COMPUTED_GOTO (0)
#define MICROPY_MODULE_WEAK_LINKS (1)
Expand All @@ -77,8 +84,12 @@
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1)
#define MICROPY_PY_BUILTINS_INPUT (1)
#define MICROPY_PY_BUILTINS_POW3 (1)
#ifndef MICROPY_PY_BUILTINS_HELP
#define MICROPY_PY_BUILTINS_HELP (1)
#endif
#ifndef MICROPY_PY_BUILTINS_HELP_MODULES
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
#endif
#define MICROPY_PY_BUILTINS_ROUND_INT (1)
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
#define MICROPY_PY_ALL_SPECIAL_METHODS (1)
Expand All @@ -97,16 +108,18 @@
#define MICROPY_PY_SYS_EXC_INFO (1)
#define MICROPY_PY_COLLECTIONS_DEQUE (1)
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1)
#ifndef MICROPY_PY_MATH_SPECIAL_FUNCTIONS
#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (1)
#define MICROPY_PY_MATH_ISCLOSE (1)
#endif
#define MICROPY_PY_MATH_ISCLOSE (MICROPY_PY_MATH_SPECIAL_FUNCTIONS)
#define MICROPY_PY_CMATH (1)
#define MICROPY_PY_IO_IOBASE (1)
#define MICROPY_PY_IO_FILEIO (1)
#define MICROPY_PY_GC_COLLECT_RETVAL (1)
#define MICROPY_MODULE_FROZEN_STR (0)

#ifndef MICROPY_STACKLESS
#define MICROPY_STACKLESS (0)
#define MICROPY_STACKLESS_STRICT (0)
#endif

#define MICROPY_PY_UTIME (1)
#define MICROPY_PY_UTIME_MP_HAL (1)
Expand Down
7 changes: 2 additions & 5 deletions ports/windows/mpconfigport.mk
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# Enable/disable modules and 3rd-party libs to be included in interpreter

# Build 32-bit binaries on a 64-bit host
MICROPY_FORCE_32BIT = 0
MICROPY_FORCE_32BIT ?= 0

# This variable can take the following values:
# 0 - no readline, just simple stdin input
# 1 - use MicroPython version of readline
MICROPY_USE_READLINE = 1

# ffi module requires libffi (libffi-dev Debian package)
MICROPY_PY_FFI = 0
MICROPY_USE_READLINE ?= 1
14 changes: 14 additions & 0 deletions ports/windows/msvc/common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Variant support. For compatibility with how it works for the other ports, this gets imported
early so variants cannot override build options like the ones specified in the rest of this file.
Use CustomPropsFile (see the .vcxproj file) for that. -->
<PropertyGroup>
<PyVariant Condition="'$(PyVariant)' == ''">standard</PyVariant>
<PyBuild Condition="'$(PyBuild)' == ''">build-$(PyVariant)</PyBuild>
</PropertyGroup>
<ImportGroup Label="PropertySheets">
<Import Project="paths.props" Condition="'$(PyPathsIncluded)' != 'True'"/>
<Import Project="$(PyVariantDir)mpconfigvariant.props"/>
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
Expand Down Expand Up @@ -31,8 +39,14 @@
<Destination>$(PyTargetDir)%(FileName)%(Extension)</Destination>
</PyOutputFiles>
<PyCookieFiles Include="$(PyBuildDir)copycookie*" Exclude="$(PyFileCopyCookie)"/>
<QstrDependencies Include="$(PyVariantDir)mpconfigvariant.h"/>
</ItemGroup>

<!-- Helper for getting resulting executable path since it depends on other properties. -->
<Target Name="ShowTargetPath">
<Message Text="$(TargetPath)" Importance="high"/>
</Target>

<!-- Copy PyOutputFiles to their target destination.
To force this when switching between platforms/configurations which are already up-to-date (and as such,
for which a build wouldn't even start because all outputs are effectively newer than the inputs)
Expand Down
9 changes: 6 additions & 3 deletions ports/windows/msvc/paths.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@
|- ports/windows [PyWinDir]
|- ...
|- micropython.exe
|- build [PyBuildDir]
|- build-standard [PyBuildDir]
|- Debugx64 [PyOutDir]
| |- ...
| |- micropython.exe
| |- micropython.map
| |- obj [PyIntDir]
|- genhdr
|- variants
|- standard [PyVariantDir]

Note that the micropython executable will be copied from PyOutDir
to PyWinDir after each build. -->

<!-- Start from project root -->
<PyBaseDir>$([System.IO.Path]::GetFullPath(`$(MSBuildThisFileDirectory)..\..\..`))\</PyBaseDir>
<PyWinDir>$(PyBaseDir)ports\windows\</PyWinDir>
<PyBuildDir Condition="'$(PyBuildDir)' == ''">$(PyWinDir)build\</PyBuildDir>
<PyBuildDir Condition="'$(PyBuildDir)' == ''">$(PyWinDir)$(PyBuild)\</PyBuildDir>
<PyVariantDir Condition="'$(PyVariantDir)' == ''">$(PyWinDir)variants\$(PyVariant)\</PyVariantDir>
<PyTargetDir Condition="'$(PyTargetDir)' == ''">$(PyWinDir)</PyTargetDir>

<!-- All include directories needed for uPy -->
<PyIncDirs>$(PyIncDirs);$(PyBaseDir);$(PyWinDir);$(PyBuildDir);$(PyWinDir)msvc</PyIncDirs>
<PyIncDirs>$(PyIncDirs);$(PyBaseDir);$(PyWinDir);$(PyBuildDir);$(PyWinDir)msvc;$(PyVariantDir)</PyIncDirs>

<!-- Within PyBuildDir different subdirectories are used based on configuration and platform.
By default these are chosen based on the Configuration and Platform properties, but
Expand Down
1 change: 1 addition & 0 deletions ports/windows/variants/dev/manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include("$(PORT_DIR)/variants/manifest.py")
37 changes: 37 additions & 0 deletions ports/windows/variants/dev/mpconfigvariant.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#define MICROPY_REPL_EMACS_WORDS_MOVE (1)
#define MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE (1)
#define MICROPY_ENABLE_SCHEDULER (1)

#define MICROPY_PY_BUILTINS_HELP (1)
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
#define MICROPY_PY_SYS_SETTRACE (1)
#define MICROPY_PERSISTENT_CODE_SAVE (1)
#define MICROPY_COMP_CONST (0)
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1)
#define MICROPY_PY_BUILTINS_SLICE_INDICES (1)
5 changes: 5 additions & 0 deletions ports/windows/variants/dev/mpconfigvariant.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PROG ?= micropython-dev

FROZEN_MANIFEST ?= $(VARIANT_DIR)/manifest.py

MICROPY_ROM_TEXT_COMPRESSION = 1
5 changes: 5 additions & 0 deletions ports/windows/variants/dev/mpconfigvariant.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<PyProg>micropython-dev</PyProg>
</PropertyGroup>
</Project>
Empty file.
28 changes: 28 additions & 0 deletions ports/windows/variants/standard/mpconfigvariant.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#define MICROPY_PY_BUILTINS_HELP (1)
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
3 changes: 3 additions & 0 deletions ports/windows/variants/standard/mpconfigvariant.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This is the default variant when you `make` the Windows port.

PROG ?= micropython
5 changes: 5 additions & 0 deletions ports/windows/variants/standard/mpconfigvariant.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<PyProg>micropython</PyProg>
</PropertyGroup>
</Project>
Loading