@@ -112,6 +112,7 @@ typedef enum {
112112 OP_REMOVE = 4 , // Remove existing example
113113 OP_VALIDATE = 5 , // Validate examples, using [examples_list.txt] as main source by default
114114 OP_UPDATE = 6 , // Validate and update required examples (as far as possible)
115+ OP_BUILD = 7 , // Build example for desktop and web, copy web output
115116} rlExampleOperation ;
116117
117118static const char * exCategories [REXM_MAX_EXAMPLE_CATEGORIES ] = { "core" , "shapes" , "textures" , "text" , "models" , "shaders" , "audio" , "others" };
@@ -356,6 +357,29 @@ int main(int argc, char *argv[])
356357
357358 opCode = OP_UPDATE ;
358359 }
360+ else if (strcmp (argv [1 ], "build" ) == 0 )
361+ {
362+ // Build example for PLATFORM_DESKTOP and PLATFORM_WEB
363+ // NOTE: Build outputs to default directory, usually where the .c file is located,
364+ // to avoid issues with copying resources (at least on Desktop)
365+ // Web build files (.html, .wasm, .js, .data) are copied to raylib.com/examples repo
366+ // Check for valid upcoming argument
367+ if (argc == 2 ) LOG ("WARNING: No example name provided to build\n" );
368+ else if (argc > 3 ) LOG ("WARNING: Too many arguments provided\n" );
369+ else
370+ {
371+ // Verify example exists in collection to be removed
372+ char * exColInfo = LoadFileText (exCollectionFilePath );
373+ if (TextFindIndex (exColInfo , argv [2 ]) != -1 ) // Example in the collection
374+ {
375+ strcpy (exName , argv [2 ]); // Register example name for removal
376+ strncpy (exCategory , exName , TextFindIndex (exName , "_" ));
377+ opCode = OP_BUILD ;
378+ }
379+ else LOG ("WARNING: REMOVE: Example not available in the collection\n" );
380+ UnloadFileText (exColInfo );
381+ }
382+ }
359383 }
360384
361385 switch (opCode )
@@ -540,25 +564,11 @@ int main(int argc, char *argv[])
540564 // Compile to: raylib.com/examples/<category>/<category>_example_name.wasm
541565 // Compile to: raylib.com/examples/<category>/<category>_example_name.js
542566 //------------------------------------------------------------------------------------------------
543- // TODO: Avoid platform-specific .BAT file
544- /*
545- SET RAYLIB_PATH=C:\GitHub\raylib
546- SET COMPILER_PATH=C:\raylib\w64devkit\bin
547- ENV_SET PATH=$(COMPILER_PATH)
548- SET MAKE=mingw32-make
549- $(MAKE) -f Makefile.Web shaders/shaders_deferred_render PLATFORM=$(PLATFORM) -B
550-
551- //int putenv(char *string); // putenv takes a string of the form NAME=VALUE
552- //int setenv(const char *envname, const char *envval, int overwrite);
553- //int unsetenv(const char *name); //unset variable
554- putenv("RAYLIB_DIR=C:\\GitHub\\raylib");
555- putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin");
556- setenv("RAYLIB_DIR", "C:\\GitHub\\raylib", 1);
557- unsetenv("RAYLIB_DIR");
558- getenv("RAYLIB_DIR");
567+ //putenv("RAYLIB_DIR=C:\\GitHub\\raylib");
568+ //putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin");
569+ // WARNING: EMSDK_PATH must be set to proper location when calling from GitHub Actions
559570 system (TextFormat ("make -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B" , exCategory , exName ));
560- */
561- system (TextFormat ("%s/build_example_web.bat %s/%s" , exBasePath , exCategory , exName ));
571+ //system(TextFormat("%s/build_example_web.bat %s/%s", exBasePath, exCategory, exName));
562572
563573 // Copy results to web side
564574 FileCopy (TextFormat ("%s/%s/%s.html" , exBasePath , exCategory , exName ),
@@ -634,8 +644,9 @@ int main(int argc, char *argv[])
634644 FileRemove (TextFormat ("%s/%s/%s.js" , exWebPath , exCategory , exName ));
635645
636646 // Recompile example (on raylib side)
637- // NOTE: Tools requirements: emscripten, w64devkit
638- system (TextFormat ("%s/build_example_web.bat %s/%s" , exBasePath , exRecategory , exRename ));
647+ // WARNING: EMSDK_PATH must be set to proper location when calling from GitHub Actions
648+ system (TextFormat ("%s/make -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B" , exBasePath , exRecategory , exRename ));
649+ //system(TextFormat("%s/build_example_web.bat %s/%s", exBasePath, exRecategory, exRename));
639650
640651 // Copy results to web side
641652 FileCopy (TextFormat ("%s/%s/%s.html" , exBasePath , exRecategory , exRename ),
@@ -1133,6 +1144,41 @@ int main(int argc, char *argv[])
11331144 //------------------------------------------------------------------------------------------------
11341145
11351146 } break ;
1147+ case OP_BUILD :
1148+ {
1149+ // Build: raylib.com/examples/<category>/<category>_example_name.html
1150+ // Build: raylib.com/examples/<category>/<category>_example_name.data
1151+ // Build: raylib.com/examples/<category>/<category>_example_name.wasm
1152+ // Build: raylib.com/examples/<category>/<category>_example_name.js
1153+ if (strcmp (exCategory , "others" ) != 0 ) // Skipping "others" category
1154+ {
1155+ // Build example for PLATFORM_DESKTOP
1156+ putenv ("RAYLIB_DIR=C:\\GitHub\\raylib" );
1157+ putenv ("PATH=%PATH%;C:\\raylib\\w64devkit\\bin" );
1158+ putenv ("MAKE=mingw32-make" );
1159+
1160+ ChangeDirectory (exBasePath );
1161+ system (TextFormat ("%s %s/%s PLATFORM=PLATFORM_DESKTOP -B" , getenv ("MAKE" ), exCategory , exName ));
1162+
1163+ // Build example for PLATFORM_WEB
1164+ system (TextFormat ("%s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B" , getenv ("MAKE" ), exCategory , exName ));
1165+ //system(TextFormat("%s/build_example_web.bat %s/%s", exBasePath, exInfo->category, exInfo->name));
1166+
1167+ // Update generated .html metadata
1168+ UpdateWebMetadata (TextFormat ("%s/%s/%s.html" , exBasePath , exCategory , exName ),
1169+ TextFormat ("%s/%s/%s.c" , exBasePath , exCategory , exName ));
1170+
1171+ // Copy results to web side
1172+ FileCopy (TextFormat ("%s/%s/%s.html" , exBasePath , exCategory , exName ),
1173+ TextFormat ("%s/%s/%s.html" , exWebPath , exCategory , exName ));
1174+ FileCopy (TextFormat ("%s/%s/%s.data" , exBasePath , exCategory , exName ),
1175+ TextFormat ("%s/%s/%s.data" , exWebPath , exCategory , exName ));
1176+ FileCopy (TextFormat ("%s/%s/%s.wasm" , exBasePath , exCategory , exName ),
1177+ TextFormat ("%s/%s/%s.wasm" , exWebPath , exCategory , exName ));
1178+ FileCopy (TextFormat ("%s/%s/%s.js" , exBasePath , exCategory , exName ),
1179+ TextFormat ("%s/%s/%s.js" , exWebPath , exCategory , exName ));
1180+ }
1181+ } break ;
11361182 default : // Help
11371183 {
11381184 // Supported commands:
0 commit comments