From 8435465c9aa8d9d78dcd8d86ac50e6c58a742430 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Fri, 17 Jul 2020 11:12:40 +0200 Subject: [PATCH] Prepare for the next cargo It depends on https://github.com/rust-lang/cargo/pull/8494 --- Cargo.toml | 4 ++-- src/bin/capi.rs | 9 +-------- src/bin/cinstall.rs | 9 +-------- src/build.rs | 28 +++++++++++++++------------- src/build_targets.rs | 2 ++ src/install.rs | 3 +-- src/target.rs | 2 +- 7 files changed, 23 insertions(+), 34 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9a3f220b..63109c08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,8 +23,8 @@ name = "cargo-cbuild" path = "src/bin/cbuild.rs" [dependencies] -cargo = "0.45" -semver = "0.9" +cargo = "0.49" +semver = "0.10" log = "0.4" structopt = "0.3" regex = "1" diff --git a/src/bin/capi.rs b/src/bin/capi.rs index 0f3ee20e..93ac45ae 100644 --- a/src/bin/capi.rs +++ b/src/bin/capi.rs @@ -1,7 +1,6 @@ use cargo_c::build::{cbuild, config_configure}; use cargo_c::cli::subcommand_cli; use cargo_c::install::cinstall; -use cargo_c::target::Target; use cargo::util::command_prelude::opt; use cargo::util::command_prelude::ArgMatchesExt; @@ -59,13 +58,7 @@ fn main() -> CliResult { let (build_targets, install_paths, capi_config) = cbuild(&mut ws, &config, &subcommand_args)?; if cmd == "install" { - cinstall( - &ws, - &Target::new(subcommand_args.target())?, - &capi_config, - build_targets, - install_paths, - )?; + cinstall(&ws, &capi_config, build_targets, install_paths)?; } Ok(()) diff --git a/src/bin/cinstall.rs b/src/bin/cinstall.rs index a6d6a27c..d2d9281a 100644 --- a/src/bin/cinstall.rs +++ b/src/bin/cinstall.rs @@ -5,7 +5,6 @@ use cargo::Config; use cargo_c::build::{cbuild, config_configure}; use cargo_c::cli::subcommand_cli; use cargo_c::install::cinstall; -use cargo_c::target::Target; use structopt::clap::*; @@ -43,13 +42,7 @@ fn main() -> CliResult { let (build_targets, install_paths, capi_config) = cbuild(&mut ws, &config, &subcommand_args)?; - cinstall( - &ws, - &Target::new(subcommand_args.target())?, - &capi_config, - build_targets, - install_paths, - )?; + cinstall(&ws, &capi_config, build_targets, install_paths)?; Ok(()) } diff --git a/src/build.rs b/src/build.rs index 20781108..640b5e00 100644 --- a/src/build.rs +++ b/src/build.rs @@ -93,7 +93,7 @@ fn build_pc_file( } fn patch_lib_kind_in_target(ws: &mut Workspace, libkinds: &[&str]) -> anyhow::Result<()> { - use cargo::core::LibKind::*; + use cargo::core::compiler::CrateType::*; let pkg = ws.current_mut()?; let manifest = pkg.manifest_mut(); @@ -103,7 +103,7 @@ fn patch_lib_kind_in_target(ws: &mut Workspace, libkinds: &[&str]) -> anyhow::Re for target in targets.iter_mut() { if target.is_lib() { - *target.kind_mut() = TargetKind::Lib(kinds.clone()); + target.set_kind(TargetKind::Lib(kinds.clone())); } } @@ -404,7 +404,16 @@ pub fn cbuild( config: &Config, args: &ArgMatches<'_>, ) -> anyhow::Result<(BuildTargets, InstallPaths, CApiConfig)> { - let rustc_target = target::Target::new(args.target())?; + let targets = args.targets(); + let target = match targets.len() { + 0 => None, + 1 => Some(targets[1].clone()), + _ => { + anyhow::bail!("Multiple targets not supported yet"); + } + }; + + let rustc_target = target::Target::new(target.as_ref())?; let libkinds = args .values_of("library-type") .map_or_else(|| vec!["staticlib", "cdylib"], |v| v.collect::>()); @@ -455,13 +464,6 @@ pub fn cbuild( ops::FilterRule::none(), ); - compile_opts.export_dir = args.value_of_path("out-dir", config); - if compile_opts.export_dir.is_some() { - config - .cli_unstable() - .fail_if_stable_opt("--out-dir", 6790)?; - } - let profiles = Profiles::new( ws.profiles(), config, @@ -475,7 +477,7 @@ pub fn cbuild( .as_path_unlocked() .to_path_buf() .join( - args.target() + target .map(|t| PathBuf::from(t)) .unwrap_or_else(|| PathBuf::from(".")), ) @@ -497,8 +499,8 @@ pub fn cbuild( let prev_hash = fingerprint(&build_targets)?; - let r = ops::compile(ws, &compile_opts)?; - assert_eq!(root_output, r.root_output); + // TODO: check the root_output + let _r = ops::compile(ws, &compile_opts)?; let cur_hash = fingerprint(&build_targets)?; diff --git a/src/build_targets.rs b/src/build_targets.rs index c948ac4d..40256f67 100644 --- a/src/build_targets.rs +++ b/src/build_targets.rs @@ -11,6 +11,7 @@ pub struct BuildTargets { pub impl_lib: Option, pub def: Option, pub pc: PathBuf, + pub target: Target, } impl BuildTargets { @@ -78,6 +79,7 @@ impl BuildTargets { shared_lib, impl_lib, def, + target: target.clone(), } } } diff --git a/src/install.rs b/src/install.rs index a89c1b2a..5105d464 100644 --- a/src/install.rs +++ b/src/install.rs @@ -5,7 +5,6 @@ use cargo::core::Workspace; use crate::build::CApiConfig; use crate::build_targets::BuildTargets; -use crate::target::Target; use anyhow::Context; @@ -77,13 +76,13 @@ fn copy, Q: AsRef>(from: P, to: Q) -> anyhow::Result { pub fn cinstall( ws: &Workspace, - target: &Target, capi_config: &CApiConfig, build_targets: BuildTargets, paths: InstallPaths, ) -> anyhow::Result<()> { use std::fs; + let target = &build_targets.target; let os = &target.os; let env = &target.env; diff --git a/src/target.rs b/src/target.rs index 13c59e0b..f897ade0 100644 --- a/src/target.rs +++ b/src/target.rs @@ -8,7 +8,7 @@ use crate::build::CApiConfig; /// /// Because of https://github.com/rust-lang/rust/issues/61558 /// It uses internally `rustc` to validate the string. -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct Target { pub arch: String, // pub vendor: String,