Skip to content

Commit ef25f09

Browse files
committed
Adding rustc-cg-gcc
GCC backend for rustc is still in a very early state. It is in the process of being merged in main rustc source: rust-lang/compiler-team#442 Currently reusing main rust compiler class and simply remove -Cllvm= argument if any (only for intel asm syntax). Disabling binary until the result is more friendly (currently binary are too big). refs compiler-explorer#2683
1 parent a44c2ae commit ef25f09

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

etc/config/rust.amazon.properties

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
compilers=&rust:&rustgcc:&mrustc
1+
compilers=&rust:&rustgcc:&mrustc:&rustccggcc
22
objdumper=/opt/compiler-explorer/gcc-11.1.0/bin/objdump
33
linker=/opt/compiler-explorer/gcc-11.1.0/bin/gcc
44
defaultCompiler=r1530
@@ -131,6 +131,12 @@ group.rustgcc.compilerType=gccrs
131131
group.rustgcc.compilers=gccrs-snapshot
132132
group.rustgcc.groupName=Rust-GCC
133133

134+
group.rustccggcc.compilers=rustccggcc-master
135+
compiler.rustccggcc-master.exe=/opt/compiler-explorer/rustc-cg-gcc-master/bin/rustc
136+
compiler.rustccggcc-master.semver=(rustc - GCC)
137+
group.rustccggcc.compilerType=rustc-cg-gcc
138+
group.rustccggcc.supportsBinary=false
139+
134140
compiler.mrustc-master.exe=/opt/compiler-explorer/mrustc-master/bin/mrustc
135141
compiler.mrustc-master.semver=(mrustc)
136142
group.mrustc.compilerType=mrustc

lib/compilers/_all.js

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export { PPCICompiler } from './ppci';
5959
export { PtxAssembler } from './ptxas';
6060
export { PythonCompiler } from './python';
6161
export { RustCompiler } from './rust';
62+
export { RustcCgGCCCompiler } from './rustc-cg-gcc';
6263
export { MrustcCompiler } from './mrustc';
6364
export { ScalaCompiler } from './scala';
6465
export { SdccCompiler } from './sdcc';

lib/compilers/rustc-cg-gcc.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// 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+
25+
import { RustCompiler } from './rust';
26+
import path from 'path';
27+
28+
export class RustcCgGCCCompiler extends RustCompiler {
29+
static get key() { return 'rustc-cg-gcc'; }
30+
31+
constructor(info, env) {
32+
super(info, env);
33+
this.compiler.supportsIrView = false;
34+
}
35+
36+
optionsForFilter(filters, outputFilename, userOptions) {
37+
// these options are direcly taken from rustc_codegen_gcc doc.
38+
// See https://github.com/antoyo/rustc_codegen_gcc
39+
let toolroot = path.resolve(path.dirname(this.compiler.exe), '..');
40+
41+
let options = ['-C', 'panic=abort',
42+
'-Z', 'codegen-backend=librustc_codegen_gcc.so',
43+
'--sysroot', toolroot + '/sysroot' ];
44+
45+
// rust.js makes the asumption that LLVM is used. This may go away when cranelift is available.
46+
// Until this is the case and the super() class is refactored, simply ditch -Cllvm arg.
47+
let super_options = super.optionsForFilter(filters, outputFilename, userOptions).filter(arg => !/-Cllvm.*/.test(arg));
48+
options = options.concat(super_options);
49+
return options;
50+
}
51+
}

0 commit comments

Comments
 (0)