diff --git a/.idea/libraries/Cargo__rustfilt_.xml b/.idea/libraries/Cargo__rustfilt_.xml index 053fc6144..517e9f476 100644 --- a/.idea/libraries/Cargo__rustfilt_.xml +++ b/.idea/libraries/Cargo__rustfilt_.xml @@ -1,19 +1,19 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/Makefile b/Makefile index 1fad81561..4b8edefbc 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ $(BOWER_MODULES): bower.json $(NODE_MODULES) @touch $@ lint: $(NODE_MODULES) - $(NODE) ./node_modules/.bin/jshint app.js $(shell find lib static -name '*.js' -not -path 'static/ext/*') + $(NODE) ./node_modules/.bin/jshint app.js $(shell find lib static -name '*.js' -not -path 'static/ext/*' -not -path static/analytics.js) LANG:=C++ diff --git a/README.md b/README.md index 79e9cb2d7..9809614da 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,9 @@ Try out one of the demo sites: [C++][cpp], [Rust][rust], [D][d] or [Go][go]. [d]: https://d.godbolt.org/ "Compiler Explorer for D" [go]: https://go.godbolt.org/ "Compiler Explorer for Go" -### Developing +You can support this [this project on Patreon](https://patreon.com/mattgodbolt). + +### Developing or running a local instance Compiler Explorer is written in node.js. @@ -33,7 +35,65 @@ The config system leaves a lot to be desired, I'm working on porting [CCS](https Feel free to raise an issue on [github](https://github.com/mattgodbolt/compiler-explorer/issues) or [email me directly](mailto:matt@godbolt.org) for more help. +There's now a [Road map](Roadmap.md) that gives a little insight into future plans for Compiler Explorer. + ### Credits Compiler Explorer is maintained by [Matt Godbolt](http://xania.org). Multiple compiler and difference view was implemented by [Gabriel Devillers](https://github.com/voxelf). + +### RESTful API + +There's a simple restful API that can be used to do compiles to asm and to list compilers. In general +all handlers live in `/api/*` endpoints, and will accept JSON or text in POSTs, and will return text responses +or JSON responses depending on the request's `Accept` header. + +At a later date there may be some form of rate-limiting: currently requests will be queued and dealt with +exactly like interactive requests on the main site. Authentication might be required at some point in the +future (for the main Compiler Explorer site anyway). + +The following endpoints are defined: + +#### `GET /api/compilers` - return a list of compilers + +Returns a list of compilers. In text form, there's a simple formatting of the ID of the compiler and its +description. In JSON, all the information is returned as an array of compilers, with the `id` key being the +primary identifier of each compiler. + +#### `POST /api//compiler` - perform a compilation + +To specify a compilation request as a JSON document, post it as the appropriate type and send an object of +the form: `{'source': 'source to compile', 'options': 'compiler flags', 'filters': {'filter': true}}`. The filters are an JSON object with true/false. If not supplied, defaults are used. If supplied, the filters are used +as-is. + +A text compilation request has the source as the body of the post, and uses query parameters to pass the +options and filters. Filters are supplied as a comma-separated string. Use the query parameter `filters=XX` +to set the filters directly, else `addFilters=XX` to add a filter to defaults, or `removeFilters` to remove from defaults. Compiler parameters should be passed as `options=-O2` and default to empty. + +Filters include `binary`, `labels`, `intel`, `comments` and `directives` and correspond to the UI buttons on +the HTML version. + +The text request is designed for simplicity for command-line clients like `curl`: + +```bash +$ curl 'https://gcc.godbolt.org/api/compiler/g63/compile?options=-Wall' --data-binary 'int foo() { return 1; }' +# Compilation provided by Compiler Explorer at gcc.godbolt.org +foo(): + push rbp + mov rbp, rsp + mov eax, 1 + pop rbp + ret +``` + +If JSON is present in the request's `Accept` header, the compilation results are of the form: + +``` +{ + code: 0 if successful, else compiler return code, + stdout: [ { text: "Output", + (optional) tag: {line: source line, text: "parsed error for that line"} } ], + stderr: (as above), + asm: [ { text: "assembly text", source: source line number or null if none } ] +} +``` diff --git a/Roadmap.md b/Roadmap.md new file mode 100644 index 000000000..bafe01e88 --- /dev/null +++ b/Roadmap.md @@ -0,0 +1,80 @@ +# Compiler Explorer Road Map + +CE was started in 2012 to serve my needs at [my company](http:/drw.com) in terms of showing how +C++ constructs translated to assembly code. It started out as a `tmux` session with `vi` running in one +pane and `watch gcc -S foo.cc -o -` running in the other. Since those days it's now a public website +serving the C++, Rust, Go and D communities and performs around 20,000 compilations per day. + +This document is an attempt to capture thoughts on the future direction of Compiler Explorer. + +## Areas to improve + +### Mobile client support + +CE's UI doesn't work well with mobile clients. The editor doesn't work well on many mobile clients, and the +layout doesn't lend itself well to small screens. + +Ideas for improving mobile support include automatically folding up all the panes into a single tab upon +detection of a mobile client. This would require a bunch of fixes in the +underlying [UI library](http://golden-layout.com) as this doesn't properly work with mobile and tabs. + +Perhaps a read-only simplified view would work better: the main reason one brings up the CE website is to +look at tweeted links rather than author content. + +### UI improvements + +The UI has a number of things that need improving: + +* Multiple editor windows +* Saving and restoring from browser-local storage +* Handling the loss of data if one has a work-in-progress CE window open and then clicks another CE link. + +### Diff view + +A frequently requested feature is to be able to diff output. A large patch was provided by @Voxelf which +helped spur on the development of the new UI, but the diff view he created has yet to be merged. There's +a possibility that moving to the [Monaco](https://microsoft.github.io/monaco-editor/) editor will not only +give a better editing experience, but also bring pretty much free diff windows out of the box. + +### Execution support + +Another big ticket item is to allow executing of the user's code. This is fraught with security issues, and +brings up a number of UI and API considerations. Compiling code every time to execute with different params +seems wasteful, so caching seems good; but in a multi-instance setup a shared cache woudl be needed. Perhaps +a backend system that caches the executables (and makes them downloadable; at least for some compilers where +license allows), and stores the binaries in ephemeral, shared storage. This same backend system could also +be used to store code, and could be part of a whole new way of sending and sharing code (if made permanent +storage). + +### Support more compilers + +Most of the open tickets are to do with adding new compilers, or fixing issues with existing compilers. +Continuing to add more compilers and make it easier for others to submit PRs to add new compilers is +very important. + +## Tensions + +There's an inherent tension between the standalone, run-it-yourself version of CE and the scalable, AWS-backed +CE instance. Care must be taken to keep the standalone version usable, not least as the majority of CE's +development is done on a laptop during a commute (with little or no internet access). + +## Priorities + +Above all, the priority is to keep the main CE site up, stable and dependable. After that, features are +added honestly in the order that is most useful and interesting to the primary developer (Matt Godbolt). + +## Non-goals + +CE will remain ad-free, open-source and non-commercial. There's no plans at all to add "freemium" content. + +## 2017 goals + +With all this in mind, the tentative goals for 2017 are: + +* Move to the Monaco editor + * Implement diff view +* Come up with a decent secure solution for code execution +* Design an API that can handle remote code execution and download needs +* Implement remote execution UIs + +These goals will be refined as time ticks on. diff --git a/app.js b/app.js index 3404f6144..676677fbd 100755 --- a/app.js +++ b/app.js @@ -138,8 +138,8 @@ fileSources.forEach(function (source) { }); var clientOptionsHandler = new ClientOptionsHandler(fileSources); -var apiHandler = new ApiHandler(); var compileHandler = new CompileHandler(gccProps, compilerProps); +var apiHandler = new ApiHandler(compileHandler); // auxiliary function used in clientOptionsHandler function compareOn(key) { @@ -271,7 +271,10 @@ function findCompilers() { var request = http.get({ hostname: host, port: port, - path: "/api/compilers" + path: "/api/compilers", + headers: { + 'Accept': 'application/json' + } }, function (res) { var str = ''; res.on('data', function (chunk) { @@ -386,27 +389,32 @@ function findCompilers() { }); } -// Instantiate a function that writes information on the compiler, -// in JSON format, for ease of external listing. -function ApiHandler() { - var reply = ""; +function ApiHandler(compileHandler) { + this.compilers = []; + this.compileHandler = compileHandler; this.setCompilers = function (compilers) { - reply = JSON.stringify(compilers); + this.compilers = compilers; }; - this.handler = function apiHandler(req, res, next) { - var bits = req.url.split("/"); - if (bits.length !== 2 || req.method !== "GET") return next(); - switch (bits[1]) { - default: - next(); - break; - - case "compilers": - res.set('Content-Type', 'application/json'); - res.end(reply); - break; + this.handler = express.Router(); + this.handler.get('/compilers', _.bind(function (req, res, next) { + if (req.accepts(['text', 'json']) == 'json') { + res.set('Content-Type', 'application/json'); + res.end(JSON.stringify(this.compilers)); + } else { + res.set('Content-Type', 'text/plain'); + var title = 'Compiler Name'; + var maxLength = _.max(_.pluck(_.pluck(this.compilers, 'id').concat([title]), 'length')); + res.write(utils.padRight(title, maxLength) + ' | Description\n'); + res.end(_.map(this.compilers, function (compiler) { + return utils.padRight(compiler.id, maxLength) + ' | ' + compiler.name; + }).join("\n")); } - }; + }, this)); + this.handler.param('compiler', _.bind(function (req, res, next, compilerName) { + req.compiler = compilerName; + next(); + }, this)); + this.handler.post('/compiler/:compiler/compile', this.compileHandler.handler); } function shortUrlHandler(req, res, next) { @@ -455,7 +463,6 @@ function embeddedHandler(req, res, next) { res.end(); } - findCompilers() .then(function (compilers) { var prevCompilers; @@ -485,7 +492,6 @@ findCompilers() var webServer = express(), sFavicon = require('serve-favicon'), - sStatic = require('serve-static'), bodyParser = require('body-parser'), morgan = require('morgan'), compression = require('compression'), @@ -502,24 +508,29 @@ findCompilers() .use(morgan('combined', {stream: logger.stream})) .use(compression()) .use(sFavicon(staticDir + '/favicon.ico')) - .use('/v', sStatic(staticDir + '/v', {maxAge: Infinity})) - .use(sStatic(staticDir, {maxAge: staticMaxAgeSecs * 1000})); + .use('/v', express.static(staticDir + '/v', {maxAge: Infinity, index: false})) + .use(express.static(staticDir, {maxAge: staticMaxAgeSecs * 1000})); if (archivedVersions) { // The archived versions directory is used to serve "old" versioned data during updates. It's expected // to contain all the SHA-hashed directories from previous versions of Compiler Explorer. logger.info(" serving archived versions from", archivedVersions); - webServer.use('/v', sStatic(archivedVersions, {maxAge: Infinity})); + webServer.use('/v', express.static(archivedVersions, {maxAge: Infinity, index: false})); } webServer .use(bodyParser.json({limit: gccProps('bodyParserLimit', '1mb')})) + .use(bodyParser.text({ + limit: gccProps('bodyParserLimit', '1mb'), type: function () { + return true; + } + })) .use(restreamer()) .get('/client-options.json', clientOptionsHandler.handler) .use('/source', getSource) .use('/api', apiHandler.handler) .use('/g', shortUrlHandler) .use('/e', embeddedHandler) - .post('/compile', compileHandler.handler) // used inside static/compiler.js - .post('/diff', diffHandler); // used inside static/compiler.js + .post('/compile', compileHandler.handler) + .post('/diff', diffHandler); logger.info("======================================="); webServer.on('error', function (err) { diff --git a/c-preload/compiler-wrapper b/c-preload/compiler-wrapper index 8bf3cc7d9..d91e8921f 100755 --- a/c-preload/compiler-wrapper +++ b/c-preload/compiler-wrapper @@ -15,7 +15,7 @@ ALLOWED_FOR_READ=${ALLOWED_FOR_READ}:/usr/share/fonts:/etc/passwd # Last-gasp limits ulimit -m $((512 * 1024)) # RSS limit in K -ulimit -t 5 # CPU time in seconds +ulimit -t 10 # CPU time in seconds ulimit -v $((2 * 1024 * 1024)) # virtual RAM limit in K "$@" diff --git a/etc/config/c++.amazon.properties b/etc/config/c++.amazon.properties index 5d7ced6a2..67bdb1194 100644 --- a/etc/config/c++.amazon.properties +++ b/etc/config/c++.amazon.properties @@ -1,8 +1,13 @@ compilers=gcc1204@20480:&gcc86:&icc:&clang:&cl:&cross:&ellcc defaultCompiler=g63 +textBanner=Compilation provided by Compiler Explorer at https://gcc.godbolt.org/ + ############################### # GCC for x86 -group.gcc86.compilers=g471:g472:g473:g474:g481:g482:g483:g484:g485:g490:g491:g492:g493:g494:g510:g520:g530:g540:g6:g62:g63:g7snapshot +group.gcc86.compilers=g464:g471:g472:g473:g474:g481:g482:g483:g484:g485:g490:g491:g492:g493:g494:g510:g520:g530:g540:g6:g62:g63:g7snapshot +compiler.g464.exe=/opt/compiler-explorer/gcc-4.6.4/bin/g++ +compiler.g464.alias=/usr/bin/g++-4.6 +compiler.g464.name=x86-64 gcc 4.6.4 compiler.g471.exe=/opt/compiler-explorer/gcc-4.7.1/bin/g++ compiler.g471.name=x86-64 gcc 4.7.1 compiler.g472.exe=/opt/compiler-explorer/gcc-4.7.2/bin/g++ @@ -50,10 +55,28 @@ compiler.g7snapshot.exe= /opt/compiler-explorer/gcc-7-snapshot/bin/g++ compiler.g7snapshot.name=x86-64 gcc 7 (snapshot) # Clang for x86 -group.clang.compilers=clang350:clang351:clang37x:clang36x:clang371:clang380:clang381:clang390:clang391:clang_trunk +group.clang.compilers=clang30:clang31:clang32:clang33:clang341:clang350:clang351:clang37x:clang36x:clang371:clang380:clang381:clang390:clang391:clang_trunk group.clang.intelAsm=-masm=intel group.clang.options=--gcc-toolchain=/opt/compiler-explorer/gcc-6.2.0 -compiler.clang350.exe=/usr/bin/clang++-3.5 +compiler.clang30.exe=/opt/compiler-explorer/clang+llvm-3.0-x86_64-linux-Ubuntu-11_10/bin/clang++ +compiler.clang30.alias=/usr/bin/clang++ +compiler.clang30.name=x86-64 clang 3.0 +compiler.clang30.options= +compiler.clang31.exe=/opt/compiler-explorer/clang+llvm-3.1-x86_64-linux-ubuntu_12.04/bin/clang++ +compiler.clang31.name=x86-64 clang 3.1 +compiler.clang31.options= +compiler.clang32.exe=/opt/compiler-explorer/clang-3.2/bin/clang++ +compiler.clang32.alias=/opt/clang-3.2/bin/clang++ +compiler.clang32.name=x86-64 clang 3.2 +compiler.clang32.options= +compiler.clang33.exe=/opt/compiler-explorer/clang-3.3/bin/clang++ +compiler.clang33.alias=/opt/clang-3.3/bin/clang++ +compiler.clang33.name=x86-64 clang 3.3 +compiler.clang33.options= +compiler.clang341.exe=/opt/compiler-explorer/clang+llvm-3.4.1-x86_64-unknown-ubuntu12.04/bin/clang++ +compiler.clang341.alias=/opt/clang+llvm-3.4.1-x86_64-unknown-ubuntu12.04/bin/clang++ +compiler.clang341.name=x86-64 clang 3.4.1 +compiler.clang350.exe=/opt/compiler-explorer/clang+llvm-3.5.0-x86_64-linux-gnu/bin/clang++ compiler.clang350.name=x86-64 clang 3.5 compiler.clang351.exe=/opt/compiler-explorer/clang+llvm-3.5.1-x86_64-linux-gnu/bin/clang++ compiler.clang351.name=x86-64 clang 3.5.1 @@ -77,9 +100,14 @@ compiler.clang_trunk.exe=/opt/compiler-explorer/clang-trunk/bin/clang++ compiler.clang_trunk.name=x86-64 clang (trunk) # icc for x86 -group.icc.compilers=icc16:icc17 +group.icc.compilers=icc1301:icc16:icc17 group.icc.intelAsm=-masm=intel group.icc.needsMulti=false +compiler.icc1301.exe=/opt/compiler-explorer/intel/bin/icc +compiler.icc1301.alias=/opt/intel/bin/icc +compiler.icc1301.name=x86-64 icc 13.0.1 +# intel 13.01 binary disabled: it just segfaults (no idea why) +compiler.icc1301.supportsBinary=false compiler.icc16.exe=/opt/compiler-explorer/intel/xe_2016_update3/bin/icc compiler.icc16.name=x86-64 icc 16 compiler.icc17.exe=/opt/compiler-explorer/intel/2017/bin/icc diff --git a/etc/config/c++.amazon1204.properties b/etc/config/c++.amazon1204.properties index e361ed8b1..b737aaddb 100644 --- a/etc/config/c++.amazon1204.properties +++ b/etc/config/c++.amazon1204.properties @@ -1,41 +1,14 @@ -compilers=&gcc86:&clang:avrg453:&gccarm:icc1301:msp430g453 +compilers=&gcc86:avrg453:&gccarm:msp430g453 defaultCompiler=g447 ############################### # GCC for x86 -group.gcc86.compilers=g447:g453:g464 +group.gcc86.compilers=g447:g453 compiler.g447.exe=/usr/bin/g++-4.4 compiler.g447.alias=/usr/bin/g++-4.4 compiler.g447.name=x86-64 gcc 4.4.7 compiler.g453.exe=/usr/bin/g++-4.5 compiler.g453.alias=/usr/bin/g++-4.5 compiler.g453.name=x86-64 gcc 4.5.3 -compiler.g464.exe=/usr/bin/g++-4.6 -compiler.g464.alias=/usr/bin/g++-4.6 -compiler.g464.name=x86-64 gcc 4.6.4 -# Intel for x86 -compiler.icc1301.exe=/opt/compiler-explorer/intel/bin/icc -compiler.icc1301.alias=/opt/intel/bin/icc -compiler.icc1301.name=x86-64 icc 13.0.1 -compiler.icc1301.intelAsm=-masm=intel -compiler.icc1301.needsMulti=false -# intel binary disabled for now TODO why does it segfault? preload? -compiler.icc1301.supportsBinary=false -# Clang for x86 -group.clang.compilers=clang30:clang32:clang33:clang341 -group.clang.intelAsm=-mllvm --x86-asm-syntax=intel -group.clang.options=--gcc-toolchain=/opt/compiler-explorer/gcc-6.2.0 -compiler.clang30.exe=/usr/bin/clang++ -compiler.clang30.alias=/usr/bin/clang++ -compiler.clang30.name=x86-64 clang 3.0 -compiler.clang32.exe=/opt/compiler-explorer/clang-3.2/bin/clang++ -compiler.clang32.alias=/opt/clang-3.2/bin/clang++ -compiler.clang32.name=x86-64 clang 3.2 -compiler.clang33.exe=/opt/compiler-explorer/clang-3.3/bin/clang++ -compiler.clang33.alias=/opt/clang-3.3/bin/clang++ -compiler.clang33.name=x86-64 clang 3.3 -compiler.clang341.exe=/opt/compiler-explorer/clang+llvm-3.4.1-x86_64-unknown-ubuntu12.04/bin/clang++ -compiler.clang341.alias=/opt/clang+llvm-3.4.1-x86_64-unknown-ubuntu12.04/bin/clang++ -compiler.clang341.name=x86-64 clang 3.4.1 ############################### # GCC for ARM diff --git a/etc/config/c++.danger.properties b/etc/config/c++.danger.properties index 5013c12b0..008eae286 100644 --- a/etc/config/c++.danger.properties +++ b/etc/config/c++.danger.properties @@ -1,6 +1,7 @@ # Matt's home development computer defaultCompiler=g54 -compilers=g54:g47:g48:avr +textBanner=Testing the text banner +#compilers=g54:g47:g48:avr #compilers=localhost@20480 compiler.g54.exe=/usr/bin/g++ compiler.g54.name=g++ 5.4 diff --git a/etc/config/c++.lud-mgodbolt01.properties b/etc/config/c++.lud-mgodbolt01.properties index 123020987..c118ed402 100644 --- a/etc/config/c++.lud-mgodbolt01.properties +++ b/etc/config/c++.lud-mgodbolt01.properties @@ -1,7 +1,7 @@ # Default settings for GCC Explorer. defaultCompiler=g52 -#compilers=g44:g45:g46:clang35:g51:g52:gdef:msp430g453:cl -compilers=&gcc:&clang:&windows +compilers=/usr/bin/g++:g44:g45:g46:clang35:g51:g52:gdef:msp430g453:cl:tcc +#compilers=&gcc:&clang:&windows group.gcc.compilers=gdef:g62 compiler.gdef.exe=/usr/bin/g++ compiler.gdef.name=Default G++ @@ -9,6 +9,12 @@ compiler.g62.exe=/home/mgodbolt/.fighome/runtime/gcc/6.2.0-1/bin/g++ compiler.g62.name=G++ 6.2 from fig #compiler-wrapper=./c-preload/compiler-wrapper +compiler.tcc.exe=/home/mgodbolt/personal/dev/tcc-0.9.26/tcc +compiler.tcc.name=TCC +compiler.tcc.versionFlag=-v +compileFilename=example.c +compiler.tcc.options=-B /home/mgodbolt/personal/dev/tcc-0.9.26 + group.clang.compilers=clang39 group.clang.supportsBinary=false group.clang.intelAsm=-mllvm --x86-asm-syntax=intel diff --git a/etc/config/compiler-explorer.amazon.properties b/etc/config/compiler-explorer.amazon.properties index eb763bca9..7abb56d0c 100644 --- a/etc/config/compiler-explorer.amazon.properties +++ b/etc/config/compiler-explorer.amazon.properties @@ -1,6 +1,6 @@ # Settings overridden for Amazon EC2 instances that power http://*.godbolt.org/ googleApiKey=AIzaSyAaz35KJv8DA0ABoime0fEIh32NmbyYbcQ -compileTimeoutMs=5000 +compileTimeoutMs=7500 compiler-wrapper=./c-preload/compiler-wrapper max-asm-size=8388608 staticMaxAgeSecs=30 diff --git a/etc/config/compiler-explorer.defaults.properties b/etc/config/compiler-explorer.defaults.properties index 0920065cb..3421abc22 100644 --- a/etc/config/compiler-explorer.defaults.properties +++ b/etc/config/compiler-explorer.defaults.properties @@ -1,6 +1,6 @@ # Default settings for GCC Explorer. port=10240 -compileTimeoutMs=3000 +compileTimeoutMs=10000 defaultSource=builtin cacheMb=50 language=C++ diff --git a/etc/config/d.amazon.properties b/etc/config/d.amazon.properties index 486e44718..9cacbc636 100644 --- a/etc/config/d.amazon.properties +++ b/etc/config/d.amazon.properties @@ -1,4 +1,5 @@ compilers=gdc48:gdc49:gdc52:&ldc +textBanner=Compilation provided by Compiler Explorer at https://d.godbolt.org/ defaultCompiler=gdc52 # This is only due to limitations on the d.godbolt.org image for now. supportsBinary=false @@ -12,11 +13,13 @@ compiler.gdc48.name=gdc 4.8.2 compiler.gdc52.exe=/opt/compiler-explorer/gdc5.2.0/x86_64-pc-linux-gnu/bin/gdc compiler.gdc52.name=gdc 5.2.0 -group.ldc.compilers=ldc017:ldc100:ldcbeta +group.ldc.compilers=ldc017:ldc100:ldc110:ldcbeta group.ldc.compilerType=ldc compiler.ldc017.exe=/opt/compiler-explorer/ldc0.17.2/ldc2-0.17.2-linux-x86_64/bin/ldc2 compiler.ldc017.name=ldc 0.17.2 compiler.ldc100.exe=/opt/compiler-explorer/ldc1.0.0/ldc2-1.0.0-linux-x86_64/bin/ldc2 compiler.ldc100.name=ldc 1.0.0 +compiler.ldc110.exe=/opt/compiler-explorer/ldc1.1.0/ldc2-1.1.0-linux-x86_64/bin/ldc2 +compiler.ldc110.name=ldc 1.1.0 compiler.ldcbeta.exe=/opt/compiler-explorer/ldcbeta/bin/ldc2 compiler.ldcbeta.name=ldc beta diff --git a/etc/config/go.amazon.properties b/etc/config/go.amazon.properties index 68c2d7ca6..0d7534841 100644 --- a/etc/config/go.amazon.properties +++ b/etc/config/go.amazon.properties @@ -1,4 +1,5 @@ defaultCompiler=gccgo491 +textBanner=Compilation provided by Compiler Explorer at https://go.godbolt.org/ compilers=gccgo491:6g141 compileFilename=file.go compiler.gccgo491.exe=/usr/bin/gccgo diff --git a/etc/config/rust.amazon.properties b/etc/config/rust.amazon.properties index 7de85c1d6..3c74a1dd9 100644 --- a/etc/config/rust.amazon.properties +++ b/etc/config/rust.amazon.properties @@ -1,4 +1,5 @@ compilers=&rust +textBanner=Compilation provided by Compiler Explorer at https://rust.godbolt.org/ defaultCompiler=r1140 group.rust.compilers=r1140:r1130:r1120:r1110:r1100:r190:r180:r170:r160:r150:r140:r130:r120:r110:r100:nightly:beta group.rust.compilerType=rust diff --git a/lib/asm-cl.js b/lib/asm-cl.js index 16abe1fcd..1a817d023 100644 --- a/lib/asm-cl.js +++ b/lib/asm-cl.js @@ -34,12 +34,12 @@ var gccExplorerDir = /\\compiler-explorer-compiler/; // has to match part of the // * optional leading whitespace // * middle part // * comment part -var parseRe = /^(\s*)([^;]*)(;.*)*$/; -var isProc = /.*PROC$/; -var isEndp = /.*ENDP$/; +var parseRe = /^(\s*)([^;]*)(;.*)?$/; +var isProc = /.*PROC\s*$/; +var isEndp = /.*ENDP\s*$/; var constDef = /^([a-zA-Z_$@][a-zA-Z_$@0-9.]*)\s*=.*$/; var labelFind = /[.a-zA-Z_@$][a-zA-Z_$@0-9.]*/g; -var labelDef = /^(.*):$/; +var labelDef = /^(.*):\s*$/; // Anything identifier-looking with a "@@" in the middle, and a comment at the end // is treated as a mangled name. The comment will be used to replace the identifier. var mangledIdentifier = /\?[^ ]+@@[^ |]+/; diff --git a/lib/base-compiler.js b/lib/base-compiler.js index 1c51b1c5b..e8e80733c 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -250,6 +250,10 @@ Compile.prototype.checkOptions = function (options) { return null; }; +// This check for arbitrary user-controlled preprocessor inclusions +// can be circumvented in more than one way. The goal here is to respond +// to simple attempts with a clear diagnostic; the service still needs to +// assume that malicious actors can make the compiler open arbitrary files. Compile.prototype.checkSource = function (source) { var re = /^\s*#\s*i(nclude|mport)(_next)?\s+["<"](\/|.*\.\.)/; var failed = []; @@ -319,4 +323,14 @@ Compile.prototype.getInfo = function () { return this.compiler; }; +Compile.prototype.getDefaultFilters = function () { + // TODO; propagate to UI? + return { + intel: true, + commentOnly: true, + directives: true, + labels: true + }; +}; + module.exports = Compile; diff --git a/lib/compilation-env.js b/lib/compilation-env.js index c028e1dcc..29ca33114 100644 --- a/lib/compilation-env.js +++ b/lib/compilation-env.js @@ -100,6 +100,10 @@ CompilationEnvironment.prototype.enqueue = function (job) { return this.compileQueue.add(job); }; +CompilationEnvironment.prototype.isBusy = function () { + return this.compileQueue.getPendingLength() > 0 || this.compileQueue.getQueueLength() > 0; +}; + CompilationEnvironment.prototype.findBadOptions = function (options) { return _.filter(options, function (option) { return !option.match(this.okOptions) || option.match(this.badOptions); diff --git a/lib/compile-handler.js b/lib/compile-handler.js index 2f874e9c8..fc8299c8c 100644 --- a/lib/compile-handler.js +++ b/lib/compile-handler.js @@ -33,26 +33,28 @@ var child_process = require('child_process'), temp.track(); -function periodicCleanup() { - temp.cleanup(function (err, stats) { - if (err) logger.error("Error cleaning directories: ", err); - if (stats) logger.debug("Directory cleanup stats:", stats); - }); -} - var oneTimeInit = false; -function initialise(gccProps, compilerProps) { +function initialise(gccProps, compilerEnv) { if (oneTimeInit) return; oneTimeInit = true; var tempDirCleanupSecs = gccProps("tempDirCleanupSecs", 600); logger.info("Cleaning temp dirs every " + tempDirCleanupSecs + " secs"); - setInterval(periodicCleanup, tempDirCleanupSecs * 1000); + setInterval(function () { + if (compilerEnv.isBusy()) { + logger.warn("Skipping temporary file clean up as compiler environment is busy"); + return; + } + temp.cleanup(function (err, stats) { + if (err) logger.error("Error cleaning directories: ", err); + if (stats) logger.debug("Directory cleanup stats:", stats); + }); + }, tempDirCleanupSecs * 1000); } function CompileHandler(gccProps, compilerProps) { - initialise(gccProps, compilerProps); this.compilersById = {}; this.compilerEnv = new CompilationEnvironment(gccProps, compilerProps); + initialise(gccProps, this.compilerEnv); this.factories = {}; this.create = function (compiler) { @@ -83,39 +85,85 @@ function CompileHandler(gccProps, compilerProps) { }); }; var proxy = httpProxy.createProxyServer({}); + var textBanner = compilerProps('textBanner'); this.handler = _.bind(function compile(req, res, next) { - var compiler = this.compilersById[req.body.compiler]; - if (!compiler) return next(); - + var source, options, filters, compiler; + if (req.is('json')) { + // JSON-style request + compiler = this.compilersById[req.compiler || req.body.compiler]; + if (!compiler) return next(); + source = req.body.source; + options = req.body.options; + filters = req.body.filters || compiler.getDefaultFilters(); + } else { + // API-style + compiler = this.compilersById[req.compiler]; + if (!compiler) return next(); + source = req.body; + options = req.query.options; + // By default we get the default filters. + filters = compiler.getDefaultFilters(); + // If specified exactly, we'll take that with ?filters=a,b,c + if (req.query.filters) { + filters = _.object(_.map(req.query.filters.split(","), function (filter) { + return [filter, true]; + })); + } + // Add a filter. ?addFilters=binary + _.each((req.query.addFilters || "").split(","), function (filter) { + filters[filter] = true; + }); + // Remove a filter. ?removeFilter=intel + _.each((req.query.removeFilters || "").split(","), function (filter) { + delete filters[filter]; + }); + } var remote = compiler.getRemote(); if (remote) { + req.url = req.originalUrl; // Undo any routing that was done to get here (i.e. /api/* path has been removed) proxy.web(req, res, {target: remote}, function (e) { logger.error("Proxy error: ", e); next(e); }); return; } - var source = req.body.source; - var options = req.body.options || ''; + if (source === undefined) { return next(new Error("Bad request")); } - options = _.chain(quote.parse(options) + options = _.chain(quote.parse(options || '') .map(function (x) { if (typeof(x) == "string") return x; return x.pattern; })) .filter(_.identity) .value(); - var filters = req.body.filters; + function textify(array) { + return _.pluck(array || [], 'text').join("\n"); + } + compiler.compile(source, options, filters).then( function (result) { - res.set('Content-Type', 'application/json'); - res.end(JSON.stringify(result)); + if (req.accepts(['text', 'json']) === 'json') { + res.set('Content-Type', 'application/json'); + res.end(JSON.stringify(result)); + } else { + res.set('Content-Type', 'text/plain'); + try { + if (!_.isEmpty(textBanner)) res.write('# ' + textBanner + "\n"); + res.write(textify(result.asm)); + if (result.code !== 0) res.write("\n# Compiler exited with result code " + result.code); + if (!_.isEmpty(result.stdout)) res.write("\nStandard out:\n" + textify(result.stdout)); + if (!_.isEmpty(result.stderr)) res.write("\nStandard error:\n" + textify(result.stderr)); + } catch (ex) { + re.write("Error handling request: " + ex); + } + res.end('\n'); + } }, function (error) { - logger.error("Error: " + error); + logger.error("Error: " + error.stack || error); if (typeof(error) !== "string") { error = "Internal GCC explorer error: " + error.toString(); } diff --git a/lib/exec.js b/lib/exec.js index 17040a266..34d474678 100644 --- a/lib/exec.js +++ b/lib/exec.js @@ -24,7 +24,8 @@ var child_process = require('child_process'), path = require('path'), - logger = require('./logger').logger; + logger = require('./logger').logger, + treeKill = require('tree-kill'); function execute(command, args, options) { options = options || {}; @@ -43,8 +44,10 @@ function execute(command, args, options) { env: env, detached: process.platform == 'linux' }); + var running = true; + var killChild = options.killChild || function () { - child.kill(); + if (running) treeKill(child.pid); }; var stderr = ""; var stdout = ""; @@ -79,6 +82,7 @@ function execute(command, args, options) { child.on('exit', function (code) { logger.debug({type: 'exited', code: code}); if (timeout !== undefined) clearTimeout(timeout); + running = false; }); return new Promise(function (resolve, reject) { child.on('error', function (e) { diff --git a/lib/utils.js b/lib/utils.js index d590f5e73..8bc0ba59b 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -66,4 +66,11 @@ function parseOutput(lines, inputFilename) { return result; } -exports.parseOutput = parseOutput; \ No newline at end of file +exports.parseOutput = parseOutput; + +function padRight(name, len) { + while (name.length < len) name = name + ' '; + return name; +} + +exports.padRight = padRight; \ No newline at end of file diff --git a/package.json b/package.json index 0a987e9de..56a1e0f3b 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,8 @@ "promise-queue": "2.1.x", "nopt": "3.0.x", "serve-favicon": "2.3.x", - "serve-static": "1.10.x", "temp": "0.8.x", + "tree-kill": "1.1.x", "underscore-node": "*", "shell-quote": "1.6.x", "winston": "2.2.x" diff --git a/static/alert.js b/static/alert.js new file mode 100644 index 000000000..c18aadae1 --- /dev/null +++ b/static/alert.js @@ -0,0 +1,41 @@ +// Copyright (c) 2012-2017, Matt Godbolt +// +// 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. + +define(function (require) { + var $ = require('jquery'); + + function Alert() { + this.modal = $('#alert'); + this.title = this.modal.find('.modal-title'); + this.body = this.modal.find('.modal-body'); + } + + Alert.prototype.alert = function (title, body) { + this.title.html(title); + this.body.html(body); + this.modal.modal(); + }; + return Alert; +}); \ No newline at end of file diff --git a/static/analytics.js b/static/analytics.js index 8f1a9d2d2..e18ba4cd0 100644 --- a/static/analytics.js +++ b/static/analytics.js @@ -55,6 +55,51 @@ define(function (require) { gaProxy = function () { window.ga.apply(window.ga, arguments); }; + // fullstory stuff: + window['_fs_debug'] = false; + window['_fs_host'] = 'www.fullstory.com'; + window['_fs_org'] = '2F4NV'; + window['_fs_namespace'] = 'FS'; + (function (m, n, e, t, l, o, g, y) { + if (e in m && m.console && m.console.log) { + m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].'); + return; + } + g = m[e] = function (a, b) { + g.q ? g.q.push([a, b]) : g._api(a, b); + }; + g.q = []; + o = n.createElement(t); + o.async = 1; + o.src = 'https://' + _fs_host + '/s/fs.js'; + y = n.getElementsByTagName(t)[0]; + y.parentNode.insertBefore(o, y); + g.identify = function (i, v) { + g(l, {uid: i}); + if (v) g(l, v) + }; + g.setUserVars = function (v) { + g(l, v) + }; + g.identifyAccount = function (i, v) { + o = 'account'; + v = v || {}; + v.acctId = i; + g(o, v) + }; + g.clearUserCookie = function (c, d, i) { + if (!c || document.cookie.match('fs_uid=[`;`]*`[`;`]*`[`;`]*`')) { + d = n.domain; + while (1) { + n.cookie = 'fs_uid=;domain=' + d + + ';path=/;expires=' + new Date(0).toUTCString(); + i = d.indexOf('.'); + if (i < 0)break; + d = d.slice(i + 1) + } + } + }; + })(window, document, window['_fs_namespace'], 'script', 'user'); } else { gaProxy = function () { }; diff --git a/static/assets/GitHub-Mark-20px.png b/static/assets/GitHub-Mark-20px.png new file mode 100644 index 000000000..87da1a4fc Binary files /dev/null and b/static/assets/GitHub-Mark-20px.png differ diff --git a/static/assets/patreon_logo.png b/static/assets/patreon_logo.png new file mode 100644 index 000000000..74d9c18d7 Binary files /dev/null and b/static/assets/patreon_logo.png differ diff --git a/static/async-get.js b/static/async-get.js new file mode 100644 index 000000000..860dcc0ef --- /dev/null +++ b/static/async-get.js @@ -0,0 +1,36 @@ +// Copyright (c) 2012-2017, Matt Godbolt +// +// 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. + +define({ + load: function (name, req, onLoad, config) { + if (config.isBuild) return onLoad(null); // optimizer build + + req(['jquery'], function ($) { + $.ajax({type: "GET", url: name}).done(function (response) { + onLoad(response); + }); + }); + } +}); diff --git a/static/compiler.js b/static/compiler.js index ad5e991c5..d0fe6f51c 100644 --- a/static/compiler.js +++ b/static/compiler.js @@ -113,7 +113,7 @@ define(function (require) { self.eventHub.emit('compilerClose', self.id); }, this); container.on('resize', this.resize, this); - container.on('shown', this.refresh, this); + container.on('shown', this.resize, this); container.on('open', function () { self.eventHub.emit('compilerOpen', self.id); self.updateFontScale(); @@ -154,10 +154,6 @@ define(function (require) { this.saveState(); } - Compiler.prototype.refresh = function () { - this.outputEditor.refresh(); - }; - // TODO: need to call resize if either .top-bar or .bottom-bar resizes, which needs some work. // Issue manifests if you make a window where one compiler is small enough that the buttons spill onto two lines: // reload the page and the bottom-bar is off the bottom until you scroll a tiny bit. @@ -165,7 +161,7 @@ define(function (require) { var topBarHeight = this.domRoot.find(".top-bar").outerHeight(true); var bottomBarHeight = this.domRoot.find(".bottom-bar").outerHeight(true); this.outputEditor.setSize(this.domRoot.width(), this.domRoot.height() - topBarHeight - bottomBarHeight); - this.refresh(); + this.outputEditor.refresh(); }; // Gets the filters that will actually be used (accounting for issues with binary @@ -218,7 +214,7 @@ define(function (require) { }, this), 500); $.ajax({ type: 'POST', - url: '/compile', + url: '/api/compiler/' + encodeURIComponent(request.compiler) + '/compile', dataType: 'json', contentType: 'application/json', data: jsonRequest, diff --git a/static/editor.js b/static/editor.js index fea65fe33..8cc2e23b4 100644 --- a/static/editor.js +++ b/static/editor.js @@ -122,14 +122,10 @@ define(function (require) { this.debouncedEmitChange(); }, this)); - function refresh() { - self.editor.refresh(); - } - function resize() { var topBarHeight = self.domRoot.find(".top-bar").outerHeight(true); self.editor.setSize(self.domRoot.width(), self.domRoot.height() - topBarHeight); - refresh(); + self.editor.refresh(); } this.domRoot.find('.load-save').click(_.bind(function () { @@ -141,7 +137,7 @@ define(function (require) { }, this)); container.on('resize', resize); - container.on('shown', refresh); + container.on('shown', resize); container.on('open', function () { self.eventHub.emit('editorOpen', self.id); }); diff --git a/static/explorer.css b/static/explorer.css index 0e76984f3..9b9641c3e 100644 --- a/static/explorer.css +++ b/static/explorer.css @@ -6,7 +6,16 @@ .navbar { border-radius: 0; - margin-bottom: 5px; + margin-bottom: 2px; +} + +.navbar-inverse { + background-color: #226; +} + +.navbar-inverse .navbar-brand { + color: #ddd; + font-weight: bold; } .float-link { @@ -213,4 +222,10 @@ pre.content { .compile-time { font-size: x-small; font-style: italic; +} + +.url-parse-info { + font-size: small; + margin-top: 1em; + font-style: italic; } \ No newline at end of file diff --git a/static/index.html b/static/index.html index 66372782b..5626a56de 100644 --- a/static/index.html +++ b/static/index.html @@ -13,12 +13,23 @@