use crate::core::NormalizedPath;
use super::{CompileContext, RustcCompileContext};
use crate::depgraph::search_paths::IncludeSearchPaths;
mod cc;
mod rustc;
pub(super) fn make_context(source: &str, user_dirs: &[&str], defines: &[&str]) -> CompileContext {
CompileContext {
source_file: NormalizedPath::from(source),
include_search: IncludeSearchPaths {
user: user_dirs
.iter()
.map(|dir| NormalizedPath::from(*dir))
.collect(),
..Default::default()
},
defines: {
let mut d: Vec<String> = defines.iter().map(|s| s.to_string()).collect();
d.sort();
d
},
flags: Vec::new(),
force_includes: Vec::new(),
unknown_flags: Vec::new(),
}
}
pub(super) fn make_rustc_context(source: &str, edition: &str) -> RustcCompileContext {
RustcCompileContext {
source_file: NormalizedPath::from(source),
crate_name: Some("mylib".to_string()),
crate_types: vec!["lib".to_string()],
edition: Some(edition.to_string()),
emit_types: vec!["link".to_string()],
cfgs: Vec::new(),
check_cfgs: Vec::new(),
codegen_flags: Vec::new(),
cargo_metadata: None,
extra_filename: None,
target: None,
cap_lints: None,
extern_crates: Vec::new(),
lint_flags: Vec::new(),
unknown_flags: Vec::new(),
remap_path_prefixes: Vec::new(),
env_vars: Vec::new(),
compiler_hash: None,
}
}
pub(super) fn make_rustc_context_with_env(env: Vec<(String, String)>) -> RustcCompileContext {
let mut ctx = make_rustc_context("/src/lib.rs", "2021");
ctx.env_vars = env;
ctx.env_vars.sort();
ctx
}