Browse Source

MSVC defaults built-in, remove env vars print

* Working CL.exe and Link.exe commands are now automatically used when
building on Windows
* Remove environment variable printing, which was for debugging only
* Fix writeIfContentsNewer() failing because file was still open,
causing moveFile() to file
windows-support
Macoy Madson 6 months ago
parent
commit
6339f3c521
3 changed files with 46 additions and 39 deletions
  1. +38
    -5
      src/ModuleManager.cpp
  2. +7
    -34
      src/RunProcess.cpp
  3. +1
    -0
      src/Writer.cpp

+ 38
- 5
src/ModuleManager.cpp View File

@ -80,6 +80,43 @@ void moduleManagerInitialize(ModuleManager& manager)
// Command defaults
{
#ifdef WINDOWS
manager.environment.compileTimeBuildCommand.fileToExecute = "cl.exe";
manager.environment.compileTimeBuildCommand.arguments = {
{ProcessCommandArgumentType_String, "/nologo"},
// Not 100% sure what the right default for this is
{ProcessCommandArgumentType_String, "/EHsc"},
{ProcessCommandArgumentType_String, "/c"},
{ProcessCommandArgumentType_SourceInput, EmptyString},
{ProcessCommandArgumentType_ObjectOutput, EmptyString},
{ProcessCommandArgumentType_CakelispHeadersInclude, EmptyString}};
// TODO: Dynamic linking support
// {ProcessCommandArgumentType_String, "-fPIC"}};
manager.environment.compileTimeLinkCommand.fileToExecute = "link.exe";
manager.environment.compileTimeLinkCommand.arguments = {
// TODO: Dynamic linking support
// {ProcessCommandArgumentType_String, "-shared"},
// {ProcessCommandArgumentType_String, "-o"},
{ProcessCommandArgumentType_DynamicLibraryOutput, EmptyString},
{ProcessCommandArgumentType_ObjectInput, EmptyString}};
manager.environment.buildTimeBuildCommand.fileToExecute = "cl.exe";
manager.environment.buildTimeBuildCommand.arguments = {
{ProcessCommandArgumentType_String, "/nologo"},
{ProcessCommandArgumentType_String, "/EHsc"},
{ProcessCommandArgumentType_String, "/c"},
{ProcessCommandArgumentType_SourceInput, EmptyString},
{ProcessCommandArgumentType_ObjectOutput, EmptyString},
{ProcessCommandArgumentType_IncludeSearchDirs, EmptyString},
{ProcessCommandArgumentType_AdditionalOptions, EmptyString}};
manager.environment.buildTimeLinkCommand.fileToExecute = "link.exe";
manager.environment.buildTimeLinkCommand.arguments = {
{ProcessCommandArgumentType_String, "/nologo"},
{ProcessCommandArgumentType_ExecutableOutput, EmptyString},
{ProcessCommandArgumentType_ObjectInput, EmptyString}};
#else
manager.environment.compileTimeBuildCommand.fileToExecute = "/usr/bin/g++";
manager.environment.compileTimeBuildCommand.arguments = {
{ProcessCommandArgumentType_String, "-g"},
@ -113,11 +150,7 @@ void moduleManagerInitialize(ModuleManager& manager)
{ProcessCommandArgumentType_String, "-o"},
{ProcessCommandArgumentType_ExecutableOutput, EmptyString},
{ProcessCommandArgumentType_ObjectInput, EmptyString}};
// TODO: Add defaults for Windows
// #ifdef WINDOWS
// #error Set sensible defaults for compile time build command
// #endif
#endif
}
manager.environment.useCachedFiles = true;


+ 7
- 34
src/RunProcess.cpp View File

@ -184,41 +184,11 @@ int runProcess(const RunProcessArguments& arguments, int* statusOut)
return 0;
#elif WINDOWS
// List all environment variables
static bool hasListed = false;
if (!hasListed)
{
hasListed = true;
LPTSTR lpszVariable;
LPTCH lpvEnv;
lpvEnv = GetEnvironmentStrings();
// If the returned pointer is NULL, exit.
if (lpvEnv == nullptr)
{
Logf("GetEnvironmentStrings failed (%d)\n", GetLastError());
return 1;
}
// Variable strings are separated by NULL byte, and the block is
// terminated by a NULL byte.
lpszVariable = (LPTSTR)lpvEnv;
while (*lpszVariable)
{
_tprintf(TEXT("%s\n"), lpszVariable);
lpszVariable += lstrlen(lpszVariable) + 1;
}
FreeEnvironmentStrings(lpvEnv);
Log("\nDone listing vars\n");
}
// We need to do some extra legwork to find which compiler they actually want to use, based on
// the current environment variables set by vcvars*.bat
// See https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-160
char fileToExecuteOverride[MAX_PATH_LENGTH] = {0};
if (_stricmp(arguments.fileToExecute, "CL.exe") == 0 ||
if (_stricmp(arguments.fileToExecute, "cl.exe") == 0 ||
_stricmp(arguments.fileToExecute, "link.exe") == 0)
{
LPTSTR vcInstallDir = nullptr;
@ -250,9 +220,12 @@ int runProcess(const RunProcessArguments& arguments, int* statusOut)
"Properties -> Debugging -> Environment\n",
msvcVariables[i].variableName);
Log("The following vars need to be defined in the environment:\n");
Log("The following vars need to be defined in the environment to be read from "
"Cakelisp directly:\n");
for (int n = 0; n < ArraySize(msvcVariables); ++n)
Logf("\t%s\n", msvcVariables[n].variableName);
Log("Note that MSVC relies on more variables which vcvars*.bat define, so you need "
"to define those as well (if you do not use vcvars script).\n");
variablesFound = false;
@ -355,11 +328,11 @@ int runProcess(const RunProcessArguments& arguments, int* statusOut)
STARTUPINFO startupInfo;
PROCESS_INFORMATION* processInfo = new PROCESS_INFORMATION;
ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
ZeroMemory(processInfo, sizeof(PROCESS_INFORMATION));
Logf("Final command string: %s\n", commandLineString);
// Start the child process.


+ 1
- 0
src/Writer.cpp View File

@ -28,6 +28,7 @@ bool writeIfContentsNewer(const char* tempFilename, const char* outputFilename)
if (logging.fileSystem)
Log("Destination file didn't exist. Writing\n");
fclose(newFile);
return moveFile(tempFilename, outputFilename);
}
else


Loading…
Cancel
Save