blob: ff6db168aaf808328275f92dd7c9addc296ac81c [file] [log] [blame] [raw]
Marc Poulhièsf000d512021-07-12 22:35:01 +02001// Copyright (c) 2021, Compiler Explorer Authors
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are met:
6//
7// * Redistributions of source code must retain the above copyright notice,
8// this list of conditions and the following disclaimer.
9// * Redistributions in binary form must reproduce the above copyright
10// notice, this list of conditions and the following disclaimer in the
11// documentation and/or other materials provided with the distribution.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23// POSSIBILITY OF SUCH DAMAGE.
24
25import path from 'path';
26
Matt Godboltf2c1e0b2022-05-09 23:13:50 -050027import {RustCompiler} from './rust';
Marc Poulhièsf000d512021-07-12 22:35:01 +020028
29export class RustcCgGCCCompiler extends RustCompiler {
Matt Godboltf2c1e0b2022-05-09 23:13:50 -050030 static get key() {
31 return 'rustc-cg-gcc';
32 }
Marc Poulhièsf000d512021-07-12 22:35:01 +020033
34 constructor(info, env) {
35 super(info, env);
36 this.compiler.supportsIrView = false;
Marc Poulhiès177fee02021-11-21 14:18:25 +010037
38 // Enable GCC dump code,
39 this.compiler.supportsGccDump = true;
40
41 // but do not try to filter out empty dumps:
42 // This filtering needs to dump all files but currently libgccjit (used by
43 // this rustc backend) and compiler-explorer's use of jails makes this task a bit tricky.
44 // The user will be presented more dumps than effectively created.
45 // Turning this to 'true' will break the dumps.
46
47 this.compiler.removeEmptyGccDump = false;
48 }
49
Matt Godboltf2c1e0b2022-05-09 23:13:50 -050050 getGccDumpOptions(gccDumpOptions, removeEmptyPasses) {
51 return ['-C', 'llvm-args=' + super.getGccDumpOptions(gccDumpOptions, removeEmptyPasses).join(' ')];
Marc Poulhièsf000d512021-07-12 22:35:01 +020052 }
53
54 optionsForFilter(filters, outputFilename, userOptions) {
55 // these options are direcly taken from rustc_codegen_gcc doc.
56 // See https://github.com/antoyo/rustc_codegen_gcc
57 let toolroot = path.resolve(path.dirname(this.compiler.exe), '..');
58
Matt Godboltf2c1e0b2022-05-09 23:13:50 -050059 let options = [
60 '-C',
61 'panic=abort',
62 '-Z',
63 'codegen-backend=librustc_codegen_gcc.so',
64 '--sysroot',
65 toolroot + '/sysroot',
66 ];
Marc Poulhièsf000d512021-07-12 22:35:01 +020067
68 // rust.js makes the asumption that LLVM is used. This may go away when cranelift is available.
69 // Until this is the case and the super() class is refactored, simply ditch -Cllvm arg.
Matt Godboltf2c1e0b2022-05-09 23:13:50 -050070 let super_options = super
71 .optionsForFilter(filters, outputFilename, userOptions)
72 .filter(arg => !/-Cllvm.*/.test(arg));
Marc Poulhièsf000d512021-07-12 22:35:01 +020073 options = options.concat(super_options);
74 return options;
75 }
76}