Support specifying OUT_DIR in json project

This commit is contained in:
Emil Lauridsen 2020-03-16 14:17:32 +01:00
parent f5a2fcf8f5
commit 4fb79f2ca0
2 changed files with 22 additions and 3 deletions

View file

@ -22,6 +22,7 @@ pub struct Crate {
pub(crate) deps: Vec<Dep>, pub(crate) deps: Vec<Dep>,
pub(crate) atom_cfgs: FxHashSet<String>, pub(crate) atom_cfgs: FxHashSet<String>,
pub(crate) key_value_cfgs: FxHashMap<String, String>, pub(crate) key_value_cfgs: FxHashMap<String, String>,
pub(crate) out_dir: Option<PathBuf>,
} }
#[derive(Clone, Copy, Debug, Deserialize)] #[derive(Clone, Copy, Debug, Deserialize)]

View file

@ -152,7 +152,15 @@ impl ProjectWorkspace {
pub fn out_dirs(&self) -> Vec<PathBuf> { pub fn out_dirs(&self) -> Vec<PathBuf> {
match self { match self {
ProjectWorkspace::Json { project: _project } => vec![], ProjectWorkspace::Json { project } => {
let mut out_dirs = Vec::with_capacity(project.crates.len());
for krate in &project.crates {
if let Some(out_dir) = &krate.out_dir {
out_dirs.push(out_dir.to_path_buf());
}
}
out_dirs
}
ProjectWorkspace::Cargo { cargo, sysroot: _sysroot } => { ProjectWorkspace::Cargo { cargo, sysroot: _sysroot } => {
let mut out_dirs = Vec::with_capacity(cargo.packages().len()); let mut out_dirs = Vec::with_capacity(cargo.packages().len());
for pkg in cargo.packages() { for pkg in cargo.packages() {
@ -202,6 +210,16 @@ impl ProjectWorkspace {
opts opts
}; };
let mut env = Env::default();
let mut extern_source = ExternSource::default();
if let Some(out_dir) = &krate.out_dir {
// FIXME: We probably mangle non UTF-8 paths here, figure out a better solution
env.set("OUT_DIR", out_dir.to_string_lossy().to_string());
if let Some(&extern_source_id) = extern_source_roots.get(out_dir) {
extern_source.set_extern_path(&out_dir, extern_source_id);
}
}
// FIXME: No crate name in json definition such that we cannot add OUT_DIR to env // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env
crates.insert( crates.insert(
crate_id, crate_id,
@ -211,8 +229,8 @@ impl ProjectWorkspace {
// FIXME json definitions can store the crate name // FIXME json definitions can store the crate name
None, None,
cfg_options, cfg_options,
Env::default(), env,
Default::default(), extern_source,
), ),
); );
} }