Skip to content

Commit 05ed19e

Browse files
pi-anldpgeorge
authored andcommitted
windows: Add support for build variants to windows port.
Following the unix port. Support for building variants with msvc was done by @stinos.
1 parent bfe9eba commit 05ed19e

File tree

15 files changed

+160
-14
lines changed

15 files changed

+160
-14
lines changed

ports/windows/Makefile

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
1+
# Select the variant to build for.
2+
VARIANT ?= standard
3+
4+
# If the build directory is not given, make it reflect the variant name.
5+
BUILD ?= build-$(VARIANT)
6+
7+
VARIANT_DIR ?= variants/$(VARIANT)
8+
ifeq ($(wildcard $(VARIANT_DIR)/.),)
9+
$(error Invalid VARIANT specified: $(VARIANT_DIR))
10+
endif
11+
112
include ../../py/mkenv.mk
213
-include mpconfigport.mk
14+
include $(VARIANT_DIR)/mpconfigvariant.mk
15+
16+
FROZEN_MANIFEST ?= variants/manifest.py
317

4-
# define main target
5-
PROG = micropython
18+
# Define main target
19+
# This should be configured by the mpconfigvariant.mk
20+
PROG ?= micropython
621

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

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

1329
INC += -I.
1430
INC += -I$(TOP)
1531
INC += -I$(BUILD)
32+
INC += -I$(VARIANT_DIR)
1633

1734
# compiler settings
1835
CFLAGS = $(INC) -Wall -Wpointer-arith -Wdouble-promotion -Werror -std=gnu99 -DUNIX -D__USE_MINGW_ANSI_STDIO=1 $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
@@ -41,7 +58,8 @@ SRC_C = \
4158
init.c \
4259
sleep.c \
4360
fmode.c \
44-
$(SRC_MOD)
61+
$(SRC_MOD) \
62+
$(wildcard $(VARIANT_DIR)/*.c)
4563

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

ports/windows/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ To build from the command line:
7171
msbuild ../../mpy-cross/mpy-cross.vcxproj
7272
msbuild micropython.vcxproj
7373

74+
__Variants__
75+
76+
The msvc port supports variants (like the unix and windows mingw ports) and the one which gets built is
77+
controlled by the `PyVariant` msbuild property. It defaults to `standard`.
78+
The other variants can be built like:
79+
80+
msbuild micropython.vcxproj /p:PyVariant=dev
81+
82+
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:
83+
84+
```xml
85+
<Project>
86+
<PropertyGroup>
87+
<PyVariant>dev</PyVariant>
88+
</PropertyGroup>
89+
</Project>
90+
```
91+
92+
See [paths.props](msvc/paths.props) for other related variables like build and variant directories.
93+
7494
__Stack usage__
7595

7696
The msvc compiler is quite stack-hungry which might result in a "maximum recursion depth exceeded"

ports/windows/micropython.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
</ImportGroup>
6565
<PropertyGroup Label="UserMacros">
6666
<CustomPropsFile Condition="'$(CustomPropsFile)'==''">msvc/user.props</CustomPropsFile>
67+
<TargetName>$(PyProg)</TargetName>
6768
</PropertyGroup>
6869
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
6970
<ClCompile />
@@ -95,6 +96,7 @@
9596
<ClCompile Include="$(PyBaseDir)ports\unix\modos.c"/>
9697
<ClCompile Include="$(PyBaseDir)ports\unix\modtime.c"/>
9798
<ClCompile Include="$(PyBaseDir)ports\unix\modmachine.c" />
99+
<ClCompile Include="$(PyVariantDir)*.c" />
98100
</ItemGroup>
99101
<ItemGroup>
100102
<ClInclude Include="@(PyCoreInclude)" />

ports/windows/mpconfigport.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
// options to control how MicroPython is built
2828

29+
// Variant-specific definitions.
30+
#include "mpconfigvariant.h"
31+
2932
// By default use MicroPython version of readline
3033
#ifndef MICROPY_USE_READLINE
3134
#define MICROPY_USE_READLINE (1)
@@ -54,9 +57,13 @@
5457
#define MICROPY_REPL_AUTO_INDENT (1)
5558
#define MICROPY_HELPER_LEXER_UNIX (1)
5659
#define MICROPY_ENABLE_SOURCE_LINE (1)
60+
#ifndef MICROPY_FLOAT_IMPL
5761
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
62+
#endif
5863
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
64+
#ifndef MICROPY_STREAMS_NON_BLOCK
5965
#define MICROPY_STREAMS_NON_BLOCK (1)
66+
#endif
6067
#define MICROPY_STREAMS_POSIX_API (1)
6168
#define MICROPY_OPT_COMPUTED_GOTO (0)
6269
#define MICROPY_MODULE_WEAK_LINKS (1)
@@ -77,8 +84,12 @@
7784
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1)
7885
#define MICROPY_PY_BUILTINS_INPUT (1)
7986
#define MICROPY_PY_BUILTINS_POW3 (1)
87+
#ifndef MICROPY_PY_BUILTINS_HELP
8088
#define MICROPY_PY_BUILTINS_HELP (1)
89+
#endif
90+
#ifndef MICROPY_PY_BUILTINS_HELP_MODULES
8191
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
92+
#endif
8293
#define MICROPY_PY_BUILTINS_ROUND_INT (1)
8394
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
8495
#define MICROPY_PY_ALL_SPECIAL_METHODS (1)
@@ -97,16 +108,18 @@
97108
#define MICROPY_PY_SYS_EXC_INFO (1)
98109
#define MICROPY_PY_COLLECTIONS_DEQUE (1)
99110
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1)
111+
#ifndef MICROPY_PY_MATH_SPECIAL_FUNCTIONS
100112
#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (1)
101-
#define MICROPY_PY_MATH_ISCLOSE (1)
113+
#endif
114+
#define MICROPY_PY_MATH_ISCLOSE (MICROPY_PY_MATH_SPECIAL_FUNCTIONS)
102115
#define MICROPY_PY_CMATH (1)
103116
#define MICROPY_PY_IO_IOBASE (1)
104117
#define MICROPY_PY_IO_FILEIO (1)
105118
#define MICROPY_PY_GC_COLLECT_RETVAL (1)
106-
#define MICROPY_MODULE_FROZEN_STR (0)
107-
119+
#ifndef MICROPY_STACKLESS
108120
#define MICROPY_STACKLESS (0)
109121
#define MICROPY_STACKLESS_STRICT (0)
122+
#endif
110123

111124
#define MICROPY_PY_UTIME (1)
112125
#define MICROPY_PY_UTIME_MP_HAL (1)

ports/windows/mpconfigport.mk

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
# Enable/disable modules and 3rd-party libs to be included in interpreter
22

33
# Build 32-bit binaries on a 64-bit host
4-
MICROPY_FORCE_32BIT = 0
4+
MICROPY_FORCE_32BIT ?= 0
55

66
# This variable can take the following values:
77
# 0 - no readline, just simple stdin input
88
# 1 - use MicroPython version of readline
9-
MICROPY_USE_READLINE = 1
10-
11-
# ffi module requires libffi (libffi-dev Debian package)
12-
MICROPY_PY_FFI = 0
9+
MICROPY_USE_READLINE ?= 1

ports/windows/msvc/common.props

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<!-- Variant support. For compatibility with how it works for the other ports, this gets imported
4+
early so variants cannot override build options like the ones specified in the rest of this file.
5+
Use CustomPropsFile (see the .vcxproj file) for that. -->
6+
<PropertyGroup>
7+
<PyVariant Condition="'$(PyVariant)' == ''">standard</PyVariant>
8+
<PyBuild Condition="'$(PyBuild)' == ''">build-$(PyVariant)</PyBuild>
9+
</PropertyGroup>
310
<ImportGroup Label="PropertySheets">
411
<Import Project="paths.props" Condition="'$(PyPathsIncluded)' != 'True'"/>
12+
<Import Project="$(PyVariantDir)mpconfigvariant.props"/>
513
</ImportGroup>
614
<PropertyGroup Label="UserMacros" />
715
<PropertyGroup>
@@ -31,6 +39,7 @@
3139
<Destination>$(PyTargetDir)%(FileName)%(Extension)</Destination>
3240
</PyOutputFiles>
3341
<PyCookieFiles Include="$(PyBuildDir)copycookie*" Exclude="$(PyFileCopyCookie)"/>
42+
<QstrDependencies Include="$(PyVariantDir)mpconfigvariant.h"/>
3443
</ItemGroup>
3544

3645
<!-- Copy PyOutputFiles to their target destination.

ports/windows/msvc/paths.props

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,28 @@
1111
|- ports/windows [PyWinDir]
1212
|- ...
1313
|- micropython.exe
14-
|- build [PyBuildDir]
14+
|- build-standard [PyBuildDir]
1515
|- Debugx64 [PyOutDir]
1616
| |- ...
1717
| |- micropython.exe
1818
| |- micropython.map
1919
| |- obj [PyIntDir]
2020
|- genhdr
21+
|- variants
22+
|- standard [PyVariantDir]
2123
2224
Note that the micropython executable will be copied from PyOutDir
2325
to PyWinDir after each build. -->
2426

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

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

3437
<!-- Within PyBuildDir different subdirectories are used based on configuration and platform.
3538
By default these are chosen based on the Configuration and Platform properties, but
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include("$(PORT_DIR)/variants/manifest.py")
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#define MICROPY_REPL_EMACS_WORDS_MOVE (1)
28+
#define MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE (1)
29+
#define MICROPY_ENABLE_SCHEDULER (1)
30+
31+
#define MICROPY_PY_BUILTINS_HELP (1)
32+
#define MICROPY_PY_BUILTINS_HELP_MODULES (1)
33+
#define MICROPY_PY_SYS_SETTRACE (1)
34+
#define MICROPY_PERSISTENT_CODE_SAVE (1)
35+
#define MICROPY_COMP_CONST (0)
36+
#define MICROPY_PY_URANDOM_EXTRA_FUNCS (1)
37+
#define MICROPY_PY_BUILTINS_SLICE_INDICES (1)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PROG ?= micropython-dev
2+
3+
FROZEN_MANIFEST ?= $(VARIANT_DIR)/manifest.py
4+
5+
MICROPY_ROM_TEXT_COMPRESSION = 1

0 commit comments

Comments
 (0)