Skip to content

Commit 9192d40

Browse files
committed
Add Windows compiler commands
1 parent 5424cd1 commit 9192d40

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/cli.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ void print_help(void)
5959

6060
int main(int argc, char *argv[])
6161
{
62-
6362
bool sourceValid = false;
6463
bool destinationValid = false;
6564
bool stageValid = false;
@@ -344,7 +343,6 @@ int main(int argc, char *argv[])
344343

345344
if (!check_for_metal_tools())
346345
{
347-
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "xcrun not found! Is Xcode installed and activated?");
348346
return 1;
349347
}
350348

@@ -454,7 +452,6 @@ int main(int argc, char *argv[])
454452

455453
if (!check_for_metal_tools())
456454
{
457-
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "xcrun not found! Is Xcode installed and activated?");
458455
return 1;
459456
}
460457

@@ -550,17 +547,30 @@ int main(int argc, char *argv[])
550547

551548
bool check_for_metal_tools(void)
552549
{
550+
#if defined(SDL_PLATFORM_MACOS)
551+
char *compilerName = "xcrun";
552+
char *cantFindMessage = "Install Xcode or the Xcode Command Line Tools.";
553+
#elif defined(SDL_PLATFORM_WIN32)
554+
char *compilerName = "metal";
555+
char *cantFindMessage = "Install Metal Developer Tools for Windows 5.0 beta 2 or newer (https://developer.apple.com/download/all/?q=metal%20developer%20tools%20for%20windows) and add \"C:\\Program Files\\Metal Developer Tools\\bin\" to your PATH.";
556+
#else
557+
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Compiling to METALLIB is not supported on this platform!");
558+
return false;
559+
#endif
560+
553561
// Check for the Metal Developer Tools...
554-
// FIXME: All the process calls need their Windows equivalents!
555562
SDL_PropertiesID props = SDL_CreateProperties();
556-
SDL_SetPointerProperty(props, SDL_PROP_PROCESS_CREATE_ARGS_POINTER, (char*[]){ "xcrun", "--help", NULL });
563+
SDL_SetPointerProperty(props, SDL_PROP_PROCESS_CREATE_ARGS_POINTER, (char*[]){ compilerName, "--help", NULL });
564+
SDL_SetNumberProperty(props, SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER, SDL_PROCESS_STDIO_NULL);
557565
SDL_SetNumberProperty(props, SDL_PROP_PROCESS_CREATE_STDERR_NUMBER, SDL_PROCESS_STDIO_NULL);
558566
SDL_Process *process = SDL_CreateProcessWithProperties(props);
559567
SDL_DestroyProperties(props);
560568

561569
if (process == NULL) {
570+
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s not found! %s", compilerName, cantFindMessage);
562571
return false;
563572
}
573+
564574
SDL_DestroyProcess(process);
565575
return true;
566576
}
@@ -580,16 +590,24 @@ int compile_metallib(ShaderCross_Platform platform, const char *outputFilename)
580590
minversion = "-miphoneos-version-min=13.0";
581591
}
582592

593+
#if defined(SDL_PLATFORM_MACOS)
594+
const char* compileToIRCommand[] = { "xcrun", "-sdk", sdkString, "metal", stdString, minversion, "-Wall", "-O3", "-c", "tmp.metal", "-o", "tmp.ir", NULL };
595+
const char* compileToMetallibCommand[] = { "xcrun", "-sdk", sdkString, "metallib", "tmp.ir", "-o", outputFilename, NULL };
596+
#elif defined(SDL_PLATFORM_WINDOWS)
597+
const char* compileToIRCommand[] = { "metal", stdString, minversion, "-Wall", "-O3", "-c", "tmp.metal", "-o", "tmp.ir", NULL};
598+
const char* compileToMetallibCommand[] = { "metallib", "tmp.ir", "-o", outputFilename, NULL};
599+
#endif
600+
583601
int exitcode;
584-
SDL_Process *process = SDL_CreateProcess((const char*[]){ "xcrun", "-sdk", sdkString, "metal", stdString, minversion, "-Wall", "-O3", "-c", "tmp.metal", "-o", "tmp.ir", NULL }, true);
602+
SDL_Process *process = SDL_CreateProcess(compileToIRCommand, true);
585603
SDL_WaitProcess(process, true, &exitcode);
586604
SDL_RemovePath("tmp.metal");
587605
if (exitcode != 0) {
588606
return exitcode;
589607
}
590608
SDL_DestroyProcess(process);
591609

592-
process = SDL_CreateProcess((const char*[]){ "xcrun", "-sdk", sdkString, "metallib", "tmp.ir", "-o", outputFilename, NULL }, true);
610+
process = SDL_CreateProcess(compileToMetallibCommand, true);
593611
SDL_WaitProcess(process, true, &exitcode);
594612
SDL_RemovePath("tmp.ir");
595613
if (exitcode != 0) {

0 commit comments

Comments
 (0)