Skip to content
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

Windows installer: install mingw libs and improve VS selection #281

Merged
merged 2 commits into from
Feb 17, 2018
Merged
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
37 changes: 35 additions & 2 deletions create_dmd_release/build_all.d
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,42 @@ void prepareExtraBins(string workDir)
"windbg.hlp", "ddemangle.exe", "lib.exe", "link.exe", "make.exe",
"replace.exe", "shell.exe", "windbg.exe", "dm.dll", "eecxxx86.dll",
"emx86.dll", "mspdb41.dll", "shcv.dll", "tlloc.dll", "libcurl.dll",
"lld-link.exe",
].addPrefix("bin/");
auto winBins64 = ["libcurl.dll"].addPrefix("bin64/");
auto mingwCoffLibs = [
"aclui.lib", "advapi32.lib", "avicap32.lib", "avifil32.lib", "bthprops.lib",
"cap.lib", "comctl32.lib", "comdlg32.lib", "crypt32.lib", "ctl3d32.lib",
"d3d8.lib", "d3d9.lib", "d3dim.lib", "d3drm.lib", "d3dx8d.lib", "d3dx9d.lib",
"d3dxof.lib", "ddraw.lib", "dhcpcsvc.lib", "dinput8.lib", "dinput.lib", "dlcapi.lib",
"dnsapi.lib", "dplayx.lib", "dpnaddr.lib", "dpnet.lib", "dpnlobby.lib", "dpvoice.lib",
"dsetup.lib", "dsound.lib", "faultrep.lib", "gdi32.lib", "gdiplus.lib", "glaux.lib",
"glu32.lib", "icmui.lib", "igmpagnt.lib", "imagehlp.lib", "imm32.lib", "iphlpapi.lib",
"kernel32.lib", "ksproxy.lib", "ksuser.lib", "lz32.lib", "mapi32.lib", "mfcuia32.lib",
"mgmtapi.lib", "mprapi.lib", "mpr.lib", "mqrt.lib", "msacm32.lib", "mscms.lib",
"msdmo.lib", "msimg32.lib", "msvcp60.lib", "msvcrt100.lib", "msvfw32.lib",
"mswsock.lib", "nddeapi.lib", "netapi32.lib", "ntdll.lib", "odbc32.lib",
"odbccp32.lib", "oldnames.lib", "ole32.lib", "oleacc.lib", "oleaut32.lib",
"olecli32.lib", "oledlg.lib", "olepro32.lib", "olesvr32.lib", "opengl32.lib",
"penwin32.lib", "pkpd32.lib", "powrprof.lib", "psapi.lib", "quartz.lib",
"rapi.lib", "rasapi32.lib", "rasdlg.lib", "rpcdce4.lib", "rpcns4.lib", "rpcrt4.lib",
"rtm.lib", "rtutils.lib", "secur32.lib", "setupapi.lib", "shell32.lib", "shfolder.lib",
"shlwapi.lib", "snmpapi.lib", "svrapi.lib", "tapi32.lib", "thunk32.lib",
"url.lib", "user32.lib", "userenv.lib", "usp10.lib", "uuid.lib", "uxtheme.lib",
"vdmdbg.lib", "version.lib", "win32spl.lib", "wininet.lib", "winmm.lib",
"winspool.lib", "winstrm.lib", "wldap32.lib", "wow32.lib", "ws2_32.lib",
"wsnmp32.lib", "wsock32.lib", "wst.lib", "wtsapi32.lib",
];
auto winLibs = [
"advapi32.lib", "COMCTL32.LIB", "comdlg32.lib", "CTL3D32.LIB",
"gdi32.lib", "kernel32.lib", "ODBC32.LIB", "ole32.lib", "OLEAUT32.LIB",
"rpcrt4.lib", "shell32.lib", "snn.lib", "user32.lib", "uuid.lib",
"winmm.lib", "winspool.lib", "WS2_32.LIB", "wsock32.lib", "curl.lib",
"update_libs.bat",
].addPrefix("lib/");
auto winLibs64 = ["curl.lib"].addPrefix("lib64/");
auto winFiles = chain(winBins, winBins64, winLibs, winLibs64).array();
auto winLibs32Coff = (mingwCoffLibs ~ "curl.lib").addPrefix("lib32mscoff/");
auto winLibs64 = (mingwCoffLibs ~ "curl.lib").addPrefix("lib64/");
auto winFiles = chain(winBins, winBins64, winLibs, winLibs32Coff, winLibs64).array();

auto extraBins = [
windows_both : winFiles,
Expand Down Expand Up @@ -460,6 +485,8 @@ int main(string[] args)
enum libC = "snn.lib";
enum libCurl = "libcurl-7.52.1-WinSSL-zlib-x86-x64.zip";
enum omflibs = "omflibs-winsdk-10.0.16299.15.zip";
enum mingwlibs = "mingw-libs-5.0.2.zip";
enum lld = "lld-link-5.0.1.zip";

auto oldCompilers = platforms
.map!(p => "dmd.%1$s.%2$s.%3$s".format(oldVer, p, p.os == OS.windows ? "7z" : "tar.xz"));
Expand All @@ -470,6 +497,8 @@ int main(string[] args)
fetchFile("http://ftp.digitalmars.com/"~libC, cacheDir~"/"~libC);
fetchFile("http://downloads.dlang.org/other/"~libCurl, cacheDir~"/"~libCurl, true);
fetchFile("http://downloads.dlang.org/other/"~omflibs, cacheDir~"/"~omflibs, true);
fetchFile("http://downloads.dlang.org/other/"~mingwlibs, cacheDir~"/"~mingwlibs, true);
fetchFile("http://downloads.dlang.org/other/"~lld, cacheDir~"/"~lld, true);

// Unpack previous dmd release
foreach (platform, oldCompiler; platforms.zip(oldCompilers))
Expand All @@ -487,6 +516,10 @@ int main(string[] args)
extract(cacheDir~"/"~libCurl, workDir~"/windows/old-dmd/");
// Get updated OMF import libraries
extract(cacheDir~"/"~omflibs, workDir~"/windows/old-dmd/dmd2/windows/lib/");
// Get mingw coff libraries
extract(cacheDir~"/"~mingwlibs, workDir~"/windows/old-dmd/");
// Get lld-link.exe
extract(cacheDir~"/"~lld, workDir~"/windows/old-dmd/dmd2/windows/bin/");
}

cloneSources(gitTag, dubTag, isBranch, skipDocs, workDir~"/clones");
Expand Down
3 changes: 2 additions & 1 deletion windows/d2-installer-descriptions.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

; Sections
LangString DESC_Dmd2Files ${LANG_ENGLISH} "Digital Mars D version 2 compiler"
LangString DESC_SMShortcuts ${LANG_ENGLISH} "Add Shortcuts to the Start Menu to start the command interpreter with adjusted environment"
LangString DESC_AddD2ToPath ${LANG_ENGLISH} "Modify the PATH environment variable so DMD can be used from any command prompt"

LangString DESC_VisualDDownload ${LANG_ENGLISH} "Visual Studio package providing both project management and language services. It works with Visual Studio 2008-2017 (and the free VS Shells)"
LangString DESC_DmcDownload ${LANG_ENGLISH} "Digital Mars C/C++ compiler"
LangString DESC_Dmd1Download ${LANG_ENGLISH} "Digital Mars D version 1 compiler (discontinued)"



; Shortcuts
LangString SHORTCUT_Uninstall ${LANG_ENGLISH} "Uninstall"

Expand All @@ -21,6 +21,7 @@ LangString SHORTCUT_Uninstall ${LANG_ENGLISH} "Uninstall"

!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${Dmd2Files} $(DESC_Dmd2Files)
!insertmacro MUI_DESCRIPTION_TEXT ${StartMenuShortcuts} $(DESC_SMShortcuts)
!insertmacro MUI_DESCRIPTION_TEXT ${AddD2ToPath} $(DESC_AddD2ToPath)
!insertmacro MUI_DESCRIPTION_TEXT ${VisualDDownload} $(DESC_VisualDDownload)
!insertmacro MUI_DESCRIPTION_TEXT ${DmcDownload} $(DESC_DmcDownload)
Expand Down
199 changes: 93 additions & 106 deletions windows/d2-installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@
!define VisualDFilename "VisualD-v${VersionVisualD}.exe"
!define DmcFilename "dmc-${VersionDMC}.exe"
!define Dmd1Filename "dmd-${Version1}.exe"
!define VS2013Filename "vs_community.exe"
!define VS2013Filename "vs_community2013.exe"
!define VS2017Filename "vs_community2017.exe"
!define VS2017BTFilename "vs_BuildTools2017.exe"
!define VCRedistx86Filename "vcredist_x86.exe"
!define VCRedistx64Filename "vcredist_x64.exe"

; URLs
!define BaseURL "http://downloads.dlang.org"
Expand All @@ -71,7 +75,18 @@
!define Dmd1AltUrl "${BaseURLAlt}/${Dmd1Filename}"

!define VS2013Url "http://go.microsoft.com/fwlink/?LinkId=517284"
!define VS2017Url "https://download.visualstudio.microsoft.com/download/pr/100404311/045b56eb413191d03850ecc425172a7d/vs_Community.exe"
!define VS2017BuildToolsUrl "https://download.visualstudio.microsoft.com/download/pr/100404314/e64d79b40219aea618ce2fe10ebd5f0d/vs_BuildTools.exe"

; see https://stackoverflow.com/questions/12206314/detect-if-visual-c-redistributable-for-visual-studio-2012-is-installed/14878248
; selecting VC2010
!define VCRedistx86Url "https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x86.exe"
!define VCRedistx64Url "https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x64.exe"

!define VCRedistx86RegKey "SOFTWARE\Classes\Installer\Products\1926E8D15D0BCE53481466615F760A7F"
!define VCRedistx64RegKey "SOFTWARE\Classes\Installer\Products\1D5E3C0FEDA1E123187686FED06E995A"

; ----------------
; Publishing Details
!define DPublisher "Digital Mars"
!define DName "DMD"
Expand All @@ -92,10 +107,9 @@

!include "MUI.nsh"
!include "EnvVarUpdate.nsh"
!include "ReplaceInFile.nsh"
!include "FileFunc.nsh"
!include "TextFunc.nsh"

!include "Sections.nsh"

;------------------------------------------------------------
; Variables
Expand All @@ -107,9 +121,6 @@ Var K
Var InstanceCheck
Var VCVer
Var VCPath
Var WinSDKPath
Var UCRTPath
Var UCRTVersion


;--------------------------------------------------------
Expand Down Expand Up @@ -152,25 +163,25 @@ SetCompressor /SOLID lzma
!macro DownloadAndRun Filename Url AltUrl
inetc::get /CAPTION "Downloading ${Filename}..." /BANNER "" "${Url}" "$TEMP\${Filename}"
Pop $0
StrCmp $0 "OK" run
StrCmp $0 "OK" run_${Filename}
!if `${AltUrl}` != ""
inetc::get /CAPTION "Downloading ${Filename}..." /BANNER "" "${AltUrl}" "$TEMP\${Filename}"
Pop $0
StrCmp $0 "OK" run
StrCmp $0 "OK" run_${Filename}
!endif

; failed
MessageBox MB_OK|MB_ICONEXCLAMATION "Could not download ${Filename}$\r$\n$\r$\n${Url}" /SD IDOK

Goto dandr_done
Goto dandr_done_${Filename}

run:
run_${Filename}:
DetailPrint "Running ${Filename}"
ExecWait "$TEMP\${Filename}"

Delete "$TEMP\${Filename}"

dandr_done:
dandr_done_${Filename}:
!macroend

; Read SDK registry entry and check if kernel32.lib exists in the expected lib folder
Expand Down Expand Up @@ -211,6 +222,7 @@ SetCompressor /SOLID lzma
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
Page custom VCInstallPage VCInstallPageValidate
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

Expand Down Expand Up @@ -245,7 +257,7 @@ SectionGroup /e "D2"

; Embed the directory specified
File /r ${EmbedD2Dir}

; Create 32-bit command line batch file
FileOpen $0 "$INSTDIR\dmd2vars32.bat" w
FileWrite $0 "@echo.$\n"
Expand Down Expand Up @@ -278,38 +290,6 @@ SectionGroup /e "D2"
WriteRegDWORD HKLM "${ARP}" "NoModify" 1
WriteRegDWORD HKLM "${ARP}" "NoRepair" 1
WriteUninstaller "uninstall.exe"

StrCmp $VCVer "" no_vc_detected write_vc_path

no_vc_detected:
MessageBox MB_OK "Could not detect Visual Studio (2008-2017 are supported). No 64-bit support." /SD IDOK
goto finish_vc_path

write_vc_path:
!insertmacro _ReplaceInFile "$INSTDIR\dmd2\windows\bin\sc.ini" ";VCINSTALLDIR=" "VCINSTALLDIR=$VCPath"
!insertmacro _ReplaceInFile "$INSTDIR\dmd2\windows\bin\sc.ini" ";$VCVer " ""

finish_vc_path:
ClearErrors

StrCmp $WinSDKPath "" no_sdk_detected write_sdk_path

no_sdk_detected:
MessageBox MB_OK "Could not detect Windows SDK (6.0A-10.0 are supported). No 64-bit support." /SD IDOK
goto finish_sdk_path

write_sdk_path:
!insertmacro _ReplaceInFile "$INSTDIR\dmd2\windows\bin\sc.ini" ";WindowsSdkDir=" "WindowsSdkDir=$WinSDKPath"

finish_sdk_path:
ClearErrors

StrCmp $UCRTVersion "" no_ucrt_detected
!insertmacro _ReplaceInFile "$INSTDIR\dmd2\windows\bin\sc.ini" ";UniversalCRTSdkDir=" "UniversalCRTSdkDir=$UCRTPath"
!insertmacro _ReplaceInFile "$INSTDIR\dmd2\windows\bin\sc.ini" ";UCRTVersion=" "UCRTVersion=$UCRTVersion"
no_ucrt_detected:
ClearErrors

SectionEnd


Expand Down Expand Up @@ -344,11 +324,79 @@ SectionGroup /e "Extras"
SectionEnd
SectionGroupEnd

;--------------------------------------------------------
; Custom page
;--------------------------------------------------------

Function VCInstallPage

Call DetectVC
StrCmp $VCVer "" ask_vs
Abort
ask_vs:

ReserveFile "vcinstall.ini"
!insertmacro MUI_HEADER_TEXT "Choose Visual Studio Installation" "Choose the Visual C runtime to link against"
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "vcinstall.ini"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "vcinstall.ini"

FunctionEnd

Function VCInstallPageValidate

!insertmacro MUI_INSTALLOPTIONS_READ $0 "vcinstall.ini" "Field 2" "State"
StrCmp $0 1 install_vs2013
!insertmacro MUI_INSTALLOPTIONS_READ $0 "vcinstall.ini" "Field 3" "State"
StrCmp $0 1 install_vs2017
!insertmacro MUI_INSTALLOPTIONS_READ $0 "vcinstall.ini" "Field 4" "State"
StrCmp $0 1 install_bt2017
!insertmacro MUI_INSTALLOPTIONS_READ $0 "vcinstall.ini" "Field 5" "State"
StrCmp $0 1 install_vc2010
goto done_vc

install_vs2013:
!insertmacro DownloadAndRun ${VS2013Filename} ${VS2013Url} ""
goto done_vc

install_vs2017:
!insertmacro DownloadAndRun ${VS2017Filename} ${VS2017Url} ""
goto done_vc

install_bt2017:
!insertmacro DownloadAndRun ${VS2017BTFilename} ${VS2017BuildToolsUrl} ""
goto done_vc

install_vc2010:
Call InstallVCRedistributable
goto done_vc

done_vc:

FunctionEnd

;--------------------------------------------------------
; Helper functions
;--------------------------------------------------------

Function DetectVSAndSDK
Function InstallVCRedistributable

SetRegView 64 ; look at the 64-bit registry hive if available
ClearErrors
ReadRegStr $0 HKLM "${VCRedistx86RegKey}" "ProductName"
IfErrors 0 vcredistx86_installed
!insertmacro DownloadAndRun ${VCRedistx86Filename} ${VCRedistx86Url} ""
vcredistx86_installed:

ClearErrors
ReadRegStr $0 HKLM "${VCRedistx64RegKey}" "ProductName"
IfErrors 0 vcredistx64_installed
!insertmacro DownloadAndRun ${VCRedistx64Filename} ${VCRedistx64Url} ""
vcredistx64_installed:
SetRegView 32 ; retore default

FunctionEnd

Function DetectVC
ClearErrors

ReadRegStr $0 HKLM "SOFTWARE\Microsoft\VisualStudio\SxS\VS7" "15.0"
Expand Down Expand Up @@ -383,52 +431,8 @@ Function DetectVSAndSDK
done_vs:
StrCpy $VCPath $0
StrCpy $VCVer $1

; detect ucrt
ReadRegStr $0 HKLM "Software\Microsoft\Windows Kits\Installed Roots" "KitsRoot10"
IfErrors done done_ucrt

done_ucrt:
StrCpy $UCRTPath $0

StrCpy $UCRTVersion ""
FindFirst $0 $1 $UCRTPath\Lib\*.*
loop_ff:
StrCmp $1 "" done_ff
StrCpy $UCRTVersion $1 ; hoping the directory is retrieved in ascending order (done by NTFS)
FindNext $0 $1
Goto loop_ff
done_ff:
FindClose $0

done:

!insertmacro _DetectSDK "Windows Kits\Installed Roots" "KitsRoot10" "Lib\$UCRTVersion\um\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Windows Kits\Installed Roots" "KitsRoot81" "Lib\winv6.3\um\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Microsoft SDKs\Windows\v8.1" "InstallationFolder" "Lib\winv6.3\um\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Microsoft SDKs\Windows\v8.1A" "InstallationFolder" "Lib\winv6.3\um\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Windows Kits\Installed Roots" "KitsRoot" "Lib\win8\um\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Microsoft SDKs\Windows\v8.0" "InstallationFolder" "Lib\win8\um\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Microsoft SDKs\Windows\v8.0A" "InstallationFolder" "Lib\win8\um\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Microsoft SDKs\Windows\v7.1A" "InstallationFolder" "Lib\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Microsoft SDKs\Windows\v7.0A" "InstallationFolder" "Lib\x64"
IfErrors 0 done_sdk
!insertmacro _DetectSDK "Microsoft SDKs\Windows\v6.0A" "InstallationFolder" "Lib\x64"
IfErrors no_sdk done_sdk

done_sdk:
StrCpy $WinSDKPath $0

no_sdk:

FunctionEnd

;--------------------------------------------------------
Expand Down Expand Up @@ -502,23 +506,6 @@ Function .onInit
Exec '$R0 /IC False /S'

done_uninst:

Call DetectVSAndSDK
StrCmp $VCVer "" ask_vs
StrCmp $WinSDKPath "" ask_vs
Goto done_vs

ask_vs:
MessageBox MB_YESNO|MB_ICONQUESTION \
"For 64-bit support MSVC and the Windows SDK are needed but no compatible versions were found. Do you want to install VS2013?" \
/SD IDNO IDYES install_vs IDNO done_vs

install_vs:
!insertmacro DownloadAndRun ${VS2013Filename} ${VS2013Url} ""
Call DetectVSAndSDK

done_vs:

FunctionEnd


Expand Down
Loading