From 7235ad9f40fbbf27b9fd1097817587e892690556 Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Fri, 23 Oct 2015 16:14:18 +0800 Subject: Automatically setup MSVC command line tools for VC2008 or above. --- install.bat | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/install.bat b/install.bat index 57e3611c..90e9b8d4 100644 --- a/install.bat +++ b/install.bat @@ -409,6 +409,25 @@ local function get_architecture() return proc end +-- uses vars.LUA_RUNTIME and vars.UNAME_M +local function get_compiler_env_cmd() + local major, minor = vars.LUA_RUNTIME:match('^MSVCR(%d+)(%d)$') + if not major then return "" end + local key = "HKEY_LOCAL_MACHINE\\SOFTWARE%s\\Microsoft\\VisualStudio\\%d.%d" + local hostarch64 = os.getenv("ProgramFiles(x86)")~=nil -- 'PROCESSOR_ARCHITECTURE' will always return 'x86' if interpreter is 32 bit. + key = key:format(hostarch64 and "\\Wow6432Node" or "", major, minor) + + local h = io.popen('reg query "'..key..'" /v InstallDir 2>NUL') + local output = h:read('*a') + h:close() + + local msvcdir = output:match("REG_SZ%s+(.+)\\Common7\\IDE") + if not msvcdir then return "" end + local msvcarch = vars.UNAME_M=="x86_64" and " x86_amd64" or "" + + return ('call "%s\\VC\\vcvarsall.bat"%s'):format(msvcdir, msvcarch) +end + local function look_for_lua_install () print("Looking for Lua interpreter") local directories @@ -627,6 +646,7 @@ if SELFCONTAINED then vars.TREE_ROOT = vars.PREFIX..[[\systree]] REGISTRY = false end +vars.COMPILER_ENV_CMD = get_compiler_env_cmd(vars.LUA_RUNTIME, vars.UNAME_M) print(S[[ @@ -731,6 +751,7 @@ for _, c in ipairs{"luarocks", "luarocks-admin"} do f:write(S[[ @ECHO OFF SETLOCAL +$COMPILER_ENV_CMD SET "LUA_PATH=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH%" IF NOT "%LUA_PATH_5_2%"=="" ( SET "LUA_PATH_5_2=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH_5_2%" -- cgit v1.2.3-55-g6feb From e5aa0e030f061d7bb9f7bd7f57d379619a9f4a4a Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Sat, 24 Oct 2015 14:41:50 +0800 Subject: Better setup vc compiler, should compatible with Windows SDK. 1. Use reg: HKEY_LOCAL_MACHINE\SOFTWARE[\Wow6432Node]\Microsoft\VisualStudio\\Setup\VC:ProductDir 2. Use bin\vcvars32.bat and bin\amd64\vcvars64.bat instead of vcvarsall.bat. --- install.bat | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/install.bat b/install.bat index 90e9b8d4..533a0700 100644 --- a/install.bat +++ b/install.bat @@ -409,23 +409,40 @@ local function get_architecture() return proc end --- uses vars.LUA_RUNTIME and vars.UNAME_M -local function get_compiler_env_cmd() +-- get a string value from windows registry. +local function get_registry(key, value) + local h = io.popen('reg query "'..key..'" /v '..value..' 2>NUL') + local output = h:read('*a') + h:close() + + return output:match('REG_SZ%s+([^\n]+)') +end + +local function visual_studio_registry_key(major, minor) + local key = "HKEY_LOCAL_MACHINE\\SOFTWARE%s\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC" + -- os.getenv('PROCESSOR_ARCHITECTURE') will always return 'x86' if lua interpreter is 32 bit. + local hostarch64 = os.getenv("ProgramFiles(x86)")~=nil + return key:format(hostarch64 and "\\Wow6432Node" or "", major, minor) +end + +-- returns the batch command to setup msvc compiler path. +-- requires vars.LUA_RUNTIME and vars.UNAME_M to be set before calling this function. +local function get_vc_env_setup_cmd() + -- 1. check installed lua runtime version local major, minor = vars.LUA_RUNTIME:match('^MSVCR(%d+)(%d)$') if not major then return "" end - local key = "HKEY_LOCAL_MACHINE\\SOFTWARE%s\\Microsoft\\VisualStudio\\%d.%d" - local hostarch64 = os.getenv("ProgramFiles(x86)")~=nil -- 'PROCESSOR_ARCHITECTURE' will always return 'x86' if interpreter is 32 bit. - key = key:format(hostarch64 and "\\Wow6432Node" or "", major, minor) - local h = io.popen('reg query "'..key..'" /v InstallDir 2>NUL') - local output = h:read('*a') - h:close() + -- 2. check if required VC version is in registry + local product_dir = get_registry(visual_studio_registry_key(major, minor), 'ProductDir') + + if not product_dir then return "" end - local msvcdir = output:match("REG_SZ%s+(.+)\\Common7\\IDE") - if not msvcdir then return "" end - local msvcarch = vars.UNAME_M=="x86_64" and " x86_amd64" or "" + -- 4. check VC batch file exists + local relative_path = vars.UNAME_M=="x86_64" and "bin\\amd64\\vcvars64.bat" or "bin\\vcvars32.bat" + local full_path = product_dir .. relative_path + if not exists(full_path) then return "" end - return ('call "%s\\VC\\vcvarsall.bat"%s'):format(msvcdir, msvcarch) + return ('call "%s"'):format(full_path) end local function look_for_lua_install () @@ -646,7 +663,7 @@ if SELFCONTAINED then vars.TREE_ROOT = vars.PREFIX..[[\systree]] REGISTRY = false end -vars.COMPILER_ENV_CMD = get_compiler_env_cmd(vars.LUA_RUNTIME, vars.UNAME_M) +vars.COMPILER_ENV_CMD = get_vc_env_setup_cmd(vars.LUA_RUNTIME, vars.UNAME_M) print(S[[ -- cgit v1.2.3-55-g6feb From d4b2ec1aa1291ec2b06ba161bc960fb848b98132 Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Tue, 27 Oct 2015 00:19:19 +0800 Subject: Better msvc compiler setup compatibility. 1. Use vcvarsall.bat if exists. 2. Use vcvars32.bat / vcvars64.bat if exists. 3. Do no compiler env setup in luarocks.bat if 1 and 2 are both not exists. --- install.bat | 54 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/install.bat b/install.bat index 533a0700..d2ab2976 100644 --- a/install.bat +++ b/install.bat @@ -411,38 +411,48 @@ end -- get a string value from windows registry. local function get_registry(key, value) - local h = io.popen('reg query "'..key..'" /v '..value..' 2>NUL') - local output = h:read('*a') - h:close() + local h = io.popen('reg query "'..key..'" /v '..value..' 2>NUL') + local output = h:read('*a') + h:close() - return output:match('REG_SZ%s+([^\n]+)') + return output:match('REG_SZ%s+([^\n]+)') end local function visual_studio_registry_key(major, minor) - local key = "HKEY_LOCAL_MACHINE\\SOFTWARE%s\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC" - -- os.getenv('PROCESSOR_ARCHITECTURE') will always return 'x86' if lua interpreter is 32 bit. - local hostarch64 = os.getenv("ProgramFiles(x86)")~=nil - return key:format(hostarch64 and "\\Wow6432Node" or "", major, minor) + local key = "HKLM\\SOFTWARE%s\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC" + -- os.getenv('PROCESSOR_ARCHITECTURE') will always return 'x86' if lua interpreter is 32 bit. + local hostx64 = os.getenv("ProgramFiles(x86)")~=nil + return key:format(hostx64 and "\\Wow6432Node" or "", major, minor) +end + +-- requires vars.LUA_RUNTIME to be set before calling this function. +local function get_visual_studio_directory() + local major, minor = vars.LUA_RUNTIME:match('VCR%u*(%d+)(%d)$') -- MSVCR or VCRUNTIME + if not major then return "" end + + return get_registry(visual_studio_registry_key(major, minor), 'ProductDir') end -- returns the batch command to setup msvc compiler path. -- requires vars.LUA_RUNTIME and vars.UNAME_M to be set before calling this function. -local function get_vc_env_setup_cmd() - -- 1. check installed lua runtime version - local major, minor = vars.LUA_RUNTIME:match('^MSVCR(%d+)(%d)$') - if not major then return "" end +local function get_msvc_env_setup_cmd() + local product_dir = get_visual_studio_directory() + local x64 = vars.UNAME_M=="x86_64" - -- 2. check if required VC version is in registry - local product_dir = get_registry(visual_studio_registry_key(major, minor), 'ProductDir') - - if not product_dir then return "" end + -- 1. try vcvarsall.bat + local vcvarsall = product_dir .. 'vcvarsall.bat' + if exists(vcvarsall) then + return ('call "%s"%s'):format(vcvarsall, x64 and ' amd64' or '') + end - -- 4. check VC batch file exists - local relative_path = vars.UNAME_M=="x86_64" and "bin\\amd64\\vcvars64.bat" or "bin\\vcvars32.bat" - local full_path = product_dir .. relative_path - if not exists(full_path) then return "" end + -- 2. try vcvars32.bat / vcvars64.bat + local relative_path = x64 and "bin\\amd64\\vcvars64.bat" or "bin\\vcvars32.bat" + local full_path = product_dir .. relative_path + if exists(full_path) then + return ('call "%s"'):format(full_path) + end - return ('call "%s"'):format(full_path) + return "" end local function look_for_lua_install () @@ -663,7 +673,7 @@ if SELFCONTAINED then vars.TREE_ROOT = vars.PREFIX..[[\systree]] REGISTRY = false end -vars.COMPILER_ENV_CMD = get_vc_env_setup_cmd(vars.LUA_RUNTIME, vars.UNAME_M) +vars.COMPILER_ENV_CMD = get_msvc_env_setup_cmd() print(S[[ -- cgit v1.2.3-55-g6feb From a5cec1848d8318f4ea8f28daf2f221d71178cf5d Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Tue, 27 Oct 2015 00:23:01 +0800 Subject: Add comments about Windows SDKs. --- install.bat | 3 +++ 1 file changed, 3 insertions(+) diff --git a/install.bat b/install.bat index d2ab2976..de572d3d 100644 --- a/install.bat +++ b/install.bat @@ -452,6 +452,9 @@ local function get_msvc_env_setup_cmd() return ('call "%s"'):format(full_path) end + -- 3. TODO: add support for Windows SDKs here. + + -- finaly, we can't detect more, just don't setup the msvc compiler in luarocks.bat. return "" end -- cgit v1.2.3-55-g6feb From 04e45199b0a76808fce9850713ba8e79a47cb9fd Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Tue, 27 Oct 2015 00:35:51 +0800 Subject: Don't setup msvc when user desires MinGW. --- install.bat | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install.bat b/install.bat index de572d3d..c3099988 100644 --- a/install.bat +++ b/install.bat @@ -436,6 +436,8 @@ end -- returns the batch command to setup msvc compiler path. -- requires vars.LUA_RUNTIME and vars.UNAME_M to be set before calling this function. local function get_msvc_env_setup_cmd() + if USE_MINGW then return "" end -- Don't setup msvc for MinGW. + local product_dir = get_visual_studio_directory() local x64 = vars.UNAME_M=="x86_64" -- cgit v1.2.3-55-g6feb From 00184f35d70af9b2cf746e8a2de156d06c88101b Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Tue, 27 Oct 2015 00:39:07 +0800 Subject: Move mingw test out of get_msvc_env_setup_cmd(). --- install.bat | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/install.bat b/install.bat index c3099988..cfc5f074 100644 --- a/install.bat +++ b/install.bat @@ -436,8 +436,6 @@ end -- returns the batch command to setup msvc compiler path. -- requires vars.LUA_RUNTIME and vars.UNAME_M to be set before calling this function. local function get_msvc_env_setup_cmd() - if USE_MINGW then return "" end -- Don't setup msvc for MinGW. - local product_dir = get_visual_studio_directory() local x64 = vars.UNAME_M=="x86_64" @@ -678,7 +676,7 @@ if SELFCONTAINED then vars.TREE_ROOT = vars.PREFIX..[[\systree]] REGISTRY = false end -vars.COMPILER_ENV_CMD = get_msvc_env_setup_cmd() +vars.COMPILER_ENV_CMD = USE_MINGW and "" or get_msvc_env_setup_cmd() print(S[[ -- cgit v1.2.3-55-g6feb From 4c3b41e765cf42afecfba8e32965e5c057c96870 Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Sun, 1 Nov 2015 13:35:33 +0800 Subject: Add support for Windows SDK v7.1 and v6.1. Other Windows SDK versions requires a separate installation of Visual Studio. --- install.bat | 84 +++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 24 deletions(-) diff --git a/install.bat b/install.bat index cfc5f074..0514af1b 100644 --- a/install.bat +++ b/install.bat @@ -411,48 +411,84 @@ end -- get a string value from windows registry. local function get_registry(key, value) - local h = io.popen('reg query "'..key..'" /v '..value..' 2>NUL') - local output = h:read('*a') - h:close() + local keys = {key} + local key64, replaces = key:gsub("(%u+\\SOFTWARE\\)", "\1Wow6432Node\\", 1) + if replaces == 0 then + key64, replaces = key:gsub("(%u+\\Software\\)", "\1Wow6432Node\\", 1) + end - return output:match('REG_SZ%s+([^\n]+)') -end + if replaces == 1 then + table.insert(keys, 1, key64) + end + + for _, k in ipairs(keys) do + local h = io.popen('reg query "'..k..'" /v '..value..' 2>NUL') + local output = h:read('*a') + h:close() -local function visual_studio_registry_key(major, minor) - local key = "HKLM\\SOFTWARE%s\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC" - -- os.getenv('PROCESSOR_ARCHITECTURE') will always return 'x86' if lua interpreter is 32 bit. - local hostx64 = os.getenv("ProgramFiles(x86)")~=nil - return key:format(hostx64 and "\\Wow6432Node" or "", major, minor) + local v = output:match('REG_SZ%s+([^\n]+)') + if v then + return v + end + end + return nil end -- requires vars.LUA_RUNTIME to be set before calling this function. local function get_visual_studio_directory() local major, minor = vars.LUA_RUNTIME:match('VCR%u*(%d+)(%d)$') -- MSVCR or VCRUNTIME if not major then return "" end - - return get_registry(visual_studio_registry_key(major, minor), 'ProductDir') + local key = ("HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC"):format(major, minor) + return get_registry(key, 'ProductDir') end +-- requires vars.LUA_RUNTIME to be set before calling this function. +local function get_windows_sdk_directory() + -- Only v7.1 and v6.1 shipped with compilers + -- Other versions requires a separate installation of Visual Studio. + -- see https://github.com/keplerproject/luarocks/pull/443#issuecomment-152792516 + local wsdks = { + ["MSVCR100"] = "v7.1", -- shipped with Visual Studio 2010 compilers. + ["MSVCR90"] = "v6.1", -- shipped with Visual Studio 2008 compilers. + } + local wsdkver = wsdks[vars.LUA_RUNTIME] + if not wsdkver then + return nil + end + + local key = "HKLM\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\"..wsdkver + return get_registry(key, 'InstallationFolder') +end -- returns the batch command to setup msvc compiler path. -- requires vars.LUA_RUNTIME and vars.UNAME_M to be set before calling this function. local function get_msvc_env_setup_cmd() - local product_dir = get_visual_studio_directory() local x64 = vars.UNAME_M=="x86_64" - -- 1. try vcvarsall.bat - local vcvarsall = product_dir .. 'vcvarsall.bat' - if exists(vcvarsall) then - return ('call "%s"%s'):format(vcvarsall, x64 and ' amd64' or '') - end + -- 1. try visual studio command line tools + local vcdir = get_visual_studio_directory() + if vcdir then + -- 1.1. try vcvarsall.bat + local vcvarsall = vcdir .. 'vcvarsall.bat' + if exists(vcvarsall) then + return ('call "%s"%s'):format(vcvarsall, x64 and ' amd64' or '') + end - -- 2. try vcvars32.bat / vcvars64.bat - local relative_path = x64 and "bin\\amd64\\vcvars64.bat" or "bin\\vcvars32.bat" - local full_path = product_dir .. relative_path - if exists(full_path) then - return ('call "%s"'):format(full_path) + -- 1.2. try vcvars32.bat / vcvars64.bat + local relative_path = x64 and "bin\\amd64\\vcvars64.bat" or "bin\\vcvars32.bat" + local full_path = vcdir .. relative_path + if exists(full_path) then + return ('call "%s"'):format(full_path) + end end - -- 3. TODO: add support for Windows SDKs here. + -- 2. try for Windows SDKs command line tools. + local wsdkdir = get_windows_sdk_directory() + if wsdkdir then + local setenv = wsdkdir.."Bin\\SetEnv.cmd" + if exists(setenv) then + return ("call \"%s\" /Release /%s"):format(setenv, x64 and "x64" or "x86") + end + end -- finaly, we can't detect more, just don't setup the msvc compiler in luarocks.bat. return "" -- cgit v1.2.3-55-g6feb From 21839814515a42e9c2da4a9cbc28029bddbab43e Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Sun, 1 Nov 2015 14:08:09 +0800 Subject: Support Visual Studio Express Editions and cleanup code. --- install.bat | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/install.bat b/install.bat index 0514af1b..01461667 100644 --- a/install.bat +++ b/install.bat @@ -412,21 +412,18 @@ end -- get a string value from windows registry. local function get_registry(key, value) local keys = {key} - local key64, replaces = key:gsub("(%u+\\SOFTWARE\\)", "\1Wow6432Node\\", 1) - if replaces == 0 then - key64, replaces = key:gsub("(%u+\\Software\\)", "\1Wow6432Node\\", 1) - end + local key64, replaced = key:gsub("(%u+\\Software\\)", "\1Wow6432Node\\", 1) - if replaces == 1 then - table.insert(keys, 1, key64) + if replaced == 1 then + keys = {key64, key} end for _, k in ipairs(keys) do local h = io.popen('reg query "'..k..'" /v '..value..' 2>NUL') - local output = h:read('*a') + local output = h:read("*a") h:close() - local v = output:match('REG_SZ%s+([^\n]+)') + local v = output:match("REG_SZ%s+([^\n]+)") if v then return v end @@ -437,9 +434,16 @@ end -- requires vars.LUA_RUNTIME to be set before calling this function. local function get_visual_studio_directory() local major, minor = vars.LUA_RUNTIME:match('VCR%u*(%d+)(%d)$') -- MSVCR or VCRUNTIME - if not major then return "" end - local key = ("HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC"):format(major, minor) - return get_registry(key, 'ProductDir') + if not major then return nil end + local keys = { + "HKLM\\Software\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC", + "HKLM\\Software\\Microsoft\\VCExpress\\%d.%d\\Setup\\VS" + } + for _, key in ipairs(keys) do + local vcdir = get_registry(key:format(major, minor), "ProductDir") + if vcdir then return vcdir end + end + return nil end -- requires vars.LUA_RUNTIME to be set before calling this function. @@ -456,8 +460,8 @@ local function get_windows_sdk_directory() return nil end - local key = "HKLM\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\"..wsdkver - return get_registry(key, 'InstallationFolder') + local key = "HKLM\\Software\\Microsoft\\Microsoft SDKs\\Windows\\"..wsdkver + return get_registry(key, "InstallationFolder") end -- returns the batch command to setup msvc compiler path. -- requires vars.LUA_RUNTIME and vars.UNAME_M to be set before calling this function. @@ -486,7 +490,7 @@ local function get_msvc_env_setup_cmd() if wsdkdir then local setenv = wsdkdir.."Bin\\SetEnv.cmd" if exists(setenv) then - return ("call \"%s\" /Release /%s"):format(setenv, x64 and "x64" or "x86") + return ('call "%s" /Release /%s'):format(setenv, x64 and "x64" or "x86") end end -- cgit v1.2.3-55-g6feb From c9ed3e1e72d0a58f26692b2dab84b6b0cec382a1 Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Sun, 1 Nov 2015 15:04:36 +0800 Subject: Enable batch script delayed expansion and extensions. This is required for Windows SDK setenv.cmd. --- install.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.bat b/install.bat index 01461667..79b71645 100644 --- a/install.bat +++ b/install.bat @@ -820,7 +820,7 @@ for _, c in ipairs{"luarocks", "luarocks-admin"} do local f = io.open(vars.BINDIR.."\\"..c..".bat", "w") f:write(S[[ @ECHO OFF -SETLOCAL +SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS $COMPILER_ENV_CMD SET "LUA_PATH=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH%" IF NOT "%LUA_PATH_5_2%"=="" ( -- cgit v1.2.3-55-g6feb From c8459585c9cb0f52d3a117125b537bd98f5515ab Mon Sep 17 00:00:00 2001 From: xpol Date: Tue, 3 Nov 2015 11:42:35 +0800 Subject: User assertion for required condition check. --- install.bat | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.bat b/install.bat index 79b71645..ab8618b9 100644 --- a/install.bat +++ b/install.bat @@ -431,8 +431,8 @@ local function get_registry(key, value) return nil end --- requires vars.LUA_RUNTIME to be set before calling this function. local function get_visual_studio_directory() + assert(type(vars.LUA_RUNTIME)=="string", "requires vars.LUA_RUNTIME to be set before calling this function.") local major, minor = vars.LUA_RUNTIME:match('VCR%u*(%d+)(%d)$') -- MSVCR or VCRUNTIME if not major then return nil end local keys = { @@ -446,8 +446,8 @@ local function get_visual_studio_directory() return nil end --- requires vars.LUA_RUNTIME to be set before calling this function. local function get_windows_sdk_directory() + assert(type(vars.LUA_RUNTIME) == "string", "requires vars.LUA_RUNTIME to be set before calling this function.") -- Only v7.1 and v6.1 shipped with compilers -- Other versions requires a separate installation of Visual Studio. -- see https://github.com/keplerproject/luarocks/pull/443#issuecomment-152792516 @@ -464,8 +464,8 @@ local function get_windows_sdk_directory() return get_registry(key, "InstallationFolder") end -- returns the batch command to setup msvc compiler path. --- requires vars.LUA_RUNTIME and vars.UNAME_M to be set before calling this function. local function get_msvc_env_setup_cmd() + assert(type(vars.UNAME_M) == "string", "requires vars.UNAME_M to be set before calling this function.") local x64 = vars.UNAME_M=="x86_64" -- 1. try visual studio command line tools -- cgit v1.2.3-55-g6feb From fd88e3664f2dfb7fad4deb99e1d4ad79a56f4bcc Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 1 Dec 2015 16:42:23 +0100 Subject: updated; - output on checks done - commandline switch to disable the auto-search for ms tools - added debug libs to the SDK search --- install.bat | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/install.bat b/install.bat index 718ec8d6..29c42d0e 100644 --- a/install.bat +++ b/install.bat @@ -29,11 +29,13 @@ vars.LUA_SHORTV = nil -- "51" vars.LUA_LIB_NAMES = "lua5.1.lib lua51.lib lua5.1.dll lua51.dll liblua.dll.a" vars.LUA_RUNTIME = nil vars.UNAME_M = nil +vars.COMPILER_ENV_CMD = nil local FORCE = false local FORCE_CONFIG = false local INSTALL_LUA = false local USE_MINGW = false +local USE_MSVC_MANUAL = false local REGISTRY = true local NOADMIN = false local PROMPT = true @@ -166,7 +168,14 @@ Configuring the Lua interpreter: (/LUA, /INC, /LIB, /BIN cannot be used with /L) Compiler configuration: -/MW Use mingw as build system instead of MSVC + By default the installer will try to determine the + Microsoft toolchain to use. And will automatically use + a setup command to initialize that toolchain when + LuaRocks is run. If it cannot find it, it will default + to the /MSVC switch. +/MSVC Use MS toolchain, without a setup command (tools must + be in your path) +/MW Use mingw as build system (tools must be in your path) Other options: /FORCECONFIG Use a single config location. Do not use the @@ -213,6 +222,8 @@ local function parse_options(args) INSTALL_LUA = true elseif name == "/MW" then USE_MINGW = true + elseif name == "/MSVC" then + USE_MSVC_MANUAL = true elseif name == "/LUA" then vars.LUA_PREFIX = option.value elseif name == "/LIB" then @@ -266,6 +277,9 @@ local function check_flags() die("Bad argument: /LV must either be 5.1, 5.2, or 5.3") end end + if USE_MSVC_MANUAL and USE_MINGW then + die("Cannot combine option /MSVC and /MW") + end end -- *********************************************************** @@ -433,14 +447,22 @@ end local function get_visual_studio_directory() assert(type(vars.LUA_RUNTIME)=="string", "requires vars.LUA_RUNTIME to be set before calling this function.") local major, minor = vars.LUA_RUNTIME:match('VCR%u*(%d+)(%d)$') -- MSVCR or VCRUNTIME - if not major then return nil end + if not major then + print(S[[ Cannot auto-detect Visual Studio version from $LUA_RUNTIME]]) + return nil + end local keys = { "HKLM\\Software\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC", "HKLM\\Software\\Microsoft\\VCExpress\\%d.%d\\Setup\\VS" } for _, key in ipairs(keys) do - local vcdir = get_registry(key:format(major, minor), "ProductDir") - if vcdir then return vcdir end + local versionedkey = key:format(major, minor) + local vcdir = get_registry(versionedkey, "ProductDir") + print(" checking: "..versionedkey) + if vcdir then + print(" Found: "..vcdir) + return vcdir + end end return nil end @@ -452,18 +474,32 @@ local function get_windows_sdk_directory() -- see https://github.com/keplerproject/luarocks/pull/443#issuecomment-152792516 local wsdks = { ["MSVCR100"] = "v7.1", -- shipped with Visual Studio 2010 compilers. + ["MSVCR100D"] = "v7.1", -- shipped with Visual Studio 2010 compilers. ["MSVCR90"] = "v6.1", -- shipped with Visual Studio 2008 compilers. + ["MSVCR90D"] = "v6.1", -- shipped with Visual Studio 2008 compilers. } local wsdkver = wsdks[vars.LUA_RUNTIME] if not wsdkver then + print(S[[ Cannot auto-detect Windows SDK version from $LUA_RUNTIME]]) return nil end local key = "HKLM\\Software\\Microsoft\\Microsoft SDKs\\Windows\\"..wsdkver - return get_registry(key, "InstallationFolder") + print(" checking: "..key) + local dir = get_registry(key, "InstallationFolder") + if dir then + print(" Found: "..dir) + return dir + end + print(" No SDK found") + return nil end + -- returns the batch command to setup msvc compiler path. +-- or an empty string (eg. "") if not found local function get_msvc_env_setup_cmd() + print(S[[Looking for Microsoft toolchain matching runtime $LUA_RUNTIME and architecture $UNAME_M]]) + assert(type(vars.UNAME_M) == "string", "requires vars.UNAME_M to be set before calling this function.") local x64 = vars.UNAME_M=="x86_64" @@ -493,7 +529,7 @@ local function get_msvc_env_setup_cmd() end end - -- finaly, we can't detect more, just don't setup the msvc compiler in luarocks.bat. + -- finally, we can't detect more, just don't setup the msvc compiler in luarocks.bat. return "" end @@ -742,7 +778,7 @@ if SELFCONTAINED then vars.TREE_ROOT = vars.PREFIX..[[\systree]] REGISTRY = false end -vars.COMPILER_ENV_CMD = USE_MINGW and "" or get_msvc_env_setup_cmd() +vars.COMPILER_ENV_CMD = (USE_MINGW and "") or (USE_MSVC_MANUAL and "") or get_msvc_env_setup_cmd() print(S[[ @@ -761,11 +797,20 @@ Lua interpreter : $LUA_BINDIR\$LUA_INTERPRETER includes : $LUA_INCDIR architecture: $UNAME_M binary link : $LUA_LIBNAME with runtime $LUA_RUNTIME.dll - ]]) +if USE_MINGW then + print("Compiler : MinGW (make sure it is in your path before using LuaRocks)") +else + if vars.COMPILER_ENV_CMD == "" then + print("Compiler : Micorosft (make sure it is in your path before using LuaRocks)") + else + print(S[[Compiler : Microsoft, using; $COMPILER_ENV_CMD]]) + end +end + if PROMPT then - print("Press to start installing, or press + to abort. Use install /? for installation options.") + print("\nPress to start installing, or press + to abort. Use install /? for installation options.") io.read() end -- cgit v1.2.3-55-g6feb From 185ec5c11db647ffdef6e128c0bb8e762449be55 Mon Sep 17 00:00:00 2001 From: Ignacio BurgueƱo Date: Tue, 1 Dec 2015 13:28:43 -0300 Subject: Fix typo --- install.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.bat b/install.bat index 29c42d0e..ad78d48e 100644 --- a/install.bat +++ b/install.bat @@ -803,7 +803,7 @@ if USE_MINGW then print("Compiler : MinGW (make sure it is in your path before using LuaRocks)") else if vars.COMPILER_ENV_CMD == "" then - print("Compiler : Micorosft (make sure it is in your path before using LuaRocks)") + print("Compiler : Microsoft (make sure it is in your path before using LuaRocks)") else print(S[[Compiler : Microsoft, using; $COMPILER_ENV_CMD]]) end -- cgit v1.2.3-55-g6feb From 30028a3e59b81bccb6ccd81609eb198e74b58ca5 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 1 Dec 2015 21:24:56 +0100 Subject: added debug/release option for SDK detection --- install.bat | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install.bat b/install.bat index 29c42d0e..4786906b 100644 --- a/install.bat +++ b/install.bat @@ -502,6 +502,7 @@ local function get_msvc_env_setup_cmd() assert(type(vars.UNAME_M) == "string", "requires vars.UNAME_M to be set before calling this function.") local x64 = vars.UNAME_M=="x86_64" + local debug = vars.LUA_RUNTIME:find("D$") -- runtime ending with "D" is a debug runtime -- 1. try visual studio command line tools local vcdir = get_visual_studio_directory() @@ -525,7 +526,7 @@ local function get_msvc_env_setup_cmd() if wsdkdir then local setenv = wsdkdir.."Bin\\SetEnv.cmd" if exists(setenv) then - return ('call "%s" /Release /%s'):format(setenv, x64 and "x64" or "x86") + return ('call "%s" /%s /%s'):format(setenv, debug and "Debug" or "Release" ,x64 and "x64" or "x86") end end -- cgit v1.2.3-55-g6feb From 6c5f261887d560b03b5fa0cc097b79d6d79c1839 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Wed, 2 Dec 2015 22:58:05 +0100 Subject: removed /debug /release switches for setting up the enviornment. it does NOT determine linking against a debug runtime or release runtime. --- install.bat | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/install.bat b/install.bat index 4cf785d4..f5692c6e 100644 --- a/install.bat +++ b/install.bat @@ -502,7 +502,6 @@ local function get_msvc_env_setup_cmd() assert(type(vars.UNAME_M) == "string", "requires vars.UNAME_M to be set before calling this function.") local x64 = vars.UNAME_M=="x86_64" - local debug = vars.LUA_RUNTIME:find("D$") -- runtime ending with "D" is a debug runtime -- 1. try visual studio command line tools local vcdir = get_visual_studio_directory() @@ -526,7 +525,7 @@ local function get_msvc_env_setup_cmd() if wsdkdir then local setenv = wsdkdir.."Bin\\SetEnv.cmd" if exists(setenv) then - return ('call "%s" /%s /%s'):format(setenv, debug and "Debug" or "Release" ,x64 and "x64" or "x86") + return ('call "%s" /%s'):format(setenv, x64 and "x64" or "x86") end end -- cgit v1.2.3-55-g6feb