diff options
author | Rui Xia <ruixia@microsoft.com> | 2019-06-19 15:07:00 -0700 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-07-26 12:49:56 -0300 |
commit | dd926404890d7cc71ce8538384305c90e318abbb (patch) | |
tree | f6a90360aaad37dd1c8337cc700bd30a7f6ab0ee | |
parent | 7b730490ade3690d1b39bbb9f5c51c4cead974ed (diff) | |
download | luarocks-dd926404890d7cc71ce8538384305c90e318abbb.tar.gz luarocks-dd926404890d7cc71ce8538384305c90e318abbb.tar.bz2 luarocks-dd926404890d7cc71ce8538384305c90e318abbb.zip |
Support VS tool chain 2017 or higher
-rw-r--r-- | install.bat | 60 |
1 files changed, 56 insertions, 4 deletions
diff --git a/install.bat b/install.bat index e1053a52..cdbc6377 100644 --- a/install.bat +++ b/install.bat | |||
@@ -446,7 +446,7 @@ local function get_registry(key, value) | |||
446 | return nil | 446 | return nil |
447 | end | 447 | end |
448 | 448 | ||
449 | local function get_visual_studio_directory() | 449 | local function get_visual_studio_directory_from_registry() |
450 | assert(type(vars.LUA_RUNTIME)=="string", "requires vars.LUA_RUNTIME to be set before calling this function.") | 450 | assert(type(vars.LUA_RUNTIME)=="string", "requires vars.LUA_RUNTIME to be set before calling this function.") |
451 | local major, minor = vars.LUA_RUNTIME:match('VCR%u*(%d+)(%d)$') -- MSVCR<x><y> or VCRUNTIME<x><y> | 451 | local major, minor = vars.LUA_RUNTIME:match('VCR%u*(%d+)(%d)$') -- MSVCR<x><y> or VCRUNTIME<x><y> |
452 | if not major then | 452 | if not major then |
@@ -469,6 +469,47 @@ local function get_visual_studio_directory() | |||
469 | return nil | 469 | return nil |
470 | end | 470 | end |
471 | 471 | ||
472 | local function get_visual_studio_directory_from_vswhere() | ||
473 | assert(type(vars.LUA_RUNTIME)=="string", "requires vars.LUA_RUNTIME to be set before calling this function.") | ||
474 | local major, minor = vars.LUA_RUNTIME:match('VCR%u*(%d+)(%d)$') | ||
475 | if not major then | ||
476 | print(S[[ Cannot auto-detect Visual Studio version from $LUA_RUNTIME]]) | ||
477 | return nil | ||
478 | end | ||
479 | if tonumber(major) < 14 then | ||
480 | return nil | ||
481 | end | ||
482 | local program_dir = os.getenv('PROGRAMFILES(X86)') | ||
483 | if not program_dir then | ||
484 | return nil | ||
485 | end | ||
486 | local vswhere = program_dir.."\\Microsoft Visual Studio\\Installer\\vswhere.exe" | ||
487 | if not exists(vswhere) then | ||
488 | return nil | ||
489 | end | ||
490 | local f, msg = io.popen('"'..vswhere..'" -products * -property installationPath') | ||
491 | if not f then return nil, "failed to run vswhere: "..msg end | ||
492 | local vsdir = nil | ||
493 | while true do | ||
494 | local l, err = f:read() | ||
495 | if not l then | ||
496 | if err then | ||
497 | f:close() | ||
498 | return nil, err | ||
499 | else | ||
500 | break | ||
501 | end | ||
502 | end | ||
503 | vsdir = l | ||
504 | end | ||
505 | f:close() | ||
506 | if not vsdir then | ||
507 | return nil | ||
508 | end | ||
509 | print(" Visual Studio 2017 or higher found in: "..vsdir) | ||
510 | return vsdir | ||
511 | end | ||
512 | |||
472 | local function get_windows_sdk_directory() | 513 | local function get_windows_sdk_directory() |
473 | assert(type(vars.LUA_RUNTIME) == "string", "requires vars.LUA_RUNTIME to be set before calling this function.") | 514 | assert(type(vars.LUA_RUNTIME) == "string", "requires vars.LUA_RUNTIME to be set before calling this function.") |
474 | -- Only v7.1 and v6.1 shipped with compilers | 515 | -- Only v7.1 and v6.1 shipped with compilers |
@@ -505,8 +546,19 @@ local function get_msvc_env_setup_cmd() | |||
505 | assert(type(vars.UNAME_M) == "string", "requires vars.UNAME_M to be set before calling this function.") | 546 | assert(type(vars.UNAME_M) == "string", "requires vars.UNAME_M to be set before calling this function.") |
506 | local x64 = vars.UNAME_M=="x86_64" | 547 | local x64 = vars.UNAME_M=="x86_64" |
507 | 548 | ||
508 | -- 1. try visual studio command line tools | 549 | -- 1. try visual studio command line tools of VS 2017 or higher |
509 | local vcdir = get_visual_studio_directory() | 550 | local vsdir = get_visual_studio_directory_from_vswhere() |
551 | if vsdir then | ||
552 | local vcvarsall = vsdir .. '\\VC\\Auxiliary\\Build\\vcvarsall.bat' | ||
553 | if exists(vcvarsall) then | ||
554 | local vcvarsall_args = { x86 = "", x86_64 = " x64" } | ||
555 | assert(vcvarsall_args[vars.UNAME_M], "vars.UNAME_M: only x86 and x86_64 are supported") | ||
556 | return ('call "%s"%s'):format(vcvarsall, vcvarsall_args[vars.UNAME_M]) | ||
557 | end | ||
558 | end | ||
559 | |||
560 | -- 2. try visual studio command line tools | ||
561 | local vcdir = get_visual_studio_directory_from_registry() | ||
510 | if vcdir then | 562 | if vcdir then |
511 | local vcvars_bats = { | 563 | local vcvars_bats = { |
512 | x86 = { | 564 | x86 = { |
@@ -535,7 +587,7 @@ local function get_msvc_env_setup_cmd() | |||
535 | end | 587 | end |
536 | end | 588 | end |
537 | 589 | ||
538 | -- 2. try for Windows SDKs command line tools. | 590 | -- 3. try for Windows SDKs command line tools. |
539 | local wsdkdir = get_windows_sdk_directory() | 591 | local wsdkdir = get_windows_sdk_directory() |
540 | if wsdkdir then | 592 | if wsdkdir then |
541 | local setenv = wsdkdir.."Bin\\SetEnv.cmd" | 593 | local setenv = wsdkdir.."Bin\\SetEnv.cmd" |