From 22331361157563cdea3b8199c8d9442e7439a574 Mon Sep 17 00:00:00 2001 From: Menci Date: Sat, 1 Dec 2018 02:53:23 +0800 Subject: [PATCH] Drop some languages and support both GCC and Clang for C++ --- src/languages/c.ts | 4 +-- src/languages/cpp.ts | 4 +-- src/languages/cpp11-clang.ts | 47 ++++++++++++++++++++++++++++++++++++ src/languages/cpp11.ts | 4 +-- src/languages/cpp17-clang.ts | 47 ++++++++++++++++++++++++++++++++++++ src/languages/cpp17.ts | 4 +-- src/languages/index.ts | 12 ++++++--- 7 files changed, 111 insertions(+), 11 deletions(-) create mode 100644 src/languages/cpp11-clang.ts create mode 100644 src/languages/cpp17-clang.ts diff --git a/src/languages/c.ts b/src/languages/c.ts index 65ab0f8..5b943b3 100644 --- a/src/languages/c.ts +++ b/src/languages/c.ts @@ -9,8 +9,8 @@ export const lang = { // To customize the compilation process, // write a shell script or some other stuff, // and put it to your sandbox. - executable: "/usr/bin/gcc", - parameters: ["gcc", sourcePath, "-o", `${outputDirectory}/a.out`, "-O2", "-fdiagnostics-color=always", "-DONLINE_JUDGE", "-mx32"], + executable: "/usr/bin/clang-7", + parameters: ["clang-7", sourcePath, "-o", `${outputDirectory}/a.out`, "-O2", "-fdiagnostics-color=always", "-DONLINE_JUDGE", "-mx32"], time: 5000, memory: 1024 * 1024 * 1024 * 2, process: 10, diff --git a/src/languages/cpp.ts b/src/languages/cpp.ts index aede29b..13d2b7c 100644 --- a/src/languages/cpp.ts +++ b/src/languages/cpp.ts @@ -9,8 +9,8 @@ export const lang = { // To customize the compilation process, // write a shell script or some other stuff, // and put it to your sandbox. - executable: "/usr/bin/g++", - parameters: ["g++", sourcePath, "-o", `${outputDirectory}/a.out`, "-std=c++03", "-O2", "-fdiagnostics-color=always", "-DONLINE_JUDGE", "-mx32"], + executable: "/usr/bin/g++-8", + parameters: ["g++-8", sourcePath, "-o", `${outputDirectory}/a.out`, "-std=c++03", "-O2", "-fdiagnostics-color=always", "-DONLINE_JUDGE", "-mx32"], time: 5000, memory: 1024 * 1024 * 1024 * 2, process: 10, diff --git a/src/languages/cpp11-clang.ts b/src/languages/cpp11-clang.ts new file mode 100644 index 0000000..ceb519d --- /dev/null +++ b/src/languages/cpp11-clang.ts @@ -0,0 +1,47 @@ +export const lang = { + name: "cpp11-clang", + sourceFileName: "a.cpp", + fileExtension: "cpp", + binarySizeLimit: 5000 * 1024, + + // Note that these two paths are in the sandboxed environment. + compile: (sourcePath, outputDirectory) => ({ + // To customize the compilation process, + // write a shell script or some other stuff, + // and put it to your sandbox. + executable: "/usr/bin/clang++-7", + parameters: ["clang++-7", sourcePath, "-o", `${outputDirectory}/a.out`, "-std=c++11", "-O2", "-fdiagnostics-color=always", "-DONLINE_JUDGE", "-mx32"], + time: 5000, + memory: 1024 * 1024 * 1024 * 2, + process: 10, + // This is just a redirection. You can simply ignore this + // if you can specify custom location for message output + // in the parameter of the compiler, or have redirected the compilation + // message to somewhere. + // An example will be available soon. + stderr: `${outputDirectory}/message.txt`, + // We will read this file for message in the output directory. + messageFile: 'message.txt', + workingDirectory: outputDirectory + }), + + run: (binaryDirectory: string, + workingDirectory: string, + time: number, + memory: number, + stdinFile = null, + stdoutFile = null, + stderrFile = null + ) => ({ + executable: `${binaryDirectory}/a.out`, + parameters: [], + time: time, + memory: memory, + stackSize: memory, + process: 1, + stdin: stdinFile, + stdout: stdoutFile, + stderr: stderrFile, + workingDirectory: workingDirectory + }) +}; diff --git a/src/languages/cpp11.ts b/src/languages/cpp11.ts index 65425bf..959306a 100644 --- a/src/languages/cpp11.ts +++ b/src/languages/cpp11.ts @@ -9,8 +9,8 @@ export const lang = { // To customize the compilation process, // write a shell script or some other stuff, // and put it to your sandbox. - executable: "/usr/bin/g++", - parameters: ["g++", sourcePath, "-o", `${outputDirectory}/a.out`, "-std=c++11", "-O2", "-fdiagnostics-color=always", "-DONLINE_JUDGE", "-mx32"], + executable: "/usr/bin/g++-8", + parameters: ["g++-8", sourcePath, "-o", `${outputDirectory}/a.out`, "-std=c++11", "-O2", "-fdiagnostics-color=always", "-DONLINE_JUDGE", "-mx32"], time: 5000, memory: 1024 * 1024 * 1024 * 2, process: 10, diff --git a/src/languages/cpp17-clang.ts b/src/languages/cpp17-clang.ts new file mode 100644 index 0000000..099f57d --- /dev/null +++ b/src/languages/cpp17-clang.ts @@ -0,0 +1,47 @@ +export const lang = { + name: "cpp17-clang", + sourceFileName: "a.cpp", + fileExtension: "cpp", + binarySizeLimit: 5000 * 1024, + + // Note that these two paths are in the sandboxed environment. + compile: (sourcePath, outputDirectory) => ({ + // To customize the compilation process, + // write a shell script or some other stuff, + // and put it to your sandbox. + executable: "/usr/bin/clang++-7", + parameters: ["clang++-7", sourcePath, "-o", `${outputDirectory}/a.out`, "-std=c++17", "-O2", "-fdiagnostics-color=always", "-DONLINE_JUDGE", "-mx32"], + time: 5000, + memory: 1024 * 1024 * 1024 * 2, + process: 10, + // This is just a redirection. You can simply ignore this + // if you can specify custom location for message output + // in the parameter of the compiler, or have redirected the compilation + // message to somewhere. + // An example will be available soon. + stderr: `${outputDirectory}/message.txt`, + // We will read this file for message in the output directory. + messageFile: 'message.txt', + workingDirectory: outputDirectory + }), + + run: (binaryDirectory: string, + workingDirectory: string, + time: number, + memory: number, + stdinFile = null, + stdoutFile = null, + stderrFile = null + ) => ({ + executable: `${binaryDirectory}/a.out`, + parameters: [], + time: time, + memory: memory, + stackSize: memory, + process: 1, + stdin: stdinFile, + stdout: stdoutFile, + stderr: stderrFile, + workingDirectory: workingDirectory + }) +}; diff --git a/src/languages/cpp17.ts b/src/languages/cpp17.ts index 91502e3..5dd8f77 100644 --- a/src/languages/cpp17.ts +++ b/src/languages/cpp17.ts @@ -9,8 +9,8 @@ export const lang = { // To customize the compilation process, // write a shell script or some other stuff, // and put it to your sandbox. - executable: "/usr/bin/g++", - parameters: ["g++", sourcePath, "-o", `${outputDirectory}/a.out`, "-std=c++17", "-O2", "-fdiagnostics-color=always", "-DONLINE_JUDGE", "-mx32"], + executable: "/usr/bin/g++-8", + parameters: ["g++-8", sourcePath, "-o", `${outputDirectory}/a.out`, "-std=c++17", "-O2", "-fdiagnostics-color=always", "-DONLINE_JUDGE", "-mx32"], time: 5000, memory: 1024 * 1024 * 1024 * 2, process: 10, diff --git a/src/languages/index.ts b/src/languages/index.ts index 6127cd5..074e246 100644 --- a/src/languages/index.ts +++ b/src/languages/index.ts @@ -33,19 +33,25 @@ export const languages: Language[] = [ require('./cpp'), require('./cpp11'), require('./cpp17'), + require('./cpp11-clang'), + require('./cpp17-clang'), require('./csharp'), require('./haskell'), require('./java'), - require('./lua'), - require('./luajit'), require('./nodejs'), - require('./ocaml'), require('./pascal'), require('./python2'), require('./python3'), require('./ruby'), + // The following languages are dropped now since almost nobody uses them in LibreOJ. + // They won't be maintained and use it at your own risk! + /* require('./vala'), + require('./lua'), + require('./luajit'), + require('./ocaml'), require('./vbnet') + */ ].map(f => f.lang); export function getLanguage(name: string): Language {