Skip to content

Commit

Permalink
Merge branch 'compiler-explorer:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tgymnich authored Feb 11, 2025
2 parents fd0c840 + 4f2d4b6 commit ad0dfa8
Show file tree
Hide file tree
Showing 47 changed files with 137 additions and 94 deletions.
8 changes: 6 additions & 2 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ import {FormattingService} from './lib/formatting-service.js';
import {AssemblyDocumentationController} from './lib/handlers/api/assembly-documentation-controller.js';
import {FormattingController} from './lib/handlers/api/formatting-controller.js';
import {HealthcheckController} from './lib/handlers/api/healthcheck-controller.js';
import {NoScriptController} from './lib/handlers/api/noscript-controller.js';
import {SiteTemplateController} from './lib/handlers/api/site-template-controller.js';
import {SourceController} from './lib/handlers/api/source-controller.js';
import {CompileHandler} from './lib/handlers/compile.js';
import {cached, csp} from './lib/handlers/middleware.js';
import {cached, createFormDataHandler, csp} from './lib/handlers/middleware.js';
import {NoScriptHandler} from './lib/handlers/noscript.js';
import {RouteAPI, ShortLinkMetaData} from './lib/handlers/route-api.js';
import {languages as allLanguages} from './lib/languages.js';
Expand Down Expand Up @@ -549,6 +550,7 @@ async function main() {

const isExecutionWorker = ceProps<boolean>('execqueue.is_worker', false);
const healthCheckFilePath = ceProps('healthCheckFilePath', null) as string | null;
const formDataHandler = createFormDataHandler();

const siteTemplateController = new SiteTemplateController();
const sourceController = new SourceController(sources);
Expand All @@ -560,6 +562,7 @@ async function main() {
isExecutionWorker,
);
const formattingController = new FormattingController(formattingService);
const noScriptController = new NoScriptController(compileHandler, formDataHandler);

logger.info('=======================================');
if (gitReleaseName) logger.info(` git release ${gitReleaseName}`);
Expand Down Expand Up @@ -850,9 +853,10 @@ async function main() {
.use(sourceController.createRouter())
.use(assemblyDocumentationController.createRouter())
.use(formattingController.createRouter())
.use(noScriptController.createRouter())
.get('/g/:id', oldGoogleUrlHandler);

noscriptHandler.InitializeRoutes({limit: ceProps('bodyParserLimit', maxUploadSize)});
noscriptHandler.InitializeRoutes();
routeApi.InitializeRoutes();

if (!defArgs.doCache) {
Expand Down
6 changes: 1 addition & 5 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@
"noControlCharactersInRegex": "off",
"noShadowRestrictedNames": "off",
"noFallthroughSwitchClause": "off",
"noDoubleEquals": "off",
"noConfusingVoidType": "off"
"noDoubleEquals": "off"
},
"style": {
"noParameterAssign": "off",
"noNonNullAssertion": "off",
"useLiteralEnumMembers": "off",
"useImportType": "off",
"useTemplate": "off"
},
"correctness": {
"noVoidTypeReturn": "off",
"noUnsafeOptionalChaining": "off"
},
"performance": {
Expand All @@ -44,7 +41,6 @@
"complexity": {
"noStaticOnlyClass": "off",
"noForEach": "off",
"noBannedTypes": "off",
"useLiteralKeys": "off"
}
}
Expand Down
3 changes: 2 additions & 1 deletion etc/config/c++.amazon.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ compilers=&gcc86:&icc:&icx:&clang:&clangx86trunk:&clang-rocm:&mosclang-trunk:&rv
# The disabled groups are actually used in the c++.gpu.properties. One day these might exist on both servers, so I want
# to keep them in the same place.
defaultCompiler=g142
demangler=/opt/compiler-explorer/gcc-14.2.0/bin/c++filt
# We use the llvm-trunk demangler for all c/c++ compilers, as c++filt tends to lag behind
demangler=/opt/compiler-explorer/clang-trunk/bin/llvm-cxxfilt
objdumper=/opt/compiler-explorer/gcc-14.2.0/bin/objdump
needsMulti=false

Expand Down
3 changes: 2 additions & 1 deletion etc/config/c.amazon.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
compilers=&cgcc86:&cclang:&nvc_x86:&armcclang32:&armcclang64:&cmosclang-trunk:&rvcclang:&wasmcclang:&ppci:&cicc:&cicx:&ccl:&ccross:&cgcc-classic:&cc65:&sdcc:&ctendra:&tinycc:&zigcc:&cproc86:&chibicc:&z88dk:&compcert:godbolt.org@443/winprod:&movfuscator:&lc3:&upmem-clang:&cvast
defaultCompiler=cg142
demangler=/opt/compiler-explorer/gcc-14.2.0/bin/c++filt
# We use the llvm-trunk demangler for all c/c++ compilers, as c++filt tends to lag behind
demangler=/opt/compiler-explorer/clang-trunk/bin/llvm-cxxfilt
objdumper=/opt/compiler-explorer/gcc-14.2.0/bin/objdump
needsMulti=false

Expand Down
5 changes: 4 additions & 1 deletion etc/config/zig.defaults.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
compilers=/usr/bin/zig
compilers=zig:/usr/bin/zig
supportsBinary=true
compilerType=zig
objdumper=objdump
versionFlag=version
binaryHideFuncRe=^(_.*|call_gmon_start|(de)?register_tm_clones|frame_dummy|.*@plt.*)$
isSemVer=true
semver=trunk
supportsLibraryCodeFilter=true

#################################
#################################
Expand Down
7 changes: 0 additions & 7 deletions lib/base-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ import type {IAsmParser} from './parsers/asm-parser.interfaces.js';
import {AsmParser} from './parsers/asm-parser.js';
import {LlvmPassDumpParser} from './parsers/llvm-pass-dump-parser.js';
import type {PropertyGetter} from './properties.interfaces.js';
import {propsFor} from './properties.js';
import {HeaptrackWrapper} from './runtime-tools/heaptrack-wrapper.js';
import {LibSegFaultHelper} from './runtime-tools/libsegfault-helper.js';
import {SentryCapture} from './sentry.js';
Expand Down Expand Up @@ -212,8 +211,6 @@ export class BaseCompiler {
protected externalparser: null | ExternalParserBase;
protected supportedLibraries?: Record<string, OptionsHandlerLibrary>;
protected packager: Packager;
protected executionType: string;
protected sandboxType: string;
protected defaultRpathFlag = '-Wl,-rpath,';
private static objdumpAndParseCounter = new PromClient.Counter({
name: 'ce_objdumpandparsetime_total',
Expand Down Expand Up @@ -258,10 +255,6 @@ export class BaseCompiler {
this.compiler.disabledFilters = (this.compiler.disabledFilters as any).split(',');
}

const execProps = propsFor('execution');
this.executionType = execProps('executionType', 'none');
this.sandboxType = execProps('sandboxType', 'none');

this.asm = new AsmParser(this.compilerProps);
const irDemangler = new LLVMIRDemangler(this.compiler.demangler, this);
this.llvmIr = new LlvmIrParser(this.compilerProps, irDemangler);
Expand Down
5 changes: 4 additions & 1 deletion lib/clientstate-normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ export class ClientStateNormalizer {
const session = this.normalized.findSessionById(file.editorId);
if (session) {
file.content = session.source;
file.filename = session.filename;
if (!file.filename && session.filename) {
// it's fine if the session doesn't contain the filename, the filename in the tree is always leading
file.filename = session.filename;
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/compilers/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import fs from 'fs-extra';
import type {ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js';
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import {BaseCompiler} from '../base-compiler.js';
import {propsFor} from '../properties.js';
import * as utils from '../utils.js';

export class CleanCompiler extends BaseCompiler {
Expand Down Expand Up @@ -114,7 +115,8 @@ export class CleanCompiler extends BaseCompiler {
await fs.mkdir(execOptions.env.CLEANABCPATH);
await fs.mkdir(execOptions.env.CLEANOPATH);

if (this.executionType === 'nsjail') {
const execProps = propsFor('execution');
if (execProps<string>('executionType') === 'nsjail') {
execOptions.env.CLEANABCPATH = '/app/Clean System Files';
execOptions.env.CLEANOPATH = '/app/obj';
}
Expand Down
3 changes: 2 additions & 1 deletion lib/compilers/zig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ export class ZigCompiler extends BaseCompiler {
if (this.self_hosted_cli) {
// Versions after 0.6.0 use a different command line interface.
const outputDir = path.dirname(outputFilename);
options.push('--cache-dir', outputDir, '--name', name);
// -fno-strip: Do not strip debug info
options.push('--cache-dir', outputDir, '--name', name, '-fno-strip');

if (filters.binary) {
options.push('-femit-bin=' + desiredName);
Expand Down
45 changes: 45 additions & 0 deletions lib/handlers/api/noscript-controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2025, Compiler Explorer Authors
// 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.

import express from 'express';

import {CompileHandler} from '../compile.js';
import {HttpController} from './controller.interfaces.js';

export class NoScriptController implements HttpController {
public constructor(
private compileHandler: CompileHandler,
private formDataHandler: express.Handler,
) {}

createRouter(): express.Router {
const router = express.Router();
router.post(
'/api/noscript/compile',
this.formDataHandler,
this.compileHandler.handle.bind(this.compileHandler),
);
return router;
}
}
14 changes: 14 additions & 0 deletions lib/handlers/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,17 @@ export const csp: express.Handler = (_, res, next) => {
// res.set('Content-Security-Policy', `default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; connect-src 'self'; frame-src 'self';`);
return next();
};

/**
* Parse the incoming request as urlencoded FormData.
*/
export function createFormDataHandler(): express.Handler {
const defaultMaxBodySize = ceProps('maxBodySize', '1mb');
const parser = express.urlencoded({
limit: ceProps('bodyParserLimit', defaultMaxBodySize),
extended: false,
});
return (req, res, next) => {
parser(req, res, next);
};
}
12 changes: 2 additions & 10 deletions lib/handlers/noscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ export class NoScriptHandler {
readonly defaultLanguage: string;
readonly compileHandler: CompileHandler;

formDataParser: ReturnType<typeof express.urlencoded> | undefined;

/* the type for config makes the most sense to define in app.ts or api.ts */
constructor(
private readonly router: express.Router,
Expand All @@ -62,12 +60,7 @@ export class NoScriptHandler {
this.defaultLanguage = config.opts.wantedLanguage;
}

InitializeRoutes(options: {limit: string}) {
this.formDataParser = express.urlencoded({
limit: options.limit,
extended: false,
});

InitializeRoutes() {
this.router
.get('/noscript', cached, csp, (req, res) => {
this.renderNoScriptLayout(undefined, req, res);
Expand All @@ -87,8 +80,7 @@ export class NoScriptHandler {
})
.get('/noscript/:language', cached, csp, (req, res) => {
this.renderNoScriptLayout(undefined, req, res);
})
.post('/api/noscript/compile', this.formDataParser, this.compileHandler.handle.bind(this.compileHandler));
});
}

storedStateHandlerNoScript(req: express.Request, res: express.Response, next: express.NextFunction) {
Expand Down
6 changes: 3 additions & 3 deletions lib/handlers/route-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import express from 'express';
import {AppDefaultArguments, CompilerExplorerOptions} from '../../app.js';
import {isString} from '../../shared/common-utils.js';
import {Language} from '../../types/languages.interfaces.js';
import {assert, unwrap} from '../assert.js';
import {assert} from '../assert.js';
import {ClientStateGoldenifier, ClientStateNormalizer} from '../clientstate-normalizer.js';
import {ClientState} from '../clientstate.js';
import {CompilationEnvironment} from '../compilation-env.js';
Expand Down Expand Up @@ -281,15 +281,15 @@ export class RouteAPI {

if (tree.isCMakeProject) {
const firstSource = tree.files.find(file => {
return unwrap(file.filename).startsWith('CMakeLists.txt');
return file.filename?.startsWith('CMakeLists.txt');
});

if (firstSource) {
source = firstSource.content;
}
} else {
const firstSource = tree.files.find(file => {
return unwrap(file.filename).startsWith('example.');
return file.filename?.startsWith('example.');
});

if (firstSource) {
Expand Down
1 change: 1 addition & 0 deletions static/graph-layout-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ export class GraphLayoutCore {
VERTICAL = 0,
RIGHTCORNER = 1,
RIGHTU = 2,
// biome-ignore lint/style/useLiteralEnumMembers: ported from cutter
NULL = Number.NaN,
}
const segments: {
Expand Down
2 changes: 1 addition & 1 deletion static/modes/asm-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@ const def = definition();
monaco.languages.register({id: 'asm'});
monaco.languages.setMonarchTokensProvider('asm', def);

export = def;
export default def;
2 changes: 1 addition & 1 deletion static/modes/asm6502-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ const def = definition();
monaco.languages.register({id: 'asm6502'});
monaco.languages.setMonarchTokensProvider('asm6502', def);

export = def;
export default def;
2 changes: 1 addition & 1 deletion static/modes/asmruby-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ const def = definition();
monaco.languages.register({id: 'asmruby'});
monaco.languages.setMonarchTokensProvider('asmruby', def);

export = def;
export default def;
2 changes: 1 addition & 1 deletion static/modes/carbon-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,4 @@ monaco.languages.register({id: 'carbon'});
monaco.languages.setMonarchTokensProvider('carbon', def);
monaco.languages.setLanguageConfiguration('carbon', cpp.conf);

export = def;
export default def;
2 changes: 1 addition & 1 deletion static/modes/cpp-for-opencl-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import * as monaco from 'monaco-editor';
// @ts-ignore "Could not find a declaration file"
import * as cpp from 'monaco-editor/esm/vs/basic-languages/cpp/cpp';

import * as cppp from './cppp-mode.js';
import cppp from './cppp-mode.js';

// We need to create a new definition for C++ for OpenCL so we can remove invalid keywords

Expand Down
2 changes: 1 addition & 1 deletion static/modes/cppcircle-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import * as monaco from 'monaco-editor';

// @ts-ignore "Could not find a declaration file"
import * as cpp from 'monaco-editor/esm/vs/basic-languages/cpp/cpp';
import * as cppp from './cppp-mode.js';
import cppp from './cppp-mode.js';

// circle is c++ with a few extra '@'-prefixed keywords.

Expand Down
2 changes: 1 addition & 1 deletion static/modes/cppfront-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import * as monaco from 'monaco-editor';

// @ts-ignore "Could not find a declaration file"
import * as cpp from 'monaco-editor/esm/vs/basic-languages/cpp/cpp';
import * as cppp from './cppp-mode.js';
import cppp from './cppp-mode.js';

function definition(): monaco.languages.IMonarchLanguage {
const cppfront = $.extend(true, {}, cppp); // deep copy
Expand Down
2 changes: 1 addition & 1 deletion static/modes/cppp-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ monaco.languages.register({id: 'cppp'});
monaco.languages.setLanguageConfiguration('cppp', cpp.conf);
monaco.languages.setMonarchTokensProvider('cppp', def);

export = def;
export default def;
2 changes: 1 addition & 1 deletion static/modes/cppx-blue-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import * as monaco from 'monaco-editor';

// @ts-ignore "Could not find a declaration file"
import * as cpp from 'monaco-editor/esm/vs/basic-languages/cpp/cpp';
import * as cppp from './cppp-mode.js';
import cppp from './cppp-mode.js';

function definition(): monaco.languages.IMonarchLanguage {
const cppx_blue = $.extend(true, {}, cppp); // deep copy
Expand Down
2 changes: 1 addition & 1 deletion static/modes/crystal-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,4 @@ monaco.languages.register({id: 'crystal'});
monaco.languages.setMonarchTokensProvider('crystal', def);
monaco.languages.setLanguageConfiguration('crystal', configuration());

export = def;
export default def;
2 changes: 1 addition & 1 deletion static/modes/cuda-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import * as monaco from 'monaco-editor';

// @ts-ignore "Could not find a declaration file"
import * as cpp from 'monaco-editor/esm/vs/basic-languages/cpp/cpp';
import * as cppp from './cppp-mode.js';
import cppp from './cppp-mode.js';

// We need to create a new definition for cpp so we can remove invalid keywords

Expand Down
2 changes: 1 addition & 1 deletion static/modes/erlang-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ monaco.languages.register({id: 'erlang'});
monaco.languages.setMonarchTokensProvider('erlang', def);
monaco.languages.setLanguageConfiguration('erlang', configuration());

export = def;
export default def;
2 changes: 1 addition & 1 deletion static/modes/fortran-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,4 +553,4 @@ monaco.languages.register({id: 'fortran'});
monaco.languages.setMonarchTokensProvider('fortran', def);
monaco.languages.setLanguageConfiguration('fortran', configuration());

export = def;
export default def;
Loading

0 comments on commit ad0dfa8

Please sign in to comment.