diff --git a/cc_bindings_from_rs/cc_bindings_from_rs.rs b/cc_bindings_from_rs/cc_bindings_from_rs.rs index abba0234f..2beefcc41 100644 --- a/cc_bindings_from_rs/cc_bindings_from_rs.rs +++ b/cc_bindings_from_rs/cc_bindings_from_rs.rs @@ -14,6 +14,7 @@ extern crate rustc_session; extern crate rustc_span; extern crate rustc_target; +#[rustversion::before(2026-02-06)] use rustc_errors::registry; use rustc_middle::ty::TyCtxt; use rustc_session::config::{ @@ -187,6 +188,78 @@ fn handle_options( } } +#[rustversion::before(2026-02-06)] +fn construct_config(input: config::Input, opts: config::Options) -> rustc_interface::Config { + rustc_interface::Config { + // Command line options + opts, + // cfg! configuration in addition to the default ones + crate_cfg: Vec::new(), // FxHashSet<(String, Option)> + crate_check_cfg: Vec::new(), // CheckCfg + input, + output_dir: None, // Option + output_file: None, // Option + file_loader: None, // Option> + locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES.to_owned(), + lint_caps: Default::default(), // FxHashMap + // This is a callback from the driver that is called when [`ParseSess`] is created. + psess_created: None, //Option> + // This is a callback from the driver that is called when we're registering lints; + // it is called during plugin registration when we have the LintStore in a non-shared state. + // + // Note that if you find a Some here you probably want to call that function in the new + // function being registered. + register_lints: None, // Option> + // This is a callback from the driver that is called just after we have populated + // the list of queries. + // + // The second parameter is local providers and the third parameter is external providers. + override_queries: None, // Option, &mut ty::query::Providers<'_>)> + // Registry of diagnostics codes. + registry: registry::Registry::new(rustc_errors::codes::DIAGNOSTICS), + make_codegen_backend: None, + ice_file: None, + hash_untracked_state: None, + using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES, + extra_symbols: vec![], + } +} + +#[rustversion::since(2026-02-06)] +fn construct_config(input: config::Input, opts: config::Options) -> rustc_interface::Config { + rustc_interface::Config { + // Command line options + opts, + // cfg! configuration in addition to the default ones + crate_cfg: Vec::new(), // FxHashSet<(String, Option)> + crate_check_cfg: Vec::new(), // CheckCfg + input, + output_dir: None, // Option + output_file: None, // Option + file_loader: None, // Option> + locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES.to_owned(), + lint_caps: Default::default(), // FxHashMap + // This is a callback from the driver that is called when [`ParseSess`] is created. + psess_created: None, //Option> + // This is a callback from the driver that is called when we're registering lints; + // it is called during plugin registration when we have the LintStore in a non-shared state. + // + // Note that if you find a Some here you probably want to call that function in the new + // function being registered. + register_lints: None, // Option> + // This is a callback from the driver that is called just after we have populated + // the list of queries. + // + // The second parameter is local providers and the third parameter is external providers. + override_queries: None, // Option, &mut ty::query::Providers<'_>)> + make_codegen_backend: None, + ice_file: None, + hash_untracked_state: None, + using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES, + extra_symbols: vec![], + } +} + /// Generates bindings using rmeta input files rather than source files and rustc args. /// This function exists so we can guard it behind a feature flag and should be cleaned up once /// we've migrated to rmetas entirely. @@ -277,45 +350,10 @@ fn main() {{}} ) .into(), }; - let config = rustc_interface::Config { - // Command line options - opts: config::Options { - externs, - search_paths, - target_triple, - cg, - ..config::Options::default() - }, - // cfg! configuration in addition to the default ones - crate_cfg: Vec::new(), // FxHashSet<(String, Option)> - crate_check_cfg: Vec::new(), // CheckCfg + let config = construct_config( input, - output_dir: None, // Option - output_file: None, // Option - file_loader: None, // Option> - locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES.to_owned(), - lint_caps: Default::default(), // FxHashMap - // This is a callback from the driver that is called when [`ParseSess`] is created. - psess_created: None, //Option> - // This is a callback from the driver that is called when we're registering lints; - // it is called during plugin registration when we have the LintStore in a non-shared state. - // - // Note that if you find a Some here you probably want to call that function in the new - // function being registered. - register_lints: None, // Option> - // This is a callback from the driver that is called just after we have populated - // the list of queries. - // - // The second parameter is local providers and the third parameter is external providers. - override_queries: None, // Option, &mut ty::query::Providers<'_>)> - // Registry of diagnostics codes. - registry: registry::Registry::new(rustc_errors::codes::DIAGNOSTICS), - make_codegen_backend: None, - ice_file: None, - hash_untracked_state: None, - using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES, - extra_symbols: vec![], - }; + config::Options { externs, sysroot, target_triple, search_paths, ..Default::default() }, + ); rustc_interface::run_compiler(config, |compiler| { // Parse the program and print the syntax tree. let krate = rustc_interface::passes::parse(&compiler.sess);