Tcl Source Code

View Ticket
Ticket UUID: 00189c4afcb9e2586301d711f71383e48817a72d
Title: Allow semi-static UCRT build on Windows with VC 14.0
Type: Patch Version: 8.6.4
Submitter: anonymous Created on: 2015-08-18 19:02:43
Subsystem: 53. Configuration and Build Tools Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2015-10-09 12:45:17
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2015-10-09 12:45:17
With VC 14.0 (in Visual Studio 2015), the majority of the C Runtime (the "Universal CRT") has become a Windows component. In the next few months, it will be installed on all current versions of Windows via an update. This means that we can distribute libraries that depend on the CRT without having to include it, and those libraries will continue to work even as the CRT version changes.

However, there is a small part of the CRT that still depends on the compiler version. This patch adds a new build option "ucrt" that will statically link this part of the runtime and dynamically link the rest, resulting in binaries that only require the universal part of the C runtime.

The build of Tcl included with CPython 3.5 will use this build option, along with the rest of CPython itself. It is how we are achieving independence from the compiler version - by not sharing version specific dependencies we allow extensions to safely compile with different compiler versions, but without sacrificing the benefits of an OS-managed CRT.

The patch applied to 8.6.4 for CPython is at

This patch includes equivalent (nearly identical) changes for both Tcl and Tk.

We'd like to see the next official release include this option, or at least one that is substantially similar.

User Comments: jan.nijtmans added on 2015-10-09 12:45:17:
Everything seems to be working fine now, closing ....

oehhar added on 2015-08-28 15:46:08:

After a "repair" of VC14, all worked ok. I have made the vc6 build on my old vista32bit laptop.

So the result is: - Builds all ok Tcl+Tk - Sizes: tcl86t.dll: 1271k, tk86t.dll: 1508k - Compared to VC6: 1894k, 1402k

-> so the tcl dll is much smaller, the tk a bit larger

Here are the make status messages at the top:

*** Compiler has 'Optimizations'
*** Compiler does not have 'Pentium 0x0f fix'
*** Linker does not have 'Win98 alignment problem'
*** Intermediate directory will be '.\Release_VC13\tcl_ThreadedDynamic'
*** Output directory will be '.\Release_VC13'
*** Suffix for binaries will be 't'
*** Compiler version 13. Target machine is IX86
*** Host architecture is AMD64
*** Compiler options '-W3 -DUNICODE -D_UNICODE  -Ot -Oi -fp:strict -Gs -GS -GL  -RTC1 -W3'
*** Link options '-ltcg'

It says "VC Version 13". cl has version 19, link has version 14.

It links with the correct library:

	link -nologo -machine:IX86 -ltcg -release -opt:ref -opt:icf,3 -nodefaultlib:libucrt.lib -dll -base:@C:\test\Tcl_Source_Code-0e6e497bf3\win\..\win\coffbase.txt,tcl -out:.\Release_VC13\tcl86t.dll  netapi32.lib kernel32.lib user32.lib advapi32.lib ws2_32.lib ucrt.lib @C:\Users\oehhar\AppData\Local\Temp\nm87E2.tmp

New test failures compared to vc6: (one is on win 8.1 64bit, other on win vista 32 bit, may also explain the difference)

==== format-6.3 floating-point zeroes FAILED
==== Contents of test case:

    format "%#.4e %#.4f %#.4g" 0.0 0.0 0.0 0.0

---- Result was:
0.0000e+00 0.0000 0.0000
---- Result should have been (exact matching):
0.0000e+00 0.0000 0.000
==== format-6.3 FAILED

---- format-6.4 start
---- format-6.5 start

==== format-6.5 floating-point zeroes FAILED
==== Contents of test case:

    format "%#.0e %#.0f %#.0g" 0.0 0.0 0.0 0.0

---- Result was:
0.e+00 0. 0.0
---- Result should have been (exact matching):
0.e+00 0. 0.
==== format-6.5 FAILED

==== text-9.2.46 TextWidgetCmd procedure, "count" option FAILED
==== Contents of test case:

    for {set i 1} {$i < 5} {incr i} {
      #              0          1          2          3          4
      #              012345 678901234 567890123 456789012 34567890123456789
      .mytop.t insert end "Line $i+++Line $i---Line $i///Line $i - This is Line [format %c [expr 64+$i]]\n"
    .mytop.t tag configure hidden -elide true
    .mytop.t tag add hidden 2.15 3.10
    .mytop.t configure -wrap char
    lappend res [.mytop.t count -displaylines 2.0 3.0]
    lappend res [.mytop.t count -displaylines 2.0 3.40]

---- Result was:
0 3
---- Result should have been (exact matching):
1 3
==== text-9.2.46 FAILED

Thank you Jan, Harald

oehhar added on 2015-08-28 13:40:11:
Sorry Jan.
I tried today to build Tcl/Tk trunk with and VC6 and VC2015.
Nothing worked due to setup problems with the compilers.
- VC6 /PSDK2003 did not digest to install vc8 (which I have purchased for win ce)
- VS2015 community edition installs with 6 errors and does not start

Sorry, will be away for 2 weeks, someone else might help,

jan.nijtmans added on 2015-08-28 11:12:51:
Harald wrote:
> Nevertheless, the patch must be extended to the other make system which is also used for the vc compilers.

Done now for Tcl (Tk and TEA still to be done). No "ucrt" build options is added, as I think everyone should be encouraged to build Tcl this way, when VC14 is available.

I would appreciate anyone else to build and test Tcl using VC14 in either build system, and see if no obvious mistake was made. (Andreas??, Harald??)

anonymous (claiming to be Steve Dower) added on 2015-08-21 15:40:27:
"All current versions" is Vista and later, and the necessary DLL (ucrtbase.dll) can be redistributed for Windows XP (later versions need to use the proper installer so they can get security updates, but XP won't be getting those anyway).

VC 14 has an XP profile, so it can be used to target XP (IIRC you need at least Windows 7 - maybe SP1 - to run the compiler). I'm not sure how you get that support through nmake though, I think you'll need an actual vcxproj file.

Chances of getting a Microsoft built Tcl/Tk is *very* slim :) (though I am building the version that ships in CPython on company time, so maybe that counts? Won't work on XP though...)

jan.nijtmans added on 2015-08-21 11:39:36:
> In the next few months, it will be installed on all current versions of Windows via an update

What does "all current versions" mean? Windows 7/8/8.1?  Well, as long as Activestate is supporting XP and Vista, VC 14.0 cannot be used for official Tcl/Tk builds, but it certainly is good news for the future! If Microsoft
would provide a "universal" Tcl/Tk 8.6 build for Windows 7/8/8.1/10, I think
that would be great (although Activestate will probably disagree on that...)!

I'm using the mingw-w64 32-bit compiler if I want to produce binaries that still work on Windowx XP and Vista. (Sorry, Steve .......)   :-)

anonymous (claiming to be Steve Dower [OP]) added on 2015-08-20 15:26:22:
If extensions are built as DLLs, then they may *want* the change (for the same reasons - not needing to redistribute the VC redist they used), but it isn't necessary to work with Tcl or Tk DLLs/EXEs built with ucrt.

If Tcl/Tk are built as a static lib with the ucrt option then it will use the static CRT for release/unchecked (== no msvcrt) and the dynamic debug CRT DLL for debug. Whoever finally passes it to link.exe needs to be aware of these options to avoid breaking things. In general, I'd say don't use ucrt for published static libs - it needs coordination with the linker to avoid significant breakage.

Thanks for getting to this so quickly.

jan.nijtmans added on 2015-08-20 14:21:33:
Patch applied to both Tcl and Tk (core-8-5-branch and trunk). Thanks! Looks good to me.

Will the same change be needed for extensions (TEA) as well? I'll also have a look at the configure/make build environment. Therefore not closing this ticket yet.

oehhar added on 2015-08-19 07:33:09:
This sounds as good news. ActiveState (and myself) tend to compile with VC6 to avoid dll hell.

So maybee we may stop that in future.

Nevertheless, the patch must be extended to the other make system which is also used for the vc compilers.

I hope, someone will care...