piston icon indicating copy to clipboard operation
piston copied to clipboard

Need a way to ignore compiler warning or pass compiler flags

Open Trimutius opened this issue 3 years ago • 4 comments

Currently there is no way to ignore compiler warning. Which creates not very good experience if you for example run winners of obfuscated code competition. For example: ./run c

int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}

Gives following output

I received c(10.2.0) compile errors

file0.code.c:1:7: warning: return type defaults to 'int' [-Wimplicit-int]
    1 | int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
      |       ^~~~
file0.code.c: In function 'main':
file0.code.c:1:39: warning: implicit declaration of function 'read' [-Wimplicit-function-declaration]
    1 | int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
      |                                       ^~~~
file0.code.c:1:61: warning: backslash-newline at end of file
    1 | int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
      |                                                              
file0.code.c: At top level:
file0.code.c:2:25: warning: return type defaults to 'int' [-Wimplicit-int]
    2 | o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}
      |                         ^~~~
file0.code.c: In function 'read':
file0.code.c:2:25: warning: type of 'j' defaults to 'int' [-Wimplicit-int]
file0.code.c:2:25: warning: type of 'i' defaults to 'int' [-Wimplicit-int]
file0.code.c:2:25: warning: type of 'p' defaults to 'int' [-Wimplicit-int]
file0.code.c:2:37: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
    2 | o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}
      |                                     ^~~~~
hello, world!

But of course if you were able to give compiler '-w' flag it would be wa cleaner: ./run

cat > file.c << EOF
int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}
EOF
/piston/pack*/gcc/1*/bin/gcc -w ./file.c
./a.out

Here is your bash(5.1.0) output

hello, world!

Would be nice for it to be supported natively rather than havin to go through bash hacks. Most of the contest winners have so many warnings that stderr of compiler eats up the whole thing.

Trimutius avatar Oct 24 '22 11:10 Trimutius

For this I'm thinking we modify the metadata.json file and add a parameters schema like so:

{
    "language": "gcc",
    "version": "10.2.0",
    "provides": [
        {
            "language": "c",
            "aliases": ["gcc"]
        },
        {
            "language": "c++",
            "aliases": ["cpp", "g++"]
        },
        {
            "language": "d",
            "aliases": ["gdc"]
        },
        {
            "language": "fortran",
            "aliases": ["fortran", "f90"]
        }
    ],
    "options": {
        "hideWarnings": {
            "type": "boolean",
            "description" : "Hide Warning when compiling"
        }
    }
}

Then in the request we could have a languageOptions key:

{
    "language": "c",
    "files": [
        {
            "name": "file.c",
            "content": "/* c */"
        }
    ],
    "languageOptions": {
        "hideWarnings": true
    }
}

This could then be passed to the run/compile scripts through env vars such as PISTON_OPT_HIDEWARNING and handled in there accordingly.

I'll whip something up and get it PR'd

HexF avatar Oct 29 '22 11:10 HexF

language_options please

realtux avatar Oct 29 '22 14:10 realtux

Why not implement this into nix-packages directly? #471

Brikaa avatar Oct 30 '22 12:10 Brikaa

Was there any updates on this?

yvonne-yang avatar Aug 31 '23 21:08 yvonne-yang