Browse Source

Merge pull request #540 from AndrewPardoe/master

Merge back changes to run CE under Windows Subsystem for Linux
master
Matt Godbolt 5 years ago committed by GitHub
parent
commit
13dce4a360
  1. 16
      app.js
  2. 2
      etc/config/c++.amazon.properties
  3. 2
      etc/config/c++.danger.properties
  4. 32
      etc/config/c++.defaults.properties
  5. 2
      etc/config/c++.lud-mgodbolt01.properties
  6. 5
      lib/base-compiler.js
  7. 67
      lib/compilers/WSL-CL.js
  8. 0
      lib/compilers/Wine-CL.js
  9. 3
      lib/exec.js

16
app.js

@ -52,11 +52,25 @@ var opts = nopt({
'debug': [Boolean],
'static': [String],
'archivedVersions': [String],
'noRemoteFetch': [Boolean]
'noRemoteFetch': [Boolean],
'tmpDir': [String]
});
if (opts.debug) logger.level = 'debug';
// AP: Detect if we're running under Windows Subsystem for Linux. Temporary modification
// of process.env is allowed: https://nodejs.org/api/process.html#process_process_env
if (child_process.execSync('uname -a').toString().indexOf('Microsoft') > -1)
process.env.wsl = true;
// AP: Allow setting of tmpDir (used in lib/base-compiler.js & lib/exec.js) through
// opts. WSL requires a tmpDir as it can't see Linux volumes so set default to c:\tmp.
if (opts.tmpDir)
process.env.tmpDir = opts.tmpDir;
else if (process.env.wsl)
process.env.tmpDir = "/mnt/c/tmp";
// Set default values for omitted arguments
var rootDir = opts.rootDir || './etc';
var language = opts.language || "C++";

2
etc/config/c++.amazon.properties

@ -212,7 +212,7 @@ compiler.mips564el.name=MIPS64 gcc 5.4 (el)
# Windows Compilers
group.cl.compilers=&cl19
group.cl.needsMulti=false
group.cl.compilerType=CL
group.cl.compilerType=Wine-CL
group.cl.versionFlag=/?
group.cl.versionRe=^Microsoft \(R\) C/C\+\+.*$
group.cl19.compilers=cl19_64:cl19_32:cl19_arm

2
etc/config/c++.danger.properties

@ -22,7 +22,7 @@ compiler.avrg454.name=AVR gcc 4.5.4
group.cl.compilers=&cl19
group.cl.needsMulti=false
group.cl.compilerType=CL
group.cl.compilerType=Wine-CL
group.cl.versionFlag=/?
group.cl.versionRe=^Microsoft \(R\) C/C\+\+.*$
group.cl19.compilers=cl19_64:cl19_32:cl19_arm

32
etc/config/c++.defaults.properties

@ -1,5 +1,6 @@
# Default settings for C++
compilers=/usr/bin/g++-4.4:/usr/bin/g++-4.5:/usr/bin/g++-4.6:/usr/bin/g++-4.7:/usr/bin/g++-4.8:/usr/bin/clang++:/usr/bin/g++-5:/usr/bin/g++-7:/usr/bin/g++-6:/usr/bin/g++
# AP: Add &cl group
compilers=/usr/bin/g++-4.4:/usr/bin/g++-4.5:/usr/bin/g++-4.6:/usr/bin/g++-4.7:/usr/bin/g++-4.8:/usr/bin/clang++:/usr/bin/g++-5:/usr/bin/g++-7:/usr/bin/g++-6:/usr/bin/g++:&cl
defaultCompiler=/usr/bin/g++
compileFilename=example.cpp
postProcess=
@ -12,8 +13,29 @@ binaryHideFuncRe=^(__.*|_(init|start|fini)|(de)?register_tm_clones|call_gmon_sta
stubRe=\bmain\b
stubText=int main(void){return 0;/*stub provided by Compiler Explorer*/}
-#################################
-#################################
-# Installed libs (See c++.amazon.properties for a scheme of libs group)
-libs=
#################################
#################################
# Installed libs (See c++.amazon.properties for a scheme of libs group)
libs=
# AP: hard-code this to my MSVC install
################################
# Windows Compilers
group.cl.compilers=&cl19
group.cl.needsMulti=false
group.cl.compilerType=WSL-CL
group.cl.versionFlag=/?
group.cl.versionRe=^Microsoft \(R\) C/C\+\+.*$
#group.cl19.compilers=cl19_64:cl19_32:cl19_arm
#group.cl19.options=/I/opt/compiler-explorer/windows/10.0.10240.0/ucrt/ /I/opt/compiler-explorer/windows/19.10.25017/lib/native/include/
#compiler.cl19_64.exe=/opt/compiler-explorer/windows/19.10.25017/lib/native/bin/amd64/cl.exe
#compiler.cl19_64.name=x86-64 CL 19 2017 RTW
#compiler.cl19_32.exe=/opt/compiler-explorer/windows/19.10.25017/lib/native/bin/amd64_x86/cl.exe
#compiler.cl19_32.name=x86 CL 19 2017 RTW
#compiler.cl19_arm.exe=/opt/compiler-explorer/windows/19.10.25017/lib/native/bin/amd64_arm/cl.exe
#compiler.cl19_arm.name=ARM CL 2017 RTW
group.cl19.compilers=cl19_64
group.cl19.options=/I/mnt/c/str/windows/10.0.15063.0/ucrt/ /I/mnt/c/str/windows/19.10.25017/lib/native/include/
compiler.cl19_64.exe=/mnt/c/str/windows/19.10.25017/lib/native/bin/amd64/cl.exe
compiler.cl19_64.name=x86-64 CL 19 2017 RTW

2
etc/config/c++.lud-mgodbolt01.properties

@ -22,7 +22,7 @@ compiler.clang39.exe=/usr/bin/clang++-3.9
compiler.clang39.name=Clang 3.9
group.windows.compilers=&cl19
group.windows.compilerType=CL
group.windows.compilerType=Wine-CL
group.windows.needsMulti=false
group.windows.versionFlag=/?
group.windows.versionRe=^Microsoft \(R\) C/C\+\+.*$

5
lib/base-compiler.js

@ -46,9 +46,12 @@ function Compile(compiler, env) {
this.compiler.supportsIntel = !!this.compiler.intelAsm;
}
// AP: Create directory in specified tmpDir. tmpDir on Windows volume is required for WSL execution.
// NPM temp package: https://www.npmjs.com/package/temp, see Affixes
Compile.prototype.newTempDir = function () {
return new Promise(function (resolve, reject) {
temp.mkdir('compiler-explorer-compiler', function (err, dirPath) {
// temp.mkdir('compiler-explorer-compiler', function (err, dirPath) {
temp.mkdir({prefix: 'compiler-explorer-compiler', dir: process.env.tmpDir}, function (err, dirPath) {
if (err)
reject("Unable to open temp file: " + err);
else

67
lib/compilers/WSL-CL.js

@ -0,0 +1,67 @@
// Copyright (c) 2017, Andrew Pardoe
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// AP: WSL-CL.js is a WSL-specific copy of CL.js (renamed to Wine-CL.js).
// Main differences:
// Don't run under Wine (obviously)
// Translate compiler path from Unix mounted volume (/mnt/c/tmp) to Windows (c:/tmp)
var Compile = require('../base-compiler');
var asm = require('../asm-cl');
function compileCl(info, env) {
var compile = new Compile(info, env);
compile.asm = new asm.AsmParser(env.compilerProps);
info.supportsFiltersInBinary = true;
if (process.platform == "linux") {
var origExec = compile.exec;
compile.exec = function (command, args, options) {
return origExec(command, args, options);
};
compile.filename = function (fn) {
// AP: Need to translate compiler paths from what the Node.js process sees
// on a Unix mounted volume (/mnt/c/tmp) to what CL sees on Windows (c:/tmp)
// We know process.env.tmpDir is of format /mnt/X/dir where X is drive letter.
var driveLetter = process.env.tmpDir.substring(5, 6);
var directoryPath = process.env.tmpDir.substring(7);
var windowsStyle = driveLetter.concat(":/", directoryPath);
return fn.replace(process.env.tmpDir, windowsStyle);
};
}
compile.supportsObjdump = function () {
return false;
};
compile.optionsForFilter = function (filters, outputFilename) {
return [
'/FAsc',
'/c',
'/Fa' + this.filename(outputFilename),
'/Fo' + this.filename(outputFilename + '.obj')
];
};
return compile.initialise();
}
module.exports = compileCl;

0
lib/compilers/CL.js → lib/compilers/Wine-CL.js

3
lib/exec.js

@ -41,7 +41,10 @@ function execute(command, args, options) {
var okToCache = true;
logger.debug({type: "executing", command: command, args: args});
// AP: Run this process in specified tmpDir. tmpDir on Windows volume is required for WSL execution.
// https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options
var child = child_process.spawn(command, args, {
cwd: process.env.tmpDir,
env: env,
detached: process.platform == 'linux'
});

Loading…
Cancel
Save