1 /+ dub.sdl: 2 name "build_lib" 3 +/ 4 module build_lexbor_lib; 5 6 import std; 7 8 int main() 9 { 10 11 version(WINDOWS) 12 { 13 return 0; 14 } 15 else 16 { 17 enum commit = "14166847cfa85d80c9041f5387014961f70f3831"; 18 19 // Ok, already done. 20 if (exists("liblexbor_parserino.a")) 21 return 0; 22 23 // Temp directory 24 auto path = tempDir.buildPath(tempDir(), "lexbor_build", "lexbor_bundle.zip"); 25 mkdirRecurse(dirName(path)); 26 27 auto cmake = executeShell("cmake --help"); 28 29 if (cmake.status != 0) 30 { 31 version(linux) stderr.writeln("Please install cmake on your system. For example on debian/ubuntu/... : `sudo apt install cmake`"); 32 version(OSX) stderr.writeln("Please install cmake on your system. Try: `brew install cmake`"); 33 return 1; 34 } 35 36 stderr.writeln; 37 stderr.writeln("-------------------------"); 38 stderr.writeln("-- One time deps build --"); 39 stderr.writeln("-------------------------"); 40 stderr.writeln; 41 42 stderr.writeln("- Temp. directory: ", path); stderr.flush(); 43 44 // Download bundle 45 stderr.writeln("- Getting zip bundle..."); stderr.flush(); 46 download("https://github.com/lexbor/lexbor/archive/" ~ commit ~ ".zip", path); 47 48 // Unzip 49 stderr.writeln("- Unzipping bundle..."); stderr.flush(); 50 ZipArchive zip = new ZipArchive(path.read); 51 52 foreach(string amPath, ref ArchiveMember am; zip.directory) 53 { 54 auto relPath = amPath; 55 auto filePath = tempDir.buildPath(tempDir(), "lexbor_build", relPath); 56 mkdirRecurse(dirName(filePath)); 57 58 zip.expand(am); 59 60 if (!filePath.endsWith("/") && !filePath.endsWith("\\")) 61 std.file.write(filePath, am.expandedData()); 62 } 63 64 // Compiling 65 stderr.writeln("- Compiling... (please wait, this will not be done anymore!)"); stderr.flush(); 66 67 string cmakeopt; 68 version(OSX) cmakeopt = " -DCMAKE_OSX_DEPLOYMENT_TARGET=10.10 "; 69 70 auto res = executeShell("cd " ~ dirName(path).buildPath("lexbor-" ~ commit) ~ " && cmake . -DLEXBOR_BUILD_TESTS=OFF -DLEXBOR_BUILD_EXAMPLES=OFF -DLEXBOR_BUILD_SEPARATELY=OFF -DLEXBOR_BUILD_SHARED=OFF -DLEXBOR_BUILD_STATIC=ON " ~ cmakeopt ~ " && make"); 71 72 stderr.writeln("- Waiting for result..."); stderr.flush(); 73 auto outputFile = dirName(path).buildPath("lexbor-" ~ commit, "liblexbor_static.a"); 74 75 bool done = true; 76 77 SysTime tm = Clock.currTime(); 78 while(!outputFile.exists && done) 79 { 80 import core.thread; 81 Thread.sleep(150.dur!"msecs"); 82 83 if (Clock.currTime() - tm > 5.dur!"seconds") 84 done = false; 85 } 86 87 if (done) 88 { 89 stderr.writeln("--- DONE ---\n"); 90 copy(dirName(path).buildPath("lexbor-" ~ commit, "liblexbor_static.a"), "liblexbor_parserino.a"); 91 } 92 else 93 { 94 stderr.writeln("--- BUILD FAIL ---\nCompiler output:\n", res.output); 95 return 2; 96 } 97 98 return 0; 99 } 100 }