rust-lang / rustc_codegen_gcc

libgccjit AOT codegen for rustc
Apache License 2.0
905 stars 60 forks source link

Building autocfg won't generate the has_std cfg #431

Closed antoyo closed 6 months ago

antoyo commented 6 months ago

For example, this build.rs:

fn main() {
    autocfg::new().emit_sysroot_crate("std");
}

with this main.rs:

#[cfg(has_std)]
fn print() {
    println!("Has std");
}

#[cfg(not(has_std))]
fn print() {
    println!("Doesn't have std");
}

fn main() {
    print();
}

Cargo.toml:

[build-dependencies.autocfg]
version = "1"

Will print "Doesn't have std" when compiled with cg_gcc.

Replacing the code for emit_ir in cg_gcc with:

            let out = cgcx.output_filenames.temp_path(OutputType::LlvmAssembly, module_name);
            std::fs::write(out, "").expect("write file");

doesn't seem enough to fix this issue.

I'm not sure how to get logs from autocfg.

antoyo commented 6 months ago

Fixed by #437.