rust-lang / rustc_codegen_gcc

libgccjit AOT codegen for rustc
Apache License 2.0
893 stars 61 forks source link

Cannot pass CG_RUSTFLAGS when building sysroot #491

Closed darcagn closed 2 months ago

darcagn commented 2 months ago

I've successfully gotten libc/std building targetting SuperH (SH4/Dreamcast). I need to build sysroot with -matomic-model=soft-imask for it to work properly.

I can insert rustflags.push_str(" -Cllvm-args=-matomic-model=soft-imask"); at this line: https://github.com/rust-lang/rustc_codegen_gcc/blob/5584f5f1a22aceb3d686cfa1165c6d160c994586/build_system/src/build.rs#L150

Or insert context.add_command_line_option("-matomic-model=soft-imask"); at this line: https://github.com/rust-lang/rustc_codegen_gcc/blob/5584f5f1a22aceb3d686cfa1165c6d160c994586/src/base.rs#L118

And I seem to get the desired effect. But I'd prefer not to patch things if I can do it without.

If I do CG_RUSTFLAGS=-Cllvm-args=-matomic-model=soft-imask y.sh build it does not seem to honor it when building the sysroot. To test this I can put gibberish flags like -blahblah and get no error when the same would give me errors when building a normal project with y.sh cargo build. Am I doing something wrong here or is this something not supported yet?

GuillaumeGomez commented 2 months ago

Normally we do use CG_RUSTFLAGS as you can see here. This function is called to build the command line which will be used for all commands, so if it's not setting variables correctly, maybe the code is wrong.

antoyo commented 2 months ago

In this case, the environment is first set to the empty one here, so that condition is never true.

antoyo commented 2 months ago

Fixed by #493.