Skip to content

Commit

Permalink
更新对msvc2019支持
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Jun 24, 2019
1 parent 6e6c314 commit dfc96fb
Showing 1 changed file with 69 additions and 27 deletions.
96 changes: 69 additions & 27 deletions Build/lua/luabuild/msvc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,74 @@ local function installpath()
return fs.path(result)
end


local function crtpath(platform)
local RedistVersion = (function ()
local verfile = installpath() / 'VC' / 'Auxiliary' / 'Build' / 'Microsoft.VCRedistVersion.default.txt'
local f = assert(io.open(verfile:string(), 'r'))
local r = f:read 'a'
f:close()
return strtrim(r)
end)()
local ToolVersion = (function ()
local verfile = installpath() / 'VC' / 'Auxiliary' / 'Build' / 'Microsoft.VCToolsVersion.default.txt'
local f = assert(io.open(verfile:string(), 'r'))
local r = f:read 'a'
f:close()
return strtrim(r)
end)()
local ToolsetVersion = (function ()
local verfile = installpath() / 'VC' / 'Tools' / 'MSVC' / ToolVersion / 'include' / 'yvals_core.h'
local f = assert(io.open(verfile:string(), 'r'))
local r = f:read 'a'
f:close()
return r:match '#define%s+_MSVC_STL_VERSION%s+(%d+)'
end)()
return installpath() / 'VC' / 'Redist' / 'MSVC' / RedistVersion / platform / ('Microsoft.VC'..ToolsetVersion..'.CRT')
end

local function ucrtpath(platform)
local registry = require 'bee.registry'
local reg = registry.open [[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots]]
local path = fs.path(reg.KitsRoot10) / 'Redist'
local res, ver
local function accept(p)
if not fs.is_directory(p) then
return
end
local ucrt = p / 'ucrt' / 'DLLs' / platform
if fs.exists(ucrt) then
local version = 0
if p ~= path then
version = p:filename():string():gsub('10%.0%.([0-9]+)%.0', '%1')
version = tonumber(version)
end
if not ver or ver < version then
res, ver = ucrt, version
end
end
end
accept(path)
for p in path:list_directory() do
accept(p)
end
if res then
return res
end
end

local function copy_crtdll(platform, target)
fs.create_directories(target)
for dll in crtpath(platform):list_directory() do
if dll:filename() ~= fs.path "vccorlib140.dll" then
fs.copy_file(dll, target / dll:filename(), true)
end
end
for dll in ucrtpath(platform):list_directory() do
fs.copy_file(dll, target / dll:filename(), true)
end
end

local function parse_env(str)
local pos = str:find('=')
if not pos then
Expand Down Expand Up @@ -72,34 +140,8 @@ function mt:initialize(version, coding)
return true
end

function mt:redistversion()
local verfile = self.__path / 'VC' / 'Auxiliary' / 'Build' / 'Microsoft.VCRedistVersion.default.txt'
local f = assert(io.open(verfile:string(), 'r'))
local r = f:read 'a'
f:close()
return strtrim(r)
end

function mt:crtpath(platform)
return self.__path / 'VC' / 'Redist' / 'MSVC' / self:redistversion() / platform / ('Microsoft.VC' .. self.version .. '.CRT')
end

function mt:sdkpath()
local reg = registry.open [[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots]]
return fs.path(reg.KitsRoot10)
end

function mt:ucrtpath(platform)
return self:sdkpath() / 'Redist' / 'ucrt' / 'DLLs' / platform
end

function mt:copy_crt_dll(platform, target)
fs.create_directories(target)
fs.copy_file(self:crtpath(platform) / 'msvcp140.dll', target / 'msvcp140.dll', true)
fs.copy_file(self:crtpath(platform) / 'vcruntime140.dll', target / 'vcruntime140.dll', true)
for dll in self:ucrtpath(platform):list_directory() do
fs.copy_file(dll, target / dll:filename(), true)
end
copy_crtdll(platform, target)
end

function mt:compile(target, solution, property)
Expand Down

0 comments on commit dfc96fb

Please sign in to comment.