Repository: rust
Issue: Could not compile XXX (build script)
Labels: S-needs-repro

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
-->

### Code
#### Build.rs
```Rust
use std::path::PathBuf;
use windows_kernel_build::DirectoryType;

use bindgen::callbacks::*;

#[derive(Debug)]
struct Callbacks;

impl ParseCallbacks for Callbacks {
    fn int_macro(&self, name: &str, _value: i64) -> Option<IntKind> {
        Some(match name {
            "TRUE" | "FALSE" => IntKind::UChar,
            _ => return None,
        })
    }
}

fn generate_base() {
    println!("cargo:rerun-if-changed=src/wrapper.h");

    let include_dir = windows_kernel_build::get_km_dir(DirectoryType::Include).unwrap();
    let out_path = PathBuf::from(
        std::env::var_os("OUT_DIR")
            .expect("the environment variable OUT_DIR is undefined")
    );

    bindgen::Builder::default()
        .header("src/wrapper.h")
        .use_core()
        .derive_debug(false)
        .layout_tests(false)
        .ctypes_prefix("cty")
        .default_enum_style(bindgen::EnumVariation::ModuleConsts)
        .clang_arg(format!("-I{}", include_dir.to_str().unwrap()))
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        .parse_callbacks(Box::new(Callbacks))
        .ignore_functions()
        .generate()
        .unwrap()
        .write_to_file(out_path.join("base.rs"))
        .unwrap();
}

#[cfg(feature = "intrin")]
fn generate_intrin() {
    println!("cargo:rerun-if-changed=src/wrapper_intrin.c");

    let include_dir = windows_kernel_build::get_km_dir(DirectoryType::Include).unwrap();

    cc::Build::new()
        .flag("/kernel")
        .include(include_dir)
        .file("src/wrapper_intrin.c")
        .compile("wrapper_intrin");
}

#[cfg(not(feature = "intrin"))]
fn generate_intrin() {
}

#[cfg(feature = "ntoskrnl")]
fn generate_ntoskrnl() {
    println!("cargo:rerun-if-changed=src/wrapper.h");
    println!("cargo:rerun-if-changed=src/wrapper.c");
    println!("cargo:rustc-link-lib=ntoskrnl");

    let include_dir = windows_kernel_build::get_km_dir(DirectoryType::Include).unwrap();
    let out_path = PathBuf::from(
        std::env::var_os("OUT_DIR")
            .expect("the environment variable OUT_DIR is undefined")
    );

    bindgen::Builder::default()
        .header("src/wrapper.h")
        .use_core()
        .derive_debug(false)
        .layout_tests(false)
        .ctypes_prefix("cty")
        .default_enum_style(bindgen::EnumVariation::ModuleConsts)
        .clang_arg(format!("-I{}", include_dir.to_str().unwrap()))
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        .blocklist_type(".*")
        .allowlist_function(".*")
        .allowlist_recursively(false)
        .generate()
        .unwrap()
        .write_to_file(out_path.join("ntoskrnl.rs"))
        .unwrap();

    cc::Build::new()
        .flag("/kernel")
        .include(include_dir)
        .file("src/wrapper.c")
        .compile("wrapper_ntoskrnl");
}

#[cfg(not(feature = "ntoskrnl"))]
fn generate_ntoskrnl() {
}

#[cfg(feature = "netio")]
fn generate_netio() {
    println!("cargo:rerun-if-changed=src/wrapper_netio.h");
    println!("cargo:rustc-link-lib=netio");

    let include_dir = windows_kernel_build::get_km_dir(DirectoryType::Include).unwrap();
    let out_path = PathBuf::from(
        std::env::var_os("OUT_DIR")
            .expect("the environment variable OUT_DIR is undefined")
    );

    bindgen::Builder::default()
        .header("src/wrapper.h")
        .use_core()
        .derive_debug(false)
        .layout_tests(false)
        .ctypes_prefix("cty")
        .default_enum_style(bindgen::EnumVariation::ModuleConsts)
        .clang_arg(format!("-I{}", include_dir.to_str().unwrap()))
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        .blocklist_type(".*")
        .allowlist_function(".*")
        .allowlist_recursively(false)
        .generate()
        .unwrap()
        .write_to_file(out_path.join("netio.rs"))
        .unwrap();
}

#[cfg(not(feature = "netio"))]
fn generate_netio() {
}

fn main() {
    println!("cargo:rerun-if-changed=build.rs");

    generate_base();
    generate_intrin();
    generate_ntoskrnl();
    generate_netio();
}
```


### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc version: 1.75.0-nightly (a2f5f9691 2023-11-02)
platform: x86_64-pc-windows-msvc
```

### Error output

```
note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [resolver_for_lowering] getting the resolver for lowering
end of query stack
error: could not compile `driver` (build script)
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
thread 'rustc' panicked at compiler\rustc_serialize\src\opaque.rs:257:9:
MemDecoder exhausted
stack backtrace:
   0:     0x7ffc2527e64f - std::backtrace::Backtrace::force_capture::he3f91dc56bf29178
   1:     0x7ffc2527e5b4 - std::backtrace::Backtrace::force_capture::he3f91dc56bf29178
   2:     0x7ffc29ad08a7 - <tracing_subscriber[348ee398b193517f]::fmt::format::Writer>::write_fmt
   3:     0x7ffc25297213 - std::panicking::rust_panic_with_hook::h3155420840ff1d0e
   4:     0x7ffc2529707b - <std::panicking::begin_panic_handler::StaticStrPayload as core::panic::PanicPayload>::take_box::h431b1dfd98712151
   5:     0x7ffc25294259 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h904bc0c04ce5a549
   6:     0x7ffc25296dc4 - rust_begin_unwind
   7:     0x7ffc252fb7c7 - core::panicking::panic_fmt::h61dffb131f6e9923
   8:     0x7ffc2b011ea9 - <rustc_serialize[78793a675bbac8e7]::opaque::MemDecoder>::decoder_exhausted
   9:     0x7ffc2884f02a - <rustc_metadata[88dd6ab9ae3c6330]::rmeta::LazyTables as rustc_serialize[78793a675bbac8e7]::serialize::Decodable<rustc_metadata[88dd6ab9ae3c6330]::rmeta::decoder::DecodeContext>>::decode
  10:     0x7ffc28840906 - <rustc_metadata[88dd6ab9ae3c6330]::rmeta::CrateRoot as rustc_serialize[78793a675bbac8e7]::serialize::Decodable<rustc_metadata[88dd6ab9ae3c6330]::rmeta::decoder::DecodeContext>>::decode
  11:     0x7ffc2885e5fc - <rustc_metadata[88dd6ab9ae3c6330]::rmeta::decoder::DecodeContext as rustc_type_ir[2dacda7cceae3ad7]::codec::TyDecoder>::decode_alloc_id
  12:     0x7ffc2951112d - <rustc_metadata[88dd6ab9ae3c6330]::creader::CStore>::from_tcx
  13:     0x7ffc2950cc5f - <rustc_metadata[88dd6ab9ae3c6330]::creader::CStore>::from_tcx
  14:     0x7ffc2950dbf4 - <rustc_metadata[88dd6ab9ae3c6330]::creader::CStore>::from_tcx
  15:     0x7ffc2950dbf4 - <rustc_metadata[88dd6ab9ae3c6330]::creader::CStore>::from_tcx
  16:     0x7ffc28837e74 - <rustc_metadata[88dd6ab9ae3c6330]::creader::CrateLoader>::maybe_process_path_extern
  17:     0x7ffc290cf41a - <rustc_resolve[f04156e10fad7049]::Segment as core[f8fea1319500e153]::convert::From<&rustc_ast[b6e260e1ed6edfd8]::ast::PathSegment>>::from
  18:     0x7ffc290ad2fd - <rustc_ast_lowering[201af491a11ab4de]::index::NodeCollector as rustc_hir[3a40cb97853f56da]::intravisit::Visitor>::visit_trait_ref
  19:     0x7ffc290bbbd7 - <rustc_resolve[f04156e10fad7049]::Resolver as rustc_expand[16a018f586d05fde]::base::ResolverExpand>::resolve_imports
  20:     0x7ffc2959e6be - <rustc_expand[16a018f586d05fde]::expand::MacroExpander>::fully_expand_fragment
  21:     0x7ffc2888c64c - <rustc_expand[16a018f586d05fde]::expand::MacroExpander>::expand_crate
  22:     0x7ffc25c80e21 - rustc_interface[389250caa294c4dd]::interface::parse_check_cfg
  23:     0x7ffc25c8f913 - rustc_interface[389250caa294c4dd]::passes::resolver_for_lowering
  24:     0x7ffc286c17ed - rustc_query_impl[cb10d16ec2d5e911]::profiling_support::alloc_self_profile_query_strings
  25:     0x7ffc286fed69 - rustc_query_impl[cb10d16ec2d5e911]::profiling_support::alloc_self_profile_query_strings
  26:     0x7ffc286fc5dc - rustc_query_impl[cb10d16ec2d5e911]::profiling_support::alloc_self_profile_query_strings
  27:     0x7ffc2872ec94 - rustc_query_impl[cb10d16ec2d5e911]::profiling_support::alloc_self_profile_query_strings
  28:     0x7ffc28700371 - rustc_query_impl[cb10d16ec2d5e911]::profiling_support::alloc_self_profile_query_strings
  29:     0x7ffc25c39ca6 - rustc_driver_impl[fd9e39ab138d307a]::main
  30:     0x7ffc25c4ac8f - <rustc_middle[c7980097819ed664]::ty::SymbolName as core[f8fea1319500e153]::fmt::Debug>::fmt
  31:     0x7ffc25c402db - rustc_driver_impl[fd9e39ab138d307a]::args::arg_expand_all
  32:     0x7ffc25c5f609 - <rustc_middle[c7980097819ed664]::ty::SymbolName as core[f8fea1319500e153]::fmt::Debug>::fmt
  33:     0x7ffc25c431d1 - rustc_driver_impl[fd9e39ab138d307a]::args::arg_expand_all
  34:     0x7ffc252aa41c - std::sys::windows::thread::Thread::new::hf36a95c7576122b9
  35:     0x7ffc91ab257d - BaseThreadInitThunk
  36:     0x7ffc92a8aa58 - RtlUserThreadStart


rustc version: 1.75.0-nightly (a2f5f9691 2023-11-02)
platform: x86_64-pc-windows-msvc

query stack during panic:
#0 [resolver_for_lowering] getting the resolver for lowering
end of query stack

```

</p>
</details>