Skip to content

Commit

Permalink
Add support for VS2015 (VC++ 14.0)
Browse files Browse the repository at this point in the history
Due to the rewritten CRT in this version of Visual C++ it is no longer
possible (or at least not at all easy) to make use of the ioinfo struct,
which commit b47a847 (re-)introduced in order to fix RT#120091/118059.
Therefore, we effectively revert commit b47a847 for VS2015 onwards on
the basis that being able to build with VS2015 onwards is more important
than the RT#120091/118059 bug fix. This does unfortunately mean that perls
built with <=VS2013 will not be compatible with perls built with >=VS2015,
but they may well not have been compatible anyway because of the CRT
rewrite, and certainly wouldn't be compatible if perl builds with VS2015
were not supported!

See RT#125714 for more discussion about this.
  • Loading branch information
steve-m-hay committed Feb 19, 2017
1 parent b3dc9cf commit 1f664ef
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 30 deletions.
18 changes: 9 additions & 9 deletions README.win32
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ that are also supported by perl's makefile.
=back

The Microsoft Visual C++ compilers are also now being given away free. They are
available as "Visual C++ Toolkit 2003" or "Visual C++ 2005-2013 Express
available as "Visual C++ Toolkit 2003" or "Visual C++ 2005-2015 Express
Edition" (and also as part of the ".NET Framework SDK") and are the same
compilers that ship with "Visual C++ .NET 2003 Professional" or "Visual C++
2005-2013 Professional" respectively.
2005-2015 Professional" respectively.

This port can also be built on IA64/AMD64 using:

Expand Down Expand Up @@ -139,9 +139,9 @@ console already set up for your target architecture (x86-32 or x86-64 or IA64).
With the newer compilers, you may also use the older batch files if you choose
so.

=item Microsoft Visual C++ 2008-2013 Express Edition
=item Microsoft Visual C++ 2008-2015 Express Edition

These free versions of Visual C++ 2008-2013 Professional contain the same
These free versions of Visual C++ 2008-2015 Professional contain the same
compilers and linkers that ship with the full versions, and also contain
everything necessary to build Perl, rather than requiring a separate download
of the Windows SDK like previous versions did.
Expand All @@ -151,14 +151,14 @@ L<http://www.microsoft.com/downloads/search.aspx?displaylang=en>. (Providing ex
links to these packages has proven a pointless task because the links keep on
changing so often.)

Install Visual C++ 2008-2013 Express, then setup your environment using, e.g.
Install Visual C++ 2008-2015 Express, then setup your environment using, e.g.

C:\Program Files\Microsoft Visual Studio 12.0\Common7\Tools\vsvars32.bat

(assuming the default installation location was chosen).

Perl should now build using the win32/Makefile. You will need to edit that
file to set CCTYPE to one of MSVC90FREE-MSVC120FREE first.
file to set CCTYPE to one of MSVC90FREE-MSVC140FREE first.

=item Microsoft Visual C++ 2005 Express Edition

Expand Down Expand Up @@ -421,8 +421,8 @@ There should be no test failures.
If you build with Visual C++ 2013 then three tests currently may fail with
Daylight Saving Time related problems: F<t/io/fs.t>,
F<cpan/HTTP-Tiny/t/110_mirror.t> and F<lib/File/Copy.t>. The failures are
caused by bugs in the CRT in VC++ 2013 which will be fixed in future releases
of VC++, as explained by Microsoft here:
caused by bugs in the CRT in VC++ 2013 which are fixed in VC++2015 and
later, as explained by Microsoft here:
L<https://connect.microsoft.com/VisualStudio/feedback/details/811534/utime-sometimes-fails-to-set-the-correct-file-times-in-visual-c-2013>. In the meantime,
if you need fixed C<stat> and C<utime> functions then have a look at the
CPAN distribution Win32::UTCFileTime.
Expand Down Expand Up @@ -950,6 +950,6 @@ Win9x support was added in 5.6 (Benjamin Stuhl).

Support for 64-bit Windows added in 5.8 (ActiveState Corp).

Last updated: 07 October 2014
Last updated: 19 February 2017

=cut
2 changes: 1 addition & 1 deletion perlio.c
Original file line number Diff line number Diff line change
Expand Up @@ -3231,7 +3231,7 @@ PerlIOStdio_invalidate_fileno(pTHX_ FILE *f)
structure at all
*/
# else
f->_file = -1;
PERLIO_FILE_file(f) = -1;
# endif
return 1;
# else
Expand Down
58 changes: 58 additions & 0 deletions win32/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ USE_LARGE_FILES := define
#CCTYPE := MSVC120
# Visual C++ 2013 Express Edition (aka Visual C++ 12.0) (free version)
#CCTYPE := MSVC120FREE
# Visual C++ 2015 (aka Visual C++ 14.0) (full version)
#CCTYPE := MSVC140
# Visual C++ 2015 Express Edition (aka Visual C++ 14.0) (free version)
#CCTYPE := MSVC140FREE
# MinGW or mingw-w64 with gcc-3.4.5 or later
#CCTYPE := GCC

Expand Down Expand Up @@ -619,7 +623,13 @@ DEFINES = -DWIN32 -D_CONSOLE -DNO_STRICT
LOCDEFS = -DPERLDLL -DPERL_CORE
CXX_FLAG = -TP -EHsc

ifeq ($(CCTYPE),MSVC140)
LIBC = ucrt.lib
else ifeq ($(CCTYPE),MSVC140FREE)
LIBC = ucrt.lib
else
LIBC = msvcrt.lib
endif

ifeq ($(CFG),Debug)
OPTIMIZE = -Od -MD -Zi -DDEBUGGING
Expand All @@ -628,7 +638,13 @@ else ifeq ($(CFG),DebugSymbols)
OPTIMIZE = -Od -MD -Zi
LINK_DBG = -debug
else ifeq ($(CFG),DebugFull)
ifeq ($(CCTYPE),MSVC140)
LIBC = ucrtd.lib
else ifeq ($(CCTYPE),MSVC140FREE)
LIBC = ucrtd.lib
else
LIBC = msvcrtd.lib
endif
OPTIMIZE = -Od -MDd -Zi -D_DEBUG -DDEBUGGING
LINK_DBG = -debug
else
Expand Down Expand Up @@ -661,6 +677,13 @@ ifeq ($(PREMSVC80),undef)
DEFINES += -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE
endif

# Likewise for deprecated Winsock APIs in VC++ 14.0 for now.
ifeq ($(CCTYPE),MSVC140)
DEFINES = $(DEFINES) -D_WINSOCK_DEPRECATED_NO_WARNINGS
else ifeq ($(CCTYPE),MSVC140FREE)
DEFINES = $(DEFINES) -D_WINSOCK_DEPRECATED_NO_WARNINGS
endif

# In VS 2005 (VC++ 8.0) Microsoft changes time_t from 32-bit to
# 64-bit, even in 32-bit mode. It also provides the _USE_32BIT_TIME_T
# preprocessor option to revert back to the old functionality for
Expand All @@ -680,6 +703,20 @@ LIBBASEFILES = oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib \
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib \
odbc32.lib odbccp32.lib comctl32.lib

ifeq ($(CCTYPE),MSVC140)
ifeq ($(CFG),DebugFull)
LIBBASEFILES += msvcrtd.lib vcruntimed.lib
else
LIBBASEFILES += msvcrt.lib vcruntime.lib
endif
else ifeq ($(CCTYPE),MSVC140FREE)
ifeq ($(CFG),DebugFull)
LIBBASEFILES += msvcrtd.lib vcruntimed.lib
else
LIBBASEFILES += msvcrt.lib vcruntime.lib
endif
endif

# Avoid __intel_new_proc_init link error for libircmt.
# libmmd is /MD equivelent, other variants exist.
# libmmd is Intel C's math addon funcs to MS CRT, contains long doubles, C99,
Expand Down Expand Up @@ -1240,6 +1277,27 @@ $(MINIDIR)\.exists : $(CFGH_TMPL)
echo #undef NVff&& \
echo #undef NVgf&& \
echo #undef USE_LONG_DOUBLE)>> config.h
ifeq ($(CCTYPE),MSVC140)
@(echo #undef FILE_ptr&& \
echo #undef FILE_cnt&& \
echo #undef FILE_base&& \
echo #undef FILE_bufsiz&& \
echo #define FILE_ptr(fp) PERLIO_FILE_ptr(fp)&& \
echo #define FILE_cnt(fp) PERLIO_FILE_cnt(fp)&& \
echo #define FILE_base(fp) PERLIO_FILE_base(fp)&& \
echo #define FILE_bufsiz(fp) (PERLIO_FILE_cnt(fp) + PERLIO_FILE_ptr(fp) - PERLIO_FILE_base(fp))&& \
echo #define I_STDBOOL)>> config.h
else ifeq ($(CCTYPE),MSVC140FREE)
@(echo #undef FILE_ptr&& \
echo #undef FILE_cnt&& \
echo #undef FILE_base&& \
echo #undef FILE_bufsiz&& \
echo #define FILE_ptr(fp) PERLIO_FILE_ptr(fp)&& \
echo #define FILE_cnt(fp) PERLIO_FILE_cnt(fp)&& \
echo #define FILE_base(fp) PERLIO_FILE_base(fp)&& \
echo #define FILE_bufsiz(fp) (PERLIO_FILE_cnt(fp) + PERLIO_FILE_ptr(fp) - PERLIO_FILE_base(fp))&& \
echo #define I_STDBOOL)>> config.h
endif
ifeq ($(USE_LARGE_FILES),define)
@(echo #define Off_t $(INT64)&& \
echo #define LSEEKSIZE ^8&& \
Expand Down
36 changes: 36 additions & 0 deletions win32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ CCTYPE = MSVC60
#CCTYPE = MSVC120
# Visual C++ 2013 Express Edition (aka Visual C++ 12.0) (free version)
#CCTYPE = MSVC120FREE
# Visual C++ 2015 (aka Visual C++ 14.0) (full version)
#CCTYPE = MSVC140
# Visual C++ 2015 Express Edition (aka Visual C++ 14.0) (free version)
#CCTYPE = MSVC140FREE

#
# If you are using Intel C++ Compiler uncomment this
Expand Down Expand Up @@ -467,7 +471,11 @@ DEFINES = -DWIN32 -D_CONSOLE -DNO_STRICT
LOCDEFS = -DPERLDLL -DPERL_CORE
CXX_FLAG = -TP -EHsc

!IF "$(CCTYPE)" == "MSVC140" || "$(CCTYPE)" == "MSVC140FREE"
LIBC = ucrt.lib
!ELSE
LIBC = msvcrt.lib
!ENDIF

!IF "$(CFG)" == "Debug"
OPTIMIZE = -Od -MD -Zi -DDEBUGGING
Expand All @@ -478,7 +486,11 @@ OPTIMIZE = -Od -MD -Zi
LINK_DBG = -debug
!ELSE
!IF "$(CFG)" == "DebugFull"
!IF "$(CCTYPE)" == "MSVC140" || "$(CCTYPE)" == "MSVC140FREE"
LIBC = ucrtd.lib
!ELSE
LIBC = msvcrtd.lib
!ENDIF
OPTIMIZE = -Od -MDd -Zi -D_DEBUG -DDEBUGGING
LINK_DBG = -debug
!ELSE
Expand Down Expand Up @@ -513,6 +525,11 @@ OPTIMIZE = $(OPTIMIZE) -fp:precise
DEFINES = $(DEFINES) -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE
!ENDIF

# Likewise for deprecated Winsock APIs in VC++ 14.0 for now.
!IF "$(CCTYPE)" == "MSVC140" || "$(CCTYPE)" == "MSVC140FREE"
DEFINES = $(DEFINES) -D_WINSOCK_DEPRECATED_NO_WARNINGS
!ENDIF

# In VS 2005 (VC++ 8.0) Microsoft changes time_t from 32-bit to
# 64-bit, even in 32-bit mode. It also provides the _USE_32BIT_TIME_T
# preprocessor option to revert back to the old functionality for
Expand All @@ -533,6 +550,14 @@ LIBBASEFILES = \
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib \
version.lib odbc32.lib odbccp32.lib comctl32.lib

!IF "$(CCTYPE)" == "MSVC140" || "$(CCTYPE)" == "MSVC140FREE"
! IF "$(CFG)" == "DebugFull"
LIBBASEFILES = $(LIBBASEFILES) msvcrtd.lib vcruntimed.lib
! ELSE
LIBBASEFILES = $(LIBBASEFILES) msvcrt.lib vcruntime.lib
! ENDIF
!ENDIF

# Avoid __intel_new_proc_init link error for libircmt.
# libmmd is /MD equivelent, other variants exist.
# libmmd is Intel C's math addon funcs to MS CRT, contains long doubles, C99,
Expand Down Expand Up @@ -928,6 +953,17 @@ perlglob$(o) : perlglob.c
@echo.>>$@
@echo #ifndef _config_h_footer_>>$@
@echo #define _config_h_footer_>>$@
!IF "$(CCTYPE)" == "MSVC140" || "$(CCTYPE)" == "MSVC140FREE"
@echo #undef FILE_ptr>>$@
@echo #define FILE_ptr(fp) PERLIO_FILE_ptr(fp)>>$@
@echo #undef FILE_cnt>>$@
@echo #define FILE_cnt(fp) PERLIO_FILE_cnt(fp)>>$@
@echo #undef FILE_base>>$@
@echo #define FILE_base(fp) PERLIO_FILE_base(fp)>>$@
@echo #undef FILE_bufsiz>>$@
@echo #define FILE_bufsiz(fp) (PERLIO_FILE_cnt(fp) + PERLIO_FILE_ptr(fp) - PERLIO_FILE_base(fp))>>$@
@echo #define I_STDBOOL>>$@
!ENDIF
@echo #undef Off_t>>$@
@echo #undef LSEEKSIZE>>$@
@echo #undef Off_t_size>>$@
Expand Down
14 changes: 14 additions & 0 deletions win32/config_sh.PL
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ if ($opt{cc} =~ /\bcl/ and $opt{ccversion} =~ /^(\d+)/) {
if($ccversion < 13) { #VC6
$opt{ar} ='lib';
}
if ($ccversion >= 19) { # VC14
$opt{stdio_base} = 'PERLIO_FILE_base(fp)';
$opt{stdio_bufsiz} = '(PERLIO_FILE_cnt(fp) + PERLIO_FILE_ptr(fp) - PERLIO_FILE_base(fp))';
$opt{stdio_cnt} = 'PERLIO_FILE_cnt(fp)';
$opt{stdio_ptr} = 'PERLIO_FILE_ptr(fp)';
$opt{i_stdbool} = 'define';
}
}
#find out which MSVC this ICC is using
elsif ($opt{cc} =~ /\bicl/) {
Expand All @@ -286,6 +293,13 @@ elsif ($opt{cc} =~ /\bicl/) {
$opt{sGMTIME_max} = 32535291599;
$opt{sLOCALTIME_max} = 32535244799;
}
if ($num_ver =~ /^(\d+)/ && $1 >= 19) { # VC14
$opt{stdio_base} = 'PERLIO_FILE_base(fp)';
$opt{stdio_bufsiz} = '(PERLIO_FILE_cnt(fp) + PERLIO_FILE_ptr(fp) - PERLIO_FILE_base(fp))';
$opt{stdio_cnt} = 'PERLIO_FILE_cnt(fp)';
$opt{stdio_ptr} = 'PERLIO_FILE_ptr(fp)';
$opt{i_stdbool} = 'define';
}
$opt{ar} ='xilib';
}

Expand Down
36 changes: 36 additions & 0 deletions win32/makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ USE_LARGE_FILES *= define
#CCTYPE = MSVC120
# Visual C++ 2013 Express Edition (aka Visual C++ 12.0) (free version)
#CCTYPE = MSVC120FREE
# Visual C++ 2015 (aka Visual C++ 14.0) (full version)
#CCTYPE = MSVC140
# Visual C++ 2015 Express Edition (aka Visual C++ 14.0) (free version)
#CCTYPE = MSVC140FREE
# MinGW or mingw-w64 with gcc-3.4.5 or later
#CCTYPE = GCC

Expand Down Expand Up @@ -606,7 +610,11 @@ DEFINES = -DWIN32 -D_CONSOLE -DNO_STRICT
LOCDEFS = -DPERLDLL -DPERL_CORE
CXX_FLAG = -TP -EHsc

.IF "$(CCTYPE)" == "MSVC140" || "$(CCTYPE)" == "MSVC140FREE"
LIBC = ucrt.lib
.ELSE
LIBC = msvcrt.lib
.ENDIF

.IF "$(CFG)" == "Debug"
OPTIMIZE = -Od -MD -Zi -DDEBUGGING
Expand All @@ -615,7 +623,11 @@ LINK_DBG = -debug
OPTIMIZE = -Od -MD -Zi
LINK_DBG = -debug
.ELIF "$(CFG)" == "DebugFull"
.IF "$(CCTYPE)" == "MSVC140" || "$(CCTYPE)" == "MSVC140FREE"
LIBC = ucrtd.lib
.ELSE
LIBC = msvcrtd.lib
.ENDIF
OPTIMIZE = -Od -MDd -Zi -D_DEBUG -DDEBUGGING
LINK_DBG = -debug
.ELSE
Expand Down Expand Up @@ -648,6 +660,11 @@ OPTIMIZE += -fp:precise
DEFINES += -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE
.ENDIF

# Likewise for deprecated Winsock APIs in VC++ 14.0 for now.
.IF "$(CCTYPE)" == "MSVC140" || "$(CCTYPE)" == "MSVC140FREE"
DEFINES = $(DEFINES) -D_WINSOCK_DEPRECATED_NO_WARNINGS
.ENDIF

# In VS 2005 (VC++ 8.0) Microsoft changes time_t from 32-bit to
# 64-bit, even in 32-bit mode. It also provides the _USE_32BIT_TIME_T
# preprocessor option to revert back to the old functionality for
Expand All @@ -667,6 +684,14 @@ LIBBASEFILES = oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib \
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib \
odbc32.lib odbccp32.lib comctl32.lib

.IF "$(CCTYPE)" == "MSVC140" || "$(CCTYPE)" == "MSVC140FREE"
.IF "$(CFG)" == "DebugFull"
LIBBASEFILES += msvcrtd.lib vcruntimed.lib
.ELSE
LIBBASEFILES += msvcrt.lib vcruntime.lib
.ENDIF
.ENDIF

# Avoid __intel_new_proc_init link error for libircmt.
# libmmd is /MD equivelent, other variants exist.
# libmmd is Intel C's math addon funcs to MS CRT, contains long doubles, C99,
Expand Down Expand Up @@ -1208,6 +1233,17 @@ $(MINIDIR)\.exists : $(CFGH_TMPL)
echo #undef NVgf&& \
echo #undef USE_LONG_DOUBLE&& \
echo #undef USE_CPLUSPLUS)>> config.h
.IF "$(CCTYPE)" == "MSVC140" || "$(CCTYPE)" == "MSVC140FREE"
@(echo #undef FILE_ptr&& \
echo #undef FILE_cnt&& \
echo #undef FILE_base&& \
echo #undef FILE_bufsiz&& \
echo #define FILE_ptr(fp) PERLIO_FILE_ptr(fp)&& \
echo #define FILE_cnt(fp) PERLIO_FILE_cnt(fp)&& \
echo #define FILE_base(fp) PERLIO_FILE_base(fp)&& \
echo #define FILE_bufsiz(fp) (PERLIO_FILE_cnt(fp) + PERLIO_FILE_ptr(fp) - PERLIO_FILE_base(fp))&& \
echo #define I_STDBOOL)>> config.h
.ENDIF
.IF "$(USE_LARGE_FILES)"=="define"
@(echo #define Off_t $(INT64)&& \
echo #define LSEEKSIZE ^8&& \
Expand Down
6 changes: 3 additions & 3 deletions win32/perlhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -836,15 +836,15 @@ PerlStdIOFdupopen(struct IPerlStdIO* piPerl, FILE* pf)
int fileno = win32_dup(win32_fileno(pf));

/* open the file in the same mode */
if((pf)->_flag & _IOREAD) {
if (PERLIO_FILE_flag(pf) & PERLIO_FILE_flag_RD) {
mode[0] = 'r';
mode[1] = 0;
}
else if((pf)->_flag & _IOWRT) {
else if (PERLIO_FILE_flag(pf) & PERLIO_FILE_flag_WR) {
mode[0] = 'a';
mode[1] = 0;
}
else if((pf)->_flag & _IORW) {
else if (PERLIO_FILE_flag(pf) & PERLIO_FILE_flag_RW) {
mode[0] = 'r';
mode[1] = '+';
mode[2] = 0;
Expand Down
6 changes: 3 additions & 3 deletions win32/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -4161,15 +4161,15 @@ win32_fdupopen(FILE *pf)
int fileno = win32_dup(win32_fileno(pf));

/* open the file in the same mode */
if((pf)->_flag & _IOREAD) {
if (PERLIO_FILE_flag(pf) & PERLIO_FILE_flag_RD) {
mode[0] = 'r';
mode[1] = 0;
}
else if((pf)->_flag & _IOWRT) {
else if (PERLIO_FILE_flag(pf) & PERLIO_FILE_flag_WR) {
mode[0] = 'a';
mode[1] = 0;
}
else if((pf)->_flag & _IORW) {
else if (PERLIO_FILE_flag(pf) & PERLIO_FILE_flag_RW) {
mode[0] = 'r';
mode[1] = '+';
mode[2] = 0;
Expand Down
Loading

0 comments on commit 1f664ef

Please sign in to comment.