Skip to content

[New custom build] Implement the new custom build command #763

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

Closed
wants to merge 11 commits into from
51 changes: 40 additions & 11 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Manifest {
targets: Vec<Target>,
target_dir: Path,
doc_dir: Path,
build: Vec<String>,
build: Vec<String>, // TODO: deprecated, remove
warnings: Vec<String>,
exclude: Vec<String>,
metadata: ManifestMetadata,
Expand Down Expand Up @@ -59,7 +59,7 @@ pub struct SerializedManifest {
targets: Vec<Target>,
target_dir: String,
doc_dir: String,
build: Option<Vec<String>>,
build: Option<Vec<String>>, // TODO: deprecated, remove
}

impl<E, S: Encoder<E>> Encodable<S, E> for Manifest {
Expand All @@ -73,6 +73,7 @@ impl<E, S: Encoder<E>> Encodable<S, E> for Manifest {
targets: self.targets.clone(),
target_dir: self.target_dir.display().to_string(),
doc_dir: self.doc_dir.display().to_string(),
// TODO: deprecated, remove
build: if self.build.len() == 0 { None } else { Some(self.build.clone()) },
}.encode(s)
}
Expand Down Expand Up @@ -131,8 +132,9 @@ pub struct Profile {
doctest: bool,
doc: bool,
dest: Option<String>,
plugin: bool,
for_host: bool,
harness: bool, // whether to use the test harness (--test)
custom_build: bool,
}

impl Profile {
Expand All @@ -146,8 +148,9 @@ impl Profile {
test: false,
doc: false,
dest: None,
plugin: false,
for_host: false,
doctest: false,
custom_build: false,
harness: true,
}
}
Expand Down Expand Up @@ -219,8 +222,13 @@ impl Profile {
self.doctest
}

pub fn is_plugin(&self) -> bool {
self.plugin
pub fn is_custom_build(&self) -> bool {
self.custom_build
}

/// Returns true if the target must be built for the host instead of the target.
pub fn is_for_host(&self) -> bool {
self.for_host
}

pub fn get_opt_level(&self) -> uint {
Expand Down Expand Up @@ -282,15 +290,22 @@ impl Profile {
self
}

pub fn plugin(mut self, plugin: bool) -> Profile {
self.plugin = plugin;
/// Sets whether the `Target` must be compiled for the host instead of the target platform.
pub fn for_host(mut self, for_host: bool) -> Profile {
self.for_host = for_host;
self
}

pub fn harness(mut self, harness: bool) -> Profile {
self.harness = harness;
self
}

/// Sets whether the `Target` is a custom build script.
pub fn custom_build(mut self, custom_build: bool) -> Profile {
self.custom_build = custom_build;
self
}
}

impl<H: hash::Writer> hash::Hash<H> for Profile {
Expand All @@ -302,7 +317,7 @@ impl<H: hash::Writer> hash::Hash<H> for Profile {
codegen_units,
debug,
rpath,
plugin,
for_host,
ref dest,
harness,

Expand All @@ -313,8 +328,10 @@ impl<H: hash::Writer> hash::Hash<H> for Profile {
env: _,
test: _,
doctest: _,

custom_build: _,
} = *self;
(opt_level, codegen_units, debug, rpath, plugin, dest, harness).hash(into)
(opt_level, codegen_units, debug, rpath, for_host, dest, harness).hash(into)
}
}

Expand Down Expand Up @@ -373,7 +390,7 @@ impl Manifest {
targets: targets,
target_dir: target_dir,
doc_dir: doc_dir,
build: build,
build: build, // TODO: deprecated, remove
warnings: Vec::new(),
exclude: exclude,
metadata: metadata,
Expand Down Expand Up @@ -466,6 +483,18 @@ impl Target {
}
}

/// Builds a `Target` corresponding to the `build = "build.rs"` entry.
pub fn custom_build_target(name: &str, src_path: &Path, profile: &Profile,
metadata: Option<Metadata>) -> Target {
Target {
kind: BinTarget,
name: name.to_string(),
src_path: src_path.clone(),
profile: profile.clone(),
metadata: metadata,
}
}

pub fn example_target(name: &str, src_path: &Path, profile: &Profile) -> Target {
Target {
kind: ExampleTarget,
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/ops/cargo_rustc/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct Compilation {
///
/// This is currently used to drive some entries which are added to the
/// LD_LIBRARY_PATH as appropriate.
// TODO: deprecated, remove
pub native_dirs: HashMap<PackageId, Path>,

/// Root output directory (for the local package's artifacts)
Expand All @@ -44,7 +45,7 @@ impl Compilation {
pub fn new(pkg: &Package) -> Compilation {
Compilation {
libraries: HashMap::new(),
native_dirs: HashMap::new(),
native_dirs: HashMap::new(), // TODO: deprecated, remove
root_output: Path::new("/"),
deps_output: Path::new("/"),
tests: Vec::new(),
Expand Down
14 changes: 7 additions & 7 deletions src/cargo/ops/cargo_rustc/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::{SourceMap, Package, PackageId, PackageSet, Resolve, Target};
use util::{mod, CargoResult, ChainError, internal, Config, profile};
use util::human;

use super::{Kind, KindPlugin, KindTarget, Compilation};
use super::{Kind, KindHost, KindTarget, Compilation};
use super::layout::{Layout, LayoutProxy};

#[deriving(Show)]
Expand Down Expand Up @@ -141,7 +141,7 @@ impl<'a, 'b> Context<'a, 'b> {
if !visiting.insert(pkg.get_package_id()) { return }

let key = (pkg.get_package_id(), target.get_name());
let req = if target.get_profile().is_plugin() {PlatformPlugin} else {req};
let req = if target.get_profile().is_for_host() {PlatformPlugin} else {req};
match self.requirements.entry(key) {
Occupied(mut entry) => { *entry.get_mut() = entry.get().combine(req); }
Vacant(entry) => { entry.set(req); }
Expand All @@ -164,10 +164,10 @@ impl<'a, 'b> Context<'a, 'b> {
pub fn layout(&self, pkg: &Package, kind: Kind) -> LayoutProxy {
let primary = pkg.get_package_id() == self.resolve.root();
match kind {
KindPlugin => LayoutProxy::new(&self.host, primary),
KindHost => LayoutProxy::new(&self.host, primary),
KindTarget => LayoutProxy::new(self.target.as_ref()
.unwrap_or(&self.host),
primary)
primary),
}
}

Expand All @@ -176,7 +176,7 @@ impl<'a, 'b> Context<'a, 'b> {
/// If `plugin` is true, the pair corresponds to the host platform,
/// otherwise it corresponds to the target platform.
fn dylib(&self, kind: Kind) -> CargoResult<(&str, &str)> {
let (triple, pair) = if kind == KindPlugin {
let (triple, pair) = if kind == KindHost {
(self.config.rustc_host(), &self.host_dylib)
} else {
(self.target_triple.as_slice(), &self.target_dylib)
Expand Down Expand Up @@ -204,8 +204,8 @@ impl<'a, 'b> Context<'a, 'b> {
ret.push(format!("{}{}", stem, self.target_exe));
} else {
if target.is_dylib() {
let plugin = target.get_profile().is_plugin();
let kind = if plugin {KindPlugin} else {KindTarget};
let plugin = target.get_profile().is_for_host();
let kind = if plugin {KindHost} else {KindTarget};
let (prefix, suffix) = try!(self.dylib(kind));
ret.push(format!("{}{}{}", prefix, stem, suffix));
}
Expand Down
Loading