Skip to content

Commit

Permalink
Merge pull request #4879 from rainers/link_vs2015
Browse files Browse the repository at this point in the history
Add support for VS2015
  • Loading branch information
MartinNowak committed Aug 27, 2015
2 parents 6c6092c + 39b6e49 commit 3b76b8c
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libmscoff.d
Expand Up @@ -151,7 +151,7 @@ public:
offset += MSCoffLibHeader.sizeof;
char* endptr = null;
uint size = strtoul(cast(char*)header.file_size, &endptr, 10);
if (endptr >= &header.file_size[10] || *endptr != ' ')
if (endptr >= header.file_size.ptr + 10 || *endptr != ' ')
{
reason = __LINE__;
goto Lcorrupt;
Expand Down
93 changes: 93 additions & 0 deletions src/link.d
Expand Up @@ -242,6 +242,37 @@ extern (C++) int runLINK()
else
cmdbuf.writestring("\\lib\"");
}
cmdbuf.writeByte(' ');
const(char)* lflags;
if (detectVS14(cmdbuf.peekString()))
{
lflags = getenv("LFLAGS_VS14");
if (!lflags)
lflags = "legacy_stdio_definitions.lib";
// environment variables UniversalCRTSdkDir and UCRTVersion set
// when running vcvarsall.bat x64
if (const(char)* UniversalCRTSdkDir = getenv("UniversalCRTSdkDir"))
if (const(char)* UCRTVersion = getenv("UCRTVersion"))
{
cmdbuf.writestring(" /LIBPATH:\"");
cmdbuf.writestring(UniversalCRTSdkDir);
cmdbuf.writestring("\\lib\\");
cmdbuf.writestring(UCRTVersion);
if (global.params.is64bit)
cmdbuf.writestring("\\ucrt\\x64\"");
else
cmdbuf.writestring("\\ucrt\\x86\"");
}
}
else
{
lflags = getenv("LFLAGS_VS12");
}
if (lflags)
{
cmdbuf.writeByte(' ');
cmdbuf.writestring(lflags);
}
char* p = cmdbuf.peekString();
const(char)* lnkfilename = null;
size_t plen = strlen(p);
Expand Down Expand Up @@ -850,3 +881,65 @@ extern (C++) int runProgram()
assert(0);
}
}

version (Windows)
{
/*****************************
* Detect whether the link will grab libraries from VS 2015 or later
*/
extern (C++) bool detectVS14(const(char)* cmdline)
{
auto libpaths = new Strings();
// grab library folders passed on the command line
for (const(char)* p = cmdline; *p;)
{
while (isspace(*p))
p++;
const(char)* arg = p;
const(char)* end = arg;
while (*end && !isspace(*end))
{
end++;
if (end[-1] == '"')
{
while (*end && *end != '"')
{
if (*end == '\\' && end[1])
end++;
end++;
}
if (*end)
end++; // skip closing quote
}
}
p = end;
// remove quotes if spanning complete argument
if (end > arg + 1 && arg[0] == '"' && end[-1] == '"')
{
arg++;
end--;
}
if (arg[0] == '-' || arg[0] == '/')
{
if (end - arg > 8 && memicmp(arg + 1, "LIBPATH:", 8) == 0)
{
arg += 9;
char* q = cast(char*)memcpy((new char[](end - arg + 1)).ptr, arg, end - arg);
q[end - arg] = 0;
Strings* paths = FileName.splitPath(q);
libpaths.append(paths);
}
}
}
// append library paths from environment
if (const(char)* lib = getenv("LIB"))
libpaths.append(FileName.splitPath(lib));
// if legacy_stdio_definitions.lib can be found in the same folder as
// libcmt.lib, libcmt.lib is assumed to be from VS2015 or later
const(char)* libcmt = FileName.searchPath(libpaths, "libcmt.lib", true);
if (!libcmt)
return false;
const(char)* liblegacy = FileName.replaceName(libcmt, "legacy_stdio_definitions.lib");
return FileName.exists(liblegacy) == 1;
}
}
3 changes: 3 additions & 0 deletions src/root/outbuffer.d
Expand Up @@ -405,7 +405,10 @@ struct OutBuffer
extern (C++) char* peekString()
{
if (!offset || data[offset - 1] != '\0')
{
writeByte(0);
offset--; // allow appending more
}
return cast(char*)data;
}

Expand Down

0 comments on commit 3b76b8c

Please sign in to comment.