Skip to content

Commit

Permalink
Add datadir support
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-zero committed Nov 13, 2021
1 parent 28a5d23 commit 095239c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
20 changes: 19 additions & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,10 @@ pub struct LibraryCApiConfig {
pub rustflags: Vec<String>,
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct InstallCApiConfig {
pub include: Vec<InstallTarget>,
pub data: Vec<InstallTarget>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -696,10 +697,27 @@ fn load_manifest_capi_config(pkg: &Package) -> anyhow::Result<CApiConfig> {
}
}
}
// TODO: Add data paths customizations
}

let default_assets_data = InstallTargetPaths {
from: "assets/capi/share/**/*".to_string(),
to: name.clone(),
};

let default_generated_data = InstallTargetPaths {
from: "capi/share/**/*".to_string(),
to: name.clone(),
};

let data_targets = vec![
InstallTarget::Asset(default_assets_data),
InstallTarget::Generated(default_generated_data),
];

let install = InstallCApiConfig {
include: include_targets,
data: data_targets,
};

Ok(CApiConfig {
Expand Down
2 changes: 2 additions & 0 deletions src/build_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::target::Target;
#[derive(Debug, Default, Clone)]
pub struct ExtraTargets {
pub include: Vec<(PathBuf, PathBuf)>,
pub data: Vec<(PathBuf, PathBuf)>,
}

impl ExtraTargets {
Expand All @@ -16,6 +17,7 @@ impl ExtraTargets {
out_dir: Option<&Path>,
) -> anyhow::Result<()> {
self.include = extra_targets(&capi_config.install.include, root_dir, out_dir)?;
self.data = extra_targets(&capi_config.install.data, root_dir, out_dir)?;

Ok(())
}
Expand Down
7 changes: 7 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ struct Common {
/// Path to directory for installing generated pkg-config .pc files
#[structopt(long = "pkgconfigdir", parse(from_os_str))]
pkgconfigdir: Option<PathBuf>,
/// Path to directory for installing read-only data (defaults to {prefix}/share)
#[structopt(long = "datarootdir", parse(from_os_str))]
datarootdir: Option<PathBuf>,
/// Path to directory for installing read-only application-specific data (defaults to
/// {datarootdir}/{crate-name})
#[structopt(long = "datadir", parse(from_os_str))]
datadir: Option<PathBuf>,
#[structopt(long = "dlltool", parse(from_os_str))]
/// Use the provided dlltool when building for the windows-gnu targets.
dlltool: Option<PathBuf>,
Expand Down
21 changes: 21 additions & 0 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ pub fn cinstall(ws: &Workspace, packages: &[CPackage]) -> anyhow::Result<()> {
let install_path_lib = append_to_destdir(destdir, &install_path_lib);
let install_path_pc = append_to_destdir(destdir, &paths.pkgconfigdir);
let install_path_include = append_to_destdir(destdir, &paths.includedir);
let install_path_data = append_to_destdir(destdir, &paths.datadir);

create_dir_all(&install_path_lib)?;
create_dir_all(&install_path_pc)?;
Expand All @@ -197,6 +198,15 @@ pub fn cinstall(ws: &Workspace, packages: &[CPackage]) -> anyhow::Result<()> {
}
}

if !build_targets.extra.data.is_empty() {
ws.config().shell().status("Installing", "data file")?;
for (from, to) in build_targets.extra.data.iter() {
let to = install_path_data.join(to);
create_dir_all(to.parent().unwrap())?;
copy(from, to)?;
}
}

if let Some(ref static_lib) = build_targets.static_lib {
ws.config().shell().status("Installing", "static library")?;
copy(
Expand Down Expand Up @@ -243,6 +253,7 @@ pub struct InstallPaths {
pub prefix: PathBuf,
pub libdir: PathBuf,
pub includedir: PathBuf,
pub datadir: PathBuf,
pub bindir: PathBuf,
pub pkgconfigdir: PathBuf,
}
Expand All @@ -265,6 +276,15 @@ impl InstallPaths {
.value_of("includedir")
.map(PathBuf::from)
.unwrap_or_else(|| prefix.join("include"));
let datarootdir = args
.value_of("datarootdir")
.map(PathBuf::from)
.unwrap_or_else(|| prefix.join("share"));
let datadir = args
.value_of("datadir")
.map(PathBuf::from)
.unwrap_or_else(|| datarootdir.clone());

let subdir_name = PathBuf::from(&capi_config.header.subdirectory);

let bindir = args
Expand All @@ -282,6 +302,7 @@ impl InstallPaths {
prefix,
libdir,
includedir,
datadir,
bindir,
pkgconfigdir,
}
Expand Down
4 changes: 1 addition & 3 deletions src/pkg_config_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,7 @@ mod test {
versioning: true,
rustflags: Vec::default(),
},
install: crate::build::InstallCApiConfig {
include: Vec::new(),
},
install: Default::default(),
},
);
pkg.add_lib("-lbar").add_cflag("-DFOO");
Expand Down

0 comments on commit 095239c

Please sign in to comment.