.map(|(ld, ls)| ld.join(format!("lib{}.rmeta", ls)));
ret.push((filename, link_dst, FileFlavor::Linkable));
} else {
- let mut add = |crate_type: &str, file_type: FileFlavor| -> CargoResult<()> {
+ let mut add = |crate_type: &str, flavor: FileFlavor| -> CargoResult<()> {
let crate_type = if crate_type == "lib" {
"rlib"
} else {
};
let file_types = info.file_types(
crate_type,
- file_type,
+ flavor,
unit.target.kind(),
cx.target_triple(),
)?;
match file_types {
- Some(types) => {
- for file_type in types {
- // wasm bin target will generate two files in deps such as
- // "web-stuff.js" and "web_stuff.wasm". Note the different usages of
- // "-" and "_". should_replace_hyphens is a flag to indicate that
- // we need to convert the stem "web-stuff" to "web_stuff", so we
- // won't miss "web_stuff.wasm".
- let conv = |s: String| {
- if file_type.should_replace_hyphens {
- s.replace("-", "_")
- } else {
- s
- }
- };
- let filename = out_dir.join(format!(
- "{}{}{}",
- file_type.prefix,
- conv(file_stem.clone()),
- file_type.suffix,
- ));
- let link_dst = link_stem.clone().map(|(ld, ls)| {
- ld.join(format!(
- "{}{}{}",
- file_type.prefix,
- conv(ls),
- file_type.suffix
- ))
- });
- ret.push((filename, link_dst, file_type.flavor));
- }
- }
+ Some(types) => for file_type in types {
+ let filename = out_dir.join(file_type.filename(&file_stem));
+ let link_dst = link_stem
+ .as_ref()
+ .map(|&(ref ld, ref ls)| ld.join(file_type.filename(ls)));
+ ret.push((filename, link_dst, file_type.flavor));
+ },
// not supported, don't worry about it
None => {
unsupported.push(crate_type.to_string());
}
pub struct FileType {
- pub suffix: String,
- pub prefix: String,
pub flavor: FileFlavor,
- pub should_replace_hyphens: bool,
+ suffix: String,
+ prefix: String,
+ // wasm bin target will generate two files in deps such as
+ // "web-stuff.js" and "web_stuff.wasm". Note the different usages of
+ // "-" and "_". should_replace_hyphens is a flag to indicate that
+ // we need to convert the stem "web-stuff" to "web_stuff", so we
+ // won't miss "web_stuff.wasm".
+ should_replace_hyphens: bool,
+}
+
+impl FileType {
+ pub fn filename(&self, stem: &str) -> String {
+ let stem = if self.should_replace_hyphens {
+ stem.replace("-", "_")
+ } else {
+ stem.to_string()
+ };
+ format!("{}{}{}", self.prefix, stem, self.suffix)
+ }
}
impl TargetInfo {
pub fn file_types(
&self,
crate_type: &str,
- file_type: FileFlavor,
+ flavor: FileFlavor,
kind: &TargetKind,
target_triple: &str,
) -> CargoResult<Option<Vec<FileType>>> {
};
let mut ret = vec![
FileType {
- suffix: suffix.to_string(),
+ suffix: suffix.clone(),
prefix: prefix.clone(),
- flavor: file_type,
+ flavor,
should_replace_hyphens: false,
},
];