Skip to content

Commit

Permalink
Prepare for the next cargo
Browse files Browse the repository at this point in the history
It depends on rust-lang/cargo#8494
  • Loading branch information
lu-zero committed Sep 7, 2020
1 parent 540de67 commit 8435465
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 1 addition & 8 deletions src/bin/capi.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(())
Expand Down
9 changes: 1 addition & 8 deletions src/bin/cinstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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(())
}
28 changes: 15 additions & 13 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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()));
}
}

Expand Down Expand Up @@ -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::<Vec<_>>());
Expand Down Expand Up @@ -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,
Expand All @@ -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(".")),
)
Expand All @@ -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)?;

Expand Down
2 changes: 2 additions & 0 deletions src/build_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct BuildTargets {
pub impl_lib: Option<PathBuf>,
pub def: Option<PathBuf>,
pub pc: PathBuf,
pub target: Target,
}

impl BuildTargets {
Expand Down Expand Up @@ -78,6 +79,7 @@ impl BuildTargets {
shared_lib,
impl_lib,
def,
target: target.clone(),
}
}
}
3 changes: 1 addition & 2 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use cargo::core::Workspace;

use crate::build::CApiConfig;
use crate::build_targets::BuildTargets;
use crate::target::Target;

use anyhow::Context;

Expand Down Expand Up @@ -77,13 +76,13 @@ fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> anyhow::Result<u64> {

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;

Expand Down
2 changes: 1 addition & 1 deletion src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8435465

Please sign in to comment.