Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for cdylib crate types #2741

Merged
merged 1 commit into from
Jun 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rustc_serialize::{Encoder, Encodable};

use core::{Dependency, PackageId, PackageIdSpec, Summary};
use core::package_id::Metadata;
use util::{CargoResult, human};

/// Contains all the information about a package, as loaded from a Cargo.toml.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -44,33 +43,40 @@ pub struct ManifestMetadata {
pub documentation: Option<String>, // url
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, RustcEncodable, Copy)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum LibKind {
Lib,
Rlib,
Dylib,
StaticLib
Other(String),
}

impl LibKind {
pub fn from_str(string: &str) -> CargoResult<LibKind> {
pub fn from_str(string: &str) -> LibKind {
match string {
"lib" => Ok(LibKind::Lib),
"rlib" => Ok(LibKind::Rlib),
"dylib" => Ok(LibKind::Dylib),
"staticlib" => Ok(LibKind::StaticLib),
_ => Err(human(format!("crate-type \"{}\" was not one of lib|rlib|dylib|staticlib",
string)))
"lib" => LibKind::Lib,
"rlib" => LibKind::Rlib,
"dylib" => LibKind::Dylib,
s => LibKind::Other(s.to_string()),
}
}

/// Returns the argument suitable for `--crate-type` to pass to rustc.
pub fn crate_type(&self) -> &'static str {
pub fn crate_type(&self) -> &str {
match *self {
LibKind::Lib => "lib",
LibKind::Rlib => "rlib",
LibKind::Dylib => "dylib",
LibKind::StaticLib => "staticlib"
LibKind::Other(ref s) => s,
}
}

pub fn linkable(&self) -> bool {
match *self {
LibKind::Lib |
LibKind::Rlib |
LibKind::Dylib => true,
LibKind::Other(..) => false,
}
}
}
Expand Down Expand Up @@ -335,12 +341,7 @@ impl Target {
pub fn linkable(&self) -> bool {
match self.kind {
TargetKind::Lib(ref kinds) => {
kinds.iter().any(|k| {
match *k {
LibKind::Lib | LibKind::Rlib | LibKind::Dylib => true,
LibKind::StaticLib => false,
}
})
kinds.iter().any(|k| k.linkable())
}
_ => false
}
Expand All @@ -353,7 +354,7 @@ impl Target {
pub fn is_custom_build(&self) -> bool { self.kind == TargetKind::CustomBuild }

/// Returns the arguments suitable for `--crate-type` to pass to rustc.
pub fn rustc_crate_types(&self) -> Vec<&'static str> {
pub fn rustc_crate_types(&self) -> Vec<&str> {
match self.kind {
TargetKind::Lib(ref kinds) => {
kinds.iter().map(|kind| kind.crate_type()).collect()
Expand All @@ -368,7 +369,11 @@ impl Target {

pub fn can_lto(&self) -> bool {
match self.kind {
TargetKind::Lib(ref v) => *v == [LibKind::StaticLib],
TargetKind::Lib(ref v) => {
!v.contains(&LibKind::Rlib) &&
!v.contains(&LibKind::Dylib) &&
!v.contains(&LibKind::Lib)
}
_ => true,
}
}
Expand Down
36 changes: 21 additions & 15 deletions src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,45 +42,51 @@ pub fn clean(manifest_path: &Path, opts: &CleanOptions) -> CargoResult<()> {
None => None,
};

let cx = try!(Context::new(&resolve, &packages, opts.config,
host_layout, target_layout,
BuildConfig::default(),
root.manifest().profiles()));
let mut cx = try!(Context::new(&resolve, &packages, opts.config,
host_layout, target_layout,
BuildConfig::default(),
root.manifest().profiles()));
let mut units = Vec::new();

// resolve package specs and remove the corresponding packages
for spec in opts.spec {
// Translate the spec to a Package
let pkgid = try!(resolve.query(spec));
let pkg = try!(packages.get(&pkgid));

// And finally, clean everything out!
// Generate all relevant `Unit` targets for this package
for target in pkg.targets() {
for kind in [Kind::Host, Kind::Target].iter() {
let layout = cx.layout(&pkg, *kind);
try!(rm_rf(&layout.proxy().fingerprint(&pkg)));
try!(rm_rf(&layout.build(&pkg)));
let Profiles {
ref release, ref dev, ref test, ref bench, ref doc,
ref custom_build, ref test_deps, ref bench_deps,
} = *root.manifest().profiles();
let profiles = [release, dev, test, bench, doc, custom_build,
test_deps, bench_deps];
for profile in profiles.iter() {
let unit = Unit {
units.push(Unit {
pkg: &pkg,
target: target,
profile: profile,
kind: *kind,
};
let root = cx.out_dir(&unit);
for filename in try!(cx.target_filenames(&unit)).iter() {
try!(rm_rf(&root.join(&filename)));
}
});
}
}
}
}

try!(cx.probe_target_info(&units));

for unit in units.iter() {
let layout = cx.layout(&unit.pkg, unit.kind);
try!(rm_rf(&layout.proxy().fingerprint(&unit.pkg)));
try!(rm_rf(&layout.build(&unit.pkg)));

let root = cx.out_dir(&unit);
for (filename, _) in try!(cx.target_filenames(&unit)) {
try!(rm_rf(&root.join(&filename)));
}
}

Ok(())
}

Expand Down
Loading